Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8267894: Skip work for empty regions in G1 Full GC
Reviewed-by: sjohanss, tschatzl
  • Loading branch information
Ivan Walulya committed Aug 23, 2021
1 parent 741f58c commit d542745
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
3 changes: 1 addition & 2 deletions src/hotspot/share/gc/g1/g1FullCollector.cpp
Expand Up @@ -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()) {
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/gc/g1/g1FullCollector.hpp
Expand Up @@ -109,7 +109,8 @@ class G1FullCollector : StackObj {
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:
Expand Down
8 changes: 6 additions & 2 deletions src/hotspot/share/gc/g1/g1FullCollector.inline.hpp
Expand Up @@ -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) {
Expand Down
16 changes: 10 additions & 6 deletions src/hotspot/share/gc/g1/g1FullGCCompactTask.cpp
Expand Up @@ -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();
}

Expand Down
14 changes: 10 additions & 4 deletions src/hotspot/share/gc/g1/g1FullGCHeapRegionAttr.hpp
Expand Up @@ -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:
Expand All @@ -57,21 +58,26 @@ class G1FullGCHeapRegionAttr : public G1BiasedMappedArray<uint8_t> {
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;
}

bool is_skip_compacting(uint idx) const {
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"); }
Expand Down
8 changes: 5 additions & 3 deletions src/hotspot/share/gc/g1/g1FullGCPrepareTask.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

1 comment on commit d542745

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