36 // |
36 // |
37 // 32 bits: |
37 // 32 bits: |
38 // -------- |
38 // -------- |
39 // hash:25 ------------>| age:4 biased_lock:1 lock:2 (normal object) |
39 // hash:25 ------------>| age:4 biased_lock:1 lock:2 (normal object) |
40 // JavaThread*:23 epoch:2 age:4 biased_lock:1 lock:2 (biased object) |
40 // JavaThread*:23 epoch:2 age:4 biased_lock:1 lock:2 (biased object) |
41 // size:32 ------------------------------------------>| (CMS free block) |
|
42 // PromotedObject*:29 ---------->| promo_bits:3 ----->| (CMS promoted object) |
|
43 // |
41 // |
44 // 64 bits: |
42 // 64 bits: |
45 // -------- |
43 // -------- |
46 // unused:25 hash:31 -->| unused:1 age:4 biased_lock:1 lock:2 (normal object) |
44 // unused:25 hash:31 -->| unused_gap:1 age:4 biased_lock:1 lock:2 (normal object) |
47 // JavaThread*:54 epoch:2 unused:1 age:4 biased_lock:1 lock:2 (biased object) |
45 // JavaThread*:54 epoch:2 unused_gap:1 age:4 biased_lock:1 lock:2 (biased object) |
48 // PromotedObject*:61 --------------------->| promo_bits:3 ----->| (CMS promoted object) |
|
49 // size:64 ----------------------------------------------------->| (CMS free block) |
|
50 // |
|
51 // unused:25 hash:31 -->| cms_free:1 age:4 biased_lock:1 lock:2 (COOPs && normal object) |
|
52 // JavaThread*:54 epoch:2 cms_free:1 age:4 biased_lock:1 lock:2 (COOPs && biased object) |
|
53 // narrowOop:32 unused:24 cms_free:1 unused:4 promo_bits:3 ----->| (COOPs && CMS promoted object) |
|
54 // unused:21 size:35 -->| cms_free:1 unused:7 ------------------>| (COOPs && CMS free block) |
|
55 // |
46 // |
56 // - hash contains the identity hash value: largest value is |
47 // - hash contains the identity hash value: largest value is |
57 // 31 bits, see os::random(). Also, 64-bit vm's require |
48 // 31 bits, see os::random(). Also, 64-bit vm's require |
58 // a hash value no bigger than 32 bits because they will not |
49 // a hash value no bigger than 32 bits because they will not |
59 // properly generate a mask larger than that: see library_call.cpp |
50 // properly generate a mask larger than that: see library_call.cpp |
80 // significant fraction of the eden semispaces and were not |
71 // significant fraction of the eden semispaces and were not |
81 // promoted promptly, causing an increase in the amount of copying |
72 // promoted promptly, causing an increase in the amount of copying |
82 // performed. The runtime system aligns all JavaThread* pointers to |
73 // performed. The runtime system aligns all JavaThread* pointers to |
83 // a very large value (currently 128 bytes (32bVM) or 256 bytes (64bVM)) |
74 // a very large value (currently 128 bytes (32bVM) or 256 bytes (64bVM)) |
84 // to make room for the age bits & the epoch bits (used in support of |
75 // to make room for the age bits & the epoch bits (used in support of |
85 // biased locking), and for the CMS "freeness" bit in the 64bVM (+COOPs). |
76 // biased locking). |
86 // |
77 // |
87 // [JavaThread* | epoch | age | 1 | 01] lock is biased toward given thread |
78 // [JavaThread* | epoch | age | 1 | 01] lock is biased toward given thread |
88 // [0 | epoch | age | 1 | 01] lock is anonymously biased |
79 // [0 | epoch | age | 1 | 01] lock is anonymously biased |
89 // |
80 // |
90 // - the two lock bits are used to describe three states: locked/unlocked and monitor. |
81 // - the two lock bits are used to describe three states: locked/unlocked and monitor. |
134 static const int age_bits = 4; |
125 static const int age_bits = 4; |
135 static const int lock_bits = 2; |
126 static const int lock_bits = 2; |
136 static const int biased_lock_bits = 1; |
127 static const int biased_lock_bits = 1; |
137 static const int max_hash_bits = BitsPerWord - age_bits - lock_bits - biased_lock_bits; |
128 static const int max_hash_bits = BitsPerWord - age_bits - lock_bits - biased_lock_bits; |
138 static const int hash_bits = max_hash_bits > 31 ? 31 : max_hash_bits; |
129 static const int hash_bits = max_hash_bits > 31 ? 31 : max_hash_bits; |
139 static const int cms_bits = LP64_ONLY(1) NOT_LP64(0); |
130 static const int unused_gap_bits = LP64_ONLY(1) NOT_LP64(0); |
140 static const int epoch_bits = 2; |
131 static const int epoch_bits = 2; |
141 |
132 |
142 // The biased locking code currently requires that the age bits be |
133 // The biased locking code currently requires that the age bits be |
143 // contiguous to the lock bits. |
134 // contiguous to the lock bits. |
144 static const int lock_shift = 0; |
135 static const int lock_shift = 0; |
145 static const int biased_lock_shift = lock_bits; |
136 static const int biased_lock_shift = lock_bits; |
146 static const int age_shift = lock_bits + biased_lock_bits; |
137 static const int age_shift = lock_bits + biased_lock_bits; |
147 static const int cms_shift = age_shift + age_bits; |
138 static const int unused_gap_shift = age_shift + age_bits; |
148 static const int hash_shift = cms_shift + cms_bits; |
139 static const int hash_shift = unused_gap_shift + unused_gap_bits; |
149 static const int epoch_shift = hash_shift; |
140 static const int epoch_shift = hash_shift; |
150 |
141 |
151 static const uintptr_t lock_mask = right_n_bits(lock_bits); |
142 static const uintptr_t lock_mask = right_n_bits(lock_bits); |
152 static const uintptr_t lock_mask_in_place = lock_mask << lock_shift; |
143 static const uintptr_t lock_mask_in_place = lock_mask << lock_shift; |
153 static const uintptr_t biased_lock_mask = right_n_bits(lock_bits + biased_lock_bits); |
144 static const uintptr_t biased_lock_mask = right_n_bits(lock_bits + biased_lock_bits); |
155 static const uintptr_t biased_lock_bit_in_place = 1 << biased_lock_shift; |
146 static const uintptr_t biased_lock_bit_in_place = 1 << biased_lock_shift; |
156 static const uintptr_t age_mask = right_n_bits(age_bits); |
147 static const uintptr_t age_mask = right_n_bits(age_bits); |
157 static const uintptr_t age_mask_in_place = age_mask << age_shift; |
148 static const uintptr_t age_mask_in_place = age_mask << age_shift; |
158 static const uintptr_t epoch_mask = right_n_bits(epoch_bits); |
149 static const uintptr_t epoch_mask = right_n_bits(epoch_bits); |
159 static const uintptr_t epoch_mask_in_place = epoch_mask << epoch_shift; |
150 static const uintptr_t epoch_mask_in_place = epoch_mask << epoch_shift; |
160 static const uintptr_t cms_mask = right_n_bits(cms_bits); |
|
161 static const uintptr_t cms_mask_in_place = cms_mask << cms_shift; |
|
162 |
151 |
163 static const uintptr_t hash_mask = right_n_bits(hash_bits); |
152 static const uintptr_t hash_mask = right_n_bits(hash_bits); |
164 static const uintptr_t hash_mask_in_place = hash_mask << hash_shift; |
153 static const uintptr_t hash_mask_in_place = hash_mask << hash_shift; |
165 |
154 |
166 // Alignment of JavaThread pointers encoded in object header required by biased locking |
155 // Alignment of JavaThread pointers encoded in object header required by biased locking |
267 // reducing the number of mark words preserved during them isn't a |
256 // reducing the number of mark words preserved during them isn't a |
268 // high priority. |
257 // high priority. |
269 template <typename KlassProxy> |
258 template <typename KlassProxy> |
270 inline bool must_be_preserved_for_promotion_failure(KlassProxy klass) const; |
259 inline bool must_be_preserved_for_promotion_failure(KlassProxy klass) const; |
271 |
260 |
272 // Should this header be preserved during a scavenge where CMS is |
|
273 // the old generation? |
|
274 // (This is basically the same body as must_be_preserved_for_promotion_failure(), |
|
275 // but takes the Klass* as argument instead) |
|
276 inline bool must_be_preserved_for_cms_scavenge(Klass* klass_of_obj_containing_mark) const; |
|
277 |
|
278 // WARNING: The following routines are used EXCLUSIVELY by |
261 // WARNING: The following routines are used EXCLUSIVELY by |
279 // synchronization functions. They are not really gc safe. |
262 // synchronization functions. They are not really gc safe. |
280 // They must get updated if markWord layout get changed. |
263 // They must get updated if markWord layout get changed. |
281 markWord set_unlocked() const { |
264 markWord set_unlocked() const { |
282 return markWord(value() | unlocked_value); |
265 return markWord(value() | unlocked_value); |
373 // Prepare address of oop for placement into mark |
356 // Prepare address of oop for placement into mark |
374 inline static markWord encode_pointer_as_mark(void* p) { return from_pointer(p).set_marked(); } |
357 inline static markWord encode_pointer_as_mark(void* p) { return from_pointer(p).set_marked(); } |
375 |
358 |
376 // Recover address of oop from encoded form used in mark |
359 // Recover address of oop from encoded form used in mark |
377 inline void* decode_pointer() { if (UseBiasedLocking && has_bias_pattern()) return NULL; return (void*)clear_lock_bits().value(); } |
360 inline void* decode_pointer() { if (UseBiasedLocking && has_bias_pattern()) return NULL; return (void*)clear_lock_bits().value(); } |
378 |
|
379 // These markWords indicate cms free chunk blocks and not objects. |
|
380 // In 64 bit, the markWord is set to distinguish them from oops. |
|
381 // These are defined in 32 bit mode for vmStructs. |
|
382 const static uintptr_t cms_free_chunk_pattern = 0x1; |
|
383 |
|
384 // Constants for the size field. |
|
385 enum { size_shift = cms_shift + cms_bits, |
|
386 size_bits = 35 // need for compressed oops 32G |
|
387 }; |
|
388 // These values are too big for Win64 |
|
389 const static uintptr_t size_mask = LP64_ONLY(right_n_bits(size_bits)) |
|
390 NOT_LP64(0); |
|
391 const static uintptr_t size_mask_in_place = |
|
392 (address_word)size_mask << size_shift; |
|
393 |
|
394 #ifdef _LP64 |
|
395 static markWord cms_free_prototype() { |
|
396 return markWord((prototype().value() & ~cms_mask_in_place) | |
|
397 ((cms_free_chunk_pattern & cms_mask) << cms_shift)); |
|
398 } |
|
399 uintptr_t cms_encoding() const { |
|
400 return mask_bits(value() >> cms_shift, cms_mask); |
|
401 } |
|
402 bool is_cms_free_chunk() const { |
|
403 return is_neutral() && |
|
404 (cms_encoding() & cms_free_chunk_pattern) == cms_free_chunk_pattern; |
|
405 } |
|
406 |
|
407 size_t get_size() const { return (size_t)(value() >> size_shift); } |
|
408 static markWord set_size_and_free(size_t size) { |
|
409 assert((size & ~size_mask) == 0, "shouldn't overflow size field"); |
|
410 return markWord((cms_free_prototype().value() & ~size_mask_in_place) | |
|
411 ((size & size_mask) << size_shift)); |
|
412 } |
|
413 #endif // _LP64 |
|
414 }; |
361 }; |
415 |
362 |
416 // Support atomic operations. |
363 // Support atomic operations. |
417 template<> |
364 template<> |
418 struct PrimitiveConversions::Translate<markWord> : public TrueType { |
365 struct PrimitiveConversions::Translate<markWord> : public TrueType { |