2019-03-28 13:53:41 -04:00
|
|
|
/*
|
2020-01-10 07:21:32 -05:00
|
|
|
* Copyright (c) 2019, 2020, Red Hat, Inc. All rights reserved.
|
2020-01-14 19:27:03 -08:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2019-03-28 13:53:41 -04: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SHARE_GC_SHENANDOAH_SHENANDOAHROOTPROCESSOR_INLINE_HPP
|
|
|
|
#define SHARE_GC_SHENANDOAH_SHENANDOAHROOTPROCESSOR_INLINE_HPP
|
|
|
|
|
2019-06-19 08:52:15 -04:00
|
|
|
#include "classfile/classLoaderDataGraph.hpp"
|
2019-06-24 11:46:46 -04:00
|
|
|
#include "classfile/stringTable.hpp"
|
|
|
|
#include "classfile/systemDictionary.hpp"
|
2019-06-19 08:52:15 -04:00
|
|
|
#include "gc/shared/oopStorageParState.inline.hpp"
|
2019-11-27 11:52:57 -05:00
|
|
|
#include "gc/shenandoah/shenandoahClosures.inline.hpp"
|
|
|
|
#include "gc/shenandoah/shenandoahConcurrentRoots.hpp"
|
2020-05-04 19:09:07 +02:00
|
|
|
#include "gc/shenandoah/shenandoahHeap.inline.hpp"
|
2020-03-06 17:03:42 +01:00
|
|
|
#include "gc/shenandoah/shenandoahPhaseTimings.hpp"
|
2019-03-28 13:53:41 -04:00
|
|
|
#include "gc/shenandoah/shenandoahRootProcessor.hpp"
|
2019-05-29 15:25:21 +02:00
|
|
|
#include "gc/shenandoah/shenandoahUtils.hpp"
|
2020-05-11 18:33:24 +02:00
|
|
|
#include "gc/shenandoah/heuristics/shenandoahHeuristics.hpp"
|
2019-05-22 10:48:46 +02:00
|
|
|
#include "memory/resourceArea.hpp"
|
2019-06-24 11:46:46 -04:00
|
|
|
#include "prims/resolvedMethodTable.hpp"
|
2019-06-20 10:12:31 -04:00
|
|
|
#include "runtime/safepoint.hpp"
|
2019-03-28 13:53:41 -04:00
|
|
|
|
2019-06-24 11:46:46 -04:00
|
|
|
template <bool CONCURRENT>
|
2020-04-30 18:05:53 +02:00
|
|
|
inline ShenandoahVMRoot<CONCURRENT>::ShenandoahVMRoot(OopStorage* storage,
|
|
|
|
ShenandoahPhaseTimings::Phase phase, ShenandoahPhaseTimings::ParPhase par_phase) :
|
|
|
|
_itr(storage), _phase(phase), _par_phase(par_phase) {
|
2019-06-24 11:46:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template <bool CONCURRENT>
|
|
|
|
template <typename Closure>
|
2019-08-07 09:17:08 -04:00
|
|
|
inline void ShenandoahVMRoot<CONCURRENT>::oops_do(Closure* cl, uint worker_id) {
|
2020-04-30 18:05:55 +02:00
|
|
|
ShenandoahWorkerTimingsTracker timer(_phase, _par_phase, worker_id);
|
|
|
|
_itr.oops_do(cl);
|
2019-06-24 11:46:46 -04:00
|
|
|
}
|
|
|
|
|
2019-08-07 09:17:08 -04:00
|
|
|
template <bool CONCURRENT>
|
2020-04-30 18:05:53 +02:00
|
|
|
inline ShenandoahWeakRoot<CONCURRENT>::ShenandoahWeakRoot(OopStorage* storage,
|
|
|
|
ShenandoahPhaseTimings::Phase phase, ShenandoahPhaseTimings::ParPhase par_phase) :
|
|
|
|
ShenandoahVMRoot<CONCURRENT>(storage, phase, par_phase) {
|
2019-08-07 09:17:08 -04:00
|
|
|
}
|
|
|
|
|
2020-04-30 18:05:53 +02:00
|
|
|
inline ShenandoahWeakRoot<false>::ShenandoahWeakRoot(OopStorage* storage,
|
|
|
|
ShenandoahPhaseTimings::Phase phase, ShenandoahPhaseTimings::ParPhase par_phase) :
|
|
|
|
_itr(storage), _phase(phase), _par_phase(par_phase) {
|
2019-06-24 11:46:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename IsAliveClosure, typename KeepAliveClosure>
|
|
|
|
void ShenandoahWeakRoot<false /* concurrent */>::weak_oops_do(IsAliveClosure* is_alive, KeepAliveClosure* keep_alive, uint worker_id) {
|
2020-04-30 18:05:53 +02:00
|
|
|
ShenandoahWorkerTimingsTracker timer(_phase, _par_phase, worker_id);
|
2019-06-24 11:46:46 -04:00
|
|
|
_itr.weak_oops_do(is_alive, keep_alive);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <bool CONCURRENT>
|
|
|
|
ShenandoahWeakRoots<CONCURRENT>::ShenandoahWeakRoots() :
|
2019-08-22 13:47:14 +02:00
|
|
|
_jni_roots(OopStorageSet::jni_weak(), ShenandoahPhaseTimings::JNIWeakRoots),
|
|
|
|
_string_table_roots(OopStorageSet::string_table_weak(), ShenandoahPhaseTimings::StringTableRoots),
|
|
|
|
_resolved_method_table_roots(OopStorageSet::resolved_method_table_weak(), ShenandoahPhaseTimings::ResolvedMethodTableRoots),
|
|
|
|
_vm_roots(OopStorageSet::vm_weak(), ShenandoahPhaseTimings::VMWeakRoots) {
|
2019-06-24 11:46:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template <bool CONCURRENT>
|
|
|
|
template <typename Closure>
|
|
|
|
void ShenandoahWeakRoots<CONCURRENT>::oops_do(Closure* cl, uint worker_id) {
|
|
|
|
_jni_roots.oops_do(cl, worker_id);
|
|
|
|
_string_table_roots.oops_do(cl, worker_id);
|
|
|
|
_resolved_method_table_roots.oops_do(cl, worker_id);
|
|
|
|
_vm_roots.oops_do(cl, worker_id);
|
|
|
|
}
|
|
|
|
|
2020-04-30 18:05:53 +02:00
|
|
|
inline ShenandoahWeakRoots<false /* concurrent */>::ShenandoahWeakRoots(ShenandoahPhaseTimings::Phase phase) :
|
|
|
|
_jni_roots(OopStorageSet::jni_weak(), phase, ShenandoahPhaseTimings::JNIWeakRoots),
|
|
|
|
_string_table_roots(OopStorageSet::string_table_weak(), phase, ShenandoahPhaseTimings::StringTableRoots),
|
|
|
|
_resolved_method_table_roots(OopStorageSet::resolved_method_table_weak(), phase, ShenandoahPhaseTimings::ResolvedMethodTableRoots),
|
|
|
|
_vm_roots(OopStorageSet::vm_weak(), phase, ShenandoahPhaseTimings::VMWeakRoots) {
|
2019-06-24 11:46:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename IsAliveClosure, typename KeepAliveClosure>
|
|
|
|
void ShenandoahWeakRoots<false /* concurrent*/>::weak_oops_do(IsAliveClosure* is_alive, KeepAliveClosure* keep_alive, uint worker_id) {
|
|
|
|
_jni_roots.weak_oops_do(is_alive, keep_alive, worker_id);
|
|
|
|
_string_table_roots.weak_oops_do(is_alive, keep_alive, worker_id);
|
|
|
|
_resolved_method_table_roots.weak_oops_do(is_alive, keep_alive, worker_id);
|
|
|
|
_vm_roots.weak_oops_do(is_alive, keep_alive, worker_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Closure>
|
|
|
|
void ShenandoahWeakRoots<false /* concurrent */>::oops_do(Closure* cl, uint worker_id) {
|
|
|
|
AlwaysTrueClosure always_true;
|
|
|
|
weak_oops_do<AlwaysTrueClosure, Closure>(&always_true, cl, worker_id);
|
|
|
|
}
|
|
|
|
|
2019-06-19 08:52:15 -04:00
|
|
|
template <bool CONCURRENT>
|
2020-04-30 18:05:53 +02:00
|
|
|
ShenandoahVMRoots<CONCURRENT>::ShenandoahVMRoots(ShenandoahPhaseTimings::Phase phase) :
|
|
|
|
_jni_handle_roots(OopStorageSet::jni_global(), phase, ShenandoahPhaseTimings::JNIRoots),
|
|
|
|
_vm_global_roots(OopStorageSet::vm_global(), phase, ShenandoahPhaseTimings::VMGlobalRoots) {
|
2019-06-19 08:52:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template <bool CONCURRENT>
|
|
|
|
template <typename T>
|
2019-08-07 09:17:08 -04:00
|
|
|
void ShenandoahVMRoots<CONCURRENT>::oops_do(T* cl, uint worker_id) {
|
|
|
|
_jni_handle_roots.oops_do(cl, worker_id);
|
|
|
|
_vm_global_roots.oops_do(cl, worker_id);
|
2019-06-19 08:52:15 -04:00
|
|
|
}
|
|
|
|
|
2019-06-24 14:13:49 -04:00
|
|
|
template <bool CONCURRENT, bool SINGLE_THREADED>
|
2020-06-02 14:27:18 +02:00
|
|
|
ShenandoahClassLoaderDataRoots<CONCURRENT, SINGLE_THREADED>::ShenandoahClassLoaderDataRoots(ShenandoahPhaseTimings::Phase phase, uint n_workers) :
|
|
|
|
_semaphore(worker_count(n_workers)),
|
2020-04-30 18:05:53 +02:00
|
|
|
_phase(phase) {
|
2019-06-20 10:12:31 -04:00
|
|
|
if (!SINGLE_THREADED) {
|
|
|
|
ClassLoaderDataGraph::clear_claimed_marks();
|
|
|
|
}
|
2019-06-24 14:13:49 -04:00
|
|
|
if (CONCURRENT) {
|
|
|
|
ClassLoaderDataGraph_lock->lock();
|
|
|
|
}
|
2019-06-20 10:12:31 -04:00
|
|
|
}
|
|
|
|
|
2019-06-24 14:13:49 -04:00
|
|
|
template <bool CONCURRENT, bool SINGLE_THREADED>
|
|
|
|
ShenandoahClassLoaderDataRoots<CONCURRENT, SINGLE_THREADED>::~ShenandoahClassLoaderDataRoots() {
|
|
|
|
if (CONCURRENT) {
|
|
|
|
ClassLoaderDataGraph_lock->unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <bool CONCURRENT, bool SINGLE_THREADED>
|
|
|
|
void ShenandoahClassLoaderDataRoots<CONCURRENT, SINGLE_THREADED>::always_strong_cld_do(CLDClosure* clds, uint worker_id) {
|
2019-06-20 10:12:31 -04:00
|
|
|
if (SINGLE_THREADED) {
|
|
|
|
assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");
|
|
|
|
assert(Thread::current()->is_VM_thread(), "Single threaded CLDG iteration can only be done by VM thread");
|
2019-06-20 18:29:34 -04:00
|
|
|
ClassLoaderDataGraph::always_strong_cld_do(clds);
|
2020-06-02 14:27:18 +02:00
|
|
|
} else if (_semaphore.try_acquire()) {
|
2020-04-30 18:05:55 +02:00
|
|
|
ShenandoahWorkerTimingsTracker timer(_phase, ShenandoahPhaseTimings::CLDGRoots, worker_id);
|
|
|
|
ClassLoaderDataGraph::always_strong_cld_do(clds);
|
2020-06-02 14:27:18 +02:00
|
|
|
_semaphore.claim_all();
|
2019-06-20 18:29:34 -04:00
|
|
|
}
|
|
|
|
}
|
2019-06-20 10:12:31 -04:00
|
|
|
|
2019-06-24 14:13:49 -04:00
|
|
|
template <bool CONCURRENT, bool SINGLE_THREADED>
|
|
|
|
void ShenandoahClassLoaderDataRoots<CONCURRENT, SINGLE_THREADED>::cld_do(CLDClosure* clds, uint worker_id) {
|
2019-06-20 18:29:34 -04:00
|
|
|
if (SINGLE_THREADED) {
|
|
|
|
assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");
|
|
|
|
assert(Thread::current()->is_VM_thread(), "Single threaded CLDG iteration can only be done by VM thread");
|
|
|
|
ClassLoaderDataGraph::cld_do(clds);
|
2020-06-02 14:27:18 +02:00
|
|
|
} else if (_semaphore.try_acquire()) {
|
2020-04-30 18:05:53 +02:00
|
|
|
ShenandoahWorkerTimingsTracker timer(_phase, ShenandoahPhaseTimings::CLDGRoots, worker_id);
|
2019-06-20 18:29:34 -04:00
|
|
|
ClassLoaderDataGraph::cld_do(clds);
|
2020-06-02 14:27:18 +02:00
|
|
|
_semaphore.claim_all();
|
2019-06-20 10:12:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-20 09:42:37 -04: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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-17 09:52:35 -04:00
|
|
|
template <typename IsAlive, typename KeepAlive>
|
|
|
|
void ShenandoahRootUpdater::roots_do(uint worker_id, IsAlive* is_alive, KeepAlive* keep_alive) {
|
|
|
|
CodeBlobToOopClosure update_blobs(keep_alive, CodeBlobToOopClosure::FixRelocations);
|
2019-11-27 11:52:57 -05:00
|
|
|
ShenandoahCodeBlobAndDisarmClosure blobs_and_disarm_Cl(keep_alive);
|
|
|
|
CodeBlobToOopClosure* codes_cl = ShenandoahConcurrentRoots::can_do_concurrent_class_unloading() ?
|
|
|
|
static_cast<CodeBlobToOopClosure*>(&blobs_and_disarm_Cl) :
|
|
|
|
static_cast<CodeBlobToOopClosure*>(&update_blobs);
|
|
|
|
|
2019-05-17 09:52:35 -04:00
|
|
|
CLDToOopClosure clds(keep_alive, ClassLoaderData::_claim_strong);
|
|
|
|
|
|
|
|
_serial_roots.oops_do(keep_alive, worker_id);
|
2019-08-07 09:17:08 -04:00
|
|
|
_vm_roots.oops_do(keep_alive, worker_id);
|
2019-03-28 13:53:41 -04:00
|
|
|
|
2019-06-20 18:29:34 -04:00
|
|
|
_cld_roots.cld_do(&clds, worker_id);
|
2019-12-11 14:01:00 -05:00
|
|
|
_code_roots.code_blobs_do(codes_cl, worker_id);
|
2019-11-27 11:52:57 -05:00
|
|
|
_thread_roots.oops_do(keep_alive, NULL, worker_id);
|
2019-05-17 09:52:35 -04:00
|
|
|
|
2019-06-24 11:46:46 -04:00
|
|
|
_serial_weak_roots.weak_oops_do(is_alive, keep_alive, worker_id);
|
|
|
|
_weak_roots.weak_oops_do(is_alive, keep_alive, worker_id);
|
2019-05-17 09:52:35 -04:00
|
|
|
_dedup_roots.oops_do(is_alive, keep_alive, worker_id);
|
2019-03-28 13:53:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SHARE_GC_SHENANDOAH_SHENANDOAHROOTPROCESSOR_INLINE_HPP
|