From 7390646a4c3d7ba1d9df43e26f0b16d82b4bac8a Mon Sep 17 00:00:00 2001 From: Pavel Afremov Date: Thu, 8 Feb 2007 16:43:55 +0300 Subject: [PATCH] Force inline of p_TLS_vmthread and tmn_suspent_enable/disable. Patch forces inlining for both x86_32 and x86_64 Linux platform and for Win32. Patch contains following changes: - Share 2 private structures of hy_thread. - Added fast version of some functions to inline. - Replace slow call to fast inline in DRLVM code. - Preallocate for VM core one TLS key. --- vm/gc_cc/src/gc_for_vm.cpp | 6 vm/gc_gen/src/common/gc_platform.h | 2 vm/include/open/hythread_ext.h | 342 ++++++++++++++++++++ vm/thread/src/hythr.exp | 1 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_native_tls.c | 2 vm/thread/src/thread_private.h | 13 - vm/thread/src/thread_ti_timing.c | 2 vm/vmcore/include/vm_log.h | 4 vm/vmcore/include/vm_threads.h | 29 +- vm/vmcore/src/exception/exceptions.cpp | 2 vm/vmcore/src/exception/exceptions_impl.cpp | 8 vm/vmcore/src/init/vm_init.cpp | 28 +- vm/vmcore/src/init/vm_shutdown.cpp | 4 vm/vmcore/src/jit/compile.cpp | 4 vm/vmcore/src/jit/jit_runtime_support.cpp | 18 + vm/vmcore/src/jni/jni.cpp | 6 vm/vmcore/src/jni/jni_utils.cpp | 28 +- vm/vmcore/src/jvmti/jvmti.cpp | 6 vm/vmcore/src/jvmti/jvmti_break.cpp | 4 vm/vmcore/src/jvmti/jvmti_event.cpp | 28 +- vm/vmcore/src/jvmti/jvmti_heap.cpp | 24 + vm/vmcore/src/jvmti/jvmti_heap.h | 8 vm/vmcore/src/jvmti/jvmti_pop_frame.cpp | 4 vm/vmcore/src/jvmti/jvmti_step.cpp | 4 vm/vmcore/src/object/object_handles.cpp | 4 vm/vmcore/src/stack/stack_trace.cpp | 2 vm/vmcore/src/thread/thread_generic.cpp | 6 vm/vmcore/src/thread/thread_manager.cpp | 29 +- vm/vmcore/src/util/linux/signals_em64t.cpp | 2 vm/vmcore/src/util/linux/signals_ia32.cpp | 2 .../src/util/win/ia32/nt_exception_filter.cpp | 4 37 files changed, 511 insertions(+), 173 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 6c74bca..799a144 100644 --- a/vm/gc_gen/src/common/gc_platform.h +++ b/vm/gc_gen/src/common/gc_platform.h @@ -84,7 +84,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 old mode 100644 new mode 100755 index 9d7e4fc..05e9c20 --- 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,169 @@ int VMCALL hythread_is_interrupted(hythr int VMCALL hythread_is_in_native(hythread_t thread) ; int VMCALL hythread_is_daemon(hythread_t thread) ; +#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 + +#if defined _EM64T_ && defined WINDOWS +#define APR_TLS_USE +#endif + +#ifdef APR_TLS_USE +hy_inline hythread_t hythread_fast_self() { + return hythread_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]; +} + +hy_inline IDATA hythread_fast_is_suspend_enabled(){ + return hythread_fast_self()->suspend_disable_count == 0; +} + +hy_inline 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 + +hy_inline void hythread_fast_safe_point() { + thread_fast_safe_point_impl(hythread_fast_self()); +} + + +hy_inline void hythread_fast_suspend_enable() { + register hythread_t thread; + assert(!hythread_is_suspend_enabled()); + +#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=hythread_fast_self(); + thread->suspend_disable_count--; + +#endif +} + +hy_inline void hythread_fast_suspend_disable() +{ + register hythread_t thread; + +#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=hythread_fast_self(); + thread->suspend_disable_count++; +#endif + + if(!thread->suspend_request || thread->suspend_disable_count!=1) { + return; + } + thread_fast_safe_point_impl(thread); +} + +#define TM_THREAD_VM_TLS_KEY 0 +#define TM_THREAD_QUANTITY_OF_PREDEFINED_TLS_KEYS 1 //@} /** 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_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 index e070461..1984850 100644 --- 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; @@ -164,7 +164,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, @@ -195,7 +195,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); @@ -269,7 +269,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); @@ -353,7 +353,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; } @@ -381,7 +381,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; } @@ -404,7 +404,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; @@ -476,7 +476,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; @@ -603,7 +603,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()); } /** @@ -624,7 +624,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; @@ -663,7 +663,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_native_tls.c b/vm/thread/src/thread_native_tls.c index 830d6c6..46010c8 100644 --- a/vm/thread/src/thread_native_tls.c +++ b/vm/thread/src/thread_native_tls.c @@ -34,7 +34,7 @@ #include //@{ int16 tm_tls_capacity = 16; -int16 tm_tls_size = 0; +int16 tm_tls_size = TM_THREAD_QUANTITY_OF_PREDEFINED_TLS_KEYS; static void tls_finalizer_placeholder(void *args) {} diff --git a/vm/thread/src/thread_private.h b/vm/thread/src/thread_private.h index f0f68a5..0fb26b6 100644 --- a/vm/thread/src/thread_private.h +++ b/vm/thread/src/thread_private.h @@ -64,15 +64,9 @@ #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 -*/ - #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -151,7 +145,7 @@ extern int16 tm_tls_capacity; */ extern int16 tm_tls_size; - +#if 0 typedef struct HyThreadLibrary { IDATA a; hymutex_t TM_LOCK; @@ -160,7 +154,6 @@ typedef struct HyThreadLibrary { } HyThreadLibrary; - /** * Native thread control structure. */ @@ -323,7 +316,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_log.h b/vm/vmcore/include/vm_log.h old mode 100644 new mode 100755 index 38d2f4e..d7805c8 --- a/vm/vmcore/include/vm_log.h +++ b/vm/vmcore/include/vm_log.h @@ -90,13 +90,13 @@ inline LoggerString& operator<<(LoggerSt * The convenience method for logging JNI object handles. */ inline LoggerString& operator<<(LoggerString& log, const jobject jobj) { - hythread_suspend_disable(); + hythread_fast_suspend_disable(); if (jobj) { log << jobj->object; } else { log << ""; } - hythread_suspend_enable(); + hythread_fast_suspend_enable(); return log; } diff --git a/vm/vmcore/include/vm_threads.h b/vm/vmcore/include/vm_threads.h old mode 100644 new mode 100755 index 80d97ce..f6f5050 --- 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 *)) @@ -162,14 +163,28 @@ #endif 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(hythread_t thr); +//VMEXPORT VM_thread *get_vm_thread_self(); + +inline VM_thread *get_vm_thread_fast_self() { + register hythread_t thr = hythread_fast_self(); + + return (VM_thread *)hythread_tls_fast_get(thr, TM_THREAD_VM_TLS_KEY); +} + +inline VM_thread *get_vm_thread(hythread_t thr) { + if (thr == NULL) { + return NULL; + } + return (VM_thread *)hythread_tls_fast_get(thr, TM_THREAD_VM_TLS_KEY); +} 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_vm_thread_fast_self()) Registers *thread_gc_get_context(VM_thread *, VmRegisterContext &); void thread_gc_set_context(VM_thread *); diff --git a/vm/vmcore/src/exception/exceptions.cpp b/vm/vmcore/src/exception/exceptions.cpp old mode 100644 new mode 100755 index 03bbd0c..ee0756f --- a/vm/vmcore/src/exception/exceptions.cpp +++ b/vm/vmcore/src/exception/exceptions.cpp @@ -331,7 +331,7 @@ static void check_pop_frame(ManagedObjec void exn_rethrow() { // exception is throwing, so suspend can be disabeled without following enabling - if (hythread_is_suspend_enabled()) { + if (hythread_fast_is_suspend_enabled()) { tmn_suspend_disable(); } diff --git a/vm/vmcore/src/exception/exceptions_impl.cpp b/vm/vmcore/src/exception/exceptions_impl.cpp old mode 100644 new mode 100755 index 4de044b..f8b6734 --- a/vm/vmcore/src/exception/exceptions_impl.cpp +++ b/vm/vmcore/src/exception/exceptions_impl.cpp @@ -229,7 +229,7 @@ jthrowable create_exception(Class* exc_c ASSERT_RAISE_AREA; assert(hythread_is_suspend_enabled()); - bool suspended_enabled = hythread_is_suspend_enabled(); + bool suspended_enabled = hythread_fast_is_suspend_enabled(); if (suspended_enabled) { tmn_suspend_disable(); @@ -300,7 +300,7 @@ jthrowable create_exception(Exception* e void exn_throw_object_internal(jthrowable exc_object) { // functions can be invoked in suspend disabled and enabled state - if (hythread_is_suspend_enabled()) { + if (hythread_fast_is_suspend_enabled()) { tmn_suspend_disable(); } assert(!hythread_is_suspend_enabled()); @@ -312,7 +312,7 @@ void exn_throw_by_class_internal(Class* jthrowable exc_cause) { // functions can be invoked in suspend disabled and enabled state - if (!hythread_is_suspend_enabled()) { + if (!hythread_fast_is_suspend_enabled()) { // exception is throwing, so suspend can be enabled safely tmn_suspend_enable(); } @@ -353,7 +353,7 @@ void exn_throw_by_name_internal(const ch jthrowable exc_cause) { // functions can be invoked in suspend disabled and enabled state - if (!hythread_is_suspend_enabled()) { + if (!hythread_fast_is_suspend_enabled()) { // exception is throwing, so suspend can be enabled safely tmn_suspend_enable(); } diff --git a/vm/vmcore/src/init/vm_init.cpp b/vm/vmcore/src/init/vm_init.cpp old mode 100644 new mode 100755 index 36d7581..f8071ee --- a/vm/vmcore/src/init/vm_init.cpp +++ b/vm/vmcore/src/init/vm_init.cpp @@ -444,10 +444,10 @@ static jint initialize_system_class_load if (! scl) return JNI_ERR; - hythread_suspend_disable(); + hythread_fast_suspend_disable(); vm_env->system_class_loader = (UserDefinedClassLoader *) ClassLoader::LookupLoader(((ObjectHandle)scl)->object); - hythread_suspend_enable(); + hythread_fast_suspend_enable(); return JNI_OK; } @@ -516,9 +516,9 @@ static jint vm_create_jthread(jthread * if (exn_raised()) { TRACE("Failed to initialize class for java/lang/Thread class = " << exn_get_name()); - hythread_suspend_enable(); + hythread_fast_suspend_enable(); exn_print_stack_trace(stderr, exn_get()); - hythread_suspend_disable(); + hythread_fast_suspend_disable(); return JNI_ERR; } @@ -551,7 +551,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); @@ -560,9 +560,9 @@ static jint vm_create_jthread(jthread * vm_execute_java_method_array((jmethodID) constructor, 0, args); if (exn_raised()) { TRACE("Failed to initialize new thread object, exception = " << exn_get_name()); - hythread_suspend_enable(); + hythread_fast_suspend_enable(); exn_print_stack_trace(stderr, exn_get()); - hythread_suspend_disable(); + hythread_fast_suspend_disable(); return JNI_ERR; } return JNI_OK; @@ -584,7 +584,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); @@ -597,10 +597,10 @@ jint vm_attach_internal(JNIEnv ** p_jni_ *p_jni_env = jni_env; - hythread_suspend_disable(); + hythread_fast_suspend_disable(); // Global reference will be created for new thread object. status = vm_create_jthread(java_thread, jni_env, group, name, daemon); - hythread_suspend_enable(); + hythread_fast_suspend_enable(); return status; } @@ -717,7 +717,7 @@ int vm_init1(JavaVM_Internal * java_vm, populate_jni_nio(); // Now the thread is attached to VM and it is valid to disable it. - hythread_suspend_disable(); + hythread_fast_suspend_disable(); // Create java.lang.Object. vm_env->java_lang_Object = oh_allocate_global_handle(); @@ -744,7 +744,7 @@ int vm_init1(JavaVM_Internal * java_vm, // Precompile InternalError. class_alloc_new_object_and_run_default_constructor(vm_env->java_lang_InternalError_Class); - hythread_suspend_enable(); + hythread_fast_suspend_enable(); // Mark j.l.Throwable() constructor as a side effects free. Method * m = vm_env->java_lang_Throwable_Class->lookup_method( @@ -800,7 +800,7 @@ jint vm_init2(JNIEnv * jni_env) { jvalue args[1]; args[0].l = jlo; - hythread_suspend_disable(); + hythread_fast_suspend_disable(); vm_execute_java_method_array(java_lang_class_init, 0, args); assert(!exn_raised()); @@ -808,7 +808,7 @@ jint vm_init2(JNIEnv * jni_env) { void unsafe_global_object_handles_init(JNIEnv *); unsafe_global_object_handles_init(jni_env); - hythread_suspend_enable(); + hythread_fast_suspend_enable(); if (get_boolean_property("vm.finalize", TRUE, VM_PROPERTIES)) { // Load and initialize finalizer thread. 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/compile.cpp b/vm/vmcore/src/jit/compile.cpp old mode 100644 new mode 100755 index 53aa123..8d4c953 --- a/vm/vmcore/src/jit/compile.cpp +++ b/vm/vmcore/src/jit/compile.cpp @@ -327,7 +327,7 @@ #endif cs = lil_parse_onto_end(cs, "out platform::void;" "call %0i;", - hythread_suspend_enable); + hythread_fast_suspend_enable); assert(cs); //***** Part 5: Set up arguments @@ -410,7 +410,7 @@ #endif cs = lil_parse_onto_end(cs, "out platform::void;" "call %0i;", - hythread_suspend_disable); + hythread_fast_suspend_disable); assert(cs); // Exception offsets diff --git a/vm/vmcore/src/jit/jit_runtime_support.cpp b/vm/vmcore/src/jit/jit_runtime_support.cpp old mode 100644 new mode 100755 index be793ba..698ced0 --- a/vm/vmcore/src/jit/jit_runtime_support.cpp +++ b/vm/vmcore/src/jit/jit_runtime_support.cpp @@ -165,14 +165,14 @@ static ManagedObject * rth_ldc_ref_helpe else if (cp.is_class(cp_index)) { assert(!hythread_is_suspend_enabled()); - hythread_suspend_enable(); + hythread_fast_suspend_enable(); Class *objClass = NULL; BEGIN_RAISE_AREA; objClass = c->_resolve_class(VM_Global_State::loader_env, cp_index); END_RAISE_AREA; - hythread_suspend_disable(); + hythread_fast_suspend_disable(); if (objClass) { return struct_Class_to_java_lang_Class(objClass); } @@ -1610,7 +1610,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, @@ -1624,7 +1624,7 @@ static void * rth_resolve(Class_Handle k Compile_Handle ch = (Compile_Handle)&comp_handle; void * ret = NULL; - hythread_suspend_enable(); + hythread_fast_suspend_enable(); switch(opcode) { case OPCODE_INVOKEINTERFACE: ret = resolve_interface_method(ch, klass, cp_idx); @@ -1658,7 +1658,7 @@ static void * rth_resolve(Class_Handle k opcode == OPCODE_PUTSTATIC); if (ret != NULL) { Class_Handle that_class = method_get_class((Method_Handle)ret); - hythread_suspend_disable(); + hythread_fast_suspend_disable(); if (class_needs_initialization(that_class)) { assert(!exn_raised()); vm_rt_class_initialize(that_class); @@ -1670,7 +1670,7 @@ static void * rth_resolve(Class_Handle k ret = resolve_static_method(ch, klass, cp_idx); if (ret != NULL) { Class_Handle that_class = method_get_class((Method_Handle)ret); - hythread_suspend_disable(); + hythread_fast_suspend_disable(); if (class_needs_initialization(that_class)) { assert(!exn_raised()); vm_rt_class_initialize(that_class); @@ -1681,7 +1681,7 @@ static void * rth_resolve(Class_Handle k default: assert(false); } // ~switch(opcode) - hythread_suspend_disable(); + hythread_fast_suspend_disable(); if (ret == NULL) { vm_rt_class_throw_linking_error(klass, cp_idx, opcode); assert(false); // must be unreachable @@ -2831,8 +2831,8 @@ VMEXPORT void * vm_create_helper_for_fun "call.noret %6i;"; // re-throw exception void * fptr_rethrow = (void*)&exn_rethrow; - void * fptr_suspend_enable = (void*)&hythread_suspend_enable; - void * fptr_suspend_disable = (void*)&hythread_suspend_disable; + void * fptr_suspend_enable = (void*)&hythread_fast_suspend_enable; + void * fptr_suspend_disable = (void*)&hythread_fast_suspend_disable; LilCodeStub* cs = lil_parse_code_stub( lil_stub, (FRAME_COMPILATION | FRAME_POPABLE), diff --git a/vm/vmcore/src/jni/jni.cpp b/vm/vmcore/src/jni/jni.cpp old mode 100644 new mode 100755 index f1d5d18..5b241a4 --- a/vm/vmcore/src/jni/jni.cpp +++ b/vm/vmcore/src/jni/jni.cpp @@ -780,13 +780,13 @@ jthrowable JNICALL ExceptionOccurred(JNI result = exn_get(); #ifdef _DEBUG - hythread_suspend_disable(); + hythread_fast_suspend_disable(); if (result) { TRACE2("jni", "Exception occured, class = " << exn_get_name()); } else { TRACE2("jni", "Exception occured, no exception"); } - hythread_suspend_enable(); + hythread_fast_suspend_enable(); #endif return result; @@ -839,7 +839,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/jni/jni_utils.cpp b/vm/vmcore/src/jni/jni_utils.cpp old mode 100644 new mode 100755 index 128f7f5..a3680c9 --- a/vm/vmcore/src/jni/jni_utils.cpp +++ b/vm/vmcore/src/jni/jni_utils.cpp @@ -58,15 +58,15 @@ jclass jni_class_from_handle(JNIEnv* UNR jobject jni_class_loader_from_handle(JNIEnv*, ClassLoaderHandle clh) { if (!clh) return NULL; - hythread_suspend_disable(); + hythread_fast_suspend_disable(); ManagedObject* obj = clh->GetLoader(); if( !obj ) { - hythread_suspend_enable(); + hythread_fast_suspend_enable(); return NULL; } ObjectHandle res = oh_allocate_local_handle(); res->object = obj; - hythread_suspend_enable(); + hythread_fast_suspend_enable(); return (jobject)res; } @@ -76,9 +76,9 @@ ClassLoaderHandle class_loader_lookup(jo ObjectHandle h = (ObjectHandle)loader; - hythread_suspend_disable(); //---------------------------------v + hythread_fast_suspend_disable(); //---------------------------------v ClassLoader* cl = ClassLoader::LookupLoader(h->object); - hythread_suspend_enable(); //---------------------------------^ + hythread_fast_suspend_enable(); //---------------------------------^ return cl; } //class_loader_lookup @@ -581,11 +581,11 @@ jboolean IsNullRef(jobject jobj) ObjectHandle h = (ObjectHandle)jobj; - hythread_suspend_disable(); //---------------------------------v + hythread_fast_suspend_disable(); //---------------------------------v jboolean ret = (h->object == NULL) ? true : false; - hythread_suspend_enable(); //---------------------------------^ + hythread_fast_suspend_enable(); //---------------------------------^ return ret; } @@ -632,13 +632,13 @@ void throw_exception_from_jni(JNIEnv *je void array_copy_jni(JNIEnv* jenv, jobject src, jint src_off, jobject dst, jint dst_off, jint count) { ArrayCopyResult res; - hythread_suspend_disable(); + hythread_fast_suspend_disable(); if (src && dst) { res = array_copy(((ObjectHandle)src)->object, src_off, ((ObjectHandle)dst)->object, dst_off, count); } else { res = ACR_NullPointer; } - hythread_suspend_enable(); + hythread_fast_suspend_enable(); jclass tclass = NULL; switch (res) { case ACR_Okay: @@ -743,9 +743,9 @@ jobject CreateNewThrowable(JNIEnv* jenv, jvalue res; assert(hythread_is_suspend_enabled()); - hythread_suspend_disable(); + hythread_fast_suspend_disable(); vm_execute_java_method_array((jmethodID) initCause, &res, initArgs); - hythread_suspend_enable(); + hythread_fast_suspend_enable(); } return obj; @@ -753,16 +753,16 @@ jobject CreateNewThrowable(JNIEnv* jenv, jobject create_default_instance(Class* clss) { - hythread_suspend_disable(); + hythread_fast_suspend_disable(); jobject h = oh_allocate_local_handle(); ManagedObject *new_obj = class_alloc_new_object_and_run_default_constructor(clss); if (new_obj == NULL) { - hythread_suspend_enable(); + hythread_fast_suspend_enable(); assert(exn_raised()); return NULL; } h->object = new_obj; - hythread_suspend_enable(); + hythread_fast_suspend_enable(); return h; } diff --git a/vm/vmcore/src/jvmti/jvmti.cpp b/vm/vmcore/src/jvmti/jvmti.cpp old mode 100644 new mode 100755 index 329d994..3c8d72a --- a/vm/vmcore/src/jvmti/jvmti.cpp +++ b/vm/vmcore/src/jvmti/jvmti.cpp @@ -712,16 +712,16 @@ 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_fast_self(), this->TL_ti_enabled) == NULL; } void DebugUtilsTI::setLocallyEnabled() { //default value is that ti enabled on thread level - hythread_tls_set(hythread_self(), this->TL_ti_enabled, NULL); + hythread_tls_set(hythread_fast_self(), this->TL_ti_enabled, NULL); } void DebugUtilsTI::setLocallyDisabled() { - hythread_tls_set(hythread_self(), this->TL_ti_enabled, this); + hythread_tls_set(hythread_fast_self(), this->TL_ti_enabled, this); } bool DebugUtilsTI::isEnabled() { diff --git a/vm/vmcore/src/jvmti/jvmti_break.cpp b/vm/vmcore/src/jvmti/jvmti_break.cpp old mode 100644 new mode 100755 index 1297579..0e3ab67 --- a/vm/vmcore/src/jvmti/jvmti_break.cpp +++ b/vm/vmcore/src/jvmti/jvmti_break.cpp @@ -59,7 +59,7 @@ bool jvmti_process_breakpoint_event(TIEn jmethodID method = bp->method; NativeCodePtr addr = bp->addr; - hythread_t h_thread = hythread_self(); + hythread_t h_thread = hythread_fast_self(); jthread j_thread = jthread_get_java_thread(h_thread); ObjectHandle hThread = oh_allocate_local_handle(); hThread->object = (Java_java_lang_Thread *)j_thread->object; @@ -98,7 +98,7 @@ bool jvmti_process_breakpoint_event(TIEn { next_et = et->next; - if (et->thread == hythread_self()) + if (et->thread == hythread_fast_self()) { TRACE2("jvmti.break", "Calling local breakpoint callback: " << class_get_name(method_get_class((Method*)method)) << "." diff --git a/vm/vmcore/src/jvmti/jvmti_event.cpp b/vm/vmcore/src/jvmti/jvmti_event.cpp old mode 100644 new mode 100755 index ff668b1..989e452 --- a/vm/vmcore/src/jvmti/jvmti_event.cpp +++ b/vm/vmcore/src/jvmti/jvmti_event.cpp @@ -641,7 +641,7 @@ jvmti_process_method_entry_event(jmethod tmn_suspend_enable(); jvmtiEvent event_type = JVMTI_EVENT_METHOD_ENTRY; - hythread_t curr_thread = hythread_self(); + hythread_t curr_thread = hythread_fast_self(); TIEnv *ti_env = ti->getEnvironments(); TIEnv *next_env; @@ -687,7 +687,7 @@ jvmti_process_method_exit_event_internal DebugUtilsTI *ti = VM_Global_State::loader_env->TI; tmn_suspend_enable(); jvmtiEvent event_type = JVMTI_EVENT_METHOD_EXIT; - hythread_t curr_native_thread = hythread_self(); + hythread_t curr_native_thread = hythread_fast_self(); TIEnv *ti_env = ti->getEnvironments(); TIEnv *next_env; @@ -889,7 +889,7 @@ jvmti_process_native_method_bind_event(j phase != JVMTI_PHASE_PRIMORDIAL) return; - hythread_t thread = hythread_self(); + hythread_t thread = hythread_fast_self(); jthread j_thread = jthread_get_java_thread(thread); JNIEnv *jni_env = p_TLS_vmthread->jni_env; @@ -953,7 +953,7 @@ jvmti_process_single_step_event(jmethodI return; jvmtiEvent event_type = JVMTI_EVENT_SINGLE_STEP; - hythread_t curr_thread = hythread_self(); + hythread_t curr_thread = hythread_fast_self(); TIEnv *ti_env = ti->getEnvironments(); TIEnv *next_env; @@ -1033,7 +1033,7 @@ VMEXPORT void jvmti_process_field_access jclass field_klass = struct_Class_to_java_lang_Class_Handle(field->get_class()); jvmtiEvent event_type = JVMTI_EVENT_FIELD_ACCESS; - hythread_t curr_thread = hythread_self(); + hythread_t curr_thread = hythread_fast_self(); TIEnv *ti_env = ti->getEnvironments(); TIEnv *next_env; while (NULL != ti_env) @@ -1108,7 +1108,7 @@ VMEXPORT void jvmti_process_field_modifi char signature_type = (char) field->get_java_type(); jvmtiEvent event_type = JVMTI_EVENT_FIELD_MODIFICATION; - hythread_t curr_thread = hythread_self(); + hythread_t curr_thread = hythread_fast_self(); TIEnv *ti_env = ti->getEnvironments(); TIEnv *next_env; while (NULL != ti_env) @@ -1159,7 +1159,7 @@ static void jvmti_process_vm_object_allo return; // check the j.l.Thread is already initialized - hythread_t curr_thread = hythread_self(); + hythread_t curr_thread = hythread_fast_self(); jthread thread = jthread_get_java_thread(curr_thread); if (NULL == thread) return; @@ -1241,7 +1241,7 @@ void jvmti_send_exception_event(jthrowab assert(!hythread_is_suspend_enabled()); VM_thread *curr_thread = p_TLS_vmthread; - hythread_t curr_native_thread=hythread_self(); + hythread_t curr_native_thread=hythread_fast_self(); curr_thread->ti_exception_callback_pending = false; DebugUtilsTI *ti = VM_Global_State::loader_env->TI; @@ -1415,7 +1415,7 @@ ManagedObject *jvmti_exception_catch_eve DebugUtilsTI *ti = VM_Global_State::loader_env->TI; assert(ti->isEnabled()); - hythread_t curr_thread = hythread_self(); + hythread_t curr_thread = hythread_fast_self(); // Create local handles frame JNIEnv *jni_env = p_TLS_vmthread->jni_env; @@ -1625,7 +1625,7 @@ void jvmti_send_class_load_event(const G // fire local events for( TIEventThread* ti_et = ti_env->event_threads[JVMTI_EVENT_CLASS_LOAD - JVMTI_MIN_EVENT_TYPE_VAL]; ti_et != NULL; ti_et = ti_et->next ) - if (ti_et->thread == hythread_self()) + if (ti_et->thread == hythread_fast_self()) { TRACE2("jvmti.class.cl", "Class load event, class name = " << clss->get_name()->bytes); tmn_suspend_disable(); @@ -1696,7 +1696,7 @@ void jvmti_send_class_file_load_hook_eve // fire local events for( TIEventThread* ti_et = ti_env->event_threads[JVMTI_EVENT_CLASS_FILE_LOAD_HOOK - JVMTI_MIN_EVENT_TYPE_VAL]; ti_et != NULL; ti_et = ti_et->next ) - if (ti_et->thread == hythread_self()) + if (ti_et->thread == hythread_fast_self()) { // free memory from previous redefinition if( last_redef && last_redef != input_class ) { @@ -1768,7 +1768,7 @@ void jvmti_send_class_prepare_event(Clas // fire local events for(TIEventThread* ti_et = ti_env->event_threads[JVMTI_EVENT_CLASS_PREPARE - JVMTI_MIN_EVENT_TYPE_VAL]; ti_et != NULL; ti_et = ti_et->next ) - if (ti_et->thread == hythread_self()) + if (ti_et->thread == hythread_fast_self()) { TRACE2("jvmti.class.cp", "Class prepare event, class name = " << clss->get_name()->bytes); tmn_suspend_disable(); // -------------------------------vv @@ -1829,7 +1829,7 @@ static void call_callback(jvmtiEvent eve static int is_interested_thread(TIEnv *ti_env, jvmtiEvent event_type) { for( TIEventThread* ti_et = ti_env->event_threads[event_type - JVMTI_MIN_EVENT_TYPE_VAL]; ti_et != NULL; ti_et = ti_et->next) { - if (ti_et->thread == hythread_self()) return 1; + if (ti_et->thread == hythread_fast_self()) return 1; } return 0; @@ -2079,7 +2079,7 @@ jvmti_process_data_dump_request() if( ti->getPhase() != JVMTI_PHASE_LIVE ) { return; } - hythread_t thread = hythread_self(); + hythread_t thread = hythread_fast_self(); TIEnv* next_env; for (TIEnv* env = ti->getEnvironments(); env; env = next_env) { diff --git a/vm/vmcore/src/jvmti/jvmti_heap.cpp b/vm/vmcore/src/jvmti/jvmti_heap.cpp old mode 100644 new mode 100755 index 04dab98..ab3c107 --- a/vm/vmcore/src/jvmti/jvmti_heap.cpp +++ b/vm/vmcore/src/jvmti/jvmti_heap.cpp @@ -173,9 +173,9 @@ jvmtiForceGarbageCollection(jvmtiEnv* en // for more details, see // * "SAFE SUSPENSION" section of Developers' Guide // * "THREAD SUSPENSION" section of Thread Manager documentation - hythread_suspend_disable(); + hythread_fast_suspend_disable(); gc_force_gc(); - hythread_suspend_enable(); + hythread_fast_suspend_enable(); return JVMTI_ERROR_NONE; } @@ -268,7 +268,7 @@ jvmtiIterateOverObjectsReachableFromObje return r; } - hythread_suspend_disable(); // to keep assertions happy + hythread_fast_suspend_disable(); // to keep assertions happy hythread_iterator_t iterator; hythread_suspend_all(&iterator, NULL); @@ -284,7 +284,7 @@ jvmtiIterateOverObjectsReachableFromObje TRACE2("ti.iterate", "iteration complete"); hythread_resume_all(NULL); - hythread_suspend_enable(); + hythread_fast_suspend_enable(); hythread_global_unlock(); return JVMTI_ERROR_NONE; @@ -344,7 +344,7 @@ jvmtiIterateOverReachableObjects(jvmtiEn return r; } - hythread_suspend_disable(); // to keep assertions happy + hythread_fast_suspend_disable(); // to keep assertions happy hythread_iterator_t iterator; hythread_suspend_all(&iterator, NULL); @@ -361,7 +361,7 @@ jvmtiIterateOverReachableObjects(jvmtiEn TRACE2("ti.iterate", "iteration complete"); hythread_resume_all(NULL); - hythread_suspend_enable(); + hythread_fast_suspend_enable(); hythread_global_unlock(); return JVMTI_ERROR_NONE; @@ -463,7 +463,7 @@ jvmtiIterateOverHeap(jvmtiEnv* env, memset(state, 0, sizeof(TIIterationState)); - hythread_suspend_disable(); // to keep assertions happy + hythread_fast_suspend_disable(); // to keep assertions happy hythread_iterator_t iterator; hythread_suspend_all(&iterator, NULL); TRACE2("ti.iterate", "suspended all threads"); @@ -487,7 +487,7 @@ jvmtiIterateOverHeap(jvmtiEnv* env, TRACE2("ti.iterate", "iteration complete"); hythread_resume_all(NULL); - hythread_suspend_enable(); + hythread_fast_suspend_enable(); hythread_global_unlock(); return JVMTI_ERROR_NONE; @@ -551,7 +551,7 @@ jvmtiIterateOverInstancesOfClass(jvmtiEn memset(state, 0, sizeof(TIIterationState)); - hythread_suspend_disable(); // to keep assertions happy + hythread_fast_suspend_disable(); // to keep assertions happy hythread_iterator_t iterator; hythread_suspend_all(&iterator, NULL); TRACE2("ti.iterate", "suspended all threads"); @@ -575,7 +575,7 @@ jvmtiIterateOverInstancesOfClass(jvmtiEn TRACE2("ti.iterate", "iteration complete"); hythread_resume_all(NULL); - hythread_suspend_enable(); + hythread_fast_suspend_enable(); hythread_global_unlock(); return JVMTI_ERROR_NONE; @@ -627,7 +627,7 @@ jvmtiGetObjectsWithTags(jvmtiEnv* env, tag_set.insert(tags[i]); } - hythread_suspend_disable(); // ---------------vv + hythread_fast_suspend_disable(); // ---------------vv ti_env->tags->get_objects_with_tags(tag_set, objects); int count = objects.size(); @@ -677,7 +677,7 @@ jvmtiGetObjectsWithTags(jvmtiEnv* env, } } - hythread_suspend_enable(); // ---------------^^ + hythread_fast_suspend_enable(); // ---------------^^ return error; } diff --git a/vm/vmcore/src/jvmti/jvmti_heap.h b/vm/vmcore/src/jvmti/jvmti_heap.h old mode 100644 new mode 100755 index 7ccfc67..73cfd87 --- a/vm/vmcore/src/jvmti/jvmti_heap.h +++ b/vm/vmcore/src/jvmti/jvmti_heap.h @@ -125,9 +125,9 @@ inline bool is_object_valid(Managed_Obje inline bool is_jobject_valid(jobject jobj) { if (jobj == NULL) return false; - hythread_suspend_disable(); + hythread_fast_suspend_disable(); bool r = is_object_valid(jobj->object); - hythread_suspend_enable(); + hythread_fast_suspend_enable(); return r; } @@ -137,14 +137,14 @@ inline bool is_jobject_valid(jobject job inline bool is_jclass_valid(jclass jobj) { if (jobj == NULL) return false; - hythread_suspend_disable(); + hythread_fast_suspend_disable(); bool r = false; if (is_object_valid(jobj->object)) { Class* cls = ((ManagedObject*)jobj->object)->vt()->clss; r = class_is_instanceof(cls, VM_Global_State::loader_env->JavaLangClass_Class); } - hythread_suspend_enable(); + hythread_fast_suspend_enable(); return r; } diff --git a/vm/vmcore/src/jvmti/jvmti_pop_frame.cpp b/vm/vmcore/src/jvmti/jvmti_pop_frame.cpp old mode 100644 new mode 100755 index 6d5a612..94a85ce --- a/vm/vmcore/src/jvmti/jvmti_pop_frame.cpp +++ b/vm/vmcore/src/jvmti/jvmti_pop_frame.cpp @@ -54,7 +54,7 @@ static void jvmti_pop_frame_callback() } else if (is_unwindable()) { // unwindable frame, wait for resume TRACE(("PopFrame callback is entering safe_point")); - hythread_safe_point(); + hythread_fast_safe_point(); TRACE(("PopFrame callback is FRAME_SAFE_POINT")); // switch execution to the previous frame @@ -398,7 +398,7 @@ void jvmti_safe_point() set_pop_frame_registers(top_frame, ®s); TRACE(("entering safe_point")); - hythread_safe_point(); + hythread_fast_safe_point(); TRACE(("left safe_point")); // find frame type diff --git a/vm/vmcore/src/jvmti/jvmti_step.cpp b/vm/vmcore/src/jvmti/jvmti_step.cpp old mode 100644 new mode 100755 index 5e27b7f..6ccbd36 --- a/vm/vmcore/src/jvmti/jvmti_step.cpp +++ b/vm/vmcore/src/jvmti/jvmti_step.cpp @@ -587,7 +587,7 @@ static bool jvmti_process_jit_single_ste return true; } - hythread_t h_thread = hythread_self(); + hythread_t h_thread = hythread_fast_self(); jthread j_thread = jthread_get_java_thread(h_thread); ObjectHandle hThread = oh_allocate_local_handle(); hThread->object = (Java_java_lang_Thread *)j_thread->object; @@ -637,7 +637,7 @@ static bool jvmti_process_jit_single_ste { next_et = et->next; - if (et->thread == hythread_self()) + if (et->thread == hythread_fast_self()) { TRACE2("jvmti.break.ss", "Calling JIT local SingleStep breakpoint callback: " diff --git a/vm/vmcore/src/object/object_handles.cpp b/vm/vmcore/src/object/object_handles.cpp old mode 100644 new mode 100755 index 462e71b..383caee --- a/vm/vmcore/src/object/object_handles.cpp +++ b/vm/vmcore/src/object/object_handles.cpp @@ -214,7 +214,7 @@ ObjectHandle oh_allocate_global_handle() h->handle.object = NULL; h->allocated_on_the_stack = false; - hythread_suspend_disable(); // ----------------vvv + hythread_fast_suspend_disable(); // ----------------vvv vm_env->p_handle_lock->_lock(); // Insert at beginning of globals list h->prev = NULL; @@ -223,7 +223,7 @@ ObjectHandle oh_allocate_global_handle() if(h->next) h->next->prev = h; vm_env->p_handle_lock->_unlock(); - hythread_suspend_enable(); //--------------------------------------------^^^ + hythread_fast_suspend_enable(); //--------------------------------------------^^^ return &h->handle; } //vm_create_global_object_handle 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_generic.cpp b/vm/vmcore/src/thread/thread_generic.cpp old mode 100644 new mode 100755 index 99a9c4f..2cd5f1d --- a/vm/vmcore/src/thread/thread_generic.cpp +++ b/vm/vmcore/src/thread/thread_generic.cpp @@ -126,9 +126,9 @@ static IDATA run_java_detach(jthread jav } exn_clear(); - hythread_suspend_disable(); + hythread_fast_suspend_disable(); vm_execute_java_method_array((jmethodID) detach, 0, args); - hythread_suspend_enable(); + hythread_fast_suspend_enable(); if (exn_raised()) { TRACE("java.lang.Thread.detach(Throwable) method completed with an exception: " << exn_get_name()); @@ -225,7 +225,7 @@ jint vm_detach(jthread java_thread) { // Destroy current VM_thread structure. apr_pool_destroy(p_vm_thread->pool); - hythread_suspend_enable(); + hythread_fast_suspend_enable(); return JNI_OK; diff --git a/vm/vmcore/src/thread/thread_manager.cpp b/vm/vmcore/src/thread/thread_manager.cpp old mode 100644 new mode 100755 index e62b367..0ef960a --- a/vm/vmcore/src/thread/thread_manager.cpp +++ b/vm/vmcore/src/thread/thread_manager.cpp @@ -91,7 +91,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) { @@ -108,13 +108,6 @@ 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) { @@ -127,21 +120,17 @@ VM_thread *get_vm_thread_ptr_safe(JNIEnv VM_thread *get_thread_ptr_stub() { - return get_vm_thread(hythread_self()); + return get_vm_thread(hythread_fast_self()); } vm_thread_accessor* get_thread_ptr = get_thread_ptr_stub; void init_TLS_data() { - hythread_tls_alloc(&TLS_key_pvmthread); -#ifndef _EM64T_ - get_thread_ptr = (vm_thread_accessor*) get_tls_helper(TLS_key_pvmthread); - //printf ("init fast call %p\n", get_thread_ptr); -#endif - + //printf ("init TLS data, TLS key = %x \n", TLS_key_pvmthread); + TLS_key_pvmthread = TM_THREAD_VM_TLS_KEY; } 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())); } @@ -188,7 +177,7 @@ void* vm_jthread_get_tm_data(jthread thr Byte * java_ref; POINTER_SIZE_INT val; - hythread_suspend_disable(); + hythread_fast_suspend_disable(); thread_obj = ((ObjectHandle)thread)->object; if (offset == -1) { @@ -199,7 +188,7 @@ void* vm_jthread_get_tm_data(jthread thr java_ref = (Byte *)thread_obj; val = *(POINTER_SIZE_INT *)(java_ref + offset); - hythread_suspend_enable(); + hythread_fast_suspend_enable(); return (void *)val; } @@ -211,7 +200,7 @@ void vm_jthread_set_tm_data(jthread thre ManagedObject * thread_obj; Byte * java_ref; - hythread_suspend_disable(); + hythread_fast_suspend_disable(); thread_obj = ((ObjectHandle)thread)->object; if (offset == -1) { @@ -223,7 +212,7 @@ void vm_jthread_set_tm_data(jthread thre java_ref = (Byte *)thread_obj; *(jlong *)(java_ref + offset) = (jlong)(POINTER_SIZE_INT)val; - hythread_suspend_enable(); + hythread_fast_suspend_enable(); } int vm_objects_are_equal(jobject obj1, jobject obj2){ diff --git a/vm/vmcore/src/util/linux/signals_em64t.cpp b/vm/vmcore/src/util/linux/signals_em64t.cpp old mode 100644 new mode 100755 index cb9c9c0..81cae1f --- a/vm/vmcore/src/util/linux/signals_em64t.cpp +++ b/vm/vmcore/src/util/linux/signals_em64t.cpp @@ -360,7 +360,7 @@ void stack_overflow_handler(int signum, return; } else { if (is_unwindable()) { - if (hythread_is_suspend_enabled()) { + if (hythread_fast_is_suspend_enabled()) { tmn_suspend_disable(); } throw_from_sigcontext( diff --git a/vm/vmcore/src/util/linux/signals_ia32.cpp b/vm/vmcore/src/util/linux/signals_ia32.cpp old mode 100644 new mode 100755 index c3aee82..123eb54 --- a/vm/vmcore/src/util/linux/signals_ia32.cpp +++ b/vm/vmcore/src/util/linux/signals_ia32.cpp @@ -456,7 +456,7 @@ void stack_overflow_handler(int signum, return; } else { if (is_unwindable()) { - if (hythread_is_suspend_enabled()) { + if (hythread_fast_is_suspend_enabled()) { tmn_suspend_disable(); } throw_from_sigcontext( diff --git a/vm/vmcore/src/util/win/ia32/nt_exception_filter.cpp b/vm/vmcore/src/util/win/ia32/nt_exception_filter.cpp old mode 100644 new mode 100755 index eab4b5d..091b775 --- a/vm/vmcore/src/util/win/ia32/nt_exception_filter.cpp +++ b/vm/vmcore/src/util/win/ia32/nt_exception_filter.cpp @@ -367,8 +367,8 @@ static LONG NTAPI vectored_exception_han // stack overflow occured in native code that can be unwound // safely. // Throwing exception requires suspend disabled status - if (hythread_is_suspend_enabled()) - hythread_suspend_disable(); + if (hythread_fast_is_suspend_enabled()) + hythread_fast_suspend_disable(); } else { // stack overflow occured in native code that // cannot be unwound. -- 1.4.2