8197570: Make rules for choosing collection set candidates more explicit
Reviewed-by: sangheki, sjohanss
--- a/src/hotspot/share/gc/g1/collectionSetChooser.cpp Mon Mar 26 16:51:41 2018 +0200
+++ b/src/hotspot/share/gc/g1/collectionSetChooser.cpp Mon Mar 26 16:51:43 2018 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, 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
@@ -83,8 +83,7 @@
100), true /* C_Heap */),
_front(0), _end(0), _first_par_unreserved_idx(0),
_region_live_threshold_bytes(0), _remaining_reclaimable_bytes(0) {
- _region_live_threshold_bytes =
- HeapRegion::GrainBytes * (size_t) G1MixedGCLiveThresholdPercent / 100;
+ _region_live_threshold_bytes = mixed_gc_live_threshold_bytes();
}
#ifndef PRODUCT
@@ -203,6 +202,16 @@
}
}
+void CollectionSetChooser::iterate(HeapRegionClosure* cl) {
+ for (uint i = _front; i < _end; i++) {
+ HeapRegion* r = regions_at(i);
+ if (cl->do_heap_region(r)) {
+ cl->set_incomplete();
+ break;
+ }
+ }
+}
+
void CollectionSetChooser::clear() {
_regions.clear();
_front = 0;
@@ -259,6 +268,17 @@
return MAX2(n_regions / (n_workers * overpartition_factor), min_chunk_size);
}
+bool CollectionSetChooser::region_occupancy_low_enough_for_evac(size_t live_bytes) {
+ return live_bytes < mixed_gc_live_threshold_bytes();
+}
+
+bool CollectionSetChooser::should_add(HeapRegion* hr) const {
+ assert(hr->is_marked(), "pre-condition");
+ assert(!hr->is_young(), "should never consider young regions");
+ return !hr->is_pinned() &&
+ region_occupancy_low_enough_for_evac(hr->live_bytes());
+}
+
void CollectionSetChooser::rebuild(WorkGang* workers, uint n_regions) {
clear();
--- a/src/hotspot/share/gc/g1/collectionSetChooser.hpp Mon Mar 26 16:51:41 2018 +0200
+++ b/src/hotspot/share/gc/g1/collectionSetChooser.hpp Mon Mar 26 16:51:43 2018 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, 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
@@ -101,17 +101,18 @@
CollectionSetChooser();
+ static size_t mixed_gc_live_threshold_bytes() {
+ return HeapRegion::GrainBytes * (size_t) G1MixedGCLiveThresholdPercent / 100;
+ }
+
+ static bool region_occupancy_low_enough_for_evac(size_t live_bytes);
+
void sort_regions();
// Determine whether to add the given region to the CSet chooser or
// not. Currently, we skip pinned regions and regions whose live
// bytes are over the threshold. Humongous regions may be reclaimed during cleanup.
- bool should_add(HeapRegion* hr) {
- assert(hr->is_marked(), "pre-condition");
- assert(!hr->is_young(), "should never consider young regions");
- return !hr->is_pinned() &&
- hr->live_bytes() < _region_live_threshold_bytes;
- }
+ bool should_add(HeapRegion* hr) const;
// Returns the number candidate old regions added
uint length() { return _end; }
@@ -133,6 +134,9 @@
// and the amount of reclaimable bytes by reclaimable_bytes.
void update_totals(uint region_num, size_t reclaimable_bytes);
+ // Iterate over all collection set candidate regions.
+ void iterate(HeapRegionClosure* cl);
+
void clear();
void rebuild(WorkGang* workers, uint n_regions);
--- a/src/hotspot/share/gc/g1/heapRegion.hpp Mon Mar 26 16:51:41 2018 +0200
+++ b/src/hotspot/share/gc/g1/heapRegion.hpp Mon Mar 26 16:51:43 2018 +0200
@@ -713,6 +713,7 @@
class HeapRegionClosure : public StackObj {
friend class HeapRegionManager;
friend class G1CollectionSet;
+ friend class CollectionSetChooser;
bool _is_complete;
void set_incomplete() { _is_complete = false; }