291 _ParkEvent = ParkEvent::Allocate(this);
292 _SleepEvent = ParkEvent::Allocate(this);
293 _MutexEvent = ParkEvent::Allocate(this);
294 _MuxEvent = ParkEvent::Allocate(this);
295
296 #ifdef CHECK_UNHANDLED_OOPS
297 if (CheckUnhandledOops) {
298 _unhandled_oops = new UnhandledOops(this);
299 }
300 #endif // CHECK_UNHANDLED_OOPS
301 #ifdef ASSERT
302 if (UseBiasedLocking) {
303 assert((((uintptr_t) this) & (markOopDesc::biased_lock_alignment - 1)) == 0, "forced alignment of thread object failed");
304 assert(this == _real_malloc_address ||
305 this == align_up(_real_malloc_address, (int)markOopDesc::biased_lock_alignment),
306 "bug in forced alignment of thread objects");
307 }
308 #endif // ASSERT
309
310 _oom_during_evac = 0;
311 }
312
313 void Thread::set_oom_during_evac(bool oom) {
314 if (oom) {
315 _oom_during_evac |= 1;
316 } else {
317 _oom_during_evac &= ~1;
318 }
319 }
320
321 bool Thread::is_oom_during_evac() const {
322 return (_oom_during_evac & 1) == 1;
323 }
324
325 #ifdef ASSERT
326 void Thread::set_evac_allowed(bool evac_allowed) {
327 if (evac_allowed) {
328 _oom_during_evac |= 2;
329 } else {
330 _oom_during_evac &= ~2;
2027 tlab().make_parsable(true); // retire TLAB
2028 }
2029
2030 if (JvmtiEnv::environments_might_exist()) {
2031 JvmtiExport::cleanup_thread(this);
2032 }
2033
2034 // We must flush any deferred card marks before removing a thread from
2035 // the list of active threads.
2036 Universe::heap()->flush_deferred_store_barrier(this);
2037 assert(deferred_card_mark().is_empty(), "Should have been flushed");
2038
2039 #if INCLUDE_ALL_GCS
2040 // We must flush the G1-related buffers before removing a thread
2041 // from the list of active threads. We must do this after any deferred
2042 // card marks have been flushed (above) so that any entries that are
2043 // added to the thread's dirty card queue as a result are not lost.
2044 if (UseG1GC || (UseShenandoahGC && (ShenandoahSATBBarrier || ShenandoahKeepAliveBarrier || ShenandoahStoreValEnqueueBarrier))) {
2045 flush_barrier_queues();
2046 }
2047 if (UseShenandoahGC && UseTLAB && gclab().is_initialized()) {
2048 gclab().make_parsable(true);
2049 }
2050 #endif // INCLUDE_ALL_GCS
2051
2052 log_info(os, thread)("JavaThread %s (tid: " UINTX_FORMAT ").",
2053 exit_type == JavaThread::normal_exit ? "exiting" : "detaching",
2054 os::current_thread_id());
2055
2056 if (log_is_enabled(Debug, os, thread, timer)) {
2057 _timer_exit_phase3.stop();
2058 _timer_exit_phase4.start();
2059 }
2060 // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread
2061 Threads::remove(this);
2062
2063 if (log_is_enabled(Debug, os, thread, timer)) {
2064 _timer_exit_phase4.stop();
2065 ResourceMark rm(this);
2066 log_debug(os, thread, timer)("name='%s'"
2067 ", exit-phase1=" JLONG_FORMAT
2068 ", exit-phase2=" JLONG_FORMAT
2088 "we should not be at a safepoint");
2089
2090 SATBMarkQueue& satb_queue = satb_mark_queue();
2091 SATBMarkQueueSet& satb_queue_set = satb_mark_queue_set();
2092 // The SATB queue should have been constructed with its active
2093 // field set to false.
2094 assert(!satb_queue.is_active(), "SATB queue should not be active");
2095 assert(satb_queue.is_empty(), "SATB queue should be empty");
2096 // If we are creating the thread during a marking cycle, we should
2097 // set the active field of the SATB queue to true.
2098 if (satb_queue_set.is_active()) {
2099 satb_queue.set_active(true);
2100 }
2101
2102 DirtyCardQueue& dirty_queue = dirty_card_queue();
2103 // The dirty card queue should have been constructed with its
2104 // active field set to true.
2105 assert(dirty_queue.is_active(), "dirty card queue should be active");
2106
2107 _gc_state = _gc_state_global;
2108 }
2109 #endif // INCLUDE_ALL_GCS
2110
2111 void JavaThread::cleanup_failed_attach_current_thread() {
2112 if (active_handles() != NULL) {
2113 JNIHandleBlock* block = active_handles();
2114 set_active_handles(NULL);
2115 JNIHandleBlock::release_block(block);
2116 }
2117
2118 if (free_handle_block() != NULL) {
2119 JNIHandleBlock* block = free_handle_block();
2120 set_free_handle_block(NULL);
2121 JNIHandleBlock::release_block(block);
2122 }
2123
2124 // These have to be removed while this is still a valid thread.
2125 remove_stack_guard_pages();
2126
2127 if (UseTLAB) {
2128 tlab().make_parsable(true); // retire TLAB, if any
2129 }
2130
2131 #if INCLUDE_ALL_GCS
2132 if (UseG1GC || (UseShenandoahGC && (ShenandoahSATBBarrier || ShenandoahKeepAliveBarrier || ShenandoahStoreValEnqueueBarrier))) {
2133 flush_barrier_queues();
2134 }
2135 if (UseShenandoahGC && UseTLAB && gclab().is_initialized()) {
2136 gclab().make_parsable(true);
2137 }
2138 #endif // INCLUDE_ALL_GCS
2139
2140 Threads::remove(this);
2141 this->smr_delete();
2142 }
2143
2144
2145
2146
2147 JavaThread* JavaThread::active() {
2148 Thread* thread = Thread::current();
2149 if (thread->is_Java_thread()) {
2150 return (JavaThread*) thread;
2151 } else {
2152 assert(thread->is_VM_thread(), "this must be a vm thread");
2153 VM_Operation* op = ((VMThread*) thread)->vm_operation();
2154 JavaThread *ret=op == NULL ? NULL : (JavaThread *)op->calling_thread();
2155 assert(ret->is_Java_thread(), "must be a Java thread");
2156 return ret;
|
291 _ParkEvent = ParkEvent::Allocate(this);
292 _SleepEvent = ParkEvent::Allocate(this);
293 _MutexEvent = ParkEvent::Allocate(this);
294 _MuxEvent = ParkEvent::Allocate(this);
295
296 #ifdef CHECK_UNHANDLED_OOPS
297 if (CheckUnhandledOops) {
298 _unhandled_oops = new UnhandledOops(this);
299 }
300 #endif // CHECK_UNHANDLED_OOPS
301 #ifdef ASSERT
302 if (UseBiasedLocking) {
303 assert((((uintptr_t) this) & (markOopDesc::biased_lock_alignment - 1)) == 0, "forced alignment of thread object failed");
304 assert(this == _real_malloc_address ||
305 this == align_up(_real_malloc_address, (int)markOopDesc::biased_lock_alignment),
306 "bug in forced alignment of thread objects");
307 }
308 #endif // ASSERT
309
310 _oom_during_evac = 0;
311 #ifdef INCLUDE_ALL_GCS
312 _gclab = NULL;
313 #endif
314 }
315
316 void Thread::set_oom_during_evac(bool oom) {
317 if (oom) {
318 _oom_during_evac |= 1;
319 } else {
320 _oom_during_evac &= ~1;
321 }
322 }
323
324 bool Thread::is_oom_during_evac() const {
325 return (_oom_during_evac & 1) == 1;
326 }
327
328 #ifdef ASSERT
329 void Thread::set_evac_allowed(bool evac_allowed) {
330 if (evac_allowed) {
331 _oom_during_evac |= 2;
332 } else {
333 _oom_during_evac &= ~2;
2030 tlab().make_parsable(true); // retire TLAB
2031 }
2032
2033 if (JvmtiEnv::environments_might_exist()) {
2034 JvmtiExport::cleanup_thread(this);
2035 }
2036
2037 // We must flush any deferred card marks before removing a thread from
2038 // the list of active threads.
2039 Universe::heap()->flush_deferred_store_barrier(this);
2040 assert(deferred_card_mark().is_empty(), "Should have been flushed");
2041
2042 #if INCLUDE_ALL_GCS
2043 // We must flush the G1-related buffers before removing a thread
2044 // from the list of active threads. We must do this after any deferred
2045 // card marks have been flushed (above) so that any entries that are
2046 // added to the thread's dirty card queue as a result are not lost.
2047 if (UseG1GC || (UseShenandoahGC && (ShenandoahSATBBarrier || ShenandoahKeepAliveBarrier || ShenandoahStoreValEnqueueBarrier))) {
2048 flush_barrier_queues();
2049 }
2050 if (UseShenandoahGC && gclab() != NULL) {
2051 ShenandoahHeap::heap()->finalize_mutator_gclab(this);
2052 }
2053 #endif // INCLUDE_ALL_GCS
2054
2055 log_info(os, thread)("JavaThread %s (tid: " UINTX_FORMAT ").",
2056 exit_type == JavaThread::normal_exit ? "exiting" : "detaching",
2057 os::current_thread_id());
2058
2059 if (log_is_enabled(Debug, os, thread, timer)) {
2060 _timer_exit_phase3.stop();
2061 _timer_exit_phase4.start();
2062 }
2063 // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread
2064 Threads::remove(this);
2065
2066 if (log_is_enabled(Debug, os, thread, timer)) {
2067 _timer_exit_phase4.stop();
2068 ResourceMark rm(this);
2069 log_debug(os, thread, timer)("name='%s'"
2070 ", exit-phase1=" JLONG_FORMAT
2071 ", exit-phase2=" JLONG_FORMAT
2091 "we should not be at a safepoint");
2092
2093 SATBMarkQueue& satb_queue = satb_mark_queue();
2094 SATBMarkQueueSet& satb_queue_set = satb_mark_queue_set();
2095 // The SATB queue should have been constructed with its active
2096 // field set to false.
2097 assert(!satb_queue.is_active(), "SATB queue should not be active");
2098 assert(satb_queue.is_empty(), "SATB queue should be empty");
2099 // If we are creating the thread during a marking cycle, we should
2100 // set the active field of the SATB queue to true.
2101 if (satb_queue_set.is_active()) {
2102 satb_queue.set_active(true);
2103 }
2104
2105 DirtyCardQueue& dirty_queue = dirty_card_queue();
2106 // The dirty card queue should have been constructed with its
2107 // active field set to true.
2108 assert(dirty_queue.is_active(), "dirty card queue should be active");
2109
2110 _gc_state = _gc_state_global;
2111
2112 if (UseShenandoahGC) {
2113 ShenandoahHeap::heap()->initialize_gclab(this);
2114 }
2115 }
2116 #endif // INCLUDE_ALL_GCS
2117
2118 void JavaThread::cleanup_failed_attach_current_thread() {
2119 if (active_handles() != NULL) {
2120 JNIHandleBlock* block = active_handles();
2121 set_active_handles(NULL);
2122 JNIHandleBlock::release_block(block);
2123 }
2124
2125 if (free_handle_block() != NULL) {
2126 JNIHandleBlock* block = free_handle_block();
2127 set_free_handle_block(NULL);
2128 JNIHandleBlock::release_block(block);
2129 }
2130
2131 // These have to be removed while this is still a valid thread.
2132 remove_stack_guard_pages();
2133
2134 if (UseTLAB) {
2135 tlab().make_parsable(true); // retire TLAB, if any
2136 }
2137
2138 #if INCLUDE_ALL_GCS
2139 if (UseG1GC || (UseShenandoahGC && (ShenandoahSATBBarrier || ShenandoahKeepAliveBarrier || ShenandoahStoreValEnqueueBarrier))) {
2140 flush_barrier_queues();
2141 }
2142 if (UseShenandoahGC && gclab() != NULL) {
2143 gclab()->flush_and_retire_stats(ShenandoahHeap::heap()->mutator_gclab_stats());
2144 }
2145 #endif // INCLUDE_ALL_GCS
2146
2147 Threads::remove(this);
2148 this->smr_delete();
2149 }
2150
2151
2152
2153
2154 JavaThread* JavaThread::active() {
2155 Thread* thread = Thread::current();
2156 if (thread->is_Java_thread()) {
2157 return (JavaThread*) thread;
2158 } else {
2159 assert(thread->is_VM_thread(), "this must be a vm thread");
2160 VM_Operation* op = ((VMThread*) thread)->vm_operation();
2161 JavaThread *ret=op == NULL ? NULL : (JavaThread *)op->calling_thread();
2162 assert(ret->is_Java_thread(), "must be a Java thread");
2163 return ret;
|