< prev index next >

src/hotspot/share/oops/oop.inline.hpp

Print this page
@@ -32,14 +32,15 @@
  #include "oops/access.inline.hpp"
  #include "oops/arrayKlass.hpp"
  #include "oops/arrayOop.hpp"
  #include "oops/compressedKlass.inline.hpp"
  #include "oops/instanceKlass.hpp"
- #include "oops/markWord.hpp"
+ #include "oops/markWord.inline.hpp"
  #include "oops/oopsHierarchy.hpp"
  #include "runtime/atomic.hpp"
  #include "runtime/globals.hpp"
+ #include "runtime/safepoint.hpp"
  #include "utilities/align.hpp"
  #include "utilities/debug.hpp"
  #include "utilities/macros.hpp"
  #include "utilities/globalDefinitions.hpp"
  

@@ -80,68 +81,115 @@
  
  markWord oopDesc::cas_set_mark(markWord new_mark, markWord old_mark, atomic_memory_order order) {
    return Atomic::cmpxchg(&_mark, old_mark, new_mark, order);
  }
  
+ markWord oopDesc::resolve_mark() const {
+   assert(LockingMode != LM_LEGACY, "Not safe with legacy stack-locking");
+   markWord m = mark();
+   if (m.has_displaced_mark_helper()) {
+     m = m.displaced_mark_helper();
+   }
+   return m;
+ }
+ 
+ markWord oopDesc::prototype_mark() const {
+   if (UseCompactObjectHeaders) {
+     return klass()->prototype_header();
+   } else {
+     return markWord::prototype();
+   }
+ }
+ 
  void oopDesc::init_mark() {
-   set_mark(markWord::prototype());
+   if (UseCompactObjectHeaders) {
+     set_mark(prototype_mark());
+   } else {
+     set_mark(markWord::prototype());
+   }
  }
  
  Klass* oopDesc::klass() const {
-   if (UseCompressedClassPointers) {
+ #ifdef _LP64
+   if (UseCompactObjectHeaders) {
+     markWord m = resolve_mark();
+     return m.klass();
+   } else if (UseCompressedClassPointers) {
      return CompressedKlassPointers::decode_not_null(_metadata._compressed_klass);
-   } else {
+   } else
+ #endif
+   {
      return _metadata._klass;
    }
  }
  
  Klass* oopDesc::klass_or_null() const {
-   if (UseCompressedClassPointers) {
+ #ifdef _LP64
+   if (UseCompactObjectHeaders) {
+     markWord m = resolve_mark();
+     return m.klass_or_null();
+   } else if (UseCompressedClassPointers) {
      return CompressedKlassPointers::decode(_metadata._compressed_klass);
-   } else {
+   } else
+ #endif
+   {
      return _metadata._klass;
    }
  }
  
  Klass* oopDesc::klass_or_null_acquire() const {
-   if (UseCompressedClassPointers) {
-     narrowKlass nklass = Atomic::load_acquire(&_metadata._compressed_klass);
-     return CompressedKlassPointers::decode(nklass);
-   } else {
+ #ifdef _LP64
+   if (UseCompactObjectHeaders) {
+     markWord m = mark_acquire();
+     if (m.has_displaced_mark_helper()) {
+       m = m.displaced_mark_helper();
+     }
+     return m.klass_or_null();
+   } else if (UseCompressedClassPointers) {
+      narrowKlass nklass = Atomic::load_acquire(&_metadata._compressed_klass);
+      return CompressedKlassPointers::decode(nklass);
+   } else
+ #endif
+   {
      return Atomic::load_acquire(&_metadata._klass);
    }
  }
  
  Klass* oopDesc::klass_raw() const {
-   if (UseCompressedClassPointers) {
+   if (UseCompactObjectHeaders) {
+     return klass();
+   } else if (UseCompressedClassPointers) {
      return CompressedKlassPointers::decode_raw(_metadata._compressed_klass);
    } else {
      return _metadata._klass;
    }
  }
  
  void oopDesc::set_klass(Klass* k) {
    assert(Universe::is_bootstrapping() || (k != nullptr && k->is_klass()), "incorrect Klass");
+   assert(!UseCompactObjectHeaders, "don't set Klass* with compact headers");
    if (UseCompressedClassPointers) {
      _metadata._compressed_klass = CompressedKlassPointers::encode_not_null(k);
    } else {
      _metadata._klass = k;
    }
  }
  
  void oopDesc::release_set_klass(HeapWord* mem, Klass* k) {
    assert(Universe::is_bootstrapping() || (k != nullptr && k->is_klass()), "incorrect Klass");
+   assert(!UseCompactObjectHeaders, "don't set Klass* with compact headers");
    char* raw_mem = ((char*)mem + klass_offset_in_bytes());
    if (UseCompressedClassPointers) {
      Atomic::release_store((narrowKlass*)raw_mem,
                            CompressedKlassPointers::encode_not_null(k));
    } else {
      Atomic::release_store((Klass**)raw_mem, k);
    }
  }
  
  void oopDesc::set_klass_gap(HeapWord* mem, int v) {
+   assert(!UseCompactObjectHeaders, "don't set Klass* gap with compact headers");
    if (UseCompressedClassPointers) {
      *(int*)(((char*)mem) + klass_gap_offset_in_bytes()) = v;
    }
  }
  

@@ -200,10 +248,57 @@
    assert(s > 0, "Oop size must be greater than zero, not " SIZE_FORMAT, s);
    assert(is_object_aligned(s), "Oop size is not properly aligned: " SIZE_FORMAT, s);
    return s;
  }
  
+ #ifdef _LP64
+ Klass* oopDesc::forward_safe_klass_impl(markWord m) const {
+   assert(UseCompactObjectHeaders, "Only get here with compact headers");
+   if (m.is_marked()) {
+     oop fwd = forwardee(m);
+     markWord m2 = fwd->mark();
+     assert(!m2.is_marked() || m2.self_forwarded(), "no double forwarding: this: " PTR_FORMAT " (" INTPTR_FORMAT "), fwd: " PTR_FORMAT " (" INTPTR_FORMAT ")", p2i(this), m.value(), p2i(fwd), m2.value());
+     m = m2;
+   }
+   return m.actual_mark().klass();
+ }
+ #endif
+ 
+ Klass* oopDesc::forward_safe_klass(markWord m) const {
+ #ifdef _LP64
+   if (UseCompactObjectHeaders) {
+     return forward_safe_klass_impl(m);
+   } else
+ #endif
+   {
+     return klass();
+   }
+ }
+ 
+ Klass* oopDesc::forward_safe_klass() const {
+ #ifdef _LP64
+   if (UseCompactObjectHeaders) {
+     return forward_safe_klass_impl(mark());
+   } else
+ #endif
+   {
+     return klass();
+   }
+ }
+ 
+ size_t oopDesc::forward_safe_size() {
+   return size_given_klass(forward_safe_klass());
+ }
+ 
+ void oopDesc::forward_safe_init_mark() {
+   if (UseCompactObjectHeaders) {
+     set_mark(forward_safe_klass()->prototype_header());
+   } else {
+     set_mark(markWord::prototype());
+   }
+ }
+ 
  bool oopDesc::is_instance()    const { return klass()->is_instance_klass();             }
  bool oopDesc::is_instanceRef() const { return klass()->is_reference_instance_klass();   }
  bool oopDesc::is_stackChunk()  const { return klass()->is_stack_chunk_instance_klass(); }
  bool oopDesc::is_array()       const { return klass()->is_array_klass();                }
  bool oopDesc::is_objArray()    const { return klass()->is_objArray_klass();             }

@@ -268,32 +363,91 @@
    return mark().is_marked();
  }
  
  // Used by scavengers
  void oopDesc::forward_to(oop p) {
+   assert(p != cast_to_oop(this) || !UseAltGCForwarding, "Must not be called with self-forwarding");
    markWord m = markWord::encode_pointer_as_mark(p);
-   assert(m.decode_pointer() == p, "encoding must be reversible");
+   assert(forwardee(m) == p, "encoding must be reversable");
    set_mark(m);
  }
  
+ void oopDesc::forward_to_self() {
+ #ifdef _LP64
+   if (UseAltGCForwarding) {
+     markWord m = mark();
+     // If mark is displaced, we need to preserve the real header during GC.
+     // It will be restored to the displaced header after GC.
+     assert(SafepointSynchronize::is_at_safepoint(), "we can only safely fetch the displaced header at safepoint");
+     if (m.has_displaced_mark_helper()) {
+       m = m.displaced_mark_helper();
+     }
+     m = m.set_self_forwarded();
+     assert(forwardee(m) == cast_to_oop(this), "encoding must be reversible");
+     set_mark(m);
+   } else
+ #endif
+   {
+     forward_to(oop(this));
+   }
+ }
+ 
  oop oopDesc::forward_to_atomic(oop p, markWord compare, atomic_memory_order order) {
+   assert(p != cast_to_oop(this) || !UseAltGCForwarding, "Must not be called with self-forwarding");
    markWord m = markWord::encode_pointer_as_mark(p);
    assert(m.decode_pointer() == p, "encoding must be reversible");
    markWord old_mark = cas_set_mark(m, compare, order);
    if (old_mark == compare) {
      return nullptr;
    } else {
-     return cast_to_oop(old_mark.decode_pointer());
+     return forwardee(old_mark);
+   }
+ }
+ 
+ oop oopDesc::forward_to_self_atomic(markWord compare, atomic_memory_order order) {
+ #ifdef _LP64
+   if (UseAltGCForwarding) {
+     markWord m = compare;
+     // If mark is displaced, we need to preserve the real header during GC.
+     // It will be restored to the displaced header after GC.
+     assert(SafepointSynchronize::is_at_safepoint(), "we can only safely fetch the displaced header at safepoint");
+     if (m.has_displaced_mark_helper()) {
+       m = m.displaced_mark_helper();
+     }
+     m = m.set_self_forwarded();
+     assert(forwardee(m) == cast_to_oop(this), "encoding must be reversible");
+     markWord old_mark = cas_set_mark(m, compare, order);
+     if (old_mark == compare) {
+       return nullptr;
+     } else {
+       assert(old_mark.is_marked(), "must be marked here");
+       return forwardee(old_mark);
+     }
+   } else
+ #endif
+   {
+     return forward_to_atomic(cast_to_oop(this), compare, order);
+   }
+ }
+ 
+ oop oopDesc::forwardee(markWord header) const {
+   assert(header.is_marked(), "only decode when actually forwarded");
+ #ifdef _LP64
+   if (header.self_forwarded()) {
+     return cast_to_oop(this);
+   } else
+ #endif
+   {
+     return cast_to_oop(header.decode_pointer());
    }
  }
  
  // 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.
  oop oopDesc::forwardee() const {
-   assert(is_forwarded(), "only decode when actually forwarded");
-   return cast_to_oop(mark().decode_pointer());
+   return forwardee(mark());
  }
  
  // The following method needs to be MT safe.
  uint oopDesc::age() const {
    markWord m = mark();

@@ -346,11 +500,12 @@
    oop_iterate_backwards(cl, klass());
  }
  
  template <typename OopClosureType>
  void oopDesc::oop_iterate_backwards(OopClosureType* cl, Klass* k) {
-   assert(k == klass(), "wrong klass");
+   // In this assert, we cannot safely access the Klass* with compact headers.
+   assert(UseCompactObjectHeaders || k == klass(), "wrong klass");
    OopIteratorClosureDispatch::oop_oop_iterate_backwards(cl, this, k);
  }
  
  bool oopDesc::is_instanceof_or_null(oop obj, Klass* klass) {
    return obj == nullptr || obj->klass()->is_subtype_of(klass);
< prev index next >