< prev index next >

src/share/vm/runtime/thread.cpp

Print this page




3375   // the data for WatcherThread is still valid upon being examined. However,
3376   // considering that WatchThread terminates when the VM is on the way to
3377   // exit at safepoint, the chance of the above is extremely small. The right
3378   // way to prevent termination of WatcherThread would be to acquire
3379   // Terminator_lock, but we can't do that without violating the lock rank
3380   // checking in some cases.
3381   if (wt != NULL) {
3382     tc->do_thread(wt);
3383   }
3384 
3385   // If CompilerThreads ever become non-JavaThreads, add them here
3386 }
3387 
3388 void Threads::parallel_java_threads_do(ThreadClosure* tc) {
3389   int cp = Threads::thread_claim_parity();
3390   ALL_JAVA_THREADS(p) {
3391     if (p->claim_oops_do(true, cp)) {
3392       tc->do_thread(p);
3393     }
3394   }







3395 }
3396 
3397 // The system initialization in the library has three phases.
3398 //
3399 // Phase 1: java.lang.System class initialization
3400 //     java.lang.System is a primordial class loaded and initialized
3401 //     by the VM early during startup.  java.lang.System.<clinit>
3402 //     only does registerNatives and keeps the rest of the class
3403 //     initialization work later until thread initialization completes.
3404 //
3405 //     System.initPhase1 initializes the system properties, the static
3406 //     fields in, out, and err. Set up java signal handlers, OS-specific
3407 //     system settings, and thread group of the main thread.
3408 static void call_initPhase1(TRAPS) {
3409   Klass* klass =  SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
3410   JavaValue result(T_VOID);
3411   JavaCalls::call_static(&result, klass, vmSymbols::initPhase1_name(),
3412                                          vmSymbols::void_method_signature(), CHECK);
3413 }
3414 


4340   VMThread::vm_thread()->oops_do(f, cf);
4341 }
4342 
4343 void Threads::change_thread_claim_parity() {
4344   // Set the new claim parity.
4345   assert(_thread_claim_parity >= 0 && _thread_claim_parity <= 2,
4346          "Not in range.");
4347   _thread_claim_parity++;
4348   if (_thread_claim_parity == 3) _thread_claim_parity = 1;
4349   assert(_thread_claim_parity >= 1 && _thread_claim_parity <= 2,
4350          "Not in range.");
4351 }
4352 
4353 #ifdef ASSERT
4354 void Threads::assert_all_threads_claimed() {
4355   ALL_JAVA_THREADS(p) {
4356     const int thread_parity = p->oops_do_parity();
4357     assert((thread_parity == _thread_claim_parity),
4358            "Thread " PTR_FORMAT " has incorrect parity %d != %d", p2i(p), thread_parity, _thread_claim_parity);
4359   }




4360 }
4361 #endif // ASSERT
4362 
4363 void Threads::possibly_parallel_oops_do(bool is_par, OopClosure* f, CodeBlobClosure* cf) {
4364   int cp = Threads::thread_claim_parity();
4365   ALL_JAVA_THREADS(p) {
4366     if (p->claim_oops_do(is_par, cp)) {
4367       p->oops_do(f, cf);
4368     }
4369   }
4370   VMThread* vmt = VMThread::vm_thread();
4371   if (vmt->claim_oops_do(is_par, cp)) {
4372     vmt->oops_do(f, cf);
4373   }
4374 }
4375 
4376 #if INCLUDE_ALL_GCS
4377 // Used by ParallelScavenge
4378 void Threads::create_thread_roots_tasks(GCTaskQueue* q) {
4379   ALL_JAVA_THREADS(p) {




3375   // the data for WatcherThread is still valid upon being examined. However,
3376   // considering that WatchThread terminates when the VM is on the way to
3377   // exit at safepoint, the chance of the above is extremely small. The right
3378   // way to prevent termination of WatcherThread would be to acquire
3379   // Terminator_lock, but we can't do that without violating the lock rank
3380   // checking in some cases.
3381   if (wt != NULL) {
3382     tc->do_thread(wt);
3383   }
3384 
3385   // If CompilerThreads ever become non-JavaThreads, add them here
3386 }
3387 
3388 void Threads::parallel_java_threads_do(ThreadClosure* tc) {
3389   int cp = Threads::thread_claim_parity();
3390   ALL_JAVA_THREADS(p) {
3391     if (p->claim_oops_do(true, cp)) {
3392       tc->do_thread(p);
3393     }
3394   }
3395   // Thread claiming protocol requires us to claim the same interesting
3396   // threads on all paths. Notably, Threads::possibly_parallel_threads_do
3397   // claims all Java threads *and* the VMThread. To avoid breaking the
3398   // claiming protocol, we have to claim VMThread on this path too, even
3399   // if we do not apply the closure to the VMThread.
3400   VMThread* vmt = VMThread::vm_thread();
3401   (void)vmt->claim_oops_do(true, cp);
3402 }
3403 
3404 // The system initialization in the library has three phases.
3405 //
3406 // Phase 1: java.lang.System class initialization
3407 //     java.lang.System is a primordial class loaded and initialized
3408 //     by the VM early during startup.  java.lang.System.<clinit>
3409 //     only does registerNatives and keeps the rest of the class
3410 //     initialization work later until thread initialization completes.
3411 //
3412 //     System.initPhase1 initializes the system properties, the static
3413 //     fields in, out, and err. Set up java signal handlers, OS-specific
3414 //     system settings, and thread group of the main thread.
3415 static void call_initPhase1(TRAPS) {
3416   Klass* klass =  SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
3417   JavaValue result(T_VOID);
3418   JavaCalls::call_static(&result, klass, vmSymbols::initPhase1_name(),
3419                                          vmSymbols::void_method_signature(), CHECK);
3420 }
3421 


4347   VMThread::vm_thread()->oops_do(f, cf);
4348 }
4349 
4350 void Threads::change_thread_claim_parity() {
4351   // Set the new claim parity.
4352   assert(_thread_claim_parity >= 0 && _thread_claim_parity <= 2,
4353          "Not in range.");
4354   _thread_claim_parity++;
4355   if (_thread_claim_parity == 3) _thread_claim_parity = 1;
4356   assert(_thread_claim_parity >= 1 && _thread_claim_parity <= 2,
4357          "Not in range.");
4358 }
4359 
4360 #ifdef ASSERT
4361 void Threads::assert_all_threads_claimed() {
4362   ALL_JAVA_THREADS(p) {
4363     const int thread_parity = p->oops_do_parity();
4364     assert((thread_parity == _thread_claim_parity),
4365            "Thread " PTR_FORMAT " has incorrect parity %d != %d", p2i(p), thread_parity, _thread_claim_parity);
4366   }
4367   VMThread* vmt = VMThread::vm_thread();
4368   const int thread_parity = vmt->oops_do_parity();
4369   assert((thread_parity == _thread_claim_parity),
4370          "VMThread " PTR_FORMAT " has incorrect parity %d != %d", p2i(vmt), thread_parity, _thread_claim_parity);
4371 }
4372 #endif // ASSERT
4373 
4374 void Threads::possibly_parallel_oops_do(bool is_par, OopClosure* f, CodeBlobClosure* cf) {
4375   int cp = Threads::thread_claim_parity();
4376   ALL_JAVA_THREADS(p) {
4377     if (p->claim_oops_do(is_par, cp)) {
4378       p->oops_do(f, cf);
4379     }
4380   }
4381   VMThread* vmt = VMThread::vm_thread();
4382   if (vmt->claim_oops_do(is_par, cp)) {
4383     vmt->oops_do(f, cf);
4384   }
4385 }
4386 
4387 #if INCLUDE_ALL_GCS
4388 // Used by ParallelScavenge
4389 void Threads::create_thread_roots_tasks(GCTaskQueue* q) {
4390   ALL_JAVA_THREADS(p) {


< prev index next >