I wanted to know how would I communicate with the jvmti agent I attached on a running JVM using attach API. When I say communicate ,here\'s what I meant : I want to call native
How would I communicate with the jvmti agent I attached on a running JVM using attach API.
If I understand what you are doing here correctly, it is entirely up to you how your external application communicates with the agent, but it is also up to you to implement it ... starting with designing or choosing the wire-protocol you are going to use.
You could try to register native methods using the JNI. I haven't tested this yet, but you might try something like this:
Add a native method to the class that is supposed to communicate with your JVMTI agent:
public native MyResponseType myNativeMethod (MyRequestType obj);
Then use the JNI to bind this Java method to some method of your JVMTI agent:
static JNINativeMethod methods[] = {
{"myNativeMethod", "(Lmy/package/MyRequestType;)Lmy/package/MyResponseType;", (void *)&native_method}
};
jni->RegisterNatives(cls, methods, 1);
where cls
is a jclass reference to the class containing your native method.