< prev index next >

src/hotspot/share/runtime/thread.cpp

Print this page




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 




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 >