8145672: Remove dependency of G1FromCardCache to HeapRegionRemSet

Move HeapRegionRemSet::num_par_rem_sets() to G1RemSet, and document it.

Reviewed-by: mgerdin, jmasa
This commit is contained in:
Thomas Schatzl 2015-12-22 11:02:04 +01:00
parent 365b569764
commit 056fb6bfd3
8 changed files with 33 additions and 31 deletions

View file

@ -1789,9 +1789,6 @@ G1CollectedHeap::G1CollectedHeap(G1CollectorPolicy* policy_) :
uint n_queues = ParallelGCThreads; uint n_queues = ParallelGCThreads;
_task_queues = new RefToScanQueueSet(n_queues); _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 = NEW_C_HEAP_ARRAY(HeapRegion*, n_queues, mtGC);
_worker_cset_start_region_time_stamp = NEW_C_HEAP_ARRAY(uint, 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); _evacuation_failed_info_array = NEW_C_HEAP_ARRAY(EvacuationFailedInfo, n_queues, mtGC);
@ -1891,7 +1888,6 @@ jint G1CollectedHeap::initialize() {
_g1_rem_set = new G1RemSet(this, g1_barrier_set()); _g1_rem_set = new G1RemSet(this, g1_barrier_set());
// Carve out the G1 part of the heap. // Carve out the G1 part of the heap.
ReservedSpace g1_rs = heap_rs.first_part(max_byte_size); ReservedSpace g1_rs = heap_rs.first_part(max_byte_size);
size_t page_size = UseLargePages ? os::large_page_size() : os::vm_page_size(); size_t page_size = UseLargePages ? os::large_page_size() : os::vm_page_size();
G1RegionToSpaceMapper* heap_storage = G1RegionToSpaceMapper* heap_storage =
@ -1940,6 +1936,8 @@ jint G1CollectedHeap::initialize() {
const uint max_region_idx = (1U << (sizeof(RegionIdx_t)*BitsPerByte-1)) - 1; const uint max_region_idx = (1U << (sizeof(RegionIdx_t)*BitsPerByte-1)) - 1;
guarantee((max_regions() - 1) <= max_region_idx, "too many regions"); 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; 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 > 0, "make sure it's initialized");
guarantee(HeapRegion::CardsPerRegion < max_cards_per_region, guarantee(HeapRegion::CardsPerRegion < max_cards_per_region,
@ -1967,9 +1965,6 @@ jint G1CollectedHeap::initialize() {
} }
_cmThread = _cm->cmThread(); _cmThread = _cm->cmThread();
// Initialize the from_card cache structure of HeapRegionRemSet.
HeapRegionRemSet::init_heap(max_regions());
// Now expand into the initial heap size. // Now expand into the initial heap size.
if (!expand(init_byte_size)) { if (!expand(init_byte_size)) {
vm_shutdown_during_initialization("Failed to allocate initial heap."); vm_shutdown_during_initialization("Failed to allocate initial heap.");

View file

@ -24,7 +24,7 @@
#include "precompiled.hpp" #include "precompiled.hpp"
#include "gc/g1/g1FromCardCache.hpp" #include "gc/g1/g1FromCardCache.hpp"
#include "gc/g1/heapRegionRemSet.hpp" #include "gc/g1/g1RemSet.hpp"
#include "memory/padded.inline.hpp" #include "memory/padded.inline.hpp"
#include "utilities/debug.hpp" #include "utilities/debug.hpp"
@ -32,11 +32,12 @@ int** G1FromCardCache::_cache = NULL;
uint G1FromCardCache::_max_regions = 0; uint G1FromCardCache::_max_regions = 0;
size_t G1FromCardCache::_static_mem_size = 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"); guarantee(_cache == NULL, "Should not call this multiple times");
_max_regions = max_num_regions; _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, _max_regions,
&_static_mem_size); &_static_mem_size);
@ -47,9 +48,10 @@ void G1FromCardCache::invalidate(uint start_idx, size_t new_num_regions) {
guarantee((size_t)start_idx + new_num_regions <= max_uintx, guarantee((size_t)start_idx + new_num_regions <= max_uintx,
"Trying to invalidate beyond maximum region, from %u size " SIZE_FORMAT, "Trying to invalidate beyond maximum region, from %u size " SIZE_FORMAT,
start_idx, new_num_regions); 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);
uint end_idx = (start_idx + (uint)new_num_regions); assert(end_idx <= _max_regions, "Must be within max.");
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++) { for (uint j = start_idx; j < end_idx; j++) {
set(i, j, InvalidCard); set(i, j, InvalidCard);
} }
@ -58,7 +60,7 @@ void G1FromCardCache::invalidate(uint start_idx, size_t new_num_regions) {
#ifndef PRODUCT #ifndef PRODUCT
void G1FromCardCache::print(outputStream* out) { 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++) { for (uint j = 0; j < _max_regions; j++) {
out->print_cr("_from_card_cache[%u][%u] = %d.", out->print_cr("_from_card_cache[%u][%u] = %d.",
i, j, at(i, j)); i, j, at(i, j));
@ -68,7 +70,7 @@ void G1FromCardCache::print(outputStream* out) {
#endif #endif
void G1FromCardCache::clear(uint region_idx) { 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++) { for (uint i = 0; i < num_par_remsets; i++) {
set(i, region_idx, InvalidCard); set(i, region_idx, InvalidCard);
} }

View file

@ -65,7 +65,7 @@ class G1FromCardCache : public AllStatic {
_cache[worker_id][region_idx] = val; _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); static void invalidate(uint start_idx, size_t num_regions);

View file

@ -25,9 +25,11 @@
#include "precompiled.hpp" #include "precompiled.hpp"
#include "gc/g1/concurrentG1Refine.hpp" #include "gc/g1/concurrentG1Refine.hpp"
#include "gc/g1/concurrentG1RefineThread.hpp" #include "gc/g1/concurrentG1RefineThread.hpp"
#include "gc/g1/dirtyCardQueue.hpp"
#include "gc/g1/g1BlockOffsetTable.inline.hpp" #include "gc/g1/g1BlockOffsetTable.inline.hpp"
#include "gc/g1/g1CollectedHeap.inline.hpp" #include "gc/g1/g1CollectedHeap.inline.hpp"
#include "gc/g1/g1CollectorPolicy.hpp" #include "gc/g1/g1CollectorPolicy.hpp"
#include "gc/g1/g1FromCardCache.hpp"
#include "gc/g1/g1GCPhaseTimes.hpp" #include "gc/g1/g1GCPhaseTimes.hpp"
#include "gc/g1/g1HotCardCache.hpp" #include "gc/g1/g1HotCardCache.hpp"
#include "gc/g1/g1OopClosures.inline.hpp" #include "gc/g1/g1OopClosures.inline.hpp"
@ -76,6 +78,14 @@ G1RemSet::~G1RemSet() {
FREE_C_HEAP_ARRAY(G1ParPushHeapRSClosure*, _cset_rs_update_cl); 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, ScanRSClosure::ScanRSClosure(G1ParPushHeapRSClosure* oc,
CodeBlobClosure* code_root_cl, CodeBlobClosure* code_root_cl,
uint worker_i) : uint worker_i) :

View file

@ -75,6 +75,16 @@ protected:
G1ParPushHeapRSClosure** _cset_rs_update_cl; G1ParPushHeapRSClosure** _cset_rs_update_cl;
public: 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 // This is called to reset dual hash tables after the gc pause
// is finished and the initial hash table is no longer being // is finished and the initial hash table is no longer being
// scanned. // scanned.

View file

@ -258,7 +258,6 @@ HeapRegion::HeapRegion(uint hrm_index,
_predicted_bytes_to_copy(0) _predicted_bytes_to_copy(0)
{ {
_rem_set = new HeapRegionRemSet(sharedOffsetArray, this); _rem_set = new HeapRegionRemSet(sharedOffsetArray, this);
assert(HeapRegionRemSet::num_par_rem_sets() > 0, "Invariant.");
initialize(mr); initialize(mr);
} }

View file

@ -687,13 +687,6 @@ OtherRegionsTable::do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task) {
_sparse_table.do_cleanup_work(hrrs_cleanup_task); _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, HeapRegionRemSet::HeapRegionRemSet(G1BlockOffsetSharedArray* bosa,
HeapRegion* hr) HeapRegion* hr)
: _bosa(bosa), : _bosa(bosa),

View file

@ -191,7 +191,6 @@ private:
public: public:
HeapRegionRemSet(G1BlockOffsetSharedArray* bosa, HeapRegion* hr); HeapRegionRemSet(G1BlockOffsetSharedArray* bosa, HeapRegion* hr);
static uint num_par_rem_sets();
static void setup_remset_size(); static void setup_remset_size();
bool is_empty() const { bool is_empty() const {
@ -321,12 +320,6 @@ public:
// Called during a stop-world phase to perform any deferred cleanups. // Called during a stop-world phase to perform any deferred cleanups.
static void cleanup(); 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) { static void invalidate_from_card_cache(uint start_idx, size_t num_regions) {
G1FromCardCache::invalidate(start_idx, num_regions); G1FromCardCache::invalidate(start_idx, num_regions);
} }