harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wjwashb...@apache.org
Subject svn commit: r549848 - in /harmony/enhanced/drlvm/trunk/vm: thread/src/thread_native_basic.c vmcore/src/thread/thread_generic.cpp
Date Fri, 22 Jun 2007 15:37:39 GMT
Author: wjwashburn
Date: Fri Jun 22 08:37:39 2007
New Revision: 549848

URL: http://svn.apache.org/viewvc?view=rev&rev=549848
Log:
harmony-4024:  this patch fixes a major problem with recycling thread IDs


Modified:
    harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp

Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c?view=diff&rev=549848&r1=549847&r2=549848
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c Fri Jun 22 08:37:39 2007
@@ -60,8 +60,9 @@
     #endif
 #endif
 
-#define MAX_ID 1000000
+#define MAX_ID 0x8000
 hythread_t fast_thread_array[MAX_ID];
+short next_free_thread_id[MAX_ID];
 int next_id = 1;
 
 /*
@@ -575,6 +576,7 @@
  */
 static IDATA register_to_group(hythread_t thread, hythread_group_t group) {
     IDATA status;
+    int free_slot_found = 0;
     hythread_t cur, prev;
 
     assert(thread);
@@ -592,14 +594,27 @@
     thread->state |= TM_THREAD_STATE_ALIVE | TM_THREAD_STATE_RUNNABLE;
     
     if (!thread->thread_id) {
-        ++next_id;
-        thread->thread_id = next_id;
-        if (next_id >= MAX_ID) {
+        U_32 i;
+        for(i = 0; i < MAX_ID; i++) {
+            // increase next_id to allow thread_id change 
+            next_id++;
+            if (next_id == MAX_ID) {
+	            next_id = 1;
+            }
+            if (fast_thread_array[next_id] == NULL) {
+                thread->thread_id = next_id;
+	            free_slot_found = 1;
+                break;
+            }
+        }
+
+        if (!free_slot_found) {
             hythread_global_unlock(NULL);
             return TM_ERROR_OUT_OF_MEMORY;
         }
     }
-    
+
+    assert(thread->thread_id);
     fast_thread_array[thread->thread_id] = thread;
 
     thread->group = group;

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp?view=diff&rev=549848&r1=549847&r2=549848
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp Fri Jun 22 08:37:39
2007
@@ -274,12 +274,12 @@
  */
 jint vm_detach(jthread java_thread) {
     VM_thread * p_vm_thread;
-    jint status;
     
     assert(hythread_is_suspend_enabled());
 
-    status = run_java_detach(java_thread);
-    if (status != JNI_OK) return status;
+    // could return error if detach throws an exception,
+    // keep exception and ignore an error
+    run_java_detach(java_thread);
 
     // Send Thread End event
     jvmti_send_thread_start_end_event(0);



Mime
View raw message