8211388: Make OtherRegionsTable independent of the region it is for
Reviewed-by: sjohanss, sangheki
--- a/src/hotspot/share/gc/g1/heapRegionRemSet.cpp Wed Oct 31 13:43:57 2018 +0100
+++ b/src/hotspot/share/gc/g1/heapRegionRemSet.cpp Wed Oct 31 13:43:57 2018 +0100
@@ -239,10 +239,9 @@
size_t OtherRegionsTable::_fine_eviction_stride = 0;
size_t OtherRegionsTable::_fine_eviction_sample_size = 0;
-OtherRegionsTable::OtherRegionsTable(HeapRegion* hr, Mutex* m) :
+OtherRegionsTable::OtherRegionsTable(Mutex* m) :
_g1h(G1CollectedHeap::heap()),
_m(m),
- _hr(hr),
_coarse_map(G1CollectedHeap::heap()->max_regions(), mtGC),
_n_coarse_entries(0),
_fine_grain_regions(NULL),
@@ -250,7 +249,7 @@
_first_all_fine_prts(NULL),
_last_all_fine_prts(NULL),
_fine_eviction_start(0),
- _sparse_table(hr)
+ _sparse_table()
{
typedef PerRegionTable* PerRegionTablePtr;
@@ -348,15 +347,6 @@
}
void OtherRegionsTable::add_reference(OopOrNarrowOopStar from, uint tid) {
- uint cur_hrm_ind = _hr->hrm_index();
-
- uintptr_t from_card = uintptr_t(from) >> CardTable::card_shift;
-
- if (G1FromCardCache::contains_or_replace(tid, cur_hrm_ind, from_card)) {
- assert(contains_reference(from), "We just found " PTR_FORMAT " in the FromCardCache", p2i(from));
- return;
- }
-
// Note that this may be a continued H region.
HeapRegion* from_hr = _g1h->heap_region_containing(from);
RegionIdx_t from_hrm_ind = (RegionIdx_t) from_hr->hrm_index();
@@ -569,10 +559,6 @@
return PerRegionTable::fl_mem_size();
}
-void OtherRegionsTable::clear_fcc() {
- G1FromCardCache::clear(_hr->hrm_index());
-}
-
void OtherRegionsTable::clear() {
// if there are no entries, skip this step
if (_first_all_fine_prts != NULL) {
@@ -590,8 +576,6 @@
}
_n_fine_entries = 0;
_n_coarse_entries = 0;
-
- clear_fcc();
}
bool OtherRegionsTable::contains_reference(OopOrNarrowOopStar from) const {
@@ -627,11 +611,16 @@
: _bot(bot),
_code_roots(),
_m(Mutex::leaf, FormatBuffer<128>("HeapRegionRemSet lock #%u", hr->hrm_index()), true, Monitor::_safepoint_check_never),
- _other_regions(hr, &_m),
+ _other_regions(&_m),
+ _hr(hr),
_state(Untracked)
{
}
+void HeapRegionRemSet::clear_fcc() {
+ G1FromCardCache::clear(_hr->hrm_index());
+}
+
void HeapRegionRemSet::setup_remset_size() {
// Setup sparse and fine-grain tables sizes.
// table_size = base * (log(region_size / 1M) + 1)
@@ -659,6 +648,7 @@
if (!only_cardset) {
_code_roots.clear();
}
+ clear_fcc();
_other_regions.clear();
set_state_empty();
assert(occupied_locked() == 0, "Should be clear.");
--- a/src/hotspot/share/gc/g1/heapRegionRemSet.hpp Wed Oct 31 13:43:57 2018 +0100
+++ b/src/hotspot/share/gc/g1/heapRegionRemSet.hpp Wed Oct 31 13:43:57 2018 +0100
@@ -76,7 +76,6 @@
G1CollectedHeap* _g1h;
Mutex* _m;
- HeapRegion* _hr;
// These are protected by "_m".
CHeapBitMap _coarse_map;
@@ -124,11 +123,8 @@
bool contains_reference_locked(OopOrNarrowOopStar from) const;
public:
- // Clear the from_card_cache entries for this region.
- void clear_fcc();
- // Create a new remembered set for the given heap region. The given mutex should
- // be used to ensure consistency.
- OtherRegionsTable(HeapRegion* hr, Mutex* m);
+ // Create a new remembered set. The given mutex is used to ensure consistency.
+ OtherRegionsTable(Mutex* m);
// Returns the card index of the given within_region pointer relative to the bottom
// of the given heap region.
@@ -182,6 +178,10 @@
OtherRegionsTable _other_regions;
+ HeapRegion* _hr;
+
+ void clear_fcc();
+
public:
HeapRegionRemSet(G1BlockOffsetTable* bot, HeapRegion* hr);
@@ -243,18 +243,18 @@
if (_state == Untracked) {
return;
}
- _other_regions.clear_fcc();
+ clear_fcc();
_state = Untracked;
}
void set_state_updating() {
guarantee(SafepointSynchronize::is_at_safepoint() && !is_tracked(), "Should only set to Updating from Untracked during safepoint but is %s", get_state_str());
- _other_regions.clear_fcc();
+ clear_fcc();
_state = Updating;
}
void set_state_complete() {
- _other_regions.clear_fcc();
+ clear_fcc();
_state = Complete;
}
@@ -269,6 +269,15 @@
if (state == Untracked) {
return;
}
+
+ uint cur_idx = _hr->hrm_index();
+ uintptr_t from_card = uintptr_t(from) >> CardTable::card_shift;
+
+ if (G1FromCardCache::contains_or_replace(tid, cur_idx, from_card)) {
+ assert(contains_reference(from), "We just found " PTR_FORMAT " in the FromCardCache", p2i(from));
+ return;
+ }
+
_other_regions.add_reference(from, tid);
}
--- a/src/hotspot/share/gc/g1/sparsePRT.cpp Wed Oct 31 13:43:57 2018 +0100
+++ b/src/hotspot/share/gc/g1/sparsePRT.cpp Wed Oct 31 13:43:57 2018 +0100
@@ -361,8 +361,8 @@
}
-SparsePRT::SparsePRT(HeapRegion* hr) :
- _hr(hr), _expanded(false), _next_expanded(NULL)
+SparsePRT::SparsePRT() :
+ _expanded(false), _next_expanded(NULL)
{
_cur = new RSHashTable(InitialCapacity);
_next = _cur;
--- a/src/hotspot/share/gc/g1/sparsePRT.hpp Wed Oct 31 13:43:57 2018 +0100
+++ b/src/hotspot/share/gc/g1/sparsePRT.hpp Wed Oct 31 13:43:57 2018 +0100
@@ -231,8 +231,6 @@
RSHashTable* _cur;
RSHashTable* _next;
- HeapRegion* _hr;
-
enum SomeAdditionalPrivateConstants {
InitialCapacity = 16
};
@@ -254,7 +252,7 @@
static SparsePRT* volatile _head_expanded_list;
public:
- SparsePRT(HeapRegion* hr);
+ SparsePRT();
~SparsePRT();