< prev index next >

src/hotspot/share/runtime/thread.cpp

Print this page
rev 48920 : [backport] Use PLAB for evacuations instead of TLAB


 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   _gclab = NULL;
 312 }
 313 
 314 void Thread::set_oom_during_evac(bool oom) {
 315   if (oom) {
 316     _oom_during_evac |= 1;
 317   } else {
 318     _oom_during_evac &= ~1;
 319   }
 320 }
 321 
 322 bool Thread::is_oom_during_evac() const {
 323   return (_oom_during_evac & 1) == 1;
 324 }
 325 
 326 #ifdef ASSERT
 327 void Thread::set_evac_allowed(bool evac_allowed) {
 328   if (evac_allowed) {
 329     _oom_during_evac |= 2;
 330   } else {
 331     _oom_during_evac &= ~2;


2028     tlab().make_parsable(true);  // retire TLAB
2029   }
2030 
2031   if (JvmtiEnv::environments_might_exist()) {
2032     JvmtiExport::cleanup_thread(this);
2033   }
2034 
2035   // We must flush any deferred card marks before removing a thread from
2036   // the list of active threads.
2037   Universe::heap()->flush_deferred_store_barrier(this);
2038   assert(deferred_card_mark().is_empty(), "Should have been flushed");
2039 
2040 #if INCLUDE_ALL_GCS
2041   // We must flush the G1-related buffers before removing a thread
2042   // from the list of active threads. We must do this after any deferred
2043   // card marks have been flushed (above) so that any entries that are
2044   // added to the thread's dirty card queue as a result are not lost.
2045   if (UseG1GC || (UseShenandoahGC && (ShenandoahSATBBarrier || ShenandoahKeepAliveBarrier || ShenandoahStoreValEnqueueBarrier))) {
2046     flush_barrier_queues();
2047   }
2048   if (UseShenandoahGC && gclab() != NULL) {
2049     ShenandoahHeap::heap()->finalize_mutator_gclab(this);
2050   }
2051 #endif // INCLUDE_ALL_GCS
2052 
2053   log_info(os, thread)("JavaThread %s (tid: " UINTX_FORMAT ").",
2054     exit_type == JavaThread::normal_exit ? "exiting" : "detaching",
2055     os::current_thread_id());
2056 
2057   if (log_is_enabled(Debug, os, thread, timer)) {
2058     _timer_exit_phase3.stop();
2059     _timer_exit_phase4.start();
2060   }
2061   // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread
2062   Threads::remove(this);
2063 
2064   if (log_is_enabled(Debug, os, thread, timer)) {
2065     _timer_exit_phase4.stop();
2066     ResourceMark rm(this);
2067     log_debug(os, thread, timer)("name='%s'"
2068                                  ", exit-phase1=" JLONG_FORMAT
2069                                  ", exit-phase2=" JLONG_FORMAT


2089          "we should not be at a safepoint");
2090 
2091   SATBMarkQueue& satb_queue = satb_mark_queue();
2092   SATBMarkQueueSet& satb_queue_set = satb_mark_queue_set();
2093   // The SATB queue should have been constructed with its active
2094   // field set to false.
2095   assert(!satb_queue.is_active(), "SATB queue should not be active");
2096   assert(satb_queue.is_empty(), "SATB queue should be empty");
2097   // If we are creating the thread during a marking cycle, we should
2098   // set the active field of the SATB queue to true.
2099   if (satb_queue_set.is_active()) {
2100     satb_queue.set_active(true);
2101   }
2102 
2103   DirtyCardQueue& dirty_queue = dirty_card_queue();
2104   // The dirty card queue should have been constructed with its
2105   // active field set to true.
2106   assert(dirty_queue.is_active(), "dirty card queue should be active");
2107 
2108   _gc_state = _gc_state_global;
2109 
2110   if (UseShenandoahGC) {
2111     ShenandoahHeap::heap()->initialize_gclab(this);
2112   }
2113 }
2114 #endif // INCLUDE_ALL_GCS
2115 
2116 void JavaThread::cleanup_failed_attach_current_thread() {
2117   if (active_handles() != NULL) {
2118     JNIHandleBlock* block = active_handles();
2119     set_active_handles(NULL);
2120     JNIHandleBlock::release_block(block);
2121   }
2122 
2123   if (free_handle_block() != NULL) {
2124     JNIHandleBlock* block = free_handle_block();
2125     set_free_handle_block(NULL);
2126     JNIHandleBlock::release_block(block);
2127   }
2128 
2129   // These have to be removed while this is still a valid thread.
2130   remove_stack_guard_pages();
2131 
2132   if (UseTLAB) {
2133     tlab().make_parsable(true);  // retire TLAB, if any
2134   }
2135 
2136 #if INCLUDE_ALL_GCS
2137   if (UseG1GC || (UseShenandoahGC && (ShenandoahSATBBarrier || ShenandoahKeepAliveBarrier || ShenandoahStoreValEnqueueBarrier))) {
2138     flush_barrier_queues();
2139   }
2140   if (UseShenandoahGC && gclab() != NULL) {
2141     gclab()->flush_and_retire_stats(ShenandoahHeap::heap()->mutator_gclab_stats());
2142   }
2143 #endif // INCLUDE_ALL_GCS
2144 
2145   Threads::remove(this);
2146   this->smr_delete();
2147 }
2148 
2149 
2150 
2151 
2152 JavaThread* JavaThread::active() {
2153   Thread* thread = Thread::current();
2154   if (thread->is_Java_thread()) {
2155     return (JavaThread*) thread;
2156   } else {
2157     assert(thread->is_VM_thread(), "this must be a vm thread");
2158     VM_Operation* op = ((VMThread*) thread)->vm_operation();
2159     JavaThread *ret=op == NULL ? NULL : (JavaThread *)op->calling_thread();
2160     assert(ret->is_Java_thread(), "must be a Java thread");
2161     return ret;


< prev index next >