harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r434076 [16/18] - in /incubator/harmony/enhanced/drlvm/trunk: build/make/components/ build/make/components/vm/ build/make/targets/ build/patches/lnx/ build/patches/lnx/APR/ build/patches/lnx/APR/threadproc/ build/patches/lnx/APR/threadproc/...
Date Wed, 23 Aug 2006 16:49:21 GMT
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?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- 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 Aug 23 09:48:41 2006
@@ -21,12 +21,10 @@
 #define LOG_DOMAIN "kernel"
 #include "cxxlog.h"
 
-#include "thread_generic.h"
-#include "object_handles.h"
-#include "mon_enter_exit.h"
-#include "open/thread.h"
-
 #include "java_lang_VMThreadManager.h"
+#include "open/hythread_ext.h"
+#include "open/jthread.h"
+#include "open/thread_externals.h"
 
 /*
  * Class:     java_lang_VMThreadManager
@@ -34,9 +32,9 @@
  * Signature: ()Ljava/lang/Thread;
  */
 JNIEXPORT jobject JNICALL Java_java_lang_VMThreadManager_currentThread
-  (JNIEnv * UNREF jenv, jclass)
+  (JNIEnv * UNREF jenv, jclass clazz)
 {
-    return thread_current_thread();
+    return jthread_self();
 }
 
 /*
@@ -45,31 +43,20 @@
  * Signature: (Ljava/lang/Object;)Z
  */
 JNIEXPORT jboolean JNICALL Java_java_lang_VMThreadManager_holdsLock
-  (JNIEnv * UNREF jenv, jclass, jobject lock)
+  (JNIEnv * UNREF jenv, jclass clazz, jobject monitor)
 {
-    //ToDo: the following code will be used.
-    //return thread_holds_lock(thread_current_thread(), lock);
-
-    VM_thread * vm_thread = get_thread_ptr();
-    tmn_suspend_disable();       //---------------------------------v
-
-    ManagedObject *p_obj = (ManagedObject *)(((ObjectHandle)lock)->object);
-    uint16 stack_key = STACK_KEY(p_obj);
-
-    tmn_suspend_enable();        //---------------------------------^
-
-    return (jboolean)((vm_thread -> thread_index == stack_key) ? JNI_TRUE : JNI_FALSE);
+    return false;//jthread_holds_lock(jthread_self(), monitor);
 }
 
 /*
  * Class:     java_lang_VMThreadManager
  * Method:    interrupt
- * Signature: (Ljava/lang/Thread;)V
+ * Signature: (Ljava/lang/Thread;)I
  */
-JNIEXPORT void JNICALL Java_java_lang_VMThreadManager_interrupt
-  (JNIEnv * UNREF jenv, jclass, jobject jthread)
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_interrupt
+  (JNIEnv * UNREF jenv, jclass clazz, jobject jthread)
 {
-    thread_interrupt(jthread);
+    return jthread_interrupt(jthread);
 }
 
 /*
@@ -78,10 +65,9 @@
  * Signature: ()Z
  */
 JNIEXPORT jboolean JNICALL Java_java_lang_VMThreadManager_isInterrupted__
-  (JNIEnv * UNREF jenv, jclass)
+  (JNIEnv * UNREF jenv, jclass clazz)
 {
-    jobject thread = thread_current_thread();
-    return thread_is_interrupted(thread, JNI_TRUE);
+    return jthread_is_interrupted(jthread_self());
 }
 
 /*
@@ -90,198 +76,193 @@
  * Signature: (Ljava/lang/Thread;)Z
  */
 JNIEXPORT jboolean JNICALL Java_java_lang_VMThreadManager_isInterrupted__Ljava_lang_Thread_2
-  (JNIEnv * UNREF jenv, jclass, jobject jthread)
+  (JNIEnv * UNREF jenv, jclass clazz, jobject thread)
 {
-    return thread_is_interrupted(jthread, JNI_FALSE);
+    return jthread_is_interrupted(thread);
 }
 
 /*
  * Class:     java_lang_VMThreadManager
  * Method:    notify
- * Signature: (Ljava/lang/Object;)V
+ * Signature: (Ljava/lang/Object;)I
  */
-JNIEXPORT void JNICALL Java_java_lang_VMThreadManager_notify
-  (JNIEnv * UNREF jenv, jclass, jobject obj)
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_notify
+  (JNIEnv * UNREF jenv, jclass clazz, jobject monitor)
 {
-    thread_object_notify(obj);
+    return jthread_monitor_notify(monitor);
 }
 
 /*
  * Class:     java_lang_VMThreadManager
  * Method:    notifyAll
- * Signature: (Ljava/lang/Object;)V
+ * Signature: (Ljava/lang/Object;)I
  */
-JNIEXPORT void JNICALL Java_java_lang_VMThreadManager_notifyAll
-  (JNIEnv * UNREF jenv, jclass, jobject obj)
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_notifyAll
+  (JNIEnv * UNREF jenv, jclass clazz, jobject monitor)
 {
-    thread_object_notify_all(obj);
+    return jthread_monitor_notify_all(monitor);
 }
 
 /*
  * Class:     java_lang_VMThreadManager
  * Method:    resume
- * Signature: (Ljava/lang/Thread;)V
+ * Signature: (Ljava/lang/Thread;)I
  */
-JNIEXPORT void JNICALL Java_java_lang_VMThreadManager_resume
-  (JNIEnv * UNREF jenv, jclass, jobject jthread)
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_resume
+  (JNIEnv * UNREF jenv, jclass clazz, jobject thread)
 {
-    thread_resume(jthread);
+    return jthread_resume(thread);
 }
 
 /*
  * Class:     java_lang_VMThreadManager
  * Method:    setPriority
- * Signature: (Ljava/lang/Thread;I)V
+ * Signature: (Ljava/lang/Thread;I)I
  */
-JNIEXPORT void JNICALL Java_java_lang_VMThreadManager_setPriority
-  (JNIEnv * UNREF jenv, jclass, jobject UNREF jthread, jint UNREF priority)
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_setPriority
+  (JNIEnv * UNREF jenv, jclass clazz, jobject UNREF thread, jint UNREF priority)
 {
-    //ToDo: the following code will be used.
-    //thread_set_priority(jthread, priority);
+    return jthread_set_priority(thread, priority);
 }
 
 /*
  * Class:     java_lang_VMThreadManager
  * Method:    sleep
+ * Signature: (JI)I
+ */
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_sleep
+  (JNIEnv * UNREF jenv, jclass clazz, jlong millis, jint nanos)
+{
+    return jthread_sleep(millis, nanos); 
+}
+
+/*
+ * Class:     java_lang_VMThreadManager
+ * Method:    init
  * Signature: (JI)V
  */
-JNIEXPORT void JNICALL Java_java_lang_VMThreadManager_sleep
-  (JNIEnv * UNREF jenv, jclass, jlong millis, jint nanos)
+JNIEXPORT jlong JNICALL Java_java_lang_VMThreadManager_init
+  (JNIEnv *jenv, jclass clazz, jobject thread, jobject ref, jlong oldThread)
 {
-#if defined (__INTEL_COMPILER)   // intel compiler
-  #pragma warning( push )
-  #pragma warning (disable:1682) // explicit conversion of a 64-bit integral type to a smaller integral type
-#elif defined (_MSC_VER)  // MS compiler
-  #pragma warning( push )
-  #pragma warning (disable:4244) // conversion from 'jlong' to 'long', possible loss of data
-#endif
-
-    thread_sleep(thread_current_thread(), millis, nanos); 
-
-#if defined (__INTEL_COMPILER) || defined (_MSC_VER)
- #pragma warning( pop )
-#endif
+    return jthread_thread_init(NULL, jenv, thread, ref, oldThread);
 }
 
 /*
  * Class:     java_lang_VMThreadManager
  * Method:    start
- * Signature: (Ljava/lang/Thread;J)V
+ * Signature: (Ljava/lang/Thread;JZI)I
  */
-JNIEXPORT void JNICALL Java_java_lang_VMThreadManager_start
-  (JNIEnv *jenv, jclass, jobject thread, jlong UNREF stackSize)
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_start
+  (JNIEnv *jenv, jclass clazz, jobject thread, jlong stackSize, jboolean daemon, jint priority)
 {
-    thread_start(jenv, thread);
+    jthread_threadattr_t attrs;
+    attrs.daemon = daemon;
+    attrs.priority = priority; 
+    attrs.stacksize = (jint)stackSize;
+    return (jint)jthread_create(jenv, thread, &attrs);
 }
 
 /*
  * Class:     java_lang_VMThreadManager
  * Method:    stop
- * Signature: (Ljava/lang/Thread;Ljava/lang/Throwable;)V
+ * Signature: (Ljava/lang/Thread;Ljava/lang/Throwable;)I
  */
-JNIEXPORT void JNICALL Java_java_lang_VMThreadManager_stop
-  (JNIEnv *, jclass, jobject UNREF thread, jthrowable UNREF threadDeathException)
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_stop
+  (JNIEnv *env, jclass clazz, jobject UNREF thread, jthrowable UNREF threadDeathException)
 {
-    //ToDo: the following code will be used.
-    //thread_stop(thread, threadDeathException);
+    return jthread_exception_stop(thread, threadDeathException);
 }
 
 /*
  * Class:     java_lang_VMThreadManager
  * Method:    suspend
- * Signature: (Ljava/lang/Thread;)V
+ * Signature: (Ljava/lang/Thread;)I
  */
-JNIEXPORT void JNICALL Java_java_lang_VMThreadManager_suspend
-  (JNIEnv * UNREF jenv, jclass, jobject jthread)
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_suspend
+  (JNIEnv * UNREF jenv, jclass clazz, jobject jthread)
 {
-    thread_suspend(jthread);
+    return jthread_suspend(jthread);
 }
 
 
 /*
  * Class:     java_lang_VMThreadManager
  * Method:    wait
- * Signature: (Ljava/lang/Object;JI)V
+ * Signature: (Ljava/lang/Object;JI)I
  */
-JNIEXPORT void JNICALL Java_java_lang_VMThreadManager_wait
-  (JNIEnv *, jclass, jobject object, jlong millis, jint nanos)
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_wait
+  (JNIEnv *env, jclass clazz, jobject monitor, jlong millis, jint UNREF nanos)
 {
-    thread_object_wait_nanos (object, millis, nanos);
+    return jthread_monitor_timed_wait(monitor, millis, nanos);
 }
 
 /*
  * Class:     java_lang_VMThreadManager
  * Method:    yield
- * Signature: ()V
+ * Signature: ()I
  */
-JNIEXPORT void JNICALL Java_java_lang_VMThreadManager_yield
-  (JNIEnv * UNREF jenv, jclass)
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_yield
+  (JNIEnv * UNREF jenv, jclass clazz)
 {
-    //ToDo: the following code will be used.
-    //thread_yield(thread_current_thread());
+    return jthread_yield();
+}
 
-    SleepEx(0, false);
+/*
+ * Class:     java_lang_VMThreadManager
+ * Method:    attach
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_VMThreadManager_attach
+  (JNIEnv * UNREF jenv, jclass clazz, jobject java_thread)
+{
+    jthread_attach(jenv, java_thread);
 }
 
 /*
  * Class:     java_lang_VMThreadManager
- * Method:    isDead
+ * Method:    isAlive
  * Signature: (Ljava/lang/Thread;)Z
  */
-JNIEXPORT jboolean JNICALL Java_java_lang_VMThreadManager_isDead
-  (JNIEnv *jenv, jclass, jobject thread)
+JNIEXPORT jboolean JNICALL Java_java_lang_VMThreadManager_isAlive
+  (JNIEnv *jenv, jclass clazz, jobject thread)
 {
-    //return ! thread_is_alive(thread);
+    hythread_t tm_native_thread;
 
-    VM_thread *p_vmthread = get_vm_thread_ptr_safe(jenv, thread);
-    if ( !p_vmthread ) {
-        return 1; // don't try to isAlive() non-existant thread
-    }   
-    
-    java_state as = p_vmthread->app_status;  
-    // According to JAVA spec, this method should return true, if and
-    // only if the thread has been died. 
-    switch (as) {
-        case thread_is_sleeping:
-        case thread_is_waiting:
-        case thread_is_timed_waiting:
-        case thread_is_blocked:
-        case thread_is_running:
-        case thread_is_birthing:
-            return 0; 
-            //break;
-        case thread_is_dying:
-        case zip:
-            return 1; 
-            //break;
-        default:
-            ABORT("Unexpected thread state");
-            return 1;
-            //break;
+    tm_native_thread = (hythread_t )vm_jthread_get_tm_data((jthread)thread);
+    assert(tm_native_thread);
+    if (hythread_is_alive(tm_native_thread))
+    { 
+        printf("isAlive\n");
+        return true;
     }
-    // must return from inside the switch statement //remark #111: statement is unreachable
+        printf ("isnot\n");
+    return false;
 }
 
 /*
  * Class:     java_lang_VMThreadManager
  * Method:    join
- * Signature: (Ljava/lang/Thread;JI)V
+ * Signature: (Ljava/lang/Thread;JI)I
  */
-JNIEXPORT void JNICALL Java_java_lang_VMThreadManager_join
-  (JNIEnv * UNREF jenv, jclass, jobject thread, jlong millis, jint nanos)
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_join
+  (JNIEnv * UNREF jenv, jclass clazz, jobject thread, jlong millis, jint nanos)
 {
-#if defined (__INTEL_COMPILER)   // intel compiler
-  #pragma warning( push )
-  #pragma warning (disable:1682) // explicit conversion of a 64-bit integral type to a smaller integral type
-#elif defined (_MSC_VER)  // MS compiler
-  #pragma warning( push )
-  #pragma warning (disable:4244) // conversion from 'jlong' to 'long', possible loss of data
-#endif
-
-    thread_join(thread, millis, nanos);
-
-#if defined (__INTEL_COMPILER) || defined (_MSC_VER)
-#pragma warning( pop )
-#endif
+    return jthread_timed_join(thread, millis, nanos);
 }
 
+
+
+/*
+ * Class:     java_lang_VMThreadManager
+ * Method:    yield
+ * Signature: ()I
+ */
+
+/*
+ * ????
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_initVMThreadManager
+  (JNIEnv * UNREF jenv, jclass clazz)
+{
+    return hythread_init();
+}
+*/

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMThreadManager.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMThreadManager.h?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMThreadManager.h (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMThreadManager.h Wed Aug 23 09:48:41 2006
@@ -13,11 +13,10 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
-/** 
+/**
  * @author Andrey Chernyshev
- * @version $Revision: 1.1.2.1.4.5 $
- */  
+ * @version $Revision: 1.1.2.1.2.2 $
+ */
 
 /*
  * THE FILE HAS BEEN AUTOGENERATED BY INTEL IJH TOOL.
@@ -26,150 +25,132 @@
  */
 
 #include <jni.h>
-
-
 /* Header for class java.lang.VMThreadManager */
 
 #ifndef _JAVA_LANG_VMTHREADMANAGER_H
 #define _JAVA_LANG_VMTHREADMANAGER_H
-
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-
 /* Native methods */
 
 /*
- * Method: java.lang.VMThreadManager.countStackFrames(Ljava/lang/Thread;)I
- */
-JNIEXPORT jint JNICALL
-Java_java_lang_VMThreadManager_countStackFrames(JNIEnv *, jclass, 
-    jobject);
-
-/*
  * Method: java.lang.VMThreadManager.currentThread()Ljava/lang/Thread;
  */
-JNIEXPORT jobject JNICALL
-Java_java_lang_VMThreadManager_currentThread(JNIEnv *, jclass);
+JNIEXPORT jobject JNICALL Java_java_lang_VMThreadManager_currentThread
+    (JNIEnv *, jclass);
 
 /*
  * Method: java.lang.VMThreadManager.holdsLock(Ljava/lang/Object;)Z
  */
-JNIEXPORT jboolean JNICALL
-Java_java_lang_VMThreadManager_holdsLock(JNIEnv *, jclass, 
-    jobject);
+JNIEXPORT jboolean JNICALL Java_java_lang_VMThreadManager_holdsLock
+    (JNIEnv *, jclass, jobject);
 
 /*
- * Method: java.lang.VMThreadManager.interrupt(Ljava/lang/Thread;)V
+ * Method: java.lang.VMThreadManager.interrupt(Ljava/lang/Thread;)I
  */
-JNIEXPORT void JNICALL
-Java_java_lang_VMThreadManager_interrupt(JNIEnv *, jclass, 
-    jobject);
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_interrupt
+    (JNIEnv *, jclass, jobject);
 
 /*
- * Method: java.lang.VMThreadManager.isDead(Ljava/lang/Thread;)Z
+ * Method: java.lang.VMThreadManager.isInterrupted()Z
  */
-JNIEXPORT jboolean JNICALL
-Java_java_lang_VMThreadManager_isDead(JNIEnv *, jclass, 
-    jobject);
+JNIEXPORT jboolean JNICALL Java_java_lang_VMThreadManager_isInterrupted__
+    (JNIEnv *, jclass);
 
 /*
- * Method: java.lang.VMThreadManager.isInterrupted()Z
+ * Method: java.lang.VMThreadManager.isInterrupted(Ljava/lang/Thread;)Z
  */
-JNIEXPORT jboolean JNICALL
-Java_java_lang_VMThreadManager_isInterrupted__(JNIEnv *, jclass);
+JNIEXPORT jboolean JNICALL Java_java_lang_VMThreadManager_isInterrupted__Ljava_lang_Thread_2
+    (JNIEnv *, jclass, jobject);
 
 /*
- * Method: java.lang.VMThreadManager.isInterrupted(Ljava/lang/Thread;)Z
+ * Method: java.lang.VMThreadManager.notify(Ljava/lang/Object;)I
  */
-JNIEXPORT jboolean JNICALL
-Java_java_lang_VMThreadManager_isInterrupted__Ljava_lang_Thread_2(JNIEnv *, jclass, 
-    jobject);
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_notify
+    (JNIEnv *, jclass, jobject);
 
 /*
- * Method: java.lang.VMThreadManager.join(Ljava/lang/Thread;JI)V
- * Throws: java.lang.InterruptedException
+ * Method: java.lang.VMThreadManager.notifyAll(Ljava/lang/Object;)I
  */
-JNIEXPORT void JNICALL
-Java_java_lang_VMThreadManager_join(JNIEnv *, jclass, 
-    jobject, jlong, jint);
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_notifyAll
+    (JNIEnv *, jclass, jobject);
 
 /*
- * Method: java.lang.VMThreadManager.notify(Ljava/lang/Object;)V
+ * Method: java.lang.VMThreadManager.resume(Ljava/lang/Thread;)I
  */
-JNIEXPORT void JNICALL
-Java_java_lang_VMThreadManager_notify(JNIEnv *, jclass, 
-    jobject);
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_resume
+    (JNIEnv *, jclass, jobject);
 
 /*
- * Method: java.lang.VMThreadManager.notifyAll(Ljava/lang/Object;)V
+ * Method: java.lang.VMThreadManager.setPriority(Ljava/lang/Thread;I)I
  */
-JNIEXPORT void JNICALL
-Java_java_lang_VMThreadManager_notifyAll(JNIEnv *, jclass, 
-    jobject);
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_setPriority
+    (JNIEnv *, jclass, jobject, jint);
 
 /*
- * Method: java.lang.VMThreadManager.resume(Ljava/lang/Thread;)V
+ * Method: java.lang.VMThreadManager.sleep(JI)I
  */
-JNIEXPORT void JNICALL
-Java_java_lang_VMThreadManager_resume(JNIEnv *, jclass, 
-    jobject);
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_sleep
+    (JNIEnv *, jclass, jlong, jint);
 
 /*
- * Method: java.lang.VMThreadManager.setPriority(Ljava/lang/Thread;I)V
+ * Method: java.lang.VMThreadManager.start(Ljava/lang/Thread;JZI)I
  */
-JNIEXPORT void JNICALL
-Java_java_lang_VMThreadManager_setPriority(JNIEnv *, jclass, 
-    jobject, jint);
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_start
+    (JNIEnv *, jclass, jobject, jlong, jboolean, jint);
 
 /*
- * Method: java.lang.VMThreadManager.sleep(JI)V
- * Throws: java.lang.InterruptedException
+ * Method: java.lang.VMThreadManager.stop(Ljava/lang/Thread;Ljava/lang/Throwable;)I
  */
-JNIEXPORT void JNICALL
-Java_java_lang_VMThreadManager_sleep(JNIEnv *, jclass, 
-    jlong, jint);
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_stop
+    (JNIEnv *, jclass, jobject, jthrowable);
 
 /*
- * Method: java.lang.VMThreadManager.start(Ljava/lang/Thread;J)V
+ * Method: java.lang.VMThreadManager.suspend(Ljava/lang/Thread;)I
  */
-JNIEXPORT void JNICALL
-Java_java_lang_VMThreadManager_start(JNIEnv *, jclass, 
-    jobject, jlong);
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_suspend
+    (JNIEnv *, jclass, jobject);
 
 /*
- * Method: java.lang.VMThreadManager.stop(Ljava/lang/Thread;Ljava/lang/Throwable;)V
+ * Method: java.lang.VMThreadManager.wait(Ljava/lang/Object;JI)I
  */
-JNIEXPORT void JNICALL
-Java_java_lang_VMThreadManager_stop(JNIEnv *, jclass, 
-    jobject, jthrowable);
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_wait
+    (JNIEnv *, jclass, jobject, jlong, jint);
 
 /*
- * Method: java.lang.VMThreadManager.suspend(Ljava/lang/Thread;)V
+ * Method: java.lang.VMThreadManager.yield()I
  */
-JNIEXPORT void JNICALL
-Java_java_lang_VMThreadManager_suspend(JNIEnv *, jclass, 
-    jobject);
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_yield
+    (JNIEnv *, jclass);
 
 /*
- * Method: java.lang.VMThreadManager.wait(Ljava/lang/Object;JI)V
- * Throws: java.lang.InterruptedException
+ * Method: java.lang.VMThreadManager.attach()V
  */
-JNIEXPORT void JNICALL
-Java_java_lang_VMThreadManager_wait(JNIEnv *, jclass, 
-    jobject, jlong, jint);
+JNIEXPORT void JNICALL Java_java_lang_VMThreadManager_attach
+    (JNIEnv *, jclass, jobject);
+
 
 /*
- * Method: java.lang.VMThreadManager.yield()V
+ * Method: java.lang.VMThreadManager.isDead(Ljava/lang/Thread;)Z
  */
-JNIEXPORT void JNICALL
-Java_java_lang_VMThreadManager_yield(JNIEnv *, jclass);
+JNIEXPORT jboolean JNICALL Java_java_lang_VMThreadManager_isAlive
+    (JNIEnv *, jclass, jobject);
 
+/*
+ * Method: java.lang.VMThreadManager.join(Ljava/lang/Thread;JI)I
+ * Throws: java.lang.InterruptedException
+ */
+JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_join
+    (JNIEnv *, jclass, jobject, jlong, jint);
 
+/*
+ * Method: java.lang.VMThreadManager.init(Ljava/lang/Thread;)V
+ */
+JNIEXPORT jlong JNICALL Java_java_lang_VMThreadManager_init
+    (JNIEnv *, jclass, jobject, jobject, jlong);
 #ifdef __cplusplus
 }
 #endif
-
-#endif /* _JAVA_LANG_VMTHREADMANAGER_H */
-
+#endif

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_util_concurrent_locks_LockSupport.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_util_concurrent_locks_LockSupport.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_util_concurrent_locks_LockSupport.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_util_concurrent_locks_LockSupport.cpp Wed Aug 23 09:48:41 2006
@@ -21,22 +21,21 @@
 #include "thread_generic.h"
 #include "java_util_concurrent_locks_LockSupport.h"
 #include "jni.h"
-
+#include "open/jthread.h"
 
 /* Inaccessible static: parked */
 /*
  * Method: java.util.concurrent.locks.LockSupport.unpark(Ljava/lang/Thread;)V
  */
 JNIEXPORT void JNICALL Java_java_util_concurrent_locks_LockSupport_unpark (JNIEnv *jenv, jclass, jobject thread) {
-    if (!thread) return;
-    unpark(get_vm_thread_ptr_safe(jenv, thread));
+    jthread_unpark(thread);
 }
 
 /*
  * Method: java.util.concurrent.locks.LockSupport.park()V
  */
 JNIEXPORT void JNICALL Java_java_util_concurrent_locks_LockSupport_park (JNIEnv * UNREF jenv, jclass) {
-    park();
+    jthread_park();
 }
 
 /*
@@ -49,7 +48,7 @@
 #endif
 
 JNIEXPORT void JNICALL Java_java_util_concurrent_locks_LockSupport_parkNanos(JNIEnv * UNREF jenv, jclass, jlong nanos) {
-    parktimed(nanos/((jlong)1000000), (jint)(nanos%((jlong)1000000)));
+    jthread_timed_park(0,(jint)nanos);
 }
 
 #if defined (__INTEL_COMPILER)
@@ -60,6 +59,7 @@
  * Method: java.util.concurrent.locks.LockSupport.parkUntil(J)V
  */
 JNIEXPORT void JNICALL Java_java_util_concurrent_locks_LockSupport_parkUntil(JNIEnv * UNREF jenv, jclass UNREF thread, jlong milis) {
-    parkuntil(milis, 0);
+    //FIXME integration should be parkUntil
+    jthread_timed_park((jlong)milis, 0);
 }
 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.cpp Wed Aug 23 09:48:41 2006
@@ -29,7 +29,6 @@
 #define LOG_DOMAIN "kernel.stack"
 #include "cxxlog.h"
 
-#include "open/thread.h"
 #include "stack_trace.h"
 #include "jni_direct.h"
 #include "jni_utils.h"
@@ -61,7 +60,7 @@
     if (!res) return NULL;
 
     // obtain and return class of the frame
-    assert(tmn_is_suspend_enabled());
+    assert(hythread_is_suspend_enabled());
     return struct_Class_to_jclass((Class*)method_get_class(frame.method));
 }
 
@@ -128,7 +127,7 @@
     unsigned maxSize = signedMaxSize;
 
 
-    assert(tmn_is_suspend_enabled());
+    assert(hythread_is_suspend_enabled());
     unsigned size;
     StackTraceFrame* frames;
     st_get_trace(&size, &frames);
@@ -152,7 +151,7 @@
         length ++;
     }
 
-    assert(tmn_is_suspend_enabled());
+    assert(hythread_is_suspend_enabled());
 
     jclass ste = struct_Class_to_java_lang_Class_Handle(VM_Global_State::loader_env->JavaLangClass_Class);
     assert(ste);
@@ -162,7 +161,7 @@
     if (arr == NULL) {
         // OutOfMemoryError
         core_free(frames);
-        assert(tmn_is_suspend_enabled());
+        assert(hythread_is_suspend_enabled());
         return NULL;
     }
 
@@ -183,7 +182,7 @@
     }
 
     core_free(frames);
-    assert(tmn_is_suspend_enabled());
+    assert(hythread_is_suspend_enabled());
     return arr;
 }
 
@@ -282,16 +281,18 @@
             }
         }
     }
+    // skip Thread.runImpl()
+    size--;
 
     // skip the VMStart$MainThread if one exits from the bottom of the stack
     // along with 2 reflection frames used to invoke method main
     static String* starter_String = genv->string_pool.lookup("java/lang/VMStart$MainThread");
-    Method_Handle method = frames[size-1].method;
+    Method_Handle method = frames[size].method;
     assert(method);
     // skip only for main application thread
-    if (!strcmp(method_get_name(method), "run")
+    if (!strcmp(method_get_name(method), "runImpl")
         && method->get_class()->name == starter_String) {
-        int rem = size - skip;
+        int rem = size - skip-1;
         size -= rem < 3 ? rem : 3;
     }
 
@@ -299,7 +300,7 @@
         << " frames but there are only "
         << size << " frames in stack");
     
-    assert(tmn_is_suspend_enabled());
+    assert(hythread_is_suspend_enabled());
     jclass ste = struct_Class_to_java_lang_Class_Handle(genv->java_lang_StackTraceElement_Class);
     assert(ste);
 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/object/object_handles.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/object/object_handles.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/object/object_handles.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/object/object_handles.cpp Wed Aug 23 09:48:41 2006
@@ -32,7 +32,7 @@
 #include "object_handles.h"
 #include "vm_stats.h"
 #include "vm_threads.h"
-#include "open/thread.h"
+
 #include "thread_manager.h"
 #include "open/types.h"
 #include "open/vm_util.h"
@@ -66,7 +66,7 @@
 
 GcFrame::GcFrame(unsigned size_hint)
 {
-    assert(!tmn_is_suspend_enabled());
+    assert(!hythread_is_suspend_enabled());
 
     if (size_hint>0)
         nodes = gc_frame_node_new(size_hint);
@@ -78,7 +78,7 @@
 
 GcFrame::~GcFrame()
 {
-    assert(!tmn_is_suspend_enabled());
+    assert(!hythread_is_suspend_enabled());
 
     assert(p_TLS_vmthread->gc_frames==this);
     p_TLS_vmthread->gc_frames = next;
@@ -97,7 +97,7 @@
     assert(p);
     assert(NULL == *p || (*p >= vm_heap_base_address()
         && *p < vm_heap_ceiling_address()));
-    assert(!tmn_is_suspend_enabled());
+    assert(!hythread_is_suspend_enabled());
 
     ensure_capacity();
     nodes->elements[nodes->obj_size+nodes->mp_size] = nodes->elements[nodes->obj_size];
@@ -107,7 +107,7 @@
 
 void GcFrame::add_managed_pointer(ManagedPointer* p)
 {
-    assert(!tmn_is_suspend_enabled());
+    assert(!hythread_is_suspend_enabled());
 
     ensure_capacity();
     nodes->elements[nodes->obj_size+nodes->mp_size] = (void**)p;
@@ -156,13 +156,13 @@
 
 bool
 managed_object_is_java_lang_class(ManagedObject* p_obj) {
-    assert(!tmn_is_suspend_enabled());
+    assert(!hythread_is_suspend_enabled());
     return managed_object_is_java_lang_class_unsafe(p_obj);
 }
 
 bool
 object_is_java_lang_class(ObjectHandle oh) {
-    assert(tmn_is_suspend_enabled());
+    assert(hythread_is_suspend_enabled());
     tmn_suspend_disable();
     bool res = managed_object_is_java_lang_class_unsafe(oh->object);
     tmn_suspend_enable();
@@ -178,13 +178,13 @@
 
 bool
 managed_object_is_valid(ManagedObject* p_obj) {
-    assert(!tmn_is_suspend_enabled());
+    assert(!hythread_is_suspend_enabled());
     return managed_object_object_is_valid_unsafe(p_obj);
 }
 
 bool
 object_is_valid(ObjectHandle oh) {
-    assert(tmn_is_suspend_enabled());
+    assert(hythread_is_suspend_enabled());
     tmn_suspend_disable();
     bool res = managed_object_object_is_valid_unsafe(oh->object);
     tmn_suspend_enable();
@@ -199,25 +199,22 @@
 
 ObjectHandle oh_allocate_global_handle()
 {
-    assert(tmn_is_suspend_enabled());
 
     // Allocate and init handle
     ObjectHandlesOld* h = oh_allocate_object_handle(); //(ObjectHandlesOld*)m_malloc(sizeof(ObjectHandlesOld));
     h->handle.object = NULL;
     h->allocated_on_the_stack = false;
     
-    tm_acquire_tm_lock();
- 
     tmn_suspend_disable(); // ----------------vvv
+    p_handle_lock->_lock(); 
     // Insert at beginning of globals list
     h->prev = NULL;
     h->next = global_object_handles;
     global_object_handles = h;
     if(h->next)
         h->next->prev = h;
+    p_handle_lock->_unlock();
     tmn_suspend_enable(); //--------------------------------------------^^^
-    tm_release_tm_lock();
-
     return &h->handle;
 } //vm_create_global_object_handle
 
@@ -230,10 +227,8 @@
 
 void oh_deallocate_global_handle(ObjectHandle handle)
 {
-    assert(tmn_is_suspend_enabled());
-
-    tm_acquire_tm_lock();
     tmn_suspend_disable(); // ----------vvv
+    p_handle_lock->_lock();
     assert(is_global_handle(handle));
 
     handle->object = NULL;
@@ -242,9 +237,8 @@
     if (h->prev) h->prev->next = h->next;
     if (h==global_object_handles) global_object_handles = h->next;
 
+    p_handle_lock->_unlock();
     tmn_suspend_enable(); // -------------------------------------^^^
-    tm_release_tm_lock();
-
     STD_FREE(h);
 } //vm_delete_global_object_handle
 
@@ -289,7 +283,7 @@
 {
     // the function should be called only from suspend disabled mode
     // as it is not gc safe.
-    assert(!tmn_is_suspend_enabled());
+    assert(!hythread_is_suspend_enabled());
     ObjectHandlesNew* cur = (ObjectHandlesNew*)*hs;
     if (!cur || cur->size>=cur->capacity)
         cur = oh_add_new_handles((ObjectHandlesNew**)hs);
@@ -356,9 +350,9 @@
 VMEXPORT // temporary solution for interpreter unplug
 ObjectHandle oh_allocate_local_handle()
 {
-    assert(!tmn_is_suspend_enabled());
+    assert(!hythread_is_suspend_enabled());
     // FIXME: it looks like this should be uncoment or suspend_disable added 
-       //assert(!tmn_is_suspend_enabled());
+       //assert(!hythread_is_suspend_enabled());
        
        
     // ? 20021202 There are really 3 cases to check: 
@@ -385,7 +379,7 @@
 }
 
 ObjectHandle oh_convert_to_local_handle(ManagedObject* pointer) {
-    assert(!tmn_is_suspend_enabled());
+    assert(!hythread_is_suspend_enabled());
     ObjectHandle jobj = oh_allocate_local_handle();
     TRACE2("oh", "oh_convert_to_local_handle() pointer = " << pointer << ", handle = " << jobj);
     jobj->object = pointer;

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/object/vm_arrays.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/object/vm_arrays.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/object/vm_arrays.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/object/vm_arrays.cpp Wed Aug 23 09:48:41 2006
@@ -33,7 +33,7 @@
 #include "vm_arrays.h"
 #include "vm_synch.h"
 #include "open/vm_util.h"
-#include "open/thread.h"
+
 #include "vm_stats.h"
 
 
@@ -78,7 +78,7 @@
 #ifdef VM_STATS
     vm_stats_total.num_anewarray++;  
 #endif
-    assert(!tmn_is_suspend_enabled());
+    assert(!hythread_is_suspend_enabled());
     assert(!arr_clss->is_array_of_primitives);
 
     if (length < 0) {
@@ -128,7 +128,7 @@
 
 VMEXPORT // temporary solution for interpreter unplug
 Vector_Handle vm_new_vector_primitive(Class *vector_class, int length) {
-    assert(!tmn_is_suspend_enabled());
+    assert(!hythread_is_suspend_enabled());
     // VM does not support arrays of length >= MAXINT>>2
     if (length & TWO_HIGHEST_BITS_SET_MASK) {
         tmn_suspend_enable();
@@ -202,7 +202,7 @@
 
 Vector_Handle vm_new_vector_using_vtable_and_thread_pointer(Allocation_Handle vector_handle, int length, void *tp)
 {
-    assert( ! tmn_is_suspend_enabled());
+    assert( ! hythread_is_suspend_enabled());
     // VM does not support arrays of length >= MAXINT>>2
     if (length & TWO_HIGHEST_BITS_SET_MASK) {
         tmn_suspend_enable();
@@ -222,9 +222,9 @@
     vector_vtable->clss->num_allocations++;
     vector_vtable->clss->num_bytes_allocated += sz;
 #endif //VM_STATS
-    assert( ! tmn_is_suspend_enabled());
+    assert( ! hythread_is_suspend_enabled());
     Vector_Handle vector = (Vector_Handle)gc_alloc(sz, vector_handle, tp);
-    assert( ! tmn_is_suspend_enabled());
+    assert( ! hythread_is_suspend_enabled());
     
     if (NULL == vector) {
         exn_throw(
@@ -275,7 +275,7 @@
                              int      *dims_array,
                              unsigned  dims)
 {
-    assert(!tmn_is_suspend_enabled());
+    assert(!hythread_is_suspend_enabled());
     Global_Env *global_env = VM_Global_State::loader_env;
     int length = *dims_array;
     assert(length >= 0);
@@ -289,7 +289,7 @@
         // Allocate an array of arrays.
         volatile Vector_Handle object_array =
             (Vector_Handle) vm_new_vector(c, length);
-        assert(!tmn_is_suspend_enabled());
+        assert(!hythread_is_suspend_enabled());
         // Alexei
         // Since this function is called from a managed code
         // generated by JIT and this is a native code,
@@ -353,7 +353,7 @@
 #ifdef VM_STATS
     vm_stats_total.num_multianewarray++;  
 #endif
-    assert(!tmn_is_suspend_enabled());
+    assert(!hythread_is_suspend_enabled());
 
     const unsigned max_dims = 100;
     int dims_array[max_dims];

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/reflection/reflection.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/reflection/reflection.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/reflection/reflection.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/reflection/reflection.cpp Wed Aug 23 09:48:41 2006
@@ -29,7 +29,7 @@
 #include "vm_strings.h"
 #include "reflection.h"
 #include "port_malloc.h"
-#include "open/thread.h"
+
 #include "exceptions.h"
 #include "heap.h"
 #include "primitives_support.h"

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/stack/stack_trace.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/stack/stack_trace.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/stack/stack_trace.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/stack/stack_trace.cpp Wed Aug 23 09:48:41 2006
@@ -24,7 +24,7 @@
 #include "stack_trace.h"
 #include "interpreter.h"
 #include "jit_intf_cpp.h"
-#include "open/thread.h"
+
 #include "method_lookup.h"
 
 Method_Handle get_method(StackIterator* si)

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/atomics.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/atomics.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/atomics.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/atomics.cpp Wed Aug 23 09:48:41 2006
@@ -27,7 +27,7 @@
 #include "atomics.h"
 #include "vm_arrays.h"
 #include "port_atomic.h"
-#include "open/thread.h"
+
 
 /*
  * Common atomic functions.
@@ -79,7 +79,7 @@
 (JNIEnv * env, jobject UNREF accesor, jobject obj, jlong offset, jobject expected, jobject value)
 {
 
-    assert(tmn_is_suspend_enabled());
+    assert(hythread_is_suspend_enabled());
 
     ObjectHandle h = (ObjectHandle)obj;
     ObjectHandle v = (ObjectHandle)value;
@@ -117,7 +117,7 @@
 JNIEXPORT jboolean compareAndSetBooleanField
 (JNIEnv * env, jobject UNREF accesor, jobject obj, jlong offset, jboolean expected, jboolean value)
 {
-    assert(tmn_is_suspend_enabled());
+    assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
     tmn_suspend_disable();
@@ -136,7 +136,7 @@
 (JNIEnv * env, jobject UNREF accesor, jobject obj, jlong offset, jint expected, jint value)
 {
 
-    assert(tmn_is_suspend_enabled());
+    assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
     tmn_suspend_disable();
@@ -154,7 +154,7 @@
 JNIEXPORT jboolean compareAndSetLongField
 (JNIEnv * env, jobject UNREF accesor, jobject obj, jlong offset, jlong expected, jlong value)
 {
-    assert(tmn_is_suspend_enabled());
+    assert(hythread_is_suspend_enabled());
     ObjectHandle h = (ObjectHandle)obj;
 
     tmn_suspend_disable();
@@ -173,7 +173,7 @@
 JNIEXPORT jboolean compareAndSetObjectArray
 (JNIEnv * UNREF env, jobject UNREF self, jobjectArray array, jint index, jobject expected, jobject value)
 {
-    assert(tmn_is_suspend_enabled());
+    assert(hythread_is_suspend_enabled());
 
     tmn_suspend_disable();
 
@@ -209,7 +209,7 @@
 JNIEXPORT jboolean compareAndSetBooleanArray
 (JNIEnv * UNREF env, jobject UNREF self, jbooleanArray array, jint index, jboolean expected, jboolean value)
 {
-    assert(tmn_is_suspend_enabled());
+    assert(hythread_is_suspend_enabled());
 
     tmn_suspend_disable();
 
@@ -228,7 +228,7 @@
 JNIEXPORT jboolean compareAndSetIntArray
 (JNIEnv * UNREF env, jobject UNREF self, jintArray array, jint index, jint expected, jint value)
 {
-    assert(tmn_is_suspend_enabled());
+    assert(hythread_is_suspend_enabled());
 
     tmn_suspend_disable();
 
@@ -247,7 +247,7 @@
 JNIEXPORT jboolean compareAndSetLongArray
 (JNIEnv * UNREF env, jobject UNREF self, jlongArray array, jint index, jlong expected, jlong value)
 {
-    assert(tmn_is_suspend_enabled());
+    assert(hythread_is_suspend_enabled());
 
     tmn_suspend_disable();
 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/hythr/hythr.def
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/hythr/hythr.def?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/hythr/hythr.def (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/hythr/hythr.def Wed Aug 23 09:48:41 2006
@@ -1,22 +0,0 @@
-LIBRARY	HYTHR
-
-EXPORTS
-       hythread_attach
-       hythread_create
-       hythread_detach
-       hythread_exit
-       hythread_global
-       hythread_monitor_destroy
-       hythread_monitor_enter
-       hythread_monitor_exit
-       hythread_monitor_init_with_name
-       hythread_monitor_notify
-       hythread_monitor_notify_all
-       hythread_monitor_try_enter
-       hythread_monitor_wait
-       hythread_self
-       hythread_tls_alloc
-       hythread_tls_free
-       hythread_tls_get
-       hythread_tls_set
- 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/hythr/hythr.exp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/hythr/hythr.exp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/hythr/hythr.exp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/hythr/hythr.exp Wed Aug 23 09:48:41 2006
@@ -1,22 +0,0 @@
-HYTHR_0.1 {
-    global :
-    hythread_attach;
-    hythread_create;
-    hythread_detach;
-    hythread_exit;
-    hythread_global;
-    hythread_monitor_destroy;
-    hythread_monitor_enter;
-    hythread_monitor_exit;
-    hythread_monitor_init_with_name;
-    hythread_monitor_notify;
-    hythread_monitor_notify_all;
-    hythread_monitor_try_enter;
-    hythread_monitor_wait;
-    hythread_self;
-    hythread_tls_alloc;
-    hythread_tls_free;
-    hythread_tls_get;
-    hythread_tls_set;
-    local : *;
-};

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/hythr/hythreads.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/hythr/hythreads.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/hythr/hythreads.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/hythr/hythreads.cpp Wed Aug 23 09:48:41 2006
@@ -1,290 +0,0 @@
-/*
- *  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: 1.1.2.1.4.5 $
- */
-#include "hythreads.h"
-#include "log_macro.h"
-
-
-#ifdef WIN32
-#include <windows.h>
-#endif
-
-#define GLOBAL_MONITOR_NAME "global_monitor"
-
-#define RET_ON_ERROR(stat) if(stat) { return -1; }
-
-extern "C" 
-{
-
-JNIEXPORT void  __cdecl hythread_init(void*  lib);
-
-#ifdef WIN32
-BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpres) {
-  if (dwReason == DLL_PROCESS_ATTACH) {
-     hythread_init (NULL);
-   }
-   return TRUE;
-}
-#else
-void __cdecl hythread_library_init(void) {
-    hythread_init(NULL);
-
-}
-#endif
-
-
-hythread_monitor_t p_global_monitor; 
-// Will do all initilalization of thread library.
-// init global_monitor now.
-JNIEXPORT void  __cdecl hythread_init (void*  lib)  {
-    apr_initialize();
-    hythread_monitor_init_with_name(&p_global_monitor, 0, "Thread Global Monitor");
-    hythread_monitor_t *mon = (hythread_monitor_t*)hythread_global(GLOBAL_MONITOR_NAME);
-    *mon = p_global_monitor;
-}
-
-
-
-// ========================== MONITOR impl ================================================
-
-static apr_pool_t* get_pool() {
-    apr_pool_t *pool;
-    apr_pool_create(&pool, 0);
-    return pool;
-}
-
-JNIEXPORT int  __cdecl hythread_monitor_init_with_name (hythread_monitor_t* handle, unsigned flags, char* name) {
-    apr_status_t stat;
-
-    apr_pool_t *pool;
-    apr_pool_create(&pool, 0);
-        *handle = (hythread_monitor_t) apr_palloc(pool, sizeof(struct hymonitor));
-    if(*handle == NULL) {
-        return -1;
-    }
-    stat = apr_thread_mutex_create(&((*handle)->mutex), APR_THREAD_MUTEX_NESTED, pool);
-    RET_ON_ERROR(stat)
-    stat = apr_thread_cond_create(&((*handle)->cond), pool);
-    RET_ON_ERROR(stat)
-        (*handle)->name = name;
-        return 0;
-}
-
-JNIEXPORT int __cdecl
-hythread_monitor_destroy (hythread_monitor_t monitor){          
-    apr_status_t stat;
-    apr_pool_t *pool = apr_thread_mutex_pool_get (monitor->mutex);
-    if(pool == NULL) {
-        return -1;
-    }
-    stat = apr_thread_mutex_destroy(monitor->mutex);
-    RET_ON_ERROR(stat)
-    stat = apr_thread_cond_destroy(monitor->cond);
-    RET_ON_ERROR(stat)
-    apr_pool_destroy(pool);
-    return 0;
-}
-
-JNIEXPORT int __cdecl 
-hythread_monitor_try_enter (hythread_monitor_t monitor){ 
-// TODO implement
-    return -1; 
-}
-JNIEXPORT int __cdecl 
-hythread_monitor_enter (hythread_monitor_t monitor){ 
-    apr_status_t stat = apr_thread_mutex_lock(monitor->mutex);
-    RET_ON_ERROR(stat)
-    return 0; 
-}
-JNIEXPORT int __cdecl 
-hythread_monitor_exit (hythread_monitor_t monitor) { 
-    apr_status_t stat = apr_thread_mutex_unlock(monitor->mutex);
-    RET_ON_ERROR(stat)
-    return 0; 
-}
-JNIEXPORT int __cdecl
-hythread_monitor_notify(hythread_monitor_t monitor){ 
-    apr_status_t stat = apr_thread_cond_signal(monitor->cond);
-    RET_ON_ERROR(stat)
-    return 0; 
-}
-JNIEXPORT int __cdecl
-hythread_monitor_notify_all (hythread_monitor_t monitor){ 
-    apr_status_t stat = apr_thread_cond_broadcast(monitor->cond);
-    RET_ON_ERROR(stat)
-    return 0; 
-}
-JNIEXPORT int __cdecl
-hythread_monitor_wait (hythread_monitor_t monitor){ 
-    apr_status_t stat = apr_thread_cond_wait(monitor->cond, monitor->mutex);
-    RET_ON_ERROR(stat)
-    return 0; 
-}
-
-// ======================= ATTACH ======================================
-
-JNIEXPORT int __cdecl 
-hythread_attach (hythread_t* handle){
-    if(handle) {
-        *handle=hythread_self();
-    }
-    return 0; 
-}
-JNIEXPORT void __cdecl 
-hythread_detach (hythread_t handle){}
-JNIEXPORT hythread_t __cdecl hythread_self() {
-    return apr_os_thread_current();
-}
-
-// very simple Map implementation
-// current scenario use only one global so it works well
-// need to be hashtable in the future
-// TODO use hashtable
-
-#define  TABLE_SIZE 256 
-char *names [TABLE_SIZE];
-unsigned data [TABLE_SIZE];
-int size = 0;
-// return index in array if found, -1 otherwise
-int find_entry (char* name) {
-    // quick pass
-    int i;
-    for (i = 0; i < size; i++) {
-        if (names[i] == name) {
-            return i;
-        }
-    }
-    // strcmp pass.
-    for (i = 0; i < size; i++) {
-        if (strcmp(names[i], name) == 0) {
-            return i;
-        }
-    }
-    return -1;
-}
-//add entry to the end of the array
-// retrun new entry index,  -1 if failed.
-int add_entry(char* name) {
-    int index = size++;
-    if(index >= TABLE_SIZE-1) {
-        return -1;
-    }
-    names[index] = name;
-    data[index] = 0;
-    return index;
-}
-
-JNIEXPORT unsigned* __cdecl 
-hythread_global (char* name) { 
-    //hythread_monitor_enter(*p_global_monitor);
-    int index = find_entry(name);
-    if(index == -1) {
-        index = add_entry(name);
-        assert(index >=0);
-        if (index < 0) {
-            //hythread_monitor_exit(*p_global_monitor);
-            return NULL;
-        }
-    }
-    //hythread_monitor_exit(*p_global_monitor);
-    return data+index;
-}
-
-// ================== TLS =======================================
-
-
-JNIEXPORT int __cdecl 
-hythread_tls_alloc (hythread_tls_key_t* handle){  
-    apr_status_t stat = apr_threadkey_private_create(handle,  NULL, get_pool());
-    RET_ON_ERROR(stat)
-    return 0; 
-}
-
-JNIEXPORT int __cdecl 
-hythread_tls_free (hythread_tls_key_t key){ 
-        
-    apr_status_t stat = apr_threadkey_private_delete(key);
-    RET_ON_ERROR(stat)
-    return 0; 
-}
-
-// TODO method work only for current thread
-JNIEXPORT void* __cdecl 
-hythread_tls_get (hythread_t thread, hythread_tls_key_t key) { 
-    void* result; 
-    apr_status_t stat = apr_threadkey_private_get(&result, key);
-    if(stat != 0) {
-        return NULL;
-    }
-    return result; 
-}
-
-// TODO method work only for current thread
-JNIEXPORT int __cdecl 
-hythread_tls_set (hythread_t thread, hythread_tls_key_t key, void* value){ 
-    apr_status_t stat = apr_threadkey_private_set(value, key);
-    RET_ON_ERROR(stat)
-    return 0; 
-}
-//  ==================== create thread ==========================
-//#ifndef WIN32
-static void* APR_THREAD_FUNC hystart_wrapper(apr_thread_t* t , void* args) {
-    hythread_entrypoint_t entrypoint = (hythread_entrypoint_t)*((void **)args);
-    void* hyargs = *((void**)args+1);
-    return (void*) entrypoint(hyargs);
-}
-
-JNIEXPORT int  __cdecl
-hythread_create(hythread_t* handle, unsigned stacksize, unsigned priority, unsigned suspend, hythread_entrypoint_t entrypoint, void* entryarg) {
-    apr_thread_t *new_thread;
-    apr_pool_t *pool = get_pool();
-    static void **port_args = (void**)apr_palloc(pool, sizeof(void*)*2);
-    port_args[0] = (void*)entrypoint;
-    port_args[1] = (void*)entryarg;
-    apr_status_t stat = apr_thread_create(&new_thread, NULL, hystart_wrapper,
-                                            port_args, pool);
-    RET_ON_ERROR(stat);
-    stat = apr_os_thread_get(&handle, new_thread);
-    RET_ON_ERROR(stat);
-    return 0;
-}
-
-
-JNIEXPORT int __cdecl
-hythread_exit (hythread_monitor_t monitor) {
-   apr_status_t stat;
-   apr_os_thread_t aott;
-   apr_thread_t *att = NULL;
-
-   // att = (apr_thread_t*)apr_pcalloc(get_pool(), sizeof(apr_thread_t*));	
-   aott = apr_os_thread_current();
-   stat = apr_os_thread_put(&att, &aott, get_pool());
-   RET_ON_ERROR(stat);
-    
-   if (monitor) {
-      hythread_monitor_exit(monitor);
-   }
-
-   return apr_thread_exit(att, 0);
-}
-
-
-
-
-}// extern "C"

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/hythr/hythreads.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/hythr/hythreads.h?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/hythr/hythreads.h (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/hythr/hythreads.h Wed Aug 23 09:48:41 2006
@@ -1,90 +0,0 @@
-/*
- *  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: 1.1.2.1.4.4 $
- */  
-#include "vm_threads.h"
-#include <apr_general.h>
-#include <apr_thread_mutex.h>
-#include <apr_thread_cond.h>
-#include <apr_thread_proc.h>
-#include <apr_portable.h>
-
-#include<stdio.h>
-#include<assert.h>
-
-#define GLOBAL_MONITOR_NAME "global_monitor"
-extern "C" 
-{
-
-JNIEXPORT void  __cdecl hythread_init (void*  lib);
-// ========================== MONITOR ================================================
-struct hymonitor {
-    char* name;
-    apr_thread_mutex_t *mutex;
-    apr_thread_cond_t *cond;
-};
-
-typedef hymonitor* hythread_monitor_t; 
-
-JNIEXPORT int  __cdecl hythread_monitor_init_with_name (hythread_monitor_t* handle, unsigned flags, char* name);
-JNIEXPORT int __cdecl
-hythread_monitor_destroy (hythread_monitor_t monitor);
-JNIEXPORT int __cdecl 
-hythread_monitor_try_enter (hythread_monitor_t monitor);
-JNIEXPORT int __cdecl 
-hythread_monitor_enter (hythread_monitor_t monitor);
-JNIEXPORT int __cdecl 
-hythread_monitor_exit (hythread_monitor_t monitor);
-JNIEXPORT int __cdecl
-hythread_monitor_notify (hythread_monitor_t monitor);
-JNIEXPORT int __cdecl
-hythread_monitor_notify_all (hythread_monitor_t monitor);
-JNIEXPORT int __cdecl
-hythread_monitor_wait (hythread_monitor_t monitor);
-
-// ======================= ATTACH ======================================
-typedef apr_os_thread_t hythread_t;
-
-JNIEXPORT int __cdecl 
-hythread_attach (hythread_t* handle);
-JNIEXPORT void __cdecl 
-hythread_detach (hythread_t handle);
-JNIEXPORT hythread_t __cdecl hythread_self();
-JNIEXPORT int __cdecl
-hythread_exit (hythread_monitor_t monitor);
-
-JNIEXPORT unsigned* __cdecl 
-hythread_global (char* name);
-
-// ==================== create thread ====================
-typedef int(__cdecl* hythread_entrypoint_t)(void*);
-JNIEXPORT int  __cdecl
-hythread_create(hythread_t* handle, unsigned stacksize, unsigned priority, unsigned suspend, hythread_entrypoint_t entrypoint, void* entryarg);
-// ================== TLS =======================================
-typedef apr_threadkey_t* hythread_tls_key_t;
-
-JNIEXPORT int __cdecl 
-hythread_tls_alloc (hythread_tls_key_t* handle);
-JNIEXPORT int __cdecl 
-hythread_tls_free (hythread_tls_key_t key);
-JNIEXPORT void* __cdecl 
-hythread_tls_get (hythread_t thread, hythread_tls_key_t key);
-JNIEXPORT int __cdecl 
-hythread_tls_set (hythread_t thread, hythread_tls_key_t key, void* value);
-
-}// extern "C"

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/lock_manager.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/lock_manager.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/lock_manager.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/lock_manager.cpp Wed Aug 23 09:48:41 2006
@@ -32,38 +32,47 @@
 Lock_Manager *p_meth_addr_table_lock;
 Lock_Manager *p_thread_lock;
 Lock_Manager *p_method_call_lock;
-Lock_Manager *p_tm_lock;
+Lock_Manager *p_handle_lock;
  
+extern hythread_library_t hythread_lib;
 
+VMEXPORT void jit_lock() {
+    p_jit_a_method_lock->_lock();
+}
 
+VMEXPORT void jit_unlock() {
+    p_jit_a_method_lock->_unlock();
+}
 
 Lock_Manager::Lock_Manager()
-{
+{   // init thread menager if needed
+    hythread_init(hythread_lib);
+    UNREF IDATA stat = hymutex_create (&lock, TM_MUTEX_NESTED);
+    assert(stat==TM_ERROR_NONE);
 }
 
 Lock_Manager::~Lock_Manager()
 {
+    UNREF IDATA stat = hymutex_destroy (lock);
+    assert(stat==TM_ERROR_NONE);
 }
 
 void Lock_Manager::_lock()
 {
-    DEBUG_CONTENDS_LOCK (this);
-    _critical_section.lock();
-    DEBUG_PUSH_LOCK (this);
+    UNREF IDATA stat = hymutex_lock(lock);
+    assert(stat==TM_ERROR_NONE);
 }
 
 bool Lock_Manager::_tryLock()
-{   if(_critical_section.tryLock()) {
-        DEBUG_PUSH_LOCK (this);
-        return true;
-    }
-    return false;
+{     
+    IDATA stat = hymutex_trylock(lock);
+    return stat==TM_ERROR_NONE;    
 }
 
 void Lock_Manager::_unlock()
 {
-    _critical_section.unlock();
-    DEBUG_POP_LOCK (this);
+    UNREF IDATA stat = hymutex_unlock(lock);
+    assert(stat==TM_ERROR_NONE);
 }
 
 
@@ -75,8 +84,7 @@
 
 void Lock_Manager::_unlock_enum()
 {
-    _critical_section.unlock();
-    DEBUG_POP_LOCK (this);
+   Lock_Manager::_unlock();
 }
 
 
@@ -89,33 +97,23 @@
 
 bool Lock_Manager::_lock_or_null()
 {
-    bool stat = _critical_section.tryLock();
-    if (!stat) {
-        return false;
-    }
-    DEBUG_PUSH_LOCK (this);
-    return true;
+    return Lock_Manager::_tryLock();
 }
 
 
 void Lock_Manager::_unlock_or_null()
 {
-    
-    _critical_section.unlock();
-    DEBUG_POP_LOCK (this);
+    Lock_Manager::_unlock_enum();
 }
 
 
 void Lock_Manager::_unlock_enum_or_null() 
 {
-    _critical_section.unlock();
-    DEBUG_POP_LOCK (this);
+     Lock_Manager::_unlock_enum();
 } 
 
 bool Lock_Manager::_lock_enum_or_null(bool UNREF return_null_on_fail)
 {
-    DEBUG_CONTENDS_LOCK (this);
-    _critical_section.lock();
-    DEBUG_PUSH_LOCK (this);
-    return true;
+    IDATA stat = hymutex_lock(lock);
+    return stat==TM_ERROR_NONE;
 }

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/mon_enter_exit.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/mon_enter_exit.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/mon_enter_exit.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/mon_enter_exit.cpp Wed Aug 23 09:48:41 2006
@@ -27,348 +27,41 @@
 #include "thread_generic.h"
 #include "vm_synch.h"
 #include "port_atomic.h"
+#include "open/jthread.h"
 
 static void vm_monitor_exit_default(ManagedObject *p_obj);
-static void vm_monitor_exit_default_handle(jobject jobj);
+static void vm_monitor_enter_default(ManagedObject *p_obj);
+
 
 void (*vm_monitor_enter)(ManagedObject *p_obj) = 0;
 void (*vm_monitor_exit)(ManagedObject *p_obj) = 0;
-void (*vm_monitor_exit_handle)(jobject jobj) = 0;
-
-volatile int active_thread_count;
-
-mon_enter_fields mon_enter_array[MAX_VM_THREADS];
-
-static void jvmti_push_monitor(jobject jobj);
-static void jvmti_pop_monitor(jobject jobj);
-
-#if defined(USE_TLS_API) || !defined(STACK_BASE_AS_TID)
-uint16 get_self_stack_key()
-{
-    return p_TLS_vmthread->stack_key;
-}
-#endif //#ifdef USE_TLS_API || !STACK_BASE_AS_TID
-
-void block_on_mon_enter(jobject obj)
-{
-    assert(!tmn_is_suspend_enabled());
-    ManagedObject *p_obj = obj->object;
-    VM_thread *p_thr = get_thread_ptr();
-
-    assert(mon_enter_array[p_thr->thread_index].p_obj == 0);
-
-    // set thread state to BLOCKED on monitor
-    // RUNNING will be set back before return
-    enum java_state old_state =  p_thr->app_status;
-    p_thr->app_status = thread_is_blocked;
-    
-#ifdef _DEBUG
-    int loop_count = 0;
-#endif
-
-    //since p_obj may be moved by GC in the below loop, we need to reload after gc_enable/disable
-    volatile ManagedObject *volatile_p_obj = (ManagedObject *)p_obj;
-
-    while (1) {
-
-        mon_enter_array[p_thr->thread_index].p_obj = (ManagedObject *)volatile_p_obj;
-
-#ifdef _DEBUG
-        loop_count++;
-        if (loop_count > max_block_on_mon_enter_loops)
-            max_block_on_mon_enter_loops = loop_count;
-#endif
-        if ( STACK_KEY(volatile_p_obj) == FREE_MONITOR)
-        {
-            mon_enter_array[p_thr->thread_index].p_obj = 0;
-
-            Boolean retval = vm_try_monitor_enter( (ManagedObject *)volatile_p_obj);
-            if (retval){
-                assert(p_thr->app_status == thread_is_blocked); 
-                p_thr->app_status = old_state;
-                return;
-            }
-            else continue;
-        }
-
-        tmn_suspend_enable(); 
-        p_thr -> is_suspended = true;
-
-        // no one sends this event
-        // DWORD stat = vm_wait_for_single_object(p_thr->event_handle_monitor, 1);
-        vm_yield();
-
-        p_thr -> is_suspended = false;
-        tmn_suspend_disable();
-
-        // by convention, *only* mon_enter_array and mon_wait_array will be enumerated to the GC
-        // thus reload from mon_enter_array[] after the waitforsingleobject returns
-        ManagedObject* p_obj = (ManagedObject *)
-                            mon_enter_array[p_thr->thread_index].p_obj;
-        assert(managed_object_is_valid(p_obj));
-        volatile_p_obj = p_obj;
-
-    } //while(1)
-}
-
-
-void find_an_interested_thread(ManagedObject *p_obj)
-{
-    assert(!tmn_is_suspend_enabled());
-    if ( ( HASH_CONTENTION(p_obj) & CONTENTION_MASK) == 0)
-        return;  // nobody wants this object
-
-    DWORD stat;
-    int xx;
-
-    for (xx = 1; xx < next_thread_index; xx++)
-    {
-        if (mon_enter_array[xx].p_obj == p_obj)
-        {
-            stat = vm_set_event(mon_enter_array[xx].p_thr->event_handle_monitor);
-            assert(stat);
-
-            return;
-        }
-    }
-}
 
 
 void vm_enumerate_root_set_mon_arrays()
 {
-    TRACE2("enumeration", "enumerating root set monitor arrays");
-    int xx;
-
-    for (xx = 1; xx < next_thread_index; xx++)
-    {
-        if (mon_enter_array[xx].p_obj){
-            assert( (STACK_KEY( mon_enter_array[xx].p_obj)) != mon_enter_array[xx].p_thr->stack_key );
-            vm_enumerate_root_reference((void **)&(mon_enter_array[xx].p_obj), FALSE);
-        }
-
-        if (mon_wait_array[xx].p_obj){
-            assert( mon_wait_array[xx].p_thr->app_status == thread_is_waiting || mon_wait_array[xx].p_thr->app_status == thread_is_timed_waiting);
-            vm_enumerate_root_reference((void **)&(mon_wait_array[xx].p_obj), FALSE);
-        }
-    }
-}
-
-void mon_enter_recursion_overflowed(ManagedObject * UNREF p_obj)
-{
-    ABORT("Not implemented"); //TODO: add the backup algorithm for recursion overflow
-
 }
 
 void vm_monitor_init()
 {
-    vm_monitor_enter = vm_monitor_enter_slow;
+    vm_monitor_enter = vm_monitor_enter_default;
     vm_monitor_exit = vm_monitor_exit_default;
-    vm_monitor_exit_handle = vm_monitor_exit_default_handle;
-}
-
-inline void pause_inst(void){
-#if defined(PLATFORM_POSIX) && !defined(_IPF_)
-    __asm__(
-#if !((__GLIBC__ == 2) && (__GLIBC_MINOR__ <= 1))
-        "pause"
-#else
-        "nop;nop;nop"
-#endif
-        : : : "memory"
-    );
-
-#else
-#ifdef _IPF_
-    // WE WILL DO NOTHING HERE FOR THE TIME BEING...until we can find a suitable & profitable IPF instruction...
-#else  // !_IPF_
-    _asm{ 
-        pause
-    }
-#endif // !_IPF_
-
-#endif
-
-}
-
-
-//return the old monitor stack key, so that 0 means success, otherwise failure;
-Boolean vm_try_monitor_enter(ManagedObject *p_obj)
-{
- 
-    uint16 current_stack_key = get_self_stack_key();
-    uint16 *p_monitor_stack_key = P_STACK_KEY(p_obj);
-    uint16 old_stack_key = FREE_MONITOR;
-    old_stack_key = port_atomic_cas16(p_monitor_stack_key, current_stack_key, FREE_MONITOR);
-    if( old_stack_key == FREE_MONITOR ){    
-        
-        return TRUE;
-
-    } else if (old_stack_key == current_stack_key) { //recursed
-        ++RECURSION(p_obj);
-        if (0 == RECURSION(p_obj)) {
-            mon_enter_recursion_overflowed(p_obj);
-        }
-        return TRUE;
-    }
-
-    //hold by other thread
-    return FALSE;
-}
-
-static inline uint8 get_recursion(jobject jobj) {
-    assert(tmn_is_suspend_enabled());
-    tmn_suspend_disable(); // ----------- vv
-    uint8 recursion = RECURSION(jobj->object);
-    tmn_suspend_enable(); // ------------ ^^
-    return recursion;
-}
-
-static inline uint16 get_stack_key(jobject jobj) {
-    assert(object_is_valid(jobj));
-    tmn_suspend_disable(); // ----------vv
-    uint16 *p_stack_key = P_STACK_KEY(jobj->object);
-    uint16 result = *p_stack_key;
-    tmn_suspend_enable(); // -----------^^
-    return result;
-}
-
-static inline uint16 compare_swap_stack_key(jobject jobj, uint16 value, uint16 expected) {
-    assert(object_is_valid(jobj));
-    tmn_suspend_disable(); // ----------vv
-    uint16 *p_stack_key = P_STACK_KEY(jobj->object);
-    uint16 old = port_atomic_cas16(p_stack_key, value, expected);
-    tmn_suspend_enable(); // -----------^^
-    return old;
-}
-
-// this is a first step of a bigger refactoring
-// of VM code to run with gc enabled.
-//
-// this function should be called instead of vm_monitor_enter_slow
-// NOTE, that only ia32 stubs were modified so.
-//
-// -salikh 2005-05-11
-VMEXPORT void vm_monitor_enter_slow_handle (jobject jobj) {
-    TRACE2("oh", "vm_monitor_enter_slow_handle()");
-    assert(tmn_is_suspend_enabled());
-    assert(object_is_valid(jobj));
-    
-    uint16 current_stack_key = get_self_stack_key();
-    uint16 old_stack_key = get_stack_key(jobj);
-    
-    if (old_stack_key == FREE_MONITOR) { //common case, fastest
-        old_stack_key = compare_swap_stack_key(jobj, current_stack_key, FREE_MONITOR);
-        if (old_stack_key == FREE_MONITOR) { //ok, got it
-            jvmti_push_monitor(jobj);
-            return;
-        }
-        // failed to grab the lock, fall through to contended case
-    } else if (old_stack_key == current_stack_key) { //recursed
-        tmn_suspend_disable(); // ---------------vv
-        ++RECURSION(jobj->object);
-        int recursion = RECURSION(jobj->object);
-        tmn_suspend_enable(); // ----------------^^
-        if (0 == recursion) {
-            tmn_suspend_disable(); // -----------vv
-            mon_enter_recursion_overflowed(jobj->object);
-            tmn_suspend_enable(); // ------------^^
-        }
-        return;
-    }
-
-    //hold by other thread, let's spin look for a short while
-
-    unsigned int i = SPIN_LOOP_COUNT;
-    while (i--) {
-        pause_inst();
-        if (0 == get_stack_key(jobj)) { //monitor is free now, try to get it
-            old_stack_key = compare_swap_stack_key(jobj, current_stack_key, FREE_MONITOR);
-            if (old_stack_key == FREE_MONITOR) { //ok, got it
-                jvmti_push_monitor(jobj);
-                return;
-            }
-        }
     }
 
-    bool isEnter = true;
-    jvmti_send_contended_enter_or_entered_monitor_event(jobj, isEnter);
-    
-    // we have no way to get the lock, then sleep; 
-    tmn_suspend_disable();
-    block_on_mon_enter(jobj);
-    tmn_suspend_enable();
-
-    assert(object_is_valid(jobj));
-    if (get_stack_key(jobj) != current_stack_key) {
-        DIE("Wrong monitor states after GC: " << jobj << ")");
-    }
-
-    return;
-}
-
-void vm_monitor_enter_slow(ManagedObject *p_obj)
+static void vm_monitor_enter_default(ManagedObject *p_obj)
 {
-    assert(!tmn_is_suspend_enabled());
+    assert(!hythread_is_suspend_enabled());
     assert(p_obj);
     jobject jobj = oh_allocate_local_handle();
     jobj->object = p_obj;
-    tmn_suspend_enable();    // we've protected the argument
-    vm_monitor_enter_slow_handle(jobj);
-    tmn_suspend_disable();   // restore suspend enabled state
+    jthread_monitor_enter(jobj); 
 }
 
-static void vm_monitor_exit_default_handle(jobject jobj) {
-    assert(object_is_valid(jobj));
-
-    uint16 current_stack_key = get_self_stack_key();
-
-    uint16 monitor_stack_key = get_stack_key(jobj);
-    if (monitor_stack_key == current_stack_key) { //common case, fastest path
-        if (!get_recursion(jobj)) { //no recursion
-            tmn_suspend_disable(); // ----------------------vv
-            STACK_KEY(jobj->object) = FREE_MONITOR; //release the lock
-            if (HASH_CONTENTION(jobj->object) & CONTENTION_MASK) { //contented
-                find_an_interested_thread(jobj->object);
-            }
-            tmn_suspend_enable(); // -----------------------^^
-            jvmti_pop_monitor(jobj);
-        } else { //recursed
-            tmn_suspend_disable(); // ----------------------vv
-            RECURSION(jobj->object)--; 
-            tmn_suspend_enable(); // -----------------------^^
-        }
-        
-    } else { //illegal monitor state
-        exn_throw_by_name("java/lang/IllegalMonitorStateException");
-    }
-
-    assert(tmn_is_suspend_enabled());
-}
-
-
-
 static void vm_monitor_exit_default(ManagedObject *p_obj)
 {
     assert(managed_object_is_valid(p_obj));
     jobject jobj = oh_allocate_local_handle();
     jobj->object = p_obj;
-    tmn_suspend_enable();
-    vm_monitor_exit_default_handle(jobj);
-    tmn_suspend_disable();
-}
-
-//#endif // !_IPF_
-
-void set_hash_bits(ManagedObject *p_obj)
-{
-    uint8 hb = (uint8) (((POINTER_SIZE_INT)p_obj >> 3) & HASH_MASK)  ;
-    // lowest 3 bits are not random enough so get rid of them
-
-    if (hb == 0)
-        hb = (23 & HASH_MASK);  // NO hash = zero allowed, thus hard map hb = 0 to a fixed prime number
-
-    // don't care if the cmpxchg fails -- just means someone else already set the hash
-    port_atomic_cas8(P_HASH_CONTENTION(p_obj),hb, 0);
+    jthread_monitor_exit(jobj);
 }
 
 
@@ -382,72 +75,5 @@
 
 Boolean verify_object_header(void *ptr)
 {
-    ManagedObject *p_obj = (ManagedObject *) ptr;
-    if (p_obj->get_obj_info() == 0) {
-        // ZERO header is valid.
         return FALSE;
     }
-
-    uint16 stack_key = STACK_KEY(p_obj);
-    // Recursion can be any 8-bit value...no way to check integrity.
-    // Contention bit can remain ON in our current implemenation at arbitrary times.
-    // Hash can be zero or non-zero at any given time, though it doesnt change after it goes non-zero
-
-    // Not much I can check here....can I????
-
-    // So I will check only if the monitor lock is held and if so by a valid thread.
-
-    if (stack_key == 0) {
-        // No thread owns the object lock
-        return FALSE;
-    }
-
-    // Object monitor is held.
-
-    Boolean res = TRUE;
-    tmn_suspend_enable();
-    tm_iterator_t * iterator = tm_iterator_create();
-    tmn_suspend_disable();
-    VM_thread *thread = tm_iterator_next(iterator);
-    assert(thread);
-    
-    while (thread) {
-        if (thread->thread_index == stack_key) {
-            res = TRUE;
-            break;
-        }
-        thread = tm_iterator_next(iterator);
-    }
-    tm_iterator_release(iterator);
-    // What should the return value be?
-    return res;
-}
-
-static void jvmti_push_monitor(jobject jobj)
-{
-    assert(tmn_is_suspend_enabled());
-    if (VM_Global_State::loader_env->TI->isEnabled()) {
-        VM_thread *thread = p_TLS_vmthread;
-        assert(thread -> jvmti_owned_monitor_count < MAX_OWNED_MONITORS);
-        ObjectHandle oh = oh_allocate_global_handle();
-        tmn_suspend_disable(); // ----------- vv
-        oh -> object = jobj -> object;
-        tmn_suspend_enable(); // ------------ ^^
-        thread -> jvmti_owned_monitors[thread -> jvmti_owned_monitor_count++] = (jobject) oh;
-    }
-}
-
-static void jvmti_pop_monitor(jobject UNREF jobj)
-{
-    assert(tmn_is_suspend_enabled());
-    if (VM_Global_State::loader_env->TI->isEnabled()) {
-        VM_thread *thread = p_TLS_vmthread;
-        if (thread -> jvmti_owned_monitor_count <= 0) return;
-        assert(thread -> jvmti_owned_monitor_count > 0);
-
-        ObjectHandle oh = (ObjectHandle)
-            thread -> jvmti_owned_monitors[--thread -> jvmti_owned_monitor_count];
-        oh_deallocate_global_handle(oh);
-    }
-}
-

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/object_generic.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/object_generic.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/object_generic.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/object_generic.cpp Wed Aug 23 09:48:41 2006
@@ -40,11 +40,13 @@
 #include "vm_arrays.h"
 
 #include "thread_generic.h"
-#include "open/thread.h"
+
+#include "open/jthread.h"
 #include "thread_manager.h"
 #include "object.h"
 #include "object_generic.h"
 #include "mon_enter_exit.h"
+#include "port_atomic.h"
 
 #include "jit_runtime_support_common.h"
 
@@ -52,272 +54,28 @@
 #include "interpreter.h"
 #include "vm_log.h"
 
-mon_wait_fields mon_wait_array[MAX_VM_THREADS];
-
-#ifdef _DEBUG
-// loose, approximate counts, full of race conditions
-int max_notifyAll = 0;
-int max_recursion = 0;
-int total_sleep_timeouts = 0;
-int total_sleep_interrupts = 0;
-int total_wait_timeouts = 0;
-int total_wait_interrupts = 0;
-int total_illegal_mon_state_exceptions = 0;
-int iterations_per_thread[MAX_VM_THREADS];
-int max_block_on_mon_enter_loops = 0;
-#endif
-
-static inline bool object_locked_by_current_thread(jobject jobj) {
-    uint16 current_stack_key = get_self_stack_key();
-    bool result = false;
-    assert(!tmn_is_suspend_enabled());
-    result = (STACK_KEY(jobj->object) == current_stack_key);
-    TRACE2("stack_key", "self = " << current_stack_key 
-        << ", locked by " << STACK_KEY(jobj->object)
-        << ", result = " << result);
-    return result;
-}
-
-void notify_internal (jobject jobj, Boolean all)
-{
-
-    tmn_suspend_disable_recursive();
-    assert(jobj->object->vt()->clss->vtable->clss->vtable);
- 
-   if (!object_locked_by_current_thread(jobj)) 
+void set_hash_bits(ManagedObject *p_obj)
     {
-        tmn_suspend_enable_recursive(); 
-        exn_raise_by_name("java/lang/IllegalMonitorStateException");
-        return;
-    }
-
-#ifdef _DEBUG
-    int notifyAll_count = 0;
-#endif
-
-    DWORD stat;
-    int xx;
-
-    for (xx = 1; xx < next_thread_index; xx++)
-    {
-        if (mon_wait_array[xx].p_obj == jobj->object)
-        {
-            stat = vm_set_event(mon_wait_array[xx].p_thr->event_handle_notify_or_interrupt);
-#ifdef _DEBUG
-            if(!stat) {
-                 WARN("set notify event failed: " << IJGetLastError());
-            }
-#endif
-            if (!all)
-                break;
-
-#ifdef _DEBUG
-            notifyAll_count++;
-            if (notifyAll_count > max_notifyAll)
-                max_notifyAll = notifyAll_count;
-#endif
-        }
-    }
-    tmn_suspend_enable_recursive(); 
-}
-
-void thread_object_notify (jobject jobj)
-{
-    java_lang_Object_notify (jobj);
-}
-void java_lang_Object_notify (jobject jobj)
-{
-    TRACE2("notify", "Notify " << p_TLS_vmthread->thread_handle << " on " << jobj);
-    //assert(tmn_is_suspend_enabled());
-
-    notify_internal(jobj, false);
-
-    //assert(tmn_is_suspend_enabled());
-    TRACE2("notify", "Finish Notify " << p_TLS_vmthread->thread_handle << " on " << jobj);
-}
-
-void thread_object_notify_all (jobject jobj)
-{
-    java_lang_Object_notifyAll (jobj);
-}
-
-void java_lang_Object_notifyAll (jobject jobj)
-{
-    TRACE2("notify", "Notify all " << p_TLS_vmthread->thread_handle << " on " << jobj);
- 
-    notify_internal(jobj, true);
+    uint8 hb = (uint8) (((POINTER_SIZE_INT)p_obj >> 3) & HASH_MASK)  ;
+    // lowest 3 bits are not random enough so get rid of them
 
-    TRACE2("notify", "Finish notify all " << p_TLS_vmthread->thread_handle << " on " << jobj);
-}
+    if (hb == 0)
+        hb = (23 & HASH_MASK);  // NO hash = zero allowed, thus hard map hb = 0 to a fixed prime number
 
-void thread_object_wait_nanos(jobject jobj, int64 msec, int nanosec) {
-    /*
-	 * We have to do something in the case millis == 0 and nanos > 0,
-	 * because otherwise we'll wait infinitely, also just return whould 
-	 * be incorrect because we have to relese lock for a while:
-	 */
-    msec += (msec==0 && nanosec>0)?1:0;
-    java_lang_Object_wait(jobj, msec);
-}
-
-void thread_object_wait(jobject jobj, int64 msec)
-{
-    java_lang_Object_wait(jobj, msec);
+    // don't care if the cmpxchg fails -- just means someone else already set the hash
+    port_atomic_cas8(P_HASH_CONTENTION_BYTE(p_obj),hb, 0);
 }
-int java_lang_Object_wait(jobject jobj, int64 msec)
-{
-    assert(tmn_is_suspend_enabled());
- 
-    // ? 2003-06-23.  The lock needs to be unreserved.
-    if (msec < 0) 
-    {
-        exn_raise_by_name("java/lang/IllegalArgumentException");
-        return -1;
-    }
-
-    assert(object_is_valid(jobj));
-    tmn_suspend_disable();
-
-    if (!object_locked_by_current_thread(jobj)) 
-    {
-        tmn_suspend_enable(); 
-        exn_raise_by_name("java/lang/IllegalMonitorStateException");
-        return -1;
-    }
- 
-    VM_thread *p_thr = get_thread_ptr();
-    DWORD stat;
-    // toss stale notifies
-    stat = vm_reset_event(p_thr->event_handle_notify_or_interrupt);
- 
-    // check prior interrupts.
-    if (p_thr->interrupt_a_waiting_thread)
-    {
-        p_thr->interrupt_a_waiting_thread = false;
-        tmn_suspend_enable();
-        exn_raise_by_name("java/lang/InterruptedException");
-
-        return -1;
-    }
-    
-    tmn_suspend_enable(); 
-    assert(tmn_is_suspend_enabled());
-    tm_acquire_tm_lock(); 
-    assert(p_thr->app_status == thread_is_running);
-    if(msec == 0 /*&& nanos == 0 // added for nanos support*/) {
-        p_thr->app_status = thread_is_waiting;
-    } else {
-        p_thr->app_status = thread_is_timed_waiting;
-    }
-    tm_release_tm_lock();
-    tmn_suspend_disable(); 
-    assert(p_thr->notify_recursion_count == 0);
-    assert(mon_wait_array[p_thr->thread_index].p_obj == 0);
-    mon_wait_array[p_thr->thread_index].p_obj = jobj->object;
-    p_thr->notify_recursion_count = RECURSION(jobj->object);
-    RECURSION(jobj->object) = 0;  // leave the recursion at zero for the next lock owner
-
-#ifdef _DEBUG
-    if (p_thr->notify_recursion_count > max_recursion)
-        max_recursion = p_thr->notify_recursion_count;
-#endif
-
-     STACK_KEY(jobj->object) = FREE_MONITOR; // finally, give up the lock
-
-
-    find_an_interested_thread(jobj->object);
-    tmn_suspend_enable();
-
-    TRACE2("wait", "thread going to wait " << p_TLS_vmthread->thread_handle);
-
-    assert(tmn_is_suspend_enabled());
-    p_thr -> is_suspended = true;
-    if (msec == 0)
-    {
-        stat = vm_wait_for_single_object(p_thr->event_handle_notify_or_interrupt, INFINITE);
-        assert(stat == WAIT_OBJECT_0);
-    }
-    else
-    {
-#if defined (__INTEL_COMPILER) 
-#pragma warning( push )
-#pragma warning (disable:1683) // to get rid of remark #1683: explicit conversion of a 64-bit integral type to a smaller integral type
-#endif
-        stat = vm_wait_for_single_object(p_thr->event_handle_notify_or_interrupt, (int)msec); 
-
-#if defined (__INTEL_COMPILER)
-#pragma warning( pop )
-#endif
-
-        assert( (stat == WAIT_OBJECT_0) || (stat == WAIT_TIMEOUT) );
-    }
-    p_thr -> is_suspended = false;
-
-    TRACE2("wait", "thread finished waiting " << p_TLS_vmthread->thread_handle);
-
-#ifdef _DEBUG
-    if (stat == WAIT_OBJECT_0)
-        total_wait_interrupts++;
-    else
-        total_wait_timeouts++;
-#endif
-
-    assert(object_is_valid(jobj));
-    tmn_suspend_disable();
-    //GC may have moved the object sitting in mon_wait_array[], thus reload it
-    assert(mon_wait_array[p_thr->thread_index].p_obj->vt()->clss->vtable->clss->vtable);
-    assert(mon_wait_array[p_thr->thread_index].p_obj == jobj->object); // jobj should have been updated too -salikh
-    
-    mon_wait_array[p_thr->thread_index].p_obj = 0;
-    //do we need to do a p4 sfence here?
-    // lock will do sfence.
-    tmn_suspend_enable();
-    
-    assert(tmn_is_suspend_enabled());
-    tm_acquire_tm_lock();
-
-    assert(p_thr->app_status == thread_is_waiting || p_thr->app_status == thread_is_timed_waiting);
-    p_thr->app_status = thread_is_running;
-
-    // now we need to re-acquire the object lock
-    // since block_on_mon_enter() can block, reload p_obj
-    tm_release_tm_lock(); //with gc_disabled xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-    tmn_suspend_disable();
-
-    block_on_mon_enter(jobj);
-    assert(jobj->object->vt()->clss->vtable->clss->vtable);
-
-    assert(object_locked_by_current_thread(jobj));
-
-    // re-install the recursion count
-    assert(RECURSION(jobj->object) == 0);
-    RECURSION(jobj->object) = (uint8)p_thr->notify_recursion_count;
-
-    p_thr->notify_recursion_count = 0;
-
-    tmn_suspend_enable(); 
-    if ( (stat == WAIT_OBJECT_0) && (p_thr->interrupt_a_waiting_thread == true) )
-    {
-        p_thr->interrupt_a_waiting_thread = false;
-        exn_raise_by_name("java/lang/InterruptedException");
-    }
-
-    return stat;
-
-    // ready to return to java code 
-}
-
 
 long generic_hashcode(ManagedObject * p_obj)
 {
     if (!p_obj) return 0L;
-    if ( HASH_CONTENTION(p_obj) & HASH_MASK)
-        return HASH_CONTENTION(p_obj) & HASH_MASK;
+    if ( *P_HASH_CONTENTION_BYTE(p_obj) & HASH_MASK)
+        return *P_HASH_CONTENTION_BYTE(p_obj) & HASH_MASK;
 
     set_hash_bits(p_obj);
 
-    if ( HASH_CONTENTION(p_obj) & HASH_MASK)
-        return HASH_CONTENTION(p_obj) & HASH_MASK;    
+    if ( *P_HASH_CONTENTION_BYTE(p_obj) & HASH_MASK)
+        return *P_HASH_CONTENTION_BYTE(p_obj) & HASH_MASK;    
     
     ASSERT(0, "All the possible cases are supposed to be covered before");
     return 0xff;
@@ -338,22 +96,10 @@
     return hash;
 }
 
-#define NEW_ARRAY(X) new_arr = jenv->New##X##Array(length); assert(new_arr);        
-
-#define GET_ARRAY_ELEMENTS(X, Y) src_bytes = jenv->Get##X##ArrayElements((j##Y##Array)jobj, &is_copy); \
-    dst_bytes = jenv->Get##X##ArrayElements((j##Y##Array)new_arr, &is_copy);
-
-#define MEMCPY(X) tmn_suspend_disable(); memcpy(dst_bytes, src_bytes, sizeof(j##X) * length); tmn_suspend_enable();
-
-#define RELEASE_ARRAY_ELEMENTS(X, Y) jenv->Release##X##ArrayElements((j##Y##Array)new_arr, (j##Y *) dst_bytes, 0); \
-    jenv->Release##X##ArrayElements((j##Y##Array)jobj, (j##Y *)src_bytes, JNI_ABORT);
-
-#define HANDLE_TYPE_COPY(A, B) NEW_ARRAY(A) GET_ARRAY_ELEMENTS(A, B) MEMCPY(B) RELEASE_ARRAY_ELEMENTS(A, B)
-
 jobject object_clone(JNIEnv *jenv, jobject jobj)
 {
     ManagedObject *result;
-    assert(tmn_is_suspend_enabled());
+    assert(hythread_is_suspend_enabled());
     if(!jobj) {
         // Throw NullPointerException.
         throw_exception_from_jni(jenv, "java/lang/NullPointerException", 0);



Mime
View raw message