From 9faa1817f765b673fa85cdd92cd4509e42cdc733 Mon Sep 17 00:00:00 2001 From: Pavel Afremov Date: Fri, 26 Jan 2007 16:36:45 +0300 Subject: [PATCH] Adapt TLS inlining for Linux. --- vm/include/open/hythread_ext.h | 92 +++++++++++++++++++++++++------ vm/thread/src/hythr.exp | 1 vm/thread/src/thread_private.h | 7 +- vm/vmcore/include/vm_threads.h | 6 -- vm/vmcore/src/thread/thread_manager.cpp | 10 ++- 5 files changed, 86 insertions(+), 30 deletions(-) diff --git a/vm/include/open/hythread_ext.h b/vm/include/open/hythread_ext.h old mode 100644 new mode 100755 index 4e1f8b4..50af3a0 --- a/vm/include/open/hythread_ext.h +++ b/vm/include/open/hythread_ext.h @@ -474,19 +474,67 @@ 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]; +#ifdef PLATFORM_POSIX +#define hy_inline inline static +#else +#define hy_inline __forceinline +#endif //PLATFORM_POSIX + +#ifdef WIN32 +//use optimized asm monitor enter and exit helpers +#define ASM_MONITOR_HELPER +// FS14_TLS_USE define turns on windows specific TLS access optimization +// We use free TIB slot with 14 offset, see following article for details +// http://www.microsoft.com/msj/archive/S2CE.aspx +#define FS14_TLS_USE +#endif + +#ifdef _EM64T_ +#define APR_TLS_USE +#endif + +#ifdef APR_TLS_USE +hythread_t hythread_fast_self() { + return hythread_self(); } -__forceinline hythread_t hythread_fast_self() { +#else +#ifdef FS14_TLS_USE +hy_inline hythread_t hythread_fast_self() { register hythread_t t; _asm { mov eax, fs:[0x14] mov t, eax; } return t; } +#else +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifdef PLATFORM_POSIX +extern __thread hythread_t tm_self_tls; +#else +extern __declspec(thread) hythread_t tm_self_tls; +#endif //PLATFORM_POSIX + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +hy_inline hythread_t hythread_fast_self() { + assert (hythread_self() == tm_self_tls); + return tm_self_tls; +} +#endif +#endif + +hy_inline void* hythread_tls_fast_get(hythread_t thread, hythread_tls_key_t key) { +// return hythread_tls_get(thread, key); + return thread->thread_local_storage[key]; +} -__forceinline void thread_fast_safe_point_impl(hythread_t thread) { +hy_inline void thread_fast_safe_point_impl(hythread_t thread) { hythread_event_callback_proc callback_func; if(thread->suspend_request >0) { @@ -524,44 +572,54 @@ __forceinline void thread_fast_safe_poin } } // thread_safe_point_impl -__forceinline void hythread_fast_suspend_enable() { +hy_inline void hythread_fast_suspend_enable() { register hythread_t thread; assert(!hythread_is_suspend_enabled()); - __asm { - mov eax, fs:[0x14] +#ifdef FS14_TLS_USE + __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(); + +#else + thread=tm_self_tls; + thread->suspend_disable_count--; + +#endif } -__forceinline void hythread_fast_suspend_disable() +hy_inline 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] +#ifdef FS14_TLS_USE + __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(); +#else + thread=tm_self_tls; + thread->suspend_disable_count++; +#endif + if(!thread->suspend_request || thread->suspend_disable_count!=1) { return; } diff --git a/vm/thread/src/hythr.exp b/vm/thread/src/hythr.exp index aaf8a32..3f56643 100644 --- a/vm/thread/src/hythr.exp +++ b/vm/thread/src/hythr.exp @@ -16,6 +16,7 @@ hythread_park; hythread_monitor_init_with_name; hythread_monitor_try_enter; hythread_self; +tm_self_tls; hythread_tls_free; hythread_yield; hythread_suspend; diff --git a/vm/thread/src/thread_private.h b/vm/thread/src/thread_private.h index 4b094f8..6febe90 100644 --- a/vm/thread/src/thread_private.h +++ b/vm/thread/src/thread_private.h @@ -58,19 +58,20 @@ #define SPIN_COUNT 5 #endif //!defined (_EM64T_) && !defined (_IPF_) +#if 0 #ifdef WIN32 //use optimized asm monitor enter and exit helpers #define ASM_MONITOR_HELPER // FS14_TLS_USE define turns on windows specific TLS access optimization // We use free TIB slot with 14 offset, see following article for details // http://www.microsoft.com/msj/archive/S2CE.aspx -#define FS14_TLS_USE +//#define FS14_TLS_USE #endif #ifdef _EM64T_ #define APR_TLS_USE #endif - +#endif #ifdef __cplusplus extern "C" { @@ -81,7 +82,7 @@ #if !defined (APR_TLS_USE ) && !defined #ifdef PLATFORM_POSIX extern __thread hythread_t tm_self_tls; #else -extern __declspec(thread) hythread_t tm_self_tls; +//extern __declspec(thread) hythread_t tm_self_tls; #endif //PLATFORM_POSIX #else diff --git a/vm/vmcore/include/vm_threads.h b/vm/vmcore/include/vm_threads.h index 9e6351e..732aabc 100644 --- a/vm/vmcore/include/vm_threads.h +++ b/vm/vmcore/include/vm_threads.h @@ -167,11 +167,7 @@ VMEXPORT VM_thread *get_vm_thread(hythre //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 - } + register hythread_t thr = hythread_fast_self(); return (VM_thread *)hythread_tls_fast_get(thr, 0 /*TLS_key_pvmthread*/); } diff --git a/vm/vmcore/src/thread/thread_manager.cpp b/vm/vmcore/src/thread/thread_manager.cpp index 18ffad7..6dde8fa 100644 --- a/vm/vmcore/src/thread/thread_manager.cpp +++ b/vm/vmcore/src/thread/thread_manager.cpp @@ -94,7 +94,7 @@ void init_TLS_data(); VM_thread * get_a_thread_block(JavaVM_Internal * java_vm) { VM_thread * p_vmthread; - apr_pool_t * thread_pool; + apr_pool_t * thread_pool; p_vmthread = p_TLS_vmthread; if (!p_vmthread) { @@ -111,7 +111,7 @@ VM_thread * get_a_thread_block(JavaVM_In } return p_vmthread; } -/* +/* VM_thread *get_vm_thread(hythread_t thr) { if (thr == NULL) { return NULL; @@ -125,9 +125,9 @@ VM_thread *get_vm_thread_ptr_safe(JNIEnv if(t == NULL) { return NULL; } - return (VM_thread *)hythread_tls_fast_get(t, TLS_key_pvmthread); + return (VM_thread *)hythread_tls_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_fast_self(), TLS_key_pvmthread, thread); + hythread_tls_set(hythread_self(), TLS_key_pvmthread, thread); //printf ("sett ls call %p %p\n", get_thread_ptr(), get_vm_thread(hythread_self())); } -- 1.4.2.1