Skip to content
Permalink
Browse files
8262398: Shenandoah: Disable nmethod barrier and stack watermark when…
… running with passive mode

Reviewed-by: rkennke, shade
  • Loading branch information
zhengyu123 committed Mar 17, 2021
1 parent 4f4ca0e commit 7674da437975d261894a9f471bbb737e0b630f82
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 18 deletions.
@@ -60,6 +60,8 @@ void ShenandoahIUMode::initialize_flags() const {
SHENANDOAH_CHECK_FLAG_SET(ShenandoahIUBarrier);
SHENANDOAH_CHECK_FLAG_SET(ShenandoahCASBarrier);
SHENANDOAH_CHECK_FLAG_SET(ShenandoahCloneBarrier);
SHENANDOAH_CHECK_FLAG_SET(ShenandoahNMethodBarrier);
SHENANDOAH_CHECK_FLAG_SET(ShenandoahStackWatermarkBarrier);
}

ShenandoahHeuristics* ShenandoahIUMode::initialize_heuristics() const {
@@ -48,6 +48,8 @@ void ShenandoahPassiveMode::initialize_flags() const {
SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahIUBarrier);
SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahCASBarrier);
SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahCloneBarrier);
SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahNMethodBarrier);
SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahStackWatermarkBarrier);

// Final configuration checks
// No barriers are required to run.
@@ -48,6 +48,8 @@ void ShenandoahSATBMode::initialize_flags() const {
SHENANDOAH_CHECK_FLAG_SET(ShenandoahSATBBarrier);
SHENANDOAH_CHECK_FLAG_SET(ShenandoahCASBarrier);
SHENANDOAH_CHECK_FLAG_SET(ShenandoahCloneBarrier);
SHENANDOAH_CHECK_FLAG_SET(ShenandoahNMethodBarrier);
SHENANDOAH_CHECK_FLAG_SET(ShenandoahStackWatermarkBarrier);
}

ShenandoahHeuristics* ShenandoahSATBMode::initialize_heuristics() const {
@@ -44,7 +44,7 @@ ShenandoahBarrierSet::ShenandoahBarrierSet(ShenandoahHeap* heap) :
BarrierSet(make_barrier_set_assembler<ShenandoahBarrierSetAssembler>(),
make_barrier_set_c1<ShenandoahBarrierSetC1>(),
make_barrier_set_c2<ShenandoahBarrierSetC2>(),
new ShenandoahBarrierSetNMethod(heap),
ShenandoahNMethodBarrier ? new ShenandoahBarrierSetNMethod(heap) : NULL,
BarrierSet::FakeRtti(BarrierSet::ShenandoahBarrierSet)),
_heap(heap),
_satb_mark_queue_buffer_allocator("SATB Buffer Allocator", ShenandoahSATBBufferSize),
@@ -101,9 +101,11 @@ void ShenandoahBarrierSet::on_thread_attach(Thread *thread) {
ShenandoahThreadLocalData::initialize_gclab(thread);
ShenandoahThreadLocalData::set_disarmed_value(thread, ShenandoahCodeRoots::disarmed_value());

JavaThread* const jt = thread->as_Java_thread();
StackWatermark* const watermark = new ShenandoahStackWatermark(jt);
StackWatermarkSet::add_watermark(jt, watermark);
if (ShenandoahStackWatermarkBarrier) {
JavaThread* const jt = thread->as_Java_thread();
StackWatermark* const watermark = new ShenandoahStackWatermark(jt);
StackWatermarkSet::add_watermark(jt, watermark);
}
}
}

@@ -117,13 +119,14 @@ void ShenandoahBarrierSet::on_thread_detach(Thread *thread) {
}

// SATB protocol requires to keep alive reacheable oops from roots at the beginning of GC
ShenandoahHeap* const heap = ShenandoahHeap::heap();
if (heap->is_concurrent_mark_in_progress()) {
ShenandoahKeepAliveClosure oops;
StackWatermarkSet::finish_processing(thread->as_Java_thread(), &oops, StackWatermarkKind::gc);
} else if (heap->is_concurrent_weak_root_in_progress() && heap->is_evacuation_in_progress()) {
ShenandoahContextEvacuateUpdateRootsClosure oops;
StackWatermarkSet::finish_processing(thread->as_Java_thread(), &oops, StackWatermarkKind::gc);
if (ShenandoahStackWatermarkBarrier) {
if (_heap->is_concurrent_mark_in_progress()) {
ShenandoahKeepAliveClosure oops;
StackWatermarkSet::finish_processing(thread->as_Java_thread(), &oops, StackWatermarkKind::gc);
} else if (_heap->is_concurrent_weak_root_in_progress() && _heap->is_evacuation_in_progress()) {
ShenandoahContextEvacuateUpdateRootsClosure oops;
StackWatermarkSet::finish_processing(thread->as_Java_thread(), &oops, StackWatermarkKind::gc);
}
}
}
}
@@ -179,8 +179,10 @@ class ShenandoahDisarmNMethodsTask : public AbstractGangTask {
};

void ShenandoahCodeRoots::disarm_nmethods() {
ShenandoahDisarmNMethodsTask task;
ShenandoahHeap::heap()->workers()->run_task(&task);
if (ShenandoahNMethodBarrier) {
ShenandoahDisarmNMethodsTask task;
ShenandoahHeap::heap()->workers()->run_task(&task);
}
}

class ShenandoahNMethodUnlinkClosure : public NMethodClosure {
@@ -402,7 +402,7 @@ jint ShenandoahHeap::initialize() {
return JNI_OK;
}

void ShenandoahHeap::initialize_heuristics() {
void ShenandoahHeap::initialize_mode() {
if (ShenandoahGCMode != NULL) {
if (strcmp(ShenandoahGCMode, "satb") == 0) {
_gc_mode = new ShenandoahSATBMode();
@@ -427,7 +427,10 @@ void ShenandoahHeap::initialize_heuristics() {
err_msg("GC mode \"%s\" is experimental, and must be enabled via -XX:+UnlockExperimentalVMOptions.",
_gc_mode->name()));
}
}

void ShenandoahHeap::initialize_heuristics() {
assert(_gc_mode != NULL, "Must be initialized");
_heuristics = _gc_mode->initialize_heuristics();

if (_heuristics->is_diagnostic() && !UnlockDiagnosticVMOptions) {
@@ -462,6 +465,7 @@ ShenandoahHeap::ShenandoahHeap(ShenandoahCollectorPolicy* policy) :
_update_refs_iterator(this),
_control_thread(NULL),
_shenandoah_policy(policy),
_gc_mode(NULL),
_heuristics(NULL),
_free_set(NULL),
_pacer(NULL),
@@ -484,6 +488,8 @@ ShenandoahHeap::ShenandoahHeap(ShenandoahCollectorPolicy* policy) :
_liveness_cache(NULL),
_collection_set(NULL)
{
// Initialize GC mode early, so we can adjust barrier support
initialize_mode();
BarrierSet::set_barrier_set(new ShenandoahBarrierSet(this));

_max_workers = MAX2(_max_workers, 1U);
@@ -148,6 +148,7 @@ class ShenandoahHeap : public CollectedHeap {
ShenandoahHeap(ShenandoahCollectorPolicy* policy);
jint initialize();
void post_initialize();
void initialize_mode();
void initialize_heuristics();

void initialize_serviceability();
@@ -79,8 +79,9 @@ void ShenandoahNMethod::heal_nmethod_metadata(ShenandoahNMethod* nmethod_data) {

void ShenandoahNMethod::disarm_nmethod(nmethod* nm) {
BarrierSetNMethod* const bs = BarrierSet::barrier_set()->barrier_set_nmethod();
assert(bs != NULL, "Sanity");
if (bs->is_armed(nm)) {
assert(bs != NULL || !ShenandoahNMethodBarrier,
"Must have nmethod barrier for concurrent GC");
if (bs != NULL && bs->is_armed(nm)) {
bs->disarm(nm);
}
}
@@ -292,7 +292,7 @@ ShenandoahRootAdjuster::ShenandoahRootAdjuster(uint n_workers, ShenandoahPhaseTi
void ShenandoahRootAdjuster::roots_do(uint worker_id, OopClosure* oops) {
CodeBlobToOopClosure code_blob_cl(oops, CodeBlobToOopClosure::FixRelocations);
ShenandoahCodeBlobAndDisarmClosure blobs_and_disarm_Cl(oops);
CodeBlobToOopClosure* adjust_code_closure = ClassUnloading ?
CodeBlobToOopClosure* adjust_code_closure = (ClassUnloading && ShenandoahNMethodBarrier) ?
static_cast<CodeBlobToOopClosure*>(&blobs_and_disarm_Cl) :
static_cast<CodeBlobToOopClosure*>(&code_blob_cl);
CLDToOopClosure adjust_cld_closure(oops, ClassLoaderData::_claim_strong);
@@ -176,7 +176,7 @@ 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);
ShenandoahCodeBlobAndDisarmClosure blobs_and_disarm_Cl(keep_alive);
CodeBlobToOopClosure* codes_cl = ClassUnloading ?
CodeBlobToOopClosure* codes_cl = (ClassUnloading && ShenandoahNMethodBarrier) ?
static_cast<CodeBlobToOopClosure*>(&blobs_and_disarm_Cl) :
static_cast<CodeBlobToOopClosure*>(&update_blobs);

@@ -352,6 +352,12 @@
product(bool, ShenandoahLoadRefBarrier, true, DIAGNOSTIC, \
"Turn on/off load-reference barriers in Shenandoah") \
\
product(bool, ShenandoahNMethodBarrier, true, DIAGNOSTIC, \
"Turn on/off NMethod entry barriers in Shenandoah") \
\
product(bool, ShenandoahStackWatermarkBarrier, true, DIAGNOSTIC, \
"Turn on/off stack watermark barriers in Shenandoah") \
\
develop(bool, ShenandoahVerifyOptoBarriers, false, \
"Verify no missing barriers in C2.") \
\
@@ -46,6 +46,8 @@ public static void main(String[] args) throws Exception {
new String[] { "ShenandoahSATBBarrier", "ShenandoahIUBarrier" },
new String[] { "ShenandoahCASBarrier" },
new String[] { "ShenandoahCloneBarrier" },
new String[] { "ShenandoahNMethodBarrier" },
new String[] { "ShenandoahStackWatermarkBarrier" }
};

int size = 1;
@@ -42,12 +42,16 @@ public static void main(String[] args) throws Exception {
"ShenandoahSATBBarrier",
"ShenandoahCASBarrier",
"ShenandoahCloneBarrier",
"ShenandoahNMethodBarrier",
"ShenandoahStackWatermarkBarrier",
};
String[] iu = {
"ShenandoahLoadRefBarrier",
"ShenandoahIUBarrier",
"ShenandoahCASBarrier",
"ShenandoahCloneBarrier",
"ShenandoahNMethodBarrier",
"ShenandoahStackWatermarkBarrier",
};

shouldFailAll("-XX:ShenandoahGCHeuristics=adaptive", concurrent);

0 comments on commit 7674da4

Please sign in to comment.