< prev index next >

src/hotspot/share/gc/g1/g1RootProcessor.cpp

Print this page
rev 56328 : [mq]: 8159984-kbarrett-review

*** 43,64 **** #include "memory/universe.hpp" #include "runtime/mutex.hpp" #include "services/management.hpp" #include "utilities/macros.hpp" ! void G1RootProcessor::worker_has_discovered_all_strong_classes() { assert(ClassUnloadingWithConcurrentMark, "Currently only needed when doing G1 Class Unloading"); uint new_value = (uint)Atomic::add(1, &_n_workers_discovered_strong_classes); if (new_value == n_workers()) { // This thread is last. Notify the others. MonitorLocker ml(&_lock, Mutex::_no_safepoint_check_flag); _lock.notify_all(); } } ! void G1RootProcessor::wait_until_all_strong_classes_discovered() { assert(ClassUnloadingWithConcurrentMark, "Currently only needed when doing G1 Class Unloading"); if ((uint)_n_workers_discovered_strong_classes != n_workers()) { MonitorLocker ml(&_lock, Mutex::_no_safepoint_check_flag); while ((uint)_n_workers_discovered_strong_classes != n_workers()) { --- 43,64 ---- #include "memory/universe.hpp" #include "runtime/mutex.hpp" #include "services/management.hpp" #include "utilities/macros.hpp" ! void G1RootProcessor::worker_has_discovered_all_strong_nmethods() { assert(ClassUnloadingWithConcurrentMark, "Currently only needed when doing G1 Class Unloading"); uint new_value = (uint)Atomic::add(1, &_n_workers_discovered_strong_classes); if (new_value == n_workers()) { // This thread is last. Notify the others. MonitorLocker ml(&_lock, Mutex::_no_safepoint_check_flag); _lock.notify_all(); } } ! void G1RootProcessor::wait_until_all_strong_nmethods_discovered() { assert(ClassUnloadingWithConcurrentMark, "Currently only needed when doing G1 Class Unloading"); if ((uint)_n_workers_discovered_strong_classes != n_workers()) { MonitorLocker ml(&_lock, Mutex::_no_safepoint_check_flag); while ((uint)_n_workers_discovered_strong_classes != n_workers()) {
*** 69,94 **** G1RootProcessor::G1RootProcessor(G1CollectedHeap* g1h, uint n_workers) : _g1h(g1h), _process_strong_tasks(G1RP_PS_NumElements), _srs(n_workers), ! _lock(Mutex::leaf, "G1 Root Scanning barrier lock", false, Monitor::_safepoint_check_never), _n_workers_discovered_strong_classes(0) {} void G1RootProcessor::evacuate_roots(G1ParScanThreadState* pss, uint worker_i) { G1GCPhaseTimes* phase_times = _g1h->phase_times(); G1EvacPhaseTimesTracker timer(phase_times, pss, G1GCPhaseTimes::ExtRootScan, worker_i); G1EvacuationRootClosures* closures = pss->closures(); ! process_java_roots(closures, phase_times, worker_i); ! ! // This is the point where this worker thread will not find more strong CLDs/nmethods. ! // Report this so G1 can synchronize the strong and weak CLDs/nmethods processing. ! if (closures->trace_metadata()) { ! worker_has_discovered_all_strong_classes(); ! } process_vm_roots(closures, phase_times, worker_i); { // Now the CM ref_processor roots. --- 69,88 ---- G1RootProcessor::G1RootProcessor(G1CollectedHeap* g1h, uint n_workers) : _g1h(g1h), _process_strong_tasks(G1RP_PS_NumElements), _srs(n_workers), ! _lock(Mutex::leaf, "G1 Root Scan barrier lock", false, Monitor::_safepoint_check_never), _n_workers_discovered_strong_classes(0) {} void G1RootProcessor::evacuate_roots(G1ParScanThreadState* pss, uint worker_i) { G1GCPhaseTimes* phase_times = _g1h->phase_times(); G1EvacPhaseTimesTracker timer(phase_times, pss, G1GCPhaseTimes::ExtRootScan, worker_i); G1EvacuationRootClosures* closures = pss->closures(); ! process_java_roots(closures, phase_times, worker_i, closures->trace_metadata() /* notify_claimed_roots_done */); process_vm_roots(closures, phase_times, worker_i); { // Now the CM ref_processor roots.
*** 101,125 **** _g1h->ref_processor_cm()->weak_oops_do(closures->strong_oops()); } } if (closures->trace_metadata()) { ! { ! G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::WaitForStrongCLD, worker_i); ! // Barrier to make sure all workers passed ! // the strong CLD and strong nmethods phases. ! wait_until_all_strong_classes_discovered(); ! } ! ! // Now take the complement of the strong CLDs. ! G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::WeakCLDRoots, worker_i); ! assert(closures->second_pass_weak_clds() != NULL, "Should be non-null if we are tracing metadata."); ! ClassLoaderDataGraph::roots_cld_do(NULL, closures->second_pass_weak_clds()); ! } else { ! phase_times->record_time_secs(G1GCPhaseTimes::WaitForStrongCLD, worker_i, 0.0); ! phase_times->record_time_secs(G1GCPhaseTimes::WeakCLDRoots, worker_i, 0.0); ! assert(closures->second_pass_weak_clds() == NULL, "Should be null if not tracing metadata."); } _process_strong_tasks.all_tasks_completed(n_workers()); } --- 95,107 ---- _g1h->ref_processor_cm()->weak_oops_do(closures->strong_oops()); } } if (closures->trace_metadata()) { ! G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::WaitForStrongRoots, worker_i); ! // Wait to make sure all workers passed the strong nmethods phase. ! wait_until_all_strong_nmethods_discovered(); } _process_strong_tasks.all_tasks_completed(n_workers()); }
*** 187,214 **** _process_strong_tasks.all_tasks_completed(n_workers()); } void G1RootProcessor::process_java_roots(G1RootClosures* closures, G1GCPhaseTimes* phase_times, ! uint worker_i) { ! // Iterating over the CLDG and the Threads are done early to allow us to ! // first process the strong CLDs and nmethods and then, after a barrier, ! // let the thread process the weak CLDs and nmethods. ! { ! G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::CLDGRoots, worker_i); ! if (_process_strong_tasks.try_claim_task(G1RP_PS_ClassLoaderDataGraph_oops_do)) { ! ClassLoaderDataGraph::roots_cld_do(closures->strong_clds(), closures->weak_clds()); ! } ! } ! { G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::ThreadRoots, worker_i); bool is_par = n_workers() > 1; Threads::possibly_parallel_oops_do(is_par, closures->strong_oops(), closures->strong_codeblobs()); } } void G1RootProcessor::process_vm_roots(G1RootClosures* closures, G1GCPhaseTimes* phase_times, uint worker_i) { --- 169,216 ---- _process_strong_tasks.all_tasks_completed(n_workers()); } void G1RootProcessor::process_java_roots(G1RootClosures* closures, G1GCPhaseTimes* phase_times, ! uint worker_i, ! bool notify_claimed_roots_done) { ! // We need to make make sure that the "strong" nmethods are processed first ! // using the strong closure. Only after that we process the weakly reachable ! // nmethods. ! // We need to strictly separate the strong and weak nmethod processing because ! // any processing claims that nmethod, i.e. will not be iterated again. ! // Which means if an nmethod is processed first and claimed, the strong processing ! // will not happen, and the oops reachable by that nmethod will not be marked ! // properly. ! // ! // That is why we process strong nmethods first, synchronize all threads via a ! // barrier, and only then allow weak processing. To minimize the wait time at ! // that barrier we do the strong nmethod processing first, and immediately after- ! // wards indicate that that thread is done. Hopefully other root processing after ! // nmethod processing is enough so there is no need to wait. ! // ! // This is only required in the concurrent start pause with class unloading enabled. { G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::ThreadRoots, worker_i); bool is_par = n_workers() > 1; Threads::possibly_parallel_oops_do(is_par, closures->strong_oops(), closures->strong_codeblobs()); } + + // This is the point where this worker thread will not find more strong nmethods. + // Report this so G1 can synchronize the strong and weak CLDs/nmethods processing. + if (notify_claimed_roots_done) { + worker_has_discovered_all_strong_nmethods(); + } + + { + G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::CLDGRoots, worker_i); + if (_process_strong_tasks.try_claim_task(G1RP_PS_ClassLoaderDataGraph_oops_do)) { + ClassLoaderDataGraph::roots_cld_do(closures->strong_clds(), closures->weak_clds()); + } + } } void G1RootProcessor::process_vm_roots(G1RootClosures* closures, G1GCPhaseTimes* phase_times, uint worker_i) {
< prev index next >