diff --git a/vm/include/open/hythread.h b/vm/include/open/hythread.h index 61d4c30..9f8a29e 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 @@ -402,21 +410,13 @@ #endif -#ifdef _EM64T_ -# ifdef _WIN64 - //don't use optimized asm monitor enter and exit helpers -# else - //use optimized asm monitor enter and exit helpers -# define ASM_MONITOR_HELPER -# endif -#else #ifdef _IPF_ //don't use optimized asm monitor enter and exit helpers #else //use optimized asm monitor enter and exit helpers # define ASM_MONITOR_HELPER #endif -#endif + #if defined (_WIN32) # define HYTHREAD_FAST_TLS_ATTRIBUTE @@ -468,11 +468,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 c49f0f8..a604d32 100644 --- a/vm/include/open/hythread_ext.h +++ b/vm/include/open/hythread_ext.h @@ -381,20 +381,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--; } /** @@ -419,24 +410,8 @@ hy_inline void VMCALL hythread_suspend_d // default group only. assert(((HyThread_public *)hythread_self())->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 f3af35a..6a6b95e 100644 --- a/vm/thread/src/thread_native_basic.c +++ b/vm/thread/src/thread_native_basic.c @@ -382,11 +382,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 /**