harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r888739 - /harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/inst_agt.c
Date Wed, 09 Dec 2009 09:08:42 GMT
Author: regisxu
Date: Wed Dec  9 09:08:41 2009
New Revision: 888739

URL: http://svn.apache.org/viewvc?rev=888739&view=rev
Log:
updating capabilities in instrument agent should consider JVM's potential capabilities

Modified:
    harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/inst_agt.c

Modified: harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/inst_agt.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/inst_agt.c?rev=888739&r1=888738&r2=888739&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/inst_agt.c
(original)
+++ harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/inst_agt.c
Wed Dec  9 09:08:41 2009
@@ -339,9 +339,9 @@
     str_support_redefine = read_attribute(vm, manifest, lwrmanifest,"can-redefine-classes");
     if(NULL != str_support_redefine){
         support_redefine = str2bol(str_support_redefine);
-        gsupport_redefine |= support_redefine;
         hymem_free_memory(str_support_redefine);
     }
+    gsupport_redefine &= support_redefine;
 
     //add bootclasspath
 
@@ -362,6 +362,10 @@
 JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved){
     PORT_ACCESS_FROM_JAVAVM(vm);
     VMI_ACCESS_FROM_JAVAVM(vm);
+    jvmtiError jvmti_err;
+    JNIEnv *env = NULL;
+    static jvmtiEnv *jvmti;
+    jvmtiCapabilities updatecapabilities;
     jint err = (*vm)->GetEnv(vm, (void **)&jnienv, JNI_VERSION_1_2);
     if(JNI_OK != err){
         return err;
@@ -371,8 +375,6 @@
         jvmtiCapabilities capabilities;
         jvmtiError jvmti_err;
         jvmtiEventCallbacks callbacks;
-        JNIEnv *env = NULL;
-        static jvmtiEnv *jvmti;
 
         gdata = hymem_allocate_memory(sizeof(AgentData));
 
@@ -383,15 +385,10 @@
         }
         gdata->jvmti = jvmti;
 
-        //set prerequisite capabilities for classfileloadhook, redefine, and VMInit event
-        memset(&capabilities, 0, sizeof(capabilities));
-        capabilities.can_generate_all_class_hook_events=1;
-        capabilities.can_redefine_classes = 1;
-        //FIXME VM doesnot support the capbility right now.
-        //capabilities.can_redefine_any_class = 1;
-        jvmti_err = (*jvmti)->AddCapabilities(jvmti, &capabilities);
-        check_jvmti_error(env, jvmti_err,
-                          "Cannot add JVMTI capabilities.");
+        //get JVMTI potential capabilities
+        jvmti_err = (*jvmti)->GetPotentialCapabilities(jvmti, &capabilities);
+        check_jvmti_error(env, jvmti_err, "Cannot get JVMTI potential capabilities.");
+        gsupport_redefine = (capabilities.can_redefine_classes == 1);
 
         //set events callback function
         (void)memset(&callbacks, 0, sizeof(callbacks));
@@ -405,7 +402,18 @@
         check_jvmti_error(env, jvmti_err, "Cannot set JVMTI VMInit event notification mode.");
     }
 
-    return Parse_Options(vm,jnienv, gdata->jvmti,options);
+    err = Parse_Options(vm,jnienv, gdata->jvmti,options);
+
+    //update capabilities JVMTI
+    memset(&updatecapabilities, 0, sizeof(updatecapabilities));
+    updatecapabilities.can_generate_all_class_hook_events = 1;
+    updatecapabilities.can_redefine_classes = gsupport_redefine;
+    //FIXME VM doesnot support the capbility right now.
+    //capabilities.can_redefine_any_class = 1;
+    jvmti_err = (*jvmti)->AddCapabilities(jvmti, &updatecapabilities);
+    check_jvmti_error(env, jvmti_err, "Cannot add JVMTI capabilities.");
+
+    return err;
 }
 
 JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm){



Mime
View raw message