< prev index next >

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

Print this page
*** 32,11 ***
  #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/oopsHierarchy.hpp"
  #include "runtime/atomic.hpp"
  #include "runtime/globals.hpp"
  #include "utilities/align.hpp"
  #include "utilities/debug.hpp"
--- 32,11 ---
  #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.inline.hpp"
  #include "oops/oopsHierarchy.hpp"
  #include "runtime/atomic.hpp"
  #include "runtime/globals.hpp"
  #include "utilities/align.hpp"
  #include "utilities/debug.hpp"

*** 64,84 ***
  
  void oopDesc::set_mark(HeapWord* mem, markWord m) {
    *(markWord*)(((char*)mem) + mark_offset_in_bytes()) = m;
  }
  
- void oopDesc::release_set_mark(HeapWord* mem, markWord m) {
-   Atomic::release_store((markWord*)(((char*)mem) + mark_offset_in_bytes()), m);
- }
- 
  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());
  }
  
  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);
    }
  }
  
  Klass* oopDesc::klass_without_asserts() const {
!   if (UseCompressedClassPointers) {
      return CompressedKlassPointers::decode_without_asserts(_metadata._compressed_klass);
    } else {
      return _metadata._klass;
    }
  }
  
  void oopDesc::set_klass(Klass* k) {
    assert(Universe::is_bootstrapping() || (k != nullptr && 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 != nullptr && 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);
    }
  }
  
  void oopDesc::set_klass_gap(HeapWord* mem, int v) {
    if (UseCompressedClassPointers) {
      *(int*)(((char*)mem) + klass_gap_offset_in_bytes()) = v;
    }
  }
  
--- 64,107 ---
  
  void oopDesc::set_mark(HeapWord* mem, markWord m) {
    *(markWord*)(((char*)mem) + mark_offset_in_bytes()) = m;
  }
  
  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::prototype_mark() const {
+   if (UseCompactObjectHeaders) {
+     return klass()->prototype_header();
+   } else {
+     return markWord::prototype();
+   }
+ }
+ 
  void oopDesc::init_mark() {
!   if (UseCompactObjectHeaders) {
+     set_mark(prototype_mark());
+   } else {
+     set_mark(markWord::prototype());
+   }
  }
  
  Klass* oopDesc::klass() const {
!   if (UseCompactObjectHeaders) {
!     return mark().klass();
+   } else if (UseCompressedClassPointers) {
+      return CompressedKlassPointers::decode_not_null(_metadata._compressed_klass);
    } else {
      return _metadata._klass;
    }
  }
  
  Klass* oopDesc::klass_or_null() const {
!   if (UseCompactObjectHeaders) {
+     return mark().klass_or_null();
+   } else if (UseCompressedClassPointers) {
      return CompressedKlassPointers::decode(_metadata._compressed_klass);
    } else {
      return _metadata._klass;
    }
  }
  
  Klass* oopDesc::klass_or_null_acquire() const {
!   if (UseCompactObjectHeaders) {
+     return mark_acquire().klass();
+   } else if (UseCompressedClassPointers) {
      narrowKlass nklass = Atomic::load_acquire(&_metadata._compressed_klass);
      return CompressedKlassPointers::decode(nklass);
    } else {
      return Atomic::load_acquire(&_metadata._klass);
    }
  }
  
  Klass* oopDesc::klass_without_asserts() const {
!   if (UseCompactObjectHeaders) {
+     return mark().klass_without_asserts();
+   } else if (UseCompressedClassPointers) {
      return CompressedKlassPointers::decode_without_asserts(_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;
    }
  }
  

*** 188,11 ***
        // This code could be simplified, but by keeping array_header_in_bytes
        // in units of bytes and doing it this way we can round up just once,
        // skipping the intermediate round to HeapWordSize.
        s = align_up(size_in_bytes, MinObjAlignmentInBytes) / HeapWordSize;
  
!       assert(s == klass->oop_size(this) || size_might_change(), "wrong array object size");
      } else {
        // Must be zero, so bite the bullet and take the virtual call.
        s = klass->oop_size(this);
      }
    }
--- 211,11 ---
        // This code could be simplified, but by keeping array_header_in_bytes
        // in units of bytes and doing it this way we can round up just once,
        // skipping the intermediate round to HeapWordSize.
        s = align_up(size_in_bytes, MinObjAlignmentInBytes) / HeapWordSize;
  
!       assert(s == klass->oop_size(this) || size_might_change(klass), "wrong array object size");
      } else {
        // Must be zero, so bite the bullet and take the virtual call.
        s = klass->oop_size(this);
      }
    }

*** 200,10 ***
--- 223,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.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();             }

*** 265,33 ***
  // Used by scavengers
  bool oopDesc::is_forwarded() const {
    return mark().is_forwarded();
  }
  
  // Used by scavengers
  void oopDesc::forward_to(oop p) {
    markWord m = markWord::encode_pointer_as_mark(p);
    assert(m.decode_pointer() == p, "encoding must be reversible");
    set_mark(m);
  }
  
! oop oopDesc::forward_to_atomic(oop p, markWord compare, atomic_memory_order order) {
!   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());
    }
  }
  
  // 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 mark().forwardee();
  }
  
  // The following method needs to be MT safe.
  uint oopDesc::age() const {
    markWord m = mark();
--- 335,65 ---
  // Used by scavengers
  bool oopDesc::is_forwarded() const {
    return mark().is_forwarded();
  }
  
+ bool oopDesc::is_self_forwarded() const {
+   return mark().self_forwarded();
+ }
+ 
  // Used by scavengers
  void oopDesc::forward_to(oop p) {
    markWord m = markWord::encode_pointer_as_mark(p);
    assert(m.decode_pointer() == p, "encoding must be reversible");
    set_mark(m);
  }
  
! void oopDesc::forward_to_self() {
!   set_mark(mark().set_self_forwarded());
! }
! 
+ oop oopDesc::cas_set_forwardee(markWord new_mark, markWord compare, atomic_memory_order order) {
+   markWord old_mark = cas_set_mark(new_mark, compare, order);
    if (old_mark == compare) {
      return nullptr;
    } else {
!     assert(old_mark.is_forwarded(), "must be forwarded here");
+     return forwardee(old_mark);
+   }
+ }
+ 
+ oop oopDesc::forward_to_atomic(oop p, markWord compare, atomic_memory_order order) {
+   markWord m = markWord::encode_pointer_as_mark(p);
+   assert(forwardee(m) == p, "encoding must be reversible");
+   return cas_set_forwardee(m, compare, order);
+ }
+ 
+ oop oopDesc::forward_to_self_atomic(markWord old_mark, atomic_memory_order order) {
+   markWord new_mark = old_mark.set_self_forwarded();
+   assert(forwardee(new_mark) == cast_to_oop(this), "encoding must be reversible");
+   return cas_set_forwardee(new_mark, old_mark, order);
+ }
+ 
+ oop oopDesc::forwardee(markWord mark) const {
+   assert(mark.is_forwarded(), "only decode when actually forwarded");
+   if (mark.self_forwarded()) {
+     return cast_to_oop(this);
+   } else {
+     return mark.forwardee();
    }
  }
  
  // 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());
+ }
+ 
+ void oopDesc::unset_self_forwarded() {
+   set_mark(mark().unset_self_forwarded());
  }
  
  // The following method needs to be MT safe.
  uint oopDesc::age() const {
    markWord m = mark();

*** 344,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 == nullptr || obj->klass()->is_subtype_of(klass);
--- 446,12 ---
    oop_iterate_backwards(cl, klass());
  }
  
  template <typename OopClosureType>
  void oopDesc::oop_iterate_backwards(OopClosureType* cl, Klass* k) {
!   // 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 >