< prev index next >

src/hotspot/share/oops/markWord.hpp

Print this page
@@ -39,11 +39,11 @@
  //             hash:25 ------------>| age:4    biased_lock:1 lock:2 (normal object)
  //             JavaThread*:23 epoch:2 age:4    biased_lock:1 lock:2 (biased object)
  //
  //  64 bits:
  //  --------
- //  unused:25 hash:31 -->| unused_gap:1   age:4    biased_lock:1 lock:2 (normal object)
+ //  nklass:32 hash:25 -->| unused_gap:1   age:4    biased_lock:1 lock:2 (normal object)
  //  JavaThread*:54 epoch:2 unused_gap:1   age:4    biased_lock:1 lock:2 (biased 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

@@ -92,10 +92,11 @@
  //    See below for is_being_inflated() and INFLATING().
  
  class BasicLock;
  class ObjectMonitor;
  class JavaThread;
+ class Klass;
  class outputStream;
  
  class markWord {
   private:
    uintptr_t _value;

@@ -127,37 +128,50 @@
  
    // Constants
    static const int age_bits                       = 4;
    static const int lock_bits                      = 2;
    static const int biased_lock_bits               = 1;
-   static const int max_hash_bits                  = BitsPerWord - age_bits - lock_bits - biased_lock_bits;
-   static const int hash_bits                      = max_hash_bits > 31 ? 31 : max_hash_bits;
-   static const int unused_gap_bits                = LP64_ONLY(1) NOT_LP64(0);
+   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 > 25 ? 25 : max_hash_bits;
+ #ifdef _LP64
+   static const int klass_bits                     = 32;
+ #endif
    static const int epoch_bits                     = 2;
  
    // The biased locking code currently requires that the age bits be
    // contiguous to the lock bits.
    static const int lock_shift                     = 0;
    static const int biased_lock_shift              = lock_bits;
-   static const int age_shift                      = lock_bits + biased_lock_bits;
-   static const int unused_gap_shift               = age_shift + age_bits;
-   static const int hash_shift                     = unused_gap_shift + unused_gap_bits;
+   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;
+ #ifdef _LP64
+   static const int klass_shift                    = hash_shift + hash_bits;
+ #endif
    static const int epoch_shift                    = hash_shift;
  
    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 biased_lock_mask         = right_n_bits(lock_bits + biased_lock_bits);
    static const uintptr_t biased_lock_mask_in_place= biased_lock_mask << lock_shift;
    static const uintptr_t biased_lock_bit_in_place = 1 << biased_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 epoch_mask               = right_n_bits(epoch_bits);
    static const uintptr_t epoch_mask_in_place      = epoch_mask << epoch_shift;
  
    static const uintptr_t hash_mask                = right_n_bits(hash_bits);
    static const uintptr_t hash_mask_in_place       = hash_mask << hash_shift;
  
+ #ifdef _LP64
+   static const uintptr_t klass_mask               = right_n_bits(klass_bits);
+   static const uintptr_t klass_mask_in_place      = klass_mask << klass_shift;
+ #endif
+ 
    // Alignment of JavaThread pointers encoded in object header required by biased locking
    static const size_t biased_lock_alignment       = 2 << (epoch_shift + epoch_bits);
  
    static const uintptr_t locked_value             = 0;
    static const uintptr_t unlocked_value           = 1;

@@ -265,26 +279,36 @@
    // They must get updated if markWord layout get changed.
    markWord set_unlocked() const {
      return markWord(value() | unlocked_value);
    }
    bool has_locker() const {
-     return ((value() & lock_mask_in_place) == locked_value);
+     return !UseFastLocking && ((value() & lock_mask_in_place) == locked_value);
    }
    BasicLock* locker() const {
      assert(has_locker(), "check");
      return (BasicLock*) value();
    }
+ 
+   bool is_fast_locked() const {
+     return UseFastLocking && ((value() & lock_mask_in_place) == locked_value);
+   }
+   markWord set_fast_locked() const {
+     return markWord(value() & ~lock_mask_in_place);
+   }
+ 
    bool has_monitor() const {
      return ((value() & monitor_value) != 0);
    }
    ObjectMonitor* monitor() const {
      assert(has_monitor(), "check");
      // Use xor instead of &~ to provide one extra tag-bit check.
      return (ObjectMonitor*) (value() ^ monitor_value);
    }
    bool has_displaced_mark_helper() const {
-     return ((value() & unlocked_value) == 0);
+     intptr_t lockbits = value() & lock_mask_in_place;
+     return UseFastLocking ? lockbits == monitor_value   // monitor?
+                           : (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);

@@ -334,10 +358,19 @@
  
    bool has_no_hash() const {
      return hash() == no_hash;
    }
  
+ #ifdef _LP64
+   inline Klass* klass() const;
+   inline Klass* klass_or_null() const;
+   inline Klass* safe_klass() const;
+   inline markWord set_klass(const Klass* klass) const;
+   inline narrowKlass narrow_klass() const;
+   inline markWord set_narrow_klass(const narrowKlass klass) const;
+ #endif
+ 
    // Prototype mark for initialization
    static markWord prototype() {
      return markWord( no_hash_in_place | no_lock_in_place );
    }
  

@@ -350,10 +383,18 @@
    // 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() { if (UseBiasedLocking && has_bias_pattern()) return NULL; return (void*)clear_lock_bits().value(); }
+ 
+   inline bool self_forwarded() const {
+     return mask_bits(value(), self_forwarded_mask_in_place) != 0;
+   }
+ 
+   inline markWord set_self_forwarded() const {
+     return markWord(value() | self_forwarded_mask_in_place | marked_value);
+   }
  };
  
  // Support atomic operations.
  template<>
  struct PrimitiveConversions::Translate<markWord> : public TrueType {
< prev index next >