harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wjwashb...@apache.org
Subject svn commit: r574297 [1/2] - in /harmony/enhanced/drlvm/trunk: build/make/targets/ vm/gc_gen/src/common/ vm/include/open/ vm/interpreter/src/ vm/port/src/lil/em64t/pim/ vm/port/src/lil/ia32/pim/ vm/port/src/lil/ipf/pim/ vm/tests/unit/thread/ vm/tests/un...
Date Mon, 10 Sep 2007 16:25:31 GMT
Author: wjwashburn
Date: Mon Sep 10 09:25:25 2007
New Revision: 574297

URL: http://svn.apache.org/viewvc?rev=574297&view=rev
Log:
Harmony-4743:  This is the third phase of Thread Lifecycle redesign and cleanup.
The major change is the merging of C structs in the Thread Manager as
well as thread C struct initialization protocol.



Modified:
    harmony/enhanced/drlvm/trunk/build/make/targets/cunit.test.xml
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_platform.h
    harmony/enhanced/drlvm/trunk/vm/include/open/hythread_ext.h
    harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp
    harmony/enhanced/drlvm/trunk/vm/port/src/lil/em64t/pim/m2n_em64t.cpp
    harmony/enhanced/drlvm/trunk/vm/port/src/lil/ia32/pim/m2n_ia32.cpp
    harmony/enhanced/drlvm/trunk/vm/port/src/lil/ipf/pim/m2n_ipf.cpp
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_fat_monitor.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_suspend.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_instrum.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_local_storage.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_monitor_info.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h
    harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.def
    harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.exp
    harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c
    harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_fat_monitor.c
    harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_interrupt.c
    harmony/enhanced/drlvm/trunk/vm/thread/src/thread_private.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/include/finalizer_thread.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_internal.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/include/thread_generic.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/include/thread_manager.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/gc/stop_the_world_root_set_enum.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/finalizer_thread.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/ref_enqueue_thread.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_init.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_shutdown.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_event.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_locals.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_pop_frame.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_roots.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_stack.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_step.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/stack/stack_trace.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_basic.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_iterator.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_monitors.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_instr.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_em64t.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_ia32.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_ipf.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32_em64t/nt_exception_filter_common.cpp

Modified: harmony/enhanced/drlvm/trunk/build/make/targets/cunit.test.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/build/make/targets/cunit.test.xml?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/build/make/targets/cunit.test.xml (original)
+++ harmony/enhanced/drlvm/trunk/build/make/targets/cunit.test.xml Mon Sep 10 09:25:25 2007
@@ -177,6 +177,9 @@
                         </fileset>
 
                         <select os="win">
+                            <select cfg="debug">
+                                <linkerarg value="/DEBUG" />
+                            </select>
                             <libset type="shared" libs="harmonyvm"
                                 dir="${hdk.lib.dir}" />
                             <libset type="shared" libs="hythr"

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_platform.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_platform.h?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_platform.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_platform.h Mon Sep 10 09:25:25 2007
@@ -104,12 +104,10 @@
 
 inline int vm_create_thread(int (*func)(void*), void *data)
 { 
-  hythread_t ret_thread = (hythread_t)STD_CALLOC(1,hythread_get_struct_size());;
-  UDATA stacksize = 0;
-  UDATA priority = 5;
-  
-  return (int)hythread_create_with_group(ret_thread, get_gc_thread_group(), stacksize, priority,  
-                              (hythread_entrypoint_t)func, data);
+  hythread_t ret_thread = (hythread_t)STD_CALLOC(1, hythread_get_struct_size());;
+  assert(ret_thread);
+  return (int)hythread_create_ex(ret_thread, get_gc_thread_group(), 0, 0,
+                    (hythread_entrypoint_t)func, data);
 }
 
 inline void *atomic_casptr(volatile void **mem, void *with, const void *cmp) 

Modified: harmony/enhanced/drlvm/trunk/vm/include/open/hythread_ext.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/include/open/hythread_ext.h?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/include/open/hythread_ext.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/include/open/hythread_ext.h Mon Sep 10 09:25:25 2007
@@ -153,6 +153,14 @@
 #include "hycond_win.h"
 #endif // _WIN32
 
+#ifdef __linux__
+#define osthread_t pthread_t
+#elif _WIN32
+#define osthread_t HANDLE
+#else // !_WIN32 && !__linux__
+#error "threading is only supported on __linux__ or _WIN32"
+#endif // !_WIN32 && !__linux__
+
 #if !defined (_IPF_)
 //use lock reservation
 #define LOCK_RESERVATION
@@ -167,7 +175,189 @@
 
 typedef void (*hythread_event_callback_proc)(void);
 
- 
+/**
+ * Native thread control structure.
+ */
+typedef struct HyThread {
+
+#ifndef POSIX
+    // This is dummy pointer for Microsoft Visual Studio debugging
+    // If this is removed, Visual Studio, when attached to VM, will show
+    // no symbolic information
+    void* reserved;
+#endif
+
+// Public fields exported by HyThread_public. If you change these fields,
+// please, check fields in hythread.h/HyThread_public
+
+    /**
+     * Number of requests made for this thread, it includes both
+     * suspend requests and safe point callback requests.
+     * The field is modified by atomic operations.
+     *
+     * Increment in functions:
+     *    1. send_suspend_request()
+     *          - sets suspend request for a given thread
+     *    2. hythread_set_safepoint_callback()
+     *          - sets safe point callback request for a given thread
+     *
+     * Decrement in functions:
+     *    1. hythread_resume()
+     *          - removes suspend request for a given thread
+     *    2. hythread_exception_safe_point()
+     *          - removes safe point callback request for current thread
+     */
+    uint32 request;
+
+    /**
+     * Field indicating that thread can safely be suspended.
+     * Safe suspension is enabled on value 0.
+     *
+     * The disable_count is increased/decreaded in
+     * hythread_suspend_disable()/hythread_suspend_enable() function
+     * for current thread only.
+     *
+     * Also disable_count could be reset to value 0 and restored in
+     * hythread_set_suspend_disable()/hythread_set_suspend_disable() function
+     * for current thread only.
+     *
+     * Function hythread_exception_safe_point() sets disable_count to
+     * value 1 before safe point callback function calling and restores
+     * it after the call.
+     *
+     * Function thread_safe_point_impl() sets disable_count to
+     * value 0 before entering to the safe point and restores it
+     * after exitting.
+     */
+    int16 disable_count;
+
+    /**
+     * Group for this thread. Different groups are needed in order
+     * to be able to quickly iterate over the specific group.
+     * Examples are: Java threads, GC private threads.
+     * Equal to the address of the head of the list of threads for this group.
+     */
+    hythread_group_t  group;
+
+    /**
+     * Array representing thread local storage
+     */
+    void *thread_local_storage[10];
+
+
+// Private fields
+
+    /**
+     * Each thread keeps a pointer to the library it belongs to.
+     */
+    hythread_library_t library;
+
+// Suspension
+
+    /**
+     * Number of suspend requests made for this thread.
+     * The field is modified by atomic operations.
+     *
+     * After increment/decrement of suspend_count, request field
+     * should be incremented/decremented too.
+     */
+    uint32 suspend_count;
+
+    /**
+     * Function to be executed at safepoint upon thread resume.
+     *
+     * Field is set in hythread_set_safepoint_callback() function
+     * and reset hythread_exception_safe_point() function.
+     *
+     * After set/reset of safepoint_callback, request field
+     * should be incremented/decremented too.
+     */
+    hythread_event_callback_proc safepoint_callback;
+
+    /**
+     * Event used to notify suspended thread that it needs to wake up.
+     */
+    hysem_t resume_event;
+
+// Basic manipulation fields
+
+    /**
+     * Points to the next thread within the group.
+     */
+    hythread_t next;
+
+    /**
+     * Points to the last thread within the group.
+     */
+    hythread_t prev;
+
+    /**
+     * Handle to OS thread.
+     */
+    osthread_t os_handle;
+
+// Synchronization stuff
+
+    /**
+     * Thread local lock, used to serialize thread state;
+     */
+    hymutex_t mutex;
+
+    /**
+     * Conditional variable used to implement wait function for sleep/park;
+     */
+    hycond_t condition;
+
+    /**
+     * Event reserved for threads that invoke join.
+     */
+    hylatch_t join_event;
+
+    /**
+     * Current conditional variable thread is waiting on (used for interrupting)
+     */
+    hycond_t *current_condition;
+
+// State
+
+    /**
+     * Thread state. Holds thread state flags as defined in JVMTI specification, plus some additional
+     * flags. See <a href=http://java.sun.com/j2se/1.5.0/docs/guide/jvmti/jvmti.html#GetThreadState>
+     * JVMTI Specification </a> for more details.
+     */
+    IDATA state;
+
+// Attributes
+
+    /**
+     * Hint for scheduler about thread priority
+     */
+    int priority;
+
+    /**
+     * Flag illustrates that java thread status
+     */
+    int java_status;
+
+    /**
+     * Size of thread's stack, set on creation
+     */
+    UDATA stacksize;
+
+// Monitors
+
+    /**
+     *  Monitor this thread is waiting on now.
+     */
+    hythread_monitor_t waited_monitor;
+
+    /**
+     * ID for this thread. The maximum number of threads is governed by the size of lockword record.
+     */
+    IDATA thread_id;
+
+} HyThread;
+
 //@}
 /** @name Thread Manager initialization / shutdown
  */
@@ -189,8 +379,8 @@
  */
 //@{
 
-IDATA VMCALL hythread_create_with_group(hythread_t new_thread, hythread_group_t group, UDATA stacksize, UDATA priority, hythread_entrypoint_t func, void *data);
-IDATA VMCALL hythread_attach_to_group(hythread_t new_handle, hythread_library_t lib, hythread_group_t group);
+IDATA VMCALL hythread_create_ex(hythread_t new_thread, hythread_group_t group, UDATA stacksize, UDATA priority, hythread_entrypoint_t func, void *data);
+IDATA VMCALL hythread_attach_ex(hythread_t new_handle, hythread_library_t lib, hythread_group_t group);
 UDATA VMCALL hythread_clear_interrupted_other(hythread_t thread);
 IDATA VMCALL hythread_join(hythread_t t);
 IDATA VMCALL hythread_join_timed(hythread_t t, I_64 millis, IDATA nanos);
@@ -423,7 +613,6 @@
     return;
 }
 
-#define TM_THREAD_VM_TLS_KEY 0
 #define TM_THREAD_QUANTITY_OF_PREDEFINED_TLS_KEYS 1
 
  //@}
@@ -432,24 +621,44 @@
   */
 //@{
 
-#define TM_THREAD_STATE_ALIVE JVMTI_THREAD_STATE_ALIVE  // 0x0001 Thread is alive. Zero if thread is new (not started) or terminated.  
-#define TM_THREAD_STATE_TERMINATED JVMTI_THREAD_STATE_TERMINATED // 0x0002Thread has completed execution.  
-#define TM_THREAD_STATE_RUNNABLE JVMTI_THREAD_STATE_RUNNABLE // 0x0004 Thread is runnable.  
-#define TM_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER // 0x0400  Thread is waiting to enter a synchronization block/method or, after an Object.wait(), waiting to re-enter a synchronization block/method.  
-#define TM_THREAD_STATE_WAITING JVMTI_THREAD_STATE_WAITING // 0x0080  Thread is waiting.  
-#define TM_THREAD_STATE_WAITING_INDEFINITELY JVMTI_THREAD_STATE_WAITING_INDEFINITELY // 0x0010  Thread is waiting without a timeout. For example, Object.wait().  
-#define TM_THREAD_STATE_WAITING_WITH_TIMEOUT JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT // 0x0020  Thread is waiting with a maximum time to wait specified. For example, Object.wait(long).  
-#define TM_THREAD_STATE_SLEEPING JVMTI_THREAD_STATE_SLEEPING // 0x0040  Thread is sleeping -- Thread.sleep(long).  
-#define TM_THREAD_STATE_IN_MONITOR_WAIT JVMTI_THREAD_STATE_IN_OBJECT_WAIT // 0x0100  Thread is waiting on an object monitor -- Object.wait.  
-#define TM_THREAD_STATE_PARKED JVMTI_THREAD_STATE_PARKED // 0x0200  Thread is parked, for example: LockSupport.park, LockSupport.parkUtil and LockSupport.parkNanos.  
-#define TM_THREAD_STATE_UNPARKED  0x0800 // 0x0800  Thread is unparked, to track staled unparks;
-#define TM_THREAD_STATE_SUSPENDED JVMTI_THREAD_STATE_SUSPENDED // 0x100000  Thread suspended. java.lang.Thread.suspend() or a JVMTI suspend function (such as SuspendThread) has been called on the thread. If this bit is set, the other bits refer to the thread state before suspension.  
-#define TM_THREAD_STATE_INTERRUPTED JVMTI_THREAD_STATE_INTERRUPTED // 0x200000  Thread has been interrupted.  
-#define TM_THREAD_STATE_IN_NATIVE JVMTI_THREAD_STATE_IN_NATIVE // 0x400000  Thread is in native code--that is, a native method is running which has not called back into the VM or Java programming language code. 
-
-#define TM_THREAD_STATE_ALLOCATED JVMTI_THREAD_STATE_VENDOR_1 // 0x10000000 Thread just has been allocated.
-#define TM_THREAD_STATE_RESERVED1 JVMTI_THREAD_STATE_VENDOR_2 // 0x20000000 Defined by VM vendor.  
-#define TM_THREAD_STATE_RESERVED2 JVMTI_THREAD_STATE_VENDOR_3 // 0x40000000 Defined by VM vendor 
+// 0x00000000   Thread is new.
+#define TM_THREAD_STATE_NEW                      0
+// 0x00000001   Thread is alive. Zero if thread is new (not started) or terminated.
+#define TM_THREAD_STATE_ALIVE                    JVMTI_THREAD_STATE_ALIVE
+// 0x00000002   Thread has completed execution.
+#define TM_THREAD_STATE_TERMINATED               JVMTI_THREAD_STATE_TERMINATED
+// 0x00000004   Thread is runnable.
+#define TM_THREAD_STATE_WAITING                  JVMTI_THREAD_STATE_WAITING
+// 0x00000010   Thread is waiting without a timeout. For example, Object.wait().
+#define TM_THREAD_STATE_WAITING_INDEFINITELY     JVMTI_THREAD_STATE_WAITING_INDEFINITELY
+// 0x00000020   Thread is waiting with a maximum time to wait specified.
+//              For example, Object.wait(long).
+#define TM_THREAD_STATE_WAITING_WITH_TIMEOUT     JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT
+// 0x00000040   Thread is sleeping. For example, Thread.sleep(long).
+#define TM_THREAD_STATE_RUNNABLE                 JVMTI_THREAD_STATE_RUNNABLE
+// 0x00000080   Thread is waiting.
+#define TM_THREAD_STATE_SLEEPING                 JVMTI_THREAD_STATE_SLEEPING
+// 0x00000100   Thread is waiting on an object monitor -- Object.wait.
+#define TM_THREAD_STATE_IN_MONITOR_WAIT          JVMTI_THREAD_STATE_IN_OBJECT_WAIT
+// 0x00000200   Thread is parked.
+//              For example: LockSupport.park, LockSupport.parkUtil and LockSupport.parkNanos.
+#define TM_THREAD_STATE_PARKED                   JVMTI_THREAD_STATE_PARKED
+// 0x00000400   Thread is waiting to enter a synchronization block/method or,
+//              after an Object.wait(), waiting to re-enter a synchronization block/method.
+#define TM_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER
+// 0x00000800   Thread is unparked, to track staled unparks
+#define TM_THREAD_STATE_UNPARKED                 0x0800
+// 0x00100000   Thread suspended.
+//              For example, java.lang.Thread.suspend()
+//              or a JVMTI suspend function (such as SuspendThread)
+//              has been called on the thread. If this bit is set,
+//              the other bits refer to the thread state before suspension.
+#define TM_THREAD_STATE_SUSPENDED                JVMTI_THREAD_STATE_SUSPENDED
+// 0x00200000   Thread has been interrupted.
+#define TM_THREAD_STATE_INTERRUPTED              JVMTI_THREAD_STATE_INTERRUPTED
+// 0x00400000   Thread is in native code. That is a native method is running which
+//              has not called back into the VM or Java programming language code.
+#define TM_THREAD_STATE_IN_NATIVE                JVMTI_THREAD_STATE_IN_NATIVE
 
 #define TM_MUTEX_DEFAULT  0   
 #define TM_MUTEX_NESTED   1  
@@ -485,6 +694,11 @@
 
 // if default stack size is not through -Xss parameter, it is 256kb
 #define TM_DEFAULT_STACKSIZE (512 * 1024)
+
+// java thread status
+#define TM_STATUS_WITHOUT_JAVA  0   // native thread cannot has associated java thread
+#define TM_STATUS_ALLOCATED     1   // associated java thread is allocated
+#define TM_STATUS_INITIALIZED   2   // associated java thread is initialized
 
 #if defined(__cplusplus)
 }

Modified: harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp Mon Sep 10 09:25:25 2007
@@ -2501,10 +2501,10 @@
 void UNUSED dump_all_java_stacks() {
     hythread_iterator_t  iterator;
     hythread_suspend_all(&iterator, NULL);
-    VM_thread *thread = get_vm_thread (hythread_iterator_next(&iterator));
+    VM_thread *thread = jthread_get_vm_thread(hythread_iterator_next(&iterator));
     while(thread) {
         stack_dump(thread);
-        thread = get_vm_thread (hythread_iterator_next(&iterator));
+        thread = jthread_get_vm_thread(hythread_iterator_next(&iterator));
     }
 
     hythread_resume_all( NULL);

Modified: harmony/enhanced/drlvm/trunk/vm/port/src/lil/em64t/pim/m2n_em64t.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/src/lil/em64t/pim/m2n_em64t.cpp?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/port/src/lil/em64t/pim/m2n_em64t.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/port/src/lil/em64t/pim/m2n_em64t.cpp Mon Sep 10 09:25:25 2007
@@ -54,7 +54,8 @@
 }
 
 void m2n_set_last_frame(M2nFrame * lm2nf) {
-    p_TLS_vmthread->last_m2n_frame = lm2nf;
+    vm_thread_t vm_thread = jthread_self_vm_thread_unsafe();
+    vm_thread->last_m2n_frame = lm2nf;
 }
 
 M2nFrame * m2n_get_previous_frame(M2nFrame * m2nf) {

Modified: harmony/enhanced/drlvm/trunk/vm/port/src/lil/ia32/pim/m2n_ia32.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/src/lil/ia32/pim/m2n_ia32.cpp?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/port/src/lil/ia32/pim/m2n_ia32.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/port/src/lil/ia32/pim/m2n_ia32.cpp Mon Sep 10 09:25:25 2007
@@ -57,7 +57,8 @@
 VMEXPORT // temporary solution for interpreter unplug
 void m2n_set_last_frame(M2nFrame* lm2nf)
 {
-    p_TLS_vmthread->last_m2n_frame = lm2nf;
+    vm_thread_t vm_thread = jthread_self_vm_thread_unsafe();
+    vm_thread->last_m2n_frame = lm2nf;
 }
 
 VMEXPORT

Modified: harmony/enhanced/drlvm/trunk/vm/port/src/lil/ipf/pim/m2n_ipf.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/src/lil/ipf/pim/m2n_ipf.cpp?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/port/src/lil/ipf/pim/m2n_ipf.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/port/src/lil/ipf/pim/m2n_ipf.cpp Mon Sep 10 09:25:25 2007
@@ -103,7 +103,8 @@
 VMEXPORT // temporary solution for interpreter unplug
 void m2n_set_last_frame(M2nFrame* lm2nf)
 {
-    p_TLS_vmthread->last_m2n_frame = lm2nf;
+    vm_thread_t vm_thread = jthread_self_vm_thread_unsafe();
+    vm_thread->last_m2n_frame = lm2nf;
 }
 
 VMEXPORT

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c Mon Sep 10 09:25:25 2007
@@ -176,7 +176,7 @@
         check_tested_thread_phase(tts, TT_PHASE_ANY);
         hythread = vm_jthread_get_tm_data(tts->java_thread);
         tf_assert(hythread);
-        vm_thread = (vm_thread_t)hythread_tls_get(hythread, TM_THREAD_VM_TLS_KEY);
+        vm_thread = jthread_get_vm_thread(hythread);
         tf_assert(vm_thread);
         tf_assert(vm_objects_are_equal(excn, vm_thread->stop_exception));
     }
@@ -219,8 +219,7 @@
 
         hythread = vm_jthread_get_tm_data(tts->java_thread);
         tf_assert(hythread);
-        vm_thread =
-            (vm_thread_t)hythread_tls_get(hythread, TM_THREAD_VM_TLS_KEY);
+        vm_thread = jthread_get_vm_thread(hythread);
         tf_assert(vm_thread);
         stop_excn_class = (*env)->CallObjectMethod(env,
             vm_thread->stop_exception, getClassId);

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_basic.c Mon Sep 10 09:25:25 2007
@@ -16,9 +16,6 @@
  */
 
 #include <stdio.h>
-#include <apr_pools.h>
-#include <apr_time.h>
-#include <open/hythread_ext.h>
 #include "testframe.h"
 #include "thread_manager.h"
 
@@ -38,29 +35,26 @@
  * Test tm_create(..)
  */
 int test_hythread_create(void){
-    apr_pool_t *pool;
     void **args; 
     hythread_t thread;
-    IDATA r;
+    IDATA res;
     
-    apr_pool_create(&pool, NULL);
-
-    args = (void**) apr_palloc(pool, sizeof(void *) *2); 
+    args = (void**)calloc(2, sizeof(void *));
     
     hythread_group_create((hythread_group_t *)&args[0]); 
     
-    args[1] = apr_palloc(pool, sizeof(jthread_threadattr_t));
+    args[1] = calloc(1, sizeof(jthread_threadattr_t));
     ((jthread_threadattr_t *)args[1])->stacksize = 1024000;
     ((jthread_threadattr_t *)args[1])->priority  = 1;
     
     thread = (hythread_t)calloc(1, hythread_get_struct_size());
     assert(thread);
-    r = hythread_create_with_group(thread, args[0], 1024000, 1,
+    res = hythread_create_ex(thread, args[0], 1024000, 1,
         (hythread_entrypoint_t)start_proc, args);
-    tf_assert(r == 0 && "thread creation failed");
+    tf_assert(res == TM_ERROR_NONE && "thread creation failed");
 
-    r = hythread_join(thread);
-    tf_assert(r == 0 && "thread join failed");
+    res = hythread_join(thread);
+    tf_assert(res == TM_ERROR_NONE && "thread join failed");
     return TEST_PASSED;
 }
 
@@ -89,10 +83,10 @@
         if (n <= count)
             break;
 
-        apr_sleep(1000); // 1ms
+        hythread_sleep(1); // 1ms
     }
 
-    apr_sleep(100000);// 0.1s to let system threads finish their work
+    hythread_sleep(100);// 0.1s to let system threads finish their work
 }
 
 hylatch_t start;
@@ -110,10 +104,12 @@
     hylatch_create(&end, 1);
 
     for (i = 0; i < n; i++) {
+        IDATA status;
         thread = (hythread_t)calloc(1, hythread_get_struct_size());
         assert(thread);
-        hythread_create_with_group(thread, group, 0, 0,
+        status = hythread_create_ex(thread, group, 0, 0,
             (hythread_entrypoint_t)start_proc_empty, NULL);
+        tf_assert_same(status, TM_ERROR_NONE);
     }
 
     // Wait util all threads have started.
@@ -150,10 +146,10 @@
     hylatch_create(&end, 1);
 
     for (i = 0; i < n; i++) {
-        thread = (hythread_t)calloc(1, hythread_get_struct_size());
-        assert(thread);
-        hythread_create_with_group(thread, NULL, 0, 0,
+        IDATA status;
+        status = hythread_create(NULL, 0, 0, 0,
             (hythread_entrypoint_t)start_proc_empty, NULL);
+        tf_assert_same(status, TM_ERROR_NONE);
     }
 
     // Wait util all threads have started.
@@ -185,40 +181,29 @@
  * Test tm_create(..)
  */
 int test_hythread_create_many(void){
-    apr_pool_t *pool;
     void **args; 
     hythread_t thread = NULL;
     hythread_group_t group = NULL;
-    IDATA r;
-    
-    char *buf;
+    IDATA res;
     int i = 10;
     
     hythread_group_create(&group);
     while(i--) {
-        apr_pool_create(&pool, NULL);
-
-        args = (void**) apr_palloc(pool, sizeof(void *) *2); 
+        args = (void**)calloc(2, sizeof(void *));
     
         args[0] = group; 
         
-        args[1] = apr_palloc(pool, sizeof(jthread_threadattr_t));
+        args[1] = calloc(1, sizeof(jthread_threadattr_t));
         ((jthread_threadattr_t *)args[1])->stacksize = 1024000;
         ((jthread_threadattr_t *)args[1])->priority  = 1;
         
         thread = (hythread_t)calloc(1, hythread_get_struct_size());
         assert(thread);
-        r = hythread_create_with_group(thread, group, 1024000, 1,
+        res = hythread_create_ex(thread, group, 1024000, 1,
             (hythread_entrypoint_t)start_proc, args);
-        tf_assert(r == 0 && "thread creation failed");
-        buf = (char *)apr_pcalloc(pool, sizeof(char)*12);
-
-        /*
-          sprintf(buf, "Thread %d\0", i);
-          hythread_set_name(thread, buf);
-        */
-        r = hythread_join(thread);
-        tf_assert(r == 0 && "thread join failed");
+        tf_assert(res == TM_ERROR_NONE && "thread creation failed");
+        res = hythread_join(thread);
+        tf_assert(res == TM_ERROR_NONE && "thread join failed");
     }
 
     //check thread structures:

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_fat_monitor.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_fat_monitor.c?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_fat_monitor.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_fat_monitor.c Mon Sep 10 09:25:25 2007
@@ -17,14 +17,13 @@
 
 #include "thread_manager.h"
 #include "testframe.h"
-#include "open/jthread.h"
 #include <open/hythread_ext.h>
 
 #define NMB 5
 
 hythread_monitor_t monitor;
-apr_thread_mutex_t *mutex;
-apr_thread_cond_t  *condvar;
+hymutex_t *mutex;
+hycond_t  *condvar;
 int waiting_count;
 
 int run_for_test_wait_signal(void *args) {
@@ -53,17 +52,15 @@
     hythread_t threads[NMB];
     int i;
 
-    //log_error("BUG IN APR");
-    //tf_assert(0);
     status = hythread_monitor_init(&monitor, 0);
     tf_assert_same(status, TM_ERROR_NONE);
     waiting_count = 0;
 
-    for (i = 0; i < NMB; i++){
-        threads[i] = (hythread_t)calloc(1, hythread_get_struct_size());
-        assert(threads[i]);
-        hythread_create_with_group(threads[i], NULL, 0, 0,
+    for (i = 0; i < NMB; i++) {
+        threads[i] = NULL;
+        status = hythread_create(&threads[i], 0, 0, 0,
             (hythread_entrypoint_t)run_for_test_wait_signal, NULL);
+        tf_assert_same(status, TM_ERROR_NONE);
     }
 
     // Wait till all tested threads call wait() 
@@ -76,7 +73,7 @@
         status = hythread_monitor_exit(monitor);
         tf_assert_same(status, TM_ERROR_NONE);
 
-        jthread_sleep(100, 0);
+        hythread_sleep(100);
     }
     status = hythread_monitor_exit(monitor);
 
@@ -95,82 +92,12 @@
         tf_assert_same(status, TM_ERROR_NONE);
     }
     for (i = 0; i < NMB; i++){
-        jthread_sleep(100, 0);
+        hythread_sleep(100);
         hythread_join(threads[i]);
     }
     return 0;
 }
 
-void * APR_THREAD_FUNC run_for_test_apr_wait_signal(apr_thread_t *thread, void *args) {
-
-    apr_status_t status;
-
-    status = apr_thread_mutex_lock(mutex);
-    waiting_count ++;
-
-    status = apr_thread_cond_wait(condvar, mutex);
-
-    waiting_count --;
-    status = apr_thread_mutex_unlock(mutex);
-
-    printf("------ waiting_count = %i\n", waiting_count);
-
-    return NULL;
-}
-
-int test_apr_wait_signal(void){
-
-    apr_thread_t *threads[NMB];
-    apr_threadattr_t *apr_attrs = NULL;
-    apr_status_t status;
-    apr_pool_t *pool;
-    int i;
-    int all_are_waiting;
-
-    log_error("BUG IN APR");
-    tf_assert(0);
-    waiting_count = 0;
-    status = apr_pool_create(&pool, NULL);
-    status = apr_thread_mutex_create(&mutex, TM_MUTEX_NESTED, pool);
-    status = apr_thread_cond_create(&condvar, pool);
-
-    for (i = 0; i < NMB; i++){
-        threads[i] = NULL;
-        // Create APR thread
-        status = apr_thread_create(
-                                   &threads[i],// new thread OS handle 
-                                   apr_attrs,
-                                   run_for_test_apr_wait_signal, // start proc
-                                   NULL,                         //start proc arg 
-                                   pool
-                                   ); 
-    }
-    all_are_waiting = 0;
-    while (!all_are_waiting){
-        status = apr_thread_mutex_lock(mutex);
-        if (waiting_count == NMB) all_are_waiting = 1;
-        status = apr_thread_mutex_unlock(mutex);
-        jthread_sleep(100, 0);
-    }
-    for (i = 0; i < NMB; i++){
-        jthread_sleep(100, 0);
-        status = apr_thread_mutex_lock(mutex);
-        apr_thread_cond_signal(condvar);
-        status = apr_thread_mutex_unlock(mutex);
-    }
-
-    //status = apr_thread_mutex_lock(mutex);
-    //apr_thread_cond_broadcast(condvar);
-    //status = apr_thread_mutex_unlock(mutex);
-
-    for (i = 0; i < NMB; i++){
-        jthread_sleep(100, 0);
-        apr_thread_join(&status, threads[i]);
-    }
-    return 0;
-}
-
 TEST_LIST_START
     TEST(test_wait_signal)
-    //TEST(test_apr_wait_signal)
 TEST_LIST_END;

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_suspend.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_suspend.c?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_suspend.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_suspend.c Mon Sep 10 09:25:25 2007
@@ -16,123 +16,218 @@
  */
 
 #include <stdio.h>
-#include <apr_pools.h>
-#include <apr_atomic.h>
 #include <open/hythread_ext.h>
 #include "testframe.h"
 #include "thread_manager.h"
 
-int start_proc(void *);
-
+int started_thread_count;
 int start_proc(void *args);
+
 int test_hythread_thread_suspend(void){
-    apr_pool_t *pool;
     void **args; 
-    hythread_t thread;
-    hythread_thin_monitor_t lockword_ptr;
+    hythread_t thread = NULL;
+    hythread_thin_monitor_t lock;
+    hythread_thin_monitor_t monitor;
     IDATA status;
     int i;
-    apr_pool_create(&pool, NULL);
 
-    args = (void**) apr_palloc(pool, sizeof(void *) *3); 
-    
-    status = hythread_thin_monitor_create(&lockword_ptr);
+    // create monitors
+    status = hythread_thin_monitor_create(&lock);
+    tf_assert_same(status, TM_ERROR_NONE);
+    status = hythread_thin_monitor_create(&monitor);
     tf_assert_same(status, TM_ERROR_NONE);
 
-    args[0] = &lockword_ptr;
-    args[1] = 0;
-    thread = (hythread_t)calloc(1, hythread_get_struct_size());
-    assert(thread);
-    hythread_create_with_group(thread, NULL, 0, 0,
-        (hythread_entrypoint_t)start_proc, args);
-    hythread_sleep(500); 
-    hythread_suspend_other(thread);
+    // alloc and set thread start procedure args
+    args = (void**)calloc(3, sizeof(void*));
+    args[0] = &lock;
+    args[1] = &monitor;
+    args[2] = 0;
+
+    // create thread
     hythread_suspend_disable();
-    status = hythread_thin_monitor_enter(&lockword_ptr);
+    status = hythread_thin_monitor_enter(&lock);
+    tf_assert_same(status, TM_ERROR_NONE);
+    hythread_suspend_enable();
+
+    status = hythread_create(&thread, 0, 0, 0,
+        (hythread_entrypoint_t)start_proc, args);
     tf_assert_same(status, TM_ERROR_NONE);
-    status = hythread_thin_monitor_notify_all(&lockword_ptr);
+
+    // waiting start of tested thread
+    hythread_suspend_disable();
+    status = hythread_thin_monitor_wait(&lock);
     tf_assert_same(status, TM_ERROR_NONE);
-    status = hythread_thin_monitor_exit(&lockword_ptr);
+
+    status = hythread_thin_monitor_exit(&lock);
     tf_assert_same(status, TM_ERROR_NONE);
     hythread_suspend_enable();
+
+    // suspend tested thread
+    status = hythread_suspend_other(thread);
     tf_assert_same(status, TM_ERROR_NONE);
 
+    // notify tested thread
+    hythread_suspend_disable();
+    status = hythread_thin_monitor_enter(&monitor);
+    tf_assert_same(status, TM_ERROR_NONE);
+    status = hythread_thin_monitor_notify_all(&monitor);
+    tf_assert_same(status, TM_ERROR_NONE);
+    status = hythread_thin_monitor_exit(&monitor);
+    tf_assert_same(status, TM_ERROR_NONE);
+    hythread_suspend_enable();
 
-    for(i = 0; i < 100000; i++) {
-        tf_assert_same(args[1], 0);
+    // check tested argument
+    for(i = 0; i < 1000; i++) {
+        tf_assert_same(args[2], 0);
+        hythread_sleep(1);
     }
-    
+
+    // resume thread
     hythread_resume(thread);
+
+    status = hythread_join(thread);
+    tf_assert_same(status, TM_ERROR_NONE);
     
-    hythread_join(thread);
-    
-    tf_assert_same((IDATA)args[1], 1);
+    tf_assert_same((IDATA)args[2], 1);
 
     return 0;
 }
 
+#define THREAD_COUNT 10
 
-int test_hythread_thread_suspend_all(void){
-    apr_pool_t *pool;
+int test_hythread_thread_suspend_all(void)
+{
     void **args; 
-    hythread_t thread = NULL;
-    hythread_thin_monitor_t *lockword_ptr;
+    hythread_t thread_list[THREAD_COUNT];
+    hythread_thin_monitor_t lock;
+    hythread_thin_monitor_t monitor;
     IDATA status;
     int i;
-    apr_pool_create(&pool, NULL);
 
-    args = (void**) apr_palloc(pool, sizeof(void *) *3); 
-    lockword_ptr = (hythread_thin_monitor_t *) apr_palloc(pool, sizeof(hythread_thin_monitor_t)); 
-    status = hythread_thin_monitor_create(lockword_ptr);
+    // create monitors
+    status = hythread_thin_monitor_create(&monitor);
+    tf_assert_same(status, TM_ERROR_NONE);
+    status = hythread_thin_monitor_create(&lock);
+    tf_assert_same(status, TM_ERROR_NONE);
+
+    // alloc and set thread start procedure args
+    args = (void**)calloc(3, sizeof(void*));
+    args[0] = &lock;
+    args[1] = &monitor;
+    args[2] = 0;
+
+    // create threads
+    hythread_suspend_disable();
+    status = hythread_thin_monitor_enter(&lock);
     tf_assert_same(status, TM_ERROR_NONE);
+    hythread_suspend_enable();
 
-    args[0] = lockword_ptr;
-    args[1] = 0;
-    for(i = 0; i < 10; i++) {
-        thread = (hythread_t)calloc(1, hythread_get_struct_size());
-        assert(thread);
-        hythread_create_with_group(thread, NULL, 0, 0,
+    started_thread_count = 0;
+    for(i = 0; i < THREAD_COUNT; i++) {
+        thread_list[i] = NULL;
+        status = hythread_create(&thread_list[i], 0, 0, 0,
             (hythread_entrypoint_t)start_proc, args);
+        tf_assert_same(status, TM_ERROR_NONE);
+        log_info("%d thread is started", i + 1);
     } 
-    hythread_sleep(500); 
-    hythread_suspend_all(NULL, ((HyThread_public*)hythread_self())->group);
+
+    // waiting start of tested thread
     hythread_suspend_disable();
-    status = hythread_thin_monitor_enter(lockword_ptr);
+    while (started_thread_count < 10) {
+        status = hythread_thin_monitor_wait(&lock);
+        tf_assert_same(status, TM_ERROR_NONE);
+    }
+
+    status = hythread_thin_monitor_exit(&lock);
     tf_assert_same(status, TM_ERROR_NONE);
-    status = hythread_thin_monitor_notify_all(lockword_ptr);
+    hythread_suspend_enable();
+
+    // suspend tested thread
+    status = hythread_suspend_all(NULL, ((HyThread_public*)hythread_self())->group);
     tf_assert_same(status, TM_ERROR_NONE);
-    status = hythread_thin_monitor_exit(lockword_ptr);
+    log_info("all threads are suspended");
+
+    // notify tested threads
+    hythread_suspend_disable();
+    status = hythread_thin_monitor_enter(&monitor);
     tf_assert_same(status, TM_ERROR_NONE);
-    hythread_suspend_enable();
+    status = hythread_thin_monitor_notify_all(&monitor);
     tf_assert_same(status, TM_ERROR_NONE);
+    status = hythread_thin_monitor_exit(&monitor);
+    tf_assert_same(status, TM_ERROR_NONE);
+    hythread_suspend_enable();
+    log_info("notify all suspended threads");
+
+    // check tested argument
+    for(i = 0; i < 1000; i++) {
+        tf_assert_same(args[2], 0);
+        hythread_sleep(1);
+    }
 
+    // resume thread
+    status = hythread_resume_all(((HyThread_public*)hythread_self())->group);
+    tf_assert_same(status, TM_ERROR_NONE);
+    log_info("resume all suspended threads");
 
-    for(i = 0; i < 100000; i++) {
-        tf_assert_same(args[1], 0);
+    for(i = 0; i < THREAD_COUNT; i++) {
+        status = hythread_join(thread_list[i]);
+        tf_assert_same(status, TM_ERROR_NONE);
+        log_info("%d thread is terminated", i + 1);
     }
-    
-    hythread_resume_all(((HyThread_public*)hythread_self())->group);
-    
-    hythread_join(thread);
-    
-    tf_assert_same((IDATA)args[1], 1);
+
+    tf_assert_same((IDATA)args[2], THREAD_COUNT);
 
     return 0;
 }
 
-int start_proc(void *args) {
-    hythread_thin_monitor_t *lockword_ptr = (hythread_thin_monitor_t*)((void**)args)[0];
-    IDATA *ret =  (IDATA*)args+1;
+int start_proc(void *args)
+{
+    hythread_thin_monitor_t *lock_p = (hythread_thin_monitor_t*)((void**)args)[0];
+    hythread_thin_monitor_t *monitor_p = (hythread_thin_monitor_t*)((void**)args)[1];
+    IDATA *ret =  (IDATA*)&(((void**)args)[2]);
     IDATA status;
-        
-    //wait to start
-       hythread_suspend_disable();
-    status = hythread_thin_monitor_enter(lockword_ptr);
-    hythread_thin_monitor_wait(lockword_ptr);
-    tf_assert_same(status, TM_ERROR_NONE);
-    status = hythread_thin_monitor_exit(lockword_ptr);
-    tf_assert_same(status, TM_ERROR_NONE);
-    *ret =1;
+
+    // wait to start
+    hythread_suspend_disable();
+
+    status = hythread_thin_monitor_enter(monitor_p);
+    if (status != TM_ERROR_NONE) {
+        hythread_suspend_enable();
+        tf_assert_same(status, TM_ERROR_NONE);
+    }
+
+    // notify main thread about thread start
+    status = hythread_thin_monitor_enter(lock_p);
+    if (status != TM_ERROR_NONE) {
+        hythread_suspend_enable();
+        tf_assert_same(status, TM_ERROR_NONE);
+    }
+    started_thread_count++;
+    status = hythread_thin_monitor_notify(lock_p);
+    if (status != TM_ERROR_NONE) {
+        hythread_suspend_enable();
+        tf_assert_same(status, TM_ERROR_NONE);
+    }
+    status = hythread_thin_monitor_exit(lock_p);
+    if (status != TM_ERROR_NONE) {
+        hythread_suspend_enable();
+        tf_assert_same(status, TM_ERROR_NONE);
+    }
+
+    // fall to infinite wait
+    status = hythread_thin_monitor_wait(monitor_p);
+    if (status != TM_ERROR_NONE) {
+        hythread_suspend_enable();
+        tf_assert_same(status, TM_ERROR_NONE);
+    }
+
+    (*ret)++;
+
+    status = hythread_thin_monitor_exit(monitor_p);
+    if (status != TM_ERROR_NONE) {
+        hythread_suspend_enable();
+        tf_assert_same(status, TM_ERROR_NONE);
+    }
     hythread_suspend_enable();
 
     return 0;

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_native_thin_monitor.c Mon Sep 10 09:25:25 2007
@@ -16,8 +16,6 @@
  */
 
 #include <stdio.h>
-#include <apr_pools.h>
-#include <apr_atomic.h>
 #include "testframe.h"
 #include <open/hythread_ext.h>
 
@@ -117,15 +115,13 @@
 
 int start_proc(void *args);
 int test_hythread_thin_monitor_enter_contended(void){
-    apr_pool_t *pool;
     void **args; 
-    hythread_t thread;
+    hythread_t thread = NULL;
     hythread_thin_monitor_t lockword_ptr;
     IDATA status;
     int i;
-    apr_pool_create(&pool, NULL);
 
-    args = (void**) apr_palloc(pool, sizeof(void *) *3); 
+    args = (void**)calloc(3, sizeof(void *));
     
     status = hythread_thin_monitor_create(&lockword_ptr);
     tf_assert_same(status, TM_ERROR_NONE);
@@ -137,9 +133,7 @@
 
     args[0] = &lockword_ptr;
     args[1] = 0;
-    thread = (hythread_t)calloc(1, hythread_get_struct_size());
-    assert(thread);
-    status = hythread_create_with_group(thread, NULL, 0, 0,
+    status = hythread_create(&thread, 0, 0, 0,
         (hythread_entrypoint_t)start_proc, args);
     tf_assert_same(status, TM_ERROR_NONE);
     for(i = 0; i < 100000; i++) {
@@ -157,7 +151,7 @@
     tf_assert_same(status, TM_ERROR_NONE);
     args[1] = 0;
     hythread_suspend_enable();    
-    status = hythread_create_with_group(thread, NULL, 0, 0,
+    status = hythread_create_ex(thread, NULL, 0, 0,
         (hythread_entrypoint_t)start_proc, args);
     tf_assert_same(status, TM_ERROR_NONE);
     for(i = 0; i < 100000; i++) {

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_instrum.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_instrum.c?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_instrum.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_instrum.c Mon Sep 10 09:25:25 2007
@@ -181,11 +181,9 @@
     int dead_list_count;
     jthread *dead_list;
     int i = 0;
-    apr_status_t apr_status;
-    apr_pool_t *pool = NULL;
 
-    apr_status = apr_pool_create(&pool, NULL);
-    thread_list = apr_palloc(pool, sizeof(int) * MAX_TESTED_THREAD_NUMBER);
+    thread_list =
+        (jthread*)calloc(MAX_TESTED_THREAD_NUMBER, sizeof(int));
 
     // Initialize tts structures and run all tested threads
     tested_threads_run_with_different_monitors(run_for_test_jthread_get_deadlocked_threads);

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_local_storage.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_local_storage.c?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_local_storage.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_local_storage.c Mon Sep 10 09:25:25 2007
@@ -19,7 +19,7 @@
 #include "testframe.h"
 #include "thread_unit_test_utils.h"
 
-#define TEST_TLS_KEY (TM_THREAD_VM_TLS_KEY + 1)
+#define TEST_TLS_KEY (TM_THREAD_QUANTITY_OF_PREDEFINED_TLS_KEYS + 1)
 
 /*
  * Test test_jthread_set_and_get_local_storage

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_monitor_info.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_monitor_info.c?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_monitor_info.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_ti_monitor_info.c Mon Sep 10 09:25:25 2007
@@ -66,12 +66,17 @@
 
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
-            tf_assert_same(jthread_get_contended_monitor(tts->java_thread, &contended_monitor), TM_ERROR_NONE);
+            while(tts->phase == TT_PHASE_NONE) {
+                // thread is not started yet
+                hythread_yield();
+            }
             if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
+                tf_assert_same(jthread_get_contended_monitor(tts->java_thread,
+                    &contended_monitor), TM_ERROR_NONE);
                 tf_assert_null(contended_monitor);
                 tf_assert_null(critical_tts);
                 critical_tts = tts;
-            } else if (tts->phase != TT_PHASE_DEAD){
+            } else if (tts->phase != TT_PHASE_DEAD) {
                 check_tested_thread_phase(tts, TT_PHASE_WAITING_ON_MONITOR);
                 // This can't be guaranteed
                 //tf_assert(vm_objects_are_equal(contended_monitor, tts->monitor));
@@ -130,6 +135,10 @@
 
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
+            while(tts->phase == TT_PHASE_NONE) {
+                // thread is not started yet
+                hythread_yield();
+            }
             if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
                 tf_assert(jthread_holds_lock(tts->java_thread, tts->monitor) > 0);
                 tf_assert_null(critical_tts);
@@ -198,6 +207,10 @@
 
         reset_tested_thread_iterator(&tts);
         while(next_tested_thread(&tts)){
+            while(tts->phase == TT_PHASE_NONE) {
+                // thread is not started yet
+                hythread_yield();
+            }
             if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
                 tf_assert_null(critical_tts);
                 critical_tts = tts;
@@ -261,15 +274,21 @@
         hysem_wait(mon_enter);
 
         reset_tested_thread_iterator(&tts);
-        while(next_tested_thread(&tts)){
-            tf_assert_same(jthread_get_owned_monitors (tts->java_thread, 
-                                                       &owned_monitors_count, &owned_monitors), TM_ERROR_NONE);
+        while(next_tested_thread(&tts)) {
+            while(tts->phase == TT_PHASE_NONE) {
+                // thread is not started yet
+                hythread_yield();
+            }
             if (tts->phase == TT_PHASE_IN_CRITICAL_SECTON){
+                tf_assert_same(jthread_get_owned_monitors (tts->java_thread,
+                    &owned_monitors_count, &owned_monitors), TM_ERROR_NONE);
                 tf_assert(critical_tts == NULL);
                 critical_tts = tts;
                 tf_assert_same(owned_monitors_count, 1);
                 tf_assert_same(owned_monitors[0]->object, tts->monitor->object);
             } else if (tts->phase == TT_PHASE_WAITING_ON_MONITOR){
+                tf_assert_same(jthread_get_owned_monitors (tts->java_thread,
+                    &owned_monitors_count, &owned_monitors), TM_ERROR_NONE);
                 tf_assert_same(owned_monitors_count, 0);
             }
         }

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.c Mon Sep 10 09:25:25 2007
@@ -24,8 +24,7 @@
 #include "open/hythread_ext.h"
 #include "open/ti_thread.h"
 #include "open/thread_externals.h"
-#include "apr_time.h"
-
+#include "thread_manager.h"
 
 /*
  * Utilities for thread manager unit tests 
@@ -36,10 +35,8 @@
 tested_thread_sturct_t tested_threads[MAX_TESTED_THREAD_NUMBER];
 JavaVM * GLOBAL_VM = NULL;
 
-apr_pool_t *pool = NULL;
-
 void sleep_a_click(void){
-    apr_sleep(CLICK_TIME_MSEC * 1000);
+    hythread_sleep(CLICK_TIME_MSEC);
 }
 
 jthread new_jobject_thread(JNIEnv * jni_env) {
@@ -64,25 +61,20 @@
     return (*jni_env)->NewObject(jni_env, thread_death_class, constructor);
 }
 
-jthread new_jobject(){
-
-    apr_status_t status;
-    _jobject *obj;
-    _jjobject *object;
-
-    if (!pool){
-        status = apr_pool_create(&pool, NULL);
-        if (status) return NULL; 
-    }
-
-    obj = apr_palloc(pool, sizeof(_jobject));
-    object = apr_palloc(pool, sizeof(_jjobject));
-    assert(obj);
-    obj->object = object;
-    obj->object->data = NULL;
-    obj->object->daemon = 0;
-    obj->object->name = NULL;
-    return obj;
+jthread new_jobject()
+{
+    _jobject *jobj;
+    _jjobject *jjobj;
+
+    jobj = (_jobject *)calloc(1, sizeof(_jobject));
+    jjobj = (_jjobject *)calloc(1, sizeof(_jjobject));
+    assert(jobj);
+    assert(jjobj);
+    jobj->object = jjobj;
+    jobj->object->data = NULL;
+    jobj->object->daemon = 0;
+    jobj->object->name = NULL;
+    return jobj;
 }
 
 void delete_jobject(jobject obj){
@@ -105,7 +97,6 @@
     log_debug("test_java_thread_init()");
 
     hythread_sleep(1000);
-    apr_initialize();
     JNI_CreateJavaVM(&GLOBAL_VM, &jni_env, &args);
 }
 
@@ -269,11 +260,11 @@
     reset_tested_thread_iterator(&tts);
     while(next_tested_thread(&tts)){
         // Create thread
-        tts->native_thread =
-            (hythread_t)calloc(1, hythread_get_struct_size());
-        assert(tts->native_thread);
-        status = hythread_create_with_group(tts->native_thread,
-            NULL, 0, 5, run_method_param, tts);
+        tts->native_thread = (hythread_t)calloc(1, sizeof(struct VM_thread));
+        tf_assert_v(tts->native_thread != NULL);
+        tts->native_thread->java_status = TM_STATUS_ALLOCATED;
+        status = hythread_create_ex(tts->native_thread,
+            NULL, 0, 0, run_method_param, tts);
         tf_assert_v(status == TM_ERROR_NONE);
         tested_thread_wait_started(tts);
     }
@@ -344,7 +335,7 @@
 
     hythread = (hythread_t) vm_jthread_get_tm_data(java_thread);
     tf_assert_same(hythread, tts->native_thread);
-    vm_thread = (vm_thread_t)hythread_tls_get(hythread, TM_THREAD_VM_TLS_KEY);
+    vm_thread = jthread_get_vm_thread(hythread);
     tf_assert(vm_thread);
     jvmti_thread = &(vm_thread->jvmti_thread);
     tf_assert(jvmti_thread);

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/utils/thread_unit_test_utils.h Mon Sep 10 09:25:25 2007
@@ -17,7 +17,6 @@
 
 #include <stdlib.h>
 #include "jvmti_types.h"
-#include "apr_thread_proc.h"
 #include "open/hycomp.h"
 #include "open/jthread.h"
 #include "thread_manager.h"

Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.def
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.def?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.def (original)
+++ harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.def Mon Sep 10 09:25:25 2007
@@ -43,8 +43,7 @@
 hythread_get_struct_size
 hythread_global_lock
 hythread_global_unlock
-hythread_attach_to_group
-hythread_create_with_group
+hythread_create_ex
 hythread_clear_interrupted_other
 hythread_join
 hythread_join_timed

Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.exp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.exp?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.exp (original)
+++ harmony/enhanced/drlvm/trunk/vm/thread/src/hythr.exp Mon Sep 10 09:25:25 2007
@@ -44,8 +44,7 @@
 hythread_get_struct_size;
 hythread_global_lock;
 hythread_global_unlock;
-hythread_attach_to_group;
-hythread_create_with_group;
+hythread_create_ex;
 hythread_clear_interrupted_other;
 hythread_join;
 hythread_join_timed;

Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c Mon Sep 10 09:25:25 2007
@@ -85,23 +85,27 @@
 	fast_thread_array[id]=thread;
 	return TM_ERROR_NONE;
 }*/
-static void thread_set_self(hythread_t thread);
+static void hythread_set_self(hythread_t thread);
 
 /**
- * Creates a new thread.
+ * Creates a new thread in a given group.
  *
- * @param[out] new_thread The newly created thread.
- * @param[in] group thread group, or NULL; in case of NULL this thread will go to the default group.
- * @param[in] attr threadattr to use to determine how to create the thread, or NULL for default attributes
- * @param[in] func function to run in the new thread
- * @param[in] data argument to be passed to starting function
- */
-IDATA VMCALL hythread_create_with_group(hythread_t new_thread,
-                                        hythread_group_t group,
-                                        UDATA stacksize,
-                                        UDATA priority,
-                                        hythread_entrypoint_t func,
-                                        void *data)
+ * @param[in] new_thread a new allocated thread.
+ * @param[in] group      a thread group or NULL
+ *                       in case of NULL this thread will go to the default group.
+ * @param[in] stacksize  a new thread stack size or 0
+ *                       in case of 0 the thread will be set the default stack size
+ * @param[in] priority   a new thread priority or 0
+ *                       in case of 0 the thread will be set HYTHREAD_PRIORITY_NORMAL priority
+ * @param[in] func       a function to run in the new thread
+ * @param[in] data       an argument to be passed to starting function
+ */
+IDATA VMCALL hythread_create_ex(hythread_t new_thread,
+                                hythread_group_t group,
+                                UDATA stacksize,
+                                UDATA priority,
+                                hythread_entrypoint_t func,
+                                void *data)
 {
     int result;
     hythread_t self;
@@ -166,30 +170,23 @@
     if (handle) {
         *handle = thread;
     }
-    return hythread_create_with_group(thread, NULL, stacksize, priority, func, data);
+    return hythread_create_ex(thread, NULL, stacksize, priority, func, data);
 }
 
 /**
  * Registers the current OS thread with the threading subsystem.
  *
- * @param[in] new_thread thread to register
- * @param[in] lib        thread library to attach to
- * @param[in] group      thread group, or NULL; in case of NULL this thread will
- *                       go to the default group
- */
-IDATA hythread_attach_to_group(hythread_t new_thread,
-                               hythread_library_t lib,
-                               hythread_group_t group)
+ * @param[in] new_thread a new thread to register
+ * @param[in] lib        a new thread library or NULL
+ *                       in case of NULL this thread will go to the default group
+ * @param[in] group      a new thread group or NULL
+ *                       in case of NULL this thread will go to the default group
+ */
+IDATA hythread_attach_ex(hythread_t new_thread,
+                         hythread_library_t lib,
+                         hythread_group_t group)
 {
-    hythread_t self;
-
     assert(new_thread);
-    self = hythread_self();
-    if (self) {
-        // The thread is already attached, just fill a given thread structure.
-        *new_thread = *self;
-        return TM_ERROR_NONE;
-    }
 
     hythread_struct_init(new_thread);
     assert(lib == NULL);
@@ -197,7 +194,7 @@
     new_thread->os_handle = os_thread_current();
     assert(new_thread->os_handle);
 
-    TRACE(("TM: native attached: native: %p ", self));
+    TRACE(("TM: native attached: native: %p ", new_thread));
 
     return register_to_group(new_thread,
         (group == NULL ? TM_DEFAULT_GROUP : group));
@@ -221,27 +218,26 @@
  * @see hythread_detach
  */
 IDATA VMCALL hythread_attach(hythread_t *handle) {
+    IDATA status;
+    hythread_t self;
+
     hythread_t thread = (hythread_t)calloc(1, hythread_get_struct_size());
     assert(thread);
     if (handle) {
         *handle = thread;
     }
-    return hythread_attach_to_group(thread, NULL, NULL);
-}
 
-/**
- * Attach an OS thread to the threading library.
- *
- * @param[out] handle pointer to a hythread_t to be set (will be ignored if null)
- * @param[in] lib thread library to attach thread to
- * @return  0 on success or negative value on failure
- *
- * @note (*handle) should be NULL or point to hythread_t structure  
- * @see hythread_detach
- */
-IDATA VMCALL hythread_attach_ex(hythread_t *handle, hythread_library_t lib) {
-    assert(handle);
-    return hythread_attach_to_group(*handle, NULL, NULL);
+    // get current thread
+    self = hythread_self();
+
+    // attach thread
+    status = hythread_attach_ex(thread, NULL, NULL);
+
+    // restore current thread
+    if (self) {
+        hythread_set_self(self);
+    }
+    return status;
 }
 
 /**
@@ -275,7 +271,7 @@
         // of forceful termination by hythread_cancel(), but thread
         // local storage can be zeroed only for current thread.
         if (thread == hythread_self() ) {
-            thread_set_self(NULL);
+            hythread_set_self(NULL);
         }
         fast_thread_array[thread->thread_id] = NULL;
         
@@ -352,7 +348,7 @@
     return thread;
 }
 
-static void thread_set_self(hythread_t  thread) {
+static void hythread_set_self(hythread_t  thread) {
     apr_threadkey_private_set(thread, TM_THREAD_KEY);
 }
 #else 
@@ -362,7 +358,7 @@
     return hythread_self();
 }
 
-static void thread_set_self(hythread_t thread) {
+static void hythread_set_self(hythread_t thread) {
 #ifndef _WIN64
 #   if (_MSC_VER >= 1400)
         __writefsdword(offsetof(NT_TIB, ArbitraryUserPointer), thread);
@@ -383,7 +379,7 @@
     return hythread_self();
 }
 
-static void thread_set_self(hythread_t  thread) {
+static void hythread_set_self(hythread_t  thread) {
     tm_self_tls = thread;
 }
 #endif // defined(_WIN32) && defined(HYTHREAD_FAST_TLS)
@@ -537,7 +533,7 @@
 
     assert(thread->os_handle);
 
-    thread_set_self(thread);
+    hythread_set_self(thread);
     assert(thread == tm_self_tls);
 
     thread->state |= TM_THREAD_STATE_ALIVE | TM_THREAD_STATE_RUNNABLE;
@@ -607,7 +603,7 @@
     new_thread->safepoint_callback = NULL;
 
     hymutex_lock(&new_thread->mutex);
-    new_thread->state = 0;
+    new_thread->state = TM_THREAD_STATE_NEW;
     hymutex_unlock(&new_thread->mutex);
 
     status = hylatch_set(new_thread->join_event, 1);

Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_fat_monitor.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_fat_monitor.c?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_fat_monitor.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_fat_monitor.c Mon Sep 10 09:25:25 2007
@@ -355,12 +355,15 @@
  * @see hythread_monitor_notify, hythread_monitor_notify_all, hythread_monitor_enter, hythread_monitor_wait
  */
 IDATA VMCALL hythread_monitor_interrupt_wait(hythread_monitor_t mon_ptr,
-					     hythread_t thread) {
+                                             hythread_t thread)
+{
     if (mon_ptr->owner != tm_self_tls) {
         return TM_ERROR_ILLEGAL_STATE;
     }
-
-    assert (thread->state & TM_THREAD_STATE_INTERRUPTED);
+    // While waiting on monitor, thread state TM_THREAD_STATE_INTERRUPTED
+    // could already clear if condition was notified by another thread,
+    // so thread state TM_THREAD_STATE_INTERRUPTED check is illegal here.
+    // Just notify condition.
     return hycond_notify_all(&mon_ptr->condition);
 }
 

Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_interrupt.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_interrupt.c?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_interrupt.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_interrupt.c Mon Sep 10 09:25:25 2007
@@ -56,8 +56,8 @@
             hythread_monitor_interrupt_wait(thread->waited_monitor, thread);
             hythread_monitor_exit(thread->waited_monitor);
         } else {
-            hythread_t interrupt_thread = (hythread_t)calloc(1, hythread_get_struct_size());
-            status = hythread_create_with_group(interrupt_thread, 0, 0, 0,
+            hythread_t interrupt_thread = NULL;
+            status = hythread_create(&interrupt_thread, 0, 0, 0,
                 interrupter_thread_function, (void *)thread);
             assert (status == TM_ERROR_NONE);
         }

Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/thread_private.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_private.h?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_private.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/thread/src/thread_private.h Mon Sep 10 09:25:25 2007
@@ -65,16 +65,6 @@
 extern "C" {
 #endif /* __cplusplus */
 
-
-#ifdef __linux__
-#define osthread_t pthread_t
-#elif _WIN32
-#define osthread_t HANDLE
-#else // !_WIN32 && !__linux__
-#error "threading is only supported on __linux__ or _WIN32"
-#endif // !_WIN32 && !__linux__
-
-
 extern hythread_group_t TM_DEFAULT_GROUP;
 /**
  * current capacity of the thread local storage
@@ -93,186 +83,6 @@
     IDATA     nondaemon_thread_count;
     hycond_t  nondaemon_thread_cond;
 } HyThreadLibrary;
-
-/**
- * Native thread control structure.
- */
-typedef struct HyThread {
-
-#ifndef POSIX
-    // This is dummy pointer for Microsoft Visual Studio debugging
-    // If this is removed, Visual Studio, when attached to VM, will show
-    // no symbolic information
-    void* reserved;
-#endif
-
-// Public fields exported by HyThread_public. If you change these fields,
-// please, check fields in hythread.h/HyThread_public
-
-    /**
-     * Number of requests made for this thread, it includes both
-     * suspend requests and safe point callback requests.
-     * The field is modified by atomic operations.
-     *
-     * Increment in functions:
-     *    1. send_suspend_request()
-     *          - sets suspend request for a given thread
-     *    2. hythread_set_safepoint_callback()
-     *          - sets safe point callback request for a given thread
-     *
-     * Decrement in functions:
-     *    1. hythread_resume()
-     *          - removes suspend request for a given thread
-     *    2. hythread_exception_safe_point()
-     *          - removes safe point callback request for current thread
-     */
-    uint32 request;
-
-    /**
-     * Field indicating that thread can safely be suspended.
-     * Safe suspension is enabled on value 0.
-     *
-     * The disable_count is increased/decreaded in
-     * hythread_suspend_disable()/hythread_suspend_enable() function
-     * for current thread only.
-     *
-     * Also disable_count could be reset to value 0 and restored in
-     * hythread_set_suspend_disable()/hythread_set_suspend_disable() function
-     * for current thread only.
-     *
-     * Function hythread_exception_safe_point() sets disable_count to
-     * value 1 before safe point callback function calling and restores
-     * it after the call.
-     *
-     * Function thread_safe_point_impl() sets disable_count to
-     * value 0 before entering to the safe point and restores it
-     * after exitting.
-     */
-    int16 disable_count;
-
-    /**
-     * Group for this thread. Different groups are needed in order 
-     * to be able to quickly iterate over the specific group.
-     * Examples are: Java threads, GC private threads.
-     * Equal to the address of the head of the list of threads for this group.
-     */
-    hythread_group_t  group; 
-
-    /**
-     * Array representing thread local storage
-     */
-    void *thread_local_storage[10];
-
-
-// Private fields
-
-    /**
-     * Each thread keeps a pointer to the library it belongs to.
-     */
-    HyThreadLibrary * library;
-
-// Suspension 
-    
-    /**
-     * Number of suspend requests made for this thread.
-     * The field is modified by atomic operations.
-     *
-     * After increment/decrement of suspend_count, request field
-     * should be incremented/decremented too.
-     */
-    uint32 suspend_count;
-        
-    /**
-     * Function to be executed at safepoint upon thread resume.
-     *
-     * Field is set in hythread_set_safepoint_callback() function
-     * and reset hythread_exception_safe_point() function.
-     *
-     * After set/reset of safepoint_callback, request field
-     * should be incremented/decremented too.
-     */
-    hythread_event_callback_proc safepoint_callback;
-
-    /**
-     * Event used to notify suspended thread that it needs to wake up.
-     */
-    hysem_t resume_event;
-
-// Basic manipulation fields
-    
-    /**
-     * Points to the next thread within the group.
-     */    
-    hythread_t next;
-
-    /**
-     * Points to the last thread within the group.
-     */
-    hythread_t prev;
-    
-    /**
-     * Handle to OS thread.
-     */
-    osthread_t os_handle;
-
-// Synchronization stuff
-
-    /*
-     * Thread local lock, used to serialize thread state;
-     */
-    hymutex_t mutex;
-
-    /*
-     * Conditional variable used to implement wait function for sleep/park;
-     */
-    hycond_t condition;
-
-    /**
-     * Event reserved for threads that invoke join.
-     */
-    hylatch_t join_event;
-    
-    /**
-     * Current conditional variable thread is waiting on (used for interrupting)
-     */
-    hycond_t *current_condition;
-
-// State
-
-    /**
-     * Thread state. Holds thread state flags as defined in JVMTI specification, plus some additional
-     * flags. See <a href=http://java.sun.com/j2se/1.5.0/docs/guide/jvmti/jvmti.html#GetThreadState> 
-     * JVMTI Specification </a> for more details.
-     */
-    IDATA state;
-
-
-// Attributes
-
-   /**
-    * Hint for scheduler about thread priority
-    */
-    IDATA priority;    
-
-    /**
-     * Size of thread's stack, set on creation
-     */
-
-    UDATA stacksize;
-
-// Monitors
-    
-    /**
-     *  Monitor this thread is waiting on now.
-     */
-    hythread_monitor_t waited_monitor;
-
-    /**
-     * ID for this thread. The maximum number of threads is governed by the size of lockword record.
-     */
-    IDATA thread_id;
-
-} HyThread;
 
 /** 
   * hythread_group_t pointer to the first element in the thread group

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/finalizer_thread.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/finalizer_thread.h?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/finalizer_thread.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/finalizer_thread.h Mon Sep 10 09:25:25 2007
@@ -29,6 +29,7 @@
 #include "open/hythread_ext.h"
 #include "open/types.h"
 #include "open/gc.h"
+#include "thread_manager.h"
 
 
 #define FINALIZER_THREAD_PRIORITY (HYTHREAD_PRIORITY_NORMAL + 2)
@@ -54,7 +55,7 @@
     hycond_t mutator_block_cond;    // mutator block condition variable for heavy finalizable obj load
     hymutex_t mutator_block_mutex;  // mutator block mutex for heavy finalizable obj load
     
-    hythread_t *thread_ids;
+    vm_thread_t *thread_ids;
     volatile unsigned int thread_num;
     
     volatile Boolean shutdown;

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_internal.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_internal.h?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_internal.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_internal.h Mon Sep 10 09:25:25 2007
@@ -153,7 +153,7 @@
         hythread_tls_key_t TL_ti_enabled; //thread local TI flag
 
         // TI event thread data
-        hythread_t event_thread;
+        vm_thread_t event_thread;
         hycond_t event_cond;
         int event_cond_initialized;
 

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/thread_generic.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/thread_generic.h?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/thread_generic.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/thread_generic.h Mon Sep 10 09:25:25 2007
@@ -24,13 +24,12 @@
 #define THREAD_GENERIC_HEADER
 
 #include "vm_threads.h"
-#include "jni.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-VMEXPORT VM_thread *get_vm_thread_ptr_safe(JNIEnv *, jobject);
+VMEXPORT vm_thread_t jthread_get_vm_thread_ptr_safe(jobject thread_obj);
 
 /////////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////////

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/thread_manager.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/thread_manager.h?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/thread_manager.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/thread_manager.h Mon Sep 10 09:25:25 2007
@@ -35,6 +35,7 @@
 struct jvmti_frame_pop_listener;
 struct JVMTISingleStepState;
 struct ClassLoader;
+struct Registers;
 
 /**
  * Java-specific context that is attached to tm_thread control structure by Java layer
@@ -109,7 +110,7 @@
 
     struct jvmti_frame_pop_listener *frame_pop_listener;
     struct JVMTISingleStepState *ss_state;
-    void *jvmti_saved_exception_registers;
+    struct Registers *jvmti_saved_exception_registers;
 };
 
 struct VM_thread
@@ -117,17 +118,25 @@
     /**
      * Native thread which is associated with VM_thread
      */
-    hythread_t p_HyThread;
+#ifdef __cplusplus
+private:
+#endif // __cplusplus
+
+    struct HyThread hy_thread;
+
+#ifdef __cplusplus
+public:
+#endif // __cplusplus
 
     /**
-     * Java thread object to corresponding java.lang.Thread instance
+     * Thread reference object to corresponding java.lang.ThreadWeakRef instance
      */
-    jobject java_thread;
+    jobject weak_ref;
 
     /**
-     * Thread reference object to corresponding java.lang.ThreadWeakRef instance
+     * Java thread object to corresponding java.lang.Thread instance
      */
-    jobject weak_ref;
+    jobject java_thread;
 
     /**
      * Exception that has to be thrown in stopped thread
@@ -172,7 +181,7 @@
     int finalize_thread_flags;
 
     // CPU registers.
-    void *regs;
+    struct Registers *regs;
 
     // This field is private the to M2nFrame module, init code should set it to NULL
     // Informational frame - created when native is called from Java,
@@ -258,6 +267,46 @@
      */
     const void *arg;
 };
+
+/**
+ * Gets VM_thread from native thread
+ */
+hy_inline vm_thread_t jthread_self_vm_thread()
+{
+    register hythread_t self = hythread_self();
+    return (self && self->java_status == TM_STATUS_INITIALIZED)
+            ? ((vm_thread_t)self) : NULL;
+} // jthread_self_vm_thread
+
+/**
+ * Gets VM_thread from a given native thread
+ */
+hy_inline vm_thread_t jthread_get_vm_thread(hythread_t native)
+{
+    return (native && native->java_status == TM_STATUS_INITIALIZED)
+            ? ((vm_thread_t)native) : NULL;
+} // jthread_get_vm_thread
+
+/**
+ * Gets unsafe VM_thread from native thread.
+ * VM_thread could be not initialized.
+ */
+hy_inline vm_thread_t jthread_self_vm_thread_unsafe()
+{
+    register hythread_t self = hythread_self();
+    return (self && self->java_status != TM_STATUS_WITHOUT_JAVA)
+            ? ((vm_thread_t)self) : NULL;
+} // jthread_self_vm_thread_unsafe
+
+/**
+ * Gets unsafe VM_thread from a given native thread.
+ * VM_thread could be not initialized.
+ */
+hy_inline vm_thread_t jthread_get_vm_thread_unsafe(hythread_t native)
+{
+    return (native && native->java_status != TM_STATUS_WITHOUT_JAVA)
+            ? ((vm_thread_t)native) : NULL;
+} // jthread_get_vm_thread_unsafe
 
 #ifdef __cplusplus
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h Mon Sep 10 09:25:25 2007
@@ -45,81 +45,29 @@
 #define tmn_suspend_disable_recursive hythread_suspend_disable
 #define tmn_suspend_enable_recursive hythread_suspend_enable
 
-typedef VM_thread *vm_thread_accessor();
-VMEXPORT extern vm_thread_accessor *get_thread_ptr;
+typedef vm_thread_t (*vm_thread_accessor)();
+VMEXPORT extern vm_thread_accessor get_thread_ptr;
 
-inline void vm_set_exception_registers(VM_thread * thread, Registers & regs)
-{
-    if (!thread->regs) {
-        thread->regs = malloc(sizeof(Registers));
-        assert(thread->regs);
-    }
-    *(Registers *) thread->regs = regs;
-}
-
-inline void *vm_get_ip_from_regs(VM_thread * thread)
-{
-    return ((Registers *) thread->regs)->get_ip();
-}
-
-inline void vm_reset_ip_from_regs(VM_thread * thread)
-{
-    ((Registers *) thread->regs)->reset_ip();
-}
-
-inline jvmti_thread_t jthread_get_jvmti_thread(hythread_t native_thread)
-{
-    assert(native_thread);
-    vm_thread_t vm_thread =
-        (vm_thread_t)hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
-    if (!vm_thread) {
-        return NULL;
-    }
-    return &(vm_thread->jvmti_thread);
-}
+#define p_TLS_vmthread (jthread_self_vm_thread())
 
+/**
+ * Gets jvmti_thread pointer from native thread
+ */
 inline jvmti_thread_t jthread_self_jvmti()
 {
-    return jthread_get_jvmti_thread(hythread_self());
-}
-
-inline void vm_set_jvmti_saved_exception_registers(VM_thread * thread,
-                                                   Registers & regs)
-{
-    assert(thread);
-    assert(&thread->jvmti_thread);
-    jvmti_thread_t jvmti_thread = &thread->jvmti_thread;
-    if (!jvmti_thread->jvmti_saved_exception_registers) {
-        jvmti_thread->jvmti_saved_exception_registers = malloc(sizeof(Registers));
-        assert(jvmti_thread->jvmti_saved_exception_registers);
-    }
-    *(Registers *) jvmti_thread->jvmti_saved_exception_registers = regs;
-}
-
-inline VM_thread *get_vm_thread_fast_self()
-{
-    register hythread_t thr = hythread_self();
-    return thr ? ((VM_thread *) hythread_tls_get(thr, TM_THREAD_VM_TLS_KEY)) :
-        NULL;
-}
+    register vm_thread_t vm_thread = jthread_self_vm_thread();
+    return vm_thread ? &(vm_thread->jvmti_thread) : NULL;
+} // jthread_self_jvmti
 
-inline VM_thread *get_vm_thread(hythread_t thr)
+/**
+ * Gets jvmti_thread pointer from a given native thread
+ */
+inline jvmti_thread_t jthread_get_jvmti_thread(hythread_t native)
 {
-    if (thr == NULL) {
-        return NULL;
-    }
-    return (VM_thread *) hythread_tls_get(thr, TM_THREAD_VM_TLS_KEY);
-}
-
-VMEXPORT void init_TLS_data();
-
-VMEXPORT void set_TLS_data(VM_thread * thread);
-uint16 get_self_stack_key();
-
-#define p_TLS_vmthread (get_vm_thread_fast_self())
-
-//Registers *thread_gc_get_context(VM_thread *, VmRegisterContext &);
-void thread_gc_set_context(VM_thread *);
+    assert(native);
+    register vm_thread_t vm_thread = jthread_get_vm_thread(native);
+    return vm_thread ? &(vm_thread->jvmti_thread) : NULL;
+} // jthread_get_jvmti_thread
 
 /**
  *  Auxiliary function to update thread count
@@ -127,8 +75,13 @@
 void jthread_start_count();
 void jthread_end_count();
 
-vm_thread_t jthread_allocate_vm_thread(hythread_t native_thread);
 jint jthread_allocate_vm_thread_pool(JavaVM * java_vm, vm_thread_t vm_thread);
 void jthread_deallocate_vm_thread_pool(vm_thread_t vm_thread);
+vm_thread_t jthread_allocate_thread();
+void vm_set_jvmti_saved_exception_registers(vm_thread_t vm_thread, Registers & regs);
+void vm_set_exception_registers(vm_thread_t vm_thread, Registers & regs);
+void *vm_get_ip_from_regs(vm_thread_t vm_thread);
+void vm_reset_ip_from_regs(vm_thread_t vm_thread);
+
 
 #endif //!_VM_THREADS_H_

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/gc/stop_the_world_root_set_enum.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/gc/stop_the_world_root_set_enum.cpp?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/gc/stop_the_world_root_set_enum.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/gc/stop_the_world_root_set_enum.cpp Mon Sep 10 09:25:25 2007
@@ -81,7 +81,7 @@
 static void
 stop_the_world_root_set_enumeration()
 {
-    VM_thread * current_vm_thread;
+    vm_thread_t current_vm_thread;
 
     TRACE2("vm.gc", "stop_the_world_root_set_enumeration()");
 
@@ -104,7 +104,7 @@
     // Run through list of active threads and enumerate each one of them.
     hythread_t tm_thread = hythread_iterator_next(&iterator);    
     while (tm_thread) {
-        VM_thread *thread = get_vm_thread(tm_thread);
+        vm_thread_t thread = jthread_get_vm_thread(tm_thread);
         //assert(thread);
         if (thread && thread != current_vm_thread) {
             vm_enumerate_thread(thread);

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/finalizer_thread.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/finalizer_thread.cpp?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/finalizer_thread.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/finalizer_thread.cpp Mon Sep 10 09:25:25 2007
@@ -103,15 +103,17 @@
     status = hymutex_create(&fin_thread_info->mutator_block_mutex, TM_MUTEX_DEFAULT);
     assert(status == TM_ERROR_NONE);
     
-    fin_thread_info->thread_ids = (hythread_t *)STD_MALLOC(sizeof(hythread_t) * fin_thread_info->thread_num);
+    fin_thread_info->thread_ids =
+        (vm_thread_t*)STD_MALLOC(fin_thread_info->thread_num * sizeof(vm_thread_t));
+    void **args = (void **)STD_MALLOC(sizeof(void *) * 2);
+    args[0] = (void*)java_vm;
+    args[1] = (void*)get_system_thread_group(jni_env);
     
     for(unsigned int i = 0; i < fin_thread_info->thread_num; i++){
-        void **args = (void **)STD_MALLOC(sizeof(void *) * 2);
-        args[0] = (void*)java_vm;
-        args[1] = (void*)get_system_thread_group(jni_env);
-        fin_thread_info->thread_ids[i] = (hythread_t)STD_CALLOC(1, hythread_get_struct_size());
-        status = hythread_create_with_group(fin_thread_info->thread_ids[i], NULL, 0,
-            FINALIZER_THREAD_PRIORITY, (hythread_entrypoint_t)finalizer_thread_func, args);
+        fin_thread_info->thread_ids[i] = jthread_allocate_thread();
+        status = hythread_create_ex((hythread_t)fin_thread_info->thread_ids[i],
+            NULL, 0, FINALIZER_THREAD_PRIORITY,
+            (hythread_entrypoint_t)finalizer_thread_func, args);
         assert(status == TM_ERROR_NONE);
         hysem_wait(fin_thread_info->attached_sem);
     }    
@@ -256,7 +258,7 @@
     hythread_t self = hythread_self();
     
     for(unsigned int i=0; i<fin_thread_info->thread_num; ++i)
-        if(self == fin_thread_info->thread_ids[i])
+        if(self == (hythread_t)fin_thread_info->thread_ids[i])
             return TRUE;
     
     return FALSE;

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/ref_enqueue_thread.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/ref_enqueue_thread.cpp?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/ref_enqueue_thread.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/ref_enqueue_thread.cpp Mon Sep 10 09:25:25 2007
@@ -65,8 +65,9 @@
     void **args = (void **)STD_MALLOC(sizeof(void *)*2);
     args[0] = (void *)java_vm;
     args[1] = (void*)get_system_thread_group(jni_env);
-    hythread_t thread = (hythread_t)STD_CALLOC(1, hythread_get_struct_size());
-    status = hythread_create_with_group(thread, NULL, 0, REF_ENQUEUE_THREAD_PRIORITY,
+    vm_thread_t thread = jthread_allocate_thread();
+    status = hythread_create_ex((hythread_t)thread, NULL, 0,
+        REF_ENQUEUE_THREAD_PRIORITY,
         (hythread_entrypoint_t)ref_enqueue_thread_func, args);
     assert(status == TM_ERROR_NONE);
     

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_init.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_init.cpp?rev=574297&r1=574296&r2=574297&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_init.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_init.cpp Mon Sep 10 09:25:25 2007
@@ -605,9 +605,8 @@
 
     native_thread = hythread_self();
     if (!native_thread) {
-        native_thread = (hythread_t)STD_CALLOC(1, hythread_get_struct_size());
-        assert(native_thread);
-        IDATA hy_status = hythread_attach_to_group(native_thread, NULL, NULL);
+        native_thread = (hythread_t)jthread_allocate_thread();
+        IDATA hy_status = hythread_attach_ex(native_thread, NULL, NULL);
         if (hy_status != TM_ERROR_NONE)
             return JNI_ERR;
     }
@@ -640,9 +639,8 @@
 
     vm_env = java_vm->vm_env;
 
-    hythread_t main_thread = (hythread_t)STD_CALLOC(1, hythread_get_struct_size());
-    assert(main_thread);
-    if (hythread_attach_to_group(main_thread, NULL, NULL) != TM_ERROR_NONE) {
+    vm_thread_t main_thread = jthread_allocate_thread();
+    if (hythread_attach_ex((hythread_t)main_thread, NULL, NULL) != TM_ERROR_NONE) {
         return JNI_ERR;
     }
 



Mime
View raw message