Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/hotspot/share/gc/shenandoah/shenandoahClosures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ class ShenandoahCleanUpdateWeakOopsClosure : public OopClosure {
};

class ShenandoahNMethodAndDisarmClosure : public NMethodToOopClosure {
private:
BarrierSetNMethod* const _bs;

public:
inline ShenandoahNMethodAndDisarmClosure(OopClosure* cl);
inline void do_nmethod(nmethod* nm);
Expand Down
6 changes: 2 additions & 4 deletions src/hotspot/share/gc/shenandoah/shenandoahClosures.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,13 @@ void ShenandoahCleanUpdateWeakOopsClosure<CONCURRENT, IsAlive, KeepAlive>::do_oo
}

ShenandoahNMethodAndDisarmClosure::ShenandoahNMethodAndDisarmClosure(OopClosure* cl) :
NMethodToOopClosure(cl, true /* fix_relocations */),
_bs(BarrierSet::barrier_set()->barrier_set_nmethod()) {
}
NMethodToOopClosure(cl, true /* fix_relocations */) {}

void ShenandoahNMethodAndDisarmClosure::do_nmethod(nmethod* nm) {
assert(nm != nullptr, "Sanity");
assert(!ShenandoahNMethod::gc_data(nm)->is_unregistered(), "Should not be here");
NMethodToOopClosure::do_nmethod(nm);
_bs->disarm(nm);
ShenandoahNMethod::disarm_nmethod(nm);
}


Expand Down
37 changes: 4 additions & 33 deletions src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,6 @@
ShenandoahNMethodTable* ShenandoahCodeRoots::_nmethod_table;
int ShenandoahCodeRoots::_disarmed_value = 1;

bool ShenandoahCodeRoots::use_nmethod_barriers_for_mark() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there diagnostic value in having the capability to not use nmethod barriers? Would we ever turn them off for passive mode?

Copy link
Copy Markdown
Member Author

@shipilev shipilev Apr 15, 2026

Choose a reason for hiding this comment

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

I don't think there is a diagnostic value in not having nmethod entry barriers. At this point, they are essential part of the Hotspot (GC) infrastructure. Even the STW mode, including passive, uses them to deal with continuations:

void ShenandoahSTWMark::mark() {
  ...
  // Arm all nmethods. Even though this is STW mark, some marking code
  // piggybacks on nmethod barriers for special instances.
  ShenandoahCodeRoots::arm_nmethods();
  ...
}

// Continuations need nmethod barriers for scanning stack chunk nmethods.
if (Continuations::enabled()) return true;

// Concurrent class unloading needs nmethod barriers.
// When a nmethod is about to be executed, we need to make sure that all its
// metadata are marked. The alternative is to remark thread roots at final mark
// pause, which would cause latency issues.
if (ShenandoahHeap::heap()->unload_classes()) return true;

// Otherwise, we can go without nmethod barriers.
return false;
}

void ShenandoahCodeRoots::initialize() {
_nmethod_table = new ShenandoahNMethodTable();
}
Expand All @@ -68,27 +54,14 @@ void ShenandoahCodeRoots::unregister_nmethod(nmethod* nm) {
_nmethod_table->unregister_nmethod(nm);
}

void ShenandoahCodeRoots::arm_nmethods_for_mark() {
if (use_nmethod_barriers_for_mark()) {
BarrierSet::barrier_set()->barrier_set_nmethod()->arm_all_nmethods();
}
}

void ShenandoahCodeRoots::arm_nmethods_for_evac() {
void ShenandoahCodeRoots::arm_nmethods() {
BarrierSet::barrier_set()->barrier_set_nmethod()->arm_all_nmethods();
}

class ShenandoahDisarmNMethodClosure : public NMethodClosure {
private:
BarrierSetNMethod* const _bs;

public:
ShenandoahDisarmNMethodClosure() :
_bs(BarrierSet::barrier_set()->barrier_set_nmethod()) {
}

virtual void do_nmethod(nmethod* nm) {
_bs->disarm(nm);
ShenandoahNMethod::disarm_nmethod(nm);
}
};

Expand All @@ -111,10 +84,8 @@ class ShenandoahDisarmNMethodsTask : public WorkerTask {
};

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

class ShenandoahNMethodUnlinkClosure : public NMethodClosure {
Expand Down
5 changes: 1 addition & 4 deletions src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,11 @@ class ShenandoahCodeRoots : public AllStatic {
// Concurrent nmethod unloading support
static void unlink(WorkerThreads* workers, bool unloading_occurred);
static void purge();
static void arm_nmethods_for_mark();
static void arm_nmethods_for_evac();
static void arm_nmethods();
static void disarm_nmethods();
static int disarmed_value() { return _disarmed_value; }
static int* disarmed_value_address() { return &_disarmed_value; }

static bool use_nmethod_barriers_for_mark();

private:
static ShenandoahNMethodTable* _nmethod_table;
static int _disarmed_value;
Expand Down
17 changes: 6 additions & 11 deletions src/hotspot/share/gc/shenandoah/shenandoahConcurrentGC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,8 @@ void ShenandoahConcurrentGC::op_init_mark() {
// Make above changes visible to worker threads
OrderAccess::fence();

// Arm nmethods for concurrent mark
ShenandoahCodeRoots::arm_nmethods_for_mark();

// Arm nmethods/stack for concurrent processing
ShenandoahCodeRoots::arm_nmethods();
ShenandoahStackWatermark::change_epoch_id();

{
Expand Down Expand Up @@ -782,7 +781,7 @@ void ShenandoahConcurrentGC::op_final_mark() {
heap->set_has_forwarded_objects(true);

// Arm nmethods/stack for concurrent processing
ShenandoahCodeRoots::arm_nmethods_for_evac();
ShenandoahCodeRoots::arm_nmethods();
ShenandoahStackWatermark::change_epoch_id();

} else {
Expand Down Expand Up @@ -1012,23 +1011,19 @@ void ShenandoahConcurrentGC::op_class_unloading() {

class ShenandoahEvacUpdateCodeCacheClosure : public NMethodClosure {
private:
BarrierSetNMethod* const _bs;
ShenandoahEvacuateUpdateMetadataClosure _cl;

public:
ShenandoahEvacUpdateCodeCacheClosure() :
_bs(BarrierSet::barrier_set()->barrier_set_nmethod()),
_cl() {
}
ShenandoahEvacUpdateCodeCacheClosure() : _cl() {}

void do_nmethod(nmethod* n) {
ShenandoahNMethod* data = ShenandoahNMethod::gc_data(n);
ShenandoahNMethodLocker locker(data->lock());
// Setup EvacOOM scope below reentrant lock to avoid deadlock with
// nmethod_entry_barrier
ShenandoahEvacOOMScope oom;
data->oops_do(&_cl, true/*fix relocation*/);
_bs->disarm(n);
data->oops_do(&_cl, /* fix_relocations = */ true);
ShenandoahNMethod::disarm_nmethod(n);
}
};

Expand Down
5 changes: 1 addition & 4 deletions src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,6 @@ ShenandoahRootAdjuster::ShenandoahRootAdjuster(uint n_workers, ShenandoahPhaseTi
void ShenandoahRootAdjuster::roots_do(uint worker_id, OopClosure* oops) {
NMethodToOopClosure code_blob_cl(oops, NMethodToOopClosure::FixRelocations);
ShenandoahNMethodAndDisarmClosure nmethods_and_disarm_Cl(oops);
NMethodToOopClosure* adjust_code_closure = ShenandoahCodeRoots::use_nmethod_barriers_for_mark() ?
static_cast<NMethodToOopClosure*>(&nmethods_and_disarm_Cl) :
static_cast<NMethodToOopClosure*>(&code_blob_cl);
CLDToOopClosure adjust_cld_closure(oops, ClassLoaderData::_claim_strong);

// Process light-weight/limited parallel roots then
Expand All @@ -211,7 +208,7 @@ void ShenandoahRootAdjuster::roots_do(uint worker_id, OopClosure* oops) {
_cld_roots.cld_do(&adjust_cld_closure, worker_id);

// Process heavy-weight/fully parallel roots the last
_code_roots.nmethods_do(adjust_code_closure, worker_id);
_code_roots.nmethods_do(&nmethods_and_disarm_Cl, worker_id);
_thread_roots.oops_do(oops, nullptr, worker_id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,6 @@ template <typename IsAlive, typename KeepAlive>
void ShenandoahRootUpdater::roots_do(uint worker_id, IsAlive* is_alive, KeepAlive* keep_alive) {
NMethodToOopClosure update_nmethods(keep_alive, NMethodToOopClosure::FixRelocations);
ShenandoahNMethodAndDisarmClosure nmethods_and_disarm_Cl(keep_alive);
NMethodToOopClosure* codes_cl = ShenandoahCodeRoots::use_nmethod_barriers_for_mark() ?
static_cast<NMethodToOopClosure*>(&nmethods_and_disarm_Cl) :
static_cast<NMethodToOopClosure*>(&update_nmethods);

CLDToOopClosure clds(keep_alive, ClassLoaderData::_claim_strong);

// Process light-weight/limited parallel roots then
Expand All @@ -184,7 +180,7 @@ void ShenandoahRootUpdater::roots_do(uint worker_id, IsAlive* is_alive, KeepAliv
_cld_roots.cld_do(&clds, worker_id);

// Process heavy-weight/fully parallel roots the last
_code_roots.nmethods_do(codes_cl, worker_id);
_code_roots.nmethods_do(&nmethods_and_disarm_Cl, worker_id);
_thread_roots.oops_do(keep_alive, nullptr, worker_id);
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/shenandoah/shenandoahSTWMark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void ShenandoahSTWMark::mark() {

// Arm all nmethods. Even though this is STW mark, some marking code
// piggybacks on nmethod barriers for special instances.
ShenandoahCodeRoots::arm_nmethods_for_mark();
ShenandoahCodeRoots::arm_nmethods();

// Weak reference processing
ShenandoahReferenceProcessor* rp = _generation->ref_processor();
Expand Down