< prev index next >

src/hotspot/share/runtime/thread.cpp

Print this page




 233   DEBUG_ONLY(_current_resource_mark = NULL;)
 234   set_handle_area(new (mtThread) HandleArea(NULL));
 235   set_metadata_handles(new (ResourceObj::C_HEAP, mtClass) GrowableArray<Metadata*>(30, true));
 236   set_active_handles(NULL);
 237   set_free_handle_block(NULL);
 238   set_last_handle_mark(NULL);
 239   DEBUG_ONLY(_missed_ic_stub_refill_verifier = NULL);
 240 
 241   // Initial value of zero ==> never claimed.
 242   _threads_do_token = 0;
 243   _threads_hazard_ptr = NULL;
 244   _threads_list_ptr = NULL;
 245   _nested_threads_hazard_ptr_cnt = 0;
 246   _rcu_counter = 0;
 247 
 248   // the handle mark links itself to last_handle_mark
 249   new HandleMark(this);
 250 
 251   // plain initialization
 252   debug_only(_owned_locks = NULL;)
 253   NOT_PRODUCT(_allow_safepoint_count = 0;)
 254   NOT_PRODUCT(_skip_gcalot = false;)
 255   _jvmti_env_iteration_count = 0;
 256   set_allocated_bytes(0);
 257   _vm_operation_started_count = 0;
 258   _vm_operation_completed_count = 0;
 259   _current_pending_monitor = NULL;
 260   _current_pending_monitor_is_from_java = true;
 261   _current_waiting_monitor = NULL;
 262   _num_nested_signal = 0;
 263   omFreeList = NULL;
 264   omFreeCount = 0;
 265   omFreeProvision = 32;
 266   omInUseList = NULL;
 267   omInUseCount = 0;
 268 
 269 #ifdef ASSERT
 270   _visited_for_critical_count = false;
 271 #endif
 272 
 273   _SR_lock = new Monitor(Mutex::suspend_resume, "SR_lock", true,


1003 
1004 static int ref_use_count  = 0;
1005 
1006 bool Thread::owns_locks_but_compiled_lock() const {
1007   for (Monitor *cur = _owned_locks; cur; cur = cur->next()) {
1008     if (cur != Compile_lock) return true;
1009   }
1010   return false;
1011 }
1012 
1013 
1014 #endif
1015 
1016 #ifndef PRODUCT
1017 
1018 // The flag: potential_vm_operation notifies if this particular safepoint state could potentially
1019 // invoke the vm-thread (e.g., an oop allocation). In that case, we also have to make sure that
1020 // no locks which allow_vm_block's are held
1021 void Thread::check_for_valid_safepoint_state(bool potential_vm_operation) {
1022   // Check if current thread is allowed to block at a safepoint
1023   if (!(_allow_safepoint_count == 0)) {
1024     fatal("Possible safepoint reached by thread that does not allow it");
1025   }
1026   if (is_Java_thread() && ((JavaThread*)this)->thread_state() != _thread_in_vm) {
1027     fatal("LEAF method calling lock?");
1028   }
1029 
1030 #ifdef ASSERT
1031   if (potential_vm_operation && is_Java_thread()
1032       && !Universe::is_bootstrapping()) {
1033     // Make sure we do not hold any locks that the VM thread also uses.
1034     // This could potentially lead to deadlocks
1035     for (Monitor *cur = _owned_locks; cur; cur = cur->next()) {
1036       // Threads_lock is special, since the safepoint synchronization will not start before this is
1037       // acquired. Hence, a JavaThread cannot be holding it at a safepoint. So is VMOperationRequest_lock,
1038       // since it is used to transfer control between JavaThreads and the VMThread
1039       // Do not *exclude* any locks unless you are absolutely sure it is correct. Ask someone else first!
1040       if ((cur->allow_vm_block() &&
1041            cur != Threads_lock &&
1042            cur != Compile_lock &&               // Temporary: should not be necessary when we get separate compilation
1043            cur != VMOperationRequest_lock &&


3526 
3527 // Possibly the ugliest for loop the world has seen. C++ does not allow
3528 // multiple types in the declaration section of the for loop. In this case
3529 // we are only dealing with pointers and hence can cast them. It looks ugly
3530 // but macros are ugly and therefore it's fine to make things absurdly ugly.
3531 #define DO_JAVA_THREADS(LIST, X)                                                                                          \
3532     for (JavaThread *MACRO_scan_interval = (JavaThread*)(uintptr_t)PrefetchScanIntervalInBytes,                           \
3533              *MACRO_list = (JavaThread*)(LIST),                                                                           \
3534              **MACRO_end = ((JavaThread**)((ThreadsList*)MACRO_list)->threads()) + ((ThreadsList*)MACRO_list)->length(),  \
3535              **MACRO_current_p = (JavaThread**)((ThreadsList*)MACRO_list)->threads(),                                     \
3536              *X = (JavaThread*)prefetch_and_load_ptr((void**)MACRO_current_p, (intx)MACRO_scan_interval);                 \
3537          MACRO_current_p != MACRO_end;                                                                                    \
3538          MACRO_current_p++,                                                                                               \
3539              X = (JavaThread*)prefetch_and_load_ptr((void**)MACRO_current_p, (intx)MACRO_scan_interval))
3540 
3541 // All JavaThreads
3542 #define ALL_JAVA_THREADS(X) DO_JAVA_THREADS(ThreadsSMRSupport::get_java_thread_list(), X)
3543 
3544 // All NonJavaThreads (i.e., every non-JavaThread in the system).
3545 void Threads::non_java_threads_do(ThreadClosure* tc) {
3546   NoSafepointVerifier nsv(!SafepointSynchronize::is_at_safepoint(), false);
3547   for (NonJavaThread::Iterator njti; !njti.end(); njti.step()) {
3548     tc->do_thread(njti.current());
3549   }
3550 }
3551 
3552 // All JavaThreads
3553 void Threads::java_threads_do(ThreadClosure* tc) {
3554   assert_locked_or_safepoint(Threads_lock);
3555   // ALL_JAVA_THREADS iterates through all JavaThreads.
3556   ALL_JAVA_THREADS(p) {
3557     tc->do_thread(p);
3558   }
3559 }
3560 
3561 void Threads::java_threads_and_vm_thread_do(ThreadClosure* tc) {
3562   assert_locked_or_safepoint(Threads_lock);
3563   java_threads_do(tc);
3564   tc->do_thread(VMThread::vm_thread());
3565 }
3566 




 233   DEBUG_ONLY(_current_resource_mark = NULL;)
 234   set_handle_area(new (mtThread) HandleArea(NULL));
 235   set_metadata_handles(new (ResourceObj::C_HEAP, mtClass) GrowableArray<Metadata*>(30, true));
 236   set_active_handles(NULL);
 237   set_free_handle_block(NULL);
 238   set_last_handle_mark(NULL);
 239   DEBUG_ONLY(_missed_ic_stub_refill_verifier = NULL);
 240 
 241   // Initial value of zero ==> never claimed.
 242   _threads_do_token = 0;
 243   _threads_hazard_ptr = NULL;
 244   _threads_list_ptr = NULL;
 245   _nested_threads_hazard_ptr_cnt = 0;
 246   _rcu_counter = 0;
 247 
 248   // the handle mark links itself to last_handle_mark
 249   new HandleMark(this);
 250 
 251   // plain initialization
 252   debug_only(_owned_locks = NULL;)
 253   NOT_PRODUCT(_no_safepoint_count = 0;)
 254   NOT_PRODUCT(_skip_gcalot = false;)
 255   _jvmti_env_iteration_count = 0;
 256   set_allocated_bytes(0);
 257   _vm_operation_started_count = 0;
 258   _vm_operation_completed_count = 0;
 259   _current_pending_monitor = NULL;
 260   _current_pending_monitor_is_from_java = true;
 261   _current_waiting_monitor = NULL;
 262   _num_nested_signal = 0;
 263   omFreeList = NULL;
 264   omFreeCount = 0;
 265   omFreeProvision = 32;
 266   omInUseList = NULL;
 267   omInUseCount = 0;
 268 
 269 #ifdef ASSERT
 270   _visited_for_critical_count = false;
 271 #endif
 272 
 273   _SR_lock = new Monitor(Mutex::suspend_resume, "SR_lock", true,


1003 
1004 static int ref_use_count  = 0;
1005 
1006 bool Thread::owns_locks_but_compiled_lock() const {
1007   for (Monitor *cur = _owned_locks; cur; cur = cur->next()) {
1008     if (cur != Compile_lock) return true;
1009   }
1010   return false;
1011 }
1012 
1013 
1014 #endif
1015 
1016 #ifndef PRODUCT
1017 
1018 // The flag: potential_vm_operation notifies if this particular safepoint state could potentially
1019 // invoke the vm-thread (e.g., an oop allocation). In that case, we also have to make sure that
1020 // no locks which allow_vm_block's are held
1021 void Thread::check_for_valid_safepoint_state(bool potential_vm_operation) {
1022   // Check if current thread is allowed to block at a safepoint
1023   if (_no_safepoint_count > 0) {
1024     fatal("Possible safepoint reached by thread that does not allow it");
1025   }
1026   if (is_Java_thread() && ((JavaThread*)this)->thread_state() != _thread_in_vm) {
1027     fatal("LEAF method calling lock?");
1028   }
1029 
1030 #ifdef ASSERT
1031   if (potential_vm_operation && is_Java_thread()
1032       && !Universe::is_bootstrapping()) {
1033     // Make sure we do not hold any locks that the VM thread also uses.
1034     // This could potentially lead to deadlocks
1035     for (Monitor *cur = _owned_locks; cur; cur = cur->next()) {
1036       // Threads_lock is special, since the safepoint synchronization will not start before this is
1037       // acquired. Hence, a JavaThread cannot be holding it at a safepoint. So is VMOperationRequest_lock,
1038       // since it is used to transfer control between JavaThreads and the VMThread
1039       // Do not *exclude* any locks unless you are absolutely sure it is correct. Ask someone else first!
1040       if ((cur->allow_vm_block() &&
1041            cur != Threads_lock &&
1042            cur != Compile_lock &&               // Temporary: should not be necessary when we get separate compilation
1043            cur != VMOperationRequest_lock &&


3526 
3527 // Possibly the ugliest for loop the world has seen. C++ does not allow
3528 // multiple types in the declaration section of the for loop. In this case
3529 // we are only dealing with pointers and hence can cast them. It looks ugly
3530 // but macros are ugly and therefore it's fine to make things absurdly ugly.
3531 #define DO_JAVA_THREADS(LIST, X)                                                                                          \
3532     for (JavaThread *MACRO_scan_interval = (JavaThread*)(uintptr_t)PrefetchScanIntervalInBytes,                           \
3533              *MACRO_list = (JavaThread*)(LIST),                                                                           \
3534              **MACRO_end = ((JavaThread**)((ThreadsList*)MACRO_list)->threads()) + ((ThreadsList*)MACRO_list)->length(),  \
3535              **MACRO_current_p = (JavaThread**)((ThreadsList*)MACRO_list)->threads(),                                     \
3536              *X = (JavaThread*)prefetch_and_load_ptr((void**)MACRO_current_p, (intx)MACRO_scan_interval);                 \
3537          MACRO_current_p != MACRO_end;                                                                                    \
3538          MACRO_current_p++,                                                                                               \
3539              X = (JavaThread*)prefetch_and_load_ptr((void**)MACRO_current_p, (intx)MACRO_scan_interval))
3540 
3541 // All JavaThreads
3542 #define ALL_JAVA_THREADS(X) DO_JAVA_THREADS(ThreadsSMRSupport::get_java_thread_list(), X)
3543 
3544 // All NonJavaThreads (i.e., every non-JavaThread in the system).
3545 void Threads::non_java_threads_do(ThreadClosure* tc) {
3546   NoSafepointVerifier nsv;
3547   for (NonJavaThread::Iterator njti; !njti.end(); njti.step()) {
3548     tc->do_thread(njti.current());
3549   }
3550 }
3551 
3552 // All JavaThreads
3553 void Threads::java_threads_do(ThreadClosure* tc) {
3554   assert_locked_or_safepoint(Threads_lock);
3555   // ALL_JAVA_THREADS iterates through all JavaThreads.
3556   ALL_JAVA_THREADS(p) {
3557     tc->do_thread(p);
3558   }
3559 }
3560 
3561 void Threads::java_threads_and_vm_thread_do(ThreadClosure* tc) {
3562   assert_locked_or_safepoint(Threads_lock);
3563   java_threads_do(tc);
3564   tc->do_thread(VMThread::vm_thread());
3565 }
3566 


< prev index next >