< prev index next >

src/hotspot/share/gc/parallel/mutableSpace.cpp

Print this page
@@ -231,15 +231,40 @@
    while (obj_addr < t) {
      obj_addr += cast_to_oop(obj_addr)->oop_iterate_size(cl);
    }
  }
  
- void MutableSpace::object_iterate(ObjectClosure* cl) {
+ template<bool COMPACT_HEADERS>
+ void MutableSpace::object_iterate_impl(ObjectClosure* cl) {
    HeapWord* p = bottom();
    while (p < top()) {
-     cl->do_object(cast_to_oop(p));
-     p += cast_to_oop(p)->size();
+     oop obj = cast_to_oop(p);
+     // When promotion-failure occurs during Young GC, eden/from space is not cleared,
+     // so we can encounter objects with "forwarded" markword.
+     // They are essentially dead, so skipping them
+     if (!obj->is_forwarded()) {
+       cl->do_object(obj);
+       p += obj->size();
+     } else {
+       assert(obj->forwardee() != obj, "must not be self-forwarded");
+       if (COMPACT_HEADERS) {
+         // It is safe to use the forwardee here. Parallel GC only uses
+         // header-based forwarding during promotion. Full GC doesn't
+         // use the object header for forwarding at all.
+         p += obj->forwardee()->size();
+       } else {
+         p += obj->size();
+       }
+     }
+   }
+ }
+ 
+ void MutableSpace::object_iterate(ObjectClosure* cl) {
+   if (UseCompactObjectHeaders) {
+     object_iterate_impl<true>(cl);
+   } else {
+     object_iterate_impl<false>(cl);
    }
  }
  
  void MutableSpace::print_short() const { print_short_on(tty); }
  void MutableSpace::print_short_on( outputStream* st) const {
< prev index next >