< prev index next >

src/hotspot/share/oops/markWord.hpp

Print this page

 29 #include "oops/compressedKlass.hpp"
 30 #include "oops/oopsHierarchy.hpp"
 31 #include "runtime/globals.hpp"
 32 
 33 #include <type_traits>
 34 
 35 // The markWord describes the header of an object.
 36 //
 37 // Bit-format of an object header (most significant first, big endian layout below):
 38 //
 39 //  32 bits:
 40 //  --------
 41 //             hash:25 ------------>| age:4  self-fwd:1  lock:2 (normal object)
 42 //
 43 //  64 bits:
 44 //  --------
 45 //  unused:22 hash:31 -->| unused_gap:4  age:4  self-fwd:1  lock:2 (normal object)
 46 //
 47 //  64 bits (with compact headers):
 48 //  -------------------------------
 49 //  klass:22  hash:31 -->| unused_gap:4  age:4  self-fwd:1  lock:2 (normal object)
 50 //
 51 //  - hash contains the identity hash value: largest value is
 52 //    31 bits, see os::random().  Also, 64-bit vm's require
 53 //    a hash value no bigger than 32 bits because they will not
 54 //    properly generate a mask larger than that: see library_call.cpp
 55 //













 56 //  - the two lock bits are used to describe three states: locked/unlocked and monitor.
 57 //
 58 //    [ptr             | 00]  locked             ptr points to real header on stack (stack-locking in use)
 59 //    [header          | 00]  locked             locked regular object header (fast-locking in use)
 60 //    [header          | 01]  unlocked           regular object header
 61 //    [ptr             | 10]  monitor            inflated lock (header is swapped out, UseObjectMonitorTable == false)
 62 //    [header          | 10]  monitor            inflated lock (UseObjectMonitorTable == true)
 63 //    [ptr             | 11]  marked             used to mark an object
 64 //    [0 ............ 0| 00]  inflating          inflation in progress (stack-locking in use)
 65 //
 66 //    We assume that stack/thread pointers have the lowest two bits cleared.
 67 //
 68 //  - INFLATING() is a distinguished markword value of all zeros that is
 69 //    used when inflating an existing stack-lock into an ObjectMonitor.
 70 //    See below for is_being_inflated() and INFLATING().
 71 
 72 class BasicLock;
 73 class ObjectMonitor;
 74 class JavaThread;
 75 class outputStream;

 88   ~markWord() = default;
 89   markWord(const markWord&) = default;
 90   markWord& operator=(const markWord&) = default;
 91 
 92   static markWord from_pointer(void* ptr) {
 93     return markWord((uintptr_t)ptr);
 94   }
 95   void* to_pointer() const {
 96     return (void*)_value;
 97   }
 98 
 99   bool operator==(const markWord& other) const {
100     return _value == other._value;
101   }
102   bool operator!=(const markWord& other) const {
103     return !operator==(other);
104   }
105 
106   // Conversion
107   uintptr_t value() const { return _value; }

108 
109   // Constants
110   static const int age_bits                       = 4;
111   static const int lock_bits                      = 2;
112   static const int self_fwd_bits                  = 1;
113   static const int max_hash_bits                  = BitsPerWord - age_bits - lock_bits - self_fwd_bits;
114   static const int hash_bits                      = max_hash_bits > 31 ? 31 : max_hash_bits;
115   static const int unused_gap_bits                = LP64_ONLY(4) NOT_LP64(0); // Reserved for Valhalla.

116 
117   static const int lock_shift                     = 0;
118   static const int self_fwd_shift                 = lock_shift + lock_bits;
119   static const int age_shift                      = self_fwd_shift + self_fwd_bits;
120   static const int hash_shift                     = age_shift + age_bits + unused_gap_bits;

121 
122   static const uintptr_t lock_mask                = right_n_bits(lock_bits);
123   static const uintptr_t lock_mask_in_place       = lock_mask << lock_shift;
124   static const uintptr_t self_fwd_mask            = right_n_bits(self_fwd_bits);
125   static const uintptr_t self_fwd_mask_in_place   = self_fwd_mask << self_fwd_shift;
126   static const uintptr_t age_mask                 = right_n_bits(age_bits);
127   static const uintptr_t age_mask_in_place        = age_mask << age_shift;
128   static const uintptr_t hash_mask                = right_n_bits(hash_bits);
129   static const uintptr_t hash_mask_in_place       = hash_mask << hash_shift;




130 
131 #ifdef _LP64
132   // Used only with compact headers:
133   // We store the (narrow) Klass* in the bits 43 to 64.
134 
135   // These are for bit-precise extraction of the narrow Klass* from the 64-bit Markword
136   static constexpr int klass_offset_in_bytes      = 4;
137   static constexpr int klass_shift                = hash_shift + hash_bits;
138   static constexpr int klass_shift_at_offset      = klass_shift - klass_offset_in_bytes * BitsPerByte;
139   static constexpr int klass_bits                 = 22;
140   static constexpr uintptr_t klass_mask           = right_n_bits(klass_bits);
141   static constexpr uintptr_t klass_mask_in_place  = klass_mask << klass_shift;
142 #endif
143 
144 
145   static const uintptr_t locked_value             = 0;
146   static const uintptr_t unlocked_value           = 1;
147   static const uintptr_t monitor_value            = 2;
148   static const uintptr_t marked_value             = 3;
149 
150   static const uintptr_t no_hash                  = 0 ;  // no hash value assigned
151   static const uintptr_t no_hash_in_place         = (uintptr_t)no_hash << hash_shift;
152   static const uintptr_t no_lock_in_place         = unlocked_value;
153 
154   static const uint max_age                       = age_mask;
155 
156   // Creates a markWord with all bits set to zero.
157   static markWord zero() { return markWord(uintptr_t(0)); }
158 
159   // lock accessors (note that these assume lock_shift == 0)
160   bool is_locked()   const {
161     return (mask_bits(value(), lock_mask_in_place) != unlocked_value);
162   }
163   bool is_unlocked() const {
164     return (mask_bits(value(), lock_mask_in_place) == unlocked_value);
165   }
166   bool is_marked()   const {
167     return (mask_bits(value(), lock_mask_in_place) == marked_value);
168   }
169   bool is_forwarded() const {
170     // Returns true for normal forwarded (0b011) and self-forwarded (0b1xx).
171     return mask_bits(value(), lock_mask_in_place | self_fwd_mask_in_place) >= static_cast<intptr_t>(marked_value);
172   }
173   bool is_neutral()  const {  // Not locked, or marked - a "clean" neutral state
174     return (mask_bits(value(), lock_mask_in_place) == unlocked_value);
175   }
176 
177   // Special temporary state of the markWord while being inflated.
178   // Code that looks at mark outside a lock need to take this into account.
179   bool is_being_inflated() const { return (value() == 0); }
180 
181   // Distinguished markword value - used when inflating over
182   // an existing stack-lock.  0 indicates the markword is "BUSY".
183   // Lockword mutators that use a LD...CAS idiom should always
184   // check for and avoid overwriting a 0 value installed by some
185   // other thread.  (They should spin or block instead.  The 0 value
186   // is transient and *should* be short-lived).
187   // Fast-locking does not use INFLATING.
188   static markWord INFLATING() { return zero(); }    // inflate-in-progress
189 
190   // Should this header be preserved during GC?
191   bool must_be_preserved(const oopDesc* obj) const {
192     return (!is_unlocked() || !has_no_hash());
193   }
194 
195   // WARNING: The following routines are used EXCLUSIVELY by
196   // synchronization functions. They are not really gc safe.
197   // They must get updated if markWord layout get changed.
198   markWord set_unlocked() const {
199     return markWord(value() | unlocked_value);
200   }
201   bool has_locker() const {
202     assert(LockingMode == LM_LEGACY, "should only be called with legacy stack locking");
203     return (value() & lock_mask_in_place) == locked_value;
204   }
205   BasicLock* locker() const {
206     assert(has_locker(), "check");
207     return (BasicLock*) value();
208   }
209 
210   bool is_fast_locked() const {
211     assert(LockingMode == LM_LIGHTWEIGHT, "should only be called with new lightweight locking");
212     return (value() & lock_mask_in_place) == locked_value;

219   bool has_monitor() const {
220     return ((value() & lock_mask_in_place) == monitor_value);
221   }
222   ObjectMonitor* monitor() const {
223     assert(has_monitor(), "check");
224     assert(!UseObjectMonitorTable, "Lightweight locking with OM table does not use markWord for monitors");
225     // Use xor instead of &~ to provide one extra tag-bit check.
226     return (ObjectMonitor*) (value() ^ monitor_value);
227   }
228   bool has_displaced_mark_helper() const {
229     intptr_t lockbits = value() & lock_mask_in_place;
230     if (LockingMode == LM_LIGHTWEIGHT) {
231       return !UseObjectMonitorTable && lockbits == monitor_value;
232     }
233     // monitor (0b10) | stack-locked (0b00)?
234     return (lockbits & unlocked_value) == 0;
235   }
236   markWord displaced_mark_helper() const;
237   void set_displaced_mark_helper(markWord m) const;
238   markWord copy_set_hash(intptr_t hash) const {

239     uintptr_t tmp = value() & (~hash_mask_in_place);
240     tmp |= ((hash & hash_mask) << hash_shift);
241     return markWord(tmp);
242   }
243   // it is only used to be stored into BasicLock as the
244   // indicator that the lock is using heavyweight monitor
245   static markWord unused_mark() {
246     return markWord(marked_value);
247   }
248   // the following two functions create the markWord to be
249   // stored into object header, it encodes monitor info
250   static markWord encode(BasicLock* lock) {
251     return from_pointer(lock);
252   }
253   static markWord encode(ObjectMonitor* monitor) {
254     assert(!UseObjectMonitorTable, "Lightweight locking with OM table does not use markWord for monitors");
255     uintptr_t tmp = (uintptr_t) monitor;
256     return markWord(tmp | monitor_value);
257   }
258 
259   markWord set_has_monitor() const {
260     return markWord((value() & ~lock_mask_in_place) | monitor_value);
261   }
262 
263   // used to encode pointers during GC
264   markWord clear_lock_bits() const { return markWord(value() & ~lock_mask_in_place); }
265 
266   // age operations
267   markWord set_marked()   { return markWord((value() & ~lock_mask_in_place) | marked_value); }
268   markWord set_unmarked() { return markWord((value() & ~lock_mask_in_place) | unlocked_value); }
269 
270   uint     age()           const { return (uint) mask_bits(value() >> age_shift, age_mask); }
271   markWord set_age(uint v) const {
272     assert((v & ~age_mask) == 0, "shouldn't overflow age field");
273     return markWord((value() & ~age_mask_in_place) | ((v & age_mask) << age_shift));
274   }
275   markWord incr_age()      const { return age() == max_age ? markWord(_value) : set_age(age() + 1); }
276 
277   // hash operations
278   intptr_t hash() const {

279     return mask_bits(value() >> hash_shift, hash_mask);
280   }
281 
282   bool has_no_hash() const {
283     return hash() == no_hash;
























































284   }
285 
286   inline Klass* klass() const;
287   inline Klass* klass_or_null() const;
288   inline Klass* klass_without_asserts() const;
289   inline narrowKlass narrow_klass() const;
290   inline markWord set_narrow_klass(narrowKlass narrow_klass) const;
291 




292   // Prototype mark for initialization
293   static markWord prototype() {
294     return markWord( no_hash_in_place | no_lock_in_place );




295   }
296 
297   // Debugging
298   void print_on(outputStream* st, bool print_monitor_info = true) const;
299 
300   // Prepare address of oop for placement into mark
301   inline static markWord encode_pointer_as_mark(void* p) { return from_pointer(p).set_marked(); }
302 
303   // Recover address of oop from encoded form used in mark
304   inline void* decode_pointer() const { return (void*)clear_lock_bits().value(); }
305 
306   inline bool is_self_forwarded() const {
307     NOT_LP64(assert(LockingMode != LM_LEGACY, "incorrect with LM_LEGACY on 32 bit");)
308     return mask_bits(value(), self_fwd_mask_in_place) != 0;

309   }
310 
311   inline markWord set_self_forwarded() const {
312     NOT_LP64(assert(LockingMode != LM_LEGACY, "incorrect with LM_LEGACY on 32 bit");)
313     return markWord(value() | self_fwd_mask_in_place);
314   }
315 
316   inline markWord unset_self_forwarded() const {
317     NOT_LP64(assert(LockingMode != LM_LEGACY, "incorrect with LM_LEGACY on 32 bit");)
318     return markWord(value() & ~self_fwd_mask_in_place);
319   }
320 
321   inline oop forwardee() const {
322     return cast_to_oop(decode_pointer());
323   }
324 };
325 
326 // Support atomic operations.
327 template<>
328 struct PrimitiveConversions::Translate<markWord> : public std::true_type {

 29 #include "oops/compressedKlass.hpp"
 30 #include "oops/oopsHierarchy.hpp"
 31 #include "runtime/globals.hpp"
 32 
 33 #include <type_traits>
 34 
 35 // The markWord describes the header of an object.
 36 //
 37 // Bit-format of an object header (most significant first, big endian layout below):
 38 //
 39 //  32 bits:
 40 //  --------
 41 //             hash:25 ------------>| age:4  self-fwd:1  lock:2 (normal object)
 42 //
 43 //  64 bits:
 44 //  --------
 45 //  unused:22 hash:31 -->| unused_gap:4  age:4  self-fwd:1  lock:2 (normal object)
 46 //
 47 //  64 bits (with compact headers):
 48 //  -------------------------------
 49 //  klass:22  unused_gap:29 hash:2 -->| unused_gap:4  age:4  self-fwd:1  lock:2 (normal object)
 50 //
 51 //  - hash contains the identity hash value: largest value is
 52 //    31 bits, see os::random().  Also, 64-bit vm's require
 53 //    a hash value no bigger than 32 bits because they will not
 54 //    properly generate a mask larger than that: see library_call.cpp
 55 //
 56 //  - With +UseCompactObjectHeaders:
 57 //    hashctrl bits indicate if object has been hashed:
 58 //    00 - never hashed
 59 //    01 - hashed, but not expanded by GC: will recompute hash
 60 //    10 - not hashed, but expanded; special state used only by CDS to deal with scratch classes
 61 //    11 - hashed and expanded by GC, and hashcode has been installed in hidden field
 62 //
 63 //    When identityHashCode() is called, the transitions work as follows:
 64 //    00 - set the hashctrl bits to 01, and compute the identity hash
 65 //    01 - recompute idendity hash. When GC encounters 01 when moving an object, it will allocate an extra word, if
 66 //         necessary, for the object copy, and install 11.
 67 //    11 - read hashcode from field
 68 //
 69 //  - the two lock bits are used to describe three states: locked/unlocked and monitor.
 70 //
 71 //    [ptr             | 00]  locked             ptr points to real header on stack (stack-locking in use)
 72 //    [header          | 00]  locked             locked regular object header (fast-locking in use)
 73 //    [header          | 01]  unlocked           regular object header
 74 //    [ptr             | 10]  monitor            inflated lock (header is swapped out, UseObjectMonitorTable == false)
 75 //    [header          | 10]  monitor            inflated lock (UseObjectMonitorTable == true)
 76 //    [ptr             | 11]  marked             used to mark an object
 77 //    [0 ............ 0| 00]  inflating          inflation in progress (stack-locking in use)
 78 //
 79 //    We assume that stack/thread pointers have the lowest two bits cleared.
 80 //
 81 //  - INFLATING() is a distinguished markword value of all zeros that is
 82 //    used when inflating an existing stack-lock into an ObjectMonitor.
 83 //    See below for is_being_inflated() and INFLATING().
 84 
 85 class BasicLock;
 86 class ObjectMonitor;
 87 class JavaThread;
 88 class outputStream;

101   ~markWord() = default;
102   markWord(const markWord&) = default;
103   markWord& operator=(const markWord&) = default;
104 
105   static markWord from_pointer(void* ptr) {
106     return markWord((uintptr_t)ptr);
107   }
108   void* to_pointer() const {
109     return (void*)_value;
110   }
111 
112   bool operator==(const markWord& other) const {
113     return _value == other._value;
114   }
115   bool operator!=(const markWord& other) const {
116     return !operator==(other);
117   }
118 
119   // Conversion
120   uintptr_t value() const { return _value; }
121   uint32_t value32() const { return (uint32_t)_value; }
122 
123   // Constants
124   static const int age_bits                       = 4;
125   static const int lock_bits                      = 2;
126   static const int self_fwd_bits                  = 1;
127   static const int max_hash_bits                  = BitsPerWord - age_bits - lock_bits - self_fwd_bits;
128   static const int hash_bits                      = max_hash_bits > 31 ? 31 : max_hash_bits;
129   static const int unused_gap_bits                = LP64_ONLY(4) NOT_LP64(0); // Reserved for Valhalla.
130   static const int hashctrl_bits                  = 2;
131 
132   static const int lock_shift                     = 0;
133   static const int self_fwd_shift                 = lock_shift + lock_bits;
134   static const int age_shift                      = self_fwd_shift + self_fwd_bits;
135   static const int hash_shift                     = age_shift + age_bits + unused_gap_bits;
136   static const int hashctrl_shift                 = age_shift + age_bits + unused_gap_bits;
137 
138   static const uintptr_t lock_mask                = right_n_bits(lock_bits);
139   static const uintptr_t lock_mask_in_place       = lock_mask << lock_shift;
140   static const uintptr_t self_fwd_mask            = right_n_bits(self_fwd_bits);
141   static const uintptr_t self_fwd_mask_in_place   = self_fwd_mask << self_fwd_shift;
142   static const uintptr_t age_mask                 = right_n_bits(age_bits);
143   static const uintptr_t age_mask_in_place        = age_mask << age_shift;
144   static const uintptr_t hash_mask                = right_n_bits(hash_bits);
145   static const uintptr_t hash_mask_in_place       = hash_mask << hash_shift;
146   static const uintptr_t hashctrl_mask            = right_n_bits(hashctrl_bits);
147   static const uintptr_t hashctrl_mask_in_place   = hashctrl_mask << hashctrl_shift;
148   static const uintptr_t hashctrl_hashed_mask_in_place    = ((uintptr_t)1) << hashctrl_shift;
149   static const uintptr_t hashctrl_expanded_mask_in_place  = ((uintptr_t)2) << hashctrl_shift;
150 
151 #ifdef _LP64
152   // Used only with compact headers:
153   // We store the (narrow) Klass* in the bits 43 to 64.
154 
155   // These are for bit-precise extraction of the narrow Klass* from the 64-bit Markword
156   static constexpr int klass_shift                = hashctrl_shift + hashctrl_bits;
157   static constexpr int klass_bits                 = 19;


158   static constexpr uintptr_t klass_mask           = right_n_bits(klass_bits);
159   static constexpr uintptr_t klass_mask_in_place  = klass_mask << klass_shift;
160 #endif
161 
162 
163   static const uintptr_t locked_value             = 0;
164   static const uintptr_t unlocked_value           = 1;
165   static const uintptr_t monitor_value            = 2;
166   static const uintptr_t marked_value             = 3;
167 
168   static const uintptr_t no_hash                  = 0 ;  // no hash value assigned
169   static const uintptr_t no_hash_in_place         = (uintptr_t)no_hash << hash_shift;
170   static const uintptr_t no_lock_in_place         = unlocked_value;
171 
172   static const uint max_age                       = age_mask;
173 
174   // Creates a markWord with all bits set to zero.
175   static markWord zero() { return markWord(uintptr_t(0)); }
176 
177   // lock accessors (note that these assume lock_shift == 0)
178   bool is_locked()   const {
179     return (mask_bits(value(), lock_mask_in_place) != unlocked_value);
180   }
181   bool is_unlocked() const {
182     return (mask_bits(value(), lock_mask_in_place) == unlocked_value);
183   }
184   bool is_marked()   const {
185     return (value() & (self_fwd_mask_in_place | lock_mask_in_place)) > monitor_value;
186   }
187   bool is_forwarded() const {
188     // Returns true for normal forwarded (0b011) and self-forwarded (0b1xx).
189     return mask_bits(value(), lock_mask_in_place | self_fwd_mask_in_place) >= static_cast<intptr_t>(marked_value);
190   }
191   bool is_neutral()  const {  // Not locked, or marked - a "clean" neutral state
192     return (mask_bits(value(), lock_mask_in_place) == unlocked_value);
193   }
194 
195   // Special temporary state of the markWord while being inflated.
196   // Code that looks at mark outside a lock need to take this into account.
197   bool is_being_inflated() const { return (value() == 0); }
198 
199   // Distinguished markword value - used when inflating over
200   // an existing stack-lock.  0 indicates the markword is "BUSY".
201   // Lockword mutators that use a LD...CAS idiom should always
202   // check for and avoid overwriting a 0 value installed by some
203   // other thread.  (They should spin or block instead.  The 0 value
204   // is transient and *should* be short-lived).
205   // Fast-locking does not use INFLATING.
206   static markWord INFLATING() { return zero(); }    // inflate-in-progress
207 
208   // Should this header be preserved during GC?
209   bool must_be_preserved(const oopDesc* obj) const {
210     return UseCompactObjectHeaders ? !is_unlocked() : (!is_unlocked() || !has_no_hash());
211   }
212 
213   // WARNING: The following routines are used EXCLUSIVELY by
214   // synchronization functions. They are not really gc safe.
215   // They must get updated if markWord layout get changed.
216   markWord set_unlocked() const {
217     return markWord(value() | unlocked_value);
218   }
219   bool has_locker() const {
220     assert(LockingMode == LM_LEGACY, "should only be called with legacy stack locking");
221     return (value() & lock_mask_in_place) == locked_value;
222   }
223   BasicLock* locker() const {
224     assert(has_locker(), "check");
225     return (BasicLock*) value();
226   }
227 
228   bool is_fast_locked() const {
229     assert(LockingMode == LM_LIGHTWEIGHT, "should only be called with new lightweight locking");
230     return (value() & lock_mask_in_place) == locked_value;

237   bool has_monitor() const {
238     return ((value() & lock_mask_in_place) == monitor_value);
239   }
240   ObjectMonitor* monitor() const {
241     assert(has_monitor(), "check");
242     assert(!UseObjectMonitorTable, "Lightweight locking with OM table does not use markWord for monitors");
243     // Use xor instead of &~ to provide one extra tag-bit check.
244     return (ObjectMonitor*) (value() ^ monitor_value);
245   }
246   bool has_displaced_mark_helper() const {
247     intptr_t lockbits = value() & lock_mask_in_place;
248     if (LockingMode == LM_LIGHTWEIGHT) {
249       return !UseObjectMonitorTable && lockbits == monitor_value;
250     }
251     // monitor (0b10) | stack-locked (0b00)?
252     return (lockbits & unlocked_value) == 0;
253   }
254   markWord displaced_mark_helper() const;
255   void set_displaced_mark_helper(markWord m) const;
256   markWord copy_set_hash(intptr_t hash) const {
257     assert(!UseCompactObjectHeaders, "Do not use with compact i-hash");
258     uintptr_t tmp = value() & (~hash_mask_in_place);
259     tmp |= ((hash & hash_mask) << hash_shift);
260     return markWord(tmp);
261   }
262   // it is only used to be stored into BasicLock as the
263   // indicator that the lock is using heavyweight monitor
264   static markWord unused_mark() {
265     return markWord(marked_value);
266   }
267   // the following two functions create the markWord to be
268   // stored into object header, it encodes monitor info
269   static markWord encode(BasicLock* lock) {
270     return from_pointer(lock);
271   }
272   static markWord encode(ObjectMonitor* monitor) {
273     assert(!UseObjectMonitorTable, "Lightweight locking with OM table does not use markWord for monitors");
274     uintptr_t tmp = (uintptr_t) monitor;
275     return markWord(tmp | monitor_value);
276   }
277 
278   markWord set_has_monitor() const {
279     return markWord((value() & ~lock_mask_in_place) | monitor_value);
280   }
281 
282   // used to encode pointers during GC
283   markWord clear_lock_bits() const { return markWord(value() & ~lock_mask_in_place); }
284 
285   // age operations
286   markWord set_marked()   { return markWord((value() & ~lock_mask_in_place) | marked_value); }
287   markWord set_unmarked() { return markWord((value() & ~lock_mask_in_place) | unlocked_value); }
288 
289   uint     age()           const { return (uint) mask_bits(value() >> age_shift, age_mask); }
290   markWord set_age(uint v) const {
291     assert((v & ~age_mask) == 0, "shouldn't overflow age field");
292     return markWord((value() & ~age_mask_in_place) | ((v & age_mask) << age_shift));
293   }
294   markWord incr_age()      const { return age() == max_age ? markWord(_value) : set_age(age() + 1); }
295 
296   // hash operations
297   intptr_t hash() const {
298     assert(!UseCompactObjectHeaders, "only without compact i-hash");
299     return mask_bits(value() >> hash_shift, hash_mask);
300   }
301 
302   bool has_no_hash() const {
303     if (UseCompactObjectHeaders) {
304       return !is_hashed();
305     } else {
306       return hash() == no_hash;
307     }
308   }
309 
310   inline bool is_hashed_not_expanded() const {
311     assert(UseCompactObjectHeaders, "only with compact i-hash");
312     return (value() & hashctrl_mask_in_place) == hashctrl_hashed_mask_in_place;
313   }
314   inline markWord set_hashed_not_expanded() const {
315     assert(UseCompactObjectHeaders, "only with compact i-hash");
316     return markWord((value() & ~hashctrl_mask_in_place) | hashctrl_hashed_mask_in_place);
317   }
318 
319   inline bool is_hashed_expanded() const {
320     assert(UseCompactObjectHeaders, "only with compact i-hash");
321     return (value() & hashctrl_mask_in_place) == (hashctrl_hashed_mask_in_place | hashctrl_expanded_mask_in_place);
322   }
323   inline markWord set_hashed_expanded() const {
324     assert(UseCompactObjectHeaders, "only with compact i-hash");
325     return markWord((value() & ~hashctrl_mask_in_place) | (hashctrl_hashed_mask_in_place | hashctrl_expanded_mask_in_place));
326   }
327 
328   // This is a special hashctrl state (11) that is only used
329   // during CDS archive dumping. There we allocate 'scratch mirrors' for
330   // each real mirror klass. We allocate those scratch mirrors
331   // in a pre-extended form, but without being hashed. When the
332   // real mirror gets hashed, then we turn the scratch mirror into
333   // hashed_moved state, otherwise we leave it in that special state
334   // which indicates that the archived copy will be allocated in the
335   // unhashed form.
336   inline bool is_not_hashed_expanded() const {
337     assert(UseCompactObjectHeaders, "only with compact i-hash");
338     return (value() & hashctrl_mask_in_place) == hashctrl_expanded_mask_in_place;
339   }
340   inline markWord set_not_hashed_expanded() const {
341     assert(UseCompactObjectHeaders, "only with compact i-hash");
342     return markWord((value() & ~hashctrl_mask_in_place) | hashctrl_expanded_mask_in_place);
343   }
344   // Return true when object is either hashed_moved or not_hashed_moved.
345   inline bool is_expanded() const {
346     assert(UseCompactObjectHeaders, "only with compact i-hash");
347     return (value() & hashctrl_expanded_mask_in_place) != 0;
348   }
349   inline bool is_hashed() const {
350     assert(UseCompactObjectHeaders, "only with compact i-hash");
351     return (value() & hashctrl_hashed_mask_in_place) != 0;
352   }
353 
354   inline markWord copy_hashctrl_from(markWord m) const {
355     if (UseCompactObjectHeaders) {
356       return markWord((value() & ~hashctrl_mask_in_place) | (m.value() & hashctrl_mask_in_place));
357     } else {
358       return markWord(value());
359     }
360   }
361 
362   inline Klass* klass() const;
363   inline Klass* klass_or_null() const;
364   inline Klass* klass_without_asserts() const;
365   inline narrowKlass narrow_klass() const;
366   inline markWord set_narrow_klass(narrowKlass narrow_klass) const;
367 
368 #ifdef _LP64
369   inline int array_length() { return checked_cast<int>(value() >> 32); }
370 #endif
371 
372   // Prototype mark for initialization
373   static markWord prototype() {
374     if (UseCompactObjectHeaders) {
375       return markWord(no_lock_in_place);
376     } else {
377       return markWord(no_hash_in_place | no_lock_in_place);
378     }
379   }
380 
381   // Debugging
382   void print_on(outputStream* st, bool print_monitor_info = true) const;
383 
384   // Prepare address of oop for placement into mark
385   inline static markWord encode_pointer_as_mark(void* p) { return from_pointer(p).set_marked(); }
386 
387   // Recover address of oop from encoded form used in mark
388   inline void* decode_pointer() const { return (void*)clear_lock_bits().value(); }
389 
390   inline bool is_self_forwarded() const {
391     NOT_LP64(assert(LockingMode != LM_LEGACY, "incorrect with LM_LEGACY on 32 bit");)
392     // Match 100, 101, 110 but not 111.
393     return mask_bits(value() + 1, (lock_mask_in_place | self_fwd_mask_in_place)) > 4;
394   }
395 
396   inline markWord set_self_forwarded() const {
397     NOT_LP64(assert(LockingMode != LM_LEGACY, "incorrect with LM_LEGACY on 32 bit");)
398     return markWord(value() | self_fwd_mask_in_place);
399   }
400 
401   inline markWord unset_self_forwarded() const {
402     NOT_LP64(assert(LockingMode != LM_LEGACY, "incorrect with LM_LEGACY on 32 bit");)
403     return markWord(value() & ~self_fwd_mask_in_place);
404   }
405 
406   inline oop forwardee() const {
407     return cast_to_oop(decode_pointer());
408   }
409 };
410 
411 // Support atomic operations.
412 template<>
413 struct PrimitiveConversions::Translate<markWord> : public std::true_type {
< prev index next >