2

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

Community
  • 1
  • 1
devoured elysium
  • 101,373
  • 131
  • 340
  • 557

2 Answers2

2

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, CallStaticVoidMethod would 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 * env parameter), the class the static method is declared in (this is the jclass cls parameter), the method to invoke (this is the jmethodID methodID parameter).

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

void CallStaticVoidMethod(jclass cls, jmethodID methodID, ...) {
    va_list args;
    va_start(args,methodID);
    functions->CallStaticVoidMethodV(this,cls,methodID,args);
    va_end(args);
}

I don't know where this is assigned: functions->CallStaticVoidMethodV but 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.

Steve
  • 31,144
  • 19
  • 99
  • 122
  • Steve, I was already well aware of the facts you referred about JNI. In fact that's precisely the motive I'm trying to get my hands on that function's body. My question is... where is its source? – devoured elysium Feb 24 '12 at 16:58
  • @Devouredelysium - Ah, ok, sorry. Well the link you provided isn't a link to a java runtime/vm - so the implementation wouldn't be in that project. If you're asking where the implementation in the OpenJDK stuff is - I have know idea - but my good friend `grep` probably does. – Steve Feb 24 '12 at 17:06
  • Oh, sorry. I had already seen the function you're showing now. But I had the idea that it was that last function that was calling the other one shown in the OP. If I'm wrong, then I'd like to know where is functions->CallStaticVoidMethodV(this,cls,methodID,args). – devoured elysium Feb 24 '12 at 17:15
  • @devouredelysium - "functions" is a variable - of some type which has a pointer to a function called "CallStaticVoidMethodV" - which is assigned somewhere. You'll need to find where it's assigned. I added more to the edit to describe why I'd bet it's probably one level removed from the actual implementation you're looking for. – Steve Feb 24 '12 at 17:18
  • "functions" is assigned right in that file, if I'm not mistaken. In that same struct, you'll find the function shown in the OP. – devoured elysium Feb 24 '12 at 17:21
  • line782: const struct JNINativeInterface_ *functions; – devoured elysium Feb 24 '12 at 17:21
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/8188/discussion-between-devoured-elysium-and-steve) – devoured elysium Feb 24 '12 at 17:25
  • Steve, I'm awarding you the answer, as after looking up in the link you provided, http://hg.openjdk.java.net/, I eventually found more useful code that proved very useful to help achieve my task. – devoured elysium Feb 25 '12 at 15:37
1

This declares CallStaticVoidMethod as a pointer to a function that returns nothing and takes three or more arguments.

Nikolai Fetissov
  • 82,306
  • 11
  • 110
  • 171