harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pavel Pervov <pmcfi...@gmail.com>
Subject Re: A question about jvmti
Date Sat, 02 May 2009 09:19:29 GMT
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 <seanny2003@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
>
>
>

Mime
View raw message