views:

50

answers:

2

In Java, several native methods e.g. in the Java Runtime Library may call regular (bytecode-based) methods. I would like to know if there is some VM command-line parameter or some instrumentation tool or API that I can use to such calls.

P.S. Note that I am not interested in calls to native code but from native code.

+1  A: 

On linux, you could use ltrace to detect calls to the JNI functions that call Java methods, such as CallVoidMethod, CallObjectMethod, etc.

Jonathan Feinberg
I tried this suggestion, but using dtrace on OSX. This seems to work, but only for native calls that actually go through the JNI. Unfortunately, when the Hotspot VM calls a method directly through native code, e.g. through reflection, then it seems that the VM does not use the JNI methods you mentioned. Therefore, the calls do not show up in dtrace.
Why do you believe that Java methods are being called at those times? And, for what it's worth, "introspection" *is* how JNI calls Java methods (as you'd see if you read that link I provided).
Jonathan Feinberg
A: 

Are you looking for something like Java Native Interface (JNI)?

"The Java Native Interface (JNI) is a programming framework that allows Java code running in a Java Virtual Machine (JVM) to call and to be called by native applications (programs specific to a hardware and operating system platform) and libraries written in other languages, such as C, C++ and assembly."

JNI Wikipedia Article

Abboq
No. I know what JNI is, but that does not answer my question.
It's odd, then, that you marked this answer as the correct one.
Jonathan Feinberg