< prev index next >

src/share/vm/gc/g1/heapRegion.inline.hpp

Print this page
rev 13047 : imported patch 8071280-specialize-heapregion-oops-on-card-seq-iterate
rev 13048 : imported patch 8071280-kim-review
rev 13049 : imported patch 8071280-kim-sangheon-review
rev 13050 : imported patch 8071280-erikh-review

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -110,10 +110,28 @@
 inline HeapWord*
 G1ContiguousSpace::block_start_const(const void* p) const {
   return _bot_part.block_start_const(p);
 }
 
+inline bool HeapRegion::is_obj_dead_with_size(const oop obj, G1CMBitMapRO* prev_bitmap, size_t* size) const {
+  HeapWord* addr = (HeapWord*) obj;
+
+  assert(addr < top(), "must be");
+  assert(!is_archive(), "Archive regions should not have references into interesting regions.");
+  assert(!is_humongous(), "Humongous objects not handled here");
+  bool obj_is_dead = is_obj_dead(obj, prev_bitmap);
+
+  if (ClassUnloadingWithConcurrentMark && obj_is_dead) {
+    assert(!block_is_obj(addr), "must be");
+    *size = block_size_using_bitmap(addr, prev_bitmap);
+  } else {
+    assert(block_is_obj(addr), "must be");
+    *size = obj->size();
+  }
+  return obj_is_dead;
+}
+
 inline bool
 HeapRegion::block_is_obj(const HeapWord* p) const {
   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 
   if (!this->is_in(p)) {

@@ -124,37 +142,42 @@
     return !g1h->is_obj_dead(oop(p), this);
   }
   return p < top();
 }
 
-inline size_t
-HeapRegion::block_size(const HeapWord *addr) const {
-  if (addr == top()) {
-    return pointer_delta(end(), addr);
-  }
-
-  if (block_is_obj(addr)) {
-    return oop(addr)->size();
-  }
-
+inline size_t HeapRegion::block_size_using_bitmap(const HeapWord* addr, const G1CMBitMapRO* prev_bitmap) const {
   assert(ClassUnloadingWithConcurrentMark,
-         "All blocks should be objects if G1 Class Unloading isn't used. "
+         "All blocks should be objects if class unloading isn't used, so this method should not be called. "
          "HR: [" PTR_FORMAT ", " PTR_FORMAT ", " PTR_FORMAT ") "
          "addr: " PTR_FORMAT,
          p2i(bottom()), p2i(top()), p2i(end()), p2i(addr));
 
   // Old regions' dead objects may have dead classes
-  // We need to find the next live object in some other
-  // manner than getting the oop size
-  G1CollectedHeap* g1h = G1CollectedHeap::heap();
-  HeapWord* next = g1h->concurrent_mark()->prevMarkBitMap()->
-      getNextMarkedWordAddress(addr, prev_top_at_mark_start());
+  // We need to find the next live object using the bitmap
+  HeapWord* next = prev_bitmap->getNextMarkedWordAddress(addr, prev_top_at_mark_start());
 
   assert(next > addr, "must get the next live object");
   return pointer_delta(next, addr);
 }
 
+inline bool HeapRegion::is_obj_dead(const oop obj, const G1CMBitMapRO* prev_bitmap) const {
+  assert(is_in_reserved(obj), "Object " PTR_FORMAT " must be in region", p2i(obj));
+  return !obj_allocated_since_prev_marking(obj) && !prev_bitmap->isMarked((HeapWord*)obj);
+}
+
+inline size_t HeapRegion::block_size(const HeapWord *addr) const {
+  if (addr == top()) {
+    return pointer_delta(end(), addr);
+  }
+
+  if (block_is_obj(addr)) {
+    return oop(addr)->size();
+  }
+
+  return block_size_using_bitmap(addr, G1CollectedHeap::heap()->concurrent_mark()->prevMarkBitMap());
+}
+
 inline HeapWord* HeapRegion::par_allocate_no_bot_updates(size_t min_word_size,
                                                          size_t desired_word_size,
                                                          size_t* actual_word_size) {
   assert(is_young(), "we can only skip BOT updates on young regions");
   return par_allocate_impl(min_word_size, desired_word_size, actual_word_size);

@@ -228,6 +251,112 @@
 
 inline bool HeapRegion::in_collection_set() const {
   return G1CollectedHeap::heap()->is_in_cset(this);
 }
 
+template <class Closure, bool is_gc_active>
+bool HeapRegion::do_oops_on_card_in_humongous(MemRegion mr,
+                                              Closure* cl,
+                                              G1CollectedHeap* g1h) {
+  assert(is_humongous(), "precondition");
+  HeapRegion* sr = humongous_start_region();
+  oop obj = oop(sr->bottom());
+
+  // If concurrent and klass_or_null is NULL, then space has been
+  // allocated but the object has not yet been published by setting
+  // the klass.  That can only happen if the card is stale.  However,
+  // we've already set the card clean, so we must return failure,
+  // since the allocating thread could have performed a write to the
+  // card that might be missed otherwise.
+  if (!is_gc_active && (obj->klass_or_null_acquire() == NULL)) {
+    return false;
+  }
+
+  // We have a well-formed humongous object at the start of sr.
+  // Only filler objects follow a humongous object in the containing
+  // regions, and we can ignore those.  So only process the one
+  // humongous object.
+  if (!g1h->is_obj_dead(obj, sr)) {
+    if (obj->is_objArray() || (sr->bottom() < mr.start())) {
+      // objArrays are always marked precisely, so limit processing
+      // with mr.  Non-objArrays might be precisely marked, and since
+      // it's humongous it's worthwhile avoiding full processing.
+      // However, the card could be stale and only cover filler
+      // objects.  That should be rare, so not worth checking for;
+      // instead let it fall out from the bounded iteration.
+      obj->oop_iterate(cl, mr);
+    } else {
+      // If obj is not an objArray and mr contains the start of the
+      // obj, then this could be an imprecise mark, and we need to
+      // process the entire object.
+      obj->oop_iterate(cl);
+    }
+  }
+  return true;
+}
+
+template <bool is_gc_active, class Closure>
+bool HeapRegion::oops_on_card_seq_iterate_careful(MemRegion mr,
+                                                  Closure* cl) {
+  assert(MemRegion(bottom(), end()).contains(mr), "Card region not in heap region");
+  G1CollectedHeap* g1h = G1CollectedHeap::heap();
+
+  // Special handling for humongous regions.
+  if (is_humongous()) {
+    return do_oops_on_card_in_humongous<Closure, is_gc_active>(mr, cl, g1h);
+  }
+  assert(is_old(), "precondition");
+
+  // Because mr has been trimmed to what's been allocated in this
+  // region, the parts of the heap that are examined here are always
+  // parsable; there's no need to use klass_or_null to detect
+  // in-progress allocation.
+
+  // Cache the boundaries of the memory region in some const locals
+  HeapWord* const start = mr.start();
+  HeapWord* const end = mr.end();
+
+  // Find the obj that extends onto mr.start().
+  // Update BOT as needed while finding start of (possibly dead)
+  // object containing the start of the region.
+  HeapWord* cur = block_start(start);
+
+#ifdef ASSERT
+  {
+    assert(cur <= start,
+           "cur: " PTR_FORMAT ", start: " PTR_FORMAT, p2i(cur), p2i(start));
+    HeapWord* next = cur + block_size(cur);
+    assert(start < next,
+           "start: " PTR_FORMAT ", next: " PTR_FORMAT, p2i(start), p2i(next));
+  }
+#endif
+
+  G1CMBitMapRO* bitmap = g1h->concurrent_mark()->prevMarkBitMap();
+  do {
+    oop obj = oop(cur);
+    assert(obj->is_oop(true), "Not an oop at " PTR_FORMAT, p2i(cur));
+    assert(obj->klass_or_null() != NULL,
+           "Unparsable heap at " PTR_FORMAT, p2i(cur));
+
+    size_t size;
+    bool is_dead = is_obj_dead_with_size(obj, bitmap, &size);
+
+    cur += size;
+    if (!is_dead) {
+      // Process live object's references.
+
+      // Non-objArrays are usually marked imprecise at the object
+      // start, in which case we need to iterate over them in full.
+      // objArrays are precisely marked, but can still be iterated
+      // over in full if completely covered.
+      if (!obj->is_objArray() || (((HeapWord*)obj) >= start && cur <= end)) {
+        obj->oop_iterate(cl);
+      } else {
+        obj->oop_iterate(cl, mr);
+      }
+    }
+  } while (cur < end);
+
+  return true;
+}
+
 #endif // SHARE_VM_GC_G1_HEAPREGION_INLINE_HPP
< prev index next >