Skip to content

Commit

Permalink
8262398: Shenandoah: Disable nmethod barrier and stack watermark when…
Browse files Browse the repository at this point in the history
… running with passive mode

Reviewed-by: rkennke, shade
  • Loading branch information
zhengyu123 committed Mar 17, 2021
1 parent 4f4ca0e commit 7674da4
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/hotspot/share/gc/shenandoah/mode/shenandoahIUMode.cpp
Expand Up @@ -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 {
Expand Down
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/gc/shenandoah/mode/shenandoahSATBMode.cpp
Expand Up @@ -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 {
Expand Down
25 changes: 14 additions & 11 deletions src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -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);
}
}
}

Expand All @@ -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);
}
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.cpp
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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),
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp
Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/hotspot/share/gc/shenandoah/shenandoahNMethod.inline.hpp
Expand Up @@ -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);
}
}
Expand Down
Expand Up @@ -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);
Expand Down
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions src/hotspot/share/gc/shenandoah/shenandoah_globals.hpp
Expand Up @@ -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.") \
\
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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);
Expand Down

1 comment on commit 7674da4

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.