Skip to content

Commit 1c9ebf7

Browse files
committed
Emulate old Valhalla decode_pointer behavior.
1 parent 2464706 commit 1c9ebf7

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/hotspot/share/oops/markWord.hpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,6 @@ class markWord {
247247
static const uintptr_t null_free_flat_array_pattern = flat_array_bit_in_place | null_free_array_pattern;
248248
static const uintptr_t nullable_flat_array_pattern = flat_array_bit_in_place | unlocked_value;
249249

250-
// Has static klass prototype, used for decode/encode pointer
251-
static const uintptr_t static_prototype_mask = LP64_ONLY(right_n_bits(inline_type_bits + flat_array_bits + null_free_array_bits)) NOT_LP64(right_n_bits(inline_type_bits));
252-
static const uintptr_t static_prototype_mask_in_place = static_prototype_mask << lock_bits;
253-
static const uintptr_t static_prototype_value_max = (1 << age_shift) - 1;
254-
255250
static const uintptr_t larval_pattern = larval_bit_in_place | inline_type_pattern;
256251

257252
static const uintptr_t no_hash = 0 ; // no hash value assigned
@@ -460,10 +455,23 @@ class markWord {
460455

461456
// Recover address of oop from encoded form used in mark
462457
inline void* decode_pointer() const {
463-
return (EnableValhalla && _value < static_prototype_value_max) ? nullptr :
458+
// Get the current age and 3 Valhalla bits.
459+
// Note that the larval bit is ignored in this case.
460+
uint n_valhalla = 3;
461+
uintptr_t age = (_value >> age_shift) & age_mask;
462+
uintptr_t valhalla = (_value >> inline_type_shift) & right_n_bits(n_valhalla);
463+
// Use the legacy indices: age = 6, Valhalla = 3.
464+
uint old_age = 6, old_valhalla = 3;
465+
// Swap into the legacy format.
466+
uintptr_t tmp = write_bits(_value, valhalla, old_valhalla, old_valhalla + n_valhalla);
467+
tmp = write_bits(tmp, age, old_age, old_age + age_bits);
468+
// No idea what this achives, but it is needed to work.
469+
uintptr_t static_prototype_value_max = (1 << old_age) - 1;
470+
return (EnableValhalla && tmp < static_prototype_value_max) ? nullptr :
464471
(void*) (clear_lock_bits().value());
465472
}
466473

474+
467475
inline bool is_self_forwarded() const {
468476
NOT_LP64(assert(LockingMode != LM_LEGACY, "incorrect with LM_LEGACY on 32 bit");)
469477
return mask_bits(value(), self_fwd_mask_in_place) != 0;
@@ -482,6 +490,13 @@ class markWord {
482490
inline oop forwardee() const {
483491
return cast_to_oop(decode_pointer());
484492
}
493+
494+
private:
495+
inline uintptr_t write_bits(uintptr_t input, uintptr_t val, uint start, uint end) const {
496+
uintptr_t mask = ((1 << start) - 1) ^ ((1 << (end + 1)) - 1);
497+
input &= ~mask;
498+
return input | (val << start);
499+
}
485500
};
486501

487502
// Support atomic operations.

0 commit comments

Comments
 (0)