I know Object.hashCode() does not necessarily be related to memory address. But I am trying to understand when it does, how it works.
I checked the code. The Object
code declares hashCode()
as native
:
public native int hashCode();
I basically dont understand how this native works.
I found below two related files:
Object.c contains [source]:
static JNINativeMethod methods[] = {
{"hashCode", "()I", (void *)&JVM_IHashCode},
{"wait", "(J)V", (void *)&JVM_MonitorWait},
{"notify", "()V", (void *)&JVM_MonitorNotify},
{"notifyAll", "()V", (void *)&JVM_MonitorNotifyAll},
{"clone", "()Ljava/lang/Object;", (void *)&JVM_Clone},
};
java_lang_Object.h contains [source]:
/*
* Class: java_lang_Object
* Method: hashCode
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_java_lang_Object_hashCode
(JNIEnv *, jobject);
However all that is not making sense. More importantly I dont find actual native implementation of hashCode()
in above files and I dont understand JNI and possibly some advanced C well. Can someone explain how all things are getting wired up?