Skip to content

8360024: Reorganize GC VM operations and implement is_gc_operation #25896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions src/hotspot/share/cds/dynamicArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,11 @@ void DynamicArchiveBuilder::gather_array_klasses() {
log_debug(aot)("Total array klasses gathered for dynamic archive: %d", DynamicArchive::num_array_klasses());
}

class VM_PopulateDynamicDumpSharedSpace: public VM_GC_Sync_Operation {
class VM_PopulateDynamicDumpSharedSpace: public VM_Heap_Sync_Operation {
DynamicArchiveBuilder _builder;
public:
VM_PopulateDynamicDumpSharedSpace(const char* archive_name)
: VM_GC_Sync_Operation(), _builder(archive_name) {}
: VM_Heap_Sync_Operation(), _builder(archive_name) {}
VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; }
void doit() {
ResourceMark rm;
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 @@ -57,7 +57,7 @@ void VM_G1CollectFull::doit() {

VM_G1TryInitiateConcMark::VM_G1TryInitiateConcMark(uint gc_count_before,
GCCause::Cause gc_cause) :
VM_GC_Operation(gc_count_before, gc_cause),
VM_GC_Collect_Operation(gc_count_before, gc_cause),
_transient_failure(false),
_cycle_already_in_progress(false),
_whitebox_attached(false),
Expand Down
7 changes: 4 additions & 3 deletions src/hotspot/share/gc/g1/g1VMOperations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@

// VM_operations for the G1 collector.

class VM_G1CollectFull : public VM_GC_Operation {
class VM_G1CollectFull : public VM_GC_Collect_Operation {
protected:
bool skip_operation() const override;

public:
VM_G1CollectFull(uint gc_count_before,
uint full_gc_count_before,
GCCause::Cause cause) :
VM_GC_Operation(gc_count_before, cause, full_gc_count_before, true) { }
VM_GC_Collect_Operation(gc_count_before, cause, full_gc_count_before, true) { }
VMOp_Type type() const override { return VMOp_G1CollectFull; }
void doit() override;
};

class VM_G1TryInitiateConcMark : public VM_GC_Operation {
class VM_G1TryInitiateConcMark : public VM_GC_Collect_Operation {
bool _transient_failure;
bool _cycle_already_in_progress;
bool _whitebox_attached;
Expand Down Expand Up @@ -89,6 +89,7 @@ class VM_G1PauseConcurrent : public VM_Operation {
bool doit_prologue() override;
void doit_epilogue() override;
void doit() override;
bool is_gc_operation() const override { return true; }
};

class VM_G1PauseRemark : public VM_G1PauseConcurrent {
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/gc/parallel/psVMOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ static bool is_cause_full(GCCause::Cause cause) {

// Only used for System.gc() calls
VM_ParallelGCCollect::VM_ParallelGCCollect(uint gc_count,
uint full_gc_count,
GCCause::Cause gc_cause) :
VM_GC_Operation(gc_count, gc_cause, full_gc_count, is_cause_full(gc_cause)) {}
uint full_gc_count,
GCCause::Cause gc_cause) :
VM_GC_Collect_Operation(gc_count, gc_cause, full_gc_count, is_cause_full(gc_cause)) {}

void VM_ParallelGCCollect::doit() {
ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/parallel/psVMOperations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class VM_ParallelCollectForAllocation : public VM_CollectForAllocation {
virtual void doit();
};

class VM_ParallelGCCollect: public VM_GC_Operation {
class VM_ParallelGCCollect: public VM_GC_Collect_Operation {
public:
VM_ParallelGCCollect(uint gc_count, uint full_gc_count, GCCause::Cause gc_cause);
virtual VMOp_Type type() const { return VMOp_ParallelGCCollect; }
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/serial/serialVMOperations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ class VM_SerialCollectForAllocation : public VM_CollectForAllocation {

// VM operation to invoke a collection of the heap as a
// SerialHeap heap.
class VM_SerialGCCollect: public VM_GC_Operation {
class VM_SerialGCCollect: public VM_GC_Collect_Operation {
public:
VM_SerialGCCollect(bool full,
uint gc_count_before,
uint full_gc_count_before,
GCCause::Cause gc_cause)
: VM_GC_Operation(gc_count_before, gc_cause, full_gc_count_before, full) {}
: VM_GC_Collect_Operation(gc_count_before, gc_cause, full_gc_count_before, full) {}

virtual VMOp_Type type() const { return VMOp_SerialGCCollect; }
virtual void doit();
Expand Down
12 changes: 6 additions & 6 deletions src/hotspot/share/gc/shared/gcVMOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
#include "gc/g1/g1Policy.hpp"
#endif // INCLUDE_G1GC

bool VM_GC_Sync_Operation::doit_prologue() {
bool VM_Heap_Sync_Operation::doit_prologue() {
Heap_lock->lock();
return true;
}

void VM_GC_Sync_Operation::doit_epilogue() {
void VM_Heap_Sync_Operation::doit_epilogue() {
Heap_lock->unlock();
}

Expand Down Expand Up @@ -115,7 +115,7 @@ bool VM_GC_Operation::doit_prologue() {
if (should_use_gclocker()) {
GCLocker::block();
}
VM_GC_Sync_Operation::doit_prologue();
VM_Heap_Sync_Operation::doit_prologue();

// Check invocations
if (skip_operation()) {
Expand All @@ -139,7 +139,7 @@ void VM_GC_Operation::doit_epilogue() {
if (Universe::has_reference_pending_list()) {
Heap_lock->notify_all();
}
VM_GC_Sync_Operation::doit_epilogue();
VM_Heap_Sync_Operation::doit_epilogue();
if (should_use_gclocker()) {
GCLocker::unblock();
}
Expand Down Expand Up @@ -206,7 +206,7 @@ VM_CollectForMetadataAllocation::VM_CollectForMetadataAllocation(ClassLoaderData
uint gc_count_before,
uint full_gc_count_before,
GCCause::Cause gc_cause)
: VM_GC_Operation(gc_count_before, gc_cause, full_gc_count_before, true),
: VM_GC_Collect_Operation(gc_count_before, gc_cause, full_gc_count_before, true),
_result(nullptr), _size(size), _mdtype(mdtype), _loader_data(loader_data) {
assert(_size != 0, "An allocation should always be requested with this operation.");
AllocTracer::send_allocation_requiring_gc_event(_size * HeapWordSize, GCId::peek());
Expand Down Expand Up @@ -269,7 +269,7 @@ void VM_CollectForMetadataAllocation::doit() {
}

VM_CollectForAllocation::VM_CollectForAllocation(size_t word_size, uint gc_count_before, GCCause::Cause cause)
: VM_GC_Operation(gc_count_before, cause), _word_size(word_size), _result(nullptr) {
: VM_GC_Collect_Operation(gc_count_before, cause), _word_size(word_size), _result(nullptr) {
// Only report if operation was really caused by an allocation.
if (_word_size != 0) {
AllocTracer::send_allocation_requiring_gc_event(_word_size * HeapWordSize, GCId::peek());
Expand Down
69 changes: 47 additions & 22 deletions src/hotspot/share/gc/shared/gcVMOperations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,22 @@
// a set of operations (VM_Operation) related to GC.
//
// VM_Operation
// VM_GC_Sync_Operation
// VM_Heap_Sync_Operation
// VM_GC_Operation
// VM_GC_HeapInspection
// VM_PopulateDynamicDumpSharedSpace
// VM_SerialGCCollect
// VM_ParallelGCCollect
// VM_CollectForAllocation
// VM_SerialCollectForAllocation
// VM_ParallelCollectForAllocation
// VM_GC_Collect_Operation
// VM_SerialGCCollect
// VM_ParallelGCCollect
// VM_CollectForAllocation
// VM_SerialCollectForAllocation
// VM_ParallelCollectForAllocation
// VM_CollectForMetadataAllocation
// VM_GC_Service_Operation
// VM_GC_HeapInspection
// VM_Verify
// VM_PopulateDynamicDumpSharedSpace
// VM_PopulateDumpSharedSpace
//
// VM_GC_Sync_Operation
// VM_Heap_Sync_Operation
// - implements only synchronization with other VM operations of the
// same kind using the Heap_lock, not actually doing a GC.
//
Expand Down Expand Up @@ -84,24 +87,24 @@
// - creates the CDS archive
//

class VM_GC_Sync_Operation : public VM_Operation {
class VM_Heap_Sync_Operation : public VM_Operation {
public:

VM_GC_Sync_Operation() : VM_Operation() { }
VM_Heap_Sync_Operation() : VM_Operation() { }

// Acquires the Heap_lock.
virtual bool doit_prologue();
// Releases the Heap_lock.
virtual void doit_epilogue();
};

class VM_Verify : public VM_GC_Sync_Operation {
class VM_Verify : public VM_Heap_Sync_Operation {
public:
VMOp_Type type() const { return VMOp_Verify; }
void doit();
};

class VM_GC_Operation: public VM_GC_Sync_Operation {
class VM_GC_Operation: public VM_Heap_Sync_Operation {
protected:
uint _gc_count_before; // gc count before acquiring the Heap_lock
uint _full_gc_count_before; // full gc count before acquiring the Heap_lock
Expand All @@ -115,7 +118,7 @@ class VM_GC_Operation: public VM_GC_Sync_Operation {
VM_GC_Operation(uint gc_count_before,
GCCause::Cause _cause,
uint full_gc_count_before = 0,
bool full = false) : VM_GC_Sync_Operation() {
bool full = false) : VM_Heap_Sync_Operation() {
_full = full;
_prologue_succeeded = false;
_gc_count_before = gc_count_before;
Expand Down Expand Up @@ -149,31 +152,53 @@ class VM_GC_Operation: public VM_GC_Sync_Operation {
static void notify_gc_end();
};

class VM_GC_Service_Operation : public VM_GC_Operation {
public:
VM_GC_Service_Operation(uint gc_count_before,
GCCause::Cause _cause,
uint full_gc_count_before = 0,
bool full = false) :
VM_GC_Operation(gc_count_before, _cause, full_gc_count_before, full) {}
};

class VM_GC_HeapInspection: public VM_GC_Operation {
class VM_GC_Collect_Operation : public VM_GC_Operation {
public:
VM_GC_Collect_Operation(uint gc_count_before,
GCCause::Cause _cause,
uint full_gc_count_before = 0,
bool full = false) :
VM_GC_Operation(gc_count_before, _cause, full_gc_count_before, full) {}

bool is_gc_operation() const { return true; }
};


class VM_GC_HeapInspection : public VM_GC_Service_Operation {
private:
outputStream* _out;
bool _full_gc;
uint _parallel_thread_num;

public:
VM_GC_HeapInspection(outputStream* out, bool request_full_gc,
uint parallel_thread_num = 1) :
VM_GC_Operation(0 /* total collections, dummy, ignored */,
GCCause::_heap_inspection /* GC Cause */,
0 /* total full collections, dummy, ignored */,
request_full_gc), _out(out), _full_gc(request_full_gc),
_parallel_thread_num(parallel_thread_num) {}
VM_GC_Service_Operation(0 /* total collections, dummy, ignored */,
GCCause::_heap_inspection /* GC Cause */,
0 /* total full collections, dummy, ignored */,
request_full_gc), _out(out), _full_gc(request_full_gc),
_parallel_thread_num(parallel_thread_num) {}

~VM_GC_HeapInspection() {}
virtual VMOp_Type type() const { return VMOp_GC_HeapInspection; }
virtual bool skip_operation() const;
virtual bool doit_prologue();
virtual void doit();

protected:
bool collect();
};

class VM_CollectForAllocation : public VM_GC_Operation {
class VM_CollectForAllocation : public VM_GC_Collect_Operation {
protected:
size_t _word_size; // Size of object to be allocated (in number of words)
HeapWord* _result; // Allocation result (null if allocation failed)
Expand All @@ -186,7 +211,7 @@ class VM_CollectForAllocation : public VM_GC_Operation {
}
};

class VM_CollectForMetadataAllocation: public VM_GC_Operation {
class VM_CollectForMetadataAllocation: public VM_GC_Collect_Operation {
private:
MetaWord* _result;
size_t _size; // size of object to be allocated
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/gc/shenandoah/shenandoahVMOperations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class VM_ShenandoahOperation : public VM_Operation {
void log_active_generation(const char* prefix);
bool doit_prologue() override;
void doit_epilogue() override;

bool is_gc_operation() const override { return true; };
};

class VM_ShenandoahReferenceOperation : public VM_ShenandoahOperation {
Expand Down
8 changes: 8 additions & 0 deletions src/hotspot/share/gc/z/zGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ class VM_ZOperation : public VM_Operation {
OopMapCache::try_trigger_cleanup();
}

virtual bool is_gc_operation() const {
return true;
}

bool success() const {
return _success;
}
Expand Down Expand Up @@ -1308,6 +1312,10 @@ class ZRendezvousGCThreads: public VM_Operation {
return true;
}

virtual bool is_gc_operation() const {
return true;
}

void doit() {
// Light weight "handshake" of the GC threads
SuspendibleThreadSet::synchronize();
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/gc/z/zMark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,10 @@ class VM_ZMarkFlushOperation : public VM_Operation {
virtual VMOp_Type type() const {
return VMOp_ZMarkFlushOperation;
}

virtual bool is_gc_operation() const {
return true;
}
};

bool ZMark::flush() {
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/runtime/vmOperation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ class VM_Operation : public StackObj {
virtual VMOp_Type type() const = 0;
virtual bool allow_nested_vm_operations() const { return false; }

// VMOp_Type may belong to a category of operation
// Override is_XX_operation() appropriately in subclasses
virtual bool is_gc_operation() const { return false; }

// You may override skip_thread_oop_barriers to return true if the operation
// does not access thread-private oops (including frames).
virtual bool skip_thread_oop_barriers() const { return false; }
Expand Down