How to communicate with jvmti agent attached on a running JVM

后端 未结 2 603
执笔经年
执笔经年 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 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.

提交回复
热议问题