8075249: Cleanup forward_to_atomic and ClaimedForwardPtr
authorstefank
Tue, 17 Mar 2015 15:53:55 +0100
changeset 29689 dc72789f83ae
parent 29688 2a0cad173059
child 29690 02ce43f0f95a
child 29691 c539e3e94ef1
8075249: Cleanup forward_to_atomic and ClaimedForwardPtr Reviewed-by: kbarrett, brutisso
hotspot/src/share/vm/gc_implementation/g1/g1ParScanThreadState.cpp
hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp
hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.hpp
hotspot/src/share/vm/oops/oop.inline.hpp
hotspot/src/share/vm/oops/oop.pcgc.inline.hpp
--- a/hotspot/src/share/vm/gc_implementation/g1/g1ParScanThreadState.cpp	Tue Mar 17 14:18:52 2015 +0100
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1ParScanThreadState.cpp	Tue Mar 17 15:53:55 2015 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2015, 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
@@ -226,6 +226,8 @@
   }
 
   assert(obj_ptr != NULL, "when we get here, allocation should have succeeded");
+  assert(_g1h->is_in_reserved(obj_ptr), "Allocated memory should be in the heap");
+
 #ifndef PRODUCT
   // Should this evacuation fail?
   if (_g1h->evacuation_should_fail()) {
--- a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp	Tue Mar 17 14:18:52 2015 +0100
+++ b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp	Tue Mar 17 15:53:55 2015 +0100
@@ -1122,14 +1122,6 @@
   return forward_ptr;
 }
 
-#ifdef ASSERT
-bool ParNewGeneration::is_legal_forward_ptr(oop p) {
-  return
-    (p == ClaimedForwardPtr)
-    || Universe::heap()->is_in_reserved(p);
-}
-#endif
-
 void ParNewGeneration::preserve_mark_if_necessary(oop obj, markOop m) {
   if (m->must_be_preserved_for_promotion_failure(obj)) {
     // We should really have separate per-worker stacks, rather
@@ -1204,6 +1196,7 @@
   } else {
     // Is in to-space; do copying ourselves.
     Copy::aligned_disjoint_words((HeapWord*)old, (HeapWord*)new_obj, sz);
+    assert(Universe::heap()->is_in_reserved(new_obj), "illegal forwarding pointer value.");
     forward_ptr = old->forward_to_atomic(new_obj);
     // Restore the mark word copied above.
     new_obj->set_mark(m);
--- a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.hpp	Tue Mar 17 14:18:52 2015 +0100
+++ b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.hpp	Tue Mar 17 15:53:55 2015 +0100
@@ -419,8 +419,6 @@
   }
 
   static oop real_forwardee(oop obj);
-
-  DEBUG_ONLY(static bool is_legal_forward_ptr(oop p);)
 };
 
 #endif // SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARNEWGENERATION_HPP
--- a/hotspot/src/share/vm/oops/oop.inline.hpp	Tue Mar 17 14:18:52 2015 +0100
+++ b/hotspot/src/share/vm/oops/oop.inline.hpp	Tue Mar 17 15:53:55 2015 +0100
@@ -630,6 +630,30 @@
   return cas_set_mark(m, compare) == compare;
 }
 
+#if INCLUDE_ALL_GCS
+inline oop oopDesc::forward_to_atomic(oop p) {
+  markOop oldMark = mark();
+  markOop forwardPtrMark = markOopDesc::encode_pointer_as_mark(p);
+  markOop curMark;
+
+  assert(forwardPtrMark->decode_pointer() == p, "encoding must be reversable");
+  assert(sizeof(markOop) == sizeof(intptr_t), "CAS below requires this.");
+
+  while (!oldMark->is_marked()) {
+    curMark = (markOop)Atomic::cmpxchg_ptr(forwardPtrMark, &_mark, oldMark);
+    assert(is_forwarded(), "object should have been forwarded");
+    if (curMark == oldMark) {
+      return NULL;
+    }
+    // If the CAS was unsuccessful then curMark->is_marked()
+    // should return true as another thread has CAS'd in another
+    // forwarding pointer.
+    oldMark = curMark;
+  }
+  return forwardee();
+}
+#endif
+
 // Note that the forwardee is not the same thing as the displaced_mark.
 // The forwardee is used when copying during scavenge and mark-sweep.
 // It does need to clear the low two locking- and GC-related bits.
--- a/hotspot/src/share/vm/oops/oop.pcgc.inline.hpp	Tue Mar 17 14:18:52 2015 +0100
+++ b/hotspot/src/share/vm/oops/oop.pcgc.inline.hpp	Tue Mar 17 15:53:55 2015 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2015, 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
@@ -54,28 +54,4 @@
   klass()->oop_follow_contents(cm, this);
 }
 
-inline oop oopDesc::forward_to_atomic(oop p) {
-  assert(ParNewGeneration::is_legal_forward_ptr(p),
-         "illegal forwarding pointer value.");
-  markOop oldMark = mark();
-  markOop forwardPtrMark = markOopDesc::encode_pointer_as_mark(p);
-  markOop curMark;
-
-  assert(forwardPtrMark->decode_pointer() == p, "encoding must be reversable");
-  assert(sizeof(markOop) == sizeof(intptr_t), "CAS below requires this.");
-
-  while (!oldMark->is_marked()) {
-    curMark = (markOop)Atomic::cmpxchg_ptr(forwardPtrMark, &_mark, oldMark);
-    assert(is_forwarded(), "object should have been forwarded");
-    if (curMark == oldMark) {
-      return NULL;
-    }
-    // If the CAS was unsuccessful then curMark->is_marked()
-    // should return true as another thread has CAS'd in another
-    // forwarding pointer.
-    oldMark = curMark;
-  }
-  return forwardee();
-}
-
 #endif // SHARE_VM_OOPS_OOP_PCGC_INLINE_HPP