Skip to content

Commit

Permalink
8331573: Rename CollectedHeap::is_gc_active to be explicitly about ST…
Browse files Browse the repository at this point in the history
…W GCs

Reviewed-by: phh
Backport-of: 1eec30a6c03b7f4028405dc9bdb4d2a663b3987d
  • Loading branch information
shipilev committed May 31, 2024
1 parent 362ecac commit 2a21044
Show file tree
Hide file tree
Showing 27 changed files with 61 additions and 63 deletions.
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/g1/g1CollectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2486,7 +2486,7 @@ void G1CollectedHeap::expand_heap_after_young_collection(){

bool G1CollectedHeap::do_collection_pause_at_safepoint() {
assert_at_safepoint_on_vm_thread();
guarantee(!is_gc_active(), "collection is not reentrant");
guarantee(!is_stw_gc_active(), "collection is not reentrant");

if (GCLocker::check_active_before_gc()) {
return false;
Expand Down Expand Up @@ -2554,7 +2554,7 @@ void G1CollectedHeap::retire_tlabs() {
void G1CollectedHeap::do_collection_pause_at_safepoint_helper() {
ResourceMark rm;

IsGCActiveMark active_gc_mark;
IsSTWGCActiveMark active_gc_mark;
GCIdMark gc_id_mark;
SvcGCMarker sgcm(SvcGCMarker::MINOR);

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/g1/g1CollectedHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ class G1CollectedHeap : public CollectedHeap {
// false if unable to do the collection due to the GC locker being
// active, true otherwise.
// precondition: at safepoint on VM thread
// precondition: !is_gc_active()
// precondition: !is_stw_gc_active()
bool do_collection_pause_at_safepoint();

// Helper for do_collection_pause_at_safepoint, containing the guts
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/g1/g1FullGCScope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class G1FullGCScope : public StackObj {
SvcGCMarker _svc_marker;
STWGCTimer _timer;
G1FullGCTracer* _tracer;
IsGCActiveMark _active;
IsSTWGCActiveMark _active;
G1FullGCJFRTracerMark _tracer_mark;
ClearedAllSoftRefs _soft_refs;
G1FullGCMonitoringScope _monitoring_scope;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/g1/g1RemSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@ bool G1RemSet::clean_card_before_refine(CardValue** const card_ptr_addr) {

void G1RemSet::refine_card_concurrently(CardValue* const card_ptr,
const uint worker_id) {
assert(!_g1h->is_gc_active(), "Only call concurrently");
assert(!_g1h->is_stw_gc_active(), "Only call concurrently");
check_card_ptr(card_ptr, _ct);

// Construct the MemRegion representing the card.
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/g1/g1VMOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void VM_G1PauseConcurrent::doit() {

G1ConcGCMonitoringScope monitoring_scope(g1h->monitoring_support());
SvcGCMarker sgcm(SvcGCMarker::CONCURRENT);
IsGCActiveMark x;
IsSTWGCActiveMark x;

work();
}
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ void ParallelScavengeHeap::do_full_collection(bool clear_all_soft_refs) {
HeapWord* ParallelScavengeHeap::failed_mem_allocate(size_t size) {
assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
assert(Thread::current() == (Thread*)VMThread::vm_thread(), "should be in vm thread");
assert(!is_gc_active(), "not reentrant");
assert(!is_stw_gc_active(), "not reentrant");
assert(!Heap_lock->owned_by_self(), "this thread should not own the Heap_lock");

// We assume that allocation in eden will fail unless we collect.
Expand Down
10 changes: 5 additions & 5 deletions src/hotspot/share/gc/parallel/psParallelCompact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1688,9 +1688,9 @@ bool PSParallelCompact::invoke(bool maximum_heap_compaction) {
"should be in vm thread");

ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
assert(!heap->is_gc_active(), "not reentrant");
assert(!heap->is_stw_gc_active(), "not reentrant");

IsGCActiveMark mark;
IsSTWGCActiveMark mark;

if (ScavengeBeforeFullGC) {
PSScavenge::invoke_no_policy();
Expand Down Expand Up @@ -1921,7 +1921,7 @@ class PCAddThreadRootsMarkingTaskClosure : public ThreadClosure {
public:
PCAddThreadRootsMarkingTaskClosure(uint worker_id) : _worker_id(worker_id) { }
void do_thread(Thread* thread) {
assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");
assert(ParallelScavengeHeap::heap()->is_stw_gc_active(), "called outside gc");

ResourceMark rm;

Expand All @@ -1938,7 +1938,7 @@ class PCAddThreadRootsMarkingTaskClosure : public ThreadClosure {
};

void steal_marking_work(TaskTerminator& terminator, uint worker_id) {
assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");
assert(ParallelScavengeHeap::heap()->is_stw_gc_active(), "called outside gc");

ParCompactionManager* cm =
ParCompactionManager::gc_thread_compaction_manager(worker_id);
Expand Down Expand Up @@ -2401,7 +2401,7 @@ void PSParallelCompact::write_block_fill_histogram()
#endif // #ifdef ASSERT

static void compaction_with_stealing_work(TaskTerminator* terminator, uint worker_id) {
assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");
assert(ParallelScavengeHeap::heap()->is_stw_gc_active(), "called outside gc");

ParCompactionManager* cm =
ParCompactionManager::gc_thread_compaction_manager(worker_id);
Expand Down
10 changes: 5 additions & 5 deletions src/hotspot/share/gc/parallel/psScavenge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ParallelScavengeTracer PSScavenge::_gc_tracer;
CollectorCounters* PSScavenge::_counters = nullptr;

static void scavenge_roots_work(ParallelRootType::Value root_type, uint worker_id) {
assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");
assert(ParallelScavengeHeap::heap()->is_stw_gc_active(), "called outside gc");

PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(worker_id);
PSPromoteRootsClosure roots_to_old_closure(pm);
Expand Down Expand Up @@ -115,7 +115,7 @@ static void scavenge_roots_work(ParallelRootType::Value root_type, uint worker_i
}

static void steal_work(TaskTerminator& terminator, uint worker_id) {
assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");
assert(ParallelScavengeHeap::heap()->is_stw_gc_active(), "called outside gc");

PSPromotionManager* pm =
PSPromotionManager::gc_thread_promotion_manager(worker_id);
Expand Down Expand Up @@ -232,11 +232,11 @@ class ParallelScavengeRefProcProxyTask : public RefProcProxyTask {
bool PSScavenge::invoke() {
assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
assert(Thread::current() == (Thread*)VMThread::vm_thread(), "should be in vm thread");
assert(!ParallelScavengeHeap::heap()->is_gc_active(), "not reentrant");
assert(!ParallelScavengeHeap::heap()->is_stw_gc_active(), "not reentrant");

ParallelScavengeHeap* const heap = ParallelScavengeHeap::heap();
PSAdaptiveSizePolicy* policy = heap->size_policy();
IsGCActiveMark mark;
IsSTWGCActiveMark mark;

const bool scavenge_done = PSScavenge::invoke_no_policy();
const bool need_full_gc = !scavenge_done;
Expand Down Expand Up @@ -264,7 +264,7 @@ class PSThreadRootsTaskClosure : public ThreadClosure {
public:
PSThreadRootsTaskClosure(uint worker_id) : _worker_id(worker_id) { }
virtual void do_thread(Thread* thread) {
assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");
assert(ParallelScavengeHeap::heap()->is_stw_gc_active(), "called outside gc");

PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(_worker_id);
PSScavengeRootsClosure roots_closure(pm);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/shared/collectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ bool CollectedHeap::is_oop(oop object) const {
CollectedHeap::CollectedHeap() :
_capacity_at_last_gc(0),
_used_at_last_gc(0),
_is_gc_active(false),
_is_stw_gc_active(false),
_last_whole_heap_examined_time_ns(os::javaTimeNanos()),
_total_collections(0),
_total_full_collections(0),
Expand Down
12 changes: 5 additions & 7 deletions src/hotspot/share/gc/shared/collectedHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class ParallelObjectIterator : public StackObj {
class CollectedHeap : public CHeapObj<mtGC> {
friend class VMStructs;
friend class JVMCIVMStructs;
friend class IsGCActiveMark; // Block structured external access to _is_gc_active
friend class DisableIsGCActiveMark; // Disable current IsGCActiveMark
friend class IsSTWGCActiveMark; // Block structured external access to _is_stw_gc_active
friend class DisableIsSTWGCActiveMark; // Disable current IsSTWGCActiveMark
friend class MemAllocator;
friend class ParallelObjectIterator;

Expand All @@ -114,7 +114,7 @@ class CollectedHeap : public CHeapObj<mtGC> {
// Not used by all GCs
MemRegion _reserved;

bool _is_gc_active;
bool _is_stw_gc_active;

// (Minimum) Alignment reserve for TLABs and PLABs.
static size_t _lab_alignment_reserve;
Expand Down Expand Up @@ -382,10 +382,8 @@ class CollectedHeap : public CHeapObj<mtGC> {
// allocated object.
virtual bool requires_barriers(stackChunkOop obj) const = 0;

// Returns "true" iff there is a stop-world GC in progress. (I assume
// that it should answer "false" for the concurrent part of a concurrent
// collector -- dld).
bool is_gc_active() const { return _is_gc_active; }
// Returns "true" iff there is a stop-world GC in progress.
bool is_stw_gc_active() const { return _is_stw_gc_active; }

// Total number of GC collections (started)
unsigned int total_collections() const { return _total_collections; }
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/shared/genCollectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ void GenCollectedHeap::do_collection(bool full,
assert(my_thread->is_VM_thread(), "only VM thread");
assert(Heap_lock->is_locked(),
"the requesting thread should have the Heap_lock");
guarantee(!is_gc_active(), "collection is not reentrant");
guarantee(!is_stw_gc_active(), "collection is not reentrant");

if (GCLocker::check_active_before_gc()) {
return; // GC is disabled (e.g. JNI GetXXXCritical operation)
Expand All @@ -468,7 +468,7 @@ void GenCollectedHeap::do_collection(bool full,

ClearedAllSoftRefs casr(do_clear_all_soft_refs, soft_ref_policy());

AutoModifyRestore<bool> temporarily(_is_gc_active, true);
AutoModifyRestore<bool> temporarily(_is_stw_gc_active, true);

bool complete = full && (max_generation == OldGen);
bool old_collects_young = complete && !ScavengeBeforeFullGC;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/shared/genCollectedHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class GenCollectedHeap : public CollectedHeap {
_old_gen->update_gc_stats(current_generation, full);
}

bool no_gc_in_progress() { return !is_gc_active(); }
bool no_gc_in_progress() { return !is_stw_gc_active(); }

void prepare_for_verify() override;
void verify(VerifyOption option) override;
Expand Down
26 changes: 13 additions & 13 deletions src/hotspot/share/gc/shared/isGCActiveMark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@
#include "utilities/debug.hpp"

// This class provides a method for block structured setting of the
// _is_gc_active state without requiring accessors in CollectedHeap
// _is_stw_gc_active state without requiring accessors in CollectedHeap

IsGCActiveMark::IsGCActiveMark() {
IsSTWGCActiveMark::IsSTWGCActiveMark() {
CollectedHeap* heap = Universe::heap();
assert(!heap->is_gc_active(), "Not reentrant");
heap->_is_gc_active = true;
assert(!heap->is_stw_gc_active(), "Not reentrant");
heap->_is_stw_gc_active = true;
}

IsGCActiveMark::~IsGCActiveMark() {
IsSTWGCActiveMark::~IsSTWGCActiveMark() {
CollectedHeap* heap = Universe::heap();
assert(heap->is_gc_active(), "Sanity");
heap->_is_gc_active = false;
assert(heap->is_stw_gc_active(), "Sanity");
heap->_is_stw_gc_active = false;
}

DisableIsGCActiveMark::DisableIsGCActiveMark() {
DisableIsSTWGCActiveMark::DisableIsSTWGCActiveMark() {
CollectedHeap* heap = Universe::heap();
assert(heap->is_gc_active(), "Not reentrant");
heap->_is_gc_active = false;
assert(heap->is_stw_gc_active(), "Not reentrant");
heap->_is_stw_gc_active = false;
}

DisableIsGCActiveMark::~DisableIsGCActiveMark() {
DisableIsSTWGCActiveMark::~DisableIsSTWGCActiveMark() {
CollectedHeap* heap = Universe::heap();
assert(!heap->is_gc_active(), "Sanity");
heap->_is_gc_active = true;
assert(!heap->is_stw_gc_active(), "Sanity");
heap->_is_stw_gc_active = true;
}
14 changes: 7 additions & 7 deletions src/hotspot/share/gc/shared/isGCActiveMark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@
#include "memory/allocation.hpp"

// This class provides a method for block structured setting of the
// _is_gc_active state without requiring accessors in CollectedHeap
// _is_stw_gc_active state without requiring accessors in CollectedHeap

class IsGCActiveMark : public StackObj {
class IsSTWGCActiveMark : public StackObj {
public:
IsGCActiveMark();
~IsGCActiveMark();
IsSTWGCActiveMark();
~IsSTWGCActiveMark();
};

class DisableIsGCActiveMark : public StackObj {
class DisableIsSTWGCActiveMark : public StackObj {
public:
DisableIsGCActiveMark();
~DisableIsGCActiveMark();
DisableIsSTWGCActiveMark();
~DisableIsSTWGCActiveMark();
};

#endif // SHARE_GC_SHARED_ISGCACTIVEMARK_HPP
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/shared/memAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void MemAllocator::Allocation::verify_before() {
JavaThread* THREAD = _thread; // For exception macros.
assert(!HAS_PENDING_EXCEPTION, "Should not allocate with exception pending");
debug_only(check_for_valid_allocation_state());
assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed");
assert(!Universe::heap()->is_stw_gc_active(), "Allocation during GC pause not allowed");
}

#ifdef ASSERT
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/shared/vmStructs_gc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
nonstatic_field(CardTableBarrierSet, _card_table, CardTable*) \
\
nonstatic_field(CollectedHeap, _reserved, MemRegion) \
nonstatic_field(CollectedHeap, _is_gc_active, bool) \
nonstatic_field(CollectedHeap, _is_stw_gc_active, bool) \
nonstatic_field(CollectedHeap, _total_collections, unsigned int) \
\
nonstatic_field(ContiguousSpace, _compaction_top, HeapWord*) \
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/shenandoah/shenandoahUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class ShenandoahGCPauseMark : public StackObj {
ShenandoahHeap* const _heap;
const GCIdMark _gc_id_mark;
const SvcGCMarker _svc_gc_mark;
const IsGCActiveMark _is_gc_active_mark;
const IsSTWGCActiveMark _is_gc_active_mark;
TraceMemoryManagerStats _trace_pause;

public:
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/x/xDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class VM_XOperation : public VM_Operation {

// Setup GC id and active marker
GCIdMark gc_id_mark(_gc_id);
IsGCActiveMark gc_active_mark;
IsSTWGCActiveMark gc_active_mark;

// Verify before operation
XVerify::before_zoperation();
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/z/zGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ class VM_ZOperation : public VM_Operation {
virtual void doit() {
// Setup GC id and active marker
GCIdMark gc_id_mark(_gc_id);
IsGCActiveMark gc_active_mark;
IsSTWGCActiveMark gc_active_mark;

// Verify before operation
ZVerify::before_zoperation();
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/z/zVerify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ void ZVerify::after_mark() {
}
if (ZVerifyObjects) {
// Workaround OopMapCacheAlloc_lock reordering with the StackWatermark_lock
DisableIsGCActiveMark mark;
DisableIsSTWGCActiveMark mark;

objects(false /* verify_weaks */);
guarantee(zverify_broken_object == zaddress::null, "Verification failed");
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/jvmci/jvmciRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ static OopStorage* object_handles() {
}

jlong JVMCIRuntime::make_oop_handle(const Handle& obj) {
assert(!Universe::heap()->is_gc_active(), "can't extend the root set during GC");
assert(!Universe::heap()->is_stw_gc_active(), "can't extend the root set during GC pause");
assert(oopDesc::is_oop(obj()), "not an oop");

oop* ptr = OopHandle(object_handles(), obj()).ptr_raw();
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/memory/universe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,8 +1291,8 @@ bool Universe::release_fullgc_alot_dummy() {
return true;
}

bool Universe::is_gc_active() {
return heap()->is_gc_active();
bool Universe::is_stw_gc_active() {
return heap()->is_stw_gc_active();
}

bool Universe::is_in_heap(const void* p) {
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/memory/universe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class Universe: AllStatic {
// The particular choice of collected heap.
static CollectedHeap* heap() { return _collectedHeap; }

DEBUG_ONLY(static bool is_gc_active();)
DEBUG_ONLY(static bool is_stw_gc_active();)
DEBUG_ONLY(static bool is_in_heap(const void* p);)
DEBUG_ONLY(static bool is_in_heap_or_null(const void* p) { return p == nullptr || is_in_heap(p); })

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/oops/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ void Method::mask_for(int bci, InterpreterOopMap* mask) {
methodHandle h_this(Thread::current(), this);
// Only GC uses the OopMapCache during thread stack root scanning
// any other uses generate an oopmap but do not save it in the cache.
if (Universe::heap()->is_gc_active()) {
if (Universe::heap()->is_stw_gc_active()) {
method_holder()->mask_for(h_this, bci, mask);
} else {
OopMapCache::compute_one_oop_map(h_this, bci, mask);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/oops/oop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,6 @@ bool oopDesc::size_might_change() {
// the grey portion of an already copied array. This will cause the first
// disjunct below to fail if the two comparands are computed across such
// a concurrent change.
return Universe::heap()->is_gc_active() && is_objArray() && is_forwarded() && (UseParallelGC || UseG1GC);
return Universe::heap()->is_stw_gc_active() && is_objArray() && is_forwarded() && (UseParallelGC || UseG1GC);
}
#endif
2 changes: 1 addition & 1 deletion src/hotspot/share/prims/forte.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ void AsyncGetCallTrace(ASGCT_CallTrace *trace, jint depth, void* ucontext) {
return;
}

if (Universe::heap()->is_gc_active()) {
if (Universe::heap()->is_stw_gc_active()) {
trace->num_frames = ticks_GC_active; // -2
return;
}
Expand Down
Loading

1 comment on commit 2a21044

@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.