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
64 class BasicLock;
65 class ObjectMonitor;
66 class JavaThread;
67 class outputStream;
68
69 class markWord {
70 private:
71 uintptr_t _value;
72
73 public:
74 explicit markWord(uintptr_t value) : _value(value) {}
80 ~markWord() = default;
81 markWord(const markWord&) = default;
82 markWord& operator=(const markWord&) = default;
83
84 static markWord from_pointer(void* ptr) {
85 return markWord((uintptr_t)ptr);
86 }
87 void* to_pointer() const {
88 return (void*)_value;
89 }
90
91 bool operator==(const markWord& other) const {
92 return _value == other._value;
93 }
94 bool operator!=(const markWord& other) const {
95 return !operator==(other);
96 }
97
98 // Conversion
99 uintptr_t value() const { return _value; }
100
101 // Constants
102 static const int age_bits = 4;
103 static const int lock_bits = 2;
104 static const int self_fwd_bits = 1;
105 static const int max_hash_bits = BitsPerWord - age_bits - lock_bits - self_fwd_bits;
106 static const int hash_bits = max_hash_bits > 31 ? 31 : max_hash_bits;
107 static const int unused_gap_bits = LP64_ONLY(4) NOT_LP64(0); // Reserved for Valhalla.
108
109 static const int lock_shift = 0;
110 static const int self_fwd_shift = lock_shift + lock_bits;
111 static const int age_shift = self_fwd_shift + self_fwd_bits;
112 static const int hash_shift = age_shift + age_bits + unused_gap_bits;
113
114 static const uintptr_t lock_mask = right_n_bits(lock_bits);
115 static const uintptr_t lock_mask_in_place = lock_mask << lock_shift;
116 static const uintptr_t self_fwd_mask = right_n_bits(self_fwd_bits);
117 static const uintptr_t self_fwd_mask_in_place = self_fwd_mask << self_fwd_shift;
118 static const uintptr_t age_mask = right_n_bits(age_bits);
119 static const uintptr_t age_mask_in_place = age_mask << age_shift;
120 static const uintptr_t hash_mask = right_n_bits(hash_bits);
121 static const uintptr_t hash_mask_in_place = hash_mask << hash_shift;
122
123 #ifdef _LP64
124 // Used only with compact headers:
125 // We store the (narrow) Klass* in the bits 43 to 64.
126
127 // These are for bit-precise extraction of the narrow Klass* from the 64-bit Markword
128 static constexpr int klass_offset_in_bytes = 4;
129 static constexpr int klass_shift = hash_shift + hash_bits;
130 static constexpr int klass_shift_at_offset = klass_shift - klass_offset_in_bytes * BitsPerByte;
131 static constexpr int klass_bits = 22;
132 static constexpr uintptr_t klass_mask = right_n_bits(klass_bits);
133 static constexpr uintptr_t klass_mask_in_place = klass_mask << klass_shift;
134 #endif
135
136
137 static const uintptr_t locked_value = 0;
138 static const uintptr_t unlocked_value = 1;
139 static const uintptr_t monitor_value = 2;
140 static const uintptr_t marked_value = 3;
141
142 static const uintptr_t no_hash = 0 ; // no hash value assigned
143 static const uintptr_t no_hash_in_place = (uintptr_t)no_hash << hash_shift;
144 static const uintptr_t no_lock_in_place = unlocked_value;
145
146 static const uint max_age = age_mask;
147
148 // Creates a markWord with all bits set to zero.
149 static markWord zero() { return markWord(uintptr_t(0)); }
150
151 // lock accessors (note that these assume lock_shift == 0)
152 bool is_locked() const {
153 return (mask_bits(value(), lock_mask_in_place) != unlocked_value);
154 }
155 bool is_unlocked() const {
156 return (mask_bits(value(), lock_mask_in_place) == unlocked_value);
157 }
158 bool is_marked() const {
159 return (mask_bits(value(), lock_mask_in_place) == marked_value);
160 }
161 bool is_forwarded() const {
162 // Returns true for normal forwarded (0b011) and self-forwarded (0b1xx).
163 return mask_bits(value(), lock_mask_in_place | self_fwd_mask_in_place) >= static_cast<intptr_t>(marked_value);
164 }
165 bool is_neutral() const { // Not locked, or marked - a "clean" neutral state
166 return (mask_bits(value(), lock_mask_in_place) == unlocked_value);
167 }
168
169 // Should this header be preserved during GC?
170 bool must_be_preserved() const {
171 return (!is_unlocked() || !has_no_hash());
172 }
173
174 // WARNING: The following routines are used EXCLUSIVELY by
175 // synchronization functions. They are not really gc safe.
176 // They must get updated if markWord layout get changed.
177 markWord set_unlocked() const {
178 return markWord(value() | unlocked_value);
179 }
180
181 bool is_fast_locked() const {
182 return (value() & lock_mask_in_place) == locked_value;
183 }
184 markWord set_fast_locked() const {
185 // Clear the lock_mask_in_place bits to set locked_value:
186 return markWord(value() & ~lock_mask_in_place);
187 }
188
189 bool has_monitor() const {
190 return ((value() & lock_mask_in_place) == monitor_value);
191 }
196 assert(has_monitor(), "check");
197 assert(!UseObjectMonitorTable, "Locking with OM table does not use markWord for monitors");
198 // Use xor instead of &~ to provide one extra tag-bit check.
199 return (ObjectMonitor*) (value() ^ monitor_value);
200 }
201
202 static markWord encode(ObjectMonitor* monitor) {
203 assert(!UseObjectMonitorTable, "Locking with OM table does not use markWord for monitors");
204 uintptr_t tmp = (uintptr_t) monitor;
205 return markWord(tmp | monitor_value);
206 }
207
208 bool has_displaced_mark_helper() const {
209 intptr_t lockbits = value() & lock_mask_in_place;
210 return !UseObjectMonitorTable && lockbits == monitor_value;
211 }
212 markWord displaced_mark_helper() const;
213 void set_displaced_mark_helper(markWord m) const;
214
215 // used to encode pointers during GC
216 markWord clear_lock_bits() const { return markWord(value() & ~lock_mask_in_place); }
217
218 // age operations
219 markWord set_marked() { return markWord((value() & ~lock_mask_in_place) | marked_value); }
220 markWord set_unmarked() { return markWord((value() & ~lock_mask_in_place) | unlocked_value); }
221
222 uint age() const { return (uint) mask_bits(value() >> age_shift, age_mask); }
223 markWord set_age(uint v) const {
224 assert((v & ~age_mask) == 0, "shouldn't overflow age field");
225 return markWord((value() & ~age_mask_in_place) | ((v & age_mask) << age_shift));
226 }
227 markWord incr_age() const { return age() == max_age ? markWord(_value) : set_age(age() + 1); }
228
229 // hash operations
230 intptr_t hash() const {
231 return mask_bits(value() >> hash_shift, hash_mask);
232 }
233
234 bool has_no_hash() const {
235 return hash() == no_hash;
236 }
237
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
244 inline Klass* klass() const;
245 inline Klass* klass_or_null() const;
246 inline Klass* klass_without_asserts() const;
247 inline narrowKlass narrow_klass() const;
248 inline markWord set_narrow_klass(narrowKlass narrow_klass) const;
249
250 // Prototype mark for initialization
251 static markWord prototype() {
252 return markWord( no_hash_in_place | no_lock_in_place );
253 }
254
255 // Debugging
256 void print_on(outputStream* st, bool print_monitor_info = true) const;
257
258 // Prepare address of oop for placement into mark
259 inline static markWord encode_pointer_as_mark(void* p) { return from_pointer(p).set_marked(); }
260
261 // Recover address of oop from encoded form used in mark
262 inline void* decode_pointer() const { return (void*)clear_lock_bits().value(); }
263
264 inline bool is_self_forwarded() const {
265 return mask_bits(value(), self_fwd_mask_in_place) != 0;
266 }
267
268 inline markWord set_self_forwarded() const {
269 return markWord(value() | self_fwd_mask_in_place);
270 }
271
272 inline markWord unset_self_forwarded() const {
273 return markWord(value() & ~self_fwd_mask_in_place);
274 }
275
276 inline oop forwardee() const {
277 return cast_to_oop(decode_pointer());
278 }
279 };
280
281 // Support atomic operations.
282 template<>
283 struct PrimitiveConversions::Translate<markWord> : public std::true_type {
284 typedef markWord Value;
285 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
79 class BasicLock;
80 class ObjectMonitor;
81 class JavaThread;
82 class outputStream;
83
84 class markWord {
85 private:
86 uintptr_t _value;
87
88 public:
89 explicit markWord(uintptr_t value) : _value(value) {}
95 ~markWord() = default;
96 markWord(const markWord&) = default;
97 markWord& operator=(const markWord&) = default;
98
99 static markWord from_pointer(void* ptr) {
100 return markWord((uintptr_t)ptr);
101 }
102 void* to_pointer() const {
103 return (void*)_value;
104 }
105
106 bool operator==(const markWord& other) const {
107 return _value == other._value;
108 }
109 bool operator!=(const markWord& other) const {
110 return !operator==(other);
111 }
112
113 // Conversion
114 uintptr_t value() const { return _value; }
115 uint32_t value32() const { return (uint32_t)_value; }
116
117 // Constants
118 static const int age_bits = 4;
119 static const int lock_bits = 2;
120 static const int self_fwd_bits = 1;
121 static const int max_hash_bits = BitsPerWord - age_bits - lock_bits - self_fwd_bits;
122 static const int hash_bits = max_hash_bits > 31 ? 31 : max_hash_bits;
123 static const int unused_gap_bits = LP64_ONLY(4) NOT_LP64(0); // Reserved for Valhalla.
124 static const int hashctrl_bits = 2;
125
126 static const int lock_shift = 0;
127 static const int self_fwd_shift = lock_shift + lock_bits;
128 static const int age_shift = self_fwd_shift + self_fwd_bits;
129 static const int hash_shift = age_shift + age_bits + unused_gap_bits;
130 static const int hashctrl_shift = age_shift + age_bits + unused_gap_bits;
131
132 static const uintptr_t lock_mask = right_n_bits(lock_bits);
133 static const uintptr_t lock_mask_in_place = lock_mask << lock_shift;
134 static const uintptr_t self_fwd_mask = right_n_bits(self_fwd_bits);
135 static const uintptr_t self_fwd_mask_in_place = self_fwd_mask << self_fwd_shift;
136 static const uintptr_t age_mask = right_n_bits(age_bits);
137 static const uintptr_t age_mask_in_place = age_mask << age_shift;
138 static const uintptr_t hash_mask = right_n_bits(hash_bits);
139 static const uintptr_t hash_mask_in_place = hash_mask << hash_shift;
140 static const uintptr_t hashctrl_mask = right_n_bits(hashctrl_bits);
141 static const uintptr_t hashctrl_mask_in_place = hashctrl_mask << hashctrl_shift;
142 static const uintptr_t hashctrl_hashed_mask_in_place = ((uintptr_t)1) << hashctrl_shift;
143 static const uintptr_t hashctrl_expanded_mask_in_place = ((uintptr_t)2) << hashctrl_shift;
144
145 #ifdef _LP64
146 // Used only with compact headers:
147 // With UseCompactObjectHeaders: We store the (narrow) Klass* in bits 13-31 (19 bits total).
148 // Without UseCompactObjectHeaders: Klass* is stored separately in object header, not in markword.
149
150 // These are for bit-precise extraction of the narrow Klass* from the markword (UseCompactObjectHeaders only)
151 //
152 // Bit position summary for UseCompactObjectHeaders:
153 // Bits 0- 1: lock (2 bits)
154 // Bit 2 : self-fwd (1 bit)
155 // Bits 3- 6: age (4 bits)
156 // Bits 7-10: unused_gap (4 bits)
157 // Bits 11-12: hashctrl (2 bits) - hash control state
158 // Bits 13-31: klass (19 bits) - narrow klass pointer
159 // Bits 32-63: unused (32 bits)
160 //
161 // Without UseCompactObjectHeaders, klass is stored separately in object header
162 static constexpr int klass_shift = hashctrl_shift + hashctrl_bits;
163 static constexpr int klass_bits = 19;
164 static constexpr uintptr_t klass_mask = right_n_bits(klass_bits);
165 static constexpr uintptr_t klass_mask_in_place = klass_mask << klass_shift;
166 #endif
167
168
169 static const uintptr_t locked_value = 0;
170 static const uintptr_t unlocked_value = 1;
171 static const uintptr_t monitor_value = 2;
172 static const uintptr_t marked_value = 3;
173 static const uintptr_t forward_expanded_value = 0b111;
174
175 static const uintptr_t no_hash = 0 ; // no hash value assigned
176 static const uintptr_t no_hash_in_place = (uintptr_t)no_hash << hash_shift;
177 static const uintptr_t no_lock_in_place = unlocked_value;
178
179 static const uint max_age = age_mask;
180
181 // Creates a markWord with all bits set to zero.
182 static markWord zero() { return markWord(uintptr_t(0)); }
183
184 // lock accessors (note that these assume lock_shift == 0)
185 bool is_locked() const {
186 return (mask_bits(value(), lock_mask_in_place) != unlocked_value);
187 }
188 bool is_unlocked() const {
189 return (mask_bits(value(), lock_mask_in_place) == unlocked_value);
190 }
191 bool is_marked() const {
192 return (value() & (self_fwd_mask_in_place | lock_mask_in_place)) > monitor_value;
193 }
194 bool is_forwarded() const {
195 // Returns true for normal forwarded (0b011) and self-forwarded (0b1xx).
196 return mask_bits(value(), lock_mask_in_place | self_fwd_mask_in_place) >= static_cast<intptr_t>(marked_value);
197 }
198 bool is_neutral() const { // Not locked, or marked - a "clean" neutral state
199 return (mask_bits(value(), lock_mask_in_place) == unlocked_value);
200 }
201
202 markWord set_forward_expanded() {
203 assert((value() & (lock_mask_in_place | self_fwd_mask_in_place)) == marked_value, "must be normal-forwarded here");
204 return markWord(value() | forward_expanded_value);
205 }
206 bool is_forward_expanded() {
207 return (value() & (lock_mask_in_place | self_fwd_mask_in_place)) == forward_expanded_value;
208 }
209
210 // Should this header be preserved during GC?
211 bool must_be_preserved() const {
212 return UseCompactObjectHeaders ? !is_unlocked() : (!is_unlocked() || !has_no_hash());
213 }
214
215 // WARNING: The following routines are used EXCLUSIVELY by
216 // synchronization functions. They are not really gc safe.
217 // They must get updated if markWord layout get changed.
218 markWord set_unlocked() const {
219 return markWord(value() | unlocked_value);
220 }
221
222 bool is_fast_locked() const {
223 return (value() & lock_mask_in_place) == locked_value;
224 }
225 markWord set_fast_locked() const {
226 // Clear the lock_mask_in_place bits to set locked_value:
227 return markWord(value() & ~lock_mask_in_place);
228 }
229
230 bool has_monitor() const {
231 return ((value() & lock_mask_in_place) == monitor_value);
232 }
237 assert(has_monitor(), "check");
238 assert(!UseObjectMonitorTable, "Locking with OM table does not use markWord for monitors");
239 // Use xor instead of &~ to provide one extra tag-bit check.
240 return (ObjectMonitor*) (value() ^ monitor_value);
241 }
242
243 static markWord encode(ObjectMonitor* monitor) {
244 assert(!UseObjectMonitorTable, "Locking with OM table does not use markWord for monitors");
245 uintptr_t tmp = (uintptr_t) monitor;
246 return markWord(tmp | monitor_value);
247 }
248
249 bool has_displaced_mark_helper() const {
250 intptr_t lockbits = value() & lock_mask_in_place;
251 return !UseObjectMonitorTable && lockbits == monitor_value;
252 }
253 markWord displaced_mark_helper() const;
254 void set_displaced_mark_helper(markWord m) const;
255
256 // used to encode pointers during GC
257 markWord clear_lock_bits() const { return markWord(value() & ~(lock_mask_in_place | self_fwd_mask_in_place)); }
258
259 // age operations
260 markWord set_marked() { return markWord((value() & ~lock_mask_in_place) | marked_value); }
261 markWord set_unmarked() { return markWord((value() & ~lock_mask_in_place) | unlocked_value); }
262
263 uint age() const { return (uint) mask_bits(value() >> age_shift, age_mask); }
264 markWord set_age(uint v) const {
265 assert((v & ~age_mask) == 0, "shouldn't overflow age field");
266 return markWord((value() & ~age_mask_in_place) | ((v & age_mask) << age_shift));
267 }
268 markWord incr_age() const { return age() == max_age ? markWord(_value) : set_age(age() + 1); }
269
270 // hash operations
271 intptr_t hash() const {
272 assert(!UseCompactObjectHeaders, "only without compact i-hash");
273 return mask_bits(value() >> hash_shift, hash_mask);
274 }
275
276 bool has_no_hash() const {
277 if (UseCompactObjectHeaders) {
278 return !is_hashed();
279 } else {
280 return hash() == no_hash;
281 }
282 }
283
284 inline bool is_hashed_not_expanded() const {
285 assert(UseCompactObjectHeaders, "only with compact i-hash");
286 return (value() & hashctrl_mask_in_place) == hashctrl_hashed_mask_in_place;
287 }
288 inline markWord set_hashed_not_expanded() const {
289 assert(UseCompactObjectHeaders, "only with compact i-hash");
290 return markWord((value() & ~hashctrl_mask_in_place) | hashctrl_hashed_mask_in_place);
291 }
292
293 inline bool is_hashed_expanded() const {
294 assert(UseCompactObjectHeaders, "only with compact i-hash");
295 return (value() & hashctrl_mask_in_place) == (hashctrl_hashed_mask_in_place | hashctrl_expanded_mask_in_place);
296 }
297 inline markWord set_hashed_expanded() const {
298 assert(UseCompactObjectHeaders, "only with compact i-hash");
299 return markWord((value() & ~hashctrl_mask_in_place) | (hashctrl_hashed_mask_in_place | hashctrl_expanded_mask_in_place));
300 }
301
302 // This is a special hashctrl state (11) that is only used
303 // during CDS archive dumping. There we allocate 'scratch mirrors' for
304 // each real mirror klass. We allocate those scratch mirrors
305 // in a pre-extended form, but without being hashed. When the
306 // real mirror gets hashed, then we turn the scratch mirror into
307 // hashed_moved state, otherwise we leave it in that special state
308 // which indicates that the archived copy will be allocated in the
309 // unhashed form.
310 inline bool is_not_hashed_expanded() const {
311 assert(UseCompactObjectHeaders, "only with compact i-hash");
312 return (value() & hashctrl_mask_in_place) == hashctrl_expanded_mask_in_place;
313 }
314 inline markWord set_not_hashed_expanded() const {
315 assert(UseCompactObjectHeaders, "only with compact i-hash");
316 return markWord((value() & ~hashctrl_mask_in_place) | hashctrl_expanded_mask_in_place);
317 }
318 inline markWord set_not_hashed_not_expanded() const {
319 assert(UseCompactObjectHeaders, "only with compact i-hash");
320 return markWord(value() & ~(hashctrl_mask_in_place | hashctrl_expanded_mask_in_place));
321 }
322 // Return true when object is either hashed_moved or not_hashed_moved.
323 inline bool is_expanded() const {
324 assert(UseCompactObjectHeaders, "only with compact i-hash");
325 return (value() & hashctrl_expanded_mask_in_place) != 0;
326 }
327 inline bool is_hashed() const {
328 assert(UseCompactObjectHeaders, "only with compact i-hash");
329 return (value() & hashctrl_hashed_mask_in_place) != 0;
330 }
331
332 inline markWord copy_hashctrl_from(markWord m) const {
333 if (UseCompactObjectHeaders) {
334 return markWord((value() & ~hashctrl_mask_in_place) | (m.value() & hashctrl_mask_in_place));
335 } else {
336 return markWord(value());
337 }
338 }
339
340 markWord copy_set_hash(intptr_t hash) const {
341 uintptr_t tmp = value() & (~hash_mask_in_place);
342 tmp |= ((hash & hash_mask) << hash_shift);
343 return markWord(tmp);
344 }
345
346 inline Klass* klass() const;
347 inline Klass* klass_or_null() const;
348 inline Klass* klass_without_asserts() const;
349 inline narrowKlass narrow_klass() const;
350 inline markWord set_narrow_klass(narrowKlass narrow_klass) const;
351
352 #ifdef _LP64
353 inline int array_length() { return checked_cast<int>(value() >> 32); }
354 #endif
355
356 // Prototype mark for initialization
357 static markWord prototype() {
358 if (UseCompactObjectHeaders) {
359 return markWord(no_lock_in_place);
360 } else {
361 return markWord(no_hash_in_place | no_lock_in_place);
362 }
363 }
364
365 // Debugging
366 void print_on(outputStream* st, bool print_monitor_info = true) const;
367
368 // Prepare address of oop for placement into mark
369 inline static markWord encode_pointer_as_mark(void* p) { return from_pointer(p).set_marked(); }
370
371 // Recover address of oop from encoded form used in mark
372 inline void* decode_pointer() const { return (void*)clear_lock_bits().value(); }
373
374 inline bool is_self_forwarded() const {
375 // Match 100, 101, 110 but not 111.
376 return mask_bits(value() + 1, (lock_mask_in_place | self_fwd_mask_in_place)) > 4;
377 }
378
379 inline markWord set_self_forwarded() const {
380 return markWord(value() | self_fwd_mask_in_place);
381 }
382
383 inline markWord unset_self_forwarded() const {
384 return markWord(value() & ~self_fwd_mask_in_place);
385 }
386
387 inline oop forwardee() const {
388 return cast_to_oop(decode_pointer());
389 }
390 };
391
392 // Support atomic operations.
393 template<>
394 struct PrimitiveConversions::Translate<markWord> : public std::true_type {
395 typedef markWord Value;
396 typedef uintptr_t Decayed;
|