--- old/src/share/vm/gc_implementation/g1/g1RootProcessor.cpp 2015-05-13 14:03:41.309390109 +0200 +++ new/src/share/vm/gc_implementation/g1/g1RootProcessor.cpp 2015-05-13 14:03:41.185385988 +0200 @@ -90,11 +90,10 @@ void G1RootProcessor::worker_has_discovered_all_strong_classes() { - uint n_workers = _g1h->n_par_threads(); 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) { + if (new_value == n_workers()) { // This thread is last. Notify the others. MonitorLockerEx ml(&_lock, Mutex::_no_safepoint_check_flag); _lock.notify_all(); @@ -102,21 +101,20 @@ } void G1RootProcessor::wait_until_all_strong_classes_discovered() { - uint n_workers = _g1h->n_par_threads(); assert(ClassUnloadingWithConcurrentMark, "Currently only needed when doing G1 Class Unloading"); - if ((uint)_n_workers_discovered_strong_classes != n_workers) { + if ((uint)_n_workers_discovered_strong_classes != n_workers()) { MonitorLockerEx ml(&_lock, Mutex::_no_safepoint_check_flag); - while ((uint)_n_workers_discovered_strong_classes != n_workers) { + while ((uint)_n_workers_discovered_strong_classes != n_workers()) { _lock.wait(Mutex::_no_safepoint_check_flag, 0, false); } } } -G1RootProcessor::G1RootProcessor(G1CollectedHeap* g1h) : +G1RootProcessor::G1RootProcessor(G1CollectedHeap* g1h, uint n_workers) : _g1h(g1h), _process_strong_tasks(new SubTasksDone(G1RP_PS_NumElements)), - _srs(), + _srs(n_workers), _lock(Mutex::leaf, "G1 Root Scanning barrier lock", false, Monitor::_safepoint_check_never), _n_workers_discovered_strong_classes(0) {} @@ -253,7 +251,7 @@ { G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::ThreadRoots, worker_i); - bool is_par = _g1h->n_par_threads() > 1; + bool is_par = n_workers() > 1; Threads::possibly_parallel_oops_do(is_par, strong_roots, thread_stack_clds, strong_code); } } @@ -330,5 +328,13 @@ } void G1RootProcessor::set_num_workers(uint active_workers) { + assert(active_workers == _srs.n_threads(), + err_msg("Mismatch between number of worker threads. active_workers: %u and n_workers(): %u", + active_workers, + _srs.n_threads())); _process_strong_tasks->set_n_threads(active_workers); } + +uint G1RootProcessor::n_workers() const { + return _srs.n_threads(); +}