How to communicate with jvmti agent attached on a running JVM

喜你入骨 提交于 2019-12-02 11:37:18

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!