8151556: Use the PreservedMarks* classes for the G1 preserved mark stacks
authortonyp
Tue, 26 Apr 2016 10:23:08 +0200
changeset 38081 a3bcb7197d45
parent 38080 bb02a3ad3b0a
child 38082 4819f68a93a6
child 38087 377153ad27c8
8151556: Use the PreservedMarks* classes for the G1 preserved mark stacks Reviewed-by: tschatzl
hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp
hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp
hotspot/src/share/vm/gc/g1/g1EvacFailure.cpp
hotspot/src/share/vm/gc/g1/g1EvacFailure.hpp
hotspot/src/share/vm/gc/shared/preservedMarks.hpp
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp	Tue Apr 26 10:19:57 2016 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp	Tue Apr 26 10:23:08 2016 +0200
@@ -65,6 +65,7 @@
 #include "gc/shared/gcTraceTime.inline.hpp"
 #include "gc/shared/generationSpec.hpp"
 #include "gc/shared/isGCActiveMark.hpp"
+#include "gc/shared/preservedMarks.inline.hpp"
 #include "gc/shared/referenceProcessor.inline.hpp"
 #include "gc/shared/taskqueue.inline.hpp"
 #include "logging/log.hpp"
@@ -1759,6 +1760,7 @@
   _cg1r(NULL),
   _g1mm(NULL),
   _refine_cte_cl(NULL),
+  _preserved_marks_set(true /* in_c_heap */),
   _secondary_free_list("Secondary Free List", new SecondaryFreeRegionListMtSafeChecker()),
   _old_set("Old Set", false /* humongous */, new OldRegionSetMtSafeChecker()),
   _humongous_set("Master Humongous Set", true /* humongous */, new HumongousRegionSetMtSafeChecker()),
@@ -2034,10 +2036,7 @@
 
   G1StringDedup::initialize();
 
-  _preserved_objs = NEW_C_HEAP_ARRAY(OopAndMarkOopStack, ParallelGCThreads, mtGC);
-  for (uint i = 0; i < ParallelGCThreads; i++) {
-    new (&_preserved_objs[i]) OopAndMarkOopStack();
-  }
+  _preserved_marks_set.init(ParallelGCThreads);
 
   return JNI_OK;
 }
@@ -3527,11 +3526,6 @@
   return true;
 }
 
-void G1CollectedHeap::restore_preserved_marks() {
-  G1RestorePreservedMarksTask rpm_task(_preserved_objs);
-  workers()->run_task(&rpm_task);
-}
-
 void G1CollectedHeap::remove_self_forwarding_pointers() {
   G1ParRemoveSelfForwardPtrsTask rsfp_task;
   workers()->run_task(&rsfp_task);
@@ -3541,7 +3535,7 @@
   double remove_self_forwards_start = os::elapsedTime();
 
   remove_self_forwarding_pointers();
-  restore_preserved_marks();
+  _preserved_marks_set.restore(workers());
 
   g1_policy()->phase_times()->record_evac_fail_remove_self_forwards((os::elapsedTime() - remove_self_forwards_start) * 1000.0);
 }
@@ -3552,13 +3546,7 @@
   }
 
   _evacuation_failed_info_array[worker_id].register_copy_failure(obj->size());
-
-  // We want to call the "for_promotion_failure" version only in the
-  // case of a promotion failure.
-  if (m->must_be_preserved_for_promotion_failure(obj)) {
-    OopAndMarkOop elem(obj, m);
-    _preserved_objs[worker_id].push(elem);
-  }
+  _preserved_marks_set.get(worker_id)->push_if_necessary(obj, m);
 }
 
 bool G1ParEvacuateFollowersClosure::offer_termination() {
@@ -4581,6 +4569,7 @@
   hot_card_cache->set_use_cache(false);
 
   g1_rem_set()->prepare_for_oops_into_collection_set_do();
+  _preserved_marks_set.assert_empty();
 }
 
 void G1CollectedHeap::evacuate_collection_set(EvacuationInfo& evacuation_info, G1ParScanThreadStateSet* per_thread_states) {
@@ -4658,6 +4647,8 @@
     NOT_PRODUCT(reset_evacuation_should_fail();)
   }
 
+  _preserved_marks_set.assert_empty();
+
   // Enqueue any remaining references remaining on the STW
   // reference processor's discovered lists. We need to do
   // this after the card table is cleaned (and verified) as
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp	Tue Apr 26 10:19:57 2016 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp	Tue Apr 26 10:23:08 2016 +0200
@@ -45,6 +45,7 @@
 #include "gc/shared/barrierSet.hpp"
 #include "gc/shared/collectedHeap.hpp"
 #include "gc/shared/plab.hpp"
+#include "gc/shared/preservedMarks.hpp"
 #include "memory/memRegion.hpp"
 #include "utilities/stack.hpp"
 
@@ -797,16 +798,11 @@
   // forwarding pointers to themselves.  Reset them.
   void remove_self_forwarding_pointers();
 
-  // Restore the preserved mark words for objects with self-forwarding pointers.
-  void restore_preserved_marks();
-
   // Restore the objects in the regions in the collection set after an
   // evacuation failure.
   void restore_after_evac_failure();
 
-  // Stores marks with the corresponding oop that we need to preserve during evacuation
-  // failure.
-  OopAndMarkOopStack*  _preserved_objs;
+  PreservedMarksSet _preserved_marks_set;
 
   // Preserve the mark of "obj", if necessary, in preparation for its mark
   // word being overwritten with a self-forwarding-pointer.
--- a/hotspot/src/share/vm/gc/g1/g1EvacFailure.cpp	Tue Apr 26 10:19:57 2016 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1EvacFailure.cpp	Tue Apr 26 10:23:08 2016 +0200
@@ -33,6 +33,7 @@
 #include "gc/g1/g1_globals.hpp"
 #include "gc/g1/heapRegion.hpp"
 #include "gc/g1/heapRegionRemSet.hpp"
+#include "gc/shared/preservedMarks.inline.hpp"
 
 class UpdateRSetDeferred : public OopsInHeapRegionClosure {
 private:
@@ -122,7 +123,7 @@
       size_t obj_size = obj->size();
 
       _marked_bytes += (obj_size * HeapWordSize);
-      obj->set_mark(markOopDesc::prototype());
+      PreservedMarks::init_forwarded_mark(obj);
 
       // While we were processing RSet buffers during the collection,
       // we actually didn't scan any cards on the collection set,
@@ -253,16 +254,3 @@
   HeapRegion* hr = _g1h->start_cset_region_for_worker(worker_id);
   _g1h->collection_set_iterate_from(hr, &rsfp_cl);
 }
-
-G1RestorePreservedMarksTask::G1RestorePreservedMarksTask(OopAndMarkOopStack* preserved_objs) :
-  AbstractGangTask("G1 Restore Preserved Marks"),
-  _preserved_objs(preserved_objs) {}
-
-void G1RestorePreservedMarksTask::work(uint worker_id) {
-  OopAndMarkOopStack& cur = _preserved_objs[worker_id];
-  while (!cur.is_empty()) {
-    OopAndMarkOop elem = cur.pop();
-    elem.set_mark();
-  }
-  cur.clear(true);
-}
--- a/hotspot/src/share/vm/gc/g1/g1EvacFailure.hpp	Tue Apr 26 10:19:57 2016 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1EvacFailure.hpp	Tue Apr 26 10:23:08 2016 +0200
@@ -27,7 +27,6 @@
 
 #include "gc/g1/g1OopClosures.hpp"
 #include "gc/g1/heapRegionManager.hpp"
- #include "gc/shared/preservedMarks.hpp"
 #include "gc/shared/workgroup.hpp"
 #include "utilities/globalDefinitions.hpp"
 
@@ -46,12 +45,4 @@
   void work(uint worker_id);
 };
 
-class G1RestorePreservedMarksTask : public AbstractGangTask {
-  OopAndMarkOopStack* _preserved_objs;
- public:
-  G1RestorePreservedMarksTask(OopAndMarkOopStack* preserved_objs);
-
-  void work(uint worker_id);
-};
-
 #endif // SHARE_VM_GC_G1_G1EVACFAILURE_HPP
--- a/hotspot/src/share/vm/gc/shared/preservedMarks.hpp	Tue Apr 26 10:19:57 2016 +0200
+++ b/hotspot/src/share/vm/gc/shared/preservedMarks.hpp	Tue Apr 26 10:23:08 2016 +0200
@@ -30,25 +30,25 @@
 #include "oops/oop.hpp"
 #include "utilities/stack.hpp"
 
-class OopAndMarkOop {
-private:
-  oop _o;
-  markOop _m;
-
-public:
-  OopAndMarkOop(oop obj, markOop m) : _o(obj), _m(m) { }
-
-  void set_mark() const {
-    _o->set_mark(_m);
-  }
-};
-typedef Stack<OopAndMarkOop, mtGC> OopAndMarkOopStack;
-
 class GCTaskManager;
 class WorkGang;
 
 class PreservedMarks VALUE_OBJ_CLASS_SPEC {
 private:
+  class OopAndMarkOop {
+  private:
+    oop _o;
+    markOop _m;
+
+  public:
+    OopAndMarkOop(oop obj, markOop m) : _o(obj), _m(m) { }
+
+    void set_mark() const {
+      _o->set_mark(_m);
+    }
+  };
+  typedef Stack<OopAndMarkOop, mtGC> OopAndMarkOopStack;
+
   OopAndMarkOopStack _stack;
 
   inline bool should_preserve_mark(oop obj, markOop m) const;