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 [3/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/helpers/thread_helpers.cpp (from r556643, harmony/enhanced/drlvm/trunk/vm/thread/src/thread_helpers.cpp)
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/helpers/thread_helpers.cpp?view=diff&rev=556704&p1=harmony/enhanced/drlvm/trunk/vm/thread/src/thread_helpers.cpp&r1=556643&p2=harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/helpers/thread_helpers.cpp&r2=556704
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_helpers.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/helpers/thread_helpers.cpp Mon Jul 16 12:32:35 2007
@@ -22,11 +22,10 @@
* This file contains the set of "VM helpers" which help to optimize monitors performance
* in the code generated by JIT compiler. Typically, these functions will be called by JIT,
* but VM also could also use them with care.
- */
+ */
#include <open/hythread_ext.h>
#include <open/thread_helpers.h>
-#include "thread_private.h"
#include "open/thread_externals.h"
#include "open/jthread.h"
@@ -40,17 +39,18 @@
*
* @return tm_self() in eax register
*/
-char* gen_hythread_self_helper(char *ss) {
+char *gen_hythread_self_helper(char *ss)
+{
#ifdef FS14_TLS_USE
//ss = mov(ss, eax_opnd, M_Base_Opnd(fs_reg, 0x14));
- *ss++ = (char)0x64;
- *ss++ = (char)0xa1;
- *ss++ = (char)0x14;
- *ss++ = (char)0x00;
- *ss++ = (char)0x00;
- *ss++ = (char)0x00;
+ *ss++ = (char) 0x64;
+ *ss++ = (char) 0xa1;
+ *ss++ = (char) 0x14;
+ *ss++ = (char) 0x00;
+ *ss++ = (char) 0x00;
+ *ss++ = (char) 0x00;
#else
- ss = call(ss, (char *)hythread_self);
+ ss = call(ss, (char *) hythread_self);
#endif
return ss;
}
@@ -67,86 +67,92 @@
*
* @return 0 if success in eax register
*/
-char* gen_monitorenter_fast_path_helper(char *ss, const R_Opnd & input_param1) {
+char *gen_monitorenter_fast_path_helper(char *ss, const R_Opnd & input_param1)
+{
if (&input_param1 != &ecx_opnd) {
- ss = mov(ss, ecx_opnd, input_param1);
+ ss = mov(ss, ecx_opnd, input_param1);
}
#ifdef ASM_MONITOR_HELPER
- signed offset2;
+ signed offset2;
//get self_id
ss = gen_hythread_self_helper(ss);
- ss = mov(ss, edx_opnd, M_Base_Opnd(eax_reg, (uint32)&((HyThread *)0)->thread_id) );
+ ss = mov(ss, edx_opnd,
+ M_Base_Opnd(eax_reg, hythread_get_thread_id_offset()));
#ifdef LOCK_RESERVATION
//get lock_id
- ss = mov(ss, eax_opnd, M_Base_Opnd(ecx_reg, 0));
+ ss = mov(ss, eax_opnd, M_Base_Opnd(ecx_reg, 0));
// move thread_id to AX
- ss = shift(ss, ror_opc, eax_opnd, Imm_Opnd(16));
+ ss = shift(ss, ror_opc, eax_opnd, Imm_Opnd(16));
// test this recursion call
- ss = alu(ss, cmp_opc, edx_opnd, eax_opnd, size_16);
- ss = branch8(ss, Condition_Z, Imm_Opnd(size_8, 0));
- char *backpatch_address__recursion_inc = ((char *)ss) - 1;
+ ss = alu(ss, cmp_opc, edx_opnd, eax_opnd, size_16);
+ ss = branch8(ss, Condition_Z, Imm_Opnd(size_8, 0));
+ char *backpatch_address__recursion_inc = ((char *) ss) - 1;
// test the lock is busy
- ss = test(ss, eax_opnd, eax_opnd, size_16);
- ss = branch8(ss, Condition_NZ, Imm_Opnd(size_8, 0));
- char *backpatch_address__inline_monitor_failed = ((char *)ss) - 1;
+ ss = test(ss, eax_opnd, eax_opnd, size_16);
+ ss = branch8(ss, Condition_NZ, Imm_Opnd(size_8, 0));
+ char *backpatch_address__inline_monitor_failed = ((char *) ss) - 1;
#else
- ss = alu(ss, xor_opc, eax_opnd, eax_opnd);
+ ss = alu(ss, xor_opc, eax_opnd, eax_opnd);
#endif
// the lock is free or not reserved
- ss = prefix(ss, lock_prefix);
- ss = cmpxchg(ss, M_Base_Opnd(ecx_reg, 2), edx_opnd, size_16);
- ss = branch8(ss, Condition_NZ, Imm_Opnd(size_8, 0));
- char *backpatch_address__inline_monitor_failed2 = ((char *)ss) - 1;
+ ss = prefix(ss, lock_prefix);
+ ss = cmpxchg(ss, M_Base_Opnd(ecx_reg, 2), edx_opnd, size_16);
+ ss = branch8(ss, Condition_NZ, Imm_Opnd(size_8, 0));
+ char *backpatch_address__inline_monitor_failed2 = ((char *) ss) - 1;
#ifdef LOCK_RESERVATION
// if this is initial reservation also increase the recursion
ss = mov(ss, edx_opnd, eax_opnd);
// eax still ROR so ROR the mask
- ss = alu(ss, and_opc, edx_opnd, Imm_Opnd(0x0400ffff));
- ss = test(ss, edx_opnd, edx_opnd);
- ss = branch8(ss, Condition_Z, Imm_Opnd(size_8, 0));
- char *backpatch_address__recursion_inc2 = ((char *)ss) - 1;
+ ss = alu(ss, and_opc, edx_opnd, Imm_Opnd(0x0400ffff));
+ ss = test(ss, edx_opnd, edx_opnd);
+ ss = branch8(ss, Condition_Z, Imm_Opnd(size_8, 0));
+ char *backpatch_address__recursion_inc2 = ((char *) ss) - 1;
#endif
- ss = ret(ss, Imm_Opnd(4));
+ ss = ret(ss, Imm_Opnd(4));
#ifdef LOCK_RESERVATION
- // increase recursion branch
- signed offset = (signed)ss - (signed)backpatch_address__recursion_inc - 1;
- *backpatch_address__recursion_inc = (char)offset;
-
+ // increase recursion branch
+ signed offset =
+ (signed) ss - (signed) backpatch_address__recursion_inc - 1;
+ *backpatch_address__recursion_inc = (char) offset;
+
// test recursion overflow
// eax still ROR so ROR the mask
- ss = alu(ss, cmp_opc, eax_opnd, Imm_Opnd(0xf4000000));
- ss = branch8(ss, Condition_A, Imm_Opnd(size_8, 0));
- char *backpatch_address__inline_monitor_failed3 = ((char *)ss) - 1;
+ ss = alu(ss, cmp_opc, eax_opnd, Imm_Opnd(0xf4000000));
+ ss = branch8(ss, Condition_A, Imm_Opnd(size_8, 0));
+ char *backpatch_address__inline_monitor_failed3 = ((char *) ss) - 1;
- offset2 = (signed)ss - (signed)backpatch_address__recursion_inc2 - 1;
- *backpatch_address__recursion_inc2 = (char)offset2;
+ offset2 = (signed) ss - (signed) backpatch_address__recursion_inc2 - 1;
+ *backpatch_address__recursion_inc2 = (char) offset2;
// restore lock_id
- ss = shift(ss, ror_opc, eax_opnd, Imm_Opnd(16));
- ss = alu(ss, add_opc, eax_opnd, Imm_Opnd(size_16, 0x800), size_16);
- ss = mov(ss, M_Base_Opnd(ecx_reg, 0), eax_opnd, size_16);
-
- ss = ret(ss, Imm_Opnd(4));
-
- offset = (signed)ss - (signed)backpatch_address__inline_monitor_failed - 1;
- *backpatch_address__inline_monitor_failed = (char)offset;
- offset = (signed)ss - (signed)backpatch_address__inline_monitor_failed3 - 1;
- *backpatch_address__inline_monitor_failed3 = (char)offset;
+ ss = shift(ss, ror_opc, eax_opnd, Imm_Opnd(16));
+ ss = alu(ss, add_opc, eax_opnd, Imm_Opnd(size_16, 0x800), size_16);
+ ss = mov(ss, M_Base_Opnd(ecx_reg, 0), eax_opnd, size_16);
+
+ ss = ret(ss, Imm_Opnd(4));
+
+ offset =
+ (signed) ss - (signed) backpatch_address__inline_monitor_failed - 1;
+ *backpatch_address__inline_monitor_failed = (char) offset;
+ offset =
+ (signed) ss - (signed) backpatch_address__inline_monitor_failed3 - 1;
+ *backpatch_address__inline_monitor_failed3 = (char) offset;
#endif
- offset2 = (signed)ss - (signed)backpatch_address__inline_monitor_failed2 - 1;
- *backpatch_address__inline_monitor_failed2 = (char)offset2;
+ offset2 =
+ (signed) ss - (signed) backpatch_address__inline_monitor_failed2 - 1;
+ *backpatch_address__inline_monitor_failed2 = (char) offset2;
#endif //ASM_MONITOR_HELPER
// the second attempt to lock monitor
- ss = push(ss, ecx_opnd);
- ss = call(ss, (char *)hythread_thin_monitor_try_enter);
- ss = alu(ss, add_opc, esp_opnd, Imm_Opnd(4)); // pop parameters
+ ss = push(ss, ecx_opnd);
+ ss = call(ss, (char *) hythread_thin_monitor_try_enter);
+ ss = alu(ss, add_opc, esp_opnd, Imm_Opnd(4)); // pop parameters
return ss;
}
@@ -162,14 +168,15 @@
* the code use and do not restore ecx, edx, eax registers
* @return 0 if success in eax register
*/
-char* gen_monitorenter_slow_path_helper(char *ss, const R_Opnd & input_param1) {
+char *gen_monitorenter_slow_path_helper(char *ss, const R_Opnd & input_param1)
+{
if (&input_param1 != &eax_opnd) {
- ss = mov(ss, eax_opnd, input_param1);
+ ss = mov(ss, eax_opnd, input_param1);
}
- ss = push(ss, eax_opnd); // push the address of the handle
- ss = call(ss, (char *)jthread_monitor_enter);
- ss = alu(ss, add_opc, esp_opnd, Imm_Opnd(4)); // pop parameters
+ ss = push(ss, eax_opnd); // push the address of the handle
+ ss = call(ss, (char *) jthread_monitor_enter);
+ ss = alu(ss, add_opc, esp_opnd, Imm_Opnd(4)); // pop parameters
return ss;
}
@@ -183,41 +190,43 @@
* The code use and do not restore eax registers.
* @return 0 if success in eax register
*/
-char* gen_monitor_exit_helper(char *ss, const R_Opnd & input_param1) {
+char *gen_monitor_exit_helper(char *ss, const R_Opnd & input_param1)
+{
if (&input_param1 != &ecx_opnd) {
- ss = mov(ss, ecx_opnd, input_param1);
+ ss = mov(ss, ecx_opnd, input_param1);
}
#ifdef ASM_MONITOR_HELPER
- ss = mov(ss, eax_opnd, M_Base_Opnd(ecx_reg, 0));
- ss = mov(ss, edx_opnd, eax_opnd);
- ss = alu(ss, and_opc, eax_opnd, 0x8000f800);
- ss = test(ss, eax_opnd, eax_opnd);
- ss = branch8(ss, Condition_Z, Imm_Opnd(size_8, 0));
- char *backpatch_address__thin_monitor = ((char *)ss) - 1;
- ss = alu(ss, and_opc, eax_opnd, 0x80000000);
- ss = test(ss, eax_opnd, eax_opnd);
- ss = branch8(ss, Condition_NZ, Imm_Opnd(size_8, 0));
- char *backpatch_address__fat_monitor = ((char *)ss) - 1;
+ ss = mov(ss, eax_opnd, M_Base_Opnd(ecx_reg, 0));
+ ss = mov(ss, edx_opnd, eax_opnd);
+ ss = alu(ss, and_opc, eax_opnd, 0x8000f800);
+ ss = test(ss, eax_opnd, eax_opnd);
+ ss = branch8(ss, Condition_Z, Imm_Opnd(size_8, 0));
+ char *backpatch_address__thin_monitor = ((char *) ss) - 1;
+ ss = alu(ss, and_opc, eax_opnd, 0x80000000);
+ ss = test(ss, eax_opnd, eax_opnd);
+ ss = branch8(ss, Condition_NZ, Imm_Opnd(size_8, 0));
+ char *backpatch_address__fat_monitor = ((char *) ss) - 1;
// recursion or reservation => dec recursion count
- ss = alu(ss, sub_opc, edx_opnd, Imm_Opnd(0x800));
- ss = mov(ss, M_Base_Opnd(ecx_reg,0), edx_opnd);
- ss = ret(ss, Imm_Opnd(4));
-
- signed offset = (signed)ss - (signed)backpatch_address__thin_monitor - 1;
- *backpatch_address__thin_monitor = (char)offset;
+ ss = alu(ss, sub_opc, edx_opnd, Imm_Opnd(0x800));
+ ss = mov(ss, M_Base_Opnd(ecx_reg, 0), edx_opnd);
+ ss = ret(ss, Imm_Opnd(4));
+
+ signed offset =
+ (signed) ss - (signed) backpatch_address__thin_monitor - 1;
+ *backpatch_address__thin_monitor = (char) offset;
ss = mov(ss, M_Base_Opnd(ecx_reg, 2), Imm_Opnd(size_16, 0), size_16);
- ss = ret(ss, Imm_Opnd(4));
+ ss = ret(ss, Imm_Opnd(4));
- offset = (signed)ss - (signed)backpatch_address__fat_monitor - 1;
- *backpatch_address__fat_monitor = (char)offset;
+ offset = (signed) ss - (signed) backpatch_address__fat_monitor - 1;
+ *backpatch_address__fat_monitor = (char) offset;
#endif
- ss = push(ss, ecx_opnd);
- ss = call(ss, (char *)hythread_thin_monitor_exit);
- ss = alu(ss, add_opc, esp_opnd, Imm_Opnd(4)); // pop parameters
+ ss = push(ss, ecx_opnd);
+ ss = call(ss, (char *) hythread_thin_monitor_exit);
+ ss = alu(ss, add_opc, esp_opnd, Imm_Opnd(4)); // pop parameters
return ss;
}
@@ -232,16 +241,17 @@
* the code use and do not restore ecx, edx, eax registers
* @return 0 if success in eax register
*/
-char* gen_monitorexit_slow_path_helper(char *ss, const R_Opnd & input_param1) {
- if (&input_param1 != &eax_opnd) {
- ss = mov(ss, eax_opnd, input_param1);
+char *gen_monitorexit_slow_path_helper(char *ss, const R_Opnd & input_param1)
+{
+ if (&input_param1 != &eax_opnd) {
+ ss = mov(ss, eax_opnd, input_param1);
}
-
- ss = push(ss, eax_opnd); // push the address of the handle
- ss = call(ss, (char *)jthread_monitor_exit);
- ss = alu(ss, add_opc, esp_opnd, Imm_Opnd(4)); // pop parameters
+
+ ss = push(ss, eax_opnd); // push the address of the handle
+ ss = call(ss, (char *) jthread_monitor_exit);
+ ss = alu(ss, add_opc, esp_opnd, Imm_Opnd(4)); // pop parameters
return ss;
-}
+}
/**
* Generates fast accessor to the TLS for the given key.<br>
@@ -255,21 +265,23 @@
* @param[in] key TLS key
* @return fast accessor to key, if one exist
*/
-fast_tls_func* get_tls_helper(hythread_tls_key_t key) {
+fast_tls_func *get_tls_helper(hythread_tls_key_t key)
+{
// return tm_self_tls->thread_local_storage[key];
- unsigned key_offset = (unsigned)&(((hythread_t)(0))->thread_local_storage[key]);
-
+ unsigned key_offset =
+ (unsigned) &(((HyThread_public *) (0))->thread_local_storage[key]);
+
const int stub_size = 126;
- char *stub = (char *)malloc(stub_size);
- memset(stub, 0xcc /*int 3*/, stub_size);
+ char *stub = (char *) malloc(stub_size);
+ memset(stub, 0xcc /*int 3 */ , stub_size);
char *ss = stub;
-
+
ss = gen_hythread_self_helper(ss);
- ss = mov(ss, eax_opnd, M_Base_Opnd(eax_reg, key_offset));
- ss = ret(ss, Imm_Opnd(0));
+ ss = mov(ss, eax_opnd, M_Base_Opnd(eax_reg, key_offset));
+ ss = ret(ss, Imm_Opnd(0));
assert((ss - stub) < stub_size);
- return (fast_tls_func*) stub;
+ return (fast_tls_func *) stub;
}
Copied: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/helpers/thread_helpers_ipf.cpp (from r556643, harmony/enhanced/drlvm/trunk/vm/thread/src/thread_helpers_ipf.c)
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/helpers/thread_helpers_ipf.cpp?view=diff&rev=556704&p1=harmony/enhanced/drlvm/trunk/vm/thread/src/thread_helpers_ipf.c&r1=556643&p2=harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/helpers/thread_helpers_ipf.cpp&r2=556704
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_helpers_ipf.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/helpers/thread_helpers_ipf.cpp Mon Jul 16 12:32:35 2007
@@ -18,7 +18,7 @@
/**
* @file thread_helpers_ipf.c
* Missing definition to ipf compile
- */
+ */
#include <open/hythread_ext.h>
#include <open/thread_helpers.h>
@@ -28,13 +28,14 @@
#include <assert.h>
-void *dummy_tls_func() {
+void *dummy_tls_func()
+{
assert(0);
abort();
}
-fast_tls_func* get_tls_helper(hythread_tls_key_t key) {
+fast_tls_func *get_tls_helper(hythread_tls_key_t key)
+{
return dummy_tls_func;
}
-
Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/lock_manager.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/lock_manager.cpp?view=diff&rev=556704&r1=556703&r2=556704
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/lock_manager.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/lock_manager.cpp Mon Jul 16 12:32:35 2007
@@ -24,10 +24,6 @@
#include "vm_threads.h"
#include "exceptions.h"
-//void vm_thread_enumerate_from_native(VM_thread *thread); // unused anywhere
-
-extern hythread_library_t hythread_lib;
-
Lock_Manager::Lock_Manager()
{
UNREF IDATA stat = hymutex_create (&lock, TM_MUTEX_NESTED);
Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_dump.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_dump.cpp?view=diff&rev=556704&r1=556703&r2=556704
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_dump.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_dump.cpp Mon Jul 16 12:32:35 2007
@@ -42,35 +42,28 @@
#include "cxxlog.h"
-static std::set<void *> unique_references;
+static std::set < void *>unique_references;
-enum reference_types {
+enum reference_types
+{
root_reference = 1,
compresses_root_reference,
managed_reference,
managed_reference_with_base
};
- void td_print_thread_dumps(FILE* f);
-#ifdef _DEBUG
- void td_print_native_dumps(FILE* f);
- #endif
- void td_attach_thread(void( *printer)(FILE *), FILE *out);
+void td_attach_thread(void (*printer) (FILE *), FILE * out);
-VMEXPORT void vm_check_if_monitor(void **reference,
- void **base_reference,
- uint32 *compressed_reference,
- int slotOffset,
- Boolean pinned,
- int type) {
+VMEXPORT void vm_check_if_monitor(void **reference,
+ void **base_reference,
+ uint32 * compressed_reference,
+ int slotOffset, Boolean pinned, int type)
+{
}
/**
* The thread dump entry poin, this function being called from the signal handler
*/
-void td_dump_all_threads(FILE *out) {
-#ifdef _DEBUG
-// td_print_native_dumps(out);
-#endif
- // td_attach_thread(td_print_thread_dumps, out);
+void td_dump_all_threads(FILE * out)
+{
}
Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp?view=diff&rev=556704&r1=556703&r2=556704
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp Mon Jul 16 12:32:35 2007
@@ -17,7 +17,7 @@
/**
* @author Andrey Chernyshev
* @version $Revision: 1.1.2.5.4.5 $
- */
+ */
#define LOG_DOMAIN "thread"
@@ -95,70 +95,18 @@
extern struct JNINativeInterface_ jni_vtable;
-struct vmthread_dummies {
- VM_thread *p_vm_thread;
- ObjectHandles *p_object_handles;
- M2nFrame *p_m2n_frame;
-};
-
-
-void *vm_allocate_thread_dummies(JavaVM *java_vm) {
- struct vmthread_dummies *p_vmt_dummies;
- VM_thread *vmt = allocate_thread_block((JavaVM_Internal *)java_vm);
-
- if (vmt == NULL)
- goto err;
-
- p_vmt_dummies =
- (struct vmthread_dummies *)apr_palloc(vmt->pool, sizeof(vmthread_dummies));
-
- if (p_vmt_dummies == NULL)
- goto err;
-
- // Create top level M2N frame.
- p_vmt_dummies->p_m2n_frame =
- (M2nFrame*) apr_palloc(vmt->pool, sizeof(M2nFrame));
- // Create local handles.
- p_vmt_dummies->p_object_handles =
- (ObjectHandles*) apr_palloc(vmt->pool, sizeof(ObjectHandlesNew));
- // allocate jni env internal structures
- vmt->jni_env = (JNIEnv_Internal *) apr_palloc(vmt->pool,
- sizeof(JNIEnv_Internal));
-
- if (vmt->jni_env == NULL || p_vmt_dummies->p_object_handles == NULL ||
- p_vmt_dummies->p_m2n_frame == NULL)
- goto err;
-
- p_vmt_dummies->p_vm_thread = vmt;
-
- return (void*)p_vmt_dummies;
-
- err:
- if (p_vmt_dummies->p_m2n_frame)
- free (p_vmt_dummies->p_m2n_frame);
- if (p_vmt_dummies->p_object_handles)
- free(p_vmt_dummies->p_object_handles);
- if (vmt->jni_env)
- free(vmt->jni_env);
- if (p_vmt_dummies)
- free(p_vmt_dummies);
- if (vmt)
- free(vmt);
-
- return NULL;
-}
-
/**
* Runs java.lang.Thread.detach() method.
*/
-static jint run_java_detach(jthread java_thread) {
- static Method * detach = NULL;
- const char * method_name = "detach";
- const char * descriptor = "(Ljava/lang/Throwable;)V";
+static jint run_java_detach(jthread java_thread)
+{
+ static Method *detach = NULL;
+ const char *method_name = "detach";
+ const char *descriptor = "(Ljava/lang/Throwable;)V";
jvalue args[2];
- JNIEnv * jni_env;
- Global_Env * vm_env;
- Class * thread_class;
+ JNIEnv *jni_env;
+ Global_Env *vm_env;
+ Class *thread_class;
assert(hythread_is_suspend_enabled());
@@ -169,18 +117,18 @@
if (detach == NULL) {
detach = class_lookup_method(thread_class, method_name, descriptor);
if (detach == NULL) {
- TRACE("Failed to find thread's detach method " << descriptor << " , exception = " << exn_get());
+ TRACE("Failed to find thread's detach method " << descriptor <<
+ " , exception = " << exn_get());
return TM_ERROR_INTERNAL;
}
}
-
// Initialize arguments.
args[0].l = java_thread;
if (vm_env->IsVmShutdowning()) {
args[1].l = NULL;
} else {
args[1].l = exn_get();
- }
+ }
exn_clear();
hythread_suspend_disable();
@@ -188,7 +136,9 @@
hythread_suspend_enable();
if (exn_raised()) {
- TRACE("java.lang.Thread.detach(Throwable) method completed with an exception: " << exn_get_name());
+ TRACE
+ ("java.lang.Thread.detach(Throwable) method completed with an exception: "
+ << exn_get_name());
return TM_ERROR_INTERNAL;
}
return TM_ERROR_NONE;
@@ -197,63 +147,53 @@
/**
* Attaches thread current thread to VM.
*/
-jint vm_attach(JavaVM * java_vm, JNIEnv ** p_jni_env,
- void *pv_vmt_dummies) {
- M2nFrame * p_m2n;
- VM_thread * p_vm_thread;
- ObjectHandles * p_handles;
- struct vmthread_dummies *p_vmt_dummies =
- (struct vmthread_dummies *)pv_vmt_dummies;
-
- if (p_vmt_dummies != NULL) {
- p_m2n = p_vmt_dummies->p_m2n_frame;
- p_vm_thread = p_vmt_dummies->p_vm_thread;
- p_handles = p_vmt_dummies->p_object_handles;
- }
-
+jint vm_attach(JavaVM * java_vm, JNIEnv ** p_jni_env)
+{
// It seems to be reasonable to have suspend enabled state here.
// It is unsafe to perform operations which require suspend disabled
// mode until current thread is not attaced to VM.
assert(hythread_is_suspend_enabled());
- if (p_vmt_dummies != NULL) {
- // VMThread structure is already allocated, we only need to set
- // TLS
- set_TLS_data (p_vm_thread);
- } else {
- p_vm_thread = get_vm_thread(hythread_self());
-
- if (p_vm_thread != NULL) {
- assert (java_vm == p_vm_thread->jni_env->vm);
- *p_jni_env = p_vm_thread->jni_env;
- return JNI_OK;
- }
-
- p_vm_thread = get_a_thread_block((JavaVM_Internal *)java_vm);
+ vm_thread_t vm_thread = p_TLS_vmthread;
+ if (!vm_thread) {
+ vm_thread = jthread_allocate_vm_thread(hythread_self());
}
// if the assertion is false we cannot notify the parent thread
// that we started and it would hang in waitloop
- assert (p_vm_thread != NULL);
-
- if (p_vmt_dummies == NULL) {
- // Create top level M2N frame.
- p_m2n = (M2nFrame*) apr_palloc(p_vm_thread->pool, sizeof(M2nFrame));
- // Create local handles.
- p_handles = (ObjectHandles*) apr_palloc(p_vm_thread->pool, sizeof(ObjectHandlesNew));
- p_vm_thread->jni_env = (JNIEnv_Internal *) apr_palloc(p_vm_thread->pool, sizeof(JNIEnv_Internal));
+ assert(vm_thread);
+
+ jint status = jthread_allocate_vm_thread_pool(java_vm, vm_thread);
+ if (status != JNI_OK) {
+ return status;
}
- assert (p_m2n != NULL && p_handles != NULL && p_vm_thread->jni_env != NULL);
+ // Create top level M2N frame.
+ M2nFrame *p_m2n = (M2nFrame *) apr_palloc(vm_thread->pool, sizeof(M2nFrame));
+ if (!p_m2n) {
+ return JNI_ENOMEM;
+ }
- // Initialize JNI environment.
- p_vm_thread->jni_env->functions = &jni_vtable;
- p_vm_thread->jni_env->vm = (JavaVM_Internal *)java_vm;
- p_vm_thread->jni_env->reserved0 = (void *)0x1234abcd;
- *p_jni_env = p_vm_thread->jni_env;
+ // Create local handles.
+ ObjectHandles *p_handles = (ObjectHandles *) apr_palloc(vm_thread->pool,
+ sizeof(ObjectHandlesNew));
+ if (!p_handles) {
+ return JNI_ENOMEM;
+ }
+ vm_thread->jni_env =
+ (JNIEnv *) apr_palloc(vm_thread->pool, sizeof(JNIEnv_Internal));
+ if (!vm_thread->jni_env) {
+ return JNI_ENOMEM;
+ }
+
+ // Initialize JNI environment.
+ JNIEnv_Internal *jni_env = (JNIEnv_Internal *) vm_thread->jni_env;
+ jni_env->functions = &jni_vtable;
+ jni_env->vm = (JavaVM_Internal *) java_vm;
+ jni_env->reserved0 = (void *) 0x1234abcd;
+ *p_jni_env = jni_env;
-
init_stack_info();
m2n_null_init(p_m2n);
@@ -263,7 +203,16 @@
m2n_set_local_handles(p_m2n, p_handles);
m2n_set_frame_type(p_m2n, FRAME_NON_UNWINDABLE);
- gc_thread_init(&p_vm_thread->_gc_private_information);
+ gc_thread_init(&vm_thread->_gc_private_information);
+
+ if (ti_is_enabled()) {
+ vm_thread->jvmti_thread.owned_monitors =
+ (jobject*)apr_palloc(vm_thread->pool,
+ sizeof(jobject) * TM_MAX_OWNED_MONITOR_NUMBER);
+ vm_thread->jvmti_thread.jvmti_jit_breakpoints_handling_buffer =
+ (jbyte*)apr_palloc(vm_thread->pool,
+ sizeof(jbyte) * TM_JVMTI_MAX_BUFFER_SIZE);
+ }
assert(hythread_is_suspend_enabled());
return JNI_OK;
@@ -272,9 +221,10 @@
/**
* Detaches current thread from VM.
*/
-jint vm_detach(jthread java_thread) {
- VM_thread * p_vm_thread;
-
+jint vm_detach(jthread java_thread)
+{
+ VM_thread *p_vm_thread;
+
assert(hythread_is_suspend_enabled());
// could return error if detach throws an exception,
@@ -297,11 +247,9 @@
remove_guard_stack();
#endif
- // Remove current VM_thread from TLS.
- set_TLS_data(NULL);
- // Destroy current VM_thread structure.
- apr_pool_destroy(p_vm_thread->pool);
-
+ // Destroy current VM_thread pool.
+ jthread_deallocate_vm_thread_pool(p_vm_thread);
+
hythread_suspend_enable();
return JNI_OK;
@@ -320,14 +268,13 @@
void vm_notify_obj_alive(void *p_obj)
{
- if (IS_FAT_LOCK(((ManagedObject *)p_obj)->get_obj_info())) {
- uint32 xx = ((ManagedObject *)p_obj)->get_obj_info();
- hythread_native_resource_is_live(xx);
+ uint32 obj_info = ((ManagedObject*)p_obj)->get_obj_info();
+ if (hythread_is_fat_lock(obj_info)) {
+ hythread_native_resource_is_live(obj_info);
}
}
void vm_reclaim_native_objs()
{
- hythread_reclaim_resources();
+ hythread_reclaim_resources();
}
-
Copied: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_attrs.cpp (from r556643, harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_attrs.c)
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_attrs.cpp?view=diff&rev=556704&p1=harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_attrs.c&r1=556643&p2=harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_attrs.cpp&r2=556704
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_attrs.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_attrs.cpp Mon Jul 16 12:32:35 2007
@@ -18,11 +18,11 @@
/**
* @file thread_java_attrs.c
* @brief Java thread priority related functions
- */
+ */
#include <open/jthread.h>
#include <open/hythread_ext.h>
-#include "thread_private.h"
+#include "vm_threads.h"
/**
* Returns the priority for the <code>thread</code>.
@@ -30,9 +30,10 @@
* @param[in] java_thread thread those attribute is read
* @sa java.lang.Thread.getPriority()
*/
-int jthread_get_priority(jthread java_thread) {
+jint jthread_get_priority(jthread java_thread)
+{
hythread_t tm_native_thread = jthread_get_native_thread(java_thread);
- return hythread_get_priority(tm_native_thread);
+ return (jint)hythread_get_priority(tm_native_thread);
}
/**
@@ -42,7 +43,8 @@
* @param[in] priority thread priority
* @sa java.lang.Thread.setPriority()
*/
-IDATA VMCALL jthread_set_priority(jthread java_thread, int priority) {
+IDATA VMCALL jthread_set_priority(jthread java_thread, jint priority)
+{
hythread_t tm_native_thread = jthread_get_native_thread(java_thread);
return hythread_set_priority(tm_native_thread, priority);
}
@@ -52,9 +54,8 @@
*
* @param[in] thread thread those attribute is read
*/
-jboolean jthread_is_daemon(jthread thread) {
- jvmti_thread_t jvmti_thread;
-
- jvmti_thread = hythread_get_private_data(hythread_self());
- return jvmti_thread->daemon;
+jboolean jthread_is_daemon(jthread thread)
+{
+ vm_thread_t vm_thread = (vm_thread_t)thread;
+ return (jboolean)vm_thread->daemon;
}
Copied: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_basic.cpp (from r556643, harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c)
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_basic.cpp?view=diff&rev=556704&p1=harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c&r1=556643&p2=harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_basic.cpp&r2=556704
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_basic.cpp Mon Jul 16 12:32:35 2007
@@ -22,34 +22,16 @@
#include <open/jthread.h>
#include <open/hythread_ext.h>
-#include <apr_atomic.h>
#include "open/thread_externals.h"
-#include "open/vm.h"
-
-#undef LOG_DOMAIN
-#define LOG_DOMAIN "tm.java"
-
-#include "thread_private.h"
+#include "vm_threads.h"
#include "jni.h"
+#define LOG_DOMAIN "tm.java"
+#include "cxxlog.h"
-
-void stop_callback(void);
-jmethodID getRunMethod(JNIEnv *env, jthread java_thread);
-IDATA increase_nondaemon_threads_count(hythread_t self);
-IDATA countdown_nondaemon_threads(hythread_t self);
-
-typedef struct {
- JavaVM * java_vm;
- jboolean daemon;
- jvmtiEnv *tiEnv;
- jvmtiStartFunction tiProc;
- void *tiProcArgs;
- void *vm_thread_dummies;
-} wrapper_proc_data;
-
-
-IDATA associate_native_and_java_thread(JNIEnv* env, jthread java_thread, hythread_t tm_native_thread, jobject thread_ref);
+static jmethodID jthread_get_run_method(JNIEnv * env, jthread java_thread);
+static IDATA jthread_associate_native_and_java_thread(JNIEnv * env,
+ jthread java_thread, hythread_t native_thread, jobject weak_ref);
/**
* Creates new Java thread.
@@ -62,56 +44,61 @@
* @param[in] attrs thread attributes.
* @sa java.lang.Thread.run()
*/
-IDATA jthread_create(JNIEnv * jni_env, jthread java_thread, jthread_threadattr_t *attrs) {
+IDATA jthread_create(JNIEnv *jni_env,
+ jthread java_thread,
+ jthread_threadattr_t *attrs)
+{
+ return jthread_create_with_function(jni_env, java_thread, attrs);
+} // jthread_create
- return jthread_create_with_function(jni_env, java_thread, attrs, NULL, NULL);
-}
+static IDATA HYTHREAD_PROC jthread_wrapper_proc(void *arg)
+{
+ assert(arg);
+ jthread_threadattr_t data = *(jthread_threadattr_t*) arg;
+ STD_FREE(arg);
-int wrapper_proc(void *arg) {
- IDATA status;
- JNIEnv * jni_env;
- hythread_t native_thread;
- jvmti_thread_t jvmti_thread;
- jthread java_thread;
- wrapper_proc_data *data = (wrapper_proc_data *)arg;
-
// Association should be already done.
- native_thread = hythread_self();
- jvmti_thread = hythread_get_private_data(native_thread);
- assert(jvmti_thread);
- java_thread = jvmti_thread->thread_object;
-
- status = vm_attach(data->java_vm, &jni_env, data->vm_thread_dummies);
- assert (status == JNI_OK);
-
- jvmti_thread->jenv = jni_env;
- jvmti_thread->daemon = data->daemon;
-
- TRACE( ("TM: Java thread started: id=%d OS_handle=%p", native_thread->thread_id, apr_os_thread_current()) );
-
- if (!jvmti_thread->daemon) {
- increase_nondaemon_threads_count(native_thread);
+ 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);
+ jobject java_thread = vm_thread->java_thread;
+
+ JNIEnv *jni_env;
+ IDATA status = vm_attach(data.java_vm, &jni_env);
+ assert(status == JNI_OK);
+
+ vm_thread->jni_env = jni_env;
+ vm_thread->daemon = data.daemon;
+
+ TRACE(("TM: Java thread started: id=%d OS_handle=%p",
+ hythread_get_id(native_thread), apr_os_thread_current()));
+
+ if (!vm_thread->daemon) {
+ status = hythread_increase_nondaemon_threads_count(native_thread);
+ assert(status == TM_ERROR_NONE);
}
// Send Thread Start event.
jvmti_send_thread_start_end_event(1);
-
- thread_start_count();
-
+ jthread_start_count();
- if (data->tiProc != NULL) {
- data->tiProc(data->tiEnv, jni_env, data->tiProcArgs);
+ if (data.proc != NULL) {
+ data.proc(data.jvmti_env, jni_env, (void*)data.arg);
} else {
// for jthread_create();
- (*jni_env) -> CallVoidMethodA(jni_env, java_thread, getRunMethod(jni_env, java_thread), NULL);
+ jni_env->CallVoidMethodA(java_thread,
+ jthread_get_run_method(jni_env, java_thread), NULL);
}
-
+
status = jthread_detach(java_thread);
- TRACE(("TM: Java thread finished: id=%d OS_handle=%p", native_thread->thread_id, apr_os_thread_current()));
+ TRACE(("TM: Java thread finished: id=%d OS_handle=%p",
+ hythread_get_id(native_thread), apr_os_thread_current()));
return status;
-}
+} // jthread_wrapper_proc
/**
* Creates new Java thread with specific execution function.
@@ -129,71 +116,62 @@
* @param[in] arg The argument to the start function. Is passed as an array.
* @sa JVMTI::RunAgentThread()
*/
-IDATA jthread_create_with_function(JNIEnv * jni_env, jthread java_thread, jthread_threadattr_t *attrs, jvmtiStartFunction proc, const void* arg)
+IDATA jthread_create_with_function(JNIEnv *jni_env,
+ jthread java_thread,
+ jthread_threadattr_t *given_attrs)
{
- hythread_t tm_native_thread = NULL;
- jvmti_thread_t tm_java_thread;
- void *vm_thread_dummies;
- static int default_stacksize = -1;
-
- wrapper_proc_data * data;
- IDATA status;
-
- if (jni_env == NULL || java_thread == NULL || attrs == NULL) {
+ if (jni_env == NULL || java_thread == NULL || given_attrs == NULL) {
return TM_ERROR_NULL_POINTER;
}
- tm_native_thread = vm_jthread_get_tm_data(java_thread);
-
+ hythread_t native_thread = vm_jthread_get_tm_data(java_thread);
+
// This is for irregular use. In ordinary live valid jthread instance
// contains weak reference associated with it and native thread to reuse.
- if (tm_native_thread == NULL) {
- if ( !jthread_thread_init(NULL, jni_env, java_thread, NULL, 0)) {
+ if (native_thread == NULL) {
+ assert(0);
+ if (!jthread_thread_init(jni_env, java_thread, NULL, 0)) {
return TM_ERROR_OUT_OF_MEMORY;
}
- tm_native_thread = vm_jthread_get_tm_data(java_thread);
+ native_thread = vm_jthread_get_tm_data(java_thread);
}
- tm_java_thread = hythread_get_private_data(tm_native_thread);
- assert(tm_java_thread);
- tm_java_thread->thread_object = (*jni_env)->NewGlobalRef(jni_env, java_thread);
+ vm_thread_t vm_thread =
+ (vm_thread_t) hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
+ assert(vm_thread);
+ vm_thread->java_thread = jni_env->NewGlobalRef(java_thread);
- data = apr_palloc(tm_java_thread->pool, sizeof(wrapper_proc_data));
- if (data == NULL) {
+ // prepare args for wrapper_proc
+ jthread_threadattr_t *attrs =
+ (jthread_threadattr_t*)STD_MALLOC(sizeof(jthread_threadattr_t));
+ if (attrs == NULL) {
return TM_ERROR_OUT_OF_MEMORY;
}
+ *attrs = *given_attrs;
// Get JavaVM
- status = (*jni_env) -> GetJavaVM(jni_env, &data->java_vm);
- if (status != JNI_OK) return TM_ERROR_INTERNAL;
-
- // Allocate memory needed by soon to be born thread
- vm_thread_dummies = vm_allocate_thread_dummies(data->java_vm);
-
- if (vm_thread_dummies == NULL) {
- return TM_ERROR_OUT_OF_MEMORY;
+ IDATA status = jni_env->GetJavaVM(&attrs->java_vm);
+ if (status != JNI_OK) {
+ return TM_ERROR_INTERNAL;
}
- if (default_stacksize == -1) {
- int ss = get_size_property("thread.stacksize", 0, VM_PROPERTIES);
- default_stacksize = ss ? ss : HY_DEFAULT_STACKSIZE;
+ static size_t default_stacksize;
+ if (0 == default_stacksize) {
+ size_t stack_size = get_size_property("thread.stacksize", 0, VM_PROPERTIES);
+ default_stacksize = stack_size ? stack_size : TM_DEFAULT_STACKSIZE;
}
+ if (!attrs->stacksize) {
+ attrs->stacksize = default_stacksize;
+ }
+ status =
+ hythread_create(&native_thread, attrs->stacksize,
+ attrs->priority, 0, jthread_wrapper_proc, attrs);
- // prepare args for wrapper_proc
- data->daemon = attrs->daemon;
- data->tiEnv = attrs->jvmti_env;
- data->tiProc = proc;
- data->tiProcArgs = (void *)arg;
- data->vm_thread_dummies = vm_thread_dummies;
-
- status = hythread_create(&tm_native_thread, (attrs->stacksize)?attrs->stacksize:default_stacksize,
- attrs->priority, 0, wrapper_proc, data);
-
- TRACE(("TM: Created thread: id=%d", tm_native_thread->thread_id));
+ TRACE(("TM: Created thread: id=%d", hythread_get_id(native_thread)));
return status;
-}
+} // jthread_create_with_function
/**
* Attaches the current native thread to Java VM.
@@ -207,72 +185,77 @@
* @param[in] daemon JNI_TRUE if attaching thread is a daemon thread, JNI_FALSE otherwise
* @sa JNI::AttachCurrentThread ()
*/
-IDATA jthread_attach(JNIEnv * jni_env, jthread java_thread, jboolean daemon) {
- hythread_t tm_native_thread;
- jvmti_thread_t jvmti_thread;
- IDATA status;
-
- // Do nothing if thread already attached.
- if (jthread_self() != NULL) return TM_ERROR_NONE;
-
- tm_native_thread = hythread_self();
- assert(tm_native_thread);
-
- status = associate_native_and_java_thread(jni_env, java_thread, tm_native_thread, NULL);
- if (status != TM_ERROR_NONE) return status;
+IDATA jthread_attach(JNIEnv *jni_env, jthread java_thread, jboolean daemon)
+{
+ if (jthread_self() != NULL) {
+ // Do nothing if thread already attached.
+ return TM_ERROR_NONE;
+ }
- jvmti_thread = hythread_get_private_data(tm_native_thread);
- assert(jvmti_thread);
- jvmti_thread->thread_object = (*jni_env)->NewGlobalRef(jni_env, java_thread);
- jvmti_thread->jenv = jni_env;
- jvmti_thread->daemon = daemon;
+ hythread_t native_thread = hythread_self();
+ assert(native_thread);
+ IDATA status = jthread_associate_native_and_java_thread(jni_env, java_thread,
+ native_thread, NULL);
+ if (status != TM_ERROR_NONE) {
+ return status;
+ }
- if (!jvmti_thread->daemon) {
- increase_nondaemon_threads_count(tm_native_thread);
+ vm_thread_t vm_thread =
+ (vm_thread_t) hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
+ assert(vm_thread);
+ vm_thread->java_thread = jni_env->NewGlobalRef(java_thread);
+ vm_thread->jni_env = jni_env;
+ vm_thread->daemon = daemon;
+ if (!daemon) {
+ status = hythread_increase_nondaemon_threads_count(native_thread);
+ assert(status == TM_ERROR_NONE);
}
// Send Thread Start event.
jvmti_send_thread_start_end_event(1);
-
- thread_start_count();
+ jthread_start_count();
TRACE(("TM: Current thread attached to jthread=%p", java_thread));
return TM_ERROR_NONE;
-}
+} // jthread_attach
/**
* Associates the Java thread with the native thread.
*
- * @param[in] ret_thread not used
* @param[in] env JNI environment that will be associated with the created Java thread
* @param[in] java_thread the Java thread for the association
* @param[in] weak_ref java.lang.WeakReference to the <code>java_thread</code> that used for native resource deletion
- * @param[in] old_thread the native thread for the association
+ * @param[in] dead_thread the native thread for the association
* @return the native thread
*/
-jlong jthread_thread_init(jvmti_thread_t *ret_thread, JNIEnv* env, jthread java_thread, jobject weak_ref, jlong old_thread) {
- hythread_t tm_native_thread = NULL;
- jvmti_thread_t tmj_thread;
- IDATA status;
-
- if (old_thread) {
- tm_native_thread = (hythread_t)((IDATA)old_thread);
- tmj_thread = (jvmti_thread_t)hythread_get_private_data(tm_native_thread);
- //delete used weak reference
- if (tmj_thread->thread_ref) (*env)->DeleteGlobalRef(env, tmj_thread->thread_ref);
+jlong jthread_thread_init(JNIEnv *env,
+ jthread java_thread,
+ jobject weak_ref,
+ hythread_t dead_thread)
+{
+ hythread_t native_thread = NULL;
+ if (dead_thread) {
+ native_thread = (hythread_t) ((IDATA) dead_thread);
+ vm_thread_t vm_thread =
+ (vm_thread_t) hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
+ if (vm_thread->weak_ref) {
+ // delete used weak reference
+ env->DeleteGlobalRef(vm_thread->weak_ref);
+ }
}
- status = hythread_struct_init(&tm_native_thread);
+ IDATA status = hythread_struct_init(&native_thread);
if (status != TM_ERROR_NONE) {
return 0;
}
-
- status = associate_native_and_java_thread(env, java_thread, tm_native_thread, weak_ref);
+
+ status = jthread_associate_native_and_java_thread(env, java_thread,
+ native_thread, weak_ref);
if (status != TM_ERROR_NONE) {
return 0;
}
- return (jlong)((IDATA)tm_native_thread);
-}
+ return (jlong)((IDATA)native_thread);
+} // jthread_thread_init
/**
* Detaches the selected thread from java VM.
@@ -281,88 +264,74 @@
*
* @param[in] java_thread Java thread to be detached
*/
-IDATA jthread_detach(jthread java_thread) {
- IDATA status;
- hythread_t tm_native_thread;
- jvmti_thread_t tm_jvmti_thread;
- JNIEnv * jni_env;
-
- assert(hythread_is_suspend_enabled());
-
+IDATA jthread_detach(jthread java_thread)
+{
// Check input arg
assert(java_thread);
+ assert(hythread_is_suspend_enabled());
+
TRACE(("TM: jthread_detach %x", hythread_self()));
- tm_native_thread = jthread_get_native_thread(java_thread);
- tm_jvmti_thread = hythread_get_private_data(tm_native_thread);
- jni_env = tm_jvmti_thread->jenv;
+ hythread_t native_thread = jthread_get_native_thread(java_thread);
+ assert(native_thread);
+ vm_thread_t vm_thread =
+ (vm_thread_t) hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
+ assert(vm_thread);
+ JNIEnv *jni_env = vm_thread->jni_env;
- if (!tm_jvmti_thread->daemon) {
- countdown_nondaemon_threads(tm_native_thread);
+ IDATA status;
+ if (!vm_thread->daemon) {
+ status = hythread_decrease_nondaemon_threads_count(native_thread, 1);
+ assert(status == TM_ERROR_NONE);
}
// Detach from VM.
status = vm_detach(java_thread);
- if (status != JNI_OK) return TM_ERROR_INTERNAL;
+ if (status != JNI_OK) {
+ return TM_ERROR_INTERNAL;
+ }
// Delete global reference to current thread object.
- (*jni_env)->DeleteGlobalRef(jni_env, tm_jvmti_thread->thread_object);
+ jni_env->DeleteGlobalRef(vm_thread->java_thread);
// jthread_self() will return NULL now.
- tm_jvmti_thread->thread_object = NULL;
+ vm_thread->java_thread = NULL;
// Decrease alive thread counter
- thread_end_count();
-
- // Deallocate tm_jvmti_thread
- //apr_pool_destroy(tm_jvmti_thread->pool);
-
+ jthread_end_count();
assert(hythread_is_suspend_enabled());
- return TM_ERROR_NONE;
-}
-IDATA associate_native_and_java_thread(JNIEnv * jni_env, jthread java_thread, hythread_t tm_native_thread, jobject thread_ref)
+ return TM_ERROR_NONE;
+} // jthread_detach
+
+static IDATA
+jthread_associate_native_and_java_thread(JNIEnv * jni_env,
+ jthread java_thread,
+ hythread_t native_thread,
+ jobject weak_ref)
{
- IDATA status;
- apr_status_t apr_status;
- apr_pool_t *pool;
- jvmti_thread_t tm_java_thread;
-
- if ((jni_env == NULL) || (java_thread == NULL) || (tm_native_thread == NULL)) {
+ if ((jni_env == NULL) || (java_thread == NULL)
+ || (native_thread == NULL))
+ {
return TM_ERROR_NULL_POINTER;
}
-
- tm_java_thread = hythread_get_private_data(tm_native_thread);
- if (!tm_java_thread) {
- apr_status = apr_pool_create(&pool, 0);
- if (apr_status != APR_SUCCESS) return CONVERT_ERROR(apr_status);
- if (pool == NULL) return TM_ERROR_OUT_OF_MEMORY;
- tm_java_thread = apr_palloc(pool, sizeof(JVMTIThread));
- if (tm_java_thread == NULL) return TM_ERROR_OUT_OF_MEMORY;
-
- tm_java_thread->pool = pool;
- status = hythread_set_private_data(tm_native_thread, tm_java_thread);
- if (status != TM_ERROR_NONE) return status;
+ vm_thread_t vm_thread =
+ (vm_thread_t)hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
+
+ if (!vm_thread) {
+ // init VM_thread structure in native thread local
+ vm_thread = jthread_allocate_vm_thread(native_thread);
}
- // JNI environment is created when this thread attaches to VM.
- tm_java_thread->jenv = NULL;
- tm_java_thread->thread_ref = (thread_ref) ? (*jni_env)->NewGlobalRef(jni_env, thread_ref) : NULL;
- tm_java_thread->contended_monitor = 0;
- tm_java_thread->wait_monitor = 0;
- tm_java_thread->blocked_count = 0;
- tm_java_thread->blocked_time = 0;
- tm_java_thread->waited_count = 0;
- tm_java_thread->waited_time = 0;
- tm_java_thread->owned_monitors = 0;
- tm_java_thread->owned_monitors_nmb = 0;
- tm_java_thread->jvmti_local_storage.env = 0;
- tm_java_thread->jvmti_local_storage.data = 0;
+ assert(vm_thread);
+
+ vm_thread->weak_ref =
+ (weak_ref) ? jni_env->NewGlobalRef(weak_ref) : NULL;
+
+ // Associate java thread with native thread
+ vm_jthread_set_tm_data(java_thread, native_thread);
- // Associate java_thread with tm_thread
- vm_jthread_set_tm_data(java_thread, tm_native_thread);
-
return TM_ERROR_NONE;
-}
+} // jthread_associate_native_and_java_thread
/**
* Waits till the <code>thread</code> is finished.
@@ -372,19 +341,23 @@
* was successfully joined.
* @sa java.lang.Thread.join()
*/
-IDATA jthread_join(jthread java_thread) {
- IDATA status;
- hythread_t tm_native_thread;
-
+IDATA jthread_join(jthread java_thread)
+{
if (java_thread == NULL) {
return TM_ERROR_NULL_POINTER;
}
- tm_native_thread = jthread_get_native_thread(java_thread);
- status = hythread_join_interruptable(tm_native_thread, 0, 0);
- TRACE(("TM: jthread %d joined %d", hythread_self()->thread_id, tm_native_thread->thread_id));
+ hythread_t native_thread = jthread_get_native_thread(java_thread);
+ if (!native_thread) {
+ return TM_ERROR_NONE;
+ }
+ IDATA status = hythread_join_interruptable(native_thread, 0, 0);
+
+ TRACE(("TM: jthread %d joined %d", hythread_get_id(hythread_self()),
+ hythread_get_id(native_thread)));
+
return status;
-}
+} // jthread_join
/**
* Waits till the <code>thread</code> is finished with specific timeout.
@@ -396,48 +369,46 @@
* was successfully joined.
* @sa java.lang.Thread.join()
*/
-IDATA jthread_timed_join(jthread java_thread, jlong millis, jint nanos) {
-
- hythread_t tm_native_thread;
- IDATA status;
-
+IDATA jthread_timed_join(jthread java_thread, jlong millis, jint nanos)
+{
if (java_thread == NULL) {
return TM_ERROR_NULL_POINTER;
}
- tm_native_thread = jthread_get_native_thread(java_thread);
- if (!tm_native_thread) {
- return TM_ERROR_NONE;
+
+ hythread_t native_thread = jthread_get_native_thread(java_thread);
+ if (!native_thread) {
+ return TM_ERROR_NONE;
}
- status = hythread_join_interruptable(tm_native_thread, millis, nanos);
- TRACE(("TM: jthread %d joined %d", hythread_self()->thread_id, tm_native_thread->thread_id));
+ IDATA status = hythread_join_interruptable(native_thread, millis, nanos);
+
+ TRACE(("TM: jthread %d joined %d", hythread_get_self_id(),
+ hythread_get_id(native_thread)));
return status;
-}
+} // jthread_timed_join
/**
* Lets an another thread to pass.
* @sa java.lang.Thread.yield()
*/
-IDATA jthread_yield() {
+IDATA jthread_yield()
+{
hythread_yield();
return TM_ERROR_NONE;
-}
+} // jthread_yield
/*
* Callback which is executed in the target thread at safe point
* whenever Thread.stop() method is called.
*/
-void stop_callback(void) {
- hythread_t tm_native_thread;
- jvmti_thread_t tm_java_thread;
- jobject excn;
-
- tm_native_thread = hythread_self();
- tm_java_thread = hythread_get_private_data(tm_native_thread);
- excn = tm_java_thread->stop_exception;
-
+static void stop_callback(void)
+{
+ vm_thread_t vm_thread = p_TLS_vmthread;
+ assert(vm_thread);
+ jobject excn = vm_thread->stop_exception;
+
jthread_throw_exception_object(excn);
-}
+} // stop_callback
/**
* Stops the execution of the given <code>thread</code> and forces
@@ -446,21 +417,20 @@
* @param[in] java_thread thread to be stopped
* @sa java.lang.Thread.stop()
*/
-IDATA jthread_stop(jthread java_thread) {
- jclass clazz;
- jmethodID excn_constr;
- jobject excen_obj;
- JNIEnv *env;
- jvmti_thread_t tm_java_thread;
- hythread_t tm_native_thread;
-
- tm_native_thread = vm_jthread_get_tm_data(java_thread);
- tm_java_thread = hythread_get_private_data(tm_native_thread);
- env = tm_java_thread->jenv;
- clazz = (*env)->FindClass(env, "java/lang/ThreadDeath");
- excn_constr = (*env)->GetMethodID(env, clazz, "<init>", "()V");
- excen_obj = (*env)->NewObject(env, clazz, excn_constr);
-
+IDATA jthread_stop(jthread java_thread)
+{
+ assert(java_thread);
+ hythread_t native_thread = vm_jthread_get_tm_data(java_thread);
+ assert(native_thread);
+ vm_thread_t vm_thread =
+ (vm_thread_t) hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
+ assert(vm_thread);
+ JNIEnv *env = vm_thread->jni_env;
+ assert(env);
+ jclass clazz = env->FindClass("java/lang/ThreadDeath");
+ jmethodID excn_constr = env->GetMethodID(clazz, "<init>", "()V");
+ jobject excen_obj = env->NewObject(clazz, excn_constr);
+
return jthread_exception_stop(java_thread, excen_obj);
}
@@ -472,43 +442,22 @@
* @param[in] excn exception to be thrown
* @sa java.lang.Thread.stop()
*/
-IDATA jthread_exception_stop(jthread java_thread, jobject excn) {
+IDATA jthread_exception_stop(jthread java_thread, jobject excn)
+{
+ assert(java_thread);
+ hythread_t native_thread = vm_jthread_get_tm_data(java_thread);
+ 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 tm_java_thread;
- hythread_t tm_native_thread;
- JNIEnv* env;
- IDATA res;
-
- tm_native_thread = jthread_get_native_thread(java_thread);
- tm_java_thread = hythread_get_private_data(tm_native_thread);
-
// Install safepoint callback that would throw exception
- env = jthread_get_JNI_env(jthread_self());
- tm_java_thread->stop_exception = (*env)->NewGlobalRef(env,excn);
-
- res = hythread_set_safepoint_callback(tm_native_thread, stop_callback);
+ JNIEnv *env = vm_thread->jni_env;
+ assert(env);
+ vm_thread->stop_exception = env->NewGlobalRef(excn);
- while (tm_native_thread->suspend_count > 0) {
- apr_atomic_dec32(&tm_native_thread->suspend_count);
- apr_atomic_dec32(&tm_native_thread->request);
- }
-
- // if there is no competition, it would be 1, but if someone else is
- // suspending the same thread simultaneously, it could be greater than 1
- // if safepoint callback isn't set it could be equal to 0.
- //
- // The following assertion may be false because at each time
- // one of the conditions is true, and the other is false, but
- // when checking the whole condition it may be failse in the result.
- // assert(tm_native_thread->request > 0 || tm_native_thread->safepoint_callback == NULL);
-
- // notify the thread that it may wake up now,
- // so that it would eventually reach exception safepoint
- // and execute callback
- hysem_post(tm_native_thread->resume_event);
-
- return res;
-}
+ return hythread_set_thread_stop_callback(native_thread, stop_callback);
+} // jthread_exception_stop
/**
* Causes the current <code>thread</code> to sleep for at least the specified time.
@@ -521,28 +470,36 @@
* or TM_THREAD_INTERRUPTED in case thread was interrupted during sleep.
* @sa java.lang.Thread.sleep()
*/
-IDATA jthread_sleep(jlong millis, jint nanos) {
-
- hythread_t tm_native_thread = hythread_self();
- IDATA status;
-
- tm_native_thread->state &= ~TM_THREAD_STATE_RUNNABLE;
- tm_native_thread->state |= TM_THREAD_STATE_WAITING | TM_THREAD_STATE_SLEEPING |
- TM_THREAD_STATE_WAITING_WITH_TIMEOUT;
+IDATA jthread_sleep(jlong millis, jint nanos)
+{
+ hythread_t native_thread = hythread_self();
+ 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_SLEEPING
+ | TM_THREAD_STATE_WAITING_WITH_TIMEOUT;
+ IDATA status = hythread_set_state(native_thread, state);
+ assert(status == TM_ERROR_NONE);
+ hythread_thread_unlock(native_thread);
- status = hythread_sleep_interruptable(millis, nanos);
+ status = hythread_sleep_interruptable(millis, nanos);
#ifndef NDEBUG
if (status == TM_ERROR_INTERRUPT) {
- TRACE(("TM: sleep interrupted status received, thread: %p", hythread_self()));
+ TRACE(("TM: sleep interrupted status received, thread: %p",
+ hythread_self()));
}
#endif
-
- tm_native_thread->state &= ~(TM_THREAD_STATE_WAITING | TM_THREAD_STATE_SLEEPING |
- TM_THREAD_STATE_WAITING_WITH_TIMEOUT);
- tm_native_thread->state |= TM_THREAD_STATE_RUNNABLE;
+ hythread_thread_lock(native_thread);
+ state = hythread_get_state(native_thread);
+ state &= ~(TM_THREAD_STATE_WAITING | TM_THREAD_STATE_SLEEPING
+ | TM_THREAD_STATE_WAITING_WITH_TIMEOUT);
+ state |= TM_THREAD_STATE_RUNNABLE;
+ hythread_set_state(native_thread, state);
+ hythread_thread_unlock(native_thread);
+
return status;
-}
+} // jthread_sleep
/**
* Returns JNI environment associated with the given jthread, or NULL if there is none.
@@ -552,25 +509,25 @@
*
* @param[in] java_thread java.lang.Thread object
*/
-JNIEnv *jthread_get_JNI_env(jthread java_thread) {
- hythread_t tm_native_thread;
- jvmti_thread_t tm_java_thread;
-
+JNIEnv * jthread_get_JNI_env(jthread java_thread)
+{
if (java_thread == NULL) {
return NULL;
}
- tm_native_thread = jthread_get_native_thread(java_thread);
- if (tm_native_thread == NULL) {
+ hythread_t native_thread = jthread_get_native_thread(java_thread);
+ if (native_thread == NULL) {
return NULL;
}
- tm_java_thread = hythread_get_private_data(tm_native_thread);
- if (tm_java_thread == NULL) {
+ vm_thread_t vm_thread =
+ (vm_thread_t) hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
+ if (vm_thread == NULL) {
return NULL;
}
- return tm_java_thread->jenv;
-}
+ return vm_thread->jni_env;
+} // jthread_get_JNI_env
+
/**
- * Returns thread Id for the given <code>thread</code>.
+ * Returns thread ID for the given <code>thread</code>.
*
* Thread ID must be unique for all Java threads.
* Can be reused after thread is finished.
@@ -578,15 +535,12 @@
* @return thread ID
* @sa java.lang.Thread.getId()
*/
-jlong jthread_get_id(jthread java_thread) {
-
- hythread_t tm_native_thread;
-
- tm_native_thread = jthread_get_native_thread(java_thread);
- assert(tm_native_thread);
-
- return hythread_get_id(tm_native_thread);
-}
+jlong jthread_get_id(jthread java_thread)
+{
+ hythread_t native_thread = jthread_get_native_thread(java_thread);
+ assert(native_thread);
+ return hythread_get_id(native_thread);
+} // jthread_get_id
/**
* Returns jthread given the thread ID.
@@ -594,187 +548,109 @@
* @param[in] thread_id thread ID
* @return jthread for the given ID, or NULL if there are no such.
*/
-jthread jthread_get_thread(jlong thread_id) {
-
- hythread_t tm_native_thread;
- jvmti_thread_t tm_java_thread;
- jthread java_thread;
-
- tm_native_thread = hythread_get_thread((jint)thread_id);
- if (tm_native_thread == NULL) {
+jthread jthread_get_thread(jlong thread_id)
+{
+ hythread_t native_thread = hythread_get_thread((IDATA)thread_id);
+ if (native_thread == NULL) {
return NULL;
}
- tm_java_thread = hythread_get_private_data(tm_native_thread);
- java_thread = 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);
+ jobject java_thread = vm_thread->java_thread;
assert(java_thread);
return java_thread;
-}
+} // jthread_get_thread
/**
* Returns native thread associated with the given Java <code>thread</code>.
*
* @return native thread
*/
-hythread_t jthread_get_native_thread(jthread thread) {
-
+hythread_t jthread_get_native_thread(jthread thread)
+{
assert(thread);
- return vm_jthread_get_tm_data(thread);
-}
+ return vm_jthread_get_tm_data(thread);
+} // jthread_get_native_thread
/**
* Returns Java thread associated with the given native <code>thread</code>.
*
* @return Java thread
*/
-jthread jthread_get_java_thread(hythread_t tm_native_thread) {
-
- jvmti_thread_t tm_java_thread;
-
- if (tm_native_thread == NULL) {
+jthread jthread_get_java_thread(hythread_t native_thread)
+{
+ if (native_thread == NULL) {
TRACE(("TM: native thread is NULL"));
return NULL;
}
- tm_java_thread = hythread_get_private_data(tm_native_thread);
-
- if (tm_java_thread == NULL) {
- TRACE(("TM: tmj thread is NULL"));
+ vm_thread_t vm_thread =
+ (vm_thread_t) hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY);
+ if (vm_thread == NULL) {
+ TRACE(("TM: vm_thread_t thread is NULL"));
return NULL;
}
+ return vm_thread->java_thread;
+} // jthread_get_java_thread
- return tm_java_thread->thread_object;
-}
/**
* Returns jthread associated with the current thread.
*
* @return jthread associated with the current thread,
* or NULL if the current native thread is not attached to JVM.
*/
-jthread jthread_self(void) {
+jthread jthread_self(void)
+{
return jthread_get_java_thread(hythread_self());
-}
+} // jthread_self
/**
* Cancels all java threads. This method being used at VM shutdown
* to terminate all java threads.
- */
-IDATA jthread_cancel_all() {
+ */
+IDATA jthread_cancel_all()
+{
return hythread_cancel_all(NULL);
-}
+} // jthread_cancel_all
/**
* waiting all nondaemon thread's
*
*/
-IDATA VMCALL jthread_wait_for_all_nondaemon_threads() {
- hythread_t native_thread;
- jvmti_thread_t jvmti_thread;
- hythread_library_t lib;
- IDATA status;
-
- native_thread = hythread_self();
- jvmti_thread = hythread_get_private_data(native_thread);
- lib = native_thread->library;
-
- status = hymutex_lock(&lib->TM_LOCK);
- if (status != TM_ERROR_NONE) return status;
-
- if (lib->nondaemon_thread_count == 1 && !jvmti_thread->daemon) {
- status = hymutex_unlock(&lib->TM_LOCK);
- return status;
- }
-
- while ((!jvmti_thread->daemon && lib->nondaemon_thread_count > 1)
- || (jvmti_thread->daemon && lib->nondaemon_thread_count > 0)) {
- status = hycond_wait(&lib->nondaemon_thread_cond, &lib->TM_LOCK);
- //check interruption and other problems
- TRACE(("TM wait for nondaemons notified, count: %d", lib->nondaemon_thread_count));
- if (status != TM_ERROR_NONE) {
- hymutex_unlock(&lib->TM_LOCK);
- return status;
- }
- }
-
- status = hymutex_unlock(&lib->TM_LOCK);
- return status;
-}
+IDATA VMCALL jthread_wait_for_all_nondaemon_threads()
+{
+ 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);
+ return hythread_wait_for_nondaemon_threads(native_thread,
+ (vm_thread->daemon ? 0 : 1));
+} // jthread_wait_for_all_nondaemon_threads
/*
* Auxiliary function to throw java.lang.InterruptedException
*/
-
-void throw_interrupted_exception(void) {
-
- jvmti_thread_t tm_java_thread;
- hythread_t tm_native_thread;
- jclass clazz;
- JNIEnv *env;
-
+void throw_interrupted_exception(void)
+{
TRACE(("interrupted_exception thrown"));
- tm_native_thread = hythread_self();
- tm_java_thread = hythread_get_private_data(tm_native_thread);
- env = tm_java_thread->jenv;
- clazz = (*env) -> FindClass(env, "java/lang/InterruptedException");
- (*env) -> ThrowNew(env, clazz, "Park() is interrupted");
-}
+ vm_thread_t vm_thread = p_TLS_vmthread;
+ assert(vm_thread);
+ JNIEnv *env = vm_thread->jni_env;
+ assert(env);
+ jclass clazz = env->FindClass("java/lang/InterruptedException");
+ env->ThrowNew(clazz, "Park() is interrupted");
+} // throw_interrupted_exception
-jmethodID getRunMethod(JNIEnv *env, jthread java_thread) {
- jclass clazz;
+static jmethodID jthread_get_run_method(JNIEnv * env, jthread java_thread)
+{
static jmethodID run_method = NULL;
- IDATA status;
-
- status=acquire_start_lock();
- assert(status == TM_ERROR_NONE);
- //printf("run method find enter\n");
+
+ TRACE("run method find enter");
if (!run_method) {
- clazz = (*env) -> GetObjectClass(env, java_thread);
- run_method = (*env) -> GetMethodID(env, clazz, "runImpl", "()V");
+ jclass clazz = env->GetObjectClass(java_thread);
+ run_method = env->GetMethodID(clazz, "runImpl", "()V");
}
- status=release_start_lock();
- //printf("run method find exit\n");
- assert(status == TM_ERROR_NONE);
+ TRACE("run method find exit");
return run_method;
-}
-
-IDATA increase_nondaemon_threads_count(hythread_t self) {
- hythread_library_t lib;
- IDATA status;
-
- lib = self->library;
-
- status = hymutex_lock(&lib->TM_LOCK);
- if (status != TM_ERROR_NONE) return status;
-
- lib->nondaemon_thread_count++;
- status = hymutex_unlock(&lib->TM_LOCK);
- return status;
-}
+} // jthread_get_run_method
-IDATA countdown_nondaemon_threads(hythread_t self) {
- hythread_library_t lib;
- IDATA status;
-
- lib = self->library;
-
- status = hymutex_lock(&lib->TM_LOCK);
- if (status != TM_ERROR_NONE) return status;
-
- if (lib->nondaemon_thread_count <= 0) {
- status = hymutex_unlock(&lib->TM_LOCK);
- if (status != TM_ERROR_NONE) return status;
- return TM_ERROR_ILLEGAL_STATE;
- }
-
- TRACE(("TM: nondaemons decreased, thread: %p count: %d\n", self, lib->nondaemon_thread_count));
- lib->nondaemon_thread_count--;
- if (lib->nondaemon_thread_count <= 1) {
- status = hycond_notify_all(&lib->nondaemon_thread_cond);
- TRACE(("TM: nondaemons all dead, thread: %p count: %d\n", self, lib->nondaemon_thread_count));
- if (status != TM_ERROR_NONE) {
- hymutex_unlock(&lib->TM_LOCK);
- return status;
- }
- }
-
- status = hymutex_unlock(&lib->TM_LOCK);
- return status;
-}
Copied: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_interrupt.cpp (from r556643, harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_interrupt.c)
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_interrupt.cpp?view=diff&rev=556704&p1=harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_interrupt.c&r1=556643&p2=harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_interrupt.cpp&r2=556704
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_interrupt.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_interrupt.cpp Mon Jul 16 12:32:35 2007
@@ -22,7 +22,7 @@
#include <open/jthread.h>
#include <open/hythread_ext.h>
-#include "thread_private.h"
+#include "vm_threads.h"
/**
* Interrupt a <code>thread</code>.
@@ -34,11 +34,12 @@
* @param[in] java_thread a thread to be interrupted
* @sa java.lang.Thread.interrupt()
*/
-IDATA VMCALL jthread_interrupt(jthread java_thread) {
- hythread_t tm_native_thread = jthread_get_native_thread(java_thread);
+IDATA VMCALL jthread_interrupt(jthread java_thread)
+{
+ hythread_t tm_native_thread = jthread_get_native_thread(java_thread);
hythread_interrupt(tm_native_thread);
return TM_ERROR_NONE;
-}
+} // jthread_interrupt
/**
* Returns <code>true</code> if the thread <code>thread</code> is interrupted.
@@ -50,11 +51,11 @@
* is interrupted; <code>false</code> otherwise.
* @sa java.lang.Thread.isInterrupted()
*/
-jboolean jthread_is_interrupted(jthread java_thread) {
+jboolean jthread_is_interrupted(jthread java_thread)
+{
hythread_t tm_native_thread = jthread_get_native_thread(java_thread);
return hythread_interrupted(tm_native_thread) > 0;
-
-}
+} // jthread_is_interrupted
/**
* Clears the interruption flag for the specific <code>thread</code>.
@@ -62,7 +63,8 @@
* @param[in] java_thread where to clear interrupt flag
* @sa java.lang.Thread.interrupted()
*/
-IDATA VMCALL jthread_clear_interrupted(jthread java_thread) {
+IDATA VMCALL jthread_clear_interrupted(jthread java_thread)
+{
hythread_t tm_native_thread = jthread_get_native_thread(java_thread);
return hythread_clear_interrupted_other(tm_native_thread);
-}
+} // jthread_clear_interrupted
Copied: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_iterator.cpp (from r556643, harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_iterator.c)
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_iterator.cpp?view=diff&rev=556704&p1=harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_iterator.c&r1=556643&p2=harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_iterator.cpp&r2=556704
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_iterator.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_java_iterator.cpp Mon Jul 16 12:32:35 2007
@@ -23,75 +23,75 @@
#include <open/ti_thread.h>
#include <open/hythread_ext.h>
#include <open/jthread.h>
-#include "thread_private.h"
-
+#include "vm_threads.h"
/**
* Creates the iterator that can be used to walk over java threads.
*/
-jthread_iterator_t VMCALL jthread_iterator_create(void) {
+jthread_iterator_t VMCALL jthread_iterator_create(void)
+{
hythread_group_t java_thread_group = get_java_thread_group();
- return (jthread_iterator_t)hythread_iterator_create(java_thread_group);
-}
+ return (jthread_iterator_t)
+ hythread_iterator_create(java_thread_group);
+} // jthread_iterator_create
/**
* Releases the iterator.
*
* @param[in] it iterator
*/
-IDATA VMCALL jthread_iterator_release(jthread_iterator_t *it) {
- return hythread_iterator_release((hythread_iterator_t *)it);
-}
+IDATA VMCALL jthread_iterator_release(jthread_iterator_t * it)
+{
+ return hythread_iterator_release((hythread_iterator_t *) it);
+} // jthread_iterator_release
/**
* Resets the iterator such that it will start from the beginning.
*
* @param[in] it iterator
*/
-IDATA VMCALL jthread_iterator_reset(jthread_iterator_t *it) {
- return hythread_iterator_reset((hythread_iterator_t *)it);
-}
+IDATA VMCALL jthread_iterator_reset(jthread_iterator_t * it)
+{
+ return hythread_iterator_reset((hythread_iterator_t *) it);
+} // jthread_iterator_reset
/**
* Returns the next jthread using the given iterator.
*
* @param[in] it iterator
*/
-jthread VMCALL jthread_iterator_next(jthread_iterator_t *it) {
- hythread_t tm_native_thread;
- jvmti_thread_t tm_java_thread;
- tm_native_thread = hythread_iterator_next((hythread_iterator_t *)it);
- while (tm_native_thread!=NULL)
- {
- if (hythread_is_alive(tm_native_thread)) {
- tm_java_thread = hythread_get_private_data(tm_native_thread);
- if (tm_java_thread) {
- return (jthread)tm_java_thread->thread_object;
+jobject VMCALL jthread_iterator_next(jthread_iterator_t * it)
+{
+ hythread_t native_thread = hythread_iterator_next((hythread_iterator_t *) it);
+ while (native_thread != NULL) {
+ if (hythread_is_alive(native_thread)) {
+ vm_thread_t vm_thread = (vm_thread_t)hythread_tls_get(native_thread,
+ TM_THREAD_VM_TLS_KEY);
+ if (vm_thread) {
+ return vm_thread->java_thread;
}
}
- tm_native_thread = hythread_iterator_next((hythread_iterator_t *)it);
+ native_thread = hythread_iterator_next((hythread_iterator_t *) it);
}
-
return NULL;
-}
+} // jthread_iterator_next
/**
* Returns the the number of Java threads.
*
* @param[in] iterator
*/
-IDATA VMCALL jthread_iterator_size(jthread_iterator_t iterator) {
- jthread res;
- IDATA status;
- int count=0;
- status=jthread_iterator_reset(&iterator);
+IDATA VMCALL jthread_iterator_size(jthread_iterator_t iterator)
+{
+ IDATA status = jthread_iterator_reset(&iterator);
assert(status == TM_ERROR_NONE);
- res = jthread_iterator_next(&iterator);
- while (res!=NULL) {
- count++;
- res = jthread_iterator_next(&iterator);
+ jthread thread = jthread_iterator_next(&iterator);
+ int count = 0;
+ while (thread != NULL) {
+ count++;
+ thread = jthread_iterator_next(&iterator);
}
- status=jthread_iterator_reset(&iterator);
+ status = jthread_iterator_reset(&iterator);
assert(status == TM_ERROR_NONE);
return count;
-}
+} // jthread_iterator_size