8267894: Skip work for empty regions in G1 Full GC

Reviewed-by: sjohanss, tschatzl
This commit is contained in:
Ivan Walulya 2021-08-23 12:58:48 +00:00
parent 741f58c18c
commit d542745dbe
6 changed files with 34 additions and 18 deletions

View File

@ -224,8 +224,7 @@ void G1FullCollector::complete_collection() {
void G1FullCollector::before_marking_update_attribute_table(HeapRegion* hr) {
if (hr->is_free()) {
// Set as Invalid by default.
_region_attr_table.verify_is_invalid(hr->hrm_index());
_region_attr_table.set_free(hr->hrm_index());
} else if (hr->is_closed_archive()) {
_region_attr_table.set_skip_marking(hr->hrm_index());
} else if (hr->is_pinned()) {

View File

@ -109,7 +109,8 @@ public:
inline bool is_skip_compacting(uint region_index) const;
inline bool is_skip_marking(oop obj) const;
inline void set_invalid(uint region_idx);
inline void set_free(uint region_idx);
inline bool is_free(uint region_idx) const;
inline void update_from_compacting_to_skip_compacting(uint region_idx);
private:

View File

@ -43,8 +43,12 @@ bool G1FullCollector::is_skip_marking(oop obj) const {
return _region_attr_table.is_skip_marking(cast_from_oop<HeapWord*>(obj));
}
void G1FullCollector::set_invalid(uint region_idx) {
_region_attr_table.set_invalid(region_idx);
void G1FullCollector::set_free(uint region_idx) {
_region_attr_table.set_free(region_idx);
}
bool G1FullCollector::is_free(uint region_idx) const {
return _region_attr_table.is_free(region_idx);
}
void G1FullCollector::update_from_compacting_to_skip_compacting(uint region_idx) {

View File

@ -79,13 +79,17 @@ size_t G1FullGCCompactTask::G1CompactRegionClosure::apply(oop obj) {
void G1FullGCCompactTask::compact_region(HeapRegion* hr) {
assert(!hr->is_pinned(), "Should be no pinned region in compaction queue");
assert(!hr->is_humongous(), "Should be no humongous regions in compaction queue");
G1CompactRegionClosure compact(collector()->mark_bitmap());
hr->apply_to_marked_objects(collector()->mark_bitmap(), &compact);
// Clear the liveness information for this region if necessary i.e. if we actually look at it
// for bitmap verification. Otherwise it is sufficient that we move the TAMS to bottom().
if (G1VerifyBitmaps) {
collector()->mark_bitmap()->clear_region(hr);
if (!collector()->is_free(hr->hrm_index())) {
G1CompactRegionClosure compact(collector()->mark_bitmap());
hr->apply_to_marked_objects(collector()->mark_bitmap(), &compact);
// Clear the liveness information for this region if necessary i.e. if we actually look at it
// for bitmap verification. Otherwise it is sufficient that we move the TAMS to bottom().
if (G1VerifyBitmaps) {
collector()->mark_bitmap()->clear_region(hr);
}
}
hr->reset_compacted_after_full_gc();
}

View File

@ -41,11 +41,12 @@ class G1FullGCHeapRegionAttr : public G1BiasedMappedArray<uint8_t> {
static const uint8_t Compacting = 0; // Region will be compacted.
static const uint8_t SkipCompacting = 1; // Region should not be compacted, but otherwise handled as usual.
static const uint8_t SkipMarking = 2; // Region contents are not even marked through, but contain live objects.
static const uint8_t Free = 3; // Regions is free.
static const uint8_t Invalid = 255;
bool is_invalid(HeapWord* obj) const {
return get_by_address(obj) == Invalid;
bool is_free(HeapWord* obj) const {
return get_by_address(obj) == Free;
}
protected:
@ -57,14 +58,15 @@ public:
void set_compacting(uint idx) { set_by_index(idx, Compacting); }
void set_skip_marking(uint idx) { set_by_index(idx, SkipMarking); }
void set_skip_compacting(uint idx) { set_by_index(idx, SkipCompacting); }
void set_free(uint idx) { set_by_index(idx, Free); }
bool is_skip_marking(HeapWord* obj) const {
assert(!is_invalid(obj), "not initialized yet");
assert(!is_free(obj), "Should not have objects in free regions.");
return get_by_address(obj) == SkipMarking;
}
bool is_compacting(HeapWord* obj) const {
assert(!is_invalid(obj), "not initialized yet");
assert(!is_free(obj), "Should not have objects in free regions.");
return get_by_address(obj) == Compacting;
}
@ -72,6 +74,10 @@ public:
return get_by_index(idx) == SkipCompacting;
}
bool is_free(uint idx) const {
return get_by_index(idx) == Free;
}
void verify_is_compacting(uint idx) { assert(get_by_index(idx) == Compacting, "invariant"); }
void verify_is_invalid(uint idx) { assert(get_by_index(idx) == Invalid, "invariant"); }

View File

@ -47,8 +47,8 @@ void G1FullGCPrepareTask::G1CalculatePointersClosure::free_pinned_region(HeapReg
} else {
_g1h->free_region(hr, nullptr);
}
_collector->set_free(hr->hrm_index());
prepare_for_compaction(hr);
_collector->set_invalid(hr->hrm_index());
}
bool G1FullGCPrepareTask::G1CalculatePointersClosure::do_heap_region(HeapRegion* hr) {
@ -182,9 +182,11 @@ size_t G1FullGCPrepareTask::G1RePrepareClosure::apply(oop obj) {
void G1FullGCPrepareTask::G1CalculatePointersClosure::prepare_for_compaction_work(G1FullGCCompactionPoint* cp,
HeapRegion* hr) {
G1PrepareCompactLiveClosure prepare_compact(cp);
hr->set_compaction_top(hr->bottom());
hr->apply_to_marked_objects(_bitmap, &prepare_compact);
if (!_collector->is_free(hr->hrm_index())) {
G1PrepareCompactLiveClosure prepare_compact(cp);
hr->apply_to_marked_objects(_bitmap, &prepare_compact);
}
}
void G1FullGCPrepareTask::G1CalculatePointersClosure::prepare_for_compaction(HeapRegion* hr) {