< prev index next >

src/hotspot/share/oops/markWord.hpp

Print this page

 23  */
 24 
 25 #ifndef SHARE_OOPS_MARKWORD_HPP
 26 #define SHARE_OOPS_MARKWORD_HPP
 27 
 28 #include "metaprogramming/integralConstant.hpp"
 29 #include "metaprogramming/primitiveConversions.hpp"
 30 #include "oops/oopsHierarchy.hpp"
 31 #include "runtime/globals.hpp"
 32 
 33 // The markWord describes the header of an object.
 34 //
 35 // Bit-format of an object header (most significant first, big endian layout below):
 36 //
 37 //  32 bits:
 38 //  --------
 39 //             hash:25 ------------>| age:4  unused_gap:1  lock:2 (normal object)
 40 //
 41 //  64 bits:
 42 //  --------
 43 //  unused:25 hash:31 -->| unused_gap:1  age:4  unused_gap:1  lock:2 (normal object)
 44 //
 45 //  - hash contains the identity hash value: largest value is
 46 //    31 bits, see os::random().  Also, 64-bit vm's require
 47 //    a hash value no bigger than 32 bits because they will not
 48 //    properly generate a mask larger than that: see library_call.cpp
 49 //
 50 //  - the two lock bits are used to describe three states: locked/unlocked and monitor.
 51 //
 52 //    [ptr             | 00]  locked             ptr points to real header on stack
 53 //    [header          | 01]  unlocked           regular object header
 54 //    [ptr             | 10]  monitor            inflated lock (header is wapped out)
 55 //    [ptr             | 11]  marked             used to mark an object
 56 //    [0 ............ 0| 00]  inflating          inflation in progress
 57 //
 58 //    We assume that stack/thread pointers have the lowest two bits cleared.
 59 //
 60 //  - INFLATING() is a distinguished markword value of all zeros that is
 61 //    used when inflating an existing stack-lock into an ObjectMonitor.
 62 //    See below for is_being_inflated() and INFLATING().
 63 

 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 first_unused_gap_bits          = 1;
105   static const int max_hash_bits                  = BitsPerWord - age_bits - lock_bits - first_unused_gap_bits;
106   static const int hash_bits                      = max_hash_bits > 31 ? 31 : max_hash_bits;
107   static const int second_unused_gap_bits         = LP64_ONLY(1) NOT_LP64(0);


108 
109   static const int lock_shift                     = 0;
110   static const int age_shift                      = lock_bits + first_unused_gap_bits;
111   static const int hash_shift                     = age_shift + age_bits + second_unused_gap_bits;




112 
113   static const uintptr_t lock_mask                = right_n_bits(lock_bits);
114   static const uintptr_t lock_mask_in_place       = lock_mask << lock_shift;


115   static const uintptr_t age_mask                 = right_n_bits(age_bits);
116   static const uintptr_t age_mask_in_place        = age_mask << age_shift;
117   static const uintptr_t hash_mask                = right_n_bits(hash_bits);
118   static const uintptr_t hash_mask_in_place       = hash_mask << hash_shift;
119 





120   static const uintptr_t locked_value             = 0;
121   static const uintptr_t unlocked_value           = 1;
122   static const uintptr_t monitor_value            = 2;
123   static const uintptr_t marked_value             = 3;
124 
125   static const uintptr_t no_hash                  = 0 ;  // no hash value assigned
126   static const uintptr_t no_hash_in_place         = (address_word)no_hash << hash_shift;
127   static const uintptr_t no_lock_in_place         = unlocked_value;
128 
129   static const uint max_age                       = age_mask;
130 
131   // Creates a markWord with all bits set to zero.
132   static markWord zero() { return markWord(uintptr_t(0)); }
133 
134   // lock accessors (note that these assume lock_shift == 0)
135   bool is_locked()   const {
136     return (mask_bits(value(), lock_mask_in_place) != unlocked_value);
137   }
138   bool is_unlocked() const {
139     return (mask_bits(value(), lock_mask_in_place) == unlocked_value);

214   // age operations
215   markWord set_marked()   { return markWord((value() & ~lock_mask_in_place) | marked_value); }
216   markWord set_unmarked() { return markWord((value() & ~lock_mask_in_place) | unlocked_value); }
217 
218   uint     age()           const { return mask_bits(value() >> age_shift, age_mask); }
219   markWord set_age(uint v) const {
220     assert((v & ~age_mask) == 0, "shouldn't overflow age field");
221     return markWord((value() & ~age_mask_in_place) | ((v & age_mask) << age_shift));
222   }
223   markWord incr_age()      const { return age() == max_age ? markWord(_value) : set_age(age() + 1); }
224 
225   // hash operations
226   intptr_t hash() const {
227     return mask_bits(value() >> hash_shift, hash_mask);
228   }
229 
230   bool has_no_hash() const {
231     return hash() == no_hash;
232   }
233 









234   // Prototype mark for initialization
235   static markWord prototype() {
236     return markWord( no_hash_in_place | no_lock_in_place );
237   }
238 
239   // Debugging
240   void print_on(outputStream* st, bool print_monitor_info = true) const;
241 
242   // Prepare address of oop for placement into mark
243   inline static markWord encode_pointer_as_mark(void* p) { return from_pointer(p).set_marked(); }
244 
245   // Recover address of oop from encoded form used in mark
246   inline void* decode_pointer() { return (void*)clear_lock_bits().value(); }








247 };
248 
249 // Support atomic operations.
250 template<>
251 struct PrimitiveConversions::Translate<markWord> : public TrueType {
252   typedef markWord Value;
253   typedef uintptr_t Decayed;
254 
255   static Decayed decay(const Value& x) { return x.value(); }
256   static Value recover(Decayed x) { return Value(x); }
257 };
258 
259 #endif // SHARE_OOPS_MARKWORD_HPP

 23  */
 24 
 25 #ifndef SHARE_OOPS_MARKWORD_HPP
 26 #define SHARE_OOPS_MARKWORD_HPP
 27 
 28 #include "metaprogramming/integralConstant.hpp"
 29 #include "metaprogramming/primitiveConversions.hpp"
 30 #include "oops/oopsHierarchy.hpp"
 31 #include "runtime/globals.hpp"
 32 
 33 // The markWord describes the header of an object.
 34 //
 35 // Bit-format of an object header (most significant first, big endian layout below):
 36 //
 37 //  32 bits:
 38 //  --------
 39 //             hash:25 ------------>| age:4  unused_gap:1  lock:2 (normal object)
 40 //
 41 //  64 bits:
 42 //  --------
 43 //  nklass:32 hash:25 -->| unused_gap:1  age:4  unused_gap:1  lock:2 (normal object)
 44 //
 45 //  - hash contains the identity hash value: largest value is
 46 //    31 bits, see os::random().  Also, 64-bit vm's require
 47 //    a hash value no bigger than 32 bits because they will not
 48 //    properly generate a mask larger than that: see library_call.cpp
 49 //
 50 //  - the two lock bits are used to describe three states: locked/unlocked and monitor.
 51 //
 52 //    [ptr             | 00]  locked             ptr points to real header on stack
 53 //    [header          | 01]  unlocked           regular object header
 54 //    [ptr             | 10]  monitor            inflated lock (header is wapped out)
 55 //    [ptr             | 11]  marked             used to mark an object
 56 //    [0 ............ 0| 00]  inflating          inflation in progress
 57 //
 58 //    We assume that stack/thread pointers have the lowest two bits cleared.
 59 //
 60 //  - INFLATING() is a distinguished markword value of all zeros that is
 61 //    used when inflating an existing stack-lock into an ObjectMonitor.
 62 //    See below for is_being_inflated() and INFLATING().
 63 

 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_forwarded_bits            = 1;
105   static const int max_hash_bits                  = BitsPerWord - age_bits - lock_bits - self_forwarded_bits;
106   static const int hash_bits                      = max_hash_bits > 25 ? 25 : max_hash_bits;
107 #ifdef _LP64
108   static const int klass_bits                     = 32;
109 #endif
110 
111   static const int lock_shift                     = 0;
112   static const int self_forwarded_shift           = lock_shift + lock_bits;
113   static const int age_shift                      = self_forwarded_shift + self_forwarded_bits;
114   static const int hash_shift                     = age_shift + age_bits;
115 #ifdef _LP64
116   static const int klass_shift                    = hash_shift + hash_bits;
117 #endif
118 
119   static const uintptr_t lock_mask                = right_n_bits(lock_bits);
120   static const uintptr_t lock_mask_in_place       = lock_mask << lock_shift;
121   static const uintptr_t self_forwarded_mask      = right_n_bits(self_forwarded_bits);
122   static const uintptr_t self_forwarded_mask_in_place = self_forwarded_mask << self_forwarded_shift;
123   static const uintptr_t age_mask                 = right_n_bits(age_bits);
124   static const uintptr_t age_mask_in_place        = age_mask << age_shift;
125   static const uintptr_t hash_mask                = right_n_bits(hash_bits);
126   static const uintptr_t hash_mask_in_place       = hash_mask << hash_shift;
127 
128 #ifdef _LP64
129   static const uintptr_t klass_mask               = right_n_bits(klass_bits);
130   static const uintptr_t klass_mask_in_place      = klass_mask << klass_shift;
131 #endif
132 
133   static const uintptr_t locked_value             = 0;
134   static const uintptr_t unlocked_value           = 1;
135   static const uintptr_t monitor_value            = 2;
136   static const uintptr_t marked_value             = 3;
137 
138   static const uintptr_t no_hash                  = 0 ;  // no hash value assigned
139   static const uintptr_t no_hash_in_place         = (address_word)no_hash << hash_shift;
140   static const uintptr_t no_lock_in_place         = unlocked_value;
141 
142   static const uint max_age                       = age_mask;
143 
144   // Creates a markWord with all bits set to zero.
145   static markWord zero() { return markWord(uintptr_t(0)); }
146 
147   // lock accessors (note that these assume lock_shift == 0)
148   bool is_locked()   const {
149     return (mask_bits(value(), lock_mask_in_place) != unlocked_value);
150   }
151   bool is_unlocked() const {
152     return (mask_bits(value(), lock_mask_in_place) == unlocked_value);

227   // age operations
228   markWord set_marked()   { return markWord((value() & ~lock_mask_in_place) | marked_value); }
229   markWord set_unmarked() { return markWord((value() & ~lock_mask_in_place) | unlocked_value); }
230 
231   uint     age()           const { return mask_bits(value() >> age_shift, age_mask); }
232   markWord set_age(uint v) const {
233     assert((v & ~age_mask) == 0, "shouldn't overflow age field");
234     return markWord((value() & ~age_mask_in_place) | ((v & age_mask) << age_shift));
235   }
236   markWord incr_age()      const { return age() == max_age ? markWord(_value) : set_age(age() + 1); }
237 
238   // hash operations
239   intptr_t hash() const {
240     return mask_bits(value() >> hash_shift, hash_mask);
241   }
242 
243   bool has_no_hash() const {
244     return hash() == no_hash;
245   }
246 
247 #ifdef _LP64
248   inline Klass* klass() const;
249   inline Klass* klass_or_null() const;
250   inline Klass* safe_klass() const;
251   inline markWord set_klass(const Klass* klass) const;
252   inline narrowKlass narrow_klass() const;
253   inline markWord set_narrow_klass(const narrowKlass klass) const;
254 #endif
255 
256   // Prototype mark for initialization
257   static markWord prototype() {
258     return markWord( no_hash_in_place | no_lock_in_place );
259   }
260 
261   // Debugging
262   void print_on(outputStream* st, bool print_monitor_info = true) const;
263 
264   // Prepare address of oop for placement into mark
265   inline static markWord encode_pointer_as_mark(void* p) { return from_pointer(p).set_marked(); }
266 
267   // Recover address of oop from encoded form used in mark
268   inline void* decode_pointer() { return (void*)clear_lock_bits().value(); }
269 
270   inline bool self_forwarded() const {
271     return mask_bits(value(), self_forwarded_mask_in_place) != 0;
272   }
273 
274   inline markWord set_self_forwarded() const {
275     return markWord(value() | self_forwarded_mask_in_place | marked_value);
276   }
277 };
278 
279 // Support atomic operations.
280 template<>
281 struct PrimitiveConversions::Translate<markWord> : public TrueType {
282   typedef markWord Value;
283   typedef uintptr_t Decayed;
284 
285   static Decayed decay(const Value& x) { return x.value(); }
286   static Value recover(Decayed x) { return Value(x); }
287 };
288 
289 #endif // SHARE_OOPS_MARKWORD_HPP
< prev index next >