2018-12-10 15:47:44 +01:00
|
|
|
/*
|
2019-03-13 13:33:50 -04:00
|
|
|
* Copyright (c) 2015, 2019, Red Hat, Inc. All rights reserved.
|
2018-12-10 15:47:44 +01:00
|
|
|
*
|
|
|
|
* 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/classLoaderDataGraph.hpp"
|
|
|
|
#include "classfile/stringTable.hpp"
|
|
|
|
#include "classfile/systemDictionary.hpp"
|
|
|
|
#include "code/codeCache.hpp"
|
2019-04-15 13:07:06 -04:00
|
|
|
#include "gc/shenandoah/shenandoahClosures.inline.hpp"
|
2018-12-10 15:47:44 +01:00
|
|
|
#include "gc/shenandoah/shenandoahRootProcessor.hpp"
|
|
|
|
#include "gc/shenandoah/shenandoahHeap.hpp"
|
|
|
|
#include "gc/shenandoah/shenandoahPhaseTimings.hpp"
|
|
|
|
#include "gc/shenandoah/shenandoahStringDedup.hpp"
|
|
|
|
#include "gc/shenandoah/shenandoahTimingTracker.hpp"
|
|
|
|
#include "gc/shenandoah/shenandoahUtils.hpp"
|
|
|
|
#include "gc/shenandoah/shenandoahVMOperations.hpp"
|
2019-03-11 14:06:05 -04:00
|
|
|
#include "gc/shared/weakProcessor.inline.hpp"
|
2018-12-10 15:47:44 +01:00
|
|
|
#include "memory/allocation.inline.hpp"
|
|
|
|
#include "memory/iterator.hpp"
|
|
|
|
#include "memory/resourceArea.hpp"
|
|
|
|
#include "runtime/thread.hpp"
|
|
|
|
#include "services/management.hpp"
|
|
|
|
|
|
|
|
ShenandoahRootProcessor::ShenandoahRootProcessor(ShenandoahHeap* heap, uint n_workers,
|
|
|
|
ShenandoahPhaseTimings::Phase phase) :
|
|
|
|
_process_strong_tasks(new SubTasksDone(SHENANDOAH_RP_PS_NumElements)),
|
|
|
|
_srs(n_workers),
|
|
|
|
_phase(phase),
|
2019-03-11 14:06:05 -04:00
|
|
|
_coderoots_all_iterator(ShenandoahCodeRoots::iterator()),
|
2019-03-13 13:33:50 -04:00
|
|
|
_weak_processor_timings(n_workers),
|
|
|
|
_weak_processor_task(&_weak_processor_timings, n_workers),
|
|
|
|
_processed_weak_roots(false) {
|
2018-12-10 15:47:44 +01:00
|
|
|
heap->phase_timings()->record_workers_start(_phase);
|
|
|
|
|
|
|
|
if (ShenandoahStringDedup::is_enabled()) {
|
|
|
|
StringDedup::gc_prologue(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ShenandoahRootProcessor::~ShenandoahRootProcessor() {
|
|
|
|
delete _process_strong_tasks;
|
|
|
|
if (ShenandoahStringDedup::is_enabled()) {
|
|
|
|
StringDedup::gc_epilogue();
|
|
|
|
}
|
|
|
|
|
2019-03-13 13:33:50 -04:00
|
|
|
if (_processed_weak_roots) {
|
|
|
|
assert(_weak_processor_timings.max_threads() == n_workers(), "Must match");
|
2019-05-02 09:49:52 -04:00
|
|
|
ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
|
|
|
|
ShenandoahTimingConverter::weak_processing_timing_to_shenandoah_timing(&_weak_processor_timings,
|
|
|
|
worker_times);
|
2019-03-13 13:33:50 -04:00
|
|
|
}
|
|
|
|
|
2018-12-10 15:47:44 +01:00
|
|
|
ShenandoahHeap::heap()->phase_timings()->record_workers_end(_phase);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShenandoahRootProcessor::process_all_roots_slow(OopClosure* oops) {
|
|
|
|
CLDToOopClosure clds(oops, ClassLoaderData::_claim_strong);
|
|
|
|
CodeBlobToOopClosure blobs(oops, !CodeBlobToOopClosure::FixRelocations);
|
|
|
|
|
|
|
|
CodeCache::blobs_do(&blobs);
|
|
|
|
ClassLoaderDataGraph::cld_do(&clds);
|
|
|
|
Universe::oops_do(oops);
|
|
|
|
Management::oops_do(oops);
|
|
|
|
JvmtiExport::oops_do(oops);
|
|
|
|
JNIHandles::oops_do(oops);
|
|
|
|
ObjectSynchronizer::oops_do(oops);
|
|
|
|
SystemDictionary::oops_do(oops);
|
|
|
|
|
2019-05-01 10:12:51 -04:00
|
|
|
AlwaysTrueClosure always_true;
|
|
|
|
WeakProcessor::weak_oops_do(&always_true, oops);
|
|
|
|
|
|
|
|
if (ShenandoahStringDedup::is_enabled()) {
|
|
|
|
ShenandoahStringDedup::oops_do_slow(oops);
|
|
|
|
}
|
|
|
|
|
2018-12-10 15:47:44 +01:00
|
|
|
// Do thread roots the last. This allows verification code to find
|
|
|
|
// any broken objects from those special roots first, not the accidental
|
|
|
|
// dangling reference from the thread root.
|
|
|
|
Threads::possibly_parallel_oops_do(false, oops, &blobs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShenandoahRootProcessor::process_strong_roots(OopClosure* oops,
|
|
|
|
CLDClosure* clds,
|
|
|
|
CodeBlobClosure* blobs,
|
|
|
|
ThreadClosure* thread_cl,
|
|
|
|
uint worker_id) {
|
|
|
|
|
2019-03-28 13:53:41 -04:00
|
|
|
process_java_roots(oops, clds, NULL, blobs, thread_cl, worker_id);
|
2019-03-26 12:12:49 -04:00
|
|
|
process_vm_roots(oops, worker_id);
|
2018-12-10 15:47:44 +01:00
|
|
|
|
|
|
|
_process_strong_tasks->all_tasks_completed(n_workers());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShenandoahRootProcessor::process_all_roots(OopClosure* oops,
|
|
|
|
CLDClosure* clds,
|
|
|
|
CodeBlobClosure* blobs,
|
|
|
|
ThreadClosure* thread_cl,
|
|
|
|
uint worker_id) {
|
|
|
|
|
|
|
|
ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
|
|
|
|
process_java_roots(oops, clds, clds, blobs, thread_cl, worker_id);
|
2019-03-26 12:12:49 -04:00
|
|
|
process_vm_roots(oops, worker_id);
|
2018-12-10 15:47:44 +01:00
|
|
|
|
|
|
|
if (blobs != NULL) {
|
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::CodeCacheRoots, worker_id);
|
|
|
|
_coderoots_all_iterator.possibly_parallel_blobs_do(blobs);
|
|
|
|
}
|
|
|
|
|
|
|
|
_process_strong_tasks->all_tasks_completed(n_workers());
|
2019-03-26 12:12:49 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-12-10 15:47:44 +01:00
|
|
|
class ShenandoahParallelOopsDoThreadClosure : public ThreadClosure {
|
|
|
|
private:
|
|
|
|
OopClosure* _f;
|
|
|
|
CodeBlobClosure* _cf;
|
|
|
|
ThreadClosure* _thread_cl;
|
|
|
|
public:
|
|
|
|
ShenandoahParallelOopsDoThreadClosure(OopClosure* f, CodeBlobClosure* cf, ThreadClosure* thread_cl) :
|
|
|
|
_f(f), _cf(cf), _thread_cl(thread_cl) {}
|
|
|
|
|
|
|
|
void do_thread(Thread* t) {
|
|
|
|
if (_thread_cl != NULL) {
|
|
|
|
_thread_cl->do_thread(t);
|
|
|
|
}
|
|
|
|
t->oops_do(_f, _cf);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void ShenandoahRootProcessor::process_java_roots(OopClosure* strong_roots,
|
|
|
|
CLDClosure* strong_clds,
|
|
|
|
CLDClosure* weak_clds,
|
|
|
|
CodeBlobClosure* strong_code,
|
|
|
|
ThreadClosure* thread_cl,
|
|
|
|
uint worker_id)
|
|
|
|
{
|
|
|
|
ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_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.
|
|
|
|
{
|
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::CLDGRoots, worker_id);
|
|
|
|
_cld_iterator.root_cld_do(strong_clds, weak_clds);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::ThreadRoots, worker_id);
|
|
|
|
bool is_par = n_workers() > 1;
|
|
|
|
ResourceMark rm;
|
|
|
|
ShenandoahParallelOopsDoThreadClosure cl(strong_roots, strong_code, thread_cl);
|
|
|
|
Threads::possibly_parallel_threads_do(is_par, &cl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShenandoahRootProcessor::process_vm_roots(OopClosure* strong_roots,
|
2019-03-26 12:12:49 -04:00
|
|
|
uint worker_id) {
|
2018-12-10 15:47:44 +01:00
|
|
|
ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
|
|
|
|
if (_process_strong_tasks->try_claim_task(SHENANDOAH_RP_PS_Universe_oops_do)) {
|
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::UniverseRoots, worker_id);
|
|
|
|
Universe::oops_do(strong_roots);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_process_strong_tasks->try_claim_task(SHENANDOAH_RP_PS_JNIHandles_oops_do)) {
|
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::JNIRoots, worker_id);
|
|
|
|
JNIHandles::oops_do(strong_roots);
|
|
|
|
}
|
|
|
|
if (_process_strong_tasks->try_claim_task(SHENANDOAH_RP_PS_Management_oops_do)) {
|
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::ManagementRoots, worker_id);
|
|
|
|
Management::oops_do(strong_roots);
|
|
|
|
}
|
|
|
|
if (_process_strong_tasks->try_claim_task(SHENANDOAH_RP_PS_jvmti_oops_do)) {
|
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::JVMTIRoots, worker_id);
|
|
|
|
JvmtiExport::oops_do(strong_roots);
|
|
|
|
}
|
|
|
|
if (_process_strong_tasks->try_claim_task(SHENANDOAH_RP_PS_SystemDictionary_oops_do)) {
|
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::SystemDictionaryRoots, worker_id);
|
|
|
|
SystemDictionary::oops_do(strong_roots);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::ObjectSynchronizerRoots, worker_id);
|
|
|
|
if (_process_strong_tasks->try_claim_task(SHENANDOAH_RP_PS_ObjectSynchronizer_oops_do)) {
|
|
|
|
ObjectSynchronizer::oops_do(strong_roots);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint ShenandoahRootProcessor::n_workers() const {
|
|
|
|
return _srs.n_threads();
|
|
|
|
}
|
|
|
|
|
|
|
|
ShenandoahRootEvacuator::ShenandoahRootEvacuator(ShenandoahHeap* heap, uint n_workers, ShenandoahPhaseTimings::Phase phase) :
|
|
|
|
_evacuation_tasks(new SubTasksDone(SHENANDOAH_EVAC_NumElements)),
|
|
|
|
_srs(n_workers),
|
|
|
|
_phase(phase),
|
2019-05-02 09:49:52 -04:00
|
|
|
_coderoots_cset_iterator(ShenandoahCodeRoots::cset_iterator()),
|
|
|
|
_weak_processor_timings(n_workers),
|
|
|
|
_weak_processor_task(&_weak_processor_timings, n_workers) {
|
2018-12-10 15:47:44 +01:00
|
|
|
heap->phase_timings()->record_workers_start(_phase);
|
2019-04-02 23:00:22 +02:00
|
|
|
if (ShenandoahStringDedup::is_enabled()) {
|
|
|
|
StringDedup::gc_prologue(false);
|
|
|
|
}
|
2018-12-10 15:47:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ShenandoahRootEvacuator::~ShenandoahRootEvacuator() {
|
|
|
|
delete _evacuation_tasks;
|
2019-04-02 23:00:22 +02:00
|
|
|
if (ShenandoahStringDedup::is_enabled()) {
|
|
|
|
StringDedup::gc_epilogue();
|
|
|
|
}
|
2019-05-02 09:49:52 -04:00
|
|
|
|
|
|
|
ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
|
|
|
|
assert(_weak_processor_timings.max_threads() == n_workers(), "Must match");
|
|
|
|
ShenandoahTimingConverter::weak_processing_timing_to_shenandoah_timing(&_weak_processor_timings,
|
|
|
|
worker_times);
|
|
|
|
|
2018-12-10 15:47:44 +01:00
|
|
|
ShenandoahHeap::heap()->phase_timings()->record_workers_end(_phase);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShenandoahRootEvacuator::process_evacuate_roots(OopClosure* oops,
|
|
|
|
CodeBlobClosure* blobs,
|
|
|
|
uint worker_id) {
|
|
|
|
|
2019-05-02 09:49:52 -04:00
|
|
|
AlwaysTrueClosure always_true;
|
2018-12-10 15:47:44 +01:00
|
|
|
ShenandoahWorkerTimings* worker_times = ShenandoahHeap::heap()->phase_timings()->worker_times();
|
|
|
|
{
|
|
|
|
bool is_par = n_workers() > 1;
|
|
|
|
ResourceMark rm;
|
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::ThreadRoots, worker_id);
|
|
|
|
Threads::possibly_parallel_oops_do(is_par, oops, NULL);
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:49:52 -04:00
|
|
|
{
|
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::CLDGRoots, worker_id);
|
|
|
|
CLDToOopClosure clds(oops, ClassLoaderData::_claim_strong);
|
|
|
|
_cld_iterator.root_cld_do(&clds, &clds);
|
|
|
|
}
|
|
|
|
|
2018-12-10 15:47:44 +01:00
|
|
|
if (blobs != NULL) {
|
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::CodeCacheRoots, worker_id);
|
|
|
|
_coderoots_cset_iterator.possibly_parallel_blobs_do(blobs);
|
|
|
|
}
|
|
|
|
|
2019-04-02 23:00:22 +02:00
|
|
|
if (ShenandoahStringDedup::is_enabled()) {
|
2019-05-02 09:49:52 -04:00
|
|
|
ShenandoahStringDedup::parallel_oops_do(&always_true, oops, worker_id);
|
2019-04-02 23:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_evacuation_tasks->try_claim_task(SHENANDOAH_EVAC_Universe_oops_do)) {
|
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::UniverseRoots, worker_id);
|
|
|
|
Universe::oops_do(oops);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_evacuation_tasks->try_claim_task(SHENANDOAH_EVAC_Management_oops_do)) {
|
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::ManagementRoots, worker_id);
|
|
|
|
Management::oops_do(oops);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_evacuation_tasks->try_claim_task(SHENANDOAH_EVAC_jvmti_oops_do)) {
|
2018-12-10 15:47:44 +01:00
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::JVMTIRoots, worker_id);
|
2019-04-02 23:00:22 +02:00
|
|
|
JvmtiExport::oops_do(oops);
|
|
|
|
ShenandoahForwardedIsAliveClosure is_alive;
|
2018-12-10 15:47:44 +01:00
|
|
|
JvmtiExport::weak_oops_do(&is_alive, oops);
|
|
|
|
}
|
2019-04-02 23:00:22 +02:00
|
|
|
|
2019-05-02 09:49:52 -04:00
|
|
|
if (_evacuation_tasks->try_claim_task(SHENANDOAH_EVAC_JNIHandles_oops_do)) {
|
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::JNIRoots, worker_id);
|
|
|
|
JNIHandles::oops_do(oops);
|
|
|
|
}
|
|
|
|
|
2019-04-02 23:00:22 +02:00
|
|
|
if (_evacuation_tasks->try_claim_task(SHENANDOAH_EVAC_SystemDictionary_oops_do)) {
|
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::SystemDictionaryRoots, worker_id);
|
|
|
|
SystemDictionary::oops_do(oops);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_evacuation_tasks->try_claim_task(SHENANDOAH_EVAC_ObjectSynchronizer_oops_do)) {
|
|
|
|
ShenandoahWorkerTimingsTracker timer(worker_times, ShenandoahPhaseTimings::ObjectSynchronizerRoots, worker_id);
|
|
|
|
ObjectSynchronizer::oops_do(oops);
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:49:52 -04:00
|
|
|
_weak_processor_task.work<AlwaysTrueClosure, OopClosure>(worker_id, &always_true, oops);
|
2018-12-10 15:47:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|