You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Pavel Pervov <pm...@gmail.com> on 2009/05/02 11:19:29 UTC

Re: A question about jvmti

Yixun,

It is by JVMTI design that you cannot call to JVMTI functions outside
an agent. You can try to trigger certain type of event in your JNI
method (something like MethodEnter or ExceptionThrow) and pass
required object handle to agent callback through some variable
accessible both to JNI and to JVMTI code.

WBR,
    Pavel.

On Tue, Apr 28, 2009 at 7:06 AM, YixunZhou <se...@gmail.com> wrote:
> 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
> seanny2003@gmail.com
>
>
>