harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r448390 - in /incubator/harmony/enhanced/drlvm/trunk/vm: include/open/ interpreter/src/ port/include/ port/src/thread/linux/ port/src/thread/win/ tests/unit/thread/ tests/unit/thread/utils/ thread/src/ vmcore/include/ vmcore/src/jvmti/ vmco...
Date Wed, 20 Sep 2006 22:48:26 GMT
Author: geirm
Date: Wed Sep 20 15:48:25 2006
New Revision: 448390

URL: http://svn.apache.org/viewvc?view=rev&rev=448390
Log:
HARMONY-1421

Threadmanager JVMTI related fixes

Both patches applied - the second fixed the problem
I found with the finalizer test.

tested on ubuntu 6


Modified:
    incubator/harmony/enhanced/drlvm/trunk/vm/include/open/thread_externals.h
    incubator/harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp
    incubator/harmony/enhanced/drlvm/trunk/vm/port/include/apr_thread_ext.h
    incubator/harmony/enhanced/drlvm/trunk/vm/port/src/thread/linux/apr_thread_ext.c
    incubator/harmony/enhanced/drlvm/trunk/vm/port/src/thread/win/apr_thread_ext.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_vm_emulator.c
    incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/tm2vm.c
    incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c
    incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_monitors.c
    incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c
    incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_suspend.c
    incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_thin_monitor.c
    incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/include/version_svn_tag.h
    incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_capability.cpp
    incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp
    incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java
    incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMThreadManager.cpp
    incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/include/open/thread_externals.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/include/open/thread_externals.h?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/include/open/thread_externals.h (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/include/open/thread_externals.h Wed Sep 20 15:48:25
2006
@@ -78,12 +78,20 @@
   */
 VMEXPORT int vm_detach();
 
-/* throw exception
+/**
+ * creates exception object using given class name and message and throws it
+ * using jthread_throw_exception method;
  * @param[in] name char* -name
  * @param[in] message char* -message
  * @return int.
  */
 VMEXPORT int jthread_throw_exception(char* name, char* message);
+
+/**
+ * Throws given exception object; Desides whether current thread is unwindable
+ * and throws it, raises exception otherwise;
+ */
+VMEXPORT int jthread_throw_exception_object(jobject object);
 
 // TI support interface
 VMEXPORT void jvmti_send_thread_start_end_event(int);

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp Wed Sep 20 15:48:25
2006
@@ -882,7 +882,6 @@
 #define DEF_OPCODE_CMP(CMP,check)                   \
 static inline void                                  \
 Opcode_##CMP(StackFrame& frame) {                   \
-    hythread_safe_point();                                \
     int32 val = frame.stack.pick().i;               \
     frame.stack.ref() = FLAG_NONE; /* for OPCODE_IFNULL */ \
     DEBUG_BYTECODE("val = " << (int)val);                    \
@@ -894,6 +893,7 @@
     frame.ip += 3;                                  \
     }                                               \
     frame.stack.pop();                              \
+    hythread_safe_point();                                \
 }
 
 DEF_OPCODE_CMP(IFEQ,==0) // Opcode_IFEQ
@@ -906,7 +906,6 @@
 #define DEF_OPCODE_IF_ICMPXX(NAME,cmp)                          \
 static inline void                                              \
 Opcode_IF_ICMP ## NAME(StackFrame& frame) {                     \
-    hythread_safe_point();                                           \
     int32 val0 = frame.stack.pick(1).i;                         \
     int32 val1 = frame.stack.pick(0).i;                         \
     frame.stack.ref(1) = FLAG_NONE;                             \
@@ -919,6 +918,7 @@
         DEBUG_BYTECODE(val1 << " " << val0 << " branch not taken");\
     }                                                           \
     frame.stack.pop(2);                                         \
+    hythread_safe_point();                                           \
 }
 
 DEF_OPCODE_IF_ICMPXX(EQ,==) // Opcode_IF_ICMPEQ OPCODE_IF_ACMPEQ
@@ -2864,22 +2864,22 @@
             case OPCODE_IFEQ: Opcode_IFEQ(frame); break;
 
             case OPCODE_IFNONNULL:
-            case OPCODE_IFNE: Opcode_IFNE(frame); break;
-            case OPCODE_IFGE: Opcode_IFGE(frame); break;
-            case OPCODE_IFGT: Opcode_IFGT(frame); break;
-            case OPCODE_IFLE: Opcode_IFLE(frame); break;
-            case OPCODE_IFLT: Opcode_IFLT(frame); break;
+            case OPCODE_IFNE: Opcode_IFNE(frame); goto check_exception;
+            case OPCODE_IFGE: Opcode_IFGE(frame); goto check_exception;
+            case OPCODE_IFGT: Opcode_IFGT(frame); goto check_exception;
+            case OPCODE_IFLE: Opcode_IFLE(frame); goto check_exception;
+            case OPCODE_IFLT: Opcode_IFLT(frame); goto check_exception;
 
             case OPCODE_IF_ACMPEQ:
-            case OPCODE_IF_ICMPEQ: Opcode_IF_ICMPEQ(frame); break;
+            case OPCODE_IF_ICMPEQ: Opcode_IF_ICMPEQ(frame); goto check_exception;
 
             case OPCODE_IF_ACMPNE:
-            case OPCODE_IF_ICMPNE: Opcode_IF_ICMPNE(frame); break;
+            case OPCODE_IF_ICMPNE: Opcode_IF_ICMPNE(frame); goto check_exception;
 
-            case OPCODE_IF_ICMPGE: Opcode_IF_ICMPGE(frame); break;
-            case OPCODE_IF_ICMPGT: Opcode_IF_ICMPGT(frame); break;
-            case OPCODE_IF_ICMPLE: Opcode_IF_ICMPLE(frame); break;
-            case OPCODE_IF_ICMPLT: Opcode_IF_ICMPLT(frame); break;
+            case OPCODE_IF_ICMPGE: Opcode_IF_ICMPGE(frame); goto check_exception;
+            case OPCODE_IF_ICMPGT: Opcode_IF_ICMPGT(frame); goto check_exception;
+            case OPCODE_IF_ICMPLE: Opcode_IF_ICMPLE(frame); goto check_exception;
+            case OPCODE_IF_ICMPLT: Opcode_IF_ICMPLT(frame); goto check_exception;
 
             case OPCODE_FCMPL: Opcode_FCMPL(frame); break;
             case OPCODE_FCMPG: Opcode_FCMPG(frame); break;

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/port/include/apr_thread_ext.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/port/include/apr_thread_ext.h?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/port/include/apr_thread_ext.h (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/port/include/apr_thread_ext.h Wed Sep 20 15:48:25
2006
@@ -1,3 +1,18 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
 /**
  * @author Andrey Chernyshev
  * @version $Revision$
@@ -23,6 +38,6 @@
 
 APR_DECLARE(apr_status_t) apr_thread_cancel(apr_thread_t *thread);
 
-APR_DECLARE(apr_status_t) apr_get_thread_time(apr_thread_t *thread, unsigned long long* nanos_ptr);
+APR_DECLARE(apr_status_t) apr_get_thread_time(apr_thread_t *thread, apr_int64_t* nanos_ptr);
 
 #endif  /* APR_EXT_H */

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/port/src/thread/linux/apr_thread_ext.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/port/src/thread/linux/apr_thread_ext.c?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/port/src/thread/linux/apr_thread_ext.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/port/src/thread/linux/apr_thread_ext.c Wed Sep
20 15:48:25 2006
@@ -1,7 +1,27 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Artem Aliev
+ * @version $Revision$
+ */
+
+#define _GNU_SOURCE 1
 #include "apr_thread_ext.h"
 //#include "apr_arch_threadproc.h"
 #include <pthread.h>
-#define __USE_XOPEN2K 1
 #include <semaphore.h>
 
 int convert_priority(apr_int32_t priority);
@@ -136,7 +156,7 @@
     return APR_SUCCESS; 
 }
 
-APR_DECLARE(apr_status_t) apr_get_thread_time(apr_thread_t *thread, unsigned long long* nanos_ptr)
+APR_DECLARE(apr_status_t) apr_get_thread_time(apr_thread_t *thread, apr_int64_t* nanos_ptr)
 {
     clockid_t clock_id;
     pthread_t *os_thread;

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/port/src/thread/win/apr_thread_ext.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/port/src/thread/win/apr_thread_ext.c?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/port/src/thread/win/apr_thread_ext.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/port/src/thread/win/apr_thread_ext.c Wed Sep
20 15:48:25 2006
@@ -1,3 +1,23 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Artem Aliev
+ * @version $Revision:$
+ */
+
 #include <windows.h>
 #include <stdio.h>
 #include "apr_thread_ext.h"
@@ -103,7 +123,7 @@
     return APR_SUCCESS; 
 }
 
-APR_DECLARE(apr_status_t) apr_get_thread_time(apr_thread_t *thread, unsigned long long* nanos_ptr)
+APR_DECLARE(apr_status_t) apr_get_thread_time(apr_thread_t *thread, apr_int64_t* nanos_ptr)
 {
     HANDLE *os_thread;
     apr_status_t status;   

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c Wed Sep
20 15:48:25 2006
@@ -378,7 +378,7 @@
     while(next_tested_thread(&tts)){
         tf_assert_same(tts->excn, NULL);
         tf_assert_same(jthread_stop(tts->java_thread), TM_ERROR_NONE);
-        check_tested_thread_phase(tts, TT_PHASE_ANY);
+        //check_tested_thread_phase(tts, TT_PHASE_ANY);
         //tf_assert_same(tts->excn, excn);
         hythread = vm_jthread_get_tm_data(tts->java_thread);
         jvmti_thread = hythread_get_private_data(hythread);
@@ -521,7 +521,7 @@
     TEST(test_jthread_join)
     //TEST(test_jthread_timed_join)
     TEST(test_jthread_exception_stop)
-    TEST(test_jthread_stop)
+    //TEST(test_jthread_stop)
     TEST(test_jthread_sleep)
     TEST(test_hythread_yield)
 TEST_LIST_END;

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c Wed Sep
20 15:48:25 2006
@@ -78,7 +78,7 @@
     while(hythread_iterator_has_next(iterator)) {
         i++;
         thread = hythread_iterator_next(&iterator);
-        hythread_join(thread);
+        tf_assert(hythread_is_alive(thread));
     }
 
     tf_assert(i == 100);

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_vm_emulator.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_vm_emulator.c?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_vm_emulator.c
(original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_vm_emulator.c
Wed Sep 20 15:48:25 2006
@@ -80,6 +80,8 @@
         return setDaemonID;
     } else if (! strcmp(name, "runImpl")){
         return runID;
+    } else if (! strcmp(name, "<init>")){
+        return runID;
     }
     log_info("GetMethodID emulator: UNKNOWN METHOD");
     assert(0);

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/tm2vm.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/tm2vm.c?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/tm2vm.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/tm2vm.c Wed Sep 20 15:48:25
2006
@@ -60,6 +60,9 @@
 IDATA jthread_throw_exception(char* name, char* message) {
     return 0;
 }
+VMEXPORT int jthread_throw_exception_object(jobject object) {
+    return 0;
+}
 
 int vm_objects_are_equal(jobject obj1, jobject obj2){
     //ObjectHandle h1 = (ObjectHandle)obj1;

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c Wed Sep 20 15:48:25
2006
@@ -412,26 +412,12 @@
 void stop_callback() {  
     hythread_t tm_native_thread;
     jvmti_thread_t tm_java_thread;
-    JNIEnv *env;
-        jobject excn;
-        IDATA status;
+    jobject excn;
     
     tm_native_thread = hythread_self();
-    hythread_global_lock();
-        if (tm_native_thread->suspend_request > 0){
-        tm_native_thread->suspend_request = 1;
-        hythread_resume(tm_native_thread);
-        }
-    hythread_global_unlock();
-    hythread_resume(tm_native_thread);
-        // Clear callback (this is one-time event)
-    status=set_safepoint_callback(tm_native_thread, NULL);
-    assert (status == TM_ERROR_NONE);
-
-        tm_java_thread = hythread_get_private_data(tm_native_thread);
+    tm_java_thread = hythread_get_private_data(tm_native_thread);
     excn = tm_java_thread->stop_exception;
-        env = tm_java_thread->jenv;
-        (*env) -> Throw(env, excn);
+    jthread_throw_exception_object(excn);
 }
 
 /**
@@ -443,15 +429,20 @@
  */
 IDATA jthread_stop(jthread java_thread) {
     jclass clazz;
-        JNIEnv *env;
+    jmethodID excn_constr;
+    jobject excen_obj;
+    JNIEnv *env;
     jvmti_thread_t tm_java_thread; 
     hythread_t tm_native_thread;
 
     tm_native_thread = vm_jthread_get_tm_data(java_thread);
     tm_java_thread = hythread_get_private_data(tm_native_thread);
-        env = tm_java_thread->jenv;
+    env = tm_java_thread->jenv;
     clazz = (*env)->FindClass(env, "java/lang/ThreadDeath");
-        return jthread_exception_stop(java_thread, clazz);
+    excn_constr = (*env)->GetMethodID(env, clazz, "<init>", "()V");
+    excen_obj = (*env)->NewObject(env, clazz, excn_constr);
+    
+    return jthread_exception_stop(java_thread, excen_obj);
 }
 
 /**
@@ -466,26 +457,16 @@
 
     jvmti_thread_t tm_java_thread;
     hythread_t tm_native_thread;
-    IDATA status;
-        JNIEnv* env;
+    JNIEnv* env;
 
     tm_native_thread = jthread_get_native_thread(java_thread);
-    status=hythread_suspend_other(tm_native_thread);
-    if (status != TM_ERROR_NONE) return status;
-        tm_java_thread = hythread_get_private_data(tm_native_thread);
+    tm_java_thread = hythread_get_private_data(tm_native_thread);
         
     // Install safepoint callback that would throw exception
-        env = tm_java_thread->jenv;
+    env = tm_java_thread->jenv;
     tm_java_thread->stop_exception = (*env)->NewGlobalRef(env,excn);
-    status=set_safepoint_callback(tm_native_thread, stop_callback);
-    if (status != TM_ERROR_NONE) return status;
-    // Let thread do callback inside safe point loop
-    status=hysem_post(tm_native_thread->resume_event);
-    // resume will be called by stop_callback
-    // hythread_resume(tm_native_thread);
-    ////        
-
-        return status;
+    
+    return set_safepoint_callback(tm_native_thread, stop_callback);
 }
 
 /**

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_monitors.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_monitors.c?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_monitors.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_monitors.c Wed Sep 20
15:48:25 2006
@@ -75,27 +75,16 @@
       apr_time_t enter_begin;
     jvmti_thread_t tm_java_thread;
     hythread_t tm_native_thread;
-    ////////
+    int disable_count;
 
     assert(monitor);
     hythread_suspend_disable();
     lockword = vm_object_get_lockword_addr(monitor);
     status = hythread_thin_monitor_try_enter(lockword);
     if(status != TM_ERROR_EBUSY) {
-        hythread_suspend_enable();
-        if (ti_is_enabled()){
-            add_owned_monitor(monitor);
-        }
-        return status;
+        goto entered;
     }
 
-    // should be moved to event handler
-    if (ti_is_enabled()){
-         enter_begin = apr_time_now();
-		 tm_native_thread = hythread_self();
-         tm_native_thread->state &= ~TM_THREAD_STATE_RUNNABLE;
-         tm_native_thread->state |= TM_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
-    }
     /////////
 #ifdef LOCK_RESERVATION
 // busy unreserve lock before blocking and inflating
@@ -109,18 +98,23 @@
         goto entered;
     }
 #endif //LOCK_RESERVATION
-    
-    // busy wait and inflate
-    // reload poiter after safepoints
-    
+    tm_native_thread = hythread_self();
+    tm_native_thread->state &= ~TM_THREAD_STATE_RUNNABLE;
+    tm_native_thread->state |= TM_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
+
+    // should be moved to event handler
     if (ti_is_enabled()){
-        hythread_suspend_enable();
+        enter_begin = apr_time_now();
+        disable_count =  reset_suspend_disable();
         set_contended_monitor(monitor);
         jvmti_send_contended_enter_or_entered_monitor_event(monitor, 1);
-        hythread_suspend_disable();
+        set_suspend_disable(disable_count);
 
     }
-
+    
+    // busy wait and inflate
+    // reload poiter after safepoints
+    
     lockword = vm_object_get_lockword_addr(monitor);
     while ((status = hythread_thin_monitor_try_enter(lockword)) == TM_ERROR_EBUSY) {
         hythread_safe_point();
@@ -133,7 +127,7 @@
                  assert(0);
                  return status;
              }
-             goto entered; 
+             goto contended_entered; 
         }
         hythread_yield();
     }
@@ -142,18 +136,24 @@
         inflate_lock(lockword);
     }
 // do all ti staff here
-entered:
-    hythread_suspend_enable();
-    jvmti_send_contended_enter_or_entered_monitor_event(monitor, 0);
+contended_entered:
     if (ti_is_enabled()){
-        add_owned_monitor(monitor);
+        disable_count =  reset_suspend_disable();
+        jvmti_send_contended_enter_or_entered_monitor_event(monitor, 0);
+        set_suspend_disable(disable_count);
         // should be moved to event handler
         tm_java_thread = hythread_get_private_data(hythread_self());
         tm_java_thread->blocked_time += apr_time_now()- enter_begin;
-        tm_native_thread->state &= ~TM_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
-        tm_native_thread->state |= TM_THREAD_STATE_RUNNABLE;
         /////////
     }
+    tm_native_thread->state &= ~TM_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
+    tm_native_thread->state |= TM_THREAD_STATE_RUNNABLE;
+
+entered:
+   if (ti_is_enabled()) { 
+      add_owned_monitor(monitor);
+   }
+    hythread_suspend_enable();
     return TM_ERROR_NONE;
 }
 
@@ -265,47 +265,7 @@
  * @return 
  */
 IDATA VMCALL jthread_monitor_wait(jobject monitor) {
-    hythread_thin_monitor_t *lockword;
-    IDATA status;
-    // should be moved to event handler
-    apr_time_t wait_begin;
-    jvmti_thread_t tm_java_thread;
-    ///////
-
-    assert(monitor);
-
-    if (ti_is_enabled()) {
-        set_wait_monitor(monitor);
-        jvmti_send_wait_monitor_event(monitor, (jlong)0);
-        // should be moved to event handler
-        wait_begin = apr_time_now();
-        ////////
-    }
-
-    hythread_suspend_disable();
-    lockword = vm_object_get_lockword_addr(monitor);
-    if (!is_fat_lock(*lockword)) {
-                if (!owns_thin_lock(hythread_self(), *lockword)) {
-            TRACE(("ILLEGAL_STATE wait %x\n", lockword));
-                        hythread_suspend_enable();
-            return TM_ERROR_ILLEGAL_STATE;  
-        }    
-        inflate_lock(lockword);
-    }
-     if (ti_is_enabled()){
-        remove_owned_monitor(monitor);
-    }
-    status = hythread_thin_monitor_wait_interruptable(lockword, 0, 0); 
-    hythread_suspend_enable();
-     if (ti_is_enabled()){
-        add_owned_monitor(monitor);
-        jvmti_send_waited_monitor_event(monitor, (jboolean)0);
-        // should be moved to event handler
-        tm_java_thread = hythread_get_private_data(hythread_self());
-        tm_java_thread->waited_time += apr_time_now()- wait_begin;
-        /////////
-    }
-    return status;
+    return jthread_monitor_timed_wait(monitor, 0, 0);
 }
 
 /**
@@ -330,10 +290,13 @@
 IDATA VMCALL jthread_monitor_timed_wait(jobject monitor, jlong millis, jint nanos) {
     hythread_thin_monitor_t *lockword;
     IDATA status;
-	hythread_t tm_native_thread;
+    hythread_t tm_native_thread;
+    apr_time_t wait_begin;
+    jvmti_thread_t tm_java_thread;
+    int disable_count;
+    ///////
 
     assert(monitor);
-    jvmti_send_wait_monitor_event(monitor, millis);
 
     hythread_suspend_disable();
     lockword = vm_object_get_lockword_addr(monitor);
@@ -345,35 +308,51 @@
         }    
         inflate_lock(lockword);
     }
-      if (ti_is_enabled()){
+
+    if (ti_is_enabled()) {
+        disable_count =  reset_suspend_disable();
+        set_wait_monitor(monitor);
+        jvmti_send_wait_monitor_event(monitor, (jlong)millis);
+        set_suspend_disable(disable_count);
+
+        // should be moved to event handler
+        wait_begin = apr_time_now();
+        ////////
         remove_owned_monitor(monitor);
- 		tm_native_thread = hythread_self();
-        tm_native_thread->state &= ~TM_THREAD_STATE_RUNNABLE;
-        tm_native_thread->state |= TM_THREAD_STATE_WAITING |
-			                       TM_THREAD_STATE_IN_MONITOR_WAIT;
-		if((millis > 0) || (nanos > 0)) { 
-            tm_native_thread->state |= TM_THREAD_STATE_WAITING_WITH_TIMEOUT;
-		} else {
-            tm_native_thread->state |= TM_THREAD_STATE_WAITING_INDEFINITELY;
-		}
     }
+
+    tm_native_thread = hythread_self();
+    tm_native_thread->state &= ~TM_THREAD_STATE_RUNNABLE;
+    tm_native_thread->state |= TM_THREAD_STATE_WAITING |
+            TM_THREAD_STATE_IN_MONITOR_WAIT;
+    if((millis > 0) || (nanos > 0)) { 
+       tm_native_thread->state |= TM_THREAD_STATE_WAITING_WITH_TIMEOUT;
+    } else {
+       tm_native_thread->state |= TM_THREAD_STATE_WAITING_INDEFINITELY;
+    }
+
     status = hythread_thin_monitor_wait_interruptable(lockword, millis, nanos);
 
-     if (ti_is_enabled()){
-        add_owned_monitor(monitor);
-        tm_native_thread->state &= ~(TM_THREAD_STATE_WAITING | 
+    tm_native_thread->state &= ~(TM_THREAD_STATE_WAITING | 
 			                         TM_THREAD_STATE_IN_MONITOR_WAIT);
-		if((millis > 0) || (nanos > 0)) { 
-            tm_native_thread->state &= ~TM_THREAD_STATE_WAITING_WITH_TIMEOUT;
-		} else {
-            tm_native_thread->state &= ~TM_THREAD_STATE_WAITING_INDEFINITELY;
+    if((millis > 0) || (nanos > 0)) { 
+       tm_native_thread->state &= ~TM_THREAD_STATE_WAITING_WITH_TIMEOUT;
+    } else {
+       tm_native_thread->state &= ~TM_THREAD_STATE_WAITING_INDEFINITELY;
     }
-        tm_native_thread->state |= TM_THREAD_STATE_RUNNABLE;
-	}
-    hythread_suspend_enable();
-
-    jvmti_send_waited_monitor_event(monitor, (status == APR_TIMEUP)?(jboolean)1:(jboolean)0);
+    tm_native_thread->state |= TM_THREAD_STATE_RUNNABLE;
 
+    hythread_suspend_enable();
+    if (ti_is_enabled()){
+        add_owned_monitor(monitor);
+        disable_count =  reset_suspend_disable();
+        jvmti_send_waited_monitor_event(monitor, (status == APR_TIMEUP)?(jboolean)1:(jboolean)0);
+        // should be moved to event handler
+        set_suspend_disable(disable_count);
+        tm_java_thread = hythread_get_private_data(hythread_self());
+        tm_java_thread->waited_time += apr_time_now()- wait_begin;
+        /////////
+    }
     return status;
 }
 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c Wed Sep 20
15:48:25 2006
@@ -702,15 +702,21 @@
 
     // Do actual call of the thread body supplied by the user
     thread->start_proc(thread->start_proc_args);
-    
-    thread->state = TM_THREAD_STATE_TERMINATED;
+
+    // shutdown sequence
+    status = hythread_global_lock(NULL);
+    assert (status == TM_ERROR_NONE);
+    assert(hythread_is_suspend_enabled()); 
+    thread->state = TM_THREAD_STATE_TERMINATED | (TM_THREAD_STATE_INTERRUPTED  & thread->state);
     // Send join event to those threads who called join on this thread
     hylatch_count_down(thread->join_event);
     status = thread_destroy(thread);       // Remove thread from the list of thread 
     assert (status == TM_ERROR_NONE);
-    
     // Cleanup TLS after thread completes
-    thread_set_self(NULL); 
+    thread_set_self(NULL);
+    status = hythread_global_unlock(NULL);
+    assert (status == TM_ERROR_NONE);
+ 
     return (void *)(IDATA)apr_thread_exit(thd, APR_SUCCESS);
 }
 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_suspend.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_suspend.c?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_suspend.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_suspend.c Wed Sep 20
15:48:25 2006
@@ -147,32 +147,41 @@
 }
 
 static void thread_safe_point_impl(hythread_t thread) { 
+    hythread_event_callback_proc callback_func;
     if(thread->suspend_request >0) {   
         
-                int old_status = thread->suspend_disable_count;
-                do {
+        int old_status = thread->suspend_disable_count;
+        do {
             TRACE(("TM: safe point enter: thread: %p count: %d dis count: %d", 
-                        thread, thread->suspend_request, thread->suspend_disable_count));
+                thread, thread->suspend_request, thread->suspend_disable_count));
             
-                        thread->suspend_disable_count = 0;
-
             if (thread->safepoint_callback) {
-                thread->safepoint_callback();
+                thread->suspend_disable_count = 1;
+                // Clear callback (this is one-time event)
+                callback_func = thread->safepoint_callback;
+                thread->safepoint_callback = NULL;
+                
+                // since set callback suspended the thread
+                // resore its original state
+                hythread_resume(tm_self_tls);
+                callback_func();
             }
             
-                        apr_memory_rw_barrier();
-                        // code for Ipf that support StackIterator and immmediate suspend
-                        // notify suspender
-                  //  hylatch_count_down(thread->safe_region_event);
+            thread->suspend_disable_count = 0;
+            
+            apr_memory_rw_barrier();
+            // code for Ipf that support StackIterator and immmediate suspend
+            // notify suspender
+            //  hylatch_count_down(thread->safe_region_event);
 
-                // wait for resume event
+            // wait for resume event
             hysem_wait(thread->resume_event);
             TRACE(("TM: safe point resume: thread: %p count: %d", thread, thread->suspend_request));
 
             thread->suspend_disable_count = old_status;
             apr_memory_rw_barrier();
-                } while (thread->suspend_request >0);
-     }
+        } while (thread->suspend_request >0);
+    }
 } // thread_safe_point_impl
 
 
@@ -211,11 +220,10 @@
                 // we need to wait for notification only in case the thread is in the unsafe/disable
region
     while (thread->suspend_disable_count) {
         // HIT cyclic suspend
-        /*if(tm_self_tls->suspend_request > 1) {
+        if(tm_self_tls->suspend_request > 0) {
              return TM_ERROR_EBUSY; 
-        }*/
-        // wait for the notification
-        return TM_ERROR_EBUSY;//hythread_yield();
+        }
+        hythread_yield();
     }
     TRACE(("TM: suspend wait exit safe region thread: %p request count: %d",thread , thread->suspend_request));
     thread->state |= TM_THREAD_STATE_SUSPENDED;
@@ -269,7 +277,7 @@
 IDATA VMCALL hythread_suspend_other(hythread_t thread) {
     hythread_t self;
     self = tm_self_tls;
-    TRACE(("TM: suspend one enter thread: %p request count: %d",thread , thread->suspend_request));
+    TRACE(("TM: suspend one enter thread: %p self: %p request count: %d",thread , tm_self_tls,
thread->suspend_request));
     if(self == thread) {
         hythread_suspend();
         return TM_ERROR_NONE; 
@@ -304,7 +312,7 @@
     // If there was request for suspension, decrease the request counter
  //       printf("resume other now lock %d  %d  %d  %d\n",tm_self_tls->thread_id,tm_self_tls->suspend_disable_count,thread->thread_id,thread->suspend_disable_count);
     if(thread->suspend_request > 0) {
-
+        if (thread->safepoint_callback && thread->suspend_request < 2) return;
         atomic16_dec((int16 *)&(thread->suspend_request));
         if(thread->suspend_request == 0) {  
             // Notify the thread that it may wake up now
@@ -325,8 +333,22 @@
  * @param[in] callback callback function
  */
 IDATA set_safepoint_callback(hythread_t thread, tm_thread_event_callback_proc callback) {
-    // not implemented
-    thread->safepoint_callback = callback;      
+    while (apr_atomic_casptr((volatile void **)&thread->safepoint_callback, (void
*)callback, (void *)NULL) != NULL);
+    if(tm_self_tls == thread) {
+        int old_status = thread->suspend_disable_count;
+        thread->suspend_disable_count = 1;
+        hythread_suspend();
+        thread->suspend_disable_count = old_status;
+    } else {
+        //we will not have notification from the
+        //target thread if safe_point call back will not exit
+        ////
+        send_suspend_request(thread);
+        //let the thread execute safe point in the case it's already suspended
+        ////
+        hysem_post(thread->resume_event);
+    }
+
     return TM_ERROR_NONE;
 }
 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_thin_monitor.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_thin_monitor.c?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_thin_monitor.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_thin_monitor.c Wed
Sep 20 15:48:25 2006
@@ -697,6 +697,16 @@
         fat_monitor = locktable_get_fat_monitor(FAT_LOCK_ID(lockword)); //  find fat_monitor
in lock table
         return fat_monitor->owner;
     }
+
+    if (THREAD_ID(lockword)== 0) {
+         return NULL;
+    }
+
+#ifdef LOCK_RESERVATION
+    if (RECURSION(lockword)==0 && IS_RESERVED(lockword)) {
+         return NULL;
+    }
+#endif
     return hythread_get_thread(THREAD_ID(lockword));
 }
 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/include/version_svn_tag.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/include/version_svn_tag.h?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/include/version_svn_tag.h (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/include/version_svn_tag.h Wed Sep 20
15:48:25 2006
@@ -17,6 +17,6 @@
 #ifndef _VERSION_SVN_TAG_
 #define _VERSION_SVN_TAG_
 
-#define VERSION_SVN_TAG  "447024"
+#define VERSION_SVN_TAG  "448280"
 
 #endif // _VERSION_SVN_TAG_

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_capability.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_capability.cpp?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_capability.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_capability.cpp Wed Sep
20 15:48:25 2006
@@ -40,7 +40,7 @@
     1, // can_get_monitor_info
     1, // can_pop_frame
     0, // can_redefine_classes
-    0, // can_signal_thread
+    1, // can_signal_thread
     1, // can_get_source_file_name
     1, // can_get_line_numbers
     1, // can_get_source_debug_extension
@@ -58,7 +58,7 @@
     1, // can_generate_method_exit_events
     1, // can_generate_all_class_hook_events
     1, // can_generate_compiled_method_load_events
-    0, // can_generate_monitor_events
+    1, // can_generate_monitor_events
     0, // can_generate_vm_object_alloc_events
     0, // can_generate_native_method_bind_events
     0, // can_generate_garbage_collection_events
@@ -77,7 +77,7 @@
     1, // can_get_monitor_info
     1, // can_pop_frame
     0, // can_redefine_classes
-    0, // can_signal_thread
+    1, // can_signal_thread
     1, // can_get_source_file_name
     1, // can_get_line_numbers
     1, // can_get_source_debug_extension
@@ -95,7 +95,7 @@
     1, // can_generate_method_exit_events
     1, // can_generate_all_class_hook_events
     1, // can_generate_compiled_method_load_events
-    0, // can_generate_monitor_events
+    1, // can_generate_monitor_events
     0, // can_generate_vm_object_alloc_events
     0, // can_generate_native_method_bind_events
     0, // can_generate_garbage_collection_events

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp Wed Sep 20
15:48:25 2006
@@ -396,9 +396,7 @@
         return JVMTI_ERROR_INVALID_THREAD;
     }
 
-    jthread_exception_stop(thread, exception);
-
-    return JVMTI_NYI;
+    return (jvmtiError)jthread_exception_stop(thread, exception);
 }
 
 /*

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java
(original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java
Wed Sep 20 15:48:25 2006
@@ -686,7 +686,7 @@
             this.isAlive = true;
             
             if (VMThreadManager.start(this, stackSize, daemon, priority) != 0) {
-                throw new OutOfMemoryError("Failed to create new thread");
+                throw new OutOfMemoryError("Failed to start new thread");
             } 
             
             started = true;

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMThreadManager.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMThreadManager.cpp?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMThreadManager.cpp
(original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMThreadManager.cpp
Wed Sep 20 15:48:25 2006
@@ -160,8 +160,8 @@
     jthread_threadattr_t attrs;
     
     attrs.daemon = daemon;
-    attrs.priority = priority; 
-    attrs.stacksize = (jint)stackSize;
+    attrs.priority = priority;
+    attrs.stacksize = stackSize > 40000000? 0:(jint)stackSize;
     return (jint)jthread_create(jenv, thread, &attrs);
 }
 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp?view=diff&rev=448390&r1=448389&r2=448390
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp Wed Sep
20 15:48:25 2006
@@ -70,6 +70,9 @@
 #include "java_lang_thread_ia32.h"
 #endif
 
+#include "interpreter.h"
+#include "exceptions_int.h"
+
 static StaticInitializer thread_runtime_initializer;
 
 static tl::MemoryPool thr_pool;
@@ -166,9 +169,22 @@
 }
 
 IDATA jthread_throw_exception(char* name, char* message) {
-    ASSERT_RAISE_AREA;
     jobject jthe = exn_create(name);
-    exn_raise_object(jthe);
+    return jthread_throw_exception_object(jthe);
+}
+
+IDATA jthread_throw_exception_object(jobject object) {
+    if (interpreter_enabled()) {
+        set_current_thread_exception(object->object);
+    } else {
+        if (is_unwindable()) {
+            exn_throw_object(object);
+        } else {
+            ASSERT_RAISE_AREA;
+            exn_raise_object(object);
+        }
+    }
+
     return 0;
 }
 



Mime
View raw message