28 #include "cppstdlib/type_traits.hpp"
29 #include "metaprogramming/primitiveConversions.hpp"
30 #include "oops/compressedKlass.hpp"
31 #include "oops/oopsHierarchy.hpp"
32 #include "runtime/globals.hpp"
33
34 // The markWord describes the header of an object.
35 //
36 // Bit-format of an object header (most significant first, big endian layout below):
37 //
38 // 32 bits:
39 // --------
40 // hash:25 ------------>| age:4 self-fwd:1 lock:2 (normal object)
41 //
42 // 64 bits:
43 // --------
44 // unused:22 hash:31 -->| unused_gap:4 age:4 self-fwd:1 lock:2 (normal object)
45 //
46 // 64 bits (with compact headers):
47 // -------------------------------
48 // klass:22 hash:31 -->| unused_gap:4 age:4 self-fwd:1 lock:2 (normal object)
49 //
50 // - hash contains the identity hash value: largest value is
51 // 31 bits, see os::random(). Also, 64-bit vm's require
52 // a hash value no bigger than 32 bits because they will not
53 // properly generate a mask larger than that: see library_call.cpp
54 //
55 // - the two lock bits are used to describe three states: locked/unlocked and monitor.
56 //
57 // [ptr | 00] locked ptr points to real header on stack (stack-locking in use)
58 // [header | 00] locked locked regular object header (fast-locking in use)
59 // [header | 01] unlocked regular object header
60 // [ptr | 10] monitor inflated lock (header is swapped out, UseObjectMonitorTable == false)
61 // [header | 10] monitor inflated lock (UseObjectMonitorTable == true)
62 // [ptr | 11] marked used to mark an object
63 // [0 ............ 0| 00] inflating inflation in progress (stack-locking in use)
64 //
65 // We assume that stack/thread pointers have the lowest two bits cleared.
66 //
67 // - INFLATING() is a distinguished markword value of all zeros that is
68 // used when inflating an existing stack-lock into an ObjectMonitor.
69 // See below for is_being_inflated() and INFLATING().
70
71 class BasicLock;
72 class ObjectMonitor;
73 class JavaThread;
74 class outputStream;
87 ~markWord() = default;
88 markWord(const markWord&) = default;
89 markWord& operator=(const markWord&) = default;
90
91 static markWord from_pointer(void* ptr) {
92 return markWord((uintptr_t)ptr);
93 }
94 void* to_pointer() const {
95 return (void*)_value;
96 }
97
98 bool operator==(const markWord& other) const {
99 return _value == other._value;
100 }
101 bool operator!=(const markWord& other) const {
102 return !operator==(other);
103 }
104
105 // Conversion
106 uintptr_t value() const { return _value; }
107
108 // Constants
109 static const int age_bits = 4;
110 static const int lock_bits = 2;
111 static const int self_fwd_bits = 1;
112 static const int max_hash_bits = BitsPerWord - age_bits - lock_bits - self_fwd_bits;
113 static const int hash_bits = max_hash_bits > 31 ? 31 : max_hash_bits;
114 static const int unused_gap_bits = LP64_ONLY(4) NOT_LP64(0); // Reserved for Valhalla.
115
116 static const int lock_shift = 0;
117 static const int self_fwd_shift = lock_shift + lock_bits;
118 static const int age_shift = self_fwd_shift + self_fwd_bits;
119 static const int hash_shift = age_shift + age_bits + unused_gap_bits;
120
121 static const uintptr_t lock_mask = right_n_bits(lock_bits);
122 static const uintptr_t lock_mask_in_place = lock_mask << lock_shift;
123 static const uintptr_t self_fwd_mask = right_n_bits(self_fwd_bits);
124 static const uintptr_t self_fwd_mask_in_place = self_fwd_mask << self_fwd_shift;
125 static const uintptr_t age_mask = right_n_bits(age_bits);
126 static const uintptr_t age_mask_in_place = age_mask << age_shift;
127 static const uintptr_t hash_mask = right_n_bits(hash_bits);
128 static const uintptr_t hash_mask_in_place = hash_mask << hash_shift;
129
130 #ifdef _LP64
131 // Used only with compact headers:
132 // We store the (narrow) Klass* in the bits 43 to 64.
133
134 // These are for bit-precise extraction of the narrow Klass* from the 64-bit Markword
135 static constexpr int klass_offset_in_bytes = 4;
136 static constexpr int klass_shift = hash_shift + hash_bits;
137 static constexpr int klass_shift_at_offset = klass_shift - klass_offset_in_bytes * BitsPerByte;
138 static constexpr int klass_bits = 22;
139 static constexpr uintptr_t klass_mask = right_n_bits(klass_bits);
140 static constexpr uintptr_t klass_mask_in_place = klass_mask << klass_shift;
141 #endif
142
143
144 static const uintptr_t locked_value = 0;
145 static const uintptr_t unlocked_value = 1;
146 static const uintptr_t monitor_value = 2;
147 static const uintptr_t marked_value = 3;
148
149 static const uintptr_t no_hash = 0 ; // no hash value assigned
150 static const uintptr_t no_hash_in_place = (uintptr_t)no_hash << hash_shift;
151 static const uintptr_t no_lock_in_place = unlocked_value;
152
153 static const uint max_age = age_mask;
154
155 // Creates a markWord with all bits set to zero.
156 static markWord zero() { return markWord(uintptr_t(0)); }
157
158 // lock accessors (note that these assume lock_shift == 0)
159 bool is_locked() const {
160 return (mask_bits(value(), lock_mask_in_place) != unlocked_value);
161 }
162 bool is_unlocked() const {
163 return (mask_bits(value(), lock_mask_in_place) == unlocked_value);
164 }
165 bool is_marked() const {
166 return (mask_bits(value(), lock_mask_in_place) == marked_value);
167 }
168 bool is_forwarded() const {
169 // Returns true for normal forwarded (0b011) and self-forwarded (0b1xx).
170 return mask_bits(value(), lock_mask_in_place | self_fwd_mask_in_place) >= static_cast<intptr_t>(marked_value);
171 }
172 bool is_neutral() const { // Not locked, or marked - a "clean" neutral state
173 return (mask_bits(value(), lock_mask_in_place) == unlocked_value);
174 }
175
176 // Special temporary state of the markWord while being inflated.
177 // Code that looks at mark outside a lock need to take this into account.
178 bool is_being_inflated() const { return (value() == 0); }
179
180 // Distinguished markword value - used when inflating over
181 // an existing stack-lock. 0 indicates the markword is "BUSY".
182 // Lockword mutators that use a LD...CAS idiom should always
183 // check for and avoid overwriting a 0 value installed by some
184 // other thread. (They should spin or block instead. The 0 value
185 // is transient and *should* be short-lived).
186 // Fast-locking does not use INFLATING.
187 static markWord INFLATING() { return zero(); } // inflate-in-progress
188
189 // Should this header be preserved during GC?
190 bool must_be_preserved() const {
191 return (!is_unlocked() || !has_no_hash());
192 }
193
194 // WARNING: The following routines are used EXCLUSIVELY by
195 // synchronization functions. They are not really gc safe.
196 // They must get updated if markWord layout get changed.
197 markWord set_unlocked() const {
198 return markWord(value() | unlocked_value);
199 }
200
201 bool is_fast_locked() const {
202 return (value() & lock_mask_in_place) == locked_value;
203 }
204 markWord set_fast_locked() const {
205 // Clear the lock_mask_in_place bits to set locked_value:
206 return markWord(value() & ~lock_mask_in_place);
207 }
208
209 bool has_monitor() const {
210 return ((value() & lock_mask_in_place) == monitor_value);
211 }
212 ObjectMonitor* monitor() const {
213 assert(has_monitor(), "check");
214 assert(!UseObjectMonitorTable, "Locking with OM table does not use markWord for monitors");
215 // Use xor instead of &~ to provide one extra tag-bit check.
216 return (ObjectMonitor*) (value() ^ monitor_value);
217 }
218 bool has_displaced_mark_helper() const {
219 intptr_t lockbits = value() & lock_mask_in_place;
220 return !UseObjectMonitorTable && lockbits == monitor_value;
221 }
222 markWord displaced_mark_helper() const;
223 void set_displaced_mark_helper(markWord m) const;
224 markWord copy_set_hash(intptr_t hash) const {
225 uintptr_t tmp = value() & (~hash_mask_in_place);
226 tmp |= ((hash & hash_mask) << hash_shift);
227 return markWord(tmp);
228 }
229 // it is only used to be stored into BasicLock as the
230 // indicator that the lock is using heavyweight monitor
231 static markWord unused_mark() {
232 return markWord(marked_value);
233 }
234 // the following two functions create the markWord to be
235 // stored into object header, it encodes monitor info
236 static markWord encode(BasicLock* lock) {
237 return from_pointer(lock);
238 }
239 static markWord encode(ObjectMonitor* monitor) {
240 assert(!UseObjectMonitorTable, "Locking with OM table does not use markWord for monitors");
241 uintptr_t tmp = (uintptr_t) monitor;
242 return markWord(tmp | monitor_value);
243 }
244
245 markWord set_has_monitor() const {
246 return markWord((value() & ~lock_mask_in_place) | monitor_value);
247 }
248
249 // used to encode pointers during GC
250 markWord clear_lock_bits() const { return markWord(value() & ~lock_mask_in_place); }
251
252 // age operations
253 markWord set_marked() { return markWord((value() & ~lock_mask_in_place) | marked_value); }
254 markWord set_unmarked() { return markWord((value() & ~lock_mask_in_place) | unlocked_value); }
255
256 uint age() const { return (uint) mask_bits(value() >> age_shift, age_mask); }
257 markWord set_age(uint v) const {
258 assert((v & ~age_mask) == 0, "shouldn't overflow age field");
259 return markWord((value() & ~age_mask_in_place) | ((v & age_mask) << age_shift));
260 }
261 markWord incr_age() const { return age() == max_age ? markWord(_value) : set_age(age() + 1); }
262
263 // hash operations
264 intptr_t hash() const {
265 return mask_bits(value() >> hash_shift, hash_mask);
266 }
267
268 bool has_no_hash() const {
269 return hash() == no_hash;
270 }
271
272 inline Klass* klass() const;
273 inline Klass* klass_or_null() const;
274 inline Klass* klass_without_asserts() const;
275 inline narrowKlass narrow_klass() const;
276 inline markWord set_narrow_klass(narrowKlass narrow_klass) const;
277
278 // Prototype mark for initialization
279 static markWord prototype() {
280 return markWord( no_hash_in_place | no_lock_in_place );
281 }
282
283 // Debugging
284 void print_on(outputStream* st, bool print_monitor_info = true) const;
285
286 // Prepare address of oop for placement into mark
287 inline static markWord encode_pointer_as_mark(void* p) { return from_pointer(p).set_marked(); }
288
289 // Recover address of oop from encoded form used in mark
290 inline void* decode_pointer() const { return (void*)clear_lock_bits().value(); }
291
292 inline bool is_self_forwarded() const {
293 return mask_bits(value(), self_fwd_mask_in_place) != 0;
294 }
295
296 inline markWord set_self_forwarded() const {
297 return markWord(value() | self_fwd_mask_in_place);
298 }
299
300 inline markWord unset_self_forwarded() const {
301 return markWord(value() & ~self_fwd_mask_in_place);
302 }
303
304 inline oop forwardee() const {
305 return cast_to_oop(decode_pointer());
306 }
307 };
308
309 // Support atomic operations.
310 template<>
311 struct PrimitiveConversions::Translate<markWord> : public std::true_type {
312 typedef markWord Value;
313 typedef uintptr_t Decayed;
|
28 #include "cppstdlib/type_traits.hpp"
29 #include "metaprogramming/primitiveConversions.hpp"
30 #include "oops/compressedKlass.hpp"
31 #include "oops/oopsHierarchy.hpp"
32 #include "runtime/globals.hpp"
33
34 // The markWord describes the header of an object.
35 //
36 // Bit-format of an object header (most significant first, big endian layout below):
37 //
38 // 32 bits:
39 // --------
40 // hash:25 ------------>| age:4 self-fwd:1 lock:2 (normal object)
41 //
42 // 64 bits:
43 // --------
44 // unused:22 hash:31 -->| unused_gap:4 age:4 self-fwd:1 lock:2 (normal object)
45 //
46 // 64 bits (with compact headers):
47 // -------------------------------
48 // unused:32 klass:19 hashctrl:2 -->| unused_gap:4 age:4 self-fwd:1 lock:2 (normal object)
49 //
50 // Note: klass occupies bits 13-31 (19 bits), hashctrl occupies bits 11-12 (2 bits)
51 //
52 // - hash contains the identity hash value: largest value is
53 // 31 bits, see os::random(). Also, 64-bit vm's require
54 // a hash value no bigger than 32 bits because they will not
55 // properly generate a mask larger than that: see library_call.cpp
56 //
57 // - With +UseCompactObjectHeaders:
58 // hashctrl bits indicate if object has been hashed:
59 // 00 - never hashed
60 // 01 - hashed, but not expanded by GC: will recompute hash
61 // 10 - not hashed, but expanded; special state used only by CDS to deal with scratch classes
62 // 11 - hashed and expanded by GC, and hashcode has been installed in hidden field
63 //
64 // When identityHashCode() is called, the transitions work as follows:
65 // 00 - set the hashctrl bits to 01, and compute the identity hash
66 // 01 - recompute idendity hash. When GC encounters 01 when moving an object, it will allocate an extra word, if
67 // necessary, for the object copy, and install 11.
68 // 11 - read hashcode from field
69 //
70 // - the two lock bits are used to describe three states: locked/unlocked and monitor.
71 //
72 // [ptr | 00] locked ptr points to real header on stack (stack-locking in use)
73 // [header | 00] locked locked regular object header (fast-locking in use)
74 // [header | 01] unlocked regular object header
75 // [ptr | 10] monitor inflated lock (header is swapped out, UseObjectMonitorTable == false)
76 // [header | 10] monitor inflated lock (UseObjectMonitorTable == true)
77 // [ptr | 11] marked used to mark an object
78 // [0 ............ 0| 00] inflating inflation in progress (stack-locking in use)
79 //
80 // We assume that stack/thread pointers have the lowest two bits cleared.
81 //
82 // - INFLATING() is a distinguished markword value of all zeros that is
83 // used when inflating an existing stack-lock into an ObjectMonitor.
84 // See below for is_being_inflated() and INFLATING().
85
86 class BasicLock;
87 class ObjectMonitor;
88 class JavaThread;
89 class outputStream;
102 ~markWord() = default;
103 markWord(const markWord&) = default;
104 markWord& operator=(const markWord&) = default;
105
106 static markWord from_pointer(void* ptr) {
107 return markWord((uintptr_t)ptr);
108 }
109 void* to_pointer() const {
110 return (void*)_value;
111 }
112
113 bool operator==(const markWord& other) const {
114 return _value == other._value;
115 }
116 bool operator!=(const markWord& other) const {
117 return !operator==(other);
118 }
119
120 // Conversion
121 uintptr_t value() const { return _value; }
122 uint32_t value32() const { return (uint32_t)_value; }
123
124 // Constants
125 static const int age_bits = 4;
126 static const int lock_bits = 2;
127 static const int self_fwd_bits = 1;
128 static const int max_hash_bits = BitsPerWord - age_bits - lock_bits - self_fwd_bits;
129 static const int hash_bits = max_hash_bits > 31 ? 31 : max_hash_bits;
130 static const int unused_gap_bits = LP64_ONLY(4) NOT_LP64(0); // Reserved for Valhalla.
131 static const int hashctrl_bits = 2;
132
133 static const int lock_shift = 0;
134 static const int self_fwd_shift = lock_shift + lock_bits;
135 static const int age_shift = self_fwd_shift + self_fwd_bits;
136 static const int hash_shift = age_shift + age_bits + unused_gap_bits;
137 static const int hashctrl_shift = age_shift + age_bits + unused_gap_bits;
138
139 static const uintptr_t lock_mask = right_n_bits(lock_bits);
140 static const uintptr_t lock_mask_in_place = lock_mask << lock_shift;
141 static const uintptr_t self_fwd_mask = right_n_bits(self_fwd_bits);
142 static const uintptr_t self_fwd_mask_in_place = self_fwd_mask << self_fwd_shift;
143 static const uintptr_t age_mask = right_n_bits(age_bits);
144 static const uintptr_t age_mask_in_place = age_mask << age_shift;
145 static const uintptr_t hash_mask = right_n_bits(hash_bits);
146 static const uintptr_t hash_mask_in_place = hash_mask << hash_shift;
147 static const uintptr_t hashctrl_mask = right_n_bits(hashctrl_bits);
148 static const uintptr_t hashctrl_mask_in_place = hashctrl_mask << hashctrl_shift;
149 static const uintptr_t hashctrl_hashed_mask_in_place = ((uintptr_t)1) << hashctrl_shift;
150 static const uintptr_t hashctrl_expanded_mask_in_place = ((uintptr_t)2) << hashctrl_shift;
151
152 #ifdef _LP64
153 // Used only with compact headers:
154 // With UseCompactObjectHeaders: We store the (narrow) Klass* in bits 13-31 (19 bits total).
155 // Without UseCompactObjectHeaders: Klass* is stored separately in object header, not in markword.
156
157 // These are for bit-precise extraction of the narrow Klass* from the markword (UseCompactObjectHeaders only)
158 //
159 // Bit position summary for UseCompactObjectHeaders:
160 // Bits 0- 1: lock (2 bits)
161 // Bit 2 : self-fwd (1 bit)
162 // Bits 3- 6: age (4 bits)
163 // Bits 7-10: unused_gap (4 bits)
164 // Bits 11-12: hashctrl (2 bits) - hash control state
165 // Bits 13-31: klass (19 bits) - narrow klass pointer
166 // Bits 32-63: unused (32 bits)
167 //
168 // Without UseCompactObjectHeaders, klass is stored separately in object header
169 static constexpr int klass_shift = hashctrl_shift + hashctrl_bits;
170 static constexpr int klass_bits = 19;
171 static constexpr uintptr_t klass_mask = right_n_bits(klass_bits);
172 static constexpr uintptr_t klass_mask_in_place = klass_mask << klass_shift;
173 #endif
174
175
176 static const uintptr_t locked_value = 0;
177 static const uintptr_t unlocked_value = 1;
178 static const uintptr_t monitor_value = 2;
179 static const uintptr_t marked_value = 3;
180 static const uintptr_t forward_expanded_value = 0b111;
181
182 static const uintptr_t no_hash = 0 ; // no hash value assigned
183 static const uintptr_t no_hash_in_place = (uintptr_t)no_hash << hash_shift;
184 static const uintptr_t no_lock_in_place = unlocked_value;
185
186 static const uint max_age = age_mask;
187
188 // Creates a markWord with all bits set to zero.
189 static markWord zero() { return markWord(uintptr_t(0)); }
190
191 // lock accessors (note that these assume lock_shift == 0)
192 bool is_locked() const {
193 return (mask_bits(value(), lock_mask_in_place) != unlocked_value);
194 }
195 bool is_unlocked() const {
196 return (mask_bits(value(), lock_mask_in_place) == unlocked_value);
197 }
198 bool is_marked() const {
199 return (value() & (self_fwd_mask_in_place | lock_mask_in_place)) > monitor_value;
200 }
201 bool is_forwarded() const {
202 // Returns true for normal forwarded (0b011) and self-forwarded (0b1xx).
203 return mask_bits(value(), lock_mask_in_place | self_fwd_mask_in_place) >= static_cast<intptr_t>(marked_value);
204 }
205 bool is_neutral() const { // Not locked, or marked - a "clean" neutral state
206 return (mask_bits(value(), lock_mask_in_place) == unlocked_value);
207 }
208
209 markWord set_forward_expanded() {
210 assert((value() & (lock_mask_in_place | self_fwd_mask_in_place)) == marked_value, "must be normal-forwarded here");
211 return markWord(value() | forward_expanded_value);
212 }
213 bool is_forward_expanded() {
214 return (value() & (lock_mask_in_place | self_fwd_mask_in_place)) == forward_expanded_value;
215 }
216
217 // Special temporary state of the markWord while being inflated.
218 // Code that looks at mark outside a lock need to take this into account.
219 bool is_being_inflated() const { return (value() == 0); }
220
221 // Distinguished markword value - used when inflating over
222 // an existing stack-lock. 0 indicates the markword is "BUSY".
223 // Lockword mutators that use a LD...CAS idiom should always
224 // check for and avoid overwriting a 0 value installed by some
225 // other thread. (They should spin or block instead. The 0 value
226 // is transient and *should* be short-lived).
227 // Fast-locking does not use INFLATING.
228 static markWord INFLATING() { return zero(); } // inflate-in-progress
229
230 // Should this header be preserved during GC?
231 bool must_be_preserved() const {
232 return UseCompactObjectHeaders ? !is_unlocked() : (!is_unlocked() || !has_no_hash());
233 }
234
235 // WARNING: The following routines are used EXCLUSIVELY by
236 // synchronization functions. They are not really gc safe.
237 // They must get updated if markWord layout get changed.
238 markWord set_unlocked() const {
239 return markWord(value() | unlocked_value);
240 }
241
242 bool is_fast_locked() const {
243 return (value() & lock_mask_in_place) == locked_value;
244 }
245 markWord set_fast_locked() const {
246 // Clear the lock_mask_in_place bits to set locked_value:
247 return markWord(value() & ~lock_mask_in_place);
248 }
249
250 bool has_monitor() const {
251 return ((value() & lock_mask_in_place) == monitor_value);
252 }
253 ObjectMonitor* monitor() const {
254 assert(has_monitor(), "check");
255 assert(!UseObjectMonitorTable, "Locking with OM table does not use markWord for monitors");
256 // Use xor instead of &~ to provide one extra tag-bit check.
257 return (ObjectMonitor*) (value() ^ monitor_value);
258 }
259 bool has_displaced_mark_helper() const {
260 intptr_t lockbits = value() & lock_mask_in_place;
261 return !UseObjectMonitorTable && lockbits == monitor_value;
262 }
263 markWord displaced_mark_helper() const;
264 void set_displaced_mark_helper(markWord m) const;
265 markWord copy_set_hash(intptr_t hash) const {
266 assert(!UseCompactObjectHeaders, "Do not use with compact i-hash");
267 uintptr_t tmp = value() & (~hash_mask_in_place);
268 tmp |= ((hash & hash_mask) << hash_shift);
269 return markWord(tmp);
270 }
271 // it is only used to be stored into BasicLock as the
272 // indicator that the lock is using heavyweight monitor
273 static markWord unused_mark() {
274 return markWord(marked_value);
275 }
276 // the following two functions create the markWord to be
277 // stored into object header, it encodes monitor info
278 static markWord encode(BasicLock* lock) {
279 return from_pointer(lock);
280 }
281 static markWord encode(ObjectMonitor* monitor) {
282 assert(!UseObjectMonitorTable, "Locking with OM table does not use markWord for monitors");
283 uintptr_t tmp = (uintptr_t) monitor;
284 return markWord(tmp | monitor_value);
285 }
286
287 markWord set_has_monitor() const {
288 return markWord((value() & ~lock_mask_in_place) | monitor_value);
289 }
290
291 // used to encode pointers during GC
292 markWord clear_lock_bits() const { return markWord(value() & ~(lock_mask_in_place | self_fwd_mask_in_place)); }
293
294 // age operations
295 markWord set_marked() { return markWord((value() & ~lock_mask_in_place) | marked_value); }
296 markWord set_unmarked() { return markWord((value() & ~lock_mask_in_place) | unlocked_value); }
297
298 uint age() const { return (uint) mask_bits(value() >> age_shift, age_mask); }
299 markWord set_age(uint v) const {
300 assert((v & ~age_mask) == 0, "shouldn't overflow age field");
301 return markWord((value() & ~age_mask_in_place) | ((v & age_mask) << age_shift));
302 }
303 markWord incr_age() const { return age() == max_age ? markWord(_value) : set_age(age() + 1); }
304
305 // hash operations
306 intptr_t hash() const {
307 assert(!UseCompactObjectHeaders, "only without compact i-hash");
308 return mask_bits(value() >> hash_shift, hash_mask);
309 }
310
311 bool has_no_hash() const {
312 if (UseCompactObjectHeaders) {
313 return !is_hashed();
314 } else {
315 return hash() == no_hash;
316 }
317 }
318
319 inline bool is_hashed_not_expanded() const {
320 assert(UseCompactObjectHeaders, "only with compact i-hash");
321 return (value() & hashctrl_mask_in_place) == hashctrl_hashed_mask_in_place;
322 }
323 inline markWord set_hashed_not_expanded() const {
324 assert(UseCompactObjectHeaders, "only with compact i-hash");
325 return markWord((value() & ~hashctrl_mask_in_place) | hashctrl_hashed_mask_in_place);
326 }
327
328 inline bool is_hashed_expanded() const {
329 assert(UseCompactObjectHeaders, "only with compact i-hash");
330 return (value() & hashctrl_mask_in_place) == (hashctrl_hashed_mask_in_place | hashctrl_expanded_mask_in_place);
331 }
332 inline markWord set_hashed_expanded() const {
333 assert(UseCompactObjectHeaders, "only with compact i-hash");
334 return markWord((value() & ~hashctrl_mask_in_place) | (hashctrl_hashed_mask_in_place | hashctrl_expanded_mask_in_place));
335 }
336
337 // This is a special hashctrl state (11) that is only used
338 // during CDS archive dumping. There we allocate 'scratch mirrors' for
339 // each real mirror klass. We allocate those scratch mirrors
340 // in a pre-extended form, but without being hashed. When the
341 // real mirror gets hashed, then we turn the scratch mirror into
342 // hashed_moved state, otherwise we leave it in that special state
343 // which indicates that the archived copy will be allocated in the
344 // unhashed form.
345 inline bool is_not_hashed_expanded() const {
346 assert(UseCompactObjectHeaders, "only with compact i-hash");
347 return (value() & hashctrl_mask_in_place) == hashctrl_expanded_mask_in_place;
348 }
349 inline markWord set_not_hashed_expanded() const {
350 assert(UseCompactObjectHeaders, "only with compact i-hash");
351 return markWord((value() & ~hashctrl_mask_in_place) | hashctrl_expanded_mask_in_place);
352 }
353 inline markWord set_not_hashed_not_expanded() const {
354 assert(UseCompactObjectHeaders, "only with compact i-hash");
355 return markWord(value() & ~(hashctrl_mask_in_place | hashctrl_expanded_mask_in_place));
356 }
357 // Return true when object is either hashed_moved or not_hashed_moved.
358 inline bool is_expanded() const {
359 assert(UseCompactObjectHeaders, "only with compact i-hash");
360 return (value() & hashctrl_expanded_mask_in_place) != 0;
361 }
362 inline bool is_hashed() const {
363 assert(UseCompactObjectHeaders, "only with compact i-hash");
364 return (value() & hashctrl_hashed_mask_in_place) != 0;
365 }
366
367 inline markWord copy_hashctrl_from(markWord m) const {
368 if (UseCompactObjectHeaders) {
369 return markWord((value() & ~hashctrl_mask_in_place) | (m.value() & hashctrl_mask_in_place));
370 } else {
371 return markWord(value());
372 }
373 }
374
375 inline Klass* klass() const;
376 inline Klass* klass_or_null() const;
377 inline Klass* klass_without_asserts() const;
378 inline narrowKlass narrow_klass() const;
379 inline markWord set_narrow_klass(narrowKlass narrow_klass) const;
380
381 #ifdef _LP64
382 inline int array_length() { return checked_cast<int>(value() >> 32); }
383 #endif
384
385 // Prototype mark for initialization
386 static markWord prototype() {
387 if (UseCompactObjectHeaders) {
388 return markWord(no_lock_in_place);
389 } else {
390 return markWord(no_hash_in_place | no_lock_in_place);
391 }
392 }
393
394 // Debugging
395 void print_on(outputStream* st, bool print_monitor_info = true) const;
396
397 // Prepare address of oop for placement into mark
398 inline static markWord encode_pointer_as_mark(void* p) { return from_pointer(p).set_marked(); }
399
400 // Recover address of oop from encoded form used in mark
401 inline void* decode_pointer() const { return (void*)clear_lock_bits().value(); }
402
403 inline bool is_self_forwarded() const {
404 // Match 100, 101, 110 but not 111.
405 return mask_bits(value() + 1, (lock_mask_in_place | self_fwd_mask_in_place)) > 4;
406 }
407
408 inline markWord set_self_forwarded() const {
409 return markWord(value() | self_fwd_mask_in_place);
410 }
411
412 inline markWord unset_self_forwarded() const {
413 return markWord(value() & ~self_fwd_mask_in_place);
414 }
415
416 inline oop forwardee() const {
417 return cast_to_oop(decode_pointer());
418 }
419 };
420
421 // Support atomic operations.
422 template<>
423 struct PrimitiveConversions::Translate<markWord> : public std::true_type {
424 typedef markWord Value;
425 typedef uintptr_t Decayed;
|