< prev index next >

src/hotspot/share/oops/markWord.hpp

Print this page
*** 23,10 ***
--- 23,11 ---
   */
  
  #ifndef SHARE_OOPS_MARKWORD_HPP
  #define SHARE_OOPS_MARKWORD_HPP
  
+ #include "gc/shared/gc_globals.hpp"
  #include "metaprogramming/primitiveConversions.hpp"
  #include "oops/oopsHierarchy.hpp"
  #include "runtime/globals.hpp"
  
  #include <type_traits>

*** 41,10 ***
--- 42,14 ---
  //
  //  64 bits:
  //  --------
  //  unused:25 hash:31 -->| unused_gap:1  age:4  unused_gap:1  lock:2 (normal object)
  //
+ //  64 bits (with compact headers):
+ //  -------------------------------
+ //  nklass:32 hash:25 -->| unused_gap:1  age:4  self-fwded:1  lock:2 (normal object)
+ //
  //  - hash contains the identity hash value: largest value is
  //    31 bits, see os::random().  Also, 64-bit vm's require
  //    a hash value no bigger than 32 bits because they will not
  //    properly generate a mask larger than that: see library_call.cpp
  //

*** 101,25 ***
    uintptr_t value() const { return _value; }
  
    // Constants
    static const int age_bits                       = 4;
    static const int lock_bits                      = 2;
!   static const int first_unused_gap_bits          = 1;
!   static const int max_hash_bits                  = BitsPerWord - age_bits - lock_bits - first_unused_gap_bits;
    static const int hash_bits                      = max_hash_bits > 31 ? 31 : max_hash_bits;
!   static const int second_unused_gap_bits         = LP64_ONLY(1) NOT_LP64(0);
  
    static const int lock_shift                     = 0;
!   static const int age_shift                      = lock_bits + first_unused_gap_bits;
!   static const int hash_shift                     = age_shift + age_bits + second_unused_gap_bits;
  
    static const uintptr_t lock_mask                = right_n_bits(lock_bits);
    static const uintptr_t lock_mask_in_place       = lock_mask << lock_shift;
    static const uintptr_t age_mask                 = right_n_bits(age_bits);
    static const uintptr_t age_mask_in_place        = age_mask << age_shift;
    static const uintptr_t hash_mask                = right_n_bits(hash_bits);
    static const uintptr_t hash_mask_in_place       = hash_mask << hash_shift;
  
    static const uintptr_t locked_value             = 0;
    static const uintptr_t unlocked_value           = 1;
    static const uintptr_t monitor_value            = 2;
    static const uintptr_t marked_value             = 3;
--- 106,47 ---
    uintptr_t value() const { return _value; }
  
    // Constants
    static const int age_bits                       = 4;
    static const int lock_bits                      = 2;
!   static const int self_forwarded_bits            = 1;
!   static const int max_hash_bits                  = BitsPerWord - age_bits - lock_bits - self_forwarded_bits;
    static const int hash_bits                      = max_hash_bits > 31 ? 31 : max_hash_bits;
!   static const int hash_bits_compact              = max_hash_bits > 25 ? 25 : max_hash_bits;
+   // Used only without compact headers.
+   static const int unused_gap_bits                = LP64_ONLY(1) NOT_LP64(0);
+ #ifdef _LP64
+   // Used only with compact headers.
+   static const int klass_bits                     = 32;
+ #endif
  
    static const int lock_shift                     = 0;
!   static const int self_forwarded_shift           = lock_shift + lock_bits;
!   static const int age_shift                      = self_forwarded_shift + self_forwarded_bits;
+   static const int hash_shift                     = age_shift + age_bits + unused_gap_bits;
+   static const int hash_shift_compact             = age_shift + age_bits;
+ #ifdef _LP64
+   // Used only with compact headers.
+   static const int klass_shift                    = hash_shift_compact + hash_bits_compact;
+ #endif
  
    static const uintptr_t lock_mask                = right_n_bits(lock_bits);
    static const uintptr_t lock_mask_in_place       = lock_mask << lock_shift;
+   static const uintptr_t self_forwarded_mask      = right_n_bits(self_forwarded_bits);
+   static const uintptr_t self_forwarded_mask_in_place = self_forwarded_mask << self_forwarded_shift;
    static const uintptr_t age_mask                 = right_n_bits(age_bits);
    static const uintptr_t age_mask_in_place        = age_mask << age_shift;
    static const uintptr_t hash_mask                = right_n_bits(hash_bits);
    static const uintptr_t hash_mask_in_place       = hash_mask << hash_shift;
+   static const uintptr_t hash_mask_compact        = right_n_bits(hash_bits_compact);
+   static const uintptr_t hash_mask_compact_in_place = hash_mask_compact << hash_shift_compact;
+ #ifdef _LP64
+   // Used only with compact headers.
+   static const uintptr_t klass_mask               = right_n_bits(klass_bits);
+   static const uintptr_t klass_mask_in_place      = klass_mask << klass_shift;
+ #endif
+ 
  
    static const uintptr_t locked_value             = 0;
    static const uintptr_t unlocked_value           = 1;
    static const uintptr_t monitor_value            = 2;
    static const uintptr_t marked_value             = 3;

*** 203,13 ***
                                            : (lockbits & unlocked_value) == 0; // monitor | stack-locked?
    }
    markWord displaced_mark_helper() const;
    void set_displaced_mark_helper(markWord m) const;
    markWord copy_set_hash(intptr_t hash) const {
!     uintptr_t tmp = value() & (~hash_mask_in_place);
!     tmp |= ((hash & hash_mask) << hash_shift);
!     return markWord(tmp);
    }
    // it is only used to be stored into BasicLock as the
    // indicator that the lock is using heavyweight monitor
    static markWord unused_mark() {
      return markWord(marked_value);
--- 230,19 ---
                                            : (lockbits & unlocked_value) == 0; // monitor | stack-locked?
    }
    markWord displaced_mark_helper() const;
    void set_displaced_mark_helper(markWord m) const;
    markWord copy_set_hash(intptr_t hash) const {
!     if (UseCompactObjectHeaders) {
!       uintptr_t tmp = value() & (~hash_mask_compact_in_place);
!       tmp |= ((hash & hash_mask_compact) << hash_shift_compact);
+       return markWord(tmp);
+     } else {
+       uintptr_t tmp = value() & (~hash_mask_in_place);
+       tmp |= ((hash & hash_mask) << hash_shift);
+       return markWord(tmp);
+     }
    }
    // it is only used to be stored into BasicLock as the
    // indicator that the lock is using heavyweight monitor
    static markWord unused_mark() {
      return markWord(marked_value);

*** 238,17 ***
    }
    markWord incr_age()      const { return age() == max_age ? markWord(_value) : set_age(age() + 1); }
  
    // hash operations
    intptr_t hash() const {
!     return mask_bits(value() >> hash_shift, hash_mask);
    }
  
    bool has_no_hash() const {
      return hash() == no_hash;
    }
  
    // Prototype mark for initialization
    static markWord prototype() {
      return markWord( no_hash_in_place | no_lock_in_place );
    }
  
--- 271,30 ---
    }
    markWord incr_age()      const { return age() == max_age ? markWord(_value) : set_age(age() + 1); }
  
    // hash operations
    intptr_t hash() const {
!     if (UseCompactObjectHeaders) {
+       return mask_bits(value() >> hash_shift_compact, hash_mask_compact);
+     } else {
+       return mask_bits(value() >> hash_shift, hash_mask);
+     }
    }
  
    bool has_no_hash() const {
      return hash() == no_hash;
    }
  
+ #ifdef _LP64
+   inline markWord actual_mark() const;
+   inline Klass* klass() const;
+   inline Klass* klass_or_null() const;
+   inline narrowKlass narrow_klass() const;
+   inline markWord set_narrow_klass(narrowKlass nklass) const;
+   inline markWord set_klass(Klass* klass) const;
+ #endif
+ 
    // Prototype mark for initialization
    static markWord prototype() {
      return markWord( no_hash_in_place | no_lock_in_place );
    }
  

*** 258,10 ***
--- 304,23 ---
    // Prepare address of oop for placement into mark
    inline static markWord encode_pointer_as_mark(void* p) { return from_pointer(p).set_marked(); }
  
    // Recover address of oop from encoded form used in mark
    inline void* decode_pointer() { return (void*)clear_lock_bits().value(); }
+ 
+ #ifdef _LP64
+   inline bool self_forwarded() const {
+     bool self_fwd = mask_bits(value(), self_forwarded_mask_in_place) != 0;
+     assert(!self_fwd || UseAltGCForwarding, "Only set self-fwd bit when using alt GC forwarding");
+     return self_fwd;
+   }
+ 
+   inline markWord set_self_forwarded() const {
+     assert(UseAltGCForwarding, "Only call this with alt GC forwarding");
+     return markWord(value() | self_forwarded_mask_in_place | marked_value);
+   }
+ #endif
  };
  
  // Support atomic operations.
  template<>
  struct PrimitiveConversions::Translate<markWord> : public std::true_type {
< prev index next >