From 5883045c1d19fdcb70820775e274bbe978601178 Mon Sep 17 00:00:00 2001 From: Pavel Afremov Date: Fri, 26 Jan 2007 14:16:47 +0300 Subject: [PATCH] Force inline of p_TLS_vmthread and tmn_suspent_enable/disable. --- vm/gc_cc/src/gc_for_vm.cpp | 6 - vm/gc_gen/src/common/gc_platform.h | 2 vm/include/open/hythread_ext.h | 274 ++++++++++++++++++++++++++++ vm/thread/src/thread_init.c | 2 vm/thread/src/thread_java_attrs.c | 2 vm/thread/src/thread_java_basic.c | 22 +- vm/thread/src/thread_java_monitors.c | 18 +- vm/thread/src/thread_native_basic.c | 8 - vm/thread/src/thread_native_thin_monitor.c | 6 - vm/thread/src/thread_private.h | 5 - vm/thread/src/thread_ti_timing.c | 2 vm/vmcore/include/vm_threads.h | 33 +++ vm/vmcore/src/init/vm_init.cpp | 4 vm/vmcore/src/init/vm_shutdown.cpp | 4 vm/vmcore/src/jit/jit_runtime_support.cpp | 2 vm/vmcore/src/jni/jni.cpp | 2 vm/vmcore/src/jvmti/jvmti.cpp | 2 vm/vmcore/src/stack/stack_trace.cpp | 2 vm/vmcore/src/thread/thread_manager.cpp | 10 + 19 files changed, 349 insertions(+), 57 deletions(-) diff --git a/vm/gc_cc/src/gc_for_vm.cpp b/vm/gc_cc/src/gc_for_vm.cpp index 1180dde..56bb951 100644 --- a/vm/gc_cc/src/gc_for_vm.cpp +++ b/vm/gc_cc/src/gc_for_vm.cpp @@ -134,7 +134,7 @@ Managed_Object_Handle gc_alloc_fast(unsi assert (ah); unsigned char *next; - unsigned char* tls_base = (unsigned char*)hythread_self(); + unsigned char* tls_base = (unsigned char*)hythread_fast_self(); GC_Thread_Info info(tls_base); Partial_Reveal_VTable *vtable = ah_to_vtable(ah); GC_VTable_Info *gcvt = vtable->get_gcvt(); @@ -181,7 +181,7 @@ Managed_Object_Handle gc_alloc(unsigned assert((in_size % GC_OBJECT_ALIGNMENT) == 0); assert (ah); - unsigned char* tls_base = (unsigned char*)hythread_self(); + unsigned char* tls_base = (unsigned char*)hythread_fast_self(); GC_Thread_Info info(tls_base); Partial_Reveal_VTable *vtable = ah_to_vtable(ah); GC_VTable_Info *gcvt = vtable->get_gcvt(); @@ -354,7 +354,7 @@ void gc_thread_init(void *gc_information tls_offset_clean = hythread_tls_get_offset(tls_key_clean); tls_offset_ceiling = hythread_tls_get_offset(tls_key_ceiling); } - unsigned char* tls_base = (unsigned char*)hythread_self(); + unsigned char* tls_base = (unsigned char*)hythread_fast_self(); GC_Thread_Info info(tls_base); info.set_tls_current_free(0); info.set_tls_current_ceiling(0); diff --git a/vm/gc_gen/src/common/gc_platform.h b/vm/gc_gen/src/common/gc_platform.h index 88ddd5c..bfe518a 100644 --- a/vm/gc_gen/src/common/gc_platform.h +++ b/vm/gc_gen/src/common/gc_platform.h @@ -69,7 +69,7 @@ inline void vm_thread_yield() { hythread_yield(); } inline void* vm_thread_local() -{ return hythread_self(); } +{ return hythread_fast_self(); } inline int vm_create_thread(int (*func)(void*), void *data) { diff --git a/vm/include/open/hythread_ext.h b/vm/include/open/hythread_ext.h index 9d7e4fc..4e1f8b4 100644 --- a/vm/include/open/hythread_ext.h +++ b/vm/include/open/hythread_ext.h @@ -123,6 +123,16 @@ #endif #include "hythread.h" +#include +#include +#include +#include +#include +#include + +#include +#include "apr_thread_ext.h" + //@{ /** * Opaque structures @@ -140,6 +150,173 @@ typedef I_32 hythread_thin_monitor_t; typedef void (*hythread_event_callback_proc)(void); +typedef struct HyThreadLibrary { + IDATA a; + hymutex_t TM_LOCK; + IDATA nondaemon_thread_count; + hycond_t nondaemon_thread_cond; +} HyThreadLibrary; + +/** + * Native thread control structure. + */ +typedef struct HyThread { + +#ifndef POSIX + // This is dummy pointer for Microsoft Visual Studio debugging + // If this is removed, Visual Studio, when attached to VM, will show + // no symbolic information + void* reserved; +#endif + + /** + * Each thread keeps a pointer to the libary it belongs to. + */ + HyThreadLibrary * library; + +// Suspension + + /** + * Number of suspend requests made for this thread. + */ + int32 suspend_request; + + /** + * Flag indicating that thread can safely be suspended. + */ + int16 suspend_disable_count; + + /** + * Event used to notify interested threads whenever thread enters the safe region. + */ + hylatch_t safe_region_event; + + /** + * Event used to notify suspended thread that it needs to wake up. + */ + hysem_t resume_event; + + /** + * Function to be executed at safepoint upon thread resume. + */ + hythread_event_callback_proc safepoint_callback; + + +// Basic manipulation fields + + /** + * Group for this thread. Different groups are needed in order + * to be able to quickly iterate over the specific group. + * Examples are: Java threads, GC private threads. + * Equal to the address of the head of the list of threads for this group. + */ + hythread_group_t group; + + /** + * Points to the next thread within the group. + */ + hythread_t next; + + /** + * Points to the last thread within the group. + */ + hythread_t prev; + + /** + * Handle to OS thread. + */ + apr_thread_t *os_handle; + + /** + * Placeholder for any data to be associated with this thread. + * Java layer is using it to keep java-specific context. + */ + void *private_data; + + /** + * Flag indicating there was request to exit + */ + Boolean exit_request; + + /** + * Exit value of this thread + */ + IDATA exit_value; + + +// Synchronization stuff + + /* + * Thread local lock, used to serialize thread state; + */ + hymutex_t mutex; + + /* + * Conditional variable used to implement wait function for sleep/park; + */ + hycond_t condition; + + /** + * Event reserved for threads that invoke join. + */ + hylatch_t join_event; + + /** + * Current conditional variable thread is waiting on (used for interrupting) + */ + hycond_t current_condition; + +// State + + /** + * Thread state. Holds thread state flags as defined in JVMTI specification, plus some additional + * flags. See + * JVMTI Specification for more details. + */ + IDATA state; + + +// Attributes + + /** + * name of the thread (useful for debugging purposes) + */ + char* name; + + /** + * Hint for scheduler about thread priority + */ + IDATA priority; + +// Monitors + + /** + * ID for this thread. The maximum number of threads is governed by the size of lockword record. + */ + IDATA thread_id; + + /** + * Memory pool in with this thread allocated + */ + apr_pool_t *pool; + + /** + * APR thread attributes + */ + apr_threadattr_t *apr_attrs; + + /** + * Array representing thread local storage + */ + void *thread_local_storage[10]; + + /** + * Extension to the standard local storage slot. + */ + void **big_local_storage; + +} HyThread; + //@} /** @name Thread Manager initialization / shutdown */ @@ -172,7 +349,7 @@ IDATA VMCALL hythread_get_id(hythread_t hythread_t VMCALL hythread_get_thread(IDATA id); IDATA VMCALL hythread_struct_init(hythread_t *ret_thread); IDATA VMCALL hythread_cancel_all(hythread_group_t group); - IDATA hythread_group_create(hythread_group_t *group); +IDATA hythread_group_create(hythread_group_t *group); IDATA VMCALL hythread_group_release(hythread_group_t group); IDATA VMCALL hythread_group_get_list(hythread_group_t **list, int* size); void* VMCALL hythread_get_private_data(hythread_t t); @@ -297,6 +474,101 @@ int VMCALL hythread_is_interrupted(hythr int VMCALL hythread_is_in_native(hythread_t thread) ; int VMCALL hythread_is_daemon(hythread_t thread) ; +__forceinline void* hythread_tls_fast_get(hythread_t thread, hythread_tls_key_t key) { + return thread->thread_local_storage[key]; +} + +__forceinline hythread_t hythread_fast_self() { + register hythread_t t; + _asm { mov eax, fs:[0x14] + mov t, eax; + } + return t; +} + +__forceinline void thread_fast_safe_point_impl(hythread_t thread) { + hythread_event_callback_proc callback_func; + if(thread->suspend_request >0) { + + int old_status = thread->suspend_disable_count; + do { + //TRACE(("TM: safe point enter: thread: %p count: %d dis count: %d", + // thread, thread->suspend_request, thread->suspend_disable_count)); + + if (thread->safepoint_callback) { + thread->suspend_disable_count = 1; + // Clear callback (this is one-time event) + callback_func = thread->safepoint_callback; + thread->safepoint_callback = NULL; + + // since set callback suspended the thread + // resore its original state + hythread_resume(hythread_fast_self()); + callback_func(); + } + + thread->suspend_disable_count = 0; + + apr_memory_rw_barrier(); + // code for Ipf that support StackIterator and immmediate suspend + // notify suspender + // hylatch_count_down(thread->safe_region_event); + + // wait for resume event + hysem_wait(thread->resume_event); + //TRACE(("TM: safe point resume: thread: %p count: %d", thread, thread->suspend_request)); + + thread->suspend_disable_count = old_status; + apr_memory_rw_barrier(); + } while (thread->suspend_request >0); + } +} // thread_safe_point_impl + +__forceinline void hythread_fast_suspend_enable() { + register hythread_t thread; + assert(!hythread_is_suspend_enabled()); + + __asm { + mov eax, fs:[0x14] + dec [eax]HyThread.suspend_disable_count + mov eax, [eax]HyThread.suspend_request + test eax, eax + jnz suspended + } + return; + +suspended: + thread=hythread_fast_self(); +} + +__forceinline void hythread_fast_suspend_disable() +{ + register hythread_t thread; +#ifndef NDEBUG + // Check that current thread is in default thread group. + // Justification: GC suspends and enumerates threads from default group only. + //assert(hythread_fast_self()->group == TM_DEFAULT_GROUP); +#endif + + __asm { + mov eax, fs:[0x14] + inc [eax]HyThread.suspend_disable_count + mov eax, [eax]HyThread.suspend_request + test eax, eax + jnz suspended + } + return; + +suspended: + thread=hythread_fast_self(); + + if(!thread->suspend_request || thread->suspend_disable_count!=1) { + return; + } + thread_fast_safe_point_impl(thread); +} + + //@} /** diff --git a/vm/thread/src/thread_init.c b/vm/thread/src/thread_init.c index 5842fc3..4a4f4e0 100644 --- a/vm/thread/src/thread_init.c +++ b/vm/thread/src/thread_init.c @@ -198,7 +198,7 @@ void VMCALL hythread_init(hythread_libra * @see hythread_init */ void VMCALL hythread_shutdown() { - hythread_lib_destroy(hythread_self()->library); + hythread_lib_destroy(hythread_fast_self()->library); } /** diff --git a/vm/thread/src/thread_java_attrs.c b/vm/thread/src/thread_java_attrs.c index 8831979..5295e89 100644 --- a/vm/thread/src/thread_java_attrs.c +++ b/vm/thread/src/thread_java_attrs.c @@ -60,6 +60,6 @@ IDATA VMCALL jthread_set_priority(jthrea jboolean jthread_is_daemon(jthread thread) { jvmti_thread_t jvmti_thread; - jvmti_thread = hythread_get_private_data(hythread_self()); + jvmti_thread = hythread_get_private_data(hythread_fast_self()); return jvmti_thread->daemon; } diff --git a/vm/thread/src/thread_java_basic.c b/vm/thread/src/thread_java_basic.c old mode 100644 new mode 100755 index 4479de6..7a09080 --- a/vm/thread/src/thread_java_basic.c +++ b/vm/thread/src/thread_java_basic.c @@ -75,7 +75,7 @@ int wrapper_proc(void *arg) { wrapper_proc_data *data = (wrapper_proc_data *)arg; // Association should be already done. - native_thread = hythread_self(); + native_thread = hythread_fast_self(); jvmti_thread = hythread_get_private_data(native_thread); assert(jvmti_thread); java_thread = jvmti_thread->thread_object; @@ -163,7 +163,7 @@ IDATA jthread_create_with_function(JNIEn data->tiProcArgs = (void *)arg; if (!data->daemon) { - increase_nondaemon_threads_count(hythread_self()); + increase_nondaemon_threads_count(hythread_fast_self()); } status = hythread_create(&tm_native_thread, (attrs->stacksize)?attrs->stacksize:1024000, @@ -194,7 +194,7 @@ IDATA jthread_attach(JNIEnv * jni_env, j // Do nothing if thread already attached. if (jthread_self() != NULL) return TM_ERROR_NONE; - tm_native_thread = hythread_self(); + tm_native_thread = hythread_fast_self(); assert(tm_native_thread); status = associate_native_and_java_thread(jni_env, java_thread, tm_native_thread, NULL); @@ -267,7 +267,7 @@ IDATA jthread_detach(jthread java_thread // Check input arg assert(java_thread); - TRACE(("TM: jthread_detach %x", hythread_self())); + TRACE(("TM: jthread_detach %x", hythread_fast_self())); tm_native_thread = jthread_get_native_thread(java_thread); tm_jvmti_thread = hythread_get_private_data(tm_native_thread); @@ -352,7 +352,7 @@ IDATA jthread_join(jthread java_thread) } 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)); + TRACE(("TM: jthread %d joined %d", hythread_fast_self()->thread_id, tm_native_thread->thread_id)); return status; } @@ -380,7 +380,7 @@ IDATA jthread_timed_join(jthread java_th 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)); + TRACE(("TM: jthread %d joined %d", hythread_fast_self()->thread_id, tm_native_thread->thread_id)); return status; } @@ -403,7 +403,7 @@ void stop_callback() { jvmti_thread_t tm_java_thread; jobject excn; - tm_native_thread = hythread_self(); + tm_native_thread = hythread_fast_self(); tm_java_thread = hythread_get_private_data(tm_native_thread); excn = tm_java_thread->stop_exception; @@ -475,7 +475,7 @@ IDATA jthread_exception_stop(jthread jav */ IDATA jthread_sleep(jlong millis, jint nanos) { - hythread_t tm_native_thread = hythread_self(); + hythread_t tm_native_thread = hythread_fast_self(); IDATA status; tm_native_thread->state &= ~TM_THREAD_STATE_RUNNABLE; @@ -602,7 +602,7 @@ jthread jthread_get_java_thread(hythread * or NULL if the current native thread is not attached to JVM. */ jthread jthread_self(void) { - return jthread_get_java_thread(hythread_self()); + return jthread_get_java_thread(hythread_fast_self()); } /** @@ -623,7 +623,7 @@ IDATA VMCALL jthread_wait_for_all_nondae hythread_library_t lib; IDATA status; - native_thread = hythread_self(); + native_thread = hythread_fast_self(); jvmti_thread = hythread_get_private_data(native_thread); lib = native_thread->library; @@ -662,7 +662,7 @@ void throw_interrupted_exception(void){ JNIEnv *env; TRACE(("interrupted_exception thrown")); - tm_native_thread = hythread_self(); + tm_native_thread = hythread_fast_self(); tm_java_thread = hythread_get_private_data(tm_native_thread); env = tm_java_thread->jenv; clazz = (*env) -> FindClass(env, "java/lang/InterruptedException"); diff --git a/vm/thread/src/thread_java_monitors.c b/vm/thread/src/thread_java_monitors.c index 9821de7..1506e1c 100644 --- a/vm/thread/src/thread_java_monitors.c +++ b/vm/thread/src/thread_java_monitors.c @@ -99,7 +99,7 @@ #ifdef LOCK_RESERVATION goto entered; } #endif //LOCK_RESERVATION - tm_native_thread = hythread_self(); + tm_native_thread = hythread_fast_self(); tm_native_thread->state &= ~TM_THREAD_STATE_RUNNABLE; tm_native_thread->state |= TM_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER; @@ -143,7 +143,7 @@ contended_entered: jvmti_send_contended_enter_or_entered_monitor_event(monitor, 0); set_suspend_disable(disable_count); // should be moved to event handler - tm_java_thread = hythread_get_private_data(hythread_self()); + tm_java_thread = hythread_get_private_data(hythread_fast_self()); tm_java_thread->blocked_time += apr_time_now()- enter_begin; ///////// } @@ -302,7 +302,7 @@ IDATA VMCALL jthread_monitor_timed_wait( hythread_suspend_disable(); lockword = vm_object_get_lockword_addr(monitor); if (!is_fat_lock(*lockword)) { - if (!owns_thin_lock(hythread_self(), *lockword)) { + if (!owns_thin_lock(hythread_fast_self(), *lockword)) { TRACE(("ILLEGAL_STATE wait %x\n", lockword)); hythread_suspend_enable(); return TM_ERROR_ILLEGAL_STATE; @@ -324,7 +324,7 @@ IDATA VMCALL jthread_monitor_timed_wait( remove_owned_monitor(monitor); } - tm_native_thread = hythread_self(); + tm_native_thread = hythread_fast_self(); tm_native_thread->state &= ~TM_THREAD_STATE_RUNNABLE; tm_native_thread->state |= TM_THREAD_STATE_WAITING | TM_THREAD_STATE_IN_MONITOR_WAIT; @@ -353,7 +353,7 @@ IDATA VMCALL jthread_monitor_timed_wait( jvmti_send_waited_monitor_event(monitor, (status == APR_TIMEUP)?(jboolean)1:(jboolean)0); // should be moved to event handler set_suspend_disable(disable_count); - tm_java_thread = hythread_get_private_data(hythread_self()); + tm_java_thread = hythread_get_private_data(hythread_fast_self()); tm_java_thread->waited_time += apr_time_now()- wait_begin; ///////// } @@ -361,7 +361,7 @@ IDATA VMCALL jthread_monitor_timed_wait( } void add_owned_monitor(jobject monitor){ - hythread_t tm_native_thread = hythread_self(); + hythread_t tm_native_thread = hythread_fast_self(); jvmti_thread_t tm_java_thread = hythread_get_private_data(tm_native_thread); int disable_status; TRACE(("TM: add owned monitor: %x", monitor)); @@ -395,7 +395,7 @@ void add_owned_monitor(jobject monitor){ void remove_owned_monitor(jobject monitor){ int i,j, disable_status; - hythread_t tm_native_thread = hythread_self(); + hythread_t tm_native_thread = hythread_fast_self(); jvmti_thread_t tm_java_thread = hythread_get_private_data(tm_native_thread); TRACE(("TM: remove owned monitor: %x", monitor)); @@ -417,7 +417,7 @@ void remove_owned_monitor(jobject monito } void set_contended_monitor(jobject monitor){ - hythread_t tm_native_thread = hythread_self(); + hythread_t tm_native_thread = hythread_fast_self(); IDATA suspend_status; jvmti_thread_t tm_java_thread = hythread_get_private_data(tm_native_thread); @@ -431,7 +431,7 @@ void set_contended_monitor(jobject monit } void set_wait_monitor(jobject monitor){ - hythread_t tm_native_thread = hythread_self(); + hythread_t tm_native_thread = hythread_fast_self(); IDATA suspend_status; jvmti_thread_t tm_java_thread = hythread_get_private_data(tm_native_thread); diff --git a/vm/thread/src/thread_native_basic.c b/vm/thread/src/thread_native_basic.c index ab5b6a5..86773e8 100644 --- a/vm/thread/src/thread_native_basic.c +++ b/vm/thread/src/thread_native_basic.c @@ -111,7 +111,7 @@ IDATA VMCALL hythread_create_with_group( return TM_ERROR_OUT_OF_MEMORY; } - new_thread->library = hythread_self()->library; + new_thread->library = hythread_fast_self()->library; if (stacksize) { apr_threadattr_create(&apr_attrs, new_thread->pool); apr_threadattr_stacksize_set(apr_attrs, stacksize); @@ -274,7 +274,7 @@ void VMCALL hythread_detach(hythread_t t IDATA status; if (thread == NULL) { - thread = hythread_self(); + thread = hythread_fast_self(); } // Acquire global TM lock to prevent concurrent access to thread list @@ -744,11 +744,11 @@ static void* APR_THREAD_FUNC thread_star extern HY_CFUNC void VMCALL hythread_exit (hythread_monitor_t monitor) { - if (monitor !=NULL && monitor->owner == hythread_self()) { + if (monitor !=NULL && monitor->owner == hythread_fast_self()) { monitor->recursion_count = 0; hythread_monitor_exit(monitor); } - apr_thread_exit(hythread_self()->os_handle, APR_SUCCESS); + apr_thread_exit(hythread_fast_self()->os_handle, APR_SUCCESS); // unreachable statement abort(); } diff --git a/vm/thread/src/thread_native_thin_monitor.c b/vm/thread/src/thread_native_thin_monitor.c index ef0e7be..bd236b9 100644 --- a/vm/thread/src/thread_native_thin_monitor.c +++ b/vm/thread/src/thread_native_thin_monitor.c @@ -116,8 +116,8 @@ extern hymutex_t TM_LOCK; void unreserve_self_lock(hythread_thin_monitor_t *lockword_ptr) { I_32 lockword = *lockword_ptr; I_32 lockword_new; - TRACE(("unreserve self_id %d lock owner %d", hythread_get_id(hythread_self()), THREAD_ID(lockword))); - assert(hythread_get_id(hythread_self()) == THREAD_ID(lockword)); + TRACE(("unreserve self_id %d lock owner %d", hythread_get_id(hythread_fast_self()), THREAD_ID(lockword))); + assert(hythread_get_id(hythread_fast_self()) == THREAD_ID(lockword)); assert (!IS_FAT_LOCK(*lockword_ptr)); assert (IS_RESERVED(lockword)); TRACE(("Unreserved self %d \n", ++unreserve_count_self/*, vm_get_object_class_name(lockword_ptr-1)*/)); @@ -165,7 +165,7 @@ IDATA unreserve_lock(hythread_thin_monit if(owner) { assert(owner); assert(hythread_get_id(owner) == lock_id); - assert(owner != hythread_self()); + assert(owner != hythread_fast_self()); status=hythread_suspend_other(owner); if(status !=TM_ERROR_NONE) { return status; diff --git a/vm/thread/src/thread_private.h b/vm/thread/src/thread_private.h index 5572a60..4b094f8 100644 --- a/vm/thread/src/thread_private.h +++ b/vm/thread/src/thread_private.h @@ -150,7 +150,7 @@ extern int16 tm_tls_capacity; */ extern int16 tm_tls_size; - +#if 0 typedef struct HyThreadLibrary { IDATA a; hymutex_t TM_LOCK; @@ -159,7 +159,6 @@ typedef struct HyThreadLibrary { } HyThreadLibrary; - /** * Native thread control structure. */ @@ -322,7 +321,7 @@ #endif void **big_local_storage; } HyThread; - +#endif /** * Java-specific context that is attached to tm_thread control structure by Java layer diff --git a/vm/thread/src/thread_ti_timing.c b/vm/thread/src/thread_ti_timing.c index eee5e47..76ec9fd 100644 --- a/vm/thread/src/thread_ti_timing.c +++ b/vm/thread/src/thread_ti_timing.c @@ -63,7 +63,7 @@ IDATA VMCALL jthread_get_thread_cpu_time assert(nanos_ptr); if (NULL == java_thread) { - tm_native_thread = hythread_self(); + tm_native_thread = hythread_fast_self(); } else { tm_native_thread = vm_jthread_get_tm_data(java_thread); } diff --git a/vm/vmcore/include/vm_threads.h b/vm/vmcore/include/vm_threads.h index 6e21ba1..9e6351e 100644 --- a/vm/vmcore/include/vm_threads.h +++ b/vm/vmcore/include/vm_threads.h @@ -34,7 +34,8 @@ #endif #include #include "open/types.h" -#include "open/hythread.h" +//#include "open/hythread.h" +#include #include "open/ti_thread.h" #include "vm_core_types.h" @@ -46,10 +47,10 @@ #include "jni_direct.h" // -#define tmn_suspend_disable assert(hythread_is_suspend_enabled());hythread_suspend_disable -#define tmn_suspend_enable assert(!hythread_is_suspend_enabled());hythread_suspend_enable -#define tmn_suspend_disable_recursive hythread_suspend_disable -#define tmn_suspend_enable_recursive hythread_suspend_enable +#define tmn_suspend_disable assert(hythread_is_suspend_enabled());hythread_fast_suspend_disable +#define tmn_suspend_enable assert(!hythread_is_suspend_enabled());hythread_fast_suspend_enable +#define tmn_suspend_disable_recursive hythread_fast_suspend_disable +#define tmn_suspend_enable_recursive hythread_fast_suspend_enable #define GC_BYTES_IN_THREAD_LOCAL (20 * sizeof(void *)) @@ -163,13 +164,33 @@ typedef VM_thread *vm_thread_accessor() VMEXPORT extern vm_thread_accessor *get_thread_ptr; VMEXPORT VM_thread *get_vm_thread(hythread_t thr); +//VMEXPORT VM_thread *get_vm_thread_self(); + +inline VM_thread *get_vm_thread_fast_self() { + register hythread_t thr; + + _asm { mov eax, fs:[0x14] + mov thr, eax + } + + return (VM_thread *)hythread_tls_fast_get(thr, 0 /*TLS_key_pvmthread*/); +} + +inline VM_thread *get_vm_thread(hythread_t thr) { + if (thr == NULL) { + return NULL; + } + return (VM_thread *)hythread_tls_fast_get(thr, 0); +} VMEXPORT void init_TLS_data(); VMEXPORT void set_TLS_data(VM_thread *thread) ; uint16 get_self_stack_key(); -#define p_TLS_vmthread (get_thread_ptr()) +//#define p_TLS_vmthread (get_thread_ptr()) +#define p_TLS_vmthread (get_vm_thread_fast_self()) +//#define p_TLS_vmthread (get_vm_thread(hythread_fast_self())) Registers *thread_gc_get_context(VM_thread *, VmRegisterContext &); void thread_gc_set_context(VM_thread *); diff --git a/vm/vmcore/src/init/vm_init.cpp b/vm/vmcore/src/init/vm_init.cpp index 0533e07..b43bd93 100644 --- a/vm/vmcore/src/init/vm_init.cpp +++ b/vm/vmcore/src/init/vm_init.cpp @@ -540,7 +540,7 @@ static jint vm_create_jthread(jthread * } else { args[2].l = NULL; } - native_thread = hythread_self(); + native_thread = hythread_fast_self(); args[3].j = (POINTER_SIZE_INT) native_thread; args[4].j = 0; args[5].i = hythread_get_priority(native_thread); @@ -570,7 +570,7 @@ jint vm_attach_internal(JNIEnv ** p_jni_ hythread_t native_thread; jint status; - native_thread = hythread_self(); + native_thread = hythread_fast_self(); if (!native_thread) { status = hythread_attach_to_group(&native_thread, ((JavaVM_Internal *)java_vm)->vm_env->hythread_lib, NULL); diff --git a/vm/vmcore/src/init/vm_shutdown.cpp b/vm/vmcore/src/init/vm_shutdown.cpp index be83164..098b773 100644 --- a/vm/vmcore/src/init/vm_shutdown.cpp +++ b/vm/vmcore/src/init/vm_shutdown.cpp @@ -90,7 +90,7 @@ static void vm_shutdown_callback() { JNIEnv * jni_env; Global_Env * vm_env; - self_native = hythread_self(); + self_native = hythread_fast_self(); self_java = jthread_get_java_thread(self_native); self_vm = get_vm_thread(self_native); @@ -130,7 +130,7 @@ static void vm_shutdown_stop_java_thread int left; int prev; - self = hythread_self(); + self = hythread_fast_self(); // Collect running java threads. size = 0; diff --git a/vm/vmcore/src/jit/jit_runtime_support.cpp b/vm/vmcore/src/jit/jit_runtime_support.cpp index 6d8a298..8f4e3b3 100644 --- a/vm/vmcore/src/jit/jit_runtime_support.cpp +++ b/vm/vmcore/src/jit/jit_runtime_support.cpp @@ -1613,7 +1613,7 @@ static NativeCodePtr rth_get_lil_gc_safe } static NativeCodePtr rth_get_lil_tls_base(int * dyn_count) { - return (NativeCodePtr)hythread_self; + return (NativeCodePtr)hythread_fast_self; } static void * rth_resolve(Class_Handle klass, unsigned cp_idx, diff --git a/vm/vmcore/src/jni/jni.cpp b/vm/vmcore/src/jni/jni.cpp index a3049a7..6db8c2b 100644 --- a/vm/vmcore/src/jni/jni.cpp +++ b/vm/vmcore/src/jni/jni.cpp @@ -840,7 +840,7 @@ void JNICALL FatalError(JNIEnv * UNREF j assert(hythread_is_suspend_enabled()); fprintf(stdout, "\nFATAL ERROR occurred in native method: %s\n", msg); - st_print(stdout, hythread_self()); + st_print(stdout, hythread_fast_self()); // Return 1 to be compatible with RI. exit(1); diff --git a/vm/vmcore/src/jvmti/jvmti.cpp b/vm/vmcore/src/jvmti/jvmti.cpp index 329d994..caedee6 100644 --- a/vm/vmcore/src/jvmti/jvmti.cpp +++ b/vm/vmcore/src/jvmti/jvmti.cpp @@ -712,7 +712,7 @@ void DebugUtilsTI::setAgents(Agent *agen bool DebugUtilsTI::isLocallyEnabled() { //default value is that ti enabled on thread level - return hythread_tls_get(hythread_self(), this->TL_ti_enabled) == NULL; + return hythread_tls_fast_get(hythread_self(), this->TL_ti_enabled) == NULL; } void DebugUtilsTI::setLocallyEnabled() { diff --git a/vm/vmcore/src/stack/stack_trace.cpp b/vm/vmcore/src/stack/stack_trace.cpp index 5ffd0c1..6e1e12d 100644 --- a/vm/vmcore/src/stack/stack_trace.cpp +++ b/vm/vmcore/src/stack/stack_trace.cpp @@ -282,5 +282,5 @@ void st_print(FILE* f, hythread_t thread } void st_print() { - st_print(stderr, hythread_self()); + st_print(stderr, hythread_fast_self()); } diff --git a/vm/vmcore/src/thread/thread_manager.cpp b/vm/vmcore/src/thread/thread_manager.cpp index 1d7305e..18ffad7 100644 --- a/vm/vmcore/src/thread/thread_manager.cpp +++ b/vm/vmcore/src/thread/thread_manager.cpp @@ -111,23 +111,23 @@ VM_thread * get_a_thread_block(JavaVM_In } return p_vmthread; } - +/* VM_thread *get_vm_thread(hythread_t thr) { if (thr == NULL) { return NULL; } return (VM_thread *)hythread_tls_get(thr, TLS_key_pvmthread); } - +*/ 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); + return (VM_thread *)hythread_tls_fast_get(t, TLS_key_pvmthread); } - +//FIXME VM_thread *get_thread_ptr_stub() { return get_vm_thread(hythread_self()); @@ -144,7 +144,7 @@ #endif } void set_TLS_data(VM_thread *thread) { - hythread_tls_set(hythread_self(), TLS_key_pvmthread, thread); + hythread_tls_set(hythread_fast_self(), TLS_key_pvmthread, thread); //printf ("sett ls call %p %p\n", get_thread_ptr(), get_vm_thread(hythread_self())); } -- 1.4.1