GetFieldID
,GetStaticFieldID
,jfieldID の生成は, jfieldIDWorkaround クラスが行っている (See: jfieldIDWorkaround).
jfieldID 値のエンコード方式は以下の通り.
instance field の場合:
最下位 1bit は 1 (これで static field と区別可能). 上位 30bits は, フィールド位置を示すオフセット情報.
static field の場合:
フィールド位置を示す JNIid オブジェクトへのポインタが jfieldID として使われる (See: JNIid). (このため最下位 1bit は 0 になる. これで instance field と区別可能).
...(#TODO)
((cite: hotspot/src/share/vm/runtime/jfieldIDWorkaround.hpp))
// This workaround is because JVMTI doesn't have distinct entry points
// for methods that use static jfieldIDs and instance jfieldIDs.
// The workaround is to steal a low-order bit:
// a 1 means the jfieldID is an instance jfieldID,
// and the rest of the word is the offset of the field.
// a 0 means the jfieldID is a static jfieldID,
// and the rest of the word is the JNIid*.
//
// Another low-order bit is used to mark if an instance field
// is accompanied by an indication of which class it applies to.
//
// Bit-format of a jfieldID (most significant first):
// address:30 instance=0:1 checked=0:1
// offset:30 instance=1:1 checked=0:1
// klass:23 offset:7 instance=1:1 checked=1:1
//
// If the offset does not fit in 7 bits, or if the fieldID is
// not checked, then the checked bit is zero and the rest of
// the word (30 bits) contains only the offset.
//
jni_GetFieldID() -> instanceKlass::find_field() -> jfieldIDWorkaround::to_instance_jfieldID()
jni_GetStaticFieldID() -> instanceKlass::find_field() -> instanceKlass::jni_id_for() -> instanceKlass::jni_id_for_impl() -> jfieldIDWorkaround::to_static_jfieldID()
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.