src/hotspot/share/runtime/thread.cpp
changeset 47637 87141990dde5
parent 47634 6a0c42c40cd1
child 47687 fb290fd1f9d4
equal deleted inserted replaced
47636:52d46d7e3454 47637:87141990dde5
  3347   }
  3347   }
  3348 
  3348 
  3349   // If CompilerThreads ever become non-JavaThreads, add them here
  3349   // If CompilerThreads ever become non-JavaThreads, add them here
  3350 }
  3350 }
  3351 
  3351 
  3352 void Threads::parallel_java_threads_do(ThreadClosure* tc) {
  3352 void Threads::possibly_parallel_threads_do(bool is_par, ThreadClosure* tc) {
  3353   int cp = Threads::thread_claim_parity();
  3353   int cp = Threads::thread_claim_parity();
  3354   ALL_JAVA_THREADS(p) {
  3354   ALL_JAVA_THREADS(p) {
  3355     if (p->claim_oops_do(true, cp)) {
  3355     if (p->claim_oops_do(is_par, cp)) {
  3356       tc->do_thread(p);
  3356       tc->do_thread(p);
  3357     }
  3357     }
  3358   }
  3358   }
  3359   // Thread claiming protocol requires us to claim the same interesting
       
  3360   // threads on all paths. Notably, Threads::possibly_parallel_threads_do
       
  3361   // claims all Java threads *and* the VMThread. To avoid breaking the
       
  3362   // claiming protocol, we have to claim VMThread on this path too, even
       
  3363   // if we do not apply the closure to the VMThread.
       
  3364   VMThread* vmt = VMThread::vm_thread();
  3359   VMThread* vmt = VMThread::vm_thread();
  3365   (void)vmt->claim_oops_do(true, cp);
  3360   if (vmt->claim_oops_do(is_par, cp)) {
       
  3361     tc->do_thread(vmt);
       
  3362   }
  3366 }
  3363 }
  3367 
  3364 
  3368 // The system initialization in the library has three phases.
  3365 // The system initialization in the library has three phases.
  3369 //
  3366 //
  3370 // Phase 1: java.lang.System class initialization
  3367 // Phase 1: java.lang.System class initialization
  4322   assert((thread_parity == _thread_claim_parity),
  4319   assert((thread_parity == _thread_claim_parity),
  4323          "VMThread " PTR_FORMAT " has incorrect parity %d != %d", p2i(vmt), thread_parity, _thread_claim_parity);
  4320          "VMThread " PTR_FORMAT " has incorrect parity %d != %d", p2i(vmt), thread_parity, _thread_claim_parity);
  4324 }
  4321 }
  4325 #endif // ASSERT
  4322 #endif // ASSERT
  4326 
  4323 
       
  4324 class ParallelOopsDoThreadClosure : public ThreadClosure {
       
  4325 private:
       
  4326   OopClosure* _f;
       
  4327   CodeBlobClosure* _cf;
       
  4328 public:
       
  4329   ParallelOopsDoThreadClosure(OopClosure* f, CodeBlobClosure* cf) : _f(f), _cf(cf) {}
       
  4330   void do_thread(Thread* t) {
       
  4331     t->oops_do(_f, _cf);
       
  4332   }
       
  4333 };
       
  4334 
  4327 void Threads::possibly_parallel_oops_do(bool is_par, OopClosure* f, CodeBlobClosure* cf) {
  4335 void Threads::possibly_parallel_oops_do(bool is_par, OopClosure* f, CodeBlobClosure* cf) {
  4328   int cp = Threads::thread_claim_parity();
  4336   ParallelOopsDoThreadClosure tc(f, cf);
  4329   ALL_JAVA_THREADS(p) {
  4337   possibly_parallel_threads_do(is_par, &tc);
  4330     if (p->claim_oops_do(is_par, cp)) {
       
  4331       p->oops_do(f, cf);
       
  4332     }
       
  4333   }
       
  4334   VMThread* vmt = VMThread::vm_thread();
       
  4335   if (vmt->claim_oops_do(is_par, cp)) {
       
  4336     vmt->oops_do(f, cf);
       
  4337   }
       
  4338 }
  4338 }
  4339 
  4339 
  4340 #if INCLUDE_ALL_GCS
  4340 #if INCLUDE_ALL_GCS
  4341 // Used by ParallelScavenge
  4341 // Used by ParallelScavenge
  4342 void Threads::create_thread_roots_tasks(GCTaskQueue* q) {
  4342 void Threads::create_thread_roots_tasks(GCTaskQueue* q) {