From nobody Mon Sep 17 00:00:00 2001 From: Pavel Afremov Date: Tue, 27 Mar 2007 19:03:45 +0400 Subject: [PATCH] Fast TLS access via intrinsics. --- vm/include/open/hythread.h | 33 +++++++++++++++++++++++++-------- vm/include/open/hythread_ext.h | 31 +++---------------------------- vm/thread/src/thread_native_basic.c | 18 +++++++++++++----- 3 files changed, 41 insertions(+), 41 deletions(-) aee200e8a667a006f3774f5807149541e77b4a92 diff --git a/vm/include/open/hythread.h b/vm/include/open/hythread.h index 6ba5c2f..56febdc 100644 --- a/vm/include/open/hythread.h +++ b/vm/include/open/hythread.h @@ -27,6 +27,14 @@ #include #include #include "hycomp.h" + +#ifdef WIN32 +# if (_MSC_VER >= 1400) +# include +# endif +#endif + + /* * Idea behind these declarations is to make some functions static inlined for * all files that include hythread_ext.h/hythread.h except one, that @@ -410,9 +418,6 @@ #define ASM_MONITOR_HELPER // http://www.microsoft.com/msj/archive/S2CE.aspx #define FS14_TLS_USE -#elif defined _EM64T_ && defined WINDOWS - -#define APR_TLS_USE #endif @@ -444,11 +449,23 @@ extern "C" { #endif /* __cplusplus */ hy_inline hythread_t VMCALL hythread_self() { - register hythread_t t; - _asm { mov eax, fs:[0x14] - mov t, eax; - } - return t; +#ifndef _WIN64 +# if (_MSC_VER >= 1400) + // file winnt.h can't be included here + // 0x14 = offsetof(NT_TIB, ArbitraryUserPointer) + return (hythread_t) __readfsdword(0x14); +# else + register hythread_t t; + _asm { mov eax, fs:[0x14] + mov t, eax; + } + return t; +# endif +#else + // file winnt.h can't be included here + // 0x28 = offsetof(NT_TIB, ArbitraryUserPointer) + return (hythread_t) __readgsqword(0x28); +#endif } #define tm_self_tls (hythread_self()) diff --git a/vm/include/open/hythread_ext.h b/vm/include/open/hythread_ext.h index b324041..22ad168 100644 --- a/vm/include/open/hythread_ext.h +++ b/vm/include/open/hythread_ext.h @@ -351,20 +351,11 @@ hy_inline IDATA VMCALL hythread_is_suspe * point where safe suspension is possible. */ hy_inline void VMCALL hythread_suspend_enable() { + register hythread_t thread; assert(!hythread_is_suspend_enabled()); -#ifdef FS14_TLS_USE - // the macros could work for WIN32 - __asm { - mov eax, fs:[0x14] - dec[eax] HyThread_public.disable_count - } -#else - { - register hythread_t thread = tm_self_tls; - ((HyThread_public *)thread)->disable_count--; - } -#endif + thread = tm_self_tls; + ((HyThread_public *)thread)->disable_count--; } /** @@ -389,24 +380,8 @@ hy_inline void VMCALL hythread_suspend_d // default group only. assert(((HyThread_public *)tm_self_tls)->group == get_java_thread_group()); -#ifdef FS14_TLS_USE - // the macros could work for WIN32 - __asm { - mov eax, fs:[0x14] - inc[eax] HyThread_public.disable_count - mov eax,[eax] HyThread_public.request - test eax, eax - jnz suspended - } - return; - - suspended: - thread = tm_self_tls; - -#else thread = tm_self_tls; ((HyThread_public *)thread)->disable_count++; -#endif if (((HyThread_public *)thread)->request && ((HyThread_public *)thread)->disable_count == 1) { diff --git a/vm/thread/src/thread_native_basic.c b/vm/thread/src/thread_native_basic.c index 52e4122..87b88ae 100644 --- a/vm/thread/src/thread_native_basic.c +++ b/vm/thread/src/thread_native_basic.c @@ -381,11 +381,19 @@ hythread_t hythread_self_slow() { } static void thread_set_self(hythread_t thread) { - //tm_self_tls = thread; - _asm{ - mov eax, thread - mov fs:[0x14], eax - } + // tm_self_tls = thread; +#ifndef _WIN64 +# if (_MSC_VER >= 1400) + __writefsdword(offsetof(NT_TIB, ArbitraryUserPointer), thread); +# else + _asm{ + mov eax, thread + mov fs:[0x14], eax + } +# endif +#else + __writegsqword(offsetof(NT_TIB, ArbitraryUserPointer), thread); +#endif } #else /** -- 1.3.3