You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2006/08/23 18:49:21 UTC
svn commit: r434076 [15/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/...
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_rawmon.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_rawmon.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_rawmon.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_rawmon.cpp Wed Aug 23 09:48:41 2006
@@ -30,96 +30,9 @@
#include "vm_threads.h"
#include "vm_process.h"
#include "cxxlog.h"
-#include "open/thread.h"
+#include "open/ti_thread.h"
#include "suspend_checker.h"
-#define JVMTI_RAW_MONITOR_TABLE_SIZE 100
-
-/**
- * Struct of raw monitor
- */
-struct jvmtiRawMonitor
-{
- // lock monitor object
- Lock_Manager m_owner_lock;
- // lock wait lock object
- Lock_Manager m_wait_lock;
- // owner thread
- VM_thread *m_owner_thread;
- // wait event
- VmEventHandle m_wait_event;
- // wait notify event
- VmEventHandle m_notify_event;
- // recursive enter counter
- unsigned m_owned_count;
- // monitor entry counter
- unsigned m_enter_count;
- // monitor waters count
- unsigned m_wait_count;
- // flag for notify
- bool m_leave;
- // flag for notifyAll
- bool m_notifyall;
- // constructor
- jvmtiRawMonitor(): m_owner_thread(NULL),
- m_wait_event(0), m_notify_event(0),
- m_owned_count(0), m_enter_count(0), m_wait_count(0),
- m_leave(false), m_notifyall(false) {}
-};
-
-/**
- * Raw monitor table entry
- */
-struct jvmtiRawMonitorTableEntry {
- // pointer for raw monitor
- jvmtiRawMonitor *m_monitor;
- // index of next free entry of table
- int m_nextFree;
- // constructor
- jvmtiRawMonitorTableEntry(): m_monitor(NULL), m_nextFree(-1) {}
-};
-
-/**
- * Raw monitor table
- */
-static jvmtiRawMonitorTableEntry g_rawMonitors[JVMTI_RAW_MONITOR_TABLE_SIZE];
-
-/**
- * Free entry in raw monitor table
- */
-static unsigned g_freeMonitor = 1;
-
-/**
- * Global entry locker for raw monitor
- */
-static Lock_Manager jvmtiRawMonitorLock;
-
-/**
- * Function checks valid monitor in raw monitor table
- * and checks monitor owner for thread.
- */
-static jvmtiError
-jvmtiCheckValidMonitor( jrawMonitorID monitor )
-{
- jvmtiRawMonitor *rawmonitor;
- unsigned index;
-
- /**
- * Check valid monitor in raw monitor table
- */
- if( (index=(unsigned)((POINTER_SIZE_INT)monitor)) >= JVMTI_RAW_MONITOR_TABLE_SIZE
- || ( (rawmonitor = g_rawMonitors[index].m_monitor) == NULL ) )
- {
- return JVMTI_ERROR_INVALID_MONITOR;
- }
- /**
- * Check monitor owner for thread
- */
- if( rawmonitor->m_owner_thread != get_thread_ptr() ) {
- return JVMTI_ERROR_NOT_MONITOR_OWNER;
- }
- return JVMTI_ERROR_NONE;
-} // jvmtiCheckValidMonitor
/*
* Create Raw Monitor
@@ -137,88 +50,11 @@
* Monitor trace
*/
TRACE2("jvmti.monitor", "CreateRawMonitor called, name = " << name);
- SuspendEnabledChecker sec;
-
- /**
- * Check given env & current phase.
- */
- jvmtiPhase phases[] = {JVMTI_PHASE_ONLOAD, JVMTI_PHASE_LIVE};
-
- CHECK_EVERYTHING();
-
- /**
- * Check valid name and monitor_ptr
- */
- if( !name || !monitor_ptr ) {
+ if (name == NULL || monitor_ptr == NULL){
return JVMTI_ERROR_NULL_POINTER;
}
- *monitor_ptr = 0;
- /**
- * Check valid index in raw monitor table
- */
- if( g_freeMonitor >= JVMTI_RAW_MONITOR_TABLE_SIZE ) {
- return JVMTI_ERROR_OUT_OF_MEMORY;
- }
- /**
- * Only one thread can run next block
- * another will be stopped at global raw monitor lock
- */
- {
- VmEventHandle handle;
- /**
- * Lock global monitor lock
- */
- LMAutoUnlock aulock( &jvmtiRawMonitorLock );
- /**
- * Create monitor
- */
- jvmtiRawMonitor *rawmonitor = new jvmtiRawMonitor;
- if( rawmonitor == NULL ) {
- return JVMTI_ERROR_OUT_OF_MEMORY;
- }
- /**
- * Create wait event handle
- */
- handle = vm_create_event( NULL, TRUE, FALSE, NULL );
- if( handle == 0 ) {
- // FIXME - What do we have to do if we cannot create event object?
- return JVMTI_ERROR_INTERNAL;
- }
- rawmonitor->m_wait_event = handle;
- /**
- * Create notify event handle
- */
- handle = vm_create_event( NULL, TRUE, FALSE, NULL );
- if( handle == 0 ) {
- // FIXME - What do we have to do if we cannot create event object?
- return JVMTI_ERROR_INTERNAL;
- }
- rawmonitor->m_notify_event = handle;
- /**
- * Set monitor into raw monitor table and
- * set monitor_ptr as index in raw monitor table
- */
- g_rawMonitors[g_freeMonitor].m_monitor = rawmonitor;
- *monitor_ptr = (jrawMonitorID)((POINTER_SIZE_INT)g_freeMonitor);
- /**
- * Change raw monitor table free
- */
- if( g_rawMonitors[g_freeMonitor].m_nextFree == -1 ) {
- // created monitor is the last in raw monitor table
- g_freeMonitor++;
- } else {
- // get next free monitor from raw monitor table entry
- g_freeMonitor = g_rawMonitors[g_freeMonitor].m_nextFree;
- }
- }
-
- /**
- * Monitor trace
- */
- TRACE2("jvmti.monitor", "CreateRawMonitor finished, name = "
- << name << " id = " << *monitor_ptr);
-
- return JVMTI_ERROR_NONE;
+ //FIXME: integration, add name.
+ return (jvmtiError)jthread_raw_monitor_create(monitor_ptr);
} // jvmtiCreateRawMonitor
/*
@@ -236,64 +72,7 @@
jvmtiDestroyRawMonitor(jvmtiEnv* env,
jrawMonitorID monitor)
{
- unsigned index;
- jvmtiRawMonitor *rawmonitor;
-
- /**
- * Monitor trace
- */
- TRACE2("jvmti.monitor", "DestroyRawMonitor called, id = " << monitor);
- SuspendEnabledChecker sec;
-
- /**
- * Check given env & current phase.
- */
- jvmtiPhase phases[] = {JVMTI_PHASE_ONLOAD, JVMTI_PHASE_LIVE};
-
- CHECK_EVERYTHING();
-
- /**
- * Check valid monitor in raw monitor table
- */
- if( (index = (unsigned)((POINTER_SIZE_INT)monitor)) >= JVMTI_RAW_MONITOR_TABLE_SIZE
- || ( (rawmonitor = g_rawMonitors[index].m_monitor) == NULL ) )
- {
- return JVMTI_ERROR_INVALID_MONITOR;
- }
-
- /**
- * Lock global raw monitor enter lock
- * It cannot allow enter monitor and stop on monitor lock
- */
- LMAutoUnlock aulock( &jvmtiRawMonitorLock );
-
- /**
- * Check monitor owner for thread
- */
- if( rawmonitor->m_owner_thread != get_thread_ptr()
- && !(rawmonitor->m_owned_count == 0 && rawmonitor->m_enter_count == 0) )
- {
- return JVMTI_ERROR_NOT_MONITOR_OWNER;
- }
-
- /**
- * Check monitor has only 1 enter, the owner enter
- * and monitor owner has no recursion
- */
- if( (rawmonitor->m_owned_count == 1 && rawmonitor->m_enter_count == 1) ||
- (rawmonitor->m_owned_count == 0 && rawmonitor->m_enter_count == 0)) {
- // delete monitor from raw monitor raw table
- delete rawmonitor;
- // null pointer to deleted monitor in the table
- g_rawMonitors[index].m_monitor = NULL;
- // set free element in table
- g_rawMonitors[index].m_nextFree = g_freeMonitor;
- // modify next free monitor variable
- g_freeMonitor = index;
- return JVMTI_ERROR_NONE;
- } else { // monitor cannot be destroyed
- return JVMTI_ERROR_NOT_MONITOR_OWNER;
- }
+ return (jvmtiError)jthread_raw_monitor_destroy(monitor);
} // jvmtiDestroyRawMonitor
/*
@@ -308,81 +87,7 @@
jvmtiRawMonitorEnter(jvmtiEnv* env,
jrawMonitorID monitor)
{
- unsigned index;
- jvmtiRawMonitor *rawmonitor;
-
- /**
- * Monitor trace
- */
- TRACE2("jvmti.monitor", "RawMonitorEnter called, id = " << monitor);
- SuspendEnabledChecker sec;
-
- /**
- * Check given env & current phase.
- */
- jvmtiPhase* phases = NULL;
-
- CHECK_EVERYTHING();
-
- /**
- * Check valid monitor
- */
- if( (index = (unsigned)((POINTER_SIZE_INT)monitor)) >= JVMTI_RAW_MONITOR_TABLE_SIZE
- || ( (rawmonitor = g_rawMonitors[index].m_monitor) == NULL ) )
- {
- return JVMTI_ERROR_INVALID_MONITOR;
- }
- // set monitor pointer
- rawmonitor = g_rawMonitors[index].m_monitor;
-
- /**
- * If current thread isn't owner of monitor try to lock monitor
- */
- if( rawmonitor->m_owner_thread != get_thread_ptr() ) {
- /**
- * Increase monitor enter count
- * Only 1 thread can execute this block
- */
- {
- // lock global raw monitor enter lock
- jvmtiRawMonitorLock._lock();
- // during lock monitor monitor can be destroyed
- if( (rawmonitor = g_rawMonitors[index].m_monitor) == NULL ) {
- // monitor was destroyed
- return JVMTI_ERROR_INVALID_MONITOR;
- }
- // increase monitor enter count
- rawmonitor->m_enter_count++;
- // unlock global raw monitor enter lock
- jvmtiRawMonitorLock._unlock();
- }
-
- /**
- * Try to lock monitor
- * This is stop point for all thread, only 1 thread can pass it
- */
- // set suspend thread flag
- assert(tmn_is_suspend_enabled());
- p_TLS_vmthread->is_suspended = true;
- tmn_safe_point();
- // all thread stoped at this point trying to lock monitor
- rawmonitor->m_owner_lock._lock();
- // only owner of monitor can execute in the following instructions
-
- // set monitor owner
- rawmonitor->m_owner_thread = get_thread_ptr();
- // lock wait lock object
- rawmonitor->m_wait_lock._lock();
- // suspend thread if needed
- //tmn_suspend_disable();
- //tmn_suspend_enable();
- // remove suspend thread flag
- p_TLS_vmthread->is_suspended = false;
- }
- // increase monitor recursion
- rawmonitor->m_owned_count++;
-
- return JVMTI_ERROR_NONE;
+ return (jvmtiError)jthread_raw_monitor_enter(monitor);
} // jvmtiRawMonitorEnter
/*
@@ -396,54 +101,7 @@
jvmtiRawMonitorExit(jvmtiEnv* env,
jrawMonitorID monitor)
{
- jvmtiRawMonitor *rawmonitor;
- jvmtiError result;
-
- /**
- * Monitor trace
- */
- TRACE2("jvmti.monitor", "RawMonitorExit called, id = " << monitor);
- SuspendEnabledChecker sec;
-
- /*
- * Check given env & current phase.
- */
- jvmtiPhase* phases = NULL;
-
- CHECK_EVERYTHING();
-
- /**
- * Check valid monitor
- */
- if( ( result = jvmtiCheckValidMonitor( monitor ) ) != JVMTI_ERROR_NONE ) {
- return result;
- }
- // set monitor pointer
- rawmonitor = g_rawMonitors[(unsigned)((POINTER_SIZE_INT)monitor)].m_monitor;
-
- /**
- * Only ower of monitor can execute this block
- */
- {
- // decrease monitor recursion
- rawmonitor->m_owned_count--;
-
- /**
- * If there is no monitor recurtion, release monitor
- */
- if( !rawmonitor->m_owned_count ) {
- // decrease monitor enter count
- rawmonitor->m_enter_count--;
- // remove monitor owner
- rawmonitor->m_owner_thread = NULL;
- // unlock wait lock object
- rawmonitor->m_wait_lock._unlock();
- // unlock owner lock object
- rawmonitor->m_owner_lock._unlock();
- }
- }
-
- return JVMTI_ERROR_NONE;
+ return (jvmtiError)jthread_raw_monitor_exit(monitor);
} // jvmtiRawMonitorExit
/*
@@ -458,243 +116,9 @@
jrawMonitorID monitor,
jlong millis)
{
- int old_owned_count;
- int64 timer;
- DWORD stat;
- VM_thread *old_owner_thread;
- jvmtiRawMonitor *rawmonitor;
- jvmtiError result;
-
- /**
- * Monitor trace
- */
- TRACE2("jvmti.monitor", "RawMonitorWait called, id = " << monitor << " timeout = " << millis);
- SuspendEnabledChecker sec;
-
- /**
- * Check given env & current phase.
- */
- jvmtiPhase* phases = NULL;
-
- CHECK_EVERYTHING();
-
- /**
- * Check valid monitor
- */
- if( ( result = jvmtiCheckValidMonitor( monitor ) ) != JVMTI_ERROR_NONE ) {
- return result;
- }
- // set monitor pointer
- rawmonitor = g_rawMonitors[(unsigned)((POINTER_SIZE_INT)monitor)].m_monitor;
-
- /**
- * Set old monitor values to reset monitor before wait state
- * Only owner of monitor can execute this block
- */
- {
- old_owned_count = rawmonitor->m_owned_count;
- old_owner_thread = rawmonitor->m_owner_thread;
- // reset monitor recursion
- rawmonitor->m_owned_count = 0;
- // reset monitor ower
- rawmonitor->m_owner_thread = 0;
- // increase count of waiters
- rawmonitor->m_wait_count++;
- // disallow leave wait state without notify
- rawmonitor->m_leave = false;
- // disallow leave wait state without notifyAll
- rawmonitor->m_notifyall = false;
- // reset wait event
- vm_reset_event( rawmonitor->m_wait_event );
- // unlock wait lock object
- rawmonitor->m_wait_lock._unlock();
- // unlock monitor lock object
- rawmonitor->m_owner_lock._unlock();
- // set thread suspend flag
- assert(tmn_is_suspend_enabled());
- p_TLS_vmthread->is_suspended = true;
- }
-
- /**
- * Wait state for all threads loop in this block
- */
- {
- while( true ) {
- // get timer
- timer = apr_time_now();
- // wait for event
-#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( rawmonitor->m_wait_event,
- millis == 0 ? INFINITE : (DWORD)millis );
-
-#if defined (__INTEL_COMPILER)
-#pragma warning( pop )
-#endif
- // get waiting time
- timer = apr_time_now() - timer;
- // check for timeout
- if( millis != 0 && stat != WAIT_TIMEOUT ) {
- millis -= timer/1000;
- if( millis <= 0 ) {
- // set timeout state
- stat = WAIT_TIMEOUT;
- millis = 1;
- }
- }
- if( stat == WAIT_FAILED ) {
- // wait state was interapted
- result = JVMTI_ERROR_INTERRUPT;
- }
- // check wait object result
- if( millis != 0 && stat == WAIT_TIMEOUT ) {
- // lock wait lock object
- rawmonitor->m_wait_lock._lock();
- break;
- } else {
- // check monitor notify set
- if( rawmonitor->m_leave ) {
- // monitor has notify, try to lock wait lock object
- if( rawmonitor->m_wait_lock._tryLock() ) {
- // wait lock object was locked
- // check monitor notifyAll set
- if( !rawmonitor->m_notifyall ) {
- // notifyAll don't set, remove monitor notify set
- rawmonitor->m_leave = false;
- }
- break;
- }
- }
- }
- }
- }
-
- /**
- * Only owner of wait lock object can execute this block
- */
- {
- // decrease count of monitor waiters
- rawmonitor->m_wait_count--;
- // if wait was interupted
- if( stat != WAIT_TIMEOUT ) {
- if( rawmonitor->m_notifyall ) {
- // wait was interupted by notifyAll call
- if( rawmonitor->m_wait_count == 0 ) {
- // last waiter sets notify event
- vm_set_event( rawmonitor->m_notify_event );
- }
- } else {
- // wait was interupted by notify
- // reset wait event if RawMonitorNotify is called
- vm_reset_event( rawmonitor->m_wait_event );
- // waiter sets notify event
- vm_set_event( rawmonitor->m_notify_event );
- }
- } else {
- // if someone waits notify event
- if( rawmonitor->m_wait_count == 0 && rawmonitor->m_leave ) {
- // last waiter sets notify event
- vm_set_event( rawmonitor->m_notify_event );
- }
- }
- // unlock wait object
- rawmonitor->m_wait_lock._unlock();
- }
-
- /**
- * This is stop point for all thread, only 1 thread can pass it
- * All thread stoped at this point trying to lock monitor
- * Only owner of monitor can execute this block
- */
- {
- // suspend thread if needed
- p_TLS_vmthread->is_suspended = true;
- tmn_safe_point();
- // lock owner lock object
- rawmonitor->m_owner_lock._lock();
- // lock wait lock object
- rawmonitor->m_wait_lock._lock();
- // restore monitor threa owner
- rawmonitor->m_owner_thread = old_owner_thread;
- // restore value of monitor recurtion
- rawmonitor->m_owned_count = old_owned_count;
- // remove suspend thread flag
- p_TLS_vmthread->is_suspended = false;
- }
-
- return result;
+ return (jvmtiError)jthread_raw_monitor_wait(monitor, millis);
} // jvmtiRawMonitorWait
-/*
- * Internal Raw Monitor Notify
- */
-static inline jvmtiError
-InternalRawMonitorNotify(jvmtiEnv* env,
- jrawMonitorID monitor,
- bool notifyAll)
-{
- jvmtiRawMonitor *rawmonitor;
- jvmtiError result;
-
- /*
- * Check given env & current phase.
- */
- jvmtiPhase phases[] = {JVMTI_PHASE_ONLOAD, JVMTI_PHASE_LIVE};
-
- CHECK_EVERYTHING();
-
- /**
- * Check valid monitor
- */
- if( ( result = jvmtiCheckValidMonitor( monitor ) ) != JVMTI_ERROR_NONE ) {
- return result;
- }
- // set monitor pointer
- rawmonitor = g_rawMonitors[(unsigned)((POINTER_SIZE_INT)monitor)].m_monitor;
-
- /**
- * Only owner of monitor can execute following block
- */
- {
- // set notifyAll for waiters to allow waters to leave wait state
- rawmonitor->m_notifyall = notifyAll;
- // set notify for waiters to allow a waiter to leave wait state
- rawmonitor->m_leave = true;
- // reset notify event
- vm_reset_event( rawmonitor->m_notify_event );
- // signal event
- vm_set_event( rawmonitor->m_wait_event );
- // unlock wait lock object
- rawmonitor->m_wait_lock._unlock();
-
- /**
- * Wait until a waiter leaves wait state
- * It decrease number of waiter by 1
- * after which will stop on monitor lock
- */
- if( rawmonitor->m_wait_count ) {
- // set suspend thread flag
- assert(tmn_is_suspend_enabled());
- p_TLS_vmthread -> is_suspended = true;
- // wait notify event
- vm_wait_for_single_object( rawmonitor->m_notify_event, INFINITE );
- // suspend thread if needed
- tmn_suspend_disable();
- tmn_suspend_enable();
- // remove suspend thread flag
- p_TLS_vmthread->is_suspended = false;
- }
-
- // lock wait lock object back
- rawmonitor->m_wait_lock._lock();
- // reset notify event
- vm_reset_event( rawmonitor->m_notify_event );
- }
-
- return JVMTI_ERROR_NONE;
-} // InternalRawMonitorNotify
/*
@@ -712,16 +136,7 @@
* Monitor trace
*/
TRACE2("jvmti.monitor", "RawMonitorNotify called, id = " << monitor);
- SuspendEnabledChecker sec;
-
- /**
- * Check given env & current phase.
- */
- jvmtiPhase phases[] = {JVMTI_PHASE_ONLOAD, JVMTI_PHASE_LIVE};
-
- CHECK_EVERYTHING();
-
- return InternalRawMonitorNotify( env, monitor, false );
+ return (jvmtiError)jthread_raw_monitor_notify(monitor);
} // jvmtiRawMonitorNotify
/*
@@ -739,14 +154,6 @@
* Monitor trace
*/
TRACE2("jvmti.monitor", "RawMonitorNotifyAll called, id = " << monitor);
- SuspendEnabledChecker sec;
-
- /**
- * Check given env & current phase.
- */
- jvmtiPhase phases[] = {JVMTI_PHASE_ONLOAD, JVMTI_PHASE_LIVE};
-
- CHECK_EVERYTHING();
-
- return InternalRawMonitorNotify( env, monitor, true );
+ return (jvmtiError)jthread_raw_monitor_notify_all(monitor);
} // jvmtiRawMonitorNotifyAll
+
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_stack.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_stack.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_stack.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_stack.cpp Wed Aug 23 09:48:41 2006
@@ -29,7 +29,7 @@
#include "Class.h"
#include "cxxlog.h"
#include "thread_generic.h"
-#include "open/thread.h"
+#include "open/jthread.h"
#include "suspend_checker.h"
#include "stack_trace.h"
#include "stack_iterator.h"
@@ -41,7 +41,7 @@
jthread getCurrentThread() {
tmn_suspend_disable();
ObjectHandle hThread = oh_allocate_local_handle();
- hThread->object = (Java_java_lang_Thread *)p_TLS_vmthread->p_java_lang_thread;
+ hThread->object = (Java_java_lang_Thread *)jthread_get_java_thread(hythread_self())->object;
tmn_suspend_enable();
return (jthread) hThread;
}
@@ -69,10 +69,10 @@
Class *clss = method_get_class(method);
assert(clss);
- if (strcmp(method_get_name(method), "run") == 0 &&
+ if (strcmp(method_get_name(method), "runImpl") == 0 &&
strcmp(class_get_name(clss), "java/lang/VMStart$MainThread") == 0)
{
- skip = 3;
+ skip = 4;
}
}
@@ -153,7 +153,7 @@
// Check that this thread is not current
if (vm_thread != p_TLS_vmthread)
{
- thread_suspend(thread);
+ jthread_suspend(thread);
thread_suspended = true;
}
}
@@ -176,7 +176,7 @@
if (start < 0)
{
if (thread_suspended)
- thread_resume(thread);
+ jthread_resume(thread);
return JVMTI_ERROR_ILLEGAL_ARGUMENT;
}
}
@@ -264,7 +264,7 @@
}
if (thread_suspended)
- thread_resume(thread);
+ jthread_resume(thread);
return errStack;
}
@@ -311,12 +311,12 @@
// FIXME: new threads can be created before all threads are suspended
// event handler for thread_creating should block creation new threads
// at this moment
- assert(tmn_is_suspend_enabled());
- tm_acquire_tm_lock();
+ assert(hythread_is_suspend_enabled());
+ hythread_global_lock();
res = jvmtiGetAllThreads(env, &count, &threads);
if (res != JVMTI_ERROR_NONE) {
- tm_release_tm_lock();
+ hythread_global_unlock();
return res;
}
@@ -345,7 +345,7 @@
if (info[i].state != JVMTI_THREAD_STATE_SUSPENDED) {
if (IsSameObject(jvmti_test_jenv, currentThread, threads[i]))
continue;
- thread_suspend(threads[i]);
+ jthread_suspend(threads[i]);
}
}
@@ -365,10 +365,10 @@
// unsuspend suspended threads.
for(i = 0; i < count; i++) {
if (info[i].state != JVMTI_THREAD_STATE_SUSPENDED)
- thread_resume(threads[i]);
+ jthread_resume(threads[i]);
}
- tm_release_tm_lock();
+ hythread_global_unlock();
* thread_count_ptr = count;
*stack_info_ptr = info;
return JVMTI_ERROR_NONE;
@@ -439,7 +439,7 @@
if (info[i].state != JVMTI_THREAD_STATE_SUSPENDED) {
if (IsSameObject(jvmti_test_jenv, currentThread, threads[i]))
continue;
- thread_suspend(threads[i]);
+ jthread_suspend(threads[i]);
}
}
@@ -459,7 +459,7 @@
// unsuspend suspended threads.
for(i = 0; i < count; i++) {
if (info[i].state != JVMTI_THREAD_STATE_SUSPENDED)
- thread_resume(threads[i]);
+ jthread_resume(threads[i]);
}
*stack_info_ptr = info;
@@ -521,7 +521,7 @@
// Check that this thread is not current
if (vm_thread != p_TLS_vmthread)
{
- thread_suspend(thread);
+ jthread_suspend(thread);
thread_suspended = true;
}
}
@@ -540,7 +540,7 @@
}
if (thread_suspended)
- thread_resume(thread);
+ jthread_resume(thread);
return errStack;
}
@@ -668,7 +668,7 @@
// Check that this thread is not current
if (vm_thread != p_TLS_vmthread)
{
- thread_suspend(thread);
+ jthread_suspend(thread);
thread_suspended = true;
}
}
@@ -760,7 +760,7 @@
}
if (thread_suspended)
- thread_resume(thread);
+ jthread_resume(thread);
return errStack;
}
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp Wed Aug 23 09:48:41 2006
@@ -27,28 +27,27 @@
#include "jvmti_utils.h"
#include "vm_threads.h"
#include "thread_generic.h"
-#include "open/thread.h"
+
+#include "open/ti_thread.h"
+#include "open/jthread.h"
#include "thread_manager.h"
#include "object_handles.h"
#include "open/vm_util.h"
#include "platform_lowlevel.h"
#include "mon_enter_exit.h"
-#include "mon_enter_exit.h"
#include "interpreter_exports.h"
#include "environment.h"
#include "suspend_checker.h"
+
#define MAX_JVMTI_ENV_NUMBER 10
-// jvmti_local_storage_static is used to store local storage for thread == NULL
-static JVMTILocalStorage jvmti_local_storage_static[MAX_JVMTI_ENV_NUMBER];
static JNIEnv * jvmti_test_jenv = jni_native_intf;
-extern VM_thread * get_vm_thread_ptr_safe(JNIEnv * env, jobject thread);
-jobject get_jobject(VM_thread * thread);
Boolean is_valid_thread_object(jthread thread)
{
- if (NULL == thread)
+ if (NULL == thread){
return false;
+ }
tmn_suspend_disable(); //---------------------------------v
ObjectHandle h = (ObjectHandle)thread;
@@ -56,15 +55,13 @@
// Check that reference pointer points to the heap
if (mo < (ManagedObject *)Class::heap_base ||
- mo > (ManagedObject *)Class::heap_end)
- {
+ mo > (ManagedObject *)Class::heap_end){
tmn_suspend_enable();
return false;
}
// Check that object is an instance of java.lang.Thread or extends it
- if (mo->vt() == NULL)
- {
+ if (mo->vt() == NULL){
tmn_suspend_enable();
return false;
}
@@ -104,21 +101,13 @@
return JVMTI_ERROR_INVALID_THREAD;
}
else
- thread = thread_current_thread();
+ thread = jthread_self();
- if (thread_state_ptr == NULL)
- {
+ if (thread_state_ptr == NULL){
return JVMTI_ERROR_NULL_POINTER;
}
-
- int state = thread_get_thread_state(thread);
-
- if (state == -1)
- {
- return JVMTI_ERROR_THREAD_NOT_ALIVE; // non-existant thread
- }
-
- * thread_state_ptr = state;
+ IDATA UNUSED status = jthread_get_state(thread, thread_state_ptr);
+ assert(status == TM_ERROR_NONE);
return JVMTI_ERROR_NONE;
}
@@ -140,6 +129,10 @@
jint* threads_count_ptr,
jthread** threads_ptr)
{
+ jthread_iterator_t iterator;
+ int i,java_thread_count;
+ jthread* java_threads;
+ jvmtiError err;
TRACE2("jvmti.thread", "GetAllThreads called");
SuspendEnabledChecker sec;
/*
@@ -149,13 +142,25 @@
CHECK_EVERYTHING();
- if (threads_count_ptr == NULL || threads_ptr == NULL)
- {
+ if (threads_count_ptr == NULL || threads_ptr == NULL){
return JVMTI_ERROR_NULL_POINTER;
}
- *threads_count_ptr = thread_get_all_threads(threads_ptr);
+ //jthread_get_all_threads(threads_ptr, threads_count_ptr);
+ iterator=jthread_iterator_create();
+ java_thread_count = jthread_iterator_size(iterator);
+ //allocate memory
+ err=jvmtiAllocate(env,java_thread_count*sizeof(jthread),(unsigned char**)&java_threads);
+ if (err != JVMTI_ERROR_NONE){
+ return err;
+ }
+ for (i=0;i<java_thread_count;i++) {
+ java_threads[i]=jthread_iterator_next(&iterator);
+ }
+ *threads_count_ptr = java_thread_count;
+ *threads_ptr = java_threads;
+ jthread_iterator_release(&iterator);
return JVMTI_ERROR_NONE;
}
@@ -186,12 +191,10 @@
jvmtiError err = env -> GetCapabilities(&capa);
- if (err != JVMTI_ERROR_NONE)
- {
+ if (err != JVMTI_ERROR_NONE){
return err;
}
- if (capa.can_suspend == 0)
- {
+ if (capa.can_suspend == 0){
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
@@ -201,24 +204,25 @@
return JVMTI_ERROR_INVALID_THREAD;
}
else
- thread = thread_current_thread();
+ thread = jthread_self();
jint state;
err = jvmtiGetThreadState(env, thread, &state);
- if (err != JVMTI_ERROR_NONE)
+ if (err != JVMTI_ERROR_NONE){
return err;
+ }
// check error condition: JVMTI_ERROR_THREAD_NOT_ALIVE
if ((state & JVMTI_THREAD_STATE_ALIVE) == 0)
return JVMTI_ERROR_THREAD_NOT_ALIVE;
- if ((state & JVMTI_THREAD_STATE_SUSPENDED) != 0)
+ if (state & JVMTI_THREAD_STATE_SUSPENDED)
return JVMTI_ERROR_THREAD_SUSPENDED;
- thread_suspend(thread);
- return JVMTI_ERROR_NONE;
+
+ return (jvmtiError)jthread_suspend(thread);
}
/*
@@ -254,27 +258,20 @@
jvmtiError err = env -> GetCapabilities(&capa);
- if (err != JVMTI_ERROR_NONE)
- {
+ if (err != JVMTI_ERROR_NONE){
return err;
}
- if (capa.can_suspend == 0)
- {
+ if (capa.can_suspend == 0){
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
-
- if (request_count < 0)
- {
+ if (request_count < 0){
return JVMTI_ERROR_ILLEGAL_ARGUMENT;
}
-
- if (request_list == NULL || results == NULL)
- {
+ if (request_list == NULL || results == NULL){
return JVMTI_ERROR_NULL_POINTER;
}
- for (int i = 0; i < request_count; i++)
- {
+ for (int i = 0; i < request_count; i++){
results[i] = jvmtiSuspendThread(env, request_list[i]);
}
@@ -308,17 +305,16 @@
jvmtiError err = jvmtiGetCapabilities(env, &capa);
- if (err != JVMTI_ERROR_NONE)
- {
+ if (err != JVMTI_ERROR_NONE){
return err;
}
- if (capa.can_suspend == 0)
- {
+ if (capa.can_suspend == 0){
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
-
- if (false)
- { // TBD
+ if (!is_valid_thread_object(thread)){
+ return JVMTI_ERROR_INVALID_THREAD;
+ }
+ if (false){ // TBD
return JVMTI_ERROR_INVALID_TYPESTATE;
}
@@ -326,20 +322,19 @@
return JVMTI_ERROR_INVALID_THREAD;
jint state;
- // check error condition: JVMTI_ERROR_INVALID_THREAD
+
err = jvmtiGetThreadState(env, thread, &state);
if (err != JVMTI_ERROR_NONE)
return err;
- // check error condition: JVMTI_ERROR_THREAD_NOT_ALIVE
if ((state & JVMTI_THREAD_STATE_ALIVE) == 0)
return JVMTI_ERROR_THREAD_NOT_ALIVE;
if ((state & JVMTI_THREAD_STATE_SUSPENDED) == 0)
return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
- thread_resume(thread);
+ jthread_resume(thread);
return JVMTI_ERROR_NONE;
}
@@ -373,27 +368,20 @@
jvmtiError err = env -> GetCapabilities(&capa);
- if (err != JVMTI_ERROR_NONE)
- {
+ if (err != JVMTI_ERROR_NONE){
return err;
}
- if (capa.can_suspend == 0)
- {
+ if (capa.can_suspend == 0){
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
-
- if (request_count < 0)
- {
+ if (request_count < 0){
return JVMTI_ERROR_ILLEGAL_ARGUMENT;
}
-
- if (request_list == NULL || results == NULL)
- {
+ if (request_list == NULL || results == NULL){
return JVMTI_ERROR_NULL_POINTER;
}
- for (int i = 0; i < request_count; i++)
- {
+ for (int i = 0; i < request_count; i++){
results[i] = jvmtiResumeThread(env, request_list[i]);
}
@@ -413,7 +401,7 @@
jvmtiError JNICALL
jvmtiStopThread(jvmtiEnv* env,
jthread thread,
- jobject UNREF exception)
+ jobject exception)
{
TRACE2("jvmti.thread", "StopThread called");
SuspendEnabledChecker sec;
@@ -428,19 +416,17 @@
jvmtiError err = env -> GetCapabilities(&capa);
- if (err != JVMTI_ERROR_NONE)
- {
+ if (err != JVMTI_ERROR_NONE){
return err;
}
- if (capa.can_signal_thread == 0)
- {
+ if (capa.can_signal_thread == 0){
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
-
- if (!is_valid_thread_object(thread))
+ if (!is_valid_thread_object(thread)){
return JVMTI_ERROR_INVALID_THREAD;
+ }
- thread_stop(thread, NULL);
+ jthread_exception_stop(thread, exception);
return JVMTI_NYI;
}
@@ -470,28 +456,17 @@
jvmtiError err = env -> GetCapabilities(&capa);
- if (err != JVMTI_ERROR_NONE)
- {
+ if (err != JVMTI_ERROR_NONE){
return err;
}
- if (capa.can_signal_thread == 0)
- {
+ if (capa.can_signal_thread == 0){
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
-
- if (!is_valid_thread_object(thread))
+ if (!is_valid_thread_object(thread)){
return JVMTI_ERROR_INVALID_THREAD;
-
- VM_thread * vm_thread = get_vm_thread_ptr_safe(jvmti_test_jenv, thread);
-
- if (!vm_thread)
- {
- return JVMTI_ERROR_THREAD_NOT_ALIVE; // non-existant thread
}
- thread_interrupt(thread);
-
- return JVMTI_ERROR_NONE;
+ return (jvmtiError)jthread_interrupt(thread);
}
/*
@@ -525,7 +500,7 @@
return JVMTI_ERROR_INVALID_THREAD;
}
else
- thread = thread_current_thread();
+ thread = jthread_self();
jclass cl = GetObjectClass(jvmti_test_jenv, thread);
jmethodID id = jvmti_test_jenv -> GetMethodID(cl, "getName","()Ljava/lang/String;");
@@ -573,42 +548,36 @@
jvmtiError err = env -> GetCapabilities(&capa);
- if (err != JVMTI_ERROR_NONE)
- {
+ if (err != JVMTI_ERROR_NONE){
return err;
}
- if (capa.can_get_owned_monitor_info == 0)
- {
+ if (capa.can_get_owned_monitor_info == 0){
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
-
if (NULL != thread)
{
if (!is_valid_thread_object(thread))
return JVMTI_ERROR_INVALID_THREAD;
}
else
- thread = thread_current_thread();
-
- VM_thread * vm_thread = get_vm_thread_ptr_safe(jvmti_test_jenv, thread);
-
- if (!vm_thread)
- {
- return JVMTI_ERROR_THREAD_NOT_ALIVE; // non-existant thread
- }
-
- if (owned_monitor_count_ptr == NULL || owned_monitors_ptr == NULL)
- {
+ thread = jthread_self();
+ if (owned_monitor_count_ptr == NULL || owned_monitors_ptr == NULL){
return JVMTI_ERROR_NULL_POINTER;
}
- int count = thread_get_owned_monitor_info(thread, owned_monitors_ptr);
+ jint state;
- if (count == -1){
- return JVMTI_ERROR_NULL_POINTER;
+ err = jvmtiGetThreadState(env, thread, &state);
+
+ if (err != JVMTI_ERROR_NONE){
+ return err;
+ }
+ if ((state & JVMTI_THREAD_STATE_ALIVE) == 0){
+ return JVMTI_ERROR_THREAD_NOT_ALIVE;
}
- *owned_monitor_count_ptr = count;
+ IDATA UNUSED status = jthread_get_owned_monitors(thread, owned_monitor_count_ptr, owned_monitors_ptr);
+ assert(status == TM_ERROR_NONE);
return JVMTI_ERROR_NONE;
}
@@ -639,37 +608,32 @@
jvmtiError err = env -> GetCapabilities(&capa);
- if (err != JVMTI_ERROR_NONE)
- {
+ if (err != JVMTI_ERROR_NONE){
return err;
}
- if (capa.can_get_current_contended_monitor == 0)
- {
+ if (capa.can_get_current_contended_monitor == 0){
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
-
- if (monitor_ptr == NULL)
- {
+ if (monitor_ptr == NULL){
return JVMTI_ERROR_NULL_POINTER;
}
-
if (NULL == thread)
- thread = thread_current_thread();
+ thread = jthread_self();
jint state;
- // check error condition: JVMTI_ERROR_INVALID_THREAD
+
err = jvmtiGetThreadState(env, thread, &state);
- if (err != JVMTI_ERROR_NONE)
+ if (err != JVMTI_ERROR_NONE){
return err;
-
- // check error condition: JVMTI_ERROR_THREAD_NOT_ALIVE
- if ((state & JVMTI_THREAD_STATE_ALIVE) == 0)
+ }
+ if ((state & JVMTI_THREAD_STATE_ALIVE) == 0){
return JVMTI_ERROR_THREAD_NOT_ALIVE;
+ }
- *monitor_ptr = thread_contends_for_lock(thread);
+ IDATA status = jthread_get_contended_monitor(thread, monitor_ptr);
- return JVMTI_ERROR_NONE;
+ return (jvmtiError)status;
}
/*
@@ -696,16 +660,13 @@
CHECK_EVERYTHING();
- if (priority < JVMTI_THREAD_MIN_PRIORITY || priority > JVMTI_THREAD_MAX_PRIORITY)
- {
+ if (priority < JVMTI_THREAD_MIN_PRIORITY || priority > JVMTI_THREAD_MAX_PRIORITY){
return JVMTI_ERROR_INVALID_PRIORITY;
}
-
- if (!is_valid_thread_object(thread))
+ if (!is_valid_thread_object(thread)){
return JVMTI_ERROR_INVALID_THREAD;
-
- if (proc == NULL)
- {
+ }
+ if (proc == NULL){
return JVMTI_ERROR_NULL_POINTER;
}
@@ -716,7 +677,14 @@
assert(set_daemon);
CallVoidMethod(jvmti_test_jenv, thread, set_daemon, JNI_TRUE);
// Run new thread
- Java_java_lang_Thread_start_generic(jvmti_test_jenv, thread, env, proc, arg, priority);
+ // FIXME TM integration, pass arguments correctly
+ //Java_java_lang_Thread_start_generic(jvmti_test_jenv, thread, env, proc, arg, priority);
+ jthread_threadattr_t attrs;
+ attrs.priority = priority;
+ attrs.stacksize = 0;
+ attrs.daemon = JNI_TRUE;
+ attrs.jvmti_env = env;
+ jthread_create_with_function(jvmti_test_jenv, thread, &attrs, proc, arg);
return JVMTI_ERROR_NONE;
}
@@ -749,33 +717,38 @@
if (NULL != thread)
{
- if (!is_valid_thread_object(thread))
+ if (!is_valid_thread_object(thread)){
return JVMTI_ERROR_INVALID_THREAD;
}
+ }
else
- thread = thread_current_thread();
+ thread = jthread_self();
- VM_thread* vm_thread = thread != NULL ?
- get_vm_thread_ptr_safe(jvmti_test_jenv, thread) : p_TLS_vmthread;
+ jint state;
- if (!vm_thread)
- {
- return JVMTI_ERROR_THREAD_NOT_ALIVE; // non-existant thread
+ jvmtiError err = jvmtiGetThreadState(env, thread, &state);
+
+ if (err != JVMTI_ERROR_NONE){
+ return err;
+ }
+ if ((state & JVMTI_THREAD_STATE_ALIVE) == 0){
+ return JVMTI_ERROR_THREAD_NOT_ALIVE;
}
+
JVMTILocalStorage* aa = NULL;
- JVMTILocalStorage* lstg = &vm_thread -> jvmti_local_storage;
+ JVMTILocalStorage* lstg = jthread_get_jvmti_local_storage(thread);
if (lstg -> env == NULL) {
if (lstg -> data == NULL) {
// we have no records stored;
// so, we put our first record into vm_thread -> jvmti_local_storage
- vm_thread -> jvmti_local_storage.env = (data == NULL) ? NULL : env;
- vm_thread -> jvmti_local_storage.data = (void *)data;
+ lstg -> env = (data == NULL) ? NULL : env;
+ lstg -> data = (void *)data;
return JVMTI_ERROR_NONE;
} else {
// we have more than one record stored;
// so, they are stored in array which is pointed at by
// vm_thread -> jvmti_local_storage -> data
- aa = (JVMTILocalStorage*)vm_thread -> jvmti_local_storage.data;
+ aa = (JVMTILocalStorage*)lstg -> data;
}
} else {
// we have just one record stored;
@@ -793,21 +766,25 @@
aa[0].env = NULL;
aa[0].data = NULL;
}
- aa[0].env = vm_thread -> jvmti_local_storage.env;
- aa[0].data = vm_thread -> jvmti_local_storage.data;
- vm_thread -> jvmti_local_storage.env = NULL;
- vm_thread -> jvmti_local_storage.data = (void *) aa;
+ aa[0].env = lstg -> env;
+ aa[0].data = lstg -> data;
+ lstg -> env = NULL;
+ lstg -> data = (void *)aa;
}
}
// array look up for existing env or for free record
+ int ii = -1;
for (int i = 0; i < MAX_JVMTI_ENV_NUMBER; i++){
- if (aa[i].env == env || aa[i].env == NULL ) {
- aa[i].env = (data == NULL) ? NULL : env;
- aa[i].data = (void *)data;
- return JVMTI_ERROR_NONE;
+ if (aa[i].env == env){
+ ii = i;
+ break;
+ } else if (aa[i].env == NULL && ii < 0){
+ ii = i;
}
}
- ASSERT(0, "Array is full");
+ assert(ii > -1); // ii == -1 => array is full
+ aa[ii].env = (data == NULL) ? NULL : env;
+ aa[ii].data = (void *)data;
return JVMTI_ERROR_NONE;
}
@@ -834,329 +811,35 @@
CHECK_EVERYTHING();
- if (data_ptr == NULL)
+ if (data_ptr == NULL){
return JVMTI_ERROR_NULL_POINTER;
+ }
if (NULL != thread)
{
- if (!is_valid_thread_object(thread))
+ if (!is_valid_thread_object(thread)){
return JVMTI_ERROR_INVALID_THREAD;
}
- else
- thread = thread_current_thread();
-
- *data_ptr = NULL;
-
- VM_thread* vm_thread = thread != NULL ?
- get_vm_thread_ptr_safe(jvmti_test_jenv, thread) : p_TLS_vmthread;
-
- if (!vm_thread)
- return JVMTI_ERROR_THREAD_NOT_ALIVE; // non-existant thread
-
- JVMTILocalStorage* lstg = &vm_thread -> jvmti_local_storage;
- if (lstg -> env == NULL) {
- if (lstg -> data != NULL) {
- // we have more than one record stored;
- // so, they are stored in array which is pointed at by
- // vm_thread -> jvmti_local_storage -> data
- JVMTILocalStorage* aa = (JVMTILocalStorage* )lstg -> data;
- for (int i = 0; i < MAX_JVMTI_ENV_NUMBER; i++){
- if (aa[i].env == env) {
- *data_ptr = aa[i].data;
- break;
- }
- }
- }
- } else {
- // we have just one record stored;
- // so, it's stored in vm_thread -> jvmti_local_storage
- if (lstg -> env == env) {
- *data_ptr = lstg -> data;
- }
- }
-
- return JVMTI_ERROR_NONE;
-}
-
-/*
- * -------------------------------------------------------------------------------
- * -------------------------------------------------------------------------------
- */
-
-jobject get_jobject(VM_thread * thread) {
- ObjectHandle hThread = oh_allocate_global_handle();
- tmn_suspend_disable();
- hThread->object = (struct ManagedObject *)thread->p_java_lang_thread;
- tmn_suspend_enable();
- return (jthread)hThread;
-}
-
-int thread_get_thread_state(jthread thread) {
-
- VM_thread * vm_thread = get_vm_thread_ptr_safe(jvmti_test_jenv, thread);
-
- if ( !vm_thread)
- {
- jclass cl = GetObjectClass(jvmti_test_jenv, thread);
- jfieldID id = jvmti_test_jenv -> GetFieldID(cl, "started", "Z");
- jboolean started = jvmti_test_jenv -> GetBooleanField(thread, id);
- return started ? JVMTI_THREAD_STATE_TERMINATED : 0; // 0 - New thread
- }
- return vm_thread -> get_jvmti_thread_state(thread);
-}
-
-jint VM_thread::get_jvmti_thread_state(jthread thread){
-
- // see: thread_is_alive(jobject jThreadObj)
- jint jvmti_thread_state = 0;
- if ( app_status == zip) {
- return JVMTI_ERROR_THREAD_NOT_ALIVE; // non-existant thread
- }
- java_state as = this->app_status;
- switch (as) {
- case thread_is_sleeping:
- jvmti_thread_state |= JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_SLEEPING |
- JVMTI_THREAD_STATE_WAITING;
- break;
- case thread_is_waiting:
- jvmti_thread_state |= JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_WAITING |
- JVMTI_THREAD_STATE_IN_OBJECT_WAIT |
- JVMTI_THREAD_STATE_WAITING_INDEFINITELY;
- break;
- case thread_is_timed_waiting:
- jvmti_thread_state |= JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_WAITING |
- JVMTI_THREAD_STATE_IN_OBJECT_WAIT |
- JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT;
- break;
- case thread_is_blocked:
- jvmti_thread_state |= JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
- break;
- case thread_is_birthing:
- case thread_is_running:
- jvmti_thread_state |= JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_RUNNABLE;
- break;
- case thread_is_dying:
- jvmti_thread_state |= JVMTI_THREAD_STATE_TERMINATED;
- break;
- default:
- ABORT("Unexpected thread state");
- break;
- }
- // end see
- jvmti_thread_state |= this -> jvmti_thread_state & JVMTI_THREAD_STATE_WAITING_INDEFINITELY;
- jvmti_thread_state |= this -> jvmti_thread_state & JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT;
- jvmti_thread_state |= this -> jvmti_thread_state & JVMTI_THREAD_STATE_SUSPENDED;
- if (thread_is_alive(thread)){
- jvmti_thread_state |= JVMTI_THREAD_STATE_ALIVE;
- }
- if (thread_is_interrupted(thread, JNI_FALSE)){
- jvmti_thread_state |= JVMTI_THREAD_STATE_INTERRUPTED;
- }
- unsigned nnn = interpreter.interpreter_st_get_interrupted_method_native_bit(this);
- if (nnn) {
- jvmti_thread_state |= JVMTI_THREAD_STATE_IN_NATIVE;
- }
- return jvmti_thread_state;
-}
-
-int thread_get_all_threads(jthread** threads_ptr){
-
- jthread * all_jthreads = NULL;
- int num_active_threads = 0;
-
- tm_iterator_t * iterator = tm_iterator_create();
- VM_thread *thread = tm_iterator_next(iterator);
- assert(thread);
- while (thread)
- {
- num_active_threads++;
- thread = tm_iterator_next(iterator);
- }
-
- jvmtiError jvmti_error = _allocate(sizeof(jthread*) *
- num_active_threads, (unsigned char **)&all_jthreads);
-
- if (JVMTI_ERROR_NONE != jvmti_error)
- {
- tm_iterator_release(iterator);
- return jvmti_error;
- }
-
- int ii = 0;
-
- tm_iterator_reset(iterator);
- thread = tm_iterator_next(iterator);
- while (thread)
- {
- all_jthreads[ii] = get_jobject(thread);
- ii++;
- thread = tm_iterator_next(iterator);
- }
- tm_iterator_release(iterator);
-
- *threads_ptr = all_jthreads;
- return num_active_threads;
-}
-
-jobject thread_contends_for_lock(jthread thread)
-{
- SuspendEnabledChecker sec;
- VM_thread *vm_thread = get_vm_thread_ptr_safe(jvmti_test_jenv, thread);
-
- assert(vm_thread);
-
- tmn_suspend_disable();
- ManagedObject *p_obj = mon_enter_array[vm_thread->thread_index].p_obj;
- if (NULL == p_obj)
- {
- tmn_suspend_enable();
- return NULL;
- }
-
- ObjectHandle oh = oh_allocate_local_handle();
- oh->object = p_obj;
- tmn_suspend_enable();
-
- return (jobject)oh;
-}
-
-int thread_get_owned_monitor_info(jthread thread, jobject ** owned_monitors_ptr) {
-
- VM_thread * vm_thread = get_vm_thread_ptr_safe(jvmti_test_jenv, thread);
-
- //assert(vm_thread);
- if (!vm_thread)
- {
- return -1; // non-existant thread
- }
-
- jint count = vm_thread -> jvmti_owned_monitor_count;
- jobject* pp = NULL;
- jvmtiError jvmti_error = _allocate(sizeof(jobject*) * count, (unsigned char **)&pp);
-
- if (jvmti_error != JVMTI_ERROR_NONE)
- {
- return -1;
- }
-
- int i;
- for(i = 0; i < count; i++)
- {
- pp[i] = vm_thread -> jvmti_owned_monitors[i];
- }
- *owned_monitors_ptr = pp;
- return count;
-}
-
-
-void thread_stop(jthread thread, jobject UNREF threadDeathException) {
-
- VM_thread * vm_thread = get_vm_thread_ptr_safe(jni_native_intf, thread);
-
- vm_thread -> is_stoped = true;
-}
-
-
-int thread_set_jvmt_thread_local_storage(jvmtiEnv* env,
- jthread thread,
- const void* data)
-{
- if (thread == NULL)
- {
- for (int i = 0; i < MAX_JVMTI_ENV_NUMBER; i++){
- if (jvmti_local_storage_static[i].env == env ||
- jvmti_local_storage_static[i].env == NULL ) {
-
- jvmti_local_storage_static[i].env = (data == NULL) ? NULL : env;
- jvmti_local_storage_static[i].data = (void *)data;
- return 0;
- }
- }
- ABORT("Can't find appropriate local storage for the thread");
- return -1;
}
+ else
+ thread = jthread_self();
- VM_thread* vm_thread = get_vm_thread_ptr_safe(jvmti_test_jenv, thread);
+ jint state;
+ jvmtiError err = jvmtiGetThreadState(env, thread, &state);
- if (!vm_thread)
- {
- return -1; // non-existant thread
- }
- JVMTILocalStorage* aa = NULL;
- JVMTILocalStorage* lstg = &vm_thread -> jvmti_local_storage;
- if (lstg -> env == NULL) {
- if (lstg -> data == NULL) {
- // we have no records stored;
- // so, we put our first record into vm_thread -> jvmti_local_storage
- vm_thread -> jvmti_local_storage.env = (data == NULL) ? NULL : env;
- vm_thread -> jvmti_local_storage.data = (void *)data;
- return JVMTI_ERROR_NONE;
- } else {
- // we have more than one record stored;
- // so, they are stored in array which is pointed at by
- // vm_thread -> jvmti_local_storage -> data
- aa = (JVMTILocalStorage*)vm_thread -> jvmti_local_storage.data;
- }
- } else {
- // we have just one record stored;
- // so, it's stored in vm_thread -> jvmti_local_storage
- if (lstg -> env == env) {
- // override data in this record
- lstg -> data = (void *)data;
- return 0;
- } else if (data != NULL){
- // we have just one record stored and we have to add another one;
- // so, array is created and record is copied there
- aa = (JVMTILocalStorage*)STD_MALLOC(sizeof(JVMTILocalStorage)*
- MAX_JVMTI_ENV_NUMBER);
- for (int i = 0; i < MAX_JVMTI_ENV_NUMBER; i++){
- aa[0].env = NULL;
- aa[0].data = NULL;
- }
- aa[0].env = vm_thread -> jvmti_local_storage.env;
- aa[0].data = vm_thread -> jvmti_local_storage.data;
- vm_thread -> jvmti_local_storage.env = NULL;
- vm_thread -> jvmti_local_storage.data = (void *) aa;
- }
- }
- // array look up for existing env or for free record
- for (int i = 0; i < MAX_JVMTI_ENV_NUMBER; i++){
- if (aa[i].env == env || aa[i].env == NULL ) {
- aa[i].env = (data == NULL) ? NULL : env;
- aa[i].data = (void *)data;
- return 0;
- }
+ if (err != JVMTI_ERROR_NONE){
+ return err;
}
- ABORT("Array is full");
-
- return 0;
+ if ((state & JVMTI_THREAD_STATE_ALIVE) == 0){
+ return JVMTI_ERROR_THREAD_NOT_ALIVE;
}
-int thread_get_jvmti_thread_local_storage(jvmtiEnv* env,
- jthread thread,
- void** data_ptr)
-{
*data_ptr = NULL;
- if (thread == NULL) // for compatibility with other Java VM
- {
- for (int i = 0; i < MAX_JVMTI_ENV_NUMBER; i++){
- if (jvmti_local_storage_static[i].env == env) {
- *data_ptr = jvmti_local_storage_static[i].data;
- break;
- }
- }
- return 0;
- }
-
- VM_thread* vm_thread = get_vm_thread_ptr_safe(jvmti_test_jenv, thread);
-
- if (!vm_thread)
- {
- return -1; // non-existant thread
- }
+ //if (!vm_thread)
+ // return JVMTI_ERROR_THREAD_NOT_ALIVE; // non-existant thread
- JVMTILocalStorage* lstg = &vm_thread -> jvmti_local_storage;
+ JVMTILocalStorage* lstg = jthread_get_jvmti_local_storage(thread);
if (lstg -> env == NULL) {
if (lstg -> data != NULL) {
// we have more than one record stored;
@@ -1177,5 +860,6 @@
*data_ptr = lstg -> data;
}
}
- return 0;
+
+ return JVMTI_ERROR_NONE;
}
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread_group.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread_group.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread_group.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread_group.cpp Wed Aug 23 09:48:41 2006
@@ -23,13 +23,13 @@
#include "jvmti_utils.h"
#include "vm_threads.h"
+#include <open/jthread.h>
#include "open/vm_util.h"
#include "cxxlog.h"
#include "suspend_checker.h"
#include "environment.h"
static JNIEnv_Internal * jvmti_test_jenv = jni_native_intf;
-jobject get_jobject(VM_thread * thread);
/*
* Get Top Thread Groups
@@ -60,7 +60,7 @@
jclass cl = struct_Class_to_java_lang_Class_Handle(VM_Global_State::loader_env->java_lang_Thread_Class);
jmethodID id = jvmti_test_jenv -> GetMethodID(cl,
"getThreadGroup","()Ljava/lang/ThreadGroup;");
- jobject current_thread = get_jobject(p_TLS_vmthread);
+ jobject current_thread = (jobject)jthread_self();
jobject group = jvmti_test_jenv -> CallObjectMethod (current_thread, id);
cl = struct_Class_to_java_lang_Class_Handle(VM_Global_State::loader_env->java_lang_ThreadGroup_Class);
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Object.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Object.java?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Object.java (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Object.java Wed Aug 23 09:48:41 2006
@@ -26,6 +26,10 @@
*/
public class Object {
+ private static final int TM_ERROR_NONE = 0;
+ private static final int TM_ERROR_INTERRUPT = 52;
+ private static final int TM_ERROR_ILLEGAL_STATE = 118;
+
public final Class getClass() {
return VMClassRegistry.getClass(this);
}
@@ -51,18 +55,38 @@
}
public final void notify() {
- VMThreadManager.notify(this);
+ int status = VMThreadManager.notify(this);
+ if (status == VMThreadManager.TM_ERROR_ILLEGAL_STATE) {
+ throw new IllegalMonitorStateException();
+ } else if (status != VMThreadManager.TM_ERROR_NONE) {
+ throw new InternalError(
+ "Thread Manager internal error " + status);
+ }
}
public final void notifyAll() {
- VMThreadManager.notifyAll(this);
+ int status = VMThreadManager.notifyAll(this);
+ if (status == VMThreadManager.TM_ERROR_ILLEGAL_STATE) {
+ throw new IllegalMonitorStateException();
+ } else if (status != VMThreadManager.TM_ERROR_NONE) {
+ throw new InternalError(
+ "Thread Manager internal error " + status);
+ }
}
public final void wait(long millis, int nanos) throws InterruptedException {
if(millis < 0 || nanos < 0 || nanos > 999999 ){
throw new IllegalArgumentException("Arguments don't match the expected range!");
}
- VMThreadManager.wait(this, millis, nanos);
+ int status = VMThreadManager.wait(this, millis, nanos);
+ if (status == VMThreadManager.TM_ERROR_INTERRUPT) {
+ throw new InterruptedException();
+ } else if (status == VMThreadManager.TM_ERROR_ILLEGAL_STATE) {
+ throw new IllegalMonitorStateException();
+ } else if (status != VMThreadManager.TM_ERROR_NONE) {
+ // throw new InternalError(
+ // "Thread Manager internal error " + status);
+ }
}
public final void wait(long millis) throws InterruptedException {
@@ -70,7 +94,15 @@
}
public final void wait() throws InterruptedException {
- VMThreadManager.wait(this, 0, 0);
+ int status = VMThreadManager.wait(this, 0, 0);
+ if (status == VMThreadManager.TM_ERROR_INTERRUPT) {
+ throw new InterruptedException();
+ } else if (status == VMThreadManager.TM_ERROR_ILLEGAL_STATE) {
+ throw new IllegalMonitorStateException();
+ } else if (status != VMThreadManager.TM_ERROR_NONE) {
+ // throw new InternalError(
+ // "Thread Manager internal error " + status);
+ }
}
protected void finalize() throws Throwable {
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Runtime.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Runtime.java?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Runtime.java (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Runtime.java Wed Aug 23 09:48:41 2006
@@ -104,9 +104,9 @@
// In the first phase all registered shutdown hooks, if any, are started in some
// unspecified order and allowed to run concurrently until they finish.
synchronized (Synchro.class) {
+ try {
if (VMState == 0) {
VMState = 1;
-
if (hooksList != null) {
for (int i = 0; i < hooksList.size(); i++) {
((Thread)hooksList.elementAt(i)).start();
@@ -126,7 +126,7 @@
hooksList.removeAllElements();
}
}
-
+ } catch (Throwable e) {} // skip any exceptions in shutdown sequence
}
// #2:
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Thread.java Wed Aug 23 09:48:41 2006
@@ -94,6 +94,12 @@
*/
boolean started = false;
+
+ /**
+ * Indicates if the thread is alive.
+ */
+ boolean isAlive = false;
+
/**
* Thread's target - a <code>Runnable</code> object whose <code>run</code>
* method should be invoked
@@ -130,7 +136,7 @@
/**
* Synchronization is done using internal lock.
*/
- private Object lock = new Object();
+ Object lock = new Object();
/**
* generates a unique thread ID
@@ -195,21 +201,6 @@
Thread currentThread = VMThreadManager.currentThread();
SecurityManager securityManager = System.getSecurityManager();
- // If currentThread == this we suppose that the constructor was called
- // by VM to create a Thread instance representing the Main Thread
- if (currentThread == this) {
- this.name = "main";
- this.group = new ThreadGroup();
- this.group.add(this);
- this.priority = NORM_PRIORITY;
- this.daemon = false;
- this.target = null;
- this.stackSize = 0;
- this.started = true;
- // initialize the system class loader and set it as context
- // classloader
- ClassLoader.getSystemClassLoader();
- } else {
ThreadGroup threadGroup = null;
if (group != null) {
if (securityManager != null) {
@@ -227,13 +218,45 @@
// throws NullPointerException if the given name is null
this.name = (name != THREAD) ? this.name = name.toString() : THREAD
+ threadCounter++;
- setPriority(currentThread.priority);
this.daemon = currentThread.daemon;
this.contextClassLoader = currentThread.contextClassLoader;
this.target = target;
this.stackSize = stackSize;
+ this.priority = currentThread.priority;
initializeInheritableLocalValues(currentThread);
+
+ checkGCWatermark();
+
+ ThreadWeakRef oldRef = ThreadWeakRef.poll();
+ ThreadWeakRef newRef = new ThreadWeakRef(this);
+
+ long oldPointer = (oldRef == null)? 0 : oldRef.getNativeAddr();
+ long newPointer = VMThreadManager.init(this, newRef, oldPointer);
+ if (newPointer == 0) {
+ throw new OutOfMemoryError("Failed to create new thread");
}
+ newRef.setNativeAddr(newPointer);
+
+ this.threadId = getNextThreadId();
+ SecurityUtils.putContext(this, AccessController.getContext());
+ checkAccess();
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ Thread(boolean nativeThread) {
+ VMThreadManager.attach(this);
+ this.name = "System thread";
+ this.group = new ThreadGroup();
+ this.group.add(this);
+ this.daemon = false;
+ this.started = true;
+ this.priority = NORM_PRIORITY;
+ // initialize the system class loader and set it as context
+ // classloader
+ ClassLoader.getSystemClassLoader();
+
this.threadId = getNextThreadId();
SecurityUtils.putContext(this, AccessController.getContext());
}
@@ -310,14 +333,24 @@
throw new IllegalArgumentException(
"Arguments don't match the expected range!");
}
- VMThreadManager.sleep(millis, nanos);
+ int status = VMThreadManager.sleep(millis, nanos);
+ if (status == VMThreadManager.TM_ERROR_INTERRUPT) {
+ throw new InterruptedException();
+ } else if (status != VMThreadManager.TM_ERROR_NONE) {
+ throw new InternalError(
+ "Thread Manager internal error " + status);
+ }
}
/**
* @com.intel.drl.spec_ref
*/
public static void yield() {
- VMThreadManager.yield();
+ int status = VMThreadManager.yield();
+ if (status != VMThreadManager.TM_ERROR_NONE) {
+ throw new InternalError(
+ "Thread Manager internal error " + status);
+ }
}
/**
@@ -465,7 +498,11 @@
public void interrupt() {
synchronized (lock) {
checkAccess();
- VMThreadManager.interrupt(this);
+ int status = VMThreadManager.interrupt(this);
+ if (status != VMThreadManager.TM_ERROR_NONE) {
+ throw new InternalError(
+ "Thread Manager internal error " + status);
+ }
}
}
@@ -474,25 +511,10 @@
*/
public final boolean isAlive() {
synchronized (lock) {
- if (!started || group == null) {
- return false;
- }
- return true;
+ return this.isAlive;
}
}
- /**
- * The method is called by VM implementation after run() so that Thread
- * could make some cleanup. Thread removes itself from ThreadGroup. It
- * automatically means that thread is not alive anymore.
- */
- void kill() {
- synchronized (lock) {
- // will set group = null.
- group.remove(this);
- lock.notifyAll();
- }
- }
/**
* @com.intel.drl.spec_ref
@@ -567,7 +589,11 @@
public final void resume() {
synchronized (lock) {
checkAccess();
- VMThreadManager.resume(this);
+ int status = VMThreadManager.resume(this);
+ if (status != VMThreadManager.TM_ERROR_NONE) {
+ throw new InternalError(
+ "Thread Manager internal error " + status);
+ }
}
}
@@ -629,7 +655,11 @@
ThreadGroup threadGroup = group;
this.priority = (priority > threadGroup.maxPriority)
? threadGroup.maxPriority : priority;
- VMThreadManager.setPriority(this, this.priority);
+ int status = VMThreadManager.setPriority(this, this.priority);
+ if (status != VMThreadManager.TM_ERROR_NONE) {
+ // throw new InternalError(
+ // "Thread Manager internal error " + status);
+ }
}
/**
@@ -642,11 +672,37 @@
throw new IllegalThreadStateException(
"This thread was already started!");
}
+
+ this.isAlive = true;
+
+ if (VMThreadManager.start(this, stackSize, daemon, priority) != 0) {
+ throw new OutOfMemoryError("Failed to create new thread");
+ }
+
started = true;
- VMThreadManager.start(this, stackSize);
}
}
+ /*
+ * This method serves as a wrapper around Thread.run() method to meet
+ * specification requirements in regard to ucaught exception catching.
+ */
+ void runImpl() {
+ try {
+ run();
+ } catch (Throwable e) {
+ getUncaughtExceptionHandler().uncaughtException(this, e);
+ } finally {
+ group.remove(this);
+ synchronized(lock) {
+ this.isAlive = false;
+ lock.notifyAll();
+ }
+ }
+ }
+
+
+
// for 5.0
/* public enum State {
NEW,
@@ -687,7 +743,11 @@
.checkPermission(RuntimePermissionCollection.STOP_THREAD_PERMISSION);
}
}
- VMThreadManager.stop(this, throwable);
+ int status = VMThreadManager.stop(this, throwable);
+ if (status != VMThreadManager.TM_ERROR_NONE) {
+ throw new InternalError(
+ "Thread Manager internal error " + status);
+ }
}
}
@@ -697,7 +757,11 @@
public final void suspend() {
synchronized (lock) {
checkAccess();
- VMThreadManager.suspend(this);
+ int status = VMThreadManager.suspend(this);
+ if (status != VMThreadManager.TM_ERROR_NONE) {
+ throw new InternalError(
+ "Thread Manager internal error " + status);
+ }
}
}
@@ -834,5 +898,26 @@
* @com.intel.drl.spec_ref
*/
void uncaughtException(Thread t, Throwable e);
+ }
+
+ /*
+ * Number of threads that was created w/o garbage collection.
+ */
+ private static int currentGCWatermarkCount = 0;
+
+ /*
+ * Max number of threads to be created w/o GC, required collect dead Thread
+ * references.
+ */
+ private static final int GC_WATERMARK_MAX_COUNT = 700;
+
+ /*
+ * Checks if more then GC_WATERMARK_MAX_COUNT threads was created and calls
+ * System.gc() to ensure that dead thread references was callected.
+ */
+ private void checkGCWatermark() {
+ if (++currentGCWatermarkCount % GC_WATERMARK_MAX_COUNT == 0) {
+ System.gc();
+ }
}
}
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ThreadGroup.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ThreadGroup.java?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ThreadGroup.java (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ThreadGroup.java Wed Aug 23 09:48:41 2006
@@ -100,7 +100,7 @@
*/
ThreadGroup() {
this.parent = null;
- this.name = "main";
+ this.name = "System";
this.daemon = false;
}
@@ -119,11 +119,13 @@
threadsCopy = copyThreads();
groupsListCopy = (List)groups.clone();
}
+
for (int i = 0; i < threadsCopy.length; i++) {
if (((Thread) threadsCopy[i]).isAlive()) {
count++;
}
}
+
for (Iterator it = groupsListCopy.iterator(); it.hasNext();) {
count += ((ThreadGroup)it.next()).activeCount();
}
Added: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ThreadWeakRef.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ThreadWeakRef.java?rev=434076&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ThreadWeakRef.java (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ThreadWeakRef.java Wed Aug 23 09:48:41 2006
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+package java.lang;
+
+import java.lang.ref.WeakReference;
+import java.lang.ref.ReferenceQueue;
+
+class ThreadWeakRef extends WeakReference {
+
+ private static ReferenceQueue refQueue = new ReferenceQueue();
+ private long nativeAddr = 0;
+
+ public ThreadWeakRef(Thread thread) {
+ super (thread, ThreadWeakRef.refQueue);
+ }
+
+ public void setNativeAddr(long newAddr) {
+ nativeAddr = newAddr;
+ }
+
+ public long getNativeAddr() {
+ return nativeAddr;
+ }
+
+ public static ThreadWeakRef poll() {
+ return (ThreadWeakRef)refQueue.poll();
+ }
+}
Propchange: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ThreadWeakRef.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMStart.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMStart.java?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMStart.java (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMStart.java Wed Aug 23 09:48:41 2006
@@ -51,6 +51,7 @@
// create main thread in new thread group
MainThread mainThread = new MainThread(mainClassName, args);
mainThread.start();
+ //startHelperThreads();
//System.out.println("Join Group " + Thread.currentThread().getThreadGroup());
} catch (Throwable e) {
e.printStackTrace(System.err);
@@ -103,8 +104,10 @@
this.args = args;
}
-
public void run() {
+ }
+
+ void runImpl() {
// prevent access from user classes to run() method
if(started) {
return;
@@ -137,8 +140,18 @@
} catch (Throwable e) {
exitCode = 1;
e.printStackTrace(System.err);
- }
- }
+ } finally {
+ group.remove(this);
+ synchronized(lock) {
+ this.isAlive = false;
+ lock.notifyAll();
+ }
+ }
+ }
+ }
+
+ static void mainThreadInit() {
+ Thread theFirstThread = new Thread(true);
}
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMThreadManager.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMThreadManager.java?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMThreadManager.java (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMThreadManager.java Wed Aug 23 09:48:41 2006
@@ -37,6 +37,13 @@
final class VMThreadManager {
/**
+ * Thread Manager functions error codes.
+ */
+ public static final int TM_ERROR_NONE = 0;
+ public static final int TM_ERROR_INTERRUPT = 52;
+ public static final int TM_ERROR_ILLEGAL_STATE = 51;
+
+ /**
* This class is not supposed to be instantiated.
*/
private VMThreadManager() {
@@ -79,7 +86,7 @@
* {@link Thread#interrupt() Thread.interrupt()} method.
* @api2vm
*/
- static native void interrupt(Thread thread);
+ static native int interrupt(Thread thread);
/**
* Checks if the specified thread is dead.
@@ -91,7 +98,7 @@
* @return true if the thread has died already, false otherwise.
* @api2vm
*/
- static native boolean isDead(Thread thread);
+ static native boolean isAlive(Thread thread);
/**
* This method satisfies the requirements of the specification for the
@@ -115,29 +122,28 @@
* must be valid.
* @api2vm
*/
- static native void join(Thread thread, long millis, int nanos)
- throws InterruptedException;
+ static native int join(Thread thread, long millis, int nanos);
/**
* This method satisfies the requirements of the specification for the
* {@link Object#notify() Object.notify()} method.
* @api2vm
*/
- static native void notify(Object object);
+ static native int notify(Object object);
/**
* This method satisfies the requirements of the specification for the
* {@link Object#notifyAll() Object.notifyAll()} method.
* @api2vm
*/
- static native void notifyAll(Object object);
+ static native int notifyAll(Object object);
/**
* This method satisfies the requirements of the specification for the
* {@link Thread#resume() Thread.resume()} method.
* @api2vm
*/
- static native void resume(Thread thread);
+ static native int resume(Thread thread);
/**
* Changes the priority of the specified thread.
@@ -149,7 +155,7 @@
* @param priority new priority value
* @api2vm
*/
- static native void setPriority(Thread thread, int priority);
+ static native int setPriority(Thread thread, int priority);
/**
* This method satisfies the requirements of the specification for the
@@ -159,8 +165,7 @@
* must be valid.
* @api2vm
*/
- static native void sleep(long millis, int nanos)
- throws InterruptedException;
+ static native int sleep(long millis, int nanos);
/**
* Starts the specified thread. Causes JVM to start executing
@@ -177,7 +182,7 @@
* @param size the desired stack size in bytes or zero to be ignored
* @api2vm
*/
- static native void start(Thread thread, long size);
+ static native int start(Thread thread, long stackSize, boolean daemon, int priority);
/**
* This method satisfies the requirements of the specification for the
@@ -186,14 +191,14 @@
* exception. The <code>throwable</code> argument must not be null.
* @api2vm
*/
- static native void stop(Thread thread, Throwable throwable);
+ static native int stop(Thread thread, Throwable throwable);
/**
* This method satisfies the requirements of the specification for the
* {@link Thread#suspend() Thread.suspend()} method.
* @api2vm
*/
- static native void suspend(Thread thread);
+ static native int suspend(Thread thread);
/**
* This method satisfies the requirements of the specification for the
@@ -203,7 +208,7 @@
* must be valid.
* @api2vm
*/
- static native void wait(Object object, long millis, int nanos)
+ static native int wait(Object object, long millis, int nanos)
throws InterruptedException;
/**
@@ -211,5 +216,20 @@
* {@link Thread#yield() Thread.yield()} method.
* @api2vm
*/
- static native void yield();
+ static native int yield();
+
+ /**
+ * This method initialize native thread structure as well as inter dependencies
+ * between java thread and native thread.
+ * @api2vm
+ */
+ static native long init(Thread thread, ThreadWeakRef ref, long oldAddr);
+
+ /**
+ * This method attches current thread to vm. Required for main thread construction.
+ * @api2vm
+ */
+ static native int attach(java.lang.Thread thread);
+
}
+
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_FinalizerThread.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_FinalizerThread.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_FinalizerThread.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_FinalizerThread.cpp Wed Aug 23 09:48:41 2006
@@ -28,9 +28,10 @@
#include "java_lang_FinalizerThread.h"
#include "open/gc.h"
-#include "open/thread.h"
+#include "open/hythread_ext.h"
#include "finalize.h"
#include "port_sysinfo.h"
+#include "vm_threads.h"
/**
* Implements getObject(..) method.
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp Wed Aug 23 09:48:41 2006
@@ -33,7 +33,7 @@
#include "jni_utils.h"
#include "reflection.h"
#include "stack_trace.h"
-#include "open/thread.h"
+
#include "vm_strings.h"
#include "java_lang_VMClassRegistry.h"
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMMemoryManager.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMMemoryManager.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMMemoryManager.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMMemoryManager.cpp Wed Aug 23 09:48:41 2006
@@ -26,12 +26,13 @@
* java.lang.VMMemoryManager class.
*/
-#include "open/thread.h"
+
#include "open/gc.h"
#include "jni_utils.h"
#include "object.h"
#include "finalize.h"
#include "cxxlog.h"
+#include "vm_threads.h"
#include "java_lang_VMMemoryManager.h"
@@ -126,7 +127,7 @@
JNIEXPORT void JNICALL Java_java_lang_VMMemoryManager_runGC
(JNIEnv *, jclass)
{
- assert(tmn_is_suspend_enabled());
+ assert(hythread_is_suspend_enabled());
// no matter how counter-intuitive,
// gc_force_gc() expects gc_enabled_status == disabled,
// but, obviously, at a GC safepoint.
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMStart.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMStart.cpp?rev=434076&r1=434075&r2=434076&view=diff
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMStart.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMStart.cpp Wed Aug 23 09:48:41 2006
@@ -18,7 +18,8 @@
* @version $Revision: 1.1.2.1.4.4 $
*/
#include "thread_generic.h"
-#include "open/thread.h"
+#include "open/hythread_ext.h"
+
#ifdef __cplusplus
extern "C" {
@@ -26,7 +27,7 @@
JNIEXPORT void JNICALL Java_java_lang_VMStart_joinAllNonDaemonThreads (JNIEnv * UNREF jenv, jclass UNREF starter)
{
- wait_until_non_daemon_threads_are_dead();
+ hythread_wait_for_all_nondaemon_threads();
}
#ifdef __cplusplus