< prev index next >

src/hotspot/share/oops/markWord.hpp

Print this page

 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_OOPS_MARKWORD_HPP
 26 #define SHARE_OOPS_MARKWORD_HPP
 27 
 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;
 75 
 76 class markWord {
 77  private:
 78   uintptr_t _value;
 79 
 80  public:
 81   explicit markWord(uintptr_t value) : _value(value) {}
 82 
 83   markWord() = default;         // Doesn't initialize _value.
 84 
 85   // It is critical for performance that this class be trivially
 86   // destructable, copyable, and assignable.
 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   }

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<>

 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_OOPS_MARKWORD_HPP
 26 #define SHARE_OOPS_MARKWORD_HPP
 27 
 28 #include "cppstdlib/type_traits.hpp"
 29 #include "metaprogramming/primitiveConversions.hpp"
 30 #include "oops/compressedKlass.hpp"
 31 #include "oops/layoutKind.hpp"
 32 #include "oops/oopsHierarchy.hpp"
 33 #include "runtime/globals.hpp"
 34 #include "utilities/vmEnums.hpp"
 35 
 36 // The markWord describes the header of an object.
 37 //
 38 // Bit-format of an object header (most significant first, big endian layout below):
 39 //
 40 //  32 bits:
 41 //  --------
 42 //             hash:25 ------------>| age:4  self-fwd:1  lock:2 (normal object)
 43 //
 44 //  64 bits:
 45 //  --------
 46 //  unused:22 hash:31 -->| valhalla:4  age:4  self-fwd:1  lock:2 (normal object)
 47 //
 48 //  64 bits (with compact headers):
 49 //  -------------------------------
 50 //  klass:22  hash:31 -->| valhalla:4  age:4  self-fwd:1  lock:2 (normal object)
 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 //  - the two lock bits are used to describe three states: locked/unlocked and monitor.
 58 //
 59 //    [ptr             | 00]  locked             ptr points to real header on stack (stack-locking in use)
 60 //    [header          | 00]  locked             locked regular object header (fast-locking in use)
 61 //    [header          | 01]  unlocked           regular object header
 62 //    [ptr             | 10]  monitor            inflated lock (header is swapped out, UseObjectMonitorTable == false)
 63 //    [header          | 10]  monitor            inflated lock (UseObjectMonitorTable == true)
 64 //    [ptr             | 11]  marked             used to mark an object
 65 //    [0 ............ 0| 00]  inflating          inflation in progress (stack-locking in use)
 66 //
 67 //    We assume that stack/thread pointers have the lowest two bits cleared.
 68 //
 69 //
 70 //  - INFLATING() is a distinguished markword value of all zeros that is
 71 //    used when inflating an existing stack-lock into an ObjectMonitor.
 72 //    See below for is_being_inflated() and INFLATING().
 73 //
 74 //  VALHALLA EXTENSIONS:
 75 //
 76 //  N.B.: 32 bit mode is not supported, this section assumes 64 bit systems.
 77 //
 78 //  Project Valhalla uses markWord bits to denote the following oops (listed least to most significant):
 79 //  * inline types: have alternative bytecode behavior, e.g. can not be locked
 80 //  * flat arrays: load/decode of klass layout helper is expensive for aaload
 81 //  * "null free" arrays: load/decode of klass layout helper again for aaload
 82 //  * inline type: "larval state": mutable state, but only during object init, observable
 83 //      by only by a single thread (generally do not mutate markWord)
 84 //
 85 //  Inline types cannot be locked, monitored or inflating.
 86 //
 87 //  Note the position of 'self-fwd' is not by accident. When forwarding an
 88 //  object to a new heap position, HeapWord alignment guarantees the lower
 89 //  bits, including 'self-fwd' are 0. "is_self_forwarded()" will be correctly
 90 //  set to false. Otherwise encode_pointer_as_mark() may have 'self-fwd' set.
 91 
 92 class BasicLock;
 93 class ObjectMonitor;
 94 class JavaThread;
 95 class outputStream;
 96 
 97 class markWord {
 98  private:
 99   uintptr_t _value;
100 
101  public:
102   explicit markWord(uintptr_t value) : _value(value) {}
103 
104   markWord() = default;         // Doesn't initialize _value.
105 
106   // It is critical for performance that this class be trivially
107   // destructable, copyable, and assignable.
108   ~markWord() = default;
109   markWord(const markWord&) = default;
110   markWord& operator=(const markWord&) = default;
111 
112   static markWord from_pointer(void* ptr) {
113     return markWord((uintptr_t)ptr);
114   }
115   void* to_pointer() const {
116     return (void*)_value;
117   }
118 
119   bool operator==(const markWord& other) const {
120     return _value == other._value;
121   }
122   bool operator!=(const markWord& other) const {
123     return !operator==(other);
124   }
125 
126   // Conversion
127   uintptr_t value() const { return _value; }
128 
129   // Constants, in least significant bit order

130   static const int lock_bits                      = 2;
131   static const int self_fwd_bits                  = 1;
132   // instance state
133   static const int age_bits                       = 4;
134   // EnableValhalla: static prototype header bits (fast path instead of klass layout_helper)
135   static const int inline_type_bits               = 1;
136   static const int null_free_array_bits           = LP64_ONLY(1) NOT_LP64(0);
137   static const int flat_array_bits                = LP64_ONLY(1) NOT_LP64(0);
138   static const int larval_bits                    = 1;
139   static const int max_hash_bits                  = BitsPerWord - age_bits - lock_bits - inline_type_bits - larval_bits - flat_array_bits - null_free_array_bits - self_fwd_bits;
140   static const int hash_bits                      = max_hash_bits > 31 ? 31 : max_hash_bits;

141 
142   static const int lock_shift                     = 0;
143   static const int self_fwd_shift                 = lock_shift + lock_bits;
144   static const int age_shift                      = self_fwd_shift + self_fwd_bits;
145   static const int inline_type_shift              = age_shift + age_bits;
146   static const int null_free_array_shift          = inline_type_shift + inline_type_bits;
147   static const int flat_array_shift               = null_free_array_shift + null_free_array_bits;
148   static const int larval_shift                   = flat_array_shift + flat_array_bits;
149   static const int hash_shift                     = larval_shift + larval_bits;
150 
151   static const uintptr_t lock_mask                = right_n_bits(lock_bits);
152   static const uintptr_t lock_mask_in_place       = lock_mask << lock_shift;
153   static const uintptr_t self_fwd_mask            = right_n_bits(self_fwd_bits);
154   static const uintptr_t self_fwd_mask_in_place   = self_fwd_mask << self_fwd_shift;
155   static const uintptr_t inline_type_bit_in_place = right_n_bits(inline_type_bits) << inline_type_shift;
156   static const uintptr_t inline_type_mask_in_place = inline_type_bit_in_place + lock_mask;
157   static const uintptr_t null_free_array_mask     = right_n_bits(null_free_array_bits);
158   static const uintptr_t null_free_array_mask_in_place = (null_free_array_mask << null_free_array_shift) | lock_mask_in_place;
159   static const uintptr_t null_free_array_bit_in_place  = (right_n_bits(null_free_array_bits) << null_free_array_shift);
160   static const uintptr_t flat_array_mask          = right_n_bits(flat_array_bits);
161   static const uintptr_t flat_array_mask_in_place = (flat_array_mask << flat_array_shift) | null_free_array_mask_in_place | lock_mask_in_place;
162   static const uintptr_t flat_array_bit_in_place  = right_n_bits(flat_array_bits) << flat_array_shift;
163   static const uintptr_t age_mask                 = right_n_bits(age_bits);
164   static const uintptr_t age_mask_in_place        = age_mask << age_shift;
165 
166   static const uintptr_t larval_mask              = right_n_bits(larval_bits);
167   static const uintptr_t larval_mask_in_place     = (larval_mask << larval_shift) | inline_type_mask_in_place;
168   static const uintptr_t larval_bit_in_place      = right_n_bits(larval_bits) << larval_shift;
169 
170   static const uintptr_t hash_mask                = right_n_bits(hash_bits);
171   static const uintptr_t hash_mask_in_place       = hash_mask << hash_shift;
172 
173 #ifdef _LP64
174   // Used only with compact headers:
175   // We store the (narrow) Klass* in the bits 43 to 64.
176 
177   // These are for bit-precise extraction of the narrow Klass* from the 64-bit Markword
178   static constexpr int klass_offset_in_bytes      = 4;
179   static constexpr int klass_shift                = hash_shift + hash_bits;
180   static constexpr int klass_shift_at_offset      = klass_shift - klass_offset_in_bytes * BitsPerByte;
181   static constexpr int klass_bits                 = 22;
182   static constexpr uintptr_t klass_mask           = right_n_bits(klass_bits);
183   static constexpr uintptr_t klass_mask_in_place  = klass_mask << klass_shift;
184 #endif
185 
186 
187   static const uintptr_t locked_value             = 0;
188   static const uintptr_t unlocked_value           = 1;
189   static const uintptr_t monitor_value            = 2;
190   static const uintptr_t marked_value             = 3;
191 
192   static const uintptr_t inline_type_pattern      = inline_type_bit_in_place | unlocked_value;
193   static const uintptr_t null_free_array_pattern  = null_free_array_bit_in_place | unlocked_value;
194   static const uintptr_t null_free_flat_array_pattern = flat_array_bit_in_place | null_free_array_pattern;
195   static const uintptr_t nullable_flat_array_pattern = flat_array_bit_in_place | unlocked_value;
196 
197   static const uintptr_t larval_pattern           = larval_bit_in_place | inline_type_pattern;
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   bool is_inline_type() const {
209     return (mask_bits(value(), inline_type_mask_in_place) == inline_type_pattern);
210   }
211 
212   // lock accessors (note that these assume lock_shift == 0)
213   bool is_locked()   const {
214     return (mask_bits(value(), lock_mask_in_place) != unlocked_value);
215   }
216   bool is_unlocked() const {
217     return (mask_bits(value(), lock_mask_in_place) == unlocked_value);
218   }
219   bool is_marked()   const {
220     return (mask_bits(value(), lock_mask_in_place) == marked_value);
221   }
222 
223   // is unlocked and not an inline type (which cannot be involved in locking, displacement or inflation)
224   // i.e. test both lock bits and the inline type bit together
225   bool is_neutral()  const {  // Not locked, or marked - a "clean" neutral state
226     return (mask_bits(value(), inline_type_mask_in_place) == unlocked_value);
227   }
228 
229   bool is_forwarded() const {
230     // Returns true for normal forwarded (0b011) and self-forwarded (0b1xx).
231     return mask_bits(value(), lock_mask_in_place | self_fwd_mask_in_place) >= static_cast<intptr_t>(marked_value);
232   }



233 
234   // Special temporary state of the markWord while being inflated.
235   // Code that looks at mark outside a lock need to take this into account.
236   bool is_being_inflated() const { return (value() == 0); }
237 
238   // Distinguished markword value - used when inflating over
239   // an existing stack-lock.  0 indicates the markword is "BUSY".
240   // Lockword mutators that use a LD...CAS idiom should always
241   // check for and avoid overwriting a 0 value installed by some
242   // other thread.  (They should spin or block instead.  The 0 value
243   // is transient and *should* be short-lived).
244   // Fast-locking does not use INFLATING.
245   static markWord INFLATING() { return zero(); }    // inflate-in-progress
246 
247   // Should this header be preserved during GC?
248   bool must_be_preserved() const {
249     return (!is_unlocked() || !has_no_hash() ||
250       (EnableValhalla && (is_larval_state() || is_inline_type() || is_flat_array() || is_null_free_array())));
251   }
252 
253   // WARNING: The following routines are used EXCLUSIVELY by
254   // synchronization functions. They are not really gc safe.
255   // They must get updated if markWord layout get changed.
256   markWord set_unlocked() const {
257     return markWord(value() | unlocked_value);
258   }
259 
260   bool is_fast_locked() const {
261     return (value() & lock_mask_in_place) == locked_value;
262   }
263   markWord set_fast_locked() const {
264     // Clear the lock_mask_in_place bits to set locked_value:
265     return markWord(value() & ~lock_mask_in_place);
266   }
267 
268   bool has_monitor() const {
269     return ((value() & lock_mask_in_place) == monitor_value);
270   }

311   // age operations
312   markWord set_marked()   { return markWord((value() & ~lock_mask_in_place) | marked_value); }
313   markWord set_unmarked() { return markWord((value() & ~lock_mask_in_place) | unlocked_value); }
314 
315   uint     age()           const { return (uint) mask_bits(value() >> age_shift, age_mask); }
316   markWord set_age(uint v) const {
317     assert((v & ~age_mask) == 0, "shouldn't overflow age field");
318     return markWord((value() & ~age_mask_in_place) | ((v & age_mask) << age_shift));
319   }
320   markWord incr_age()      const { return age() == max_age ? markWord(_value) : set_age(age() + 1); }
321 
322   // hash operations
323   intptr_t hash() const {
324     return mask_bits(value() >> hash_shift, hash_mask);
325   }
326 
327   bool has_no_hash() const {
328     return hash() == no_hash;
329   }
330 
331   // private buffered value operations
332   markWord enter_larval_state() const {
333     return markWord(value() | larval_bit_in_place);
334   }
335   markWord exit_larval_state() const {
336     return markWord(value() & ~larval_bit_in_place);
337   }
338   bool is_larval_state() const {
339     return (mask_bits(value(), larval_mask_in_place) == larval_pattern);
340   }
341 
342   bool is_flat_array() const {
343 #ifdef _LP64 // 64 bit encodings only
344     return (mask_bits(value(), flat_array_mask_in_place) == null_free_flat_array_pattern)
345            || (mask_bits(value(), flat_array_mask_in_place) == nullable_flat_array_pattern);
346 #else
347     return false;
348 #endif
349   }
350 
351   bool is_null_free_array() const {
352 #ifdef _LP64 // 64 bit encodings only
353     return (mask_bits(value(), null_free_array_mask_in_place) == null_free_array_pattern);
354 #else
355     return false;
356 #endif
357   }
358 
359   inline Klass* klass() const;
360   inline Klass* klass_or_null() const;
361   inline Klass* klass_without_asserts() const;
362   inline narrowKlass narrow_klass() const;
363   inline markWord set_narrow_klass(narrowKlass narrow_klass) const;
364 
365   // Prototype mark for initialization
366   static markWord prototype() {
367     return markWord( no_hash_in_place | no_lock_in_place );
368   }
369 
370   static markWord inline_type_prototype() {
371     return markWord(inline_type_pattern);
372   }
373 
374 #ifdef _LP64 // 64 bit encodings only
375   static markWord flat_array_prototype(LayoutKind lk);
376 
377   static markWord null_free_array_prototype() {
378     return markWord(null_free_array_pattern);
379   }
380 #endif
381 
382   // Debugging
383   void print_on(outputStream* st, bool print_monitor_info = true) const;
384 
385   // Prepare address of oop for placement into mark
386   inline static markWord encode_pointer_as_mark(void* p) { return from_pointer(p).set_marked(); }
387 
388   inline void* decode_pointer() const {
389     return (void*) (clear_lock_bits().value());
390   }
391 
392   inline bool is_self_forwarded() const {
393     return mask_bits(value(), self_fwd_mask_in_place) != 0;
394   }
395 
396   inline markWord set_self_forwarded() const {
397     return markWord(value() | self_fwd_mask_in_place);
398   }
399 
400   inline markWord unset_self_forwarded() const {
401     return markWord(value() & ~self_fwd_mask_in_place);
402   }
403 
404   inline oop forwardee() const {
405     return cast_to_oop(decode_pointer());
406   }
407 };
408 
409 // Support atomic operations.
410 template<>
< prev index next >