How to communicate with jvmti agent attached on a running JVM

后端 未结 2 547
执笔经年
执笔经年 2021-01-26 10:10

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

相关标签:
2条回答
  • 2021-01-26 10:45

    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.

    0 讨论(0)
  • 2021-01-26 11:04

    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.

    0 讨论(0)
提交回复
热议问题