tags:

views:

23

answers:

1

I have the following java code

public class Test {
    public void sayHello(String msg) {
         System.out.println(msg);
    }
}

new Test().sayHello("Bonjour");

I have a jvmti agent attached to java where I catch function calls. I want to get parameter value which was passed to my method (e.g. "Bonjour")

  static void JNICALL cbMethodEntry(jvmtiEnv *jvmti, 
                         JNIEnv* jni_env, jthread thread, jmethodID method) {
        // here I want to get a parameter value "Bonjour"
        // which was passed to my method sayHello("Bonjour")
  }

  jvmtiEventCallbacks    callbacks;
  callbacks.MethodEntry = &cbMethodEntry;

In the callback itself I have a thread and method ID.

Looking into a jvmti.h header I found only this structure dealing with parameters but there are no values.

typedef struct {
    char* name;
    jvmtiParamKind kind;
    jvmtiParamTypes base_type;
    jboolean null_ok;
} jvmtiParamInfo;

How can I get parameter values from my callback?

+1  A: 

You are going to want to start by using GetLocalObject. In this respect I was able to find the following example that should help get you going in the right direction.

Alex Winston
Alex, it works. Thanks a lot!!!
Oleg Pavliv