harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r514881 - in /harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti: jvmti_capability.cpp jvmti_tags.cpp jvmti_tags.h jvmti_thread.cpp
Date Mon, 05 Mar 2007 21:58:46 GMT
Author: gshimansky
Date: Mon Mar  5 13:58:46 2007
New Revision: 514881

URL: http://svn.apache.org/viewvc?view=rev&rev=514881
Log:
Applied HARMONY-3294 and HARMONY-3295 - two minor bugfixes in JVMTI code


Modified:
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_capability.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_tags.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_tags.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_capability.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_capability.cpp?view=diff&rev=514881&r1=514880&r2=514881
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_capability.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_capability.cpp Mon Mar  5 13:58:46
2007
@@ -24,6 +24,7 @@
 
 #include "jvmti_direct.h"
 #include "jvmti_utils.h"
+#include "jvmti_tags.h"
 #include "cxxlog.h"
 #include "suspend_checker.h"
 #include "environment.h"
@@ -142,6 +143,44 @@
     1  // can_generate_object_free_events
 };
 
+// Implementation for jvmtiGetPotentialCapabilities()
+void static get_available_caps(jvmtiEnv* env,
+                               jvmtiPhase phase,
+                               jvmtiCapabilities* capabilities_ptr)
+{
+    TIEnv *ti_env = reinterpret_cast<TIEnv *>(env);
+
+    if (JVMTI_PHASE_ONLOAD == phase)
+        *capabilities_ptr = interpreter_enabled() ?
+            jvmti_supported_interpreter_capabilities : jvmti_supported_jit_capabilities;
+    else
+    {
+        // Add all capabilities from supported on live phase to already posessed capabilities
+        unsigned char* puchar_ptr = (unsigned char*)capabilities_ptr;
+        unsigned char* enable_ptr = (unsigned char*)&jvmti_enable_on_live_flags;
+
+        *capabilities_ptr = ti_env->posessed_capabilities;
+
+        for (int i = 0; i < int(sizeof(jvmtiCapabilities)); i++)
+            puchar_ptr[i] |= enable_ptr[i]; 
+    }
+
+    DebugUtilsTI* ti = VM_Global_State::loader_env->TI;
+
+    // can_tag_objects capability can only be possessed by one environment.
+    // The feature should be globally enabled in OnLoad phase. If not, it
+    // can't be possesed in live phase.
+    // Thus can_tag_objects is available IF
+    // ( we're in the OnLoad phase OR the feature is already enabled ) AND
+    // no other environment possesses this capability.
+    if ( (JVMTI_PHASE_ONLOAD == phase || ManagedObject::_tag_pointer) && 
+        (!ti->get_global_capability(DebugUtilsTI::TI_GC_ENABLE_TAG_OBJECTS) ||
+            ti_env->posessed_capabilities.can_tag_objects) )
+        capabilities_ptr->can_tag_objects = 1;
+    else
+        capabilities_ptr->can_tag_objects = 0;
+}
+
 /*
  * Get Potential Capabilities
  *
@@ -171,21 +210,7 @@
     if (errorCode != JVMTI_ERROR_NONE)
         return errorCode;
 
-    if (JVMTI_PHASE_ONLOAD == phase)
-        *capabilities_ptr = interpreter_enabled() ?
-            jvmti_supported_interpreter_capabilities : jvmti_supported_jit_capabilities;
-    else
-    {
-        // Add all capabilities from supported on live phase to already posessed capabilities
-        TIEnv *ti_env = reinterpret_cast<TIEnv *>(env);
-        unsigned char* puchar_ptr = (unsigned char*)capabilities_ptr;
-        unsigned char* enable_ptr = (unsigned char*)&jvmti_enable_on_live_flags;
-
-        *capabilities_ptr = ti_env->posessed_capabilities;
-
-        for (int i = 0; i < int(sizeof(jvmtiCapabilities)); i++)
-            puchar_ptr[i] |= enable_ptr[i]; 
-    }
+    get_available_caps(env, phase, capabilities_ptr);
 
     return JVMTI_ERROR_NONE;
 }
@@ -220,41 +245,32 @@
     if (errorCode != JVMTI_ERROR_NONE)
         return errorCode;
 
+    // make a copy of already possessed caps
     TIEnv *ti_env = reinterpret_cast<TIEnv *>(env);
-    jvmtiCapabilities posessed = ti_env->posessed_capabilities;
+    jvmtiCapabilities possessed_caps = ti_env->posessed_capabilities;
     
-    const jvmtiCapabilities* available_caps =
-        (phase == JVMTI_PHASE_LIVE) ? &jvmti_enable_on_live_flags :
-        (interpreter_enabled() ?
-            &jvmti_supported_interpreter_capabilities :
-            &jvmti_supported_jit_capabilities);
-
-    unsigned char* requested = (unsigned char*)capabilities_ptr;
-    unsigned char* available = (unsigned char*)available_caps;
-    unsigned char* p_posessed = (unsigned char*)&posessed;
+    jvmtiCapabilities available_caps;
+    get_available_caps(env, phase, &available_caps);
 
-    DebugUtilsTI *ti = ti_env->vm->vm_env->TI;
+    unsigned char* p_requested = (unsigned char*) capabilities_ptr;
+    unsigned char* p_available = (unsigned char*) &available_caps;
+    unsigned char* p_possessed = (unsigned char*) &possessed_caps;
 
-    // if the global capability can_tag_objects has already been enabled,
-    // requested by this environment, but not yet posessed by this environment,
-    // reject the request
-    if (ti->get_global_capability(DebugUtilsTI::TI_GC_ENABLE_TAG_OBJECTS)
-            && !posessed.can_tag_objects && capabilities_ptr->can_tag_objects)
-        return JVMTI_ERROR_NOT_AVAILABLE;
+    DebugUtilsTI *ti = ti_env->vm->vm_env->TI;
 
     // Allow to turn on any capabilities that are listed in potential capabilities
     for (int i = 0; i < int(sizeof(jvmtiCapabilities)); i++)
     {
-        unsigned char adding_new = requested[i] & ~p_posessed[i];
+        unsigned char adding_new = p_requested[i] & ~p_possessed[i];
 
-        if (adding_new & ~available[i])
+        if (adding_new & ~p_available[i])
             return JVMTI_ERROR_NOT_AVAILABLE;
 
-        p_posessed[i] |= adding_new;
+        p_possessed[i] |= adding_new;
     }
 
     // Add new capabilities after checking was done
-    ti_env->posessed_capabilities = posessed;
+    ti_env->posessed_capabilities = possessed_caps;
 
     // Update global capabilities
     if (capabilities_ptr->can_generate_method_entry_events)
@@ -289,11 +305,14 @@
 
     if (capabilities_ptr->can_tag_objects) {
         ti->set_global_capability(DebugUtilsTI::TI_GC_ENABLE_TAG_OBJECTS);
+
+        // this flag could be set only once and mustn't be reset by
+        // RelinquishCapabilities.
         ManagedObject::_tag_pointer = true;
     }
 
     return JVMTI_ERROR_NONE;
-}
+} // jvmtiAddCapabilities
 
 /*
  * Relinquish Capabilities
@@ -377,17 +396,31 @@
     if (removed_caps.can_generate_field_modification_events)
         ti->reset_global_capability(DebugUtilsTI::TI_GC_ENABLE_FIELD_MODIFICATION_EVENT);
 
-    if (capabilities_ptr->can_pop_frame)
+    if (removed_caps.can_pop_frame)
         ti->reset_global_capability(DebugUtilsTI::TI_GC_ENABLE_POP_FRAME);
 
+    if (removed_caps.can_tag_objects) {
+        // clear tags on relinquishing can_tag_objects capability
+        ti_env = reinterpret_cast<TIEnv *>(env);
+        assert(ti_env->lock);
+        hymutex_lock(ti_env->lock);
+        if (ti_env->tags) {
+            ti_env->tags->clear();
+            delete ti_env->tags;
+            ti_env->tags = NULL;
+        }
+        hymutex_unlock(ti_env->lock);
+
+        ti->reset_global_capability(DebugUtilsTI::TI_GC_ENABLE_TAG_OBJECTS);
+    }
+
     // relinquishing following capabilities will not revert VM operation mode
     // back to optimized, so we do not reset global capabilities
     //
     //     TI_GC_ENABLE_MONITOR_EVENTS
-    //     TI_GC_ENABLE_TAG_OBJECTS
 
     return JVMTI_ERROR_NONE;
-}
+} // jvmtiRelinquishCapabilities
 
 /*
  * Get Capabilities
@@ -424,5 +457,5 @@
     *capabilities_ptr = ti_env->posessed_capabilities;
 
     return JVMTI_ERROR_NONE;
-}
+} // jvmtiGetCapabilities
 

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_tags.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_tags.cpp?view=diff&rev=514881&r1=514880&r2=514881
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_tags.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_tags.cpp Mon Mar  5 13:58:46 2007
@@ -184,3 +184,12 @@
         ti_env = next_env;
     }
 }
+
+void TITags::clear()
+{
+    assert(!hythread_is_suspend_enabled());
+    tag_pair_list::iterator i;
+    for (i = tags.begin(); i != tags.end(); i++) {
+        update(i->obj, 0, ti_get_object_tptr(i->obj));
+    }
+}

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_tags.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_tags.h?view=diff&rev=514881&r1=514880&r2=514881
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_tags.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_tags.h Mon Mar  5 13:58:46 2007
@@ -78,6 +78,9 @@
     /// @param ti_env - the pass-through parameter 
     ///   to jvmti_send_object_free_event()
     void clean_reclaimed_object_tags(bool send_event, TIEnv* ti_env);
+
+    /// deletes all tags.
+    void clear();
 };
 
 /**

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp?view=diff&rev=514881&r1=514880&r2=514881
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp Mon Mar  5 13:58:46
2007
@@ -459,12 +459,21 @@
     if (err != JVMTI_ERROR_NONE){
        return err; 
     } 
+
     if (capa.can_signal_thread == 0){
         return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
     }
+
     if (!is_valid_thread_object(thread)){
         return JVMTI_ERROR_INVALID_THREAD;
     }
+
+    jint thread_state;
+    IDATA UNUSED status = jthread_get_state(thread, &thread_state);
+    assert(status == TM_ERROR_NONE);
+
+    if (! (JVMTI_THREAD_STATE_ALIVE & thread_state))
+        return JVMTI_ERROR_THREAD_NOT_ALIVE;
 
     return (jvmtiError)jthread_interrupt(thread);
 }



Mime
View raw message