< prev index next >

src/share/vm/gc/shenandoah/shenandoahBarrierSet.cpp

Print this page
rev 13055 : Implement barriers for maintaining connection matrix.

@@ -22,10 +22,11 @@
  */
 
 #include "precompiled.hpp"
 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
+#include "gc/shenandoah/shenandoahConnectionMatrix.hpp"
 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
 #include "runtime/interfaceSupport.hpp"
 
 class UpdateRefsForOopClosure: public ExtendedOopClosure {
 

@@ -48,10 +49,36 @@
     do_oop_work(p);
   }
 
 };
 
+class UpdateRefsForOopMatrixClosure: public ExtendedOopClosure {
+
+private:
+  ShenandoahHeap* _heap;
+  template <class T>
+  inline void do_oop_work(T* p) {
+    oop o = _heap->maybe_update_oop_ref(p);
+    if (! oopDesc::is_null(o)) {
+      _heap->connection_matrix()->set_connected(_heap->heap_region_index_containing(p), _heap->heap_region_index_containing(o), true);
+    }
+  }
+public:
+  UpdateRefsForOopMatrixClosure() {
+    _heap = ShenandoahHeap::heap();
+  }
+
+  void do_oop(oop* p)       {
+    do_oop_work(p);
+  }
+
+  void do_oop(narrowOop* p) {
+    do_oop_work(p);
+  }
+
+};
+
 ShenandoahBarrierSet::ShenandoahBarrierSet(ShenandoahHeap* heap) :
   BarrierSet(BarrierSet::FakeRtti(BarrierSet::ShenandoahBarrierSet)),
   _heap(heap)
 {
 }

@@ -158,28 +185,37 @@
   Unimplemented();
   return false;
 }
 
 bool ShenandoahBarrierSet::need_update_refs_barrier() {
-  return _heap->concurrent_mark_in_progress() && _heap->need_update_refs();
+  return UseShenandoahMatrix || (_heap->concurrent_mark_in_progress() && _heap->need_update_refs());
 }
 
 void ShenandoahBarrierSet::write_ref_array_work(MemRegion r) {
   ShouldNotReachHere();
 }
 
 void ShenandoahBarrierSet::write_ref_array(HeapWord* start, size_t count) {
   if (! need_update_refs_barrier()) return;
+  ShenandoahHeap* heap = ShenandoahHeap::heap();
+  ShenandoahConnectionMatrix* matrix = heap->connection_matrix();
+  // TODO: Use templated loop and split on oop/narrowOop and UseShenandoahMatrix.
   if (UseCompressedOops) {
     narrowOop* dst = (narrowOop*) start;
     for (size_t i = 0; i < count; i++, dst++) {
-      _heap->maybe_update_oop_ref(dst);
+      oop o = _heap->maybe_update_oop_ref(dst);
+      if (UseShenandoahMatrix && ! oopDesc::is_null(o)) {
+        matrix->set_connected(heap->heap_region_index_containing(dst), heap->heap_region_index_containing(o), true);
+      }
     }
   } else {
     oop* dst = (oop*) start;
     for (size_t i = 0; i < count; i++, dst++) {
-      _heap->maybe_update_oop_ref(dst);
+      oop o = _heap->maybe_update_oop_ref(dst);
+      if (UseShenandoahMatrix && ! oopDesc::is_null(o)) {
+        matrix->set_connected(heap->heap_region_index_containing(dst), heap->heap_region_index_containing(o), true);
+      }
     }
   }
 }
 
 template <class T>

@@ -216,14 +252,15 @@
     write_ref_array_pre_work(dst, count);
   }
 }
 
 template <class T>
-void ShenandoahBarrierSet::write_ref_field_pre_static(T* field, oop newVal) {
+void ShenandoahBarrierSet::write_ref_field_pre_static(T* field, oop new_val) {
   T heap_oop = oopDesc::load_heap_oop(field);
 
 #ifdef ASSERT
+  {
   ShenandoahHeap* heap = ShenandoahHeap::heap();
     if (heap->is_in(field) &&
         heap->in_collection_set(field) &&
         ! heap->cancelled_concgc()) {
       tty->print_cr("field = "PTR_FORMAT, p2i(field));

@@ -232,15 +269,21 @@
       tty->print_cr("marking: %s, evacuating: %s",
                     BOOL_TO_STR(heap->concurrent_mark_in_progress()),
                     BOOL_TO_STR(heap->is_evacuation_in_progress()));
       assert(false, "We should have fixed this earlier");
     }
+  }
 #endif
 
   if (!oopDesc::is_null(heap_oop)) {
     G1SATBCardTableModRefBS::enqueue(oopDesc::decode_heap_oop(heap_oop));
   }
+  if (UseShenandoahMatrix && ! oopDesc::is_null(new_val)) {
+    ShenandoahHeap* heap = ShenandoahHeap::heap();
+    ShenandoahConnectionMatrix* matrix = heap->connection_matrix();
+    matrix->set_connected(heap->heap_region_index_containing(field), heap->heap_region_index_containing(new_val), true);
+  }
 }
 
 template <class T>
 inline void ShenandoahBarrierSet::inline_write_ref_field_pre(T* field, oop newVal) {
   write_ref_field_pre_static(field, newVal);

@@ -266,14 +309,20 @@
     tty->print_cr("field not in collection set: "PTR_FORMAT, p2i(v));
     tty->print_cr("containing heap region:");
     ShenandoahHeap::heap()->heap_region_containing(v)->print();
   }
   assert(heap->cancelled_concgc() || !heap->in_collection_set(v), "only write to to-space");
-  if (! need_update_refs_barrier()) return;
+  if (_heap->concurrent_mark_in_progress()) {
   assert(o == NULL || oopDesc::unsafe_equals(o, resolve_oop_static(o)), "only write to-space values");
   assert(o == NULL || !heap->in_collection_set(o), "only write to-space values");
+  }
 #endif
+  if (UseShenandoahMatrix && ! oopDesc::is_null(o)) {
+    ShenandoahHeap* heap = ShenandoahHeap::heap();
+    ShenandoahConnectionMatrix* matrix = heap->connection_matrix();
+    matrix->set_connected(heap->heap_region_index_containing(v), heap->heap_region_index_containing(o), true);
+  }
 }
 
 void ShenandoahBarrierSet::write_region_work(MemRegion mr) {
 
   if (! need_update_refs_barrier()) return;

@@ -283,12 +332,17 @@
   // it would be NULL in any case. But we *are* interested in any oop*
   // that potentially need to be updated.
 
   oop obj = oop(mr.start());
   assert(obj->is_oop(), "must be an oop");
+  if (UseShenandoahMatrix) {
+    UpdateRefsForOopMatrixClosure cl;
+    obj->oop_iterate(&cl);
+  } else {
   UpdateRefsForOopClosure cl;
   obj->oop_iterate(&cl);
+  }
 }
 
 oop ShenandoahBarrierSet::read_barrier(oop src) {
   if (ShenandoahReadBarrier) {
     return ShenandoahBarrierSet::resolve_oop_static(src);
< prev index next >