harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r607130 - in /harmony/enhanced/drlvm/trunk/vm/vmcore/src: jvmti/jvmti_thread.cpp thread/thread_ti_instr.cpp
Date Thu, 27 Dec 2007 22:21:03 GMT
Author: gshimansky
Date: Thu Dec 27 14:21:03 2007
New Revision: 607130

URL: http://svn.apache.org/viewvc?rev=607130&view=rev
Log:
Fix GetOwnedMonitors stack. Target thread has to be suspended when copying
its owned monitors array, and monitor handles have to be an array of local
handles according to the spec.


Modified:
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_instr.cpp

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?rev=607130&r1=607129&r2=607130&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp Thu Dec 27 14:21:03
2007
@@ -587,8 +587,25 @@
         return JVMTI_ERROR_THREAD_NOT_ALIVE;
     }
 
+    bool thread_suspended = false;
+    // Gregory -
+    // There is a race condition. If target thread is not suspended,
+    // it may exit some of its owned monitors which leads to incorrect
+    // references in the array.
+    vm_thread_t vm_thread = jthread_get_vm_thread_ptr_safe(thread);
+    // Check that this thread is not current
+    if (vm_thread != p_TLS_vmthread)
+    {
+        IDATA UNREF status = hythread_suspend_other((hythread_t)vm_thread);
+        assert(TM_ERROR_NONE == status);
+        thread_suspended = true;
+    }
+
     IDATA UNUSED status = jthread_get_owned_monitors(thread, owned_monitor_count_ptr, owned_monitors_ptr);
     assert(status == TM_ERROR_NONE);
+
+    if (thread_suspended)
+        hythread_resume((hythread_t)vm_thread);
 
     return JVMTI_ERROR_NONE;
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_instr.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_instr.cpp?rev=607130&r1=607129&r2=607130&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_instr.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_instr.cpp Thu Dec 27 14:21:03
2007
@@ -489,11 +489,24 @@
         hythread_global_unlock();
         return TM_ERROR_OUT_OF_MEMORY;
     }
+
+    tmn_suspend_disable();
     for (int i = 0; i < jvmti_thread->owned_monitors_nmb; i++) {
+        jobject new_ref = oh_allocate_local_handle_from_jni();
+
+        if (NULL != new_ref)
+            new_ref->object = jvmti_thread->owned_monitors[i]->object;
+        else
+        {
+            tmn_suspend_enable();   
+            hythread_global_unlock();
+            return TM_ERROR_OUT_OF_MEMORY;
+        }
         // change the order of reported monitors to be compliant with RI
-        monitors[jvmti_thread->owned_monitors_nmb - 1 - i] =
-                jvmti_thread->owned_monitors[i];
+        monitors[jvmti_thread->owned_monitors_nmb - 1 - i] = new_ref;
     }
+    tmn_suspend_enable();   
+
     *monitors_ptr = monitors;
     *monitor_count_ptr = jvmti_thread->owned_monitors_nmb;
 



Mime
View raw message