You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by wj...@apache.org on 2007/07/16 21:32:52 UTC
svn commit: r556704 [4/5] - in /harmony/enhanced/drlvm/trunk: build/make/
build/make/components/vm/ build/make/targets/ vm/include/ 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/te...
Copied: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_monitors.cpp (from r556643, harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_monitors.c)
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_monitors.cpp?view=diff&rev=556704&p1=harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_monitors.c&r1=556643&p2=harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_monitors.cpp&r2=556704
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_monitors.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_monitors.cpp Mon Jul 16 12:32:35 2007
@@ -19,19 +19,20 @@
* @file thread_java_monitors.c
* @brief Java thread monitors related functions
*/
-
-#undef LOG_DOMAIN
-#define LOG_DOMAIN "tm.monitor"
+#include <open/hythread_ext.h>
#include <open/jthread.h>
#include <open/hythread_ext.h>
#include <open/thread_externals.h>
-#include "thread_private.h"
+#include "vm_threads.h"
#include "jni.h"
-void add_owned_monitor(jobject monitor);
-void remove_owned_monitor(jobject monitor);
-void set_contended_monitor(jobject monitor);
-void set_wait_monitor(jobject monitor);
+#define LOG_DOMAIN "tm.monitor"
+#include "cxxlog.h"
+
+static void jthread_add_owned_monitor(jobject monitor);
+static void jthread_remove_owned_monitor(jobject monitor);
+static void jthread_set_owned_monitor(jobject monitor);
+static void jthread_set_wait_monitor(jobject monitor);
/**
@@ -43,18 +44,16 @@
*
* @param[in] monitor object where monitor needs to be initialized.
*/
-IDATA VMCALL jthread_monitor_init(jobject monitor) {
-
- hythread_thin_monitor_t *lockword;
- IDATA status;
+IDATA VMCALL jthread_monitor_init(jobject monitor)
+{
assert(monitor);
-
+
hythread_suspend_disable();
- lockword = vm_object_get_lockword_addr(monitor);
- status = hythread_thin_monitor_create(lockword);
+ hythread_thin_monitor_t *lockword = vm_object_get_lockword_addr(monitor);
+ IDATA status = hythread_thin_monitor_create(lockword);
hythread_suspend_enable();
return status;
-}
+} // jthread_monitor_init
@@ -66,27 +65,23 @@
* @param[in] monitor object where monitor is located
* @sa JNI::MonitorEnter()
*/
-IDATA VMCALL jthread_monitor_enter(jobject monitor) {
- hythread_thin_monitor_t *lockword;
- IDATA status;
- // should be moved to event handler
+IDATA VMCALL jthread_monitor_enter(jobject monitor)
+{
+ IDATA state;
+ hythread_t native_thread;
apr_time_t enter_begin;
- jvmti_thread_t tm_java_thread;
- hythread_t tm_native_thread;
- int disable_count;
assert(monitor);
hythread_suspend_disable();
- lockword = vm_object_get_lockword_addr(monitor);
- status = hythread_thin_monitor_try_enter(lockword);
+ hythread_thin_monitor_t *lockword = vm_object_get_lockword_addr(monitor);
+ IDATA status = hythread_thin_monitor_try_enter(lockword);
if (status != TM_ERROR_EBUSY) {
goto entered;
}
- /////////
#ifdef LOCK_RESERVATION
// busy unreserve lock before blocking and inflating
- while (TM_ERROR_NONE !=unreserve_lock(lockword)) {
+ while (TM_ERROR_NONE != hythread_unreserve_lock(lockword)) {
hythread_yield();
hythread_safe_point();
hythread_exception_safe_point();
@@ -97,86 +92,98 @@
goto entered;
}
#endif //LOCK_RESERVATION
- tm_native_thread = hythread_self();
- tm_native_thread->state &= ~TM_THREAD_STATE_RUNNABLE;
- tm_native_thread->state |= TM_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
+
+ native_thread = hythread_self();
+ hythread_thread_lock(native_thread);
+ state = hythread_get_state(native_thread);
+ state &= ~TM_THREAD_STATE_RUNNABLE;
+ state |= TM_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
+ status = hythread_set_state(native_thread, state);
+ assert(status == TM_ERROR_NONE);
+ hythread_thread_unlock(native_thread);
// should be moved to event handler
if (ti_is_enabled()) {
enter_begin = apr_time_now();
- disable_count = reset_suspend_disable();
- set_contended_monitor(monitor);
+ int disable_count = hythread_reset_suspend_disable();
+ jthread_set_owned_monitor(monitor);
jvmti_send_contended_enter_or_entered_monitor_event(monitor, 1);
- set_suspend_disable(disable_count);
-
+ hythread_set_suspend_disable(disable_count);
}
-
+
// busy wait and inflate
// reload pointer after safepoints
-
lockword = vm_object_get_lockword_addr(monitor);
- while ((status = hythread_thin_monitor_try_enter(lockword)) == TM_ERROR_EBUSY) {
+ while ((status =
+ hythread_thin_monitor_try_enter(lockword)) == TM_ERROR_EBUSY)
+ {
hythread_safe_point();
hythread_exception_safe_point();
lockword = vm_object_get_lockword_addr(monitor);
-
- if (is_fat_lock(*lockword)) {
+
+ if (hythread_is_fat_lock(*lockword)) {
status = hythread_thin_monitor_enter(lockword);
- if (status != TM_ERROR_NONE) {
- hythread_suspend_enable();
- assert(0);
- return status;
- }
- goto contended_entered;
+ if (status != TM_ERROR_NONE) {
+ hythread_suspend_enable();
+ assert(0);
+ return status;
+ }
+ goto contended_entered;
}
hythread_yield();
}
assert(status == TM_ERROR_NONE);
- if (!is_fat_lock(*lockword)) {
- inflate_lock(lockword);
+ if (!hythread_is_fat_lock(*lockword)) {
+ hythread_inflate_lock(lockword);
}
+
// do all ti staff here
contended_entered:
if (ti_is_enabled()) {
- disable_count = reset_suspend_disable();
+ int disable_count = hythread_reset_suspend_disable();
jvmti_send_contended_enter_or_entered_monitor_event(monitor, 0);
- set_suspend_disable(disable_count);
+ hythread_set_suspend_disable(disable_count);
// should be moved to event handler
- tm_java_thread = hythread_get_private_data(hythread_self());
- tm_java_thread->blocked_time += apr_time_now()- enter_begin;
- /////////
+ jvmti_thread_t jvmti_thread =
+ jthread_get_jvmti_thread(hythread_self());
+ jvmti_thread->blocked_time += apr_time_now() - enter_begin;
}
- tm_native_thread->state &= ~TM_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
- tm_native_thread->state |= TM_THREAD_STATE_RUNNABLE;
+
+ hythread_thread_lock(native_thread);
+ state = hythread_get_state(native_thread);
+ state &= ~TM_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
+ state |= TM_THREAD_STATE_RUNNABLE;
+ status = hythread_set_state(native_thread, state);
+ assert(status == TM_ERROR_NONE);
+ hythread_thread_unlock(native_thread);
entered:
- if (ti_is_enabled()) {
- add_owned_monitor(monitor);
- }
+ if (ti_is_enabled()) {
+ jthread_add_owned_monitor(monitor);
+ }
hythread_suspend_enable();
return TM_ERROR_NONE;
-}
+} // jthread_monitor_enter
/**
* Attempt to gain the ownership over monitor without blocking.
*
* @param[in] monitor object where monitor is located
*/
-IDATA VMCALL jthread_monitor_try_enter(jobject monitor) {
- hythread_thin_monitor_t *lockword;
- IDATA status;
+IDATA VMCALL jthread_monitor_try_enter(jobject monitor)
+{
assert(monitor);
hythread_suspend_disable();
- lockword = vm_object_get_lockword_addr(monitor);
- status = hythread_thin_monitor_try_enter(lockword);
-
+ hythread_thin_monitor_t *lockword = vm_object_get_lockword_addr(monitor);
+ IDATA status = hythread_thin_monitor_try_enter(lockword);
hythread_suspend_enable();
+
if (status == TM_ERROR_NONE && ti_is_enabled()) {
- add_owned_monitor(monitor);
+ jthread_add_owned_monitor(monitor);
}
return status;
-}
+} // jthread_monitor_try_enter
/**
* Releases the ownership over monitor.
@@ -184,24 +191,24 @@
* @param[in] monitor monitor
* @sa JNI::MonitorExit()
*/
-IDATA VMCALL jthread_monitor_exit(jobject monitor) {
- hythread_thin_monitor_t *lockword;
- IDATA status;
+IDATA VMCALL jthread_monitor_exit(jobject monitor)
+{
assert(monitor);
hythread_suspend_disable();
-
- lockword = vm_object_get_lockword_addr(monitor);
- status = hythread_thin_monitor_exit(lockword);
+ hythread_thin_monitor_t *lockword = vm_object_get_lockword_addr(monitor);
+ IDATA status = hythread_thin_monitor_exit(lockword);
hythread_suspend_enable();
+
if (status == TM_ERROR_NONE && ti_is_enabled()) {
- remove_owned_monitor(monitor);
+ jthread_remove_owned_monitor(monitor);
}
if (status == TM_ERROR_ILLEGAL_STATE) {
- jthread_throw_exception("java/lang/IllegalMonitorStateException", "Illegal monitor state");
+ jthread_throw_exception("java/lang/IllegalMonitorStateException",
+ "Illegal monitor state");
}
return status;
-}
+} // jthread_monitor_exit
/**
* Notifies one thread waiting on the monitor.
@@ -213,18 +220,17 @@
* @param[in] monitor object where monitor is located
* @sa java.lang.Object.notify()
*/
-IDATA VMCALL jthread_monitor_notify(jobject monitor) {
- hythread_thin_monitor_t *lockword;
- IDATA status;
+IDATA VMCALL jthread_monitor_notify(jobject monitor)
+{
assert(monitor);
hythread_suspend_disable();
- lockword = vm_object_get_lockword_addr(monitor);
- status = hythread_thin_monitor_notify(lockword);
+ hythread_thin_monitor_t *lockword = vm_object_get_lockword_addr(monitor);
+ IDATA status = hythread_thin_monitor_notify(lockword);
hythread_suspend_enable();
return status;
-}
+} // jthread_monitor_notify
/**
* Notifies all threads which are waiting on the monitor.
@@ -235,18 +241,17 @@
* @param[in] monitor object where monitor is located
* @sa java.lang.Object.notifyAll()
*/
-IDATA VMCALL jthread_monitor_notify_all(jobject monitor) {
- hythread_thin_monitor_t *lockword;
- IDATA status;
+IDATA VMCALL jthread_monitor_notify_all(jobject monitor)
+{
assert(monitor);
hythread_suspend_disable();
- lockword = vm_object_get_lockword_addr(monitor);
- status = hythread_thin_monitor_notify_all(lockword);
+ hythread_thin_monitor_t *lockword = vm_object_get_lockword_addr(monitor);
+ IDATA status = hythread_thin_monitor_notify_all(lockword);
hythread_suspend_enable();
return status;
-}
+} // jthread_monitor_notify_all
/**
* Wait on the <code>object</code>'s monitor.
@@ -264,9 +269,10 @@
* @sa java.lang.Object.wait()
* @return
*/
-IDATA VMCALL jthread_monitor_wait(jobject monitor) {
+IDATA VMCALL jthread_monitor_wait(jobject monitor)
+{
return jthread_monitor_timed_wait(monitor, 0, 0);
-}
+} // jthread_monitor_wait
/**
* Wait on the <code>object</code>'s monitor with the specified timeout.
@@ -287,158 +293,187 @@
* @param[in] nanos time to wait (in nanoseconds)
* @sa java.lang.Object.wait()
*/
-
-IDATA VMCALL jthread_monitor_timed_wait(jobject monitor, jlong millis, jint nanos) {
- hythread_thin_monitor_t *lockword;
- IDATA status;
- hythread_t tm_native_thread;
- apr_time_t wait_begin;
- jvmti_thread_t tm_java_thread;
- int disable_count;
-
+IDATA VMCALL
+jthread_monitor_timed_wait(jobject monitor, jlong millis, jint nanos)
+{
assert(monitor);
hythread_suspend_disable();
- lockword = vm_object_get_lockword_addr(monitor);
- if (!is_fat_lock(*lockword)) {
- if (!owns_thin_lock(hythread_self(), *lockword)) {
+ hythread_t native_thread = hythread_self();
+ hythread_thin_monitor_t *lockword = vm_object_get_lockword_addr(monitor);
+ if (!hythread_is_fat_lock(*lockword)) {
+ if (!hythread_owns_thin_lock(native_thread, *lockword)) {
TRACE(("ILLEGAL_STATE wait %x\n", lockword));
hythread_suspend_enable();
- return TM_ERROR_ILLEGAL_STATE;
- }
- inflate_lock(lockword);
+ return TM_ERROR_ILLEGAL_STATE;
+ }
+ hythread_inflate_lock(lockword);
}
+ apr_time_t wait_begin;
if (ti_is_enabled()) {
- disable_count = reset_suspend_disable();
- set_wait_monitor(monitor);
- set_contended_monitor(monitor);
- jvmti_send_wait_monitor_event(monitor, (jlong)millis);
+ int disable_count = hythread_reset_suspend_disable();
+ jthread_set_wait_monitor(monitor);
+ jthread_set_owned_monitor(monitor);
+ jvmti_send_wait_monitor_event(monitor, (jlong) millis);
jvmti_send_contended_enter_or_entered_monitor_event(monitor, 1);
- set_suspend_disable(disable_count);
+ hythread_set_suspend_disable(disable_count);
// should be moved to event handler
wait_begin = apr_time_now();
- ////////
- remove_owned_monitor(monitor);
+ jthread_remove_owned_monitor(monitor);
}
- tm_native_thread = hythread_self();
- tm_native_thread->state &= ~TM_THREAD_STATE_RUNNABLE;
- tm_native_thread->state |= TM_THREAD_STATE_WAITING |
- TM_THREAD_STATE_IN_MONITOR_WAIT;
-
+ hythread_thread_lock(native_thread);
+ IDATA state = hythread_get_state(native_thread);
+ state &= ~TM_THREAD_STATE_RUNNABLE;
+ state |= TM_THREAD_STATE_WAITING | TM_THREAD_STATE_IN_MONITOR_WAIT;
if ((millis > 0) || (nanos > 0)) {
- tm_native_thread->state |= TM_THREAD_STATE_WAITING_WITH_TIMEOUT;
- } else {
- tm_native_thread->state |= TM_THREAD_STATE_WAITING_INDEFINITELY;
+ state |= TM_THREAD_STATE_WAITING_WITH_TIMEOUT;
}
+ else {
+ state |= TM_THREAD_STATE_WAITING_INDEFINITELY;
+ }
+ IDATA status = hythread_set_state(native_thread, state);
+ assert(status == TM_ERROR_NONE);
+ hythread_thread_unlock(native_thread);
- status = hythread_thin_monitor_wait_interruptable(lockword, millis, nanos);
+ status =
+ hythread_thin_monitor_wait_interruptable(lockword, millis, nanos);
- tm_native_thread->state &= ~(TM_THREAD_STATE_WAITING |
- TM_THREAD_STATE_IN_MONITOR_WAIT);
+ hythread_thread_lock(native_thread);
+ state = hythread_get_state(native_thread);
if ((millis > 0) || (nanos > 0)) {
- tm_native_thread->state &= ~TM_THREAD_STATE_WAITING_WITH_TIMEOUT;
- } else {
- tm_native_thread->state &= ~TM_THREAD_STATE_WAITING_INDEFINITELY;
+ state &= ~TM_THREAD_STATE_WAITING_WITH_TIMEOUT;
+ }
+ else {
+ state &= ~TM_THREAD_STATE_WAITING_INDEFINITELY;
}
- tm_native_thread->state |= TM_THREAD_STATE_RUNNABLE;
+ state &= ~(TM_THREAD_STATE_WAITING | TM_THREAD_STATE_IN_MONITOR_WAIT);
+ state |= TM_THREAD_STATE_RUNNABLE;
+ hythread_set_state(native_thread, state);
+ hythread_thread_unlock(native_thread);
hythread_suspend_enable();
if (ti_is_enabled()) {
- add_owned_monitor(monitor);
- disable_count = reset_suspend_disable();
+ jthread_add_owned_monitor(monitor);
+ int disable_count = hythread_reset_suspend_disable();
jvmti_send_contended_enter_or_entered_monitor_event(monitor, 0);
- jvmti_send_waited_monitor_event(monitor, (status == APR_TIMEUP)?(jboolean)1:(jboolean)0);
+ jvmti_send_waited_monitor_event(monitor,
+ ((status == APR_TIMEUP) ? (jboolean) 1 : (jboolean) 0));
+ hythread_set_suspend_disable(disable_count);
// should be moved to event handler
- set_suspend_disable(disable_count);
- tm_java_thread = hythread_get_private_data(hythread_self());
- tm_java_thread->waited_time += apr_time_now()- wait_begin;
- /////////
+ jvmti_thread_t jvmti_thread =
+ jthread_get_jvmti_thread(hythread_self());
+ jvmti_thread->waited_time += apr_time_now() - wait_begin;
}
return status;
-}
+} // jthread_monitor_timed_wait
-void add_owned_monitor(jobject monitor){
- hythread_t tm_native_thread = hythread_self();
- jvmti_thread_t tm_java_thread = hythread_get_private_data(tm_native_thread);
- int disable_status;
+static void jthread_add_owned_monitor(jobject monitor)
+{
+ hythread_t native_thread = hythread_self();
+ assert(native_thread);
+ vm_thread_t vm_thread =
+ (vm_thread_t)hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
+ assert(vm_thread);
+ jvmti_thread_t jvmti_thread = &vm_thread->jvmti_thread;
+
+ if (!jvmti_thread) {
+ // nothing to do
+ return;
+ }
TRACE(("TM: add owned monitor: %x", monitor));
- if (!tm_java_thread) return;
-
- disable_status = reset_suspend_disable();
- if (tm_java_thread->contended_monitor) {
- (*(tm_java_thread->jenv))->DeleteGlobalRef(tm_java_thread->jenv, tm_java_thread->contended_monitor);
- tm_java_thread->contended_monitor = NULL;
- }
-
- if (tm_java_thread->wait_monitor) {
- (*(tm_java_thread->jenv))->DeleteGlobalRef(tm_java_thread->jenv, tm_java_thread->wait_monitor);
- tm_java_thread->wait_monitor = NULL;
- }
-
-
- if (!tm_java_thread->owned_monitors) {
- tm_java_thread->owned_monitors = apr_pcalloc(tm_java_thread->pool,
- MAX_OWNED_MONITOR_NUMBER * sizeof(jobject));
- assert(tm_java_thread->owned_monitors);
- tm_java_thread->owned_monitors_nmb = 0;
- }
- assert(tm_java_thread->owned_monitors_nmb < MAX_OWNED_MONITOR_NUMBER);
-
- tm_java_thread->owned_monitors[tm_java_thread->owned_monitors_nmb]
- = (*(tm_java_thread->jenv))->NewGlobalRef(tm_java_thread->jenv, monitor);
- set_suspend_disable(disable_status);
- tm_java_thread->owned_monitors_nmb++;
-}
-
-void remove_owned_monitor(jobject monitor) {
- int i,j, disable_status;
- hythread_t tm_native_thread = hythread_self();
- jvmti_thread_t tm_java_thread = hythread_get_private_data(tm_native_thread);
-
+
+ int disable_status = hythread_reset_suspend_disable();
+
+ if (jvmti_thread->contended_monitor) {
+ vm_thread->jni_env->
+ DeleteGlobalRef(jvmti_thread->contended_monitor);
+ jvmti_thread->contended_monitor = NULL;
+ }
+
+ if (jvmti_thread->wait_monitor) {
+ vm_thread->jni_env->DeleteGlobalRef(jvmti_thread->wait_monitor);
+ jvmti_thread->wait_monitor = NULL;
+ }
+
+ assert(jvmti_thread->owned_monitors_nmb < TM_MAX_OWNED_MONITOR_NUMBER);
+ jvmti_thread->owned_monitors[jvmti_thread->owned_monitors_nmb]
+ = vm_thread->jni_env->NewGlobalRef(monitor);
+ jvmti_thread->owned_monitors_nmb++;
+
+ hythread_set_suspend_disable(disable_status);
+} // jthread_add_owned_monitor
+
+static void jthread_remove_owned_monitor(jobject monitor)
+{
+ hythread_t native_thread = hythread_self();
+ assert(native_thread);
+ vm_thread_t vm_thread =
+ (vm_thread_t)hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
+ assert(vm_thread);
+ jvmti_thread_t jvmti_thread = &vm_thread->jvmti_thread;
+
+ if (!jvmti_thread) {
+ // nothing to do
+ return;
+ }
TRACE(("TM: remove owned monitor: %x", monitor));
-
- if (!tm_java_thread) return;
- for (i = tm_java_thread->owned_monitors_nmb - 1; i >= 0; i--) {
- if (vm_objects_are_equal(tm_java_thread->owned_monitors[i], monitor)) {
- disable_status = reset_suspend_disable();
- (*(tm_java_thread->jenv))->DeleteGlobalRef(tm_java_thread->jenv, tm_java_thread->owned_monitors[i]);
- set_suspend_disable(disable_status);
- for (j = i; j < tm_java_thread->owned_monitors_nmb - 1; j++) {
- tm_java_thread->owned_monitors[j] = tm_java_thread->owned_monitors[j + 1];
+
+ for (int i = jvmti_thread->owned_monitors_nmb - 1; i >= 0; i--) {
+ if (vm_objects_are_equal(jvmti_thread->owned_monitors[i], monitor)) {
+ int disable_status = hythread_reset_suspend_disable();
+ vm_thread->jni_env->DeleteGlobalRef(jvmti_thread->owned_monitors[i]);
+ hythread_set_suspend_disable(disable_status);
+ int j;
+ for (j = i; j < jvmti_thread->owned_monitors_nmb - 1; j++) {
+ jvmti_thread->owned_monitors[j] =
+ jvmti_thread->owned_monitors[j + 1];
}
- tm_java_thread->owned_monitors_nmb--;
+ jvmti_thread->owned_monitors[j] = NULL;
+ jvmti_thread->owned_monitors_nmb--;
return;
}
}
-}
+} // jthread_remove_owned_monitor
-void set_contended_monitor(jobject monitor){
- hythread_t tm_native_thread = hythread_self();
- IDATA suspend_status;
-
- jvmti_thread_t tm_java_thread = hythread_get_private_data(tm_native_thread);
-
- if (!tm_java_thread) return;
-
- suspend_status = reset_suspend_disable();
- tm_java_thread->contended_monitor = (*(tm_java_thread->jenv))->NewGlobalRef(tm_java_thread->jenv, monitor);
-
- set_suspend_disable(suspend_status);
-}
-
-void set_wait_monitor(jobject monitor){
- hythread_t tm_native_thread = hythread_self();
- IDATA suspend_status;
-
- jvmti_thread_t tm_java_thread = hythread_get_private_data(tm_native_thread);
-
- if (!tm_java_thread) return;
-
- suspend_status = reset_suspend_disable();
- assert(suspend_status == TM_ERROR_NONE);
- tm_java_thread->wait_monitor = (*(tm_java_thread->jenv))->NewGlobalRef(tm_java_thread->jenv, monitor);
- set_suspend_disable(suspend_status);
-}
+static void jthread_set_owned_monitor(jobject monitor)
+{
+ hythread_t native_thread = hythread_self();
+ assert(native_thread);
+ vm_thread_t vm_thread =
+ (vm_thread_t)hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
+ assert(vm_thread);
+ jvmti_thread_t jvmti_thread = &vm_thread->jvmti_thread;
+
+ if (!jvmti_thread) {
+ // nothing to do
+ return;
+ }
+ TRACE(("TM: set contended monitor: %x", monitor));
+
+ int disable_count = hythread_reset_suspend_disable();
+ jvmti_thread->contended_monitor = vm_thread->jni_env->NewGlobalRef(monitor);
+ hythread_set_suspend_disable(disable_count);
+} // jthread_set_owned_monitor
+
+static void jthread_set_wait_monitor(jobject monitor)
+{
+ hythread_t native_thread = hythread_self();
+ assert(native_thread);
+ vm_thread_t vm_thread =
+ (vm_thread_t)hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
+ assert(vm_thread);
+ jvmti_thread_t jvmti_thread = &vm_thread->jvmti_thread;
+
+ if (!jvmti_thread) {
+ // nothing to do
+ return;
+ }
+ TRACE(("TM: set wait monitor: %x", monitor));
+
+ int disable_count = hythread_reset_suspend_disable();
+ jvmti_thread->wait_monitor = vm_thread->jni_env->NewGlobalRef(monitor);
+ hythread_set_suspend_disable(disable_count);
+} // jthread_set_wait_monitor
Copied: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_park.cpp (from r556643, harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_park.c)
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_park.cpp?view=diff&rev=556704&p1=harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_park.c&r1=556643&p2=harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_park.cpp&r2=556704
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_park.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_park.cpp Mon Jul 16 12:32:35 2007
@@ -23,7 +23,7 @@
#include <apr_time.h>
#include <open/jthread.h>
#include <open/hythread_ext.h>
-#include "thread_private.h"
+#include "vm_threads.h"
/**
* Parks the current thread.
@@ -33,9 +33,10 @@
*
* @sa java.util.concurrent.locks.LockSupport.park()
*/
-IDATA VMCALL jthread_park() {
+IDATA VMCALL jthread_park()
+{
return hythread_park(0, 0);
-}
+} // jthread_park
/**
* Parks the current thread with the specified timeout.
@@ -48,9 +49,10 @@
* @param[in] nanos timeout in nanoseconds
* @sa java.util.concurrent.locks.LockSupport.park()
*/
-IDATA VMCALL jthread_timed_park(jlong millis, jint nanos) {
- return hythread_park((I_64)millis, (IDATA)nanos);
-}
+IDATA VMCALL jthread_timed_park(jlong millis, jint nanos)
+{
+ return hythread_park((I_64) millis, (IDATA) nanos);
+} // jthread_timed_park
/**
* Unparks the given thread.
@@ -65,15 +67,13 @@
* @param[in] java_thread thread that needs to be unparked
* @sa java.util.concurrent.locks.LockSupport.unpark()
*/
-IDATA VMCALL jthread_unpark(jthread java_thread) {
- hythread_t tm_native_thread;
-
+IDATA VMCALL jthread_unpark(jthread java_thread)
+{
assert(java_thread);
- tm_native_thread = jthread_get_native_thread(java_thread);
- hythread_unpark(tm_native_thread);
-
+ hythread_t native_thread = jthread_get_native_thread(java_thread);
+ hythread_unpark(native_thread);
return TM_ERROR_NONE;
-}
+} // jthread_unpark
/**
* Parks the current thread until the specified deadline
@@ -85,8 +85,10 @@
* @param[in] millis absolute time in milliseconds to wait until
* @sa java.util.concurrent.locks.LockSupport.parkUntil()
*/
-IDATA VMCALL jthread_park_until(jlong millis) {
- jlong delta = millis - apr_time_now()/1000;
- if (delta <= 0) return TM_ERROR_NONE;
- return hythread_park((I_64)delta, 0);
-}
+IDATA VMCALL jthread_park_until(jlong millis)
+{
+ jlong delta = millis - apr_time_now() / 1000;
+ if (delta <= 0)
+ return TM_ERROR_NONE;
+ return hythread_park((I_64) delta, 0);
+} // jthread_park_until
Copied: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_suspend.cpp (from r556643, harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_suspend.c)
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_suspend.cpp?view=diff&rev=556704&p1=harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_suspend.c&r1=556643&p2=harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_suspend.cpp&r2=556704
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_suspend.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_suspend.cpp Mon Jul 16 12:32:35 2007
@@ -22,7 +22,8 @@
#include <open/jthread.h>
#include <open/hythread_ext.h>
-#include "thread_private.h"
+#include <open/thread_externals.h>
+#include "vm_threads.h"
/**
* Resumes the suspended thread <code>thread</code> execution.
@@ -34,11 +35,12 @@
* @param[in] java_thread thread to be resumed
* @sa java.lang.Thread.resume(), JVMTI::ResumeThread()
*/
-IDATA VMCALL jthread_resume(jthread java_thread) {
- hythread_t tm_native_thread = vm_jthread_get_tm_data(java_thread);
- hythread_resume(tm_native_thread);
+IDATA VMCALL jthread_resume(jthread java_thread)
+{
+ hythread_t native_thread = vm_jthread_get_tm_data(java_thread);
+ hythread_resume(native_thread);
return TM_ERROR_NONE;
-}
+} // jthread_resume
/**
* Resumes the suspended threads from the list.
@@ -48,14 +50,16 @@
* @param[in] thread_list list of threads to be resumed
* @sa JVMTI::ResumeThreadList()
*/
-IDATA VMCALL jthread_resume_all(jvmtiError* results, jint count, const jthread* thread_list) {
- int i;
-
- for (i = 0; i < count; i++) {
+IDATA VMCALL
+jthread_resume_all(jvmtiError *results,
+ jint count,
+ const jthread *thread_list)
+{
+ for (jint i = 0; i < count; i++) {
results[i] = (jvmtiError)jthread_resume(thread_list[i]);
}
return TM_ERROR_NONE;
-}
+} // jthread_resume_all
/**
* Suspends the <code>thread</code> execution.
@@ -75,10 +79,11 @@
* @param[in] java_thread thread to be suspended
* @sa java.lang.Thread.suspend(), JVMTI::SuspendThread()
*/
-IDATA VMCALL jthread_suspend(jthread java_thread) {
- hythread_t tm_native_thread = vm_jthread_get_tm_data(java_thread);
- return hythread_suspend_other(tm_native_thread);
-}
+IDATA VMCALL jthread_suspend(jthread java_thread)
+{
+ hythread_t native_thread = vm_jthread_get_tm_data(java_thread);
+ return hythread_suspend_other(native_thread);
+} // jthread_suspend
/**
* Suspends the threads from the list.
@@ -100,11 +105,13 @@
* @param[in] thread_list list of threads to be suspended
* @sa JVMTI::SuspendThreadList()
*/
-IDATA VMCALL jthread_suspend_all(jvmtiError* results, jint count, const jthread* thread_list) {
- int i;
- for (i = 0; i < count; i++) {
+IDATA VMCALL
+jthread_suspend_all(jvmtiError *results,
+ jint count,
+ const jthread *thread_list)
+{
+ for (jint i = 0; i < count; i++) {
results[i] = (jvmtiError)jthread_suspend(thread_list[i]);
}
return TM_ERROR_NONE;
-}
-
+} // jthread_suspend_all
Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp?view=diff&rev=556704&r1=556703&r2=556704
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp Mon Jul 16 12:32:35 2007
@@ -17,7 +17,7 @@
/**
* @author Andrey Chernyshev
* @version $Revision: 1.1.2.1.4.5 $
- */
+ */
#include "open/thread_externals.h"
@@ -73,88 +73,107 @@
#define LOG_DOMAIN "vmcore.thread"
#include "cxxlog.h"
-hythread_tls_key_t TLS_key_pvmthread;
-
#ifdef __cplusplus
-extern "C" {
+extern "C"
+{
#endif
-volatile VM_thread *p_the_safepoint_control_thread = 0; // only set when a gc is happening
+volatile VM_thread *p_the_safepoint_control_thread = 0; // only set when a gc is happening
volatile safepoint_state global_safepoint_status = nill;
#ifdef __cplusplus
}
#endif
+jint jthread_allocate_vm_thread_pool(JavaVM *java_vm,
+ vm_thread_t vm_thread)
+{
+ assert(java_vm);
+ assert(vm_thread);
-void init_TLS_data();
-
-VM_thread * allocate_thread_block(JavaVM_Internal * java_vm) {
- VM_thread * p_vmthread;
- apr_pool_t * thread_pool;
-
- if (apr_pool_create(&thread_pool, java_vm->vm_env->mem_pool) != APR_SUCCESS) {
- return NULL;
+ apr_pool_t *thread_pool;
+ if (apr_pool_create(&thread_pool,
+ ((JavaVM_Internal*)java_vm)->vm_env->mem_pool) != APR_SUCCESS)
+ {
+ return JNI_ENOMEM;
}
- p_vmthread = (VM_thread *) apr_pcalloc(thread_pool, sizeof(VM_thread));
+ vm_thread->pool = thread_pool;
- if (!p_vmthread) return NULL;
+ return JNI_OK;
+}
+
+void jthread_deallocate_vm_thread_pool(vm_thread_t vm_thread)
+{
+ assert(vm_thread);
- p_vmthread->pool = thread_pool;
+ // Destroy current VM_thread pool.
+ apr_pool_destroy(vm_thread->pool);
- return p_vmthread;
+ // mark VM_thread structure
+ jobject weak_ref = vm_thread->weak_ref;
+ memset(vm_thread, 0, sizeof(VM_thread));
+ vm_thread->weak_ref = weak_ref;
}
-
-
-VM_thread * get_a_thread_block(JavaVM_Internal * java_vm) {
- VM_thread * p_vmthread;
+vm_thread_t jthread_allocate_vm_thread(hythread_t native_thread)
+{
+ assert(native_thread);
+ vm_thread_t vm_thread;
- p_vmthread = p_TLS_vmthread;
- if (!p_vmthread) {
- p_vmthread = allocate_thread_block(java_vm);
-
- if (!p_vmthread) return NULL;
- set_TLS_data(p_vmthread);
+ // check current VM thread
+#ifdef _DEBUG
+ vm_thread =
+ (vm_thread_t)hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
+ assert(NULL == vm_thread);
+#endif // _DEBUG
+
+ // allocate VM thread
+ vm_thread = (vm_thread_t)STD_MALLOC(sizeof(VM_thread));
+ if (!vm_thread) {
+ return NULL;
+ }
+ memset(vm_thread, 0, sizeof(VM_thread));
- } else {
- memset(p_vmthread, 0, sizeof(VM_thread));
+ // set VM thread to thread local storage
+ IDATA status =
+ hythread_tls_set(native_thread, TM_THREAD_VM_TLS_KEY, vm_thread);
+ if (status != TM_ERROR_NONE) {
+ return NULL;
}
- return p_vmthread;
-}
+ return vm_thread;
+}
-VM_thread *get_vm_thread_ptr_safe(JNIEnv *jenv, jobject jThreadObj)
+VM_thread *get_vm_thread_ptr_safe(JNIEnv * jenv, jobject jThreadObj)
{
- hythread_t t=jthread_get_native_thread(jThreadObj);
- if(t == NULL) {
- return NULL;
- }
- return (VM_thread *)hythread_tls_get(t, TLS_key_pvmthread);
+ hythread_t t = jthread_get_native_thread(jThreadObj);
+ if (t == NULL) {
+ return NULL;
+ }
+ return (VM_thread *) hythread_tls_get(t, TM_THREAD_VM_TLS_KEY);
}
VM_thread *get_thread_ptr_stub()
-{
- return get_vm_thread(hythread_self());
+{
+ return get_vm_thread(hythread_self());
}
-
-vm_thread_accessor* get_thread_ptr = get_thread_ptr_stub;
-void init_TLS_data() {
- //printf ("init TLS data, TLS key = %x \n", TLS_key_pvmthread);
- TLS_key_pvmthread = TM_THREAD_VM_TLS_KEY;
-}
-
-void set_TLS_data(VM_thread *thread) {
- hythread_tls_set(hythread_self(), TLS_key_pvmthread, thread);
+
+vm_thread_accessor *get_thread_ptr = get_thread_ptr_stub;
+
+void set_TLS_data(VM_thread * thread)
+{
+ hythread_tls_set(hythread_self(), TM_THREAD_VM_TLS_KEY, thread);
//printf ("sett ls call %p %p\n", get_thread_ptr(), get_vm_thread(hythread_self()));
}
-IDATA jthread_throw_exception(char* name, char* message) {
+IDATA jthread_throw_exception(char *name, char *message)
+{
assert(hythread_is_suspend_enabled());
jobject jthe = exn_create(name);
return jthread_throw_exception_object(jthe);
}
-IDATA jthread_throw_exception_object(jobject object) {
+IDATA jthread_throw_exception_object(jobject object)
+{
if (interpreter_enabled()) {
// FIXME - Function set_current_thread_exception does the same
// actions as exn_raise_object, and it should be replaced.
@@ -178,73 +197,97 @@
* This localizes the dependencies of Thread Manager on vmcore component.
*/
-void *vm_object_get_lockword_addr(jobject monitor){
- return (*(ManagedObject**)monitor)->get_obj_info_addr();
+hythread_thin_monitor_t *vm_object_get_lockword_addr(jobject monitor)
+{
+ assert(monitor);
+ return (hythread_thin_monitor_t *) (*(ManagedObject **) monitor)->
+ get_obj_info_addr();
}
-extern "C" char *vm_get_object_class_name(void* ptr) {
- return (char*)(((ManagedObject*)ptr)->vt()->clss->get_name()->bytes);
+extern "C" char *vm_get_object_class_name(void *ptr)
+{
+ return (char *) (((ManagedObject *) ptr)->vt()->clss->get_name()->bytes);
}
-void* vm_jthread_get_tm_data(jthread thread)
+hythread_t vm_jthread_get_tm_data(jthread thread)
{
static int offset = -1;
- Class * clazz;
- Field * field;
- ManagedObject * thread_obj;
- Byte * java_ref;
+ Class *clazz;
+ Field *field;
+ ManagedObject *thread_obj;
+ Byte *java_ref;
POINTER_SIZE_INT val;
hythread_suspend_disable();
- thread_obj = ((ObjectHandle)thread)->object;
+ thread_obj = ((ObjectHandle) thread)->object;
if (offset == -1) {
clazz = thread_obj->vt()->clss;
field = class_lookup_field_recursive(clazz, "vm_thread", "J");
offset = field->get_offset();
}
- java_ref = (Byte *)thread_obj;
- val = *(POINTER_SIZE_INT *)(java_ref + offset);
+ java_ref = (Byte *) thread_obj;
+ val = *(POINTER_SIZE_INT *) (java_ref + offset);
hythread_suspend_enable();
- return (void *)val;
+ return (hythread_t) val;
}
-void vm_jthread_set_tm_data(jthread thread, void* val) {
- static int offset = -1;
- Class * clazz;
- Field * field;
- ManagedObject * thread_obj;
- Byte * java_ref;
-
+void vm_jthread_set_tm_data(jthread thread, void *val)
+{
hythread_suspend_disable();
- thread_obj = ((ObjectHandle)thread)->object;
- if (offset == -1) {
- clazz = thread_obj->vt()->clss;
- field = class_lookup_field_recursive(clazz, "vm_thread", "J");
+ ManagedObject *thread_obj = ((ObjectHandle) thread)->object;
+
+ // offset 0 has an virtual table of object,
+ // thus field "vm_thread" cannot have such offset value
+ static unsigned offset = 0;
+ if (!offset) {
+ Class *clazz = thread_obj->vt()->clss;
+ Field *field = class_lookup_field_recursive(clazz, "vm_thread", "J");
offset = field->get_offset();
}
- java_ref = (Byte *)thread_obj;
- *(jlong *)(java_ref + offset) = (jlong)(POINTER_SIZE_INT)val;
+ Byte *java_ref = (Byte *) thread_obj;
+ *(jlong *) (java_ref + offset) = (jlong) (POINTER_SIZE_INT) val;
hythread_suspend_enable();
}
-int vm_objects_are_equal(jobject obj1, jobject obj2){
+int vm_objects_are_equal(jobject obj1, jobject obj2)
+{
//ObjectHandle h1 = (ObjectHandle)obj1;
//ObjectHandle h2 = (ObjectHandle)obj2;
- if (obj1 == NULL && obj2 == NULL){
+ if (obj1 == NULL && obj2 == NULL) {
return 1;
-}
- if (obj1 == NULL || obj2 == NULL){
- return 0;
-}
- return obj1->object == obj2->object;
}
+ if (obj1 == NULL || obj2 == NULL) {
+ return 0;
+ }
+ return obj1->object == obj2->object;
+}
-int ti_is_enabled(){
+int ti_is_enabled()
+{
return VM_Global_State::loader_env->TI->isEnabled();
}
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ * Class: org_apache_harmony_drlvm_thread_ThreadHelper
+ * Method: getThreadIdOffset
+ * Signature: ()I
+ */
+VMEXPORT jint JNICALL
+Java_org_apache_harmony_drlvm_thread_ThreadHelper_getThreadIdOffset(JNIEnv *env, jclass klass)
+{
+ return (jint)hythread_get_thread_id_offset();
+}
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
Copied: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_instr.cpp (from r556643, harmony/enhanced/drlvm/trunk/vm/thread/src/thread_ti_instr.c)
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_instr.cpp?view=diff&rev=556704&p1=harmony/enhanced/drlvm/trunk/vm/thread/src/thread_ti_instr.c&r1=556643&p2=harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_instr.cpp&r2=556704
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_ti_instr.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_instr.cpp Mon Jul 16 12:32:35 2007
@@ -18,12 +18,13 @@
/**
* @file thread_ti_instr.c
* @brief JVMTI basic related functions
- */
+ */
#include <open/ti_thread.h>
#include <open/hythread_ext.h>
#include <open/jthread.h>
-#include "thread_private.h"
+#include <open/thread_externals.h>
+#include "vm_threads.h"
/**
* Returns the list of all Java threads.
@@ -31,84 +32,62 @@
* @param[out] threads resulting threads list
* @param[out] count_ptr number of threads in the resulting list
*/
-IDATA VMCALL jthread_get_all_threads(jthread** threads, jint *count_ptr) {
-
- hythread_group_t java_thread_group = get_java_thread_group();
- hythread_iterator_t iterator;
- hythread_t tm_native_thread;
- jvmti_thread_t tm_java_thread;
- jthread* java_threads;
- int i;
- int count = 0;
- int java_thread_count = 0;
- IDATA status;
- //apr_status_t apr_status;
- //apr_pool_t *pool;
+IDATA VMCALL jthread_get_all_threads(jthread ** threads, jint * count_ptr)
+{
+ assert(threads);
+ assert(count_ptr);
+ hythread_group_t java_thread_group = get_java_thread_group();
assert(java_thread_group);
- iterator = hythread_iterator_create(java_thread_group);
- count = hythread_iterator_size (iterator);
- for (i = 0; i < count; i++) {
- tm_native_thread = hythread_iterator_next(&iterator);
- tm_java_thread = hythread_get_private_data(tm_native_thread);
- if (tm_java_thread) {
+ hythread_iterator_t iterator = hythread_iterator_create(java_thread_group);
+ IDATA count = hythread_iterator_size(iterator);
+
+ IDATA java_thread_count = 0;
+ for (IDATA i = 0; i < count; i++) {
+ hythread_t native_thread = hythread_iterator_next(&iterator);
+ vm_thread_t vm_thread =
+ (vm_thread_t) hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
+ if (vm_thread) {
java_thread_count++;
}
}
- /*apr_status = apr_pool_create(&pool, 0);
- if (apr_status != APR_SUCCESS) {
- hythread_iterator_release(&iterator);
- return CONVERT_ERROR(apr_status);
- }
- java_threads = apr_palloc(pool, sizeof(jthread)* java_thread_count);*/
- java_threads = (jthread*)malloc(sizeof(jthread)* java_thread_count);
+
+ jthread *java_threads = (jthread*)malloc(sizeof(jthread) * java_thread_count);
if (!java_threads) {
hythread_iterator_release(&iterator);
return TM_ERROR_OUT_OF_MEMORY;
}
+
hythread_iterator_reset(&iterator);
java_thread_count = 0;
- for (i = 0; i < count; i++) {
- tm_native_thread = hythread_iterator_next(&iterator);
- tm_java_thread = hythread_get_private_data(tm_native_thread);
- if (tm_java_thread) {
- java_threads[java_thread_count] = tm_java_thread->thread_object;
- java_thread_count++;
+ for (IDATA i = 0; i < count; i++) {
+ hythread_t native_thread = hythread_iterator_next(&iterator);
+ vm_thread_t vm_thread =
+ (vm_thread_t) hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
+ if (vm_thread) {
+ java_threads[java_thread_count++] = vm_thread->java_thread;
}
}
*threads = java_threads;
- *count_ptr = java_thread_count;
- status = hythread_iterator_release(&iterator);
+ *count_ptr = (jint)java_thread_count;
+ IDATA status = hythread_iterator_release(&iterator);
return status;
-}
-/*
- */
-IDATA deads_expand(jthread **deads, int deads_size) {
-
- jthread *new_deads;
- int i;
- new_deads = (jthread *)malloc(sizeof(jthread) * deads_size * 2);
- if (!new_deads) return TM_ERROR_OUT_OF_MEMORY;
+} // jthread_get_all_threads
- for (i = 0; i < deads_size; i++) {
- new_deads[i] = (*deads)[i];
- }
- *deads = new_deads;
- return TM_ERROR_NONE;
-}
/*
*/
-int deads_find(jobject thread, jobject *deads, int base, int top, int deads_size) {
- int i;
-
- for (i = 0; i < top; i++) {
+int
+jthread_find_deads(jobject thread, jobject *deads, int base, int top)
+{
+ for (int i = 0; i < top; i++) {
if (vm_objects_are_equal(thread, deads[i])) {
return 1;
}
}
return 0;
}
+
// FIXME: synchronization and maybe thread suspension needed
/**
* Checks for the deadlock conditions within the specified thread list.
@@ -118,176 +97,173 @@
* @param[out] dead_list deadlocked threads
* @param[out] dead_count number of deadlocked threads
*/
-IDATA VMCALL jthread_get_deadlocked_threads(jthread *thread_list, jint thread_count, jthread **dead_list, jint *dead_count) {
- jthread *deads;
- int deads_size = 1;
- int deads_base = 0;
- int deads_top = 0;
- jthread *output;
- int output_top = 0;
- jobject monitor;
- jthread thread;
- //apr_pool_t *pool;
- /*apr_pool_t *pool_out;
- apr_status_t apr_status;*/
- IDATA status;
- int i;
-
- /*apr_status = apr_pool_create(&pool, NULL);
- if (apr_status != APR_SUCCESS) return CONVERT_ERROR(apr_status);
-
- deads = apr_palloc(pool, sizeof(jthread) * deads_size);
- output = apr_palloc(pool, sizeof(jthread) * thread_count);
- if (!deads || !output) return TM_ERROR_OUT_OF_MEMORY;*/
-
- deads = (jthread *)malloc(sizeof(jthread) * deads_size);
- output = (jthread *)malloc(sizeof(jthread) * thread_count);
- if ((deads==NULL)||(output==NULL)) {
- return TM_ERROR_OUT_OF_MEMORY;
- }
- for (i = 0; i < thread_count; i++) {
- thread = thread_list[i];
- while (1) {
- status=jthread_get_contended_monitor(thread, &monitor);
- if (status != TM_ERROR_NONE) return status;
- if (! monitor) {
+IDATA VMCALL
+jthread_get_deadlocked_threads(jthread * thread_list,
+ jint thread_count,
+ jthread ** dead_list,
+ jint * dead_count)
+{
+ int deads_size;
+ int deads_base;
+ int deads_top;
+ int output_top;
+
+ IDATA status = TM_ERROR_NONE;
+ jthread *deads = (jthread *) malloc(sizeof(jthread) * thread_count);
+ jthread *output = (jthread *) malloc(sizeof(jthread) * thread_count);
+ if ((deads == NULL) || (output == NULL)) {
+ status = TM_ERROR_OUT_OF_MEMORY;
+ goto free_allocated_memory;
+ }
+
+ deads_size = 1;
+ deads_base = 0;
+ deads_top = 0;
+ output_top = 0;
+ for (jint i = 0; i < thread_count; i++) {
+ jthread thread = thread_list[i];
+ output[output_top] = thread;
+ while (true) {
+ jobject monitor;
+ IDATA status = jthread_get_contended_monitor(thread, &monitor);
+ if (status != TM_ERROR_NONE) {
+ goto free_allocated_memory;
+ }
+ if (!monitor) {
deads_top = deads_base; // remove frame
break;
}
- if (deads_find(thread, deads, deads_base, deads_top, deads_size)) {
- output[output_top] = thread;
+ if (jthread_find_deads(thread, deads, deads_base, deads_top)) {
output_top++;
deads_base = deads_top; // add frame
break;
}
if (deads_top == deads_size) {
- status = deads_expand(&deads, deads_size);
- if (status != TM_ERROR_NONE) return status;
+ // status = deads_expand(&deads, deads_size);
+ if (status != TM_ERROR_NONE)
+ return status;
}
deads[deads_top] = thread;
deads_top++;
status = jthread_get_lock_owner(monitor, &thread);
- if (status != TM_ERROR_NONE) return status;
+ if (status != TM_ERROR_NONE) {
+ goto free_allocated_memory;
+ }
}
}
if (output_top > 0) {
- /* apr_status = apr_pool_create(&pool_out, NULL);
- if (apr_status != APR_SUCCESS) return CONVERT_ERROR(apr_status);*/
- *dead_list = (jthread *)malloc(sizeof(jthread) * output_top);
- if (! *dead_list) return TM_ERROR_OUT_OF_MEMORY;
-
- for (i = 0; i < output_top; i++) {
- (*dead_list)[i] = output[i];
+ output = (jthread*)realloc(output, sizeof(jthread) * output_top);
+ if (!output) {
+ status = TM_ERROR_OUT_OF_MEMORY;
+ goto free_allocated_memory;
}
+ *dead_list = output;
} else {
*dead_list = NULL;
}
*dead_count = output_top;
+ if (!deads) {
+ free(deads);
+ }
return TM_ERROR_NONE;
-}
+
+free_allocated_memory:
+ if (!deads) {
+ free(deads);
+ }
+ if (!output) {
+ free(output);
+ }
+ return status;
+} // jthread_get_deadlocked_threads
/**
* Returns the number of all Java threads.
*
* @param[out] count_ptr number of threads.
*/
-IDATA VMCALL jthread_get_thread_count(jint *count_ptr) {
-
- hythread_group_t java_thread_group = get_java_thread_group();
- hythread_iterator_t iterator;
- hythread_t tm_native_thread;
- jvmti_thread_t tm_java_thread;
- int i;
- int count = 0;
- int java_thread_count = 0;
- IDATA status;
-
+IDATA VMCALL jthread_get_thread_count(jint * count_ptr)
+{
+ assert(count_ptr);
+ hythread_group_t java_thread_group = get_java_thread_group();
assert(java_thread_group);
- iterator = hythread_iterator_create(java_thread_group);
- count = hythread_iterator_size (iterator);
- for (i = 0; i < count; i++) {
- tm_native_thread = hythread_iterator_next(&iterator);
- tm_java_thread = hythread_get_private_data(tm_native_thread);
- if (tm_java_thread) {
+ hythread_iterator_t iterator = hythread_iterator_create(java_thread_group);
+ IDATA count = hythread_iterator_size(iterator);
+
+ IDATA java_thread_count = 0;
+ for (IDATA i = 0; i < count; i++) {
+ hythread_t native_thread = hythread_iterator_next(&iterator);
+ vm_thread_t vm_thread =
+ (vm_thread_t) hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
+ if (vm_thread) {
java_thread_count++;
}
}
- *count_ptr = java_thread_count;
- status = hythread_iterator_release(&iterator);
+ *count_ptr = (jint)java_thread_count;
+ IDATA status = hythread_iterator_release(&iterator);
return status;
-}
-
-/**
- * Returns the number of total started Java threads.
- *
- * @param[out] count_ptr number of started threads.
- */
-IDATA VMCALL jthread_get_total_started_thread_count(jint *count_ptr) {
- *count_ptr = total_started_thread_count;
- return TM_ERROR_NONE;
-}
+} // jthread_get_thread_count
/**
* Returns the number of blocked threads.
*
* @param[out] count_ptr number of threads.
*/
-IDATA VMCALL jthread_get_blocked_count(jint* count_ptr) {
-
- hythread_group_t java_thread_group = get_java_thread_group();
- hythread_iterator_t iterator;
- hythread_t tm_native_thread;
- int nmb = 0;
- int count;
- IDATA status;
+IDATA VMCALL jthread_get_blocked_count(jint * count_ptr)
+{
+ assert(count_ptr);
+ hythread_group_t java_thread_group = get_java_thread_group();
assert(java_thread_group);
- iterator = hythread_iterator_create(java_thread_group);
- count = hythread_iterator_size (iterator);
+ hythread_iterator_t iterator = hythread_iterator_create(java_thread_group);
+ IDATA count = hythread_iterator_size(iterator);
- while (hythread_iterator_has_next(iterator)) {
- tm_native_thread = hythread_iterator_next(&iterator);
- if (tm_native_thread && hythread_is_blocked_on_monitor_enter(tm_native_thread)) {
- nmb++;
+ IDATA thread_count = 0;
+ for (IDATA i = 0; i < count; i++) {
+ hythread_t native_thread = hythread_iterator_next(&iterator);
+ if (native_thread
+ && hythread_is_blocked_on_monitor_enter(native_thread))
+ {
+ thread_count++;
}
}
- *count_ptr = nmb;
- status = hythread_iterator_release(&iterator);
+ *count_ptr = (jint)thread_count;
+ IDATA status = hythread_iterator_release(&iterator);
- return status;
-}
+ return status;
+} // jthread_get_blocked_count
/**
* Returns the number of waiting threads.
*
* @param[out] count number of threads.
*/
-IDATA VMCALL jthread_get_waited_count(jint* count) {
-
- hythread_group_t java_thread_group = get_java_thread_group();
- hythread_iterator_t iterator;
- hythread_t tm_native_thread;
- int nmb = 0;
- IDATA status;
+IDATA VMCALL jthread_get_waited_count(jint * count_ptr)
+{
+ assert(count_ptr);
+ hythread_group_t java_thread_group = get_java_thread_group();
assert(java_thread_group);
- iterator = hythread_iterator_create(java_thread_group);
+ hythread_iterator_t iterator = hythread_iterator_create(java_thread_group);
+ IDATA count = hythread_iterator_size(iterator);
- while (hythread_iterator_has_next(iterator)) {
- tm_native_thread = hythread_iterator_next(&iterator);
- //if (hythread_is_in_monitor_wait(tm_native_thread)) { ???????????????????????
- if (hythread_is_waiting(tm_native_thread)) {
- nmb++;
+ IDATA thread_count = 0;
+ for (IDATA i = 0; i < count; i++) {
+ hythread_t native_thread = hythread_iterator_next(&iterator);
+ if (native_thread
+ && hythread_is_waiting(native_thread))
+ {
+ thread_count++;
}
}
- *count = nmb;
- status = hythread_iterator_release(&iterator);
+ *count_ptr = (jint)thread_count;
+ IDATA status = hythread_iterator_release(&iterator);
return status;
-}
+} // jthread_get_waited_count
/**
* Returns the <code>thread</code>'s state according
@@ -298,66 +274,59 @@
* @param[out] state resulting thread state
*
*/
-IDATA VMCALL jthread_get_state(jthread java_thread, jint *state) {
- hythread_t tm_native_thread;
-
- assert(java_thread);
+IDATA VMCALL jthread_get_jvmti_state(jthread java_thread, jint * state)
+{
assert(state);
- tm_native_thread = vm_jthread_get_tm_data(java_thread);
-
- *state = 0;
- if (! tm_native_thread) return TM_ERROR_NONE; // Not started yet
-
- if (hythread_is_alive(tm_native_thread)) {*state |= JVMTI_THREAD_STATE_ALIVE;}
- if (hythread_is_runnable(tm_native_thread)) {*state |= JVMTI_THREAD_STATE_RUNNABLE;}
- if (hythread_is_blocked_on_monitor_enter(tm_native_thread)) {*state |= JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;}
- if (hythread_is_waiting(tm_native_thread)) {*state |= JVMTI_THREAD_STATE_WAITING;}
- if (hythread_is_waiting_indefinitely(tm_native_thread)) {*state |= JVMTI_THREAD_STATE_WAITING_INDEFINITELY;}
- if (hythread_is_waiting_with_timeout(tm_native_thread)) {*state |= JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT;}
- if (hythread_is_sleeping(tm_native_thread)) {*state |= JVMTI_THREAD_STATE_SLEEPING;}
- if (hythread_is_in_monitor_wait(tm_native_thread)) {*state |= JVMTI_THREAD_STATE_IN_OBJECT_WAIT;}
- if (hythread_is_parked(tm_native_thread)) {*state |= JVMTI_THREAD_STATE_PARKED;}
- if (hythread_is_suspended(tm_native_thread)) {*state |= JVMTI_THREAD_STATE_SUSPENDED;}
- if (hythread_interrupted(tm_native_thread)) {*state |= JVMTI_THREAD_STATE_INTERRUPTED;}
- if (hythread_is_in_native(tm_native_thread)) {*state |= JVMTI_THREAD_STATE_IN_NATIVE;}
- if (hythread_is_terminated(tm_native_thread)) {*state |= JVMTI_THREAD_STATE_TERMINATED;}
-
- return TM_ERROR_NONE;
-}
-
-/**
- * Puts the data into thread local storage.
- *
- * @param[in] java_thread thread where to put the data
- * @param[in] data data to be put
- */
-IDATA VMCALL jthread_set_local_storage(jthread java_thread, const void* data) {
- hythread_t tm_native_thread;
-
assert(java_thread);
- tm_native_thread = vm_jthread_get_tm_data(java_thread);
- assert(tm_native_thread);
-
- return hythread_set_private_data(tm_native_thread, (void *)data);
-}
-
-/**
- * Extracts the data from the thread local storage.
- *
- * @param[in] java_thread thread where to get the data
- * @param[out] data_ptr pointer to the data
- */
-IDATA VMCALL jthread_get_local_storage(jthread java_thread, void** data_ptr) {
- hythread_t tm_native_thread;
- assert(java_thread);
- assert(data_ptr);
- tm_native_thread = vm_jthread_get_tm_data(java_thread);
- assert(tm_native_thread);
- *data_ptr = hythread_get_private_data (tm_native_thread);
+ *state = 0;
+ hythread_t native_thread = vm_jthread_get_tm_data(java_thread);
+ if (!native_thread) {
+ // Not started yet
+ return TM_ERROR_NONE;
+ }
+ if (hythread_is_alive(native_thread)) {
+ *state |= JVMTI_THREAD_STATE_ALIVE;
+ }
+ if (hythread_is_runnable(native_thread)) {
+ *state |= JVMTI_THREAD_STATE_RUNNABLE;
+ }
+ if (hythread_is_blocked_on_monitor_enter(native_thread)) {
+ *state |= JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
+ }
+ if (hythread_is_waiting(native_thread)) {
+ *state |= JVMTI_THREAD_STATE_WAITING;
+ }
+ if (hythread_is_waiting_indefinitely(native_thread)) {
+ *state |= JVMTI_THREAD_STATE_WAITING_INDEFINITELY;
+ }
+ if (hythread_is_waiting_with_timeout(native_thread)) {
+ *state |= JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT;
+ }
+ if (hythread_is_sleeping(native_thread)) {
+ *state |= JVMTI_THREAD_STATE_SLEEPING;
+ }
+ if (hythread_is_in_monitor_wait(native_thread)) {
+ *state |= JVMTI_THREAD_STATE_IN_OBJECT_WAIT;
+ }
+ if (hythread_is_parked(native_thread)) {
+ *state |= JVMTI_THREAD_STATE_PARKED;
+ }
+ if (hythread_is_suspended(native_thread)) {
+ *state |= JVMTI_THREAD_STATE_SUSPENDED;
+ }
+ if (hythread_interrupted(native_thread)) {
+ *state |= JVMTI_THREAD_STATE_INTERRUPTED;
+ }
+ if (hythread_is_in_native(native_thread)) {
+ *state |= JVMTI_THREAD_STATE_IN_NATIVE;
+ }
+ if (hythread_is_terminated(native_thread)) {
+ *state |= JVMTI_THREAD_STATE_TERMINATED;
+ }
return TM_ERROR_NONE;
-}
+} // jthread_get_jvmti_state
/**
* Returns true if specified thread holds the lock associated with the given monitor.
@@ -366,21 +335,18 @@
* @param[in] monitor object those monitor is possibly locked
* @return true if thread holds the lock, false otherwise;
*/
-jboolean VMCALL jthread_holds_lock(jthread thread, jobject monitor) {
-
- jthread lock_owner;
- IDATA status;
- jboolean res;
-
- status = jthread_get_lock_owner(monitor, &lock_owner);
- assert(status == TM_ERROR_NONE);
+jboolean VMCALL jthread_holds_lock(jthread thread, jobject monitor)
+{
+ jthread lock_owner;
+ IDATA status = jthread_get_lock_owner(monitor, &lock_owner);
+ assert(status == TM_ERROR_NONE);
- hythread_suspend_disable();
- res = vm_objects_are_equal(thread, lock_owner);
- hythread_suspend_enable();
+ hythread_suspend_disable();
+ jboolean result = vm_objects_are_equal(thread, lock_owner);
+ hythread_suspend_enable();
- return res;
-}
+ return result;
+} // jthread_holds_lock
/**
* Returns the monitor the specific thread is currently contending for.
@@ -389,18 +355,16 @@
* @param[out] monitor monitor the thread <code>thread</code> is currently contending for,
* or NULL if thread doesn't contend for any monitor.
*/
-IDATA VMCALL jthread_get_contended_monitor(jthread java_thread, jobject* monitor) {
-
- hythread_t tm_native_thread;
- jvmti_thread_t tm_java_thread;
-
+IDATA VMCALL
+jthread_get_contended_monitor(jthread java_thread, jobject * monitor)
+{
assert(java_thread);
- tm_native_thread = vm_jthread_get_tm_data(java_thread);
- tm_java_thread = hythread_get_private_data(tm_native_thread);
- assert(tm_java_thread);
- *monitor = tm_java_thread->contended_monitor;
+ hythread_t native_thread = vm_jthread_get_tm_data(java_thread);
+ jvmti_thread_t jvmti_thread = jthread_get_jvmti_thread(native_thread);
+ assert(jvmti_thread);
+ *monitor = jvmti_thread->contended_monitor;
return TM_ERROR_NONE;
-}
+} // jthread_get_contended_monitor
/**
* Returns the monitor the specific thread is currently waiting on.
@@ -409,18 +373,15 @@
* @param[out] monitor monitor the thread <code>thread</code> is currently contending for,
* or NULL if thread doesn't contend for any monitor.
*/
-IDATA VMCALL jthread_get_wait_monitor(jthread java_thread, jobject* monitor) {
-
- hythread_t tm_native_thread;
- jvmti_thread_t tm_java_thread;
-
+IDATA VMCALL jthread_get_wait_monitor(jthread java_thread, jobject * monitor)
+{
assert(java_thread);
- tm_native_thread = vm_jthread_get_tm_data(java_thread);
- tm_java_thread = hythread_get_private_data(tm_native_thread);
- assert(tm_java_thread);
- *monitor = tm_java_thread->wait_monitor;
+ hythread_t native_thread = vm_jthread_get_tm_data(java_thread);
+ jvmti_thread_t jvmti_thread = jthread_get_jvmti_thread(native_thread);
+ assert(jvmti_thread);
+ *monitor = jvmti_thread->wait_monitor;
return TM_ERROR_NONE;
-}
+} // jthread_get_wait_monitor
/**
* Returns the owner of the lock associated with the given monitor.
@@ -430,26 +391,26 @@
* @param[in] monitor monitor those owner needs to be determined
* @param[out] lock_owner thread which owns the monitor
*/
-IDATA VMCALL jthread_get_lock_owner(jobject monitor, jthread* lock_owner) {
-
- hythread_t tm_native_thread = NULL;
- jvmti_thread_t tm_java_thread = NULL;
- hythread_thin_monitor_t *lockword;
-
+IDATA VMCALL jthread_get_lock_owner(jobject monitor, jthread * lock_owner)
+{
assert(monitor);
+ assert(lock_owner);
+
hythread_suspend_disable();
- lockword = vm_object_get_lockword_addr(monitor);
- tm_native_thread = hythread_thin_monitor_get_owner(lockword);
- if (!tm_native_thread) {
+ hythread_thin_monitor_t *lockword = vm_object_get_lockword_addr(monitor);
+ hythread_t native_thread = hythread_thin_monitor_get_owner(lockword);
+ if (!native_thread) {
*lock_owner = NULL;
} else {
- tm_java_thread = hythread_get_private_data(tm_native_thread);
- *lock_owner = tm_java_thread->thread_object;
+ vm_thread_t vm_thread =
+ (vm_thread_t) hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
+ assert(vm_thread);
+ *lock_owner = vm_thread->java_thread;
}
hythread_suspend_enable();
return TM_ERROR_NONE;
-}
+} // jthread_get_lock_owner
/**
* Returns the number of times given thread have entered given monitor;
@@ -459,27 +420,27 @@
* @param[in] monitor monitor those owner needs to be determined
* @param[in] owner thread which owns the monitor
*/
-IDATA VMCALL jthread_get_lock_recursion(jobject monitor, jthread owner) {
+IDATA VMCALL jthread_get_lock_recursion(jobject monitor, jthread owner)
+{
+ assert(monitor);
- hythread_t given_thread, lock_owner = NULL;
- jvmti_thread_t tm_java_thread = NULL;
- hythread_thin_monitor_t *lockword;
- IDATA recursion = 0;
+ hythread_t given_thread = owner ? vm_jthread_get_tm_data(owner) : NULL;
- assert(monitor);
- given_thread = owner?vm_jthread_get_tm_data(owner):NULL;
hythread_suspend_disable();
-
- lockword = vm_object_get_lockword_addr(monitor);
- lock_owner = hythread_thin_monitor_get_owner(lockword);
-
- if (lock_owner && (!given_thread || lock_owner->thread_id == given_thread->thread_id))
+ hythread_thin_monitor_t *lockword = vm_object_get_lockword_addr(monitor);
+ hythread_t lock_owner = hythread_thin_monitor_get_owner(lockword);
+
+ IDATA recursion = 0;
+ if (lock_owner
+ && (!given_thread
+ || hythread_get_id(lock_owner) == hythread_get_id(given_thread)))
+ {
recursion = hythread_thin_monitor_get_recursion(lockword);
-
+ }
hythread_suspend_enable();
return recursion;
-}
+} // jthread_get_lock_recursion
/**
* Returns all monitors owned by the specific thread.
@@ -488,40 +449,36 @@
* @param[out] monitor_count_ptr number of owned monitors
* @param[out] monitors_ptr array of owned monitors
*/
-IDATA VMCALL jthread_get_owned_monitors(jthread java_thread,
- jint* monitor_count_ptr, jobject** monitors_ptr) {
-
- hythread_t tm_native_thread;
- jvmti_thread_t tm_java_thread;
- // apr_pool_t* pool;
- // apr_status_t apr_status;
- jobject* monitors;
- int i;
- IDATA status;
-
- status =hythread_global_lock();
- if (status != TM_ERROR_NONE) return status;
+IDATA VMCALL
+jthread_get_owned_monitors(jthread java_thread,
+ jint *monitor_count_ptr,
+ jobject **monitors_ptr)
+{
assert(java_thread);
- tm_native_thread = vm_jthread_get_tm_data(java_thread);
- tm_java_thread = hythread_get_private_data(tm_native_thread);
- assert(tm_java_thread);
- /* apr_status = apr_pool_create(&pool, 0);
- if (apr_status != APR_SUCCESS) {
- hythread_global_unlock();
- return TM_ERROR_INTERNAL;
+ assert(monitors_ptr);
+ assert(monitor_count_ptr);
+
+ IDATA status = hythread_global_lock();
+ if (status != TM_ERROR_NONE) {
+ return status;
}
- monitors = apr_palloc(pool, sizeof(jobject*) * tm_java_thread->owned_monitors_nmb); */
- monitors = (jobject *)malloc(sizeof(jobject*) * tm_java_thread->owned_monitors_nmb);
+ hythread_t native_thread = vm_jthread_get_tm_data(java_thread);
+ jvmti_thread_t jvmti_thread = jthread_get_jvmti_thread(native_thread);
+ assert(jvmti_thread);
+
+ jobject *monitors =
+ (jobject *) malloc(sizeof(jobject *) *
+ jvmti_thread->owned_monitors_nmb);
if (!monitors) {
hythread_global_unlock();
return TM_ERROR_OUT_OF_MEMORY;
}
- for (i = 0; i < tm_java_thread->owned_monitors_nmb; i++) {
- monitors[i] = tm_java_thread->owned_monitors[i];
+ for (int i = 0; i < jvmti_thread->owned_monitors_nmb; i++) {
+ monitors[i] = jvmti_thread->owned_monitors[i];
}
*monitors_ptr = monitors;
- *monitor_count_ptr = tm_java_thread->owned_monitors_nmb;
+ *monitor_count_ptr = jvmti_thread->owned_monitors_nmb;
status = hythread_global_unlock();
return status;
-}
+} // jthread_get_owned_monitors
Copied: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_monitors.cpp (from r556643, harmony/enhanced/drlvm/trunk/vm/thread/src/thread_ti_monitors.c)
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_monitors.cpp?view=diff&rev=556704&p1=harmony/enhanced/drlvm/trunk/vm/thread/src/thread_ti_monitors.c&r1=556643&p2=harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_monitors.cpp&r2=556704
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_ti_monitors.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_monitors.cpp Mon Jul 16 12:32:35 2007
@@ -18,15 +18,131 @@
/**
* @file thread_ti_monitors.c
* @brief JVMTI raw monitors related functions
- */
+ */
#include <open/hythread_ext.h>
-#include "thread_private.h"
+#include "vm_threads.h"
+
+typedef struct ResizableArrayEntry *array_entry_t;
+typedef struct ResizableArrayType *array_t;
+
+struct ResizableArrayEntry {
+ void *entry;
+ UDATA next_free;
+};
+
+struct ResizableArrayType {
+ UDATA size;
+ UDATA capacity;
+ UDATA next_index;
+ array_entry_t entries;
+};
+
+/**
+ * Resizable array implementation
+ */
+static IDATA array_create(array_t * arr)
+{
+ array_t ptr = (array_t) malloc(sizeof(ResizableArrayType));
+ if (!ptr) {
+ return -1;
+ }
+ ptr->capacity = 1024;
+ ptr->size = 0;
+ ptr->next_index = 0;
+ ptr->entries =
+ (array_entry_t) malloc(sizeof(ResizableArrayEntry) * ptr->capacity);
+ if (!ptr->entries) {
+ free(ptr);
+ return -1;
+ }
+ *arr = ptr;
+ return 0;
+} // array_create
+
+static IDATA array_destroy(array_t arr)
+{
+ if (!arr) {
+ return -1;
+ }
+ free(arr->entries);
+ free(arr);
+ return 0;
+} // array_destroy
+
+static UDATA array_add(array_t arr, void *value)
+{
+ UDATA index;
+ if (!arr) {
+ return 0;
+ }
+ if (arr->next_index) {
+ index = arr->next_index;
+ } else {
+ index = arr->size + 1;
+ if (index >= arr->capacity) {
+ arr->entries = (array_entry_t)realloc(arr->entries,
+ sizeof(void *) * arr->capacity * 2);
+ if (!arr->entries)
+ return 0;
+ arr->capacity *= 2;
+ }
+ arr->entries[index].next_free = 0;
+ }
+ arr->next_index = arr->entries[index].next_free;
+ arr->entries[index].entry = value;
+ arr->size++;
+
+ return index;
+} // array_add
+
+static void * array_delete(array_t arr, UDATA index)
+{
+ void *return_value;
+ if (!arr || index > arr->size || index == 0) {
+ return NULL;
+ }
+ return_value = arr->entries[index].entry;
+
+ arr->entries[index].entry = NULL;
+ arr->entries[index].next_free = arr->next_index;
+ arr->next_index = index;
+
+ return return_value;
+} // array_delete
+
+static void * array_get(array_t arr, UDATA index)
+{
+ if (!arr || index > arr->size || index == 0) {
+ return NULL;
+ }
+ return arr->entries[index].entry;
+} // array_get
static array_t jvmti_monitor_table = 0;
static hymutex_t jvmti_monitor_table_lock;
-//#define jrawMonitorID hythread_monitor_t;
+static IDATA jthread_init_jvmti_monitor_table()
+{
+ IDATA status = hythread_global_lock();
+ if (status != TM_ERROR_NONE) {
+ return status;
+ }
+ if (!jvmti_monitor_table) {
+ if (array_create(&jvmti_monitor_table)) {
+ hythread_global_unlock();
+ return TM_ERROR_OUT_OF_MEMORY;
+ }
+ status = hymutex_create(&jvmti_monitor_table_lock, TM_MUTEX_NESTED);
+ if (status != TM_ERROR_NONE) {
+ hythread_global_unlock();
+ return status;
+ }
+ }
+ status = hythread_global_unlock();
+ return status;
+} // jthread_init_jvmti_monitor_table
+
/**
* Initializes raw monitor.
*
@@ -37,68 +153,67 @@
*
* @param[in] mon_ptr address where monitor needs to be created and initialized.
*/
-IDATA VMCALL jthread_raw_monitor_create(jrawMonitorID* mon_ptr) {
+IDATA VMCALL jthread_raw_monitor_create(jrawMonitorID * mon_ptr)
+{
+ assert(mon_ptr);
+
hythread_monitor_t monitor;
- IDATA status;
- status = hythread_monitor_init(&monitor, 0);
- if (status != TM_ERROR_NONE) return status;
+ IDATA status = hythread_monitor_init(&monitor, 0);
+ if (status != TM_ERROR_NONE) {
+ return status;
+ }
+
// possibly should be moved to jvmti(environment?) init section
- ////
if (!jvmti_monitor_table) {
- status =hythread_global_lock();
- if (status != TM_ERROR_NONE) return status;
- if (!jvmti_monitor_table) {
-
- if (array_create(&jvmti_monitor_table)) {
- hythread_global_unlock();
- return TM_ERROR_OUT_OF_MEMORY;
- }
- status = hymutex_create(&jvmti_monitor_table_lock, TM_MUTEX_NESTED);
- if (status != TM_ERROR_NONE) {
- hythread_global_unlock();
- return status;
- }
+ status = jthread_init_jvmti_monitor_table();
+ if (status != TM_ERROR_NONE) {
+ return status;
}
- status =hythread_global_unlock();
- if (status != TM_ERROR_NONE) return status;
}
-
- status =hymutex_lock(&jvmti_monitor_table_lock);
- if (status != TM_ERROR_NONE) return status;
- *mon_ptr = array_add(jvmti_monitor_table, monitor);
-
- status =hymutex_unlock(&jvmti_monitor_table_lock);
- if (status != TM_ERROR_NONE) return status;
- if (!(*mon_ptr)) return TM_ERROR_OUT_OF_MEMORY;
-
- return TM_ERROR_NONE;
-
-}
+
+ status = hymutex_lock(&jvmti_monitor_table_lock);
+ if (status != TM_ERROR_NONE) {
+ return status;
+ }
+ *mon_ptr = (jrawMonitorID)array_add(jvmti_monitor_table, monitor);
+ if (!(*mon_ptr)) {
+ hymutex_unlock(&jvmti_monitor_table_lock);
+ return TM_ERROR_OUT_OF_MEMORY;
+ }
+
+ status = hymutex_unlock(&jvmti_monitor_table_lock);
+ return status;
+} // jthread_raw_monitor_create
/**
* Destroys raw monitor.
*
* @param[in] mon_ptr address where monitor needs to be destroyed.
*/
-IDATA VMCALL jthread_raw_monitor_destroy(jrawMonitorID mon_ptr) {
- IDATA status = 0;
- hythread_monitor_t monitor;
-
- if (!(monitor = (hythread_monitor_t)array_get(jvmti_monitor_table, (UDATA)mon_ptr))) {
+IDATA VMCALL jthread_raw_monitor_destroy(jrawMonitorID mon_ptr)
+{
+ hythread_monitor_t monitor =
+ (hythread_monitor_t)array_get(jvmti_monitor_table, (UDATA)mon_ptr);
+ if (!monitor) {
return TM_ERROR_INVALID_MONITOR;
}
- while (hythread_monitor_destroy((hythread_monitor_t)monitor) != TM_ERROR_NONE) {
- if ((status = hythread_monitor_exit((hythread_monitor_t)monitor)) != TM_ERROR_NONE)
+ while (hythread_monitor_destroy((hythread_monitor_t)monitor) != TM_ERROR_NONE)
+ {
+ IDATA status = hythread_monitor_exit((hythread_monitor_t) monitor);
+ if (status != TM_ERROR_NONE) {
return status;
+ }
}
-
- status =hymutex_lock(&jvmti_monitor_table_lock);
- if (status != TM_ERROR_NONE) return status;
- array_delete(jvmti_monitor_table, (UDATA)mon_ptr);
- status =hymutex_unlock(&jvmti_monitor_table_lock);
+
+ IDATA status = hymutex_lock(&jvmti_monitor_table_lock);
+ if (status != TM_ERROR_NONE) {
+ return status;
+ }
+ array_delete(jvmti_monitor_table, (UDATA) mon_ptr);
+ status = hymutex_unlock(&jvmti_monitor_table_lock);
return status;
-}
+} // jthread_raw_monitor_destroy
/**
* Gains the ownership over monitor.
@@ -107,17 +222,18 @@
*
* @param[in] mon_ptr monitor
*/
-IDATA VMCALL jthread_raw_monitor_enter(jrawMonitorID mon_ptr) {
- hythread_monitor_t monitor;
- IDATA stat;
- if (!(monitor = (hythread_monitor_t)array_get(jvmti_monitor_table, (UDATA)mon_ptr))) {
+IDATA VMCALL jthread_raw_monitor_enter(jrawMonitorID mon_ptr)
+{
+ hythread_monitor_t monitor =
+ (hythread_monitor_t)array_get(jvmti_monitor_table, (UDATA)mon_ptr);
+ if (!monitor) {
return TM_ERROR_INVALID_MONITOR;
}
- stat = hythread_monitor_enter(monitor);
+ IDATA status = hythread_monitor_enter(monitor);
hythread_safe_point();
hythread_exception_safe_point();
- return stat;
-}
+ return status;
+} // jthread_raw_monitor_enter
/**
* Attempt to gain the ownership over monitor without blocking.
@@ -125,30 +241,33 @@
* @param[in] mon_ptr monitor
* @return 0 in case of successful attempt.
*/
-IDATA VMCALL jthread_raw_monitor_try_enter(jrawMonitorID mon_ptr) {
- hythread_monitor_t monitor;
- if (!(monitor = (hythread_monitor_t)array_get(jvmti_monitor_table, (UDATA)mon_ptr))) {
+IDATA VMCALL jthread_raw_monitor_try_enter(jrawMonitorID mon_ptr)
+{
+ hythread_monitor_t monitor =
+ (hythread_monitor_t)array_get(jvmti_monitor_table, (UDATA)mon_ptr);
+ if (!monitor) {
return TM_ERROR_INVALID_MONITOR;
}
- return hythread_monitor_try_enter((hythread_monitor_t)monitor);
-}
+ return hythread_monitor_try_enter((hythread_monitor_t) monitor);
+} // jthread_raw_monitor_try_enter
/**
* Releases the ownership over monitor.
*
* @param[in] mon_ptr monitor
*/
-IDATA VMCALL jthread_raw_monitor_exit(jrawMonitorID mon_ptr) {
- hythread_monitor_t monitor;
- IDATA stat;
- if (!(monitor = (hythread_monitor_t)array_get(jvmti_monitor_table, (UDATA)mon_ptr))) {
+IDATA VMCALL jthread_raw_monitor_exit(jrawMonitorID mon_ptr)
+{
+ hythread_monitor_t monitor =
+ (hythread_monitor_t)array_get(jvmti_monitor_table, (UDATA)mon_ptr);
+ if (!monitor) {
return TM_ERROR_INVALID_MONITOR;
}
- stat = hythread_monitor_exit(monitor);
+ IDATA status = hythread_monitor_exit(monitor);
hythread_safe_point();
hythread_exception_safe_point();
- return stat;
-}
+ return status;
+} // jthread_raw_monitor_exit
/**
* Wait on the monitor.
@@ -171,15 +290,15 @@
* TM_ERROR_INTERRUPT wait was interrupted
* TM_ERROR_INVALID_MONITOR current thread isn't the owner
*/
-IDATA VMCALL jthread_raw_monitor_wait(jrawMonitorID mon_ptr, I_64 millis) {
- hythread_monitor_t monitor;
-
- if (!(monitor = (hythread_monitor_t)array_get(jvmti_monitor_table, (UDATA)mon_ptr))) {
+IDATA VMCALL jthread_raw_monitor_wait(jrawMonitorID mon_ptr, I_64 millis)
+{
+ hythread_monitor_t monitor =
+ (hythread_monitor_t)array_get(jvmti_monitor_table, (UDATA)mon_ptr);
+ if (!monitor) {
return TM_ERROR_INVALID_MONITOR;
}
-
return hythread_monitor_wait_interruptable(monitor, millis, 0);
-}
+} // jthread_raw_monitor_wait
/**
* Notifies one thread waiting on the monitor.
@@ -190,13 +309,15 @@
*
* @param[in] mon_ptr monitor
*/
-IDATA VMCALL jthread_raw_monitor_notify(jrawMonitorID mon_ptr) {
- hythread_monitor_t monitor;
- if (!(monitor = (hythread_monitor_t)array_get(jvmti_monitor_table, (UDATA)mon_ptr))) {
+IDATA VMCALL jthread_raw_monitor_notify(jrawMonitorID mon_ptr)
+{
+ hythread_monitor_t monitor =
+ (hythread_monitor_t)array_get(jvmti_monitor_table, (UDATA)mon_ptr);
+ if (!monitor) {
return TM_ERROR_INVALID_MONITOR;
}
- return hythread_monitor_notify(monitor);
-}
+ return hythread_monitor_notify(monitor);
+} // jthread_raw_monitor_notify
/**
* Notifies all threads which are waiting on the monitor.
@@ -206,10 +327,12 @@
*
* @param[in] mon_ptr monitor
*/
-IDATA VMCALL jthread_raw_monitor_notify_all(jrawMonitorID mon_ptr) {
- hythread_monitor_t monitor;
- if (!(monitor = (hythread_monitor_t)array_get(jvmti_monitor_table, (UDATA)mon_ptr))) {
+IDATA VMCALL jthread_raw_monitor_notify_all(jrawMonitorID mon_ptr)
+{
+ hythread_monitor_t monitor =
+ (hythread_monitor_t)array_get(jvmti_monitor_table, (UDATA)mon_ptr);
+ if (!monitor) {
return TM_ERROR_INVALID_MONITOR;
}
- return hythread_monitor_notify_all(monitor);
-}
+ return hythread_monitor_notify_all(monitor);
+} // jthread_raw_monitor_notify_all
Copied: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_others.cpp (from r556643, harmony/enhanced/drlvm/trunk/vm/thread/src/thread_ti_others.c)
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_others.cpp?view=diff&rev=556704&p1=harmony/enhanced/drlvm/trunk/vm/thread/src/thread_ti_others.c&r1=556643&p2=harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_others.cpp&r2=556704
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_ti_others.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_others.cpp Mon Jul 16 12:32:35 2007
@@ -18,114 +18,129 @@
/**
* @file thread_ti_others.c
* @brief JVMTI peak related functions
- */
+ */
#include <open/jthread.h>
#include <open/hythread_ext.h>
#include <open/ti_thread.h>
-#include "thread_private.h"
+#include <open/thread_externals.h>
+#include "vm_threads.h"
#define THREAD_CONTENTION_MONITORING_SUPPORTED 1
/*
* Monitors contentions requests enabled flag.
*/
-int thread_contention_monitoring_enabled = 0;
+static int thread_contention_monitoring_enabled = 0;
/*
* Total started thread counter.
*/
-int total_started_thread_count = 0;
+static int total_started_thread_count = 0;
/*
* Alive thread counter.
*/
-int alive_thread_count = 0;
+static int alive_thread_count = 0;
/*
* Peak count
*/
-int peak_thread_count = 0;
-
+static int peak_thread_count = 0;
+
/**
* Resets the thread peak counter to current value.
*/
-IDATA jthread_reset_peak_thread_count () {
-
+IDATA jthread_reset_peak_thread_count()
+{
peak_thread_count = alive_thread_count;
return TM_ERROR_NONE;
-}
+} // jthread_reset_peak_thread_count
/**
* Returns the peak thread count since the last peak reset.
*/
-IDATA jthread_get_peak_thread_count (jint *threads_count_ptr) {
+IDATA jthread_get_peak_thread_count(jint * threads_count_ptr)
+{
*threads_count_ptr = peak_thread_count;
return TM_ERROR_NONE;
-}
-
+} // jthread_get_peak_thread_count
+
/**
* Returns true if VM supports monitors contention requests and
* this feature is enabled
*
* @return true if monitors contention requests are enabled, false otherwise;
*/
-jboolean jthread_is_thread_contention_monitoring_enabled(){
+jboolean jthread_is_thread_contention_monitoring_enabled()
+{
return thread_contention_monitoring_enabled;
-}
+} // jthread_is_thread_contention_monitoring_enabled
/**
* Returns true if VM supports monitors contention requests
*
* @return true if monitors contention requests are supported, false otherwise;
*/
-jboolean jthread_is_thread_contention_monitoring_supported(){
-
+jboolean jthread_is_thread_contention_monitoring_supported()
+{
return THREAD_CONTENTION_MONITORING_SUPPORTED;
-}
+} // jthread_is_thread_contention_monitoring_supported
/**
* Enabled or diabled thread monitors contention requests
*
* @param[in] true or false to enable or disable the feature
*/
-void jthread_set_thread_contention_monitoring_enabled(jboolean flag){
-
- thread_contention_monitoring_enabled = THREAD_CONTENTION_MONITORING_SUPPORTED ? flag : 0;
-}
+void jthread_set_thread_contention_monitoring_enabled(jboolean flag)
+{
+ thread_contention_monitoring_enabled =
+ THREAD_CONTENTION_MONITORING_SUPPORTED ? flag : 0;
+} // jthread_set_thread_contention_monitoring_enabled
/**
* Returns JVMTILocalStorage pointer.
*
* @param[in] java_thread
*/
-JVMTILocalStorage* jthread_get_jvmti_local_storage(jthread java_thread) {
-
- jvmti_thread_t tm_java_thread;
- hythread_t tm_native_thread;
+JVMTILocalStorage *jthread_get_jvmti_local_storage(jthread java_thread)
+{
+ assert(java_thread);
+ hythread_t native_thread = vm_jthread_get_tm_data(java_thread);
+ assert(native_thread);
+ jvmti_thread_t jvmti_thread = jthread_get_jvmti_thread(native_thread);
+ assert(jvmti_thread);
+ return &jvmti_thread->jvmti_local_storage;
+} // jthread_get_jvmti_local_storage
- tm_native_thread = vm_jthread_get_tm_data(java_thread);
- tm_java_thread = hythread_get_private_data(tm_native_thread);
-
- return &tm_java_thread->jvmti_local_storage;
-
-}
+/**
+ * Returns the number of total started Java threads.
+ *
+ * @param[out] count_ptr number of started threads.
+ */
+IDATA VMCALL jthread_get_total_started_thread_count(jint * count_ptr)
+{
+ assert(count_ptr);
+ *count_ptr = total_started_thread_count;
+ return TM_ERROR_NONE;
+} // jthread_get_total_started_thread_count
/**
* Increase thread counters.
*/
-void thread_start_count(){
+void jthread_start_count()
+{
alive_thread_count++;
total_started_thread_count++;
if (peak_thread_count < alive_thread_count) {
peak_thread_count = alive_thread_count;
}
-}
+} // jthread_start_count
/**
* Decrease alive thread counter.
*/
-void thread_end_count(){
+void jthread_end_count()
+{
alive_thread_count--;
-}
-
+} // jthread_end_count