/* * Copyright (c) 2015, Red Hat, Inc. and/or its affiliates. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #include "precompiled.hpp" #include "classfile/stringTable.hpp" #include "classfile/systemDictionary.hpp" #include "code/codeCache.hpp" #include "gc/shenandoah/shenandoahRootProcessor.hpp" #include "gc/shenandoah/shenandoahHeap.hpp" #include "gc/shenandoah/shenandoahBarrierSet.hpp" #include "gc/shenandoah/shenandoahCollectorPolicy.hpp" #include "gc/shenandoah/shenandoahPhaseTimes.hpp" #include "memory/allocation.inline.hpp" #include "runtime/fprofiler.hpp" #include "runtime/mutex.hpp" #include "services/management.hpp" ShenandoahRootProcessor::ShenandoahRootProcessor(ShenandoahHeap* heap, uint n_workers, ShenandoahCollectorPolicy::TimingPhase phase) : _process_strong_tasks(new SubTasksDone(SHENANDOAH_RP_PS_NumElements)), _srs(n_workers), _phase(phase), _codecache_iterator(CodeCache::parallel_iterator()), _om_iterator(ObjectSynchronizer::parallel_iterator()) { heap->shenandoahPolicy()->record_workers_start(_phase); } ShenandoahRootProcessor::~ShenandoahRootProcessor() { delete _process_strong_tasks; ShenandoahHeap::heap()->shenandoahPolicy()->record_workers_end(_phase); } void ShenandoahRootProcessor::process_strong_roots(OopClosure* oops, OopClosure* weak_oops, CLDClosure* clds, CodeBlobClosure* blobs, uint worker_id) { process_java_roots(oops, clds, NULL, blobs, worker_id); process_vm_roots(oops, NULL, weak_oops, worker_id); _process_strong_tasks->all_tasks_completed(n_workers()); } void ShenandoahRootProcessor::process_all_roots(OopClosure* oops, OopClosure* weak_oops, CLDClosure* clds, CodeBlobClosure* blobs, uint worker_id) { ShenandoahPhaseTimes* phase_times = ShenandoahHeap::heap()->shenandoahPolicy()->phase_times(); process_java_roots(oops, clds, clds, NULL, worker_id); process_vm_roots(oops, oops, weak_oops, worker_id); if (blobs != NULL) { ShenandoahParPhaseTimesTracker timer(phase_times, ShenandoahPhaseTimes::CodeCacheRoots, worker_id); _codecache_iterator.parallel_blobs_do(blobs); } _process_strong_tasks->all_tasks_completed(n_workers()); } void ShenandoahRootProcessor::process_java_roots(OopClosure* strong_roots, CLDClosure* strong_clds, CLDClosure* weak_clds, CodeBlobClosure* strong_code, uint worker_id) { ShenandoahPhaseTimes* phase_times = ShenandoahHeap::heap()->shenandoahPolicy()->phase_times(); // 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. { ShenandoahParPhaseTimesTracker timer(phase_times, ShenandoahPhaseTimes::CLDGRoots, worker_id); _cld_iterator.root_cld_do(strong_clds, weak_clds); } { ShenandoahParPhaseTimesTracker timer(phase_times, ShenandoahPhaseTimes::ThreadRoots, worker_id); bool is_par = n_workers() > 1; ResourceMark rm; Threads::possibly_parallel_oops_do(is_par, strong_roots, strong_code); } } void ShenandoahRootProcessor::process_vm_roots(OopClosure* strong_roots, OopClosure* weak_roots, OopClosure* jni_weak_roots, uint worker_id) { ShenandoahPhaseTimes* phase_times = ShenandoahHeap::heap()->shenandoahPolicy()->phase_times(); if (!_process_strong_tasks->is_task_claimed(SHENANDOAH_RP_PS_Universe_oops_do)) { ShenandoahParPhaseTimesTracker timer(phase_times, ShenandoahPhaseTimes::UniverseRoots, worker_id); Universe::oops_do(strong_roots); } if (!_process_strong_tasks->is_task_claimed(SHENANDOAH_RP_PS_JNIHandles_oops_do)) { ShenandoahParPhaseTimesTracker timer(phase_times, ShenandoahPhaseTimes::JNIRoots, worker_id); JNIHandles::oops_do(strong_roots); } if (!_process_strong_tasks->is_task_claimed(SHENANDOAH_RP_PS_FlatProfiler_oops_do)) { ShenandoahParPhaseTimesTracker timer(phase_times, ShenandoahPhaseTimes::FlatProfilerRoots, worker_id); FlatProfiler::oops_do(strong_roots); } if (!_process_strong_tasks->is_task_claimed(SHENANDOAH_RP_PS_Management_oops_do)) { ShenandoahParPhaseTimesTracker timer(phase_times, ShenandoahPhaseTimes::ManagementRoots, worker_id); Management::oops_do(strong_roots); } if (!_process_strong_tasks->is_task_claimed(SHENANDOAH_RP_PS_jvmti_oops_do)) { ShenandoahParPhaseTimesTracker timer(phase_times, ShenandoahPhaseTimes::JVMTIRoots, worker_id); JvmtiExport::oops_do(strong_roots); } if (!_process_strong_tasks->is_task_claimed(SHENANDOAH_RP_PS_SystemDictionary_oops_do)) { ShenandoahParPhaseTimesTracker timer(phase_times, ShenandoahPhaseTimes::SystemDictionaryRoots, worker_id); SystemDictionary::roots_oops_do(strong_roots, weak_roots); } if (jni_weak_roots != NULL) { if (!_process_strong_tasks->is_task_claimed(SHENANDOAH_RP_PS_JNIHandles_weak_oops_do)) { ShenandoahAlwaysTrueClosure always_true; ShenandoahParPhaseTimesTracker timer(phase_times, ShenandoahPhaseTimes::JNIWeakRoots, worker_id); JNIHandles::weak_oops_do(&always_true, jni_weak_roots); } } { ShenandoahParPhaseTimesTracker timer(phase_times, ShenandoahPhaseTimes::ObjectSynchronizerRoots, worker_id); while(_om_iterator.parallel_oops_do(strong_roots)); } // All threads execute the following. A specific chunk of buckets // from the StringTable are the individual tasks. if (weak_roots != NULL) { ShenandoahParPhaseTimesTracker timer(phase_times, ShenandoahPhaseTimes::StringTableRoots, worker_id); StringTable::possibly_parallel_oops_do(weak_roots); } } uint ShenandoahRootProcessor::n_workers() const { return _srs.n_threads(); } ShenandoahRootEvacuator::ShenandoahRootEvacuator(ShenandoahHeap* heap, uint n_workers, ShenandoahCollectorPolicy::TimingPhase phase) : _process_strong_tasks(new SubTasksDone(SHENANDOAH_RP_PS_NumElements)), _srs(n_workers), _phase(phase), _codecache_iterator(CodeCache::parallel_iterator()) { heap->shenandoahPolicy()->record_workers_start(_phase); } ShenandoahRootEvacuator::~ShenandoahRootEvacuator() { delete _process_strong_tasks; ShenandoahHeap::heap()->shenandoahPolicy()->record_workers_end(_phase); } void ShenandoahRootEvacuator::process_evacuate_roots(OopClosure* oops, CodeBlobClosure* blobs, uint worker_id) { ShenandoahPhaseTimes* phase_times = ShenandoahHeap::heap()->shenandoahPolicy()->phase_times(); { bool is_par = n_workers() > 1; ResourceMark rm; ShenandoahParPhaseTimesTracker timer(phase_times, ShenandoahPhaseTimes::ThreadRoots, worker_id); Threads::possibly_parallel_oops_do(is_par, oops, NULL); } if (blobs != NULL) { ShenandoahParPhaseTimesTracker timer(phase_times, ShenandoahPhaseTimes::CodeCacheRoots, worker_id); _codecache_iterator.parallel_blobs_do(blobs); } _process_strong_tasks->all_tasks_completed(n_workers()); } uint ShenandoahRootEvacuator::n_workers() const { return _srs.n_threads(); } // Implemenation of ParallelCLDRootIterator ParallelCLDRootIterator::ParallelCLDRootIterator() { assert(SafepointSynchronize::is_at_safepoint(), "Must at safepoint"); ClassLoaderDataGraph::clear_claimed_marks(); } void ParallelCLDRootIterator::root_cld_do(CLDClosure* strong, CLDClosure* weak) { ClassLoaderDataGraph::roots_cld_do(strong, weak); }