< prev index next >

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

Print this page
*** 34,10 ***
--- 34,12 ---
  #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/objectMonitor.inline.hpp"
  #include "utilities/align.hpp"
  #include "utilities/debug.hpp"
  #include "utilities/macros.hpp"
  #include "utilities/globalDefinitions.hpp"
  

*** 49,11 ***
  }
  
  markWord oopDesc::mark_acquire() const {
    return Atomic::load_acquire(&_mark);
  }
- 
  markWord* oopDesc::mark_addr() const {
    return (markWord*) &_mark;
  }
  
  void oopDesc::set_mark(markWord m) {
--- 51,10 ---

*** 66,78 ***
  
  void oopDesc::release_set_mark(markWord m) {
    Atomic::release_store(&_mark, m);
  }
  
  markWord oopDesc::cas_set_mark(markWord new_mark, markWord old_mark) {
    return Atomic::cmpxchg(&_mark, old_mark, new_mark);
  }
  
  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_for_klass(klass()));
  }
  
  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) {
      _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 != NULL && k->is_klass()), "incorrect Klass");
    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);
    }
  }
  
  int oopDesc::klass_gap() const {
    return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
  }
  
  void oopDesc::set_klass_gap(HeapWord* mem, int v) {
    if (UseCompressedClassPointers) {
      *(int*)(((char*)mem) + klass_gap_offset_in_bytes()) = v;
    }
  }
  
  void oopDesc::set_klass_gap(int v) {
    set_klass_gap((HeapWord*)this, v);
  }
  
  bool oopDesc::is_a(Klass* k) const {
    return klass()->is_subtype_of(k);
--- 67,122 ---
  
  void oopDesc::release_set_mark(markWord m) {
    Atomic::release_store(&_mark, m);
  }
  
+ void oopDesc::release_set_mark(HeapWord* mem, markWord m) {
+   Atomic::release_store((markWord*)(((char*)mem) + mark_offset_in_bytes()), m);
+ }
+ 
  markWord oopDesc::cas_set_mark(markWord new_mark, markWord old_mark) {
    return Atomic::cmpxchg(&_mark, old_mark, new_mark);
  }
  
  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 hdr = mark();
+   if (hdr.has_displaced_mark_helper()) {
+     hdr = hdr.displaced_mark_helper();
+   }
+   return hdr;
+ }
+ 
+ markWord oopDesc::prototype_mark() const {
+   if (UseCompactObjectHeaders) {
+     return klass()->prototype_header();
+   } else {
+     return markWord::prototype();
+   }
+ }
+ 
  void oopDesc::init_mark() {
    set_mark(markWord::prototype_for_klass(klass()));
  }
  
  Klass* oopDesc::klass() const {
! #ifdef _LP64
+   if (UseCompactObjectHeaders) {
+     assert(UseCompressedClassPointers, "only with compressed class pointers");
+     markWord header = resolve_mark();
+     return header.klass();
+   } else if (UseCompressedClassPointers) {
      return CompressedKlassPointers::decode_not_null(_metadata._compressed_klass);
!   } else
! #endif
!   return _metadata._klass;
  }
  
  Klass* oopDesc::klass_or_null() const {
! #ifdef _LP64
+   if (UseCompactObjectHeaders) {
+     assert(UseCompressedClassPointers, "only with compressed class pointers");
+     markWord header = resolve_mark();
+     return header.klass_or_null();
+   } else if (UseCompressedClassPointers) {
      return CompressedKlassPointers::decode(_metadata._compressed_klass);
!   } else
! #endif
!   return _metadata._klass;
  }
  
  Klass* oopDesc::klass_or_null_acquire() const {
! #ifdef _LP64
!   if (UseCompactObjectHeaders) {
!     assert(UseCompressedClassPointers, "only with compressed class pointers");
!     markWord header = mark_acquire();
!     if (header.has_monitor()) {
!       header = header.monitor()->header();
+     }
+     return header.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);
  }
  
  void oopDesc::set_klass(Klass* k) {
    assert(Universe::is_bootstrapping() || (k != NULL && 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 != NULL && 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);
    }
  }
  
  int oopDesc::klass_gap() const {
+   assert(!UseCompactObjectHeaders, "don't get Klass* gap with compact headers");
    return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
  }
  
  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;
    }
  }
  
  void oopDesc::set_klass_gap(int v) {
+   assert(!UseCompactObjectHeaders, "don't set Klass* gap with compact headers");
    set_klass_gap((HeapWord*)this, v);
  }
  
  bool oopDesc::is_a(Klass* k) const {
    return klass()->is_subtype_of(k);

*** 201,10 ***
--- 246,57 ---
    assert(s > 0, "Oop size must be greater than zero, not %d", s);
    assert(is_object_aligned(s), "Oop size is not properly aligned: %d", 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 {
+     init_mark();
+   }
+ }
+ 
  bool oopDesc::is_instance()  const { return klass()->is_instance_klass();  }
  bool oopDesc::is_array()     const { return klass()->is_array_klass();     }
  bool oopDesc::is_objArray()  const { return klass()->is_objArray_klass();  }
  bool oopDesc::is_typeArray() const { return klass()->is_typeArray_klass(); }
  

*** 272,41 ***
    return mark().is_marked();
  }
  
  // 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);
  }
  
! // Used by parallel scavengers
! bool oopDesc::cas_forward_to(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");
!   return cas_set_mark(m, compare, order) == compare;
  }
  
  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 {
!   return cast_to_oop(mark().decode_pointer());
  }
  
  // The following method needs to be MT safe.
  uint oopDesc::age() const {
    assert(!is_forwarded(), "Attempt to read age from forwarded mark");
--- 364,93 ---
    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");
    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
!   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");
    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
+   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 {
!   return forwardee(mark());
  }
  
  // The following method needs to be MT safe.
  uint oopDesc::age() const {
    assert(!is_forwarded(), "Attempt to read age from forwarded mark");

*** 357,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);
--- 501,11 ---
    oop_iterate_backwards(cl, klass());
  }
  
  template <typename OopClosureType>
  void oopDesc::oop_iterate_backwards(OopClosureType* cl, Klass* k) {
!   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 == NULL || obj->klass()->is_subtype_of(klass);
< prev index next >