Hi all,
I have a question about jvmti agent. I get the capability
"can_tag_objects" and "can_generate_field_modification_events" on jvm
start up,
but I want to tag some object in java method, so I use jni code as
following:
JNIEXPORT jboolean JNICALL Java_Test_tagObj(JNIEnv * jni, jclass clzz,
jobject obj){
// get jvmti environment
JavaVM* jvm;
jvmtiEnv * jvmti;
jint res;
jvmtiError error;
// get jvm
(*jni)->GetJavaVM(jni, &jvm);
// get jvmti
res = (*jvm)->GetEnv(jvm, (void **) &jvmti, JVMTI_VERSION_1_0);
// check if jvmti capacities has been set: tag, watch
jvmtiCapabilities capa;
(void) memset(&capa, 0, sizeof(jvmtiCapabilities));
capa.can_tag_objects = 1;
capa.can_generate_field_modification_events = 1;
error = (*jvmti)->AddCapabilities(jvmti, &capa);
// check error
check_jvmti_error(jvmti, error, "Unable to get necessary JVMTI
capabilities: can_tag_objects.");
// protect all fields of obj, just tag the object
error = (*jvmti)->SetTag(jvmti, obj, PROTECTION_TAG);
check_jvmti_error(jvmti, error, "set tag error");
return JNI_TRUE;
}
Both capabilities are not gained. So I looked into AddCapabilities,
it says "can_tag_objects" can only be owned by one agent, and
"can_generate_field_modification_events" can not be gained on live
phase. However, I already get these capabilities on start, can I
pass them to the new agent? or can I pass the jvmti as parameter to the
above function?
--
Best regard,
Yixun Zhou
[email protected]