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