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/copy.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/g1ConcurrentMarkThread.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"
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 JavaThreads + all non-JavaThreads (i.e., every thread in the system)
3437 void Threads::threads_do(ThreadClosure* tc) {
3438 assert_locked_or_safepoint(Threads_lock);
3439 // ALL_JAVA_THREADS iterates through all JavaThreads
3440 ALL_JAVA_THREADS(p) {
3441 tc->do_thread(p);
3442 }
3443 // Someday we could have a table or list of all non-JavaThreads.
3444 // For now, just manually iterate through them.
3445 tc->do_thread(VMThread::vm_thread());
3446 Universe::heap()->gc_threads_do(tc);
3447 WatcherThread *wt = WatcherThread::watcher_thread();
3448 // Strictly speaking, the following NULL check isn't sufficient to make sure
3449 // the data for WatcherThread is still valid upon being examined. However,
3450 // considering that WatchThread terminates when the VM is on the way to
3451 // exit at safepoint, the chance of the above is extremely small. The right
3452 // way to prevent termination of WatcherThread would be to acquire
3453 // Terminator_lock, but we can't do that without violating the lock rank
3454 // checking in some cases.
3455 if (wt != NULL) {
3456 tc->do_thread(wt);
3457 }
3458
3459 // If CompilerThreads ever become non-JavaThreads, add them here
3460 }
3461
3462 void Threads::possibly_parallel_threads_do(bool is_par, ThreadClosure* tc) {
3463 int cp = Threads::thread_claim_parity();
3464 ALL_JAVA_THREADS(p) {
3465 if (p->claim_oops_do(is_par, cp)) {
3466 tc->do_thread(p);
3467 }
3468 }
3469 VMThread* vmt = VMThread::vm_thread();
3470 if (vmt->claim_oops_do(is_par, cp)) {
3471 tc->do_thread(vmt);
3472 }
3473 }
3474
3475 // The system initialization in the library has three phases.
3476 //
3477 // Phase 1: java.lang.System class initialization
3478 // java.lang.System is a primordial class loaded and initialized
3479 // by the VM early during startup. java.lang.System.<clinit>
3480 // only does registerNatives and keeps the rest of the class
3481 // 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/copy.hpp"
111 #include "utilities/defaultStream.hpp"
112 #include "utilities/dtrace.hpp"
113 #include "utilities/events.hpp"
114 #include "utilities/macros.hpp"
115 #include "utilities/preserveException.hpp"
116 #include "utilities/vmError.hpp"
117 #if INCLUDE_ALL_GCS
118 #include "gc/cms/concurrentMarkSweepThread.hpp"
119 #include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
120 #include "gc/parallel/pcTasks.hpp"
121 #endif // INCLUDE_ALL_GCS
122 #if INCLUDE_JVMCI
123 #include "jvmci/jvmciCompiler.hpp"
124 #include "jvmci/jvmciRuntime.hpp"
125 #include "logging/logHandle.hpp"
126 #endif
127 #ifdef COMPILER1
128 #include "c1/c1_Compiler.hpp"
3417 return *addr;
3418 }
3419
3420 // Possibly the ugliest for loop the world has seen. C++ does not allow
3421 // multiple types in the declaration section of the for loop. In this case
3422 // we are only dealing with pointers and hence can cast them. It looks ugly
3423 // but macros are ugly and therefore it's fine to make things absurdly ugly.
3424 #define DO_JAVA_THREADS(LIST, X) \
3425 for (JavaThread *MACRO_scan_interval = (JavaThread*)(uintptr_t)PrefetchScanIntervalInBytes, \
3426 *MACRO_list = (JavaThread*)(LIST), \
3427 **MACRO_end = ((JavaThread**)((ThreadsList*)MACRO_list)->threads()) + ((ThreadsList*)MACRO_list)->length(), \
3428 **MACRO_current_p = (JavaThread**)((ThreadsList*)MACRO_list)->threads(), \
3429 *X = (JavaThread*)prefetch_and_load_ptr((void**)MACRO_current_p, (intx)MACRO_scan_interval); \
3430 MACRO_current_p != MACRO_end; \
3431 MACRO_current_p++, \
3432 X = (JavaThread*)prefetch_and_load_ptr((void**)MACRO_current_p, (intx)MACRO_scan_interval))
3433
3434 // All JavaThreads
3435 #define ALL_JAVA_THREADS(X) DO_JAVA_THREADS(ThreadsSMRSupport::get_java_thread_list(), X)
3436
3437 // All non-JavaThreads (i.e., every non-JavaThread in the system).
3438 void Threads::non_java_threads_do(ThreadClosure* tc) {
3439 // Someday we could have a table or list of all non-JavaThreads.
3440 // For now, just manually iterate through them.
3441 tc->do_thread(VMThread::vm_thread());
3442 if (Universe::heap() != NULL) {
3443 Universe::heap()->gc_threads_do(tc);
3444 }
3445 WatcherThread *wt = WatcherThread::watcher_thread();
3446 // Strictly speaking, the following NULL check isn't sufficient to make sure
3447 // the data for WatcherThread is still valid upon being examined. However,
3448 // considering that WatchThread terminates when the VM is on the way to
3449 // exit at safepoint, the chance of the above is extremely small. The right
3450 // way to prevent termination of WatcherThread would be to acquire
3451 // Terminator_lock, but we can't do that without violating the lock rank
3452 // checking in some cases.
3453 if (wt != NULL) {
3454 tc->do_thread(wt);
3455 }
3456
3457 #if INCLUDE_TRACE
3458 Thread* sampler_thread = TracingExport::sampler_thread_acquire();
3459 if (sampler_thread != NULL) {
3460 tc->do_thread(sampler_thread);
3461 }
3462 #endif
3463
3464 // If CompilerThreads ever become non-JavaThreads, add them here
3465 }
3466
3467 // All JavaThreads + all non-JavaThreads (i.e., every thread in the system).
3468 void Threads::threads_do(ThreadClosure* tc) {
3469 assert_locked_or_safepoint(Threads_lock);
3470 // ALL_JAVA_THREADS iterates through all JavaThreads.
3471 ALL_JAVA_THREADS(p) {
3472 tc->do_thread(p);
3473 }
3474 non_java_threads_do(tc);
3475 }
3476
3477 void Threads::possibly_parallel_threads_do(bool is_par, ThreadClosure* tc) {
3478 int cp = Threads::thread_claim_parity();
3479 ALL_JAVA_THREADS(p) {
3480 if (p->claim_oops_do(is_par, cp)) {
3481 tc->do_thread(p);
3482 }
3483 }
3484 VMThread* vmt = VMThread::vm_thread();
3485 if (vmt->claim_oops_do(is_par, cp)) {
3486 tc->do_thread(vmt);
3487 }
3488 }
3489
3490 // The system initialization in the library has three phases.
3491 //
3492 // Phase 1: java.lang.System class initialization
3493 // java.lang.System is a primordial class loaded and initialized
3494 // by the VM early during startup. java.lang.System.<clinit>
3495 // only does registerNatives and keeps the rest of the class
3496 // initialization work later until thread initialization completes.
|