8145672: Remove dependency of G1FromCardCache to HeapRegionRemSet
Summary: Move HeapRegionRemSet::num_par_rem_sets() to G1RemSet, and document it.
Reviewed-by: mgerdin, jmasa
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp Tue Dec 22 00:08:38 2015 +0000
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp Tue Dec 22 11:02:04 2015 +0100
@@ -1789,9 +1789,6 @@
uint n_queues = ParallelGCThreads;
_task_queues = new RefToScanQueueSet(n_queues);
- uint n_rem_sets = HeapRegionRemSet::num_par_rem_sets();
- assert(n_rem_sets > 0, "Invariant.");
-
_worker_cset_start_region = NEW_C_HEAP_ARRAY(HeapRegion*, n_queues, mtGC);
_worker_cset_start_region_time_stamp = NEW_C_HEAP_ARRAY(uint, n_queues, mtGC);
_evacuation_failed_info_array = NEW_C_HEAP_ARRAY(EvacuationFailedInfo, n_queues, mtGC);
@@ -1891,7 +1888,6 @@
_g1_rem_set = new G1RemSet(this, g1_barrier_set());
// Carve out the G1 part of the heap.
-
ReservedSpace g1_rs = heap_rs.first_part(max_byte_size);
size_t page_size = UseLargePages ? os::large_page_size() : os::vm_page_size();
G1RegionToSpaceMapper* heap_storage =
@@ -1940,6 +1936,8 @@
const uint max_region_idx = (1U << (sizeof(RegionIdx_t)*BitsPerByte-1)) - 1;
guarantee((max_regions() - 1) <= max_region_idx, "too many regions");
+ G1RemSet::initialize(max_regions());
+
size_t max_cards_per_region = ((size_t)1 << (sizeof(CardIdx_t)*BitsPerByte-1)) - 1;
guarantee(HeapRegion::CardsPerRegion > 0, "make sure it's initialized");
guarantee(HeapRegion::CardsPerRegion < max_cards_per_region,
@@ -1967,9 +1965,6 @@
}
_cmThread = _cm->cmThread();
- // Initialize the from_card cache structure of HeapRegionRemSet.
- HeapRegionRemSet::init_heap(max_regions());
-
// Now expand into the initial heap size.
if (!expand(init_byte_size)) {
vm_shutdown_during_initialization("Failed to allocate initial heap.");
--- a/hotspot/src/share/vm/gc/g1/g1FromCardCache.cpp Tue Dec 22 00:08:38 2015 +0000
+++ b/hotspot/src/share/vm/gc/g1/g1FromCardCache.cpp Tue Dec 22 11:02:04 2015 +0100
@@ -24,7 +24,7 @@
#include "precompiled.hpp"
#include "gc/g1/g1FromCardCache.hpp"
-#include "gc/g1/heapRegionRemSet.hpp"
+#include "gc/g1/g1RemSet.hpp"
#include "memory/padded.inline.hpp"
#include "utilities/debug.hpp"
@@ -32,11 +32,12 @@
uint G1FromCardCache::_max_regions = 0;
size_t G1FromCardCache::_static_mem_size = 0;
-void G1FromCardCache::initialize(uint n_par_rs, uint max_num_regions) {
+void G1FromCardCache::initialize(uint num_par_rem_sets, uint max_num_regions) {
+ guarantee(max_num_regions > 0, "Heap size must be valid");
guarantee(_cache == NULL, "Should not call this multiple times");
_max_regions = max_num_regions;
- _cache = Padded2DArray<int, mtGC>::create_unfreeable(n_par_rs,
+ _cache = Padded2DArray<int, mtGC>::create_unfreeable(num_par_rem_sets,
_max_regions,
&_static_mem_size);
@@ -47,9 +48,10 @@
guarantee((size_t)start_idx + new_num_regions <= max_uintx,
"Trying to invalidate beyond maximum region, from %u size " SIZE_FORMAT,
start_idx, new_num_regions);
- for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) {
- uint end_idx = (start_idx + (uint)new_num_regions);
- assert(end_idx <= _max_regions, "Must be within max.");
+ uint end_idx = (start_idx + (uint)new_num_regions);
+ assert(end_idx <= _max_regions, "Must be within max.");
+
+ for (uint i = 0; i < G1RemSet::num_par_rem_sets(); i++) {
for (uint j = start_idx; j < end_idx; j++) {
set(i, j, InvalidCard);
}
@@ -58,7 +60,7 @@
#ifndef PRODUCT
void G1FromCardCache::print(outputStream* out) {
- for (uint i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) {
+ for (uint i = 0; i < G1RemSet::num_par_rem_sets(); i++) {
for (uint j = 0; j < _max_regions; j++) {
out->print_cr("_from_card_cache[%u][%u] = %d.",
i, j, at(i, j));
@@ -68,7 +70,7 @@
#endif
void G1FromCardCache::clear(uint region_idx) {
- uint num_par_remsets = HeapRegionRemSet::num_par_rem_sets();
+ uint num_par_remsets = G1RemSet::num_par_rem_sets();
for (uint i = 0; i < num_par_remsets; i++) {
set(i, region_idx, InvalidCard);
}
--- a/hotspot/src/share/vm/gc/g1/g1FromCardCache.hpp Tue Dec 22 00:08:38 2015 +0000
+++ b/hotspot/src/share/vm/gc/g1/g1FromCardCache.hpp Tue Dec 22 11:02:04 2015 +0100
@@ -65,7 +65,7 @@
_cache[worker_id][region_idx] = val;
}
- static void initialize(uint n_par_rs, uint max_num_regions);
+ static void initialize(uint num_par_rem_sets, uint max_num_regions);
static void invalidate(uint start_idx, size_t num_regions);
--- a/hotspot/src/share/vm/gc/g1/g1RemSet.cpp Tue Dec 22 00:08:38 2015 +0000
+++ b/hotspot/src/share/vm/gc/g1/g1RemSet.cpp Tue Dec 22 11:02:04 2015 +0100
@@ -25,9 +25,11 @@
#include "precompiled.hpp"
#include "gc/g1/concurrentG1Refine.hpp"
#include "gc/g1/concurrentG1RefineThread.hpp"
+#include "gc/g1/dirtyCardQueue.hpp"
#include "gc/g1/g1BlockOffsetTable.inline.hpp"
#include "gc/g1/g1CollectedHeap.inline.hpp"
#include "gc/g1/g1CollectorPolicy.hpp"
+#include "gc/g1/g1FromCardCache.hpp"
#include "gc/g1/g1GCPhaseTimes.hpp"
#include "gc/g1/g1HotCardCache.hpp"
#include "gc/g1/g1OopClosures.inline.hpp"
@@ -76,6 +78,14 @@
FREE_C_HEAP_ARRAY(G1ParPushHeapRSClosure*, _cset_rs_update_cl);
}
+uint G1RemSet::num_par_rem_sets() {
+ return MAX2(DirtyCardQueueSet::num_par_ids() + ConcurrentG1Refine::thread_num(), ParallelGCThreads);
+}
+
+void G1RemSet::initialize(uint max_regions) {
+ G1FromCardCache::initialize(num_par_rem_sets(), max_regions);
+}
+
ScanRSClosure::ScanRSClosure(G1ParPushHeapRSClosure* oc,
CodeBlobClosure* code_root_cl,
uint worker_i) :
--- a/hotspot/src/share/vm/gc/g1/g1RemSet.hpp Tue Dec 22 00:08:38 2015 +0000
+++ b/hotspot/src/share/vm/gc/g1/g1RemSet.hpp Tue Dec 22 11:02:04 2015 +0100
@@ -75,6 +75,16 @@
G1ParPushHeapRSClosure** _cset_rs_update_cl;
public:
+ // Gives an approximation on how many threads can be expected to add records to
+ // a remembered set in parallel. This can be used for sizing data structures to
+ // decrease performance losses due to data structure sharing.
+ // Examples for quantities that influence this value are the maximum number of
+ // mutator threads, maximum number of concurrent refinement or GC threads.
+ static uint num_par_rem_sets();
+
+ // Initialize data that depends on the heap size being known.
+ static void initialize(uint max_regions);
+
// This is called to reset dual hash tables after the gc pause
// is finished and the initial hash table is no longer being
// scanned.
--- a/hotspot/src/share/vm/gc/g1/heapRegion.cpp Tue Dec 22 00:08:38 2015 +0000
+++ b/hotspot/src/share/vm/gc/g1/heapRegion.cpp Tue Dec 22 11:02:04 2015 +0100
@@ -258,7 +258,6 @@
_predicted_bytes_to_copy(0)
{
_rem_set = new HeapRegionRemSet(sharedOffsetArray, this);
- assert(HeapRegionRemSet::num_par_rem_sets() > 0, "Invariant.");
initialize(mr);
}
--- a/hotspot/src/share/vm/gc/g1/heapRegionRemSet.cpp Tue Dec 22 00:08:38 2015 +0000
+++ b/hotspot/src/share/vm/gc/g1/heapRegionRemSet.cpp Tue Dec 22 11:02:04 2015 +0100
@@ -687,13 +687,6 @@
_sparse_table.do_cleanup_work(hrrs_cleanup_task);
}
-// Determines how many threads can add records to an rset in parallel.
-// This can be done by either mutator threads together with the
-// concurrent refinement threads or GC threads.
-uint HeapRegionRemSet::num_par_rem_sets() {
- return MAX2(DirtyCardQueueSet::num_par_ids() + ConcurrentG1Refine::thread_num(), ParallelGCThreads);
-}
-
HeapRegionRemSet::HeapRegionRemSet(G1BlockOffsetSharedArray* bosa,
HeapRegion* hr)
: _bosa(bosa),
--- a/hotspot/src/share/vm/gc/g1/heapRegionRemSet.hpp Tue Dec 22 00:08:38 2015 +0000
+++ b/hotspot/src/share/vm/gc/g1/heapRegionRemSet.hpp Tue Dec 22 11:02:04 2015 +0100
@@ -191,7 +191,6 @@
public:
HeapRegionRemSet(G1BlockOffsetSharedArray* bosa, HeapRegion* hr);
- static uint num_par_rem_sets();
static void setup_remset_size();
bool is_empty() const {
@@ -321,12 +320,6 @@
// Called during a stop-world phase to perform any deferred cleanups.
static void cleanup();
- // Declare the heap size (in # of regions) to the HeapRegionRemSet(s).
- // (Uses it to initialize from_card_cache).
- static void init_heap(uint max_regions) {
- G1FromCardCache::initialize(num_par_rem_sets(), max_regions);
- }
-
static void invalidate_from_card_cache(uint start_idx, size_t num_regions) {
G1FromCardCache::invalidate(start_idx, num_regions);
}