src/hotspot/share/gc/g1/heapRegionRemSet.hpp
changeset 52347 14ef0f74667b
parent 52345 418fb8bb5151
child 52716 877dd2b0f36c
--- 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);
   }