20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_RUNTIME_THREAD_INLINE_HPP 26 #define SHARE_RUNTIME_THREAD_INLINE_HPP 27 28 #include "runtime/atomic.hpp" 29 #include "runtime/globals.hpp" 30 #include "runtime/orderAccess.hpp" 31 #include "runtime/os.inline.hpp" 32 #include "runtime/safepoint.hpp" 33 #include "runtime/thread.hpp" 34 35 inline void Thread::set_suspend_flag(SuspendFlags f) { 36 uint32_t flags; 37 do { 38 flags = _suspend_flags; 39 } 40 while (Atomic::cmpxchg((flags | f), &_suspend_flags, flags) != flags); 41 } 42 inline void Thread::clear_suspend_flag(SuspendFlags f) { 43 uint32_t flags; 44 do { 45 flags = _suspend_flags; 46 } 47 while (Atomic::cmpxchg((flags & ~f), &_suspend_flags, flags) != flags); 48 } 49 50 inline void Thread::set_has_async_exception() { 51 set_suspend_flag(_has_async_exception); 52 } 53 inline void Thread::clear_has_async_exception() { 54 clear_suspend_flag(_has_async_exception); 55 } 56 inline void Thread::set_critical_native_unlock() { 57 set_suspend_flag(_critical_native_unlock); 58 } 59 inline void Thread::clear_critical_native_unlock() { 60 clear_suspend_flag(_critical_native_unlock); 61 } 62 inline void Thread::set_trace_flag() { 63 set_suspend_flag(_trace_flag); 64 } 65 inline void Thread::clear_trace_flag() { 66 clear_suspend_flag(_trace_flag); 67 } 68 69 inline jlong Thread::cooked_allocated_bytes() { 70 jlong allocated_bytes = Atomic::load_acquire(&_allocated_bytes); 71 if (UseTLAB) { 72 size_t used_bytes = tlab().used_bytes(); 73 if (used_bytes <= ThreadLocalAllocBuffer::max_size_in_bytes()) { 74 // Comparing used_bytes with the maximum allowed size will ensure 75 // that we don't add the used bytes from a semi-initialized TLAB 76 // ending up with incorrect values. There is still a race between 77 // incrementing _allocated_bytes and clearing the TLAB, that might 78 // cause double counting in rare cases. 79 return allocated_bytes + used_bytes; 80 } 81 } 82 return allocated_bytes; 83 } 84 85 inline ThreadsList* Thread::cmpxchg_threads_hazard_ptr(ThreadsList* exchange_value, ThreadsList* compare_value) { 86 return (ThreadsList*)Atomic::cmpxchg(exchange_value, &_threads_hazard_ptr, compare_value); 87 } 88 89 inline ThreadsList* Thread::get_threads_hazard_ptr() { 90 return (ThreadsList*)Atomic::load_acquire(&_threads_hazard_ptr); 91 } 92 93 inline void Thread::set_threads_hazard_ptr(ThreadsList* new_list) { 94 Atomic::release_store_fence(&_threads_hazard_ptr, new_list); 95 } 96 97 inline void JavaThread::set_ext_suspended() { 98 set_suspend_flag (_ext_suspended); 99 } 100 inline void JavaThread::clear_ext_suspended() { 101 clear_suspend_flag(_ext_suspended); 102 } 103 104 inline void JavaThread::set_external_suspend() { 105 set_suspend_flag(_external_suspend); 106 } | 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_RUNTIME_THREAD_INLINE_HPP 26 #define SHARE_RUNTIME_THREAD_INLINE_HPP 27 28 #include "runtime/atomic.hpp" 29 #include "runtime/globals.hpp" 30 #include "runtime/orderAccess.hpp" 31 #include "runtime/os.inline.hpp" 32 #include "runtime/safepoint.hpp" 33 #include "runtime/thread.hpp" 34 35 inline void Thread::set_suspend_flag(SuspendFlags f) { 36 uint32_t flags; 37 do { 38 flags = _suspend_flags; 39 } 40 while (Atomic::cmpxchg(&_suspend_flags, flags, (flags | f)) != flags); 41 } 42 inline void Thread::clear_suspend_flag(SuspendFlags f) { 43 uint32_t flags; 44 do { 45 flags = _suspend_flags; 46 } 47 while (Atomic::cmpxchg(&_suspend_flags, flags, (flags & ~f)) != flags); 48 } 49 50 inline void Thread::set_has_async_exception() { 51 set_suspend_flag(_has_async_exception); 52 } 53 inline void Thread::clear_has_async_exception() { 54 clear_suspend_flag(_has_async_exception); 55 } 56 inline void Thread::set_critical_native_unlock() { 57 set_suspend_flag(_critical_native_unlock); 58 } 59 inline void Thread::clear_critical_native_unlock() { 60 clear_suspend_flag(_critical_native_unlock); 61 } 62 inline void Thread::set_trace_flag() { 63 set_suspend_flag(_trace_flag); 64 } 65 inline void Thread::clear_trace_flag() { 66 clear_suspend_flag(_trace_flag); 67 } 68 69 inline jlong Thread::cooked_allocated_bytes() { 70 jlong allocated_bytes = Atomic::load_acquire(&_allocated_bytes); 71 if (UseTLAB) { 72 size_t used_bytes = tlab().used_bytes(); 73 if (used_bytes <= ThreadLocalAllocBuffer::max_size_in_bytes()) { 74 // Comparing used_bytes with the maximum allowed size will ensure 75 // that we don't add the used bytes from a semi-initialized TLAB 76 // ending up with incorrect values. There is still a race between 77 // incrementing _allocated_bytes and clearing the TLAB, that might 78 // cause double counting in rare cases. 79 return allocated_bytes + used_bytes; 80 } 81 } 82 return allocated_bytes; 83 } 84 85 inline ThreadsList* Thread::cmpxchg_threads_hazard_ptr(ThreadsList* exchange_value, ThreadsList* compare_value) { 86 return (ThreadsList*)Atomic::cmpxchg(&_threads_hazard_ptr, compare_value, exchange_value); 87 } 88 89 inline ThreadsList* Thread::get_threads_hazard_ptr() { 90 return (ThreadsList*)Atomic::load_acquire(&_threads_hazard_ptr); 91 } 92 93 inline void Thread::set_threads_hazard_ptr(ThreadsList* new_list) { 94 Atomic::release_store_fence(&_threads_hazard_ptr, new_list); 95 } 96 97 inline void JavaThread::set_ext_suspended() { 98 set_suspend_flag (_ext_suspended); 99 } 100 inline void JavaThread::clear_ext_suspended() { 101 clear_suspend_flag(_ext_suspended); 102 } 103 104 inline void JavaThread::set_external_suspend() { 105 set_suspend_flag(_external_suspend); 106 } |