I’m diving into Java’s OpenJDK’s source code and I was in hopes of learning a bit about CallStaticVoidMethod. But I’m having a hardtime doing so.
This is where I got stomped:
00535 void (JNICALL *CallStaticVoidMethod)
00536 (JNIEnv *env, jclass cls, jmethodID methodID, ...);
If my rough C knowledge is right, this seems like a function call(to where?). Maybe it could be that’s making a call to some alread compiled library?
(JNICALL is just a calling convention)
being that JNICALL seems to be __stdcall ( What is __stdcall? )
Here is the file’s full source code:
http://xdprof.sourceforge.net/doxygen/jni_8h-source.html
Thanks
Maybe it could be that's making a call to some alread compiled library?Yeah – I think you need some background on what the JNI is. Let me try and provide that background quickly, as I think it will clear up your confusion, or at least set you on the right track.
Java runtimes can’t run on Java – they are implemented as native executables.
The JNI (the Java Native Interface) is, essentially, a native interface for asking a Java runtime to do various things.
Amongst a ton of other things, you can use the JNI to invoke methods implemented in Java.
The JNI has a bunch of different helper methods for invoking different types of methods.
The method you are asking about, in particular,
CallStaticVoidMethodwould be used to invoke a Java function such as the one in this example:public static void DoSomething() { ... }In order for the runtime to invoke that method, it needs to know a few things – such as: information about the current runtime/context/environment (this is the
JNIEnv * envparameter), the class the static method is declared in (this is thejclass clsparameter), the method to invoke (this is thejmethodID methodIDparameter).EDIT:
Followup to your reply:
I found it without much trouble in the OpenJDK code.
http://hg.openjdk.java.net/
cvmi/cvmi/jdk Common VM Interface
http://hg.openjdk.java.net/cvmi/cvmi/jdk/archive/tip.zip
Under:
./src/share/javavm/export/jni.h
I don’t know where this is assigned:
functions->CallStaticVoidMethodVbut I’m sure if you go through the trouble of downloading all the source for the various components you’ll find a struct with that member and/or an assignment to that function pointer – and you can go from there.Because it’s supposed to be a standard/common interface for multiple runtimes I wouldn’t be surprised if there was some layer of indirection between the actual implementation and the way it’s exposed through the JNI.