< prev index next >

src/hotspot/share/runtime/thread.cpp

Print this page
rev 49501 : 8200374: Add ThreadsSMRSupport::verify_hazard_pointer_scanned() to verify threads_do().


  88 #include "runtime/stubRoutines.hpp"
  89 #include "runtime/sweeper.hpp"
  90 #include "runtime/task.hpp"
  91 #include "runtime/thread.inline.hpp"
  92 #include "runtime/threadCritical.hpp"
  93 #include "runtime/threadSMR.inline.hpp"
  94 #include "runtime/timer.hpp"
  95 #include "runtime/timerTrace.hpp"
  96 #include "runtime/vframe.inline.hpp"
  97 #include "runtime/vframeArray.hpp"
  98 #include "runtime/vframe_hp.hpp"
  99 #include "runtime/vmThread.hpp"
 100 #include "runtime/vm_operations.hpp"
 101 #include "runtime/vm_version.hpp"
 102 #include "services/attachListener.hpp"
 103 #include "services/management.hpp"
 104 #include "services/memTracker.hpp"
 105 #include "services/threadService.hpp"
 106 #include "trace/traceMacros.hpp"
 107 #include "trace/tracing.hpp"

 108 #include "utilities/align.hpp"
 109 #include "utilities/defaultStream.hpp"
 110 #include "utilities/dtrace.hpp"
 111 #include "utilities/events.hpp"
 112 #include "utilities/macros.hpp"
 113 #include "utilities/preserveException.hpp"
 114 #include "utilities/vmError.hpp"
 115 #if INCLUDE_ALL_GCS
 116 #include "gc/cms/concurrentMarkSweepThread.hpp"
 117 #include "gc/g1/concurrentMarkThread.inline.hpp"
 118 #include "gc/parallel/pcTasks.hpp"
 119 #endif // INCLUDE_ALL_GCS
 120 #if INCLUDE_JVMCI
 121 #include "jvmci/jvmciCompiler.hpp"
 122 #include "jvmci/jvmciRuntime.hpp"
 123 #include "logging/logHandle.hpp"
 124 #endif
 125 #ifdef COMPILER1
 126 #include "c1/c1_Compiler.hpp"
 127 #endif


3415   return *addr;
3416 }
3417 
3418 // Possibly the ugliest for loop the world has seen. C++ does not allow
3419 // multiple types in the declaration section of the for loop. In this case
3420 // we are only dealing with pointers and hence can cast them. It looks ugly
3421 // but macros are ugly and therefore it's fine to make things absurdly ugly.
3422 #define DO_JAVA_THREADS(LIST, X)                                                                                          \
3423     for (JavaThread *MACRO_scan_interval = (JavaThread*)(uintptr_t)PrefetchScanIntervalInBytes,                           \
3424              *MACRO_list = (JavaThread*)(LIST),                                                                           \
3425              **MACRO_end = ((JavaThread**)((ThreadsList*)MACRO_list)->threads()) + ((ThreadsList*)MACRO_list)->length(),  \
3426              **MACRO_current_p = (JavaThread**)((ThreadsList*)MACRO_list)->threads(),                                     \
3427              *X = (JavaThread*)prefetch_and_load_ptr((void**)MACRO_current_p, (intx)MACRO_scan_interval);                 \
3428          MACRO_current_p != MACRO_end;                                                                                    \
3429          MACRO_current_p++,                                                                                               \
3430              X = (JavaThread*)prefetch_and_load_ptr((void**)MACRO_current_p, (intx)MACRO_scan_interval))
3431 
3432 // All JavaThreads
3433 #define ALL_JAVA_THREADS(X) DO_JAVA_THREADS(ThreadsSMRSupport::get_java_thread_list(), X)
3434 
3435 // All JavaThreads + all non-JavaThreads (i.e., every thread in the system)
3436 void Threads::threads_do(ThreadClosure* tc) {
3437   assert_locked_or_safepoint(Threads_lock);
3438   // ALL_JAVA_THREADS iterates through all JavaThreads
3439   ALL_JAVA_THREADS(p) {
3440     tc->do_thread(p);
3441   }
3442   // Someday we could have a table or list of all non-JavaThreads.
3443   // For now, just manually iterate through them.
3444   tc->do_thread(VMThread::vm_thread());
3445   Universe::heap()->gc_threads_do(tc);
3446   WatcherThread *wt = WatcherThread::watcher_thread();
3447   // Strictly speaking, the following NULL check isn't sufficient to make sure
3448   // the data for WatcherThread is still valid upon being examined. However,
3449   // considering that WatchThread terminates when the VM is on the way to
3450   // exit at safepoint, the chance of the above is extremely small. The right
3451   // way to prevent termination of WatcherThread would be to acquire
3452   // Terminator_lock, but we can't do that without violating the lock rank
3453   // checking in some cases.
3454   if (wt != NULL) {
3455     tc->do_thread(wt);
3456   }
3457 







3458   // If CompilerThreads ever become non-JavaThreads, add them here
3459 }
3460 










3461 void Threads::possibly_parallel_threads_do(bool is_par, ThreadClosure* tc) {
3462   int cp = Threads::thread_claim_parity();
3463   ALL_JAVA_THREADS(p) {
3464     if (p->claim_oops_do(is_par, cp)) {
3465       tc->do_thread(p);
3466     }
3467   }
3468   VMThread* vmt = VMThread::vm_thread();
3469   if (vmt->claim_oops_do(is_par, cp)) {
3470     tc->do_thread(vmt);
3471   }
3472 }
3473 
3474 // The system initialization in the library has three phases.
3475 //
3476 // Phase 1: java.lang.System class initialization
3477 //     java.lang.System is a primordial class loaded and initialized
3478 //     by the VM early during startup.  java.lang.System.<clinit>
3479 //     only does registerNatives and keeps the rest of the class
3480 //     initialization work later until thread initialization completes.




  88 #include "runtime/stubRoutines.hpp"
  89 #include "runtime/sweeper.hpp"
  90 #include "runtime/task.hpp"
  91 #include "runtime/thread.inline.hpp"
  92 #include "runtime/threadCritical.hpp"
  93 #include "runtime/threadSMR.inline.hpp"
  94 #include "runtime/timer.hpp"
  95 #include "runtime/timerTrace.hpp"
  96 #include "runtime/vframe.inline.hpp"
  97 #include "runtime/vframeArray.hpp"
  98 #include "runtime/vframe_hp.hpp"
  99 #include "runtime/vmThread.hpp"
 100 #include "runtime/vm_operations.hpp"
 101 #include "runtime/vm_version.hpp"
 102 #include "services/attachListener.hpp"
 103 #include "services/management.hpp"
 104 #include "services/memTracker.hpp"
 105 #include "services/threadService.hpp"
 106 #include "trace/traceMacros.hpp"
 107 #include "trace/tracing.hpp"
 108 #include "trace/tracingExport.hpp"
 109 #include "utilities/align.hpp"
 110 #include "utilities/defaultStream.hpp"
 111 #include "utilities/dtrace.hpp"
 112 #include "utilities/events.hpp"
 113 #include "utilities/macros.hpp"
 114 #include "utilities/preserveException.hpp"
 115 #include "utilities/vmError.hpp"
 116 #if INCLUDE_ALL_GCS
 117 #include "gc/cms/concurrentMarkSweepThread.hpp"
 118 #include "gc/g1/concurrentMarkThread.inline.hpp"
 119 #include "gc/parallel/pcTasks.hpp"
 120 #endif // INCLUDE_ALL_GCS
 121 #if INCLUDE_JVMCI
 122 #include "jvmci/jvmciCompiler.hpp"
 123 #include "jvmci/jvmciRuntime.hpp"
 124 #include "logging/logHandle.hpp"
 125 #endif
 126 #ifdef COMPILER1
 127 #include "c1/c1_Compiler.hpp"
 128 #endif


3416   return *addr;
3417 }
3418 
3419 // Possibly the ugliest for loop the world has seen. C++ does not allow
3420 // multiple types in the declaration section of the for loop. In this case
3421 // we are only dealing with pointers and hence can cast them. It looks ugly
3422 // but macros are ugly and therefore it's fine to make things absurdly ugly.
3423 #define DO_JAVA_THREADS(LIST, X)                                                                                          \
3424     for (JavaThread *MACRO_scan_interval = (JavaThread*)(uintptr_t)PrefetchScanIntervalInBytes,                           \
3425              *MACRO_list = (JavaThread*)(LIST),                                                                           \
3426              **MACRO_end = ((JavaThread**)((ThreadsList*)MACRO_list)->threads()) + ((ThreadsList*)MACRO_list)->length(),  \
3427              **MACRO_current_p = (JavaThread**)((ThreadsList*)MACRO_list)->threads(),                                     \
3428              *X = (JavaThread*)prefetch_and_load_ptr((void**)MACRO_current_p, (intx)MACRO_scan_interval);                 \
3429          MACRO_current_p != MACRO_end;                                                                                    \
3430          MACRO_current_p++,                                                                                               \
3431              X = (JavaThread*)prefetch_and_load_ptr((void**)MACRO_current_p, (intx)MACRO_scan_interval))
3432 
3433 // All JavaThreads
3434 #define ALL_JAVA_THREADS(X) DO_JAVA_THREADS(ThreadsSMRSupport::get_java_thread_list(), X)
3435 
3436 // All non-JavaThreads (i.e., every non-JavaThread in the system).
3437 void Threads::non_java_threads_do(ThreadClosure* tc) {





3438   // Someday we could have a table or list of all non-JavaThreads.
3439   // For now, just manually iterate through them.
3440   tc->do_thread(VMThread::vm_thread());
3441   Universe::heap()->gc_threads_do(tc);
3442   WatcherThread *wt = WatcherThread::watcher_thread();
3443   // Strictly speaking, the following NULL check isn't sufficient to make sure
3444   // the data for WatcherThread is still valid upon being examined. However,
3445   // considering that WatchThread terminates when the VM is on the way to
3446   // exit at safepoint, the chance of the above is extremely small. The right
3447   // way to prevent termination of WatcherThread would be to acquire
3448   // Terminator_lock, but we can't do that without violating the lock rank
3449   // checking in some cases.
3450   if (wt != NULL) {
3451     tc->do_thread(wt);
3452   }
3453 
3454 #if INCLUDE_TRACE
3455   Thread* sampler_thread = TracingExport::get_sampler_thread();
3456   if (sampler_thread != NULL) {
3457     tc->do_thread(sampler_thread);
3458   }
3459 #endif
3460 
3461   // If CompilerThreads ever become non-JavaThreads, add them here
3462 }
3463 
3464 // All JavaThreads + all non-JavaThreads (i.e., every thread in the system).
3465 void Threads::threads_do(ThreadClosure* tc) {
3466   assert_locked_or_safepoint(Threads_lock);
3467   // ALL_JAVA_THREADS iterates through all JavaThreads.
3468   ALL_JAVA_THREADS(p) {
3469     tc->do_thread(p);
3470   }
3471   non_java_threads_do(tc);
3472 }
3473 
3474 void Threads::possibly_parallel_threads_do(bool is_par, ThreadClosure* tc) {
3475   int cp = Threads::thread_claim_parity();
3476   ALL_JAVA_THREADS(p) {
3477     if (p->claim_oops_do(is_par, cp)) {
3478       tc->do_thread(p);
3479     }
3480   }
3481   VMThread* vmt = VMThread::vm_thread();
3482   if (vmt->claim_oops_do(is_par, cp)) {
3483     tc->do_thread(vmt);
3484   }
3485 }
3486 
3487 // The system initialization in the library has three phases.
3488 //
3489 // Phase 1: java.lang.System class initialization
3490 //     java.lang.System is a primordial class loaded and initialized
3491 //     by the VM early during startup.  java.lang.System.<clinit>
3492 //     only does registerNatives and keeps the rest of the class
3493 //     initialization work later until thread initialization completes.


< prev index next >