< prev index next >

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

Print this page
*** 30,14 ***
  #include "memory/universe.hpp"
  #include "oops/access.inline.hpp"
  #include "oops/arrayKlass.hpp"
  #include "oops/arrayOop.hpp"
  #include "oops/compressedOops.inline.hpp"
! #include "oops/markWord.hpp"
  #include "oops/oopsHierarchy.hpp"
  #include "runtime/atomic.hpp"
  #include "runtime/globals.hpp"
  #include "utilities/align.hpp"
  #include "utilities/debug.hpp"
  #include "utilities/macros.hpp"
  #include "utilities/globalDefinitions.hpp"
  
--- 30,16 ---
  #include "memory/universe.hpp"
  #include "oops/access.inline.hpp"
  #include "oops/arrayKlass.hpp"
  #include "oops/arrayOop.hpp"
  #include "oops/compressedOops.inline.hpp"
! #include "oops/markWord.inline.hpp"
  #include "oops/oopsHierarchy.hpp"
  #include "runtime/atomic.hpp"
  #include "runtime/globals.hpp"
+ #include "runtime/safepoint.hpp"
+ #include "runtime/synchronizer.hpp"
  #include "utilities/align.hpp"
  #include "utilities/debug.hpp"
  #include "utilities/macros.hpp"
  #include "utilities/globalDefinitions.hpp"
  

*** 75,36 ***
  markWord oopDesc::cas_set_mark(markWord new_mark, markWord old_mark, atomic_memory_order order) {
    return Atomic::cmpxchg(&_mark, old_mark, new_mark, order);
  }
  
  void oopDesc::init_mark() {
!   set_mark(markWord::prototype());
  }
  
  Klass* oopDesc::klass() const {
!   if (UseCompressedClassPointers) {
!     return CompressedKlassPointers::decode_not_null(_metadata._compressed_klass);
!   } else {
!     return _metadata._klass;
    }
  }
  
  Klass* oopDesc::klass_or_null() const {
!   if (UseCompressedClassPointers) {
!     return CompressedKlassPointers::decode(_metadata._compressed_klass);
!   } else {
!     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 {
!     return Atomic::load_acquire(&_metadata._klass);
    }
  }
  
  void oopDesc::set_klass(Klass* k) {
    assert(Universe::is_bootstrapping() || (k != NULL && k->is_klass()), "incorrect Klass");
    if (UseCompressedClassPointers) {
--- 77,67 ---
  markWord oopDesc::cas_set_mark(markWord new_mark, markWord old_mark, atomic_memory_order order) {
    return Atomic::cmpxchg(&_mark, old_mark, new_mark, order);
  }
  
  void oopDesc::init_mark() {
! #ifdef _LP64
+   markWord header = ObjectSynchronizer::stable_mark(cast_to_oop(this));
+   assert(_metadata._compressed_klass == header.narrow_klass(), "klass must match: " PTR_FORMAT, header.value());
+   assert(UseCompressedClassPointers, "expect compressed klass pointers");
+   header = markWord((header.value() & markWord::klass_mask_in_place) | markWord::prototype().value());
+ #else
+   markWord header = markWord::prototype();
+ #endif
+   set_mark(header);
  }
  
  Klass* oopDesc::klass() const {
! #ifdef _LP64
!   assert(UseCompressedClassPointers, "only with compressed class pointers");
!   markWord header = mark();
!   if (!header.is_neutral()) {
+     header = ObjectSynchronizer::stable_mark(cast_to_oop(this));
    }
+   assert(_metadata._compressed_klass == header.narrow_klass(), "narrow klass must be equal, header: " INTPTR_FORMAT ", nklass: " INTPTR_FORMAT, header.value(), intptr_t(_metadata._compressed_klass));
+   Klass* klass = header.klass();
+   assert(klass == CompressedKlassPointers::decode_not_null(_metadata._compressed_klass), "klass must match: header: " INTPTR_FORMAT ", nklass: " INTPTR_FORMAT, header.value(), intptr_t(_metadata._compressed_klass));
+   return klass;
+ #else
+   return _metadata._klass;
+ #endif
  }
  
  Klass* oopDesc::klass_or_null() const {
! #ifdef _LP64
!   assert(UseCompressedClassPointers, "only with compressed class pointers");
!   markWord header = mark();
!   if (!header.is_neutral()) {
+     header = ObjectSynchronizer::stable_mark(cast_to_oop(this));
    }
+   assert(_metadata._compressed_klass == header.narrow_klass(), "narrow klass must be equal, header: " INTPTR_FORMAT ", nklass: " INTPTR_FORMAT, header.value(), intptr_t(_metadata._compressed_klass));
+   Klass* klass = header.klass_or_null();
+   assert(klass == CompressedKlassPointers::decode(_metadata._compressed_klass), "klass must match: header: " INTPTR_FORMAT ", nklass: " INTPTR_FORMAT, header.value(), intptr_t(_metadata._compressed_klass));
+   return klass;
+ #else
+   return _metadata._klass;
+ #endif
  }
  
  Klass* oopDesc::klass_or_null_acquire() const {
! #ifdef _LP64
!   assert(UseCompressedClassPointers, "only with compressed class pointers");
!   markWord header = mark_acquire();
!   if (!header.is_neutral()) {
!     header = ObjectSynchronizer::stable_mark(cast_to_oop(this));
    }
+   assert(_metadata._compressed_klass == header.narrow_klass(), "narrow klass must be equal, header: " INTPTR_FORMAT ", nklass: " INTPTR_FORMAT, header.value(), intptr_t(_metadata._compressed_klass));
+   Klass* klass = header.klass_or_null();
+   assert(klass == CompressedKlassPointers::decode(_metadata._compressed_klass), "klass must match: header: " INTPTR_FORMAT ", nklass: " INTPTR_FORMAT, header.value(), intptr_t(_metadata._compressed_klass));
+   return klass;
+ #else
+   return Atomic::load_acquire(&_metadata._klass);
+ #endif
  }
  
  void oopDesc::set_klass(Klass* k) {
    assert(Universe::is_bootstrapping() || (k != NULL && k->is_klass()), "incorrect Klass");
    if (UseCompressedClassPointers) {

*** 267,32 ***
  
  // Used by scavengers
  void oopDesc::forward_to(oop p) {
    verify_forwardee(p);
    markWord m = markWord::encode_pointer_as_mark(p);
!   assert(m.decode_pointer() == p, "encoding must be reversable");
    set_mark(m);
  }
  
  oop oopDesc::forward_to_atomic(oop p, markWord compare, atomic_memory_order order) {
    verify_forwardee(p);
    markWord m = markWord::encode_pointer_as_mark(p);
!   assert(m.decode_pointer() == p, "encoding must be reversable");
    markWord old_mark = cas_set_mark(m, compare, order);
    if (old_mark == compare) {
      return NULL;
    } else {
!     return cast_to_oop(old_mark.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());
  }
  
  // The following method needs to be MT safe.
  uint oopDesc::age() const {
    assert(!mark().is_marked(), "Attempt to read age from forwarded mark");
--- 300,83 ---
  
  // Used by scavengers
  void oopDesc::forward_to(oop p) {
    verify_forwardee(p);
    markWord m = markWord::encode_pointer_as_mark(p);
!   assert(forwardee(m) == p, "encoding must be reversable");
+   set_mark(m);
+ }
+ 
+ void oopDesc::forward_to_self() {
+ #ifdef _LP64
+   verify_forwardee(this);
+   markWord m = mark();
+   // If mark is displaced, we need to preserve the Klass* from real header.
+   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 reversable");
    set_mark(m);
+ #else
+   forward_to(oop(this));
+ #endif
  }
  
  oop oopDesc::forward_to_atomic(oop p, markWord compare, atomic_memory_order order) {
    verify_forwardee(p);
    markWord m = markWord::encode_pointer_as_mark(p);
!   assert(forwardee(m) == p, "encoding must be reversable");
    markWord old_mark = cas_set_mark(m, compare, order);
    if (old_mark == compare) {
      return NULL;
    } else {
!     return forwardee(old_mark);
    }
  }
  
+ oop oopDesc::forward_to_self_atomic(markWord compare, atomic_memory_order order) {
+ #ifdef _LP64
+   verify_forwardee(this);
+   markWord m = compare;
+   // If mark is displaced, we need to preserve the Klass* from real header.
+   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 reversable");
+   markWord old_mark = cas_set_mark(m, compare, order);
+   if (old_mark == compare) {
+     return NULL;
+   } else {
+     assert(old_mark.is_marked(), "must be marked here");
+     return forwardee(old_mark);
+   }
+ #else
+   return forward_to_atomic(oop(this), compare, order);
+ #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.
  oop oopDesc::forwardee() const {
!   return forwardee(mark());
! }
+ 
+ oop oopDesc::forwardee(markWord header) const {
+   assert(header.is_marked(), "must be forwarded");
+ #ifdef _LP64
+   if (header.self_forwarded()) {
+     return cast_to_oop(this);
+   } else
+ #endif
+   {
+     return cast_to_oop(header.decode_pointer());
+   }
  }
  
  // The following method needs to be MT safe.
  uint oopDesc::age() const {
    assert(!mark().is_marked(), "Attempt to read age from forwarded mark");

*** 343,11 ***
    oop_iterate_backwards(cl, klass());
  }
  
  template <typename OopClosureType>
  void oopDesc::oop_iterate_backwards(OopClosureType* cl, Klass* k) {
-   assert(k == klass(), "wrong klass");
    OopIteratorClosureDispatch::oop_oop_iterate_backwards(cl, this, k);
  }
  
  bool oopDesc::is_instanceof_or_null(oop obj, Klass* klass) {
    return obj == NULL || obj->klass()->is_subtype_of(klass);
--- 427,10 ---
< prev index next >