profiling java code which is being called from native code

profiling java code which is being called from native code

I am able to profile native code which is being called from java code. But I could not able to profile java code which is being called from native code.

I have written a win32 application in Delphi. This application calls java methods using JNI. I want to find hotspots in both Delphi code and java code.

Friends please suggest me how to do this.

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.


To load the profiler dll with the JVM you need to specify "-Xrunjavaperf" in the options field of the JavaVMInitArgs structure when you load the JVM.
(for call graph you need to specify "-Xrunjavaperf:cg")

I'll demonstrate it in C++ sample, but I guess it's the same for Delphi:

#define USER_CLASSPATH "." /* where Prog.class is */

main() {
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
jint res;
JavaVMOption options[2];
options[0].optionString = "-Xrunjavaperf:cg";
options[1].optionString = "-Djava.class.path=" USER_CLASSPATH;

vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = 2;

/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if (res < 0) {
printf("Error loading VM!!
return 1;

jclass cls = env->FindClass("JNITest");
jmethodID mid = env->GetStaticMethodID(cls, "test", "()V");
env->CallStaticVoidMethod(cls, mid);


return 0;

I tried it with sun JVM 1.4.2 and I had segmentation fault, but with BEA JRockit 8.1 sp1 and IBM 1.3.1 it worked fine.

I hope it answer your question.

Hi Haimc,
Thanks for the reply. Putting "cg" in command line option is new to me. I will try this and share the experience.
Can u please also tell me what is the command line option for sampling..?

Sampling is the default. Do not specify ":cg"

Hi all,

I'm trying to do the same thing, but I don't understand is how to configure the VTune activity. Do I creata Java sampling activity? If so, Do I choose Application, Script or Applet?

Maybe I'm going down the wrong path?


Leave a Comment

Please sign in to add a comment. Not a member? Join today