8199407: Skip Rebuild Remset Phase if there are no rebuild candidates

Reviewed-by: tschatzl, sjohanss
This commit is contained in:
Ivan Walulya 2021-04-19 14:37:16 +00:00
parent 8dbf7aa1f9
commit d9e40dd593
5 changed files with 123 additions and 10 deletions

@ -410,7 +410,8 @@ G1ConcurrentMark::G1ConcurrentMark(G1CollectedHeap* g1h,
_max_concurrent_workers(0),
_region_mark_stats(NEW_C_HEAP_ARRAY(G1RegionMarkStats, _g1h->max_reserved_regions(), mtGC)),
_top_at_rebuild_starts(NEW_C_HEAP_ARRAY(HeapWord*, _g1h->max_reserved_regions(), mtGC))
_top_at_rebuild_starts(NEW_C_HEAP_ARRAY(HeapWord*, _g1h->max_reserved_regions(), mtGC)),
_needs_remembered_set_rebuild(false)
{
assert(CGC_lock != NULL, "CGC_lock must be initialized");
@ -1150,6 +1151,8 @@ void G1ConcurrentMark::remark() {
log_debug(gc, remset, tracking)("Remembered Set Tracking update regions total %u, selected %u",
_g1h->num_regions(), cl.total_selected_for_rebuild());
_needs_remembered_set_rebuild = (cl.total_selected_for_rebuild() > 0);
}
{
GCTraceTime(Debug, gc, phases) debug("Reclaim Empty Regions", _gc_timer_cm);
@ -1321,10 +1324,12 @@ void G1ConcurrentMark::cleanup() {
verify_during_pause(G1HeapVerifier::G1VerifyCleanup, VerifyOption_G1UsePrevMarking, "Cleanup before");
{
if (needs_remembered_set_rebuild()) {
GCTraceTime(Debug, gc, phases) debug("Update Remembered Set Tracking After Rebuild", _gc_timer_cm);
G1UpdateRemSetTrackingAfterRebuild cl(_g1h);
_g1h->heap_region_iterate(&cl);
} else {
log_debug(gc, phases)("No Remembered Sets to update after rebuild");
}
verify_during_pause(G1HeapVerifier::G1VerifyCleanup, VerifyOption_G1UsePrevMarking, "Cleanup after");
@ -1340,7 +1345,7 @@ void G1ConcurrentMark::cleanup() {
{
GCTraceTime(Debug, gc, phases) debug("Finalize Concurrent Mark Cleanup", _gc_timer_cm);
policy->record_concurrent_mark_cleanup_end();
policy->record_concurrent_mark_cleanup_end(needs_remembered_set_rebuild());
}
}
@ -1953,6 +1958,12 @@ void G1ConcurrentMark::verify_no_collection_set_oops() {
#endif // PRODUCT
void G1ConcurrentMark::rebuild_rem_set_concurrently() {
// If Remark did not select any regions for RemSet rebuild,
// skip the rebuild remembered set phase
if (!needs_remembered_set_rebuild()) {
log_debug(gc, marking)("Skipping Remembered Set Rebuild. No regions selected for rebuild");
return;
}
_g1h->rem_set()->rebuild_rem_set(this, _concurrent_workers, _worker_id_offset);
}

@ -457,6 +457,8 @@ class G1ConcurrentMark : public CHeapObj<mtGC> {
// means that this region does not be scanned during the rebuilding remembered
// set phase at all.
HeapWord* volatile* _top_at_rebuild_starts;
// True when Remark pause selected regions for rebuilding.
bool _needs_remembered_set_rebuild;
public:
void add_to_liveness(uint worker_id, oop const obj, size_t size);
// Live words in the given region as determined by concurrent marking, i.e. the amount of
@ -597,6 +599,9 @@ public:
private:
// Rebuilds the remembered sets for chosen regions in parallel and concurrently to the application.
void rebuild_rem_set_concurrently();
uint needs_remembered_set_rebuild() const { return _needs_remembered_set_rebuild; }
};
// A class representing a marking task.

@ -549,7 +549,6 @@ void G1Policy::record_concurrent_mark_remark_end() {
double end_time_sec = os::elapsedTime();
double elapsed_time_ms = (end_time_sec - _mark_remark_start_sec)*1000.0;
_analytics->report_concurrent_mark_remark_times_ms(elapsed_time_ms);
record_pause(G1GCPauseType::Remark, _mark_remark_start_sec, end_time_sec);
}
@ -1098,16 +1097,19 @@ void G1Policy::decide_on_conc_mark_initiation() {
}
}
void G1Policy::record_concurrent_mark_cleanup_end() {
G1CollectionSetCandidates* candidates = G1CollectionSetChooser::build(_g1h->workers(), _g1h->num_regions());
_collection_set->set_candidates(candidates);
void G1Policy::record_concurrent_mark_cleanup_end(bool has_rebuilt_remembered_sets) {
bool mixed_gc_pending = false;
if (has_rebuilt_remembered_sets) {
G1CollectionSetCandidates* candidates = G1CollectionSetChooser::build(_g1h->workers(), _g1h->num_regions());
_collection_set->set_candidates(candidates);
mixed_gc_pending = next_gc_should_be_mixed("request mixed gcs", "request young-only gcs");
}
if (log_is_enabled(Trace, gc, liveness)) {
G1PrintRegionLivenessInfoClosure cl("Post-Cleanup");
_g1h->heap_region_iterate(&cl);
}
bool mixed_gc_pending = next_gc_should_be_mixed("request mixed gcs", "request young-only gcs");
if (!mixed_gc_pending) {
clear_collection_set_candidates();
abort_time_to_mixed_tracking();
@ -1134,6 +1136,9 @@ class G1ClearCollectionSetCandidateRemSets : public HeapRegionClosure {
};
void G1Policy::clear_collection_set_candidates() {
if (_collection_set->candidates() == NULL) {
return;
}
// Clear remembered sets of remaining candidate regions and the actual candidate
// set.
G1ClearCollectionSetCandidateRemSets cl;
@ -1229,7 +1234,7 @@ bool G1Policy::next_gc_should_be_mixed(const char* true_action_str,
const char* false_action_str) const {
G1CollectionSetCandidates* candidates = _collection_set->candidates();
if (candidates->is_empty()) {
if (candidates == NULL || candidates->is_empty()) {
log_debug(gc, ergo)("%s (candidate old regions not available)", false_action_str);
return false;
}

@ -321,7 +321,7 @@ public:
// Record start, end, and completion of cleanup.
void record_concurrent_mark_cleanup_start();
void record_concurrent_mark_cleanup_end();
void record_concurrent_mark_cleanup_end(bool has_rebuilt_remembered_sets);
void print_phases();

@ -0,0 +1,92 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package gc.g1;
/*
* @test TestSkipRebuildRemsetPhase
* @summary Skip Rebuild Remset Phase if the Remark pause does not identify any rebuild candidates.
* Fill up a region to above the set G1MixedGCLiveThresholdPercent.
* @requires vm.gc.G1
* @library /test/lib
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run driver gc.g1.TestSkipRebuildRemsetPhase
*/
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.Asserts;
import sun.hotspot.WhiteBox;
public class TestSkipRebuildRemsetPhase {
public static void main(String[] args) throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xbootclasspath/a:.",
"-XX:+UseG1GC",
"-XX:+UnlockExperimentalVMOptions",
"-XX:+UnlockDiagnosticVMOptions",
"-XX:+WhiteBoxAPI",
"-XX:G1MixedGCLiveThresholdPercent=20",
"-Xlog:gc+marking=debug,gc+phases=debug,gc+remset+tracking=trace",
"-Xms10M",
"-Xmx10M",
GCTest.class.getName());
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldContain("Skipping Remembered Set Rebuild.");
output.shouldContain("No Remembered Sets to update after rebuild");
output.shouldHaveExitValue(0);
}
public static class GCTest {
public static void main(String args[]) throws Exception {
WhiteBox wb = WhiteBox.getWhiteBox();
// Allocate some memory less than region size.
Object used = alloc();
// Trigger the full GC using the WhiteBox API.
wb.fullGC(); // full
// Memory objects have been promoted to old by full GC.
// Concurrent cycle should not select any regions for rebuilding
wb.g1StartConcMarkCycle(); // concurrent-start, remark and cleanup
// Sleep to make sure concurrent cycle is done
while (wb.g1InConcurrentMark()) {
Thread.sleep(1000);
}
System.out.println(used);
}
private static Object alloc() {
// Since G1MixedGCLiveThresholdPercent is 20%, make sure to allocate object larger than that
// so that it will not be collected and the expected message printed.
final int objectSize = WhiteBox.getWhiteBox().g1RegionSize() / 3;
Object ret = new byte[objectSize];
return ret;
}
}
}