thx so much for your care.
That's my first question in this usenet.
Those ids are only used to call non-native method?
All jni method in C can use the first parameter to call non-native
method of that java object without any extra info,why those ids are
need?What things they really are?
On 11月17日, 下午8时19分, Thomas Fritsch
<i.dont.like.s...@invalid.com> wrote:
> 仁者无敌 schrieb:> what's the native initIDs method of it used for?The initID method typically gets some JNI method IDs of the
> FileXXXStream class and stores them somewhere in the C code. Later,
[quoted text clipped - 3 lines]
> --
> Thomas
By using the first two, I'm sorry,
"env" and "jobject"
en,but initIDs is a static native method, lack the "jobject"...
however,
this method is only called once in the static area,what did it store in
C code?
On 11月17日, 下午8时19分, Thomas Fritsch
<i.dont.like.s...@invalid.com> wrote:
> 仁者无敌 schrieb:> what's the native initIDs method of it used for?The initID method typically gets some JNI method IDs of the
> FileXXXStream class and stores them somewhere in the C code. Later,
[quoted text clipped - 3 lines]
> --
> Thomas
Gordon Beaton - 17 Nov 2006 13:00 GMT
On 17 Nov 2006 04:46:11 -0800, =?gb2312?B?yMrV387etdA=?= wrote:
> By using the first two, I'm sorry,
> "env" and "jobject"
>
> en,but initIDs is a static native method, lack the "jobject"...
Static methods have "jclass" instead.
> however, this method is only called once in the static area,what did
> it store in C code?
It makes calls to GetFieldID() to look up commonly used fields in the
class. This is a relatively expensive operation that only needs to be
done once for a given class. By caching the results the ids can be
reused by subsequent calls to the class's other native methods.
See section 10.7:
http://java.sun.com/docs/books/jni/html/pitfalls.html#29161
Why don't you get the source and check for yourself?
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Thomas Fritsch - 17 Nov 2006 13:23 GMT
仁者无敌 schrieb:
> On 11月17日, 下午8时19分, Thomas Fritsch
> <i.dont.like.s...@invalid.com> wrote:
[quoted text clipped - 9 lines]
>
> en,but initIDs is a static native method, lack the "jobject"...
You don't need it for getting method or field IDs.
> however,
> this method is only called once in the static area,what did it store
> in C code?
It might do for example look below:
#include "FileInputStream.h"
static jmethodID readMethodID;
static jmethodID closeMethodID;
void Java_FileInputStream_initIDs(JNIEnv *env, jclass c)
{
readMethodID = env->GetMethodID(env, c, "read", "()I");
closeMethodID = env->GetMethodID(env, c, "close", "()V");
}
void Java_FileInputStream_exampleMethod(JNIEnv *env, jobject obj)
{
env->CallVoidMethod(env, obj, closeMethodID);
}
By the way: If you want a deeper understanding of JNI, I suggest you
work through Sun's JNI tutorial and/or a text-book.

Signature
Thomas
仁者无敌 - 17 Nov 2006 13:41 GMT
To Gordon,Thomas:
Thanks for your help and suggestion.
On 11月17日, 下午9时23分, Thomas Fritsch
<i.dont.like.s...@invalid.com> wrote:
> 仁者无敌 schrieb:> On 11月17日, 下午8时19分, Thomas Fritsch
> > <i.dont.like.s...@invalid.com> wrote:
[quoted text clipped - 33 lines]
> --
> Thomas