As in previous answers, implementation is not specified.
To get an idea of ββwhat the implementation might look like, I looked at the runtime portion of the newly created JVM Hotspot. In Hotspot, each object begins with a tag word (for GC and other purposes) and a klass pointer. If you call getClass, then the native implementation in Object.c is called:
JNIEXPORT jclass JNICALL Java_java_lang_Object_getClass(JNIEnv *env, jobject this) { if (this == NULL) { JNU_ThrowNullPointerException(env, NULL); return 0; } else { return (*env)->GetObjectClass(env, this); } }
GetObjectClass is part of the JNI API. ( http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html ) JNI's internal implementation of GetObjectClass really just solves the object pointer, reads the class from the class pointer, and returns a Java view of this class:
JNI_ENTRY(jclass, jni_GetObjectClass(JNIEnv *env, jobject obj)) JNIWrapper("GetObjectClass"); HOTSPOT_JNI_GETOBJECTCLASS_ENTRY(env, obj); Klass* k = JNIHandles::resolve_non_null(obj)->klass(); jclass ret = (jclass) JNIHandles::make_local(env, k->java_mirror()); HOTSPOT_JNI_GETOBJECTCLASS_RETURN(ret); return ret; JNI_END
source share