Skip to content

Commit 3149ed4

Browse files
committed
8230203: Replace markWord enums with typed constants
Reviewed-by: kbarrett, dholmes
1 parent c7f0ae0 commit 3149ed4

File tree

7 files changed

+78
-82
lines changed

7 files changed

+78
-82
lines changed

src/hotspot/cpu/aarch64/aarch64.ad

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3547,7 +3547,7 @@ encode %{
35473547
// markWord of object (disp_hdr) with the stack pointer.
35483548
__ mov(rscratch1, sp);
35493549
__ sub(disp_hdr, disp_hdr, rscratch1);
3550-
__ mov(tmp, (address) (~(os::vm_page_size()-1) | (uintptr_t)markWord::lock_mask_in_place));
3550+
__ mov(tmp, (address) (~(os::vm_page_size()-1) | markWord::lock_mask_in_place));
35513551
// If condition is true we are cont and hence we can store 0 as the
35523552
// displaced header in the box, which indicates that it is a recursive lock.
35533553
__ ands(tmp/*==0?*/, disp_hdr, tmp); // Sets flags for result
@@ -3616,7 +3616,8 @@ encode %{
36163616

36173617
// Handle existing monitor.
36183618
__ bind(object_has_monitor);
3619-
__ add(tmp, tmp, -markWord::monitor_value); // monitor
3619+
STATIC_ASSERT(markWord::monitor_value <= INT_MAX);
3620+
__ add(tmp, tmp, -(int)markWord::monitor_value); // monitor
36203621
__ ldr(rscratch1, Address(tmp, ObjectMonitor::owner_offset_in_bytes()));
36213622
__ ldr(disp_hdr, Address(tmp, ObjectMonitor::recursions_offset_in_bytes()));
36223623
__ eor(rscratch1, rscratch1, rthread); // Will be 0 if we are the owner.

src/hotspot/cpu/arm/macroAssembler_arm.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ int MacroAssembler::biased_locking_enter(Register obj_reg, Register swap_reg, Re
13671367
// On MP platform loads could return 'stale' values in some cases.
13681368
// That is acceptable since either CAS or slow case path is taken in the worst case.
13691369

1370-
andr(tmp_reg, swap_reg, (uintx)markWord::biased_lock_mask_in_place);
1370+
andr(tmp_reg, swap_reg, markWord::biased_lock_mask_in_place);
13711371
cmp(tmp_reg, markWord::biased_lock_pattern);
13721372

13731373
b(cas_label, ne);
@@ -1401,7 +1401,7 @@ int MacroAssembler::biased_locking_enter(Register obj_reg, Register swap_reg, Re
14011401
// If the low three bits in the xor result aren't clear, that means
14021402
// the prototype header is no longer biased and we have to revoke
14031403
// the bias on this object.
1404-
tst(tmp_reg, (uintx)markWord::biased_lock_mask_in_place);
1404+
tst(tmp_reg, markWord::biased_lock_mask_in_place);
14051405
b(try_revoke_bias, ne);
14061406

14071407
// Biasing is still enabled for this data type. See whether the
@@ -1413,7 +1413,7 @@ int MacroAssembler::biased_locking_enter(Register obj_reg, Register swap_reg, Re
14131413
// that the current epoch is invalid in order to do this because
14141414
// otherwise the manipulations it performs on the mark word are
14151415
// illegal.
1416-
tst(tmp_reg, (uintx)markWord::epoch_mask_in_place);
1416+
tst(tmp_reg, markWord::epoch_mask_in_place);
14171417
b(try_rebias, ne);
14181418

14191419
// tmp_reg has the age, epoch and pattern bits cleared
@@ -1519,7 +1519,7 @@ void MacroAssembler::biased_locking_exit(Register obj_reg, Register tmp_reg, Lab
15191519
// the bias bit would be clear.
15201520
ldr(tmp_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
15211521

1522-
andr(tmp_reg, tmp_reg, (uintx)markWord::biased_lock_mask_in_place);
1522+
andr(tmp_reg, tmp_reg, markWord::biased_lock_mask_in_place);
15231523
cmp(tmp_reg, markWord::biased_lock_pattern);
15241524
b(done, eq);
15251525
}

src/hotspot/cpu/ppc/macroAssembler_ppc.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3000,7 +3000,8 @@ void MacroAssembler::compiler_fast_unlock_object(ConditionRegister flag, Registe
30003000
b(cont);
30013001

30023002
bind(object_has_monitor);
3003-
addi(current_header, current_header, -markWord::monitor_value); // monitor
3003+
STATIC_ASSERT(markWord::monitor_value <= INT_MAX);
3004+
addi(current_header, current_header, -(int)markWord::monitor_value); // monitor
30043005
ld(temp, ObjectMonitor::owner_offset_in_bytes(), current_header);
30053006

30063007
// It's inflated.

src/hotspot/share/interpreter/bytecodeInterpreter.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ BytecodeInterpreter::run(interpreterState istate) {
666666
BasicObjectLock* mon = &istate->monitor_base()[-1];
667667
mon->set_obj(rcvr);
668668
bool success = false;
669-
uintptr_t epoch_mask_in_place = (uintptr_t)markWord::epoch_mask_in_place;
669+
uintptr_t epoch_mask_in_place = markWord::epoch_mask_in_place;
670670
markWord mark = rcvr->mark();
671671
intptr_t hash = (intptr_t) markWord::no_hash;
672672
// Implies UseBiasedLocking.
@@ -675,8 +675,8 @@ BytecodeInterpreter::run(interpreterState istate) {
675675
uintptr_t anticipated_bias_locking_value;
676676
thread_ident = (uintptr_t)istate->thread();
677677
anticipated_bias_locking_value =
678-
(((uintptr_t)rcvr->klass()->prototype_header().value() | thread_ident) ^ mark.value()) &
679-
~((uintptr_t) markWord::age_mask_in_place);
678+
((rcvr->klass()->prototype_header().value() | thread_ident) ^ mark.value()) &
679+
~(markWord::age_mask_in_place);
680680

681681
if (anticipated_bias_locking_value == 0) {
682682
// Already biased towards this thread, nothing to do.
@@ -711,8 +711,8 @@ BytecodeInterpreter::run(interpreterState istate) {
711711
} else {
712712
// Try to bias towards thread in case object is anonymously biased.
713713
markWord header(mark.value() &
714-
((uintptr_t)markWord::biased_lock_mask_in_place |
715-
(uintptr_t)markWord::age_mask_in_place | epoch_mask_in_place));
714+
(markWord::biased_lock_mask_in_place |
715+
markWord::age_mask_in_place | epoch_mask_in_place));
716716
if (hash != markWord::no_hash) {
717717
header = header.copy_set_hash(hash);
718718
}
@@ -851,7 +851,7 @@ BytecodeInterpreter::run(interpreterState istate) {
851851
assert(entry->obj() == NULL, "Frame manager didn't allocate the monitor");
852852
entry->set_obj(lockee);
853853
bool success = false;
854-
uintptr_t epoch_mask_in_place = (uintptr_t)markWord::epoch_mask_in_place;
854+
uintptr_t epoch_mask_in_place = markWord::epoch_mask_in_place;
855855

856856
markWord mark = lockee->mark();
857857
intptr_t hash = (intptr_t) markWord::no_hash;
@@ -861,8 +861,8 @@ BytecodeInterpreter::run(interpreterState istate) {
861861
uintptr_t anticipated_bias_locking_value;
862862
thread_ident = (uintptr_t)istate->thread();
863863
anticipated_bias_locking_value =
864-
(((uintptr_t)lockee->klass()->prototype_header().value() | thread_ident) ^ mark.value()) &
865-
~((uintptr_t) markWord::age_mask_in_place);
864+
((lockee->klass()->prototype_header().value() | thread_ident) ^ mark.value()) &
865+
~(markWord::age_mask_in_place);
866866

867867
if (anticipated_bias_locking_value == 0) {
868868
// already biased towards this thread, nothing to do
@@ -897,8 +897,8 @@ BytecodeInterpreter::run(interpreterState istate) {
897897
success = true;
898898
} else {
899899
// try to bias towards thread in case object is anonymously biased
900-
markWord header(mark.value() & ((uintptr_t)markWord::biased_lock_mask_in_place |
901-
(uintptr_t)markWord::age_mask_in_place | epoch_mask_in_place));
900+
markWord header(mark.value() & (markWord::biased_lock_mask_in_place |
901+
markWord::age_mask_in_place | epoch_mask_in_place));
902902
if (hash != markWord::no_hash) {
903903
header = header.copy_set_hash(hash);
904904
}
@@ -1791,7 +1791,7 @@ BytecodeInterpreter::run(interpreterState istate) {
17911791
if (entry != NULL) {
17921792
entry->set_obj(lockee);
17931793
int success = false;
1794-
uintptr_t epoch_mask_in_place = (uintptr_t)markWord::epoch_mask_in_place;
1794+
uintptr_t epoch_mask_in_place = markWord::epoch_mask_in_place;
17951795

17961796
markWord mark = lockee->mark();
17971797
intptr_t hash = (intptr_t) markWord::no_hash;
@@ -1801,8 +1801,8 @@ BytecodeInterpreter::run(interpreterState istate) {
18011801
uintptr_t anticipated_bias_locking_value;
18021802
thread_ident = (uintptr_t)istate->thread();
18031803
anticipated_bias_locking_value =
1804-
(((uintptr_t)lockee->klass()->prototype_header().value() | thread_ident) ^ mark.value()) &
1805-
~((uintptr_t) markWord::age_mask_in_place);
1804+
((lockee->klass()->prototype_header().value() | thread_ident) ^ mark.value()) &
1805+
~(markWord::age_mask_in_place);
18061806

18071807
if (anticipated_bias_locking_value == 0) {
18081808
// already biased towards this thread, nothing to do
@@ -1839,8 +1839,8 @@ BytecodeInterpreter::run(interpreterState istate) {
18391839
}
18401840
else {
18411841
// try to bias towards thread in case object is anonymously biased
1842-
markWord header(mark.value() & ((uintptr_t)markWord::biased_lock_mask_in_place |
1843-
(uintptr_t)markWord::age_mask_in_place |
1842+
markWord header(mark.value() & (markWord::biased_lock_mask_in_place |
1843+
markWord::age_mask_in_place |
18441844
epoch_mask_in_place));
18451845
if (hash != markWord::no_hash) {
18461846
header = header.copy_set_hash(hash);

src/hotspot/share/oops/markWord.hpp

Lines changed: 49 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -131,61 +131,54 @@ class markWord {
131131
uintptr_t value() const { return _value; }
132132

133133
// Constants
134-
enum { age_bits = 4,
135-
lock_bits = 2,
136-
biased_lock_bits = 1,
137-
max_hash_bits = BitsPerWord - age_bits - lock_bits - biased_lock_bits,
138-
hash_bits = max_hash_bits > 31 ? 31 : max_hash_bits,
139-
cms_bits = LP64_ONLY(1) NOT_LP64(0),
140-
epoch_bits = 2
141-
};
134+
static const int age_bits = 4;
135+
static const int lock_bits = 2;
136+
static const int biased_lock_bits = 1;
137+
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;
139+
static const int cms_bits = LP64_ONLY(1) NOT_LP64(0);
140+
static const int epoch_bits = 2;
142141

143142
// The biased locking code currently requires that the age bits be
144143
// contiguous to the lock bits.
145-
enum { lock_shift = 0,
146-
biased_lock_shift = lock_bits,
147-
age_shift = lock_bits + biased_lock_bits,
148-
cms_shift = age_shift + age_bits,
149-
hash_shift = cms_shift + cms_bits,
150-
epoch_shift = hash_shift
151-
};
152-
153-
enum { lock_mask = right_n_bits(lock_bits),
154-
lock_mask_in_place = lock_mask << lock_shift,
155-
biased_lock_mask = right_n_bits(lock_bits + biased_lock_bits),
156-
biased_lock_mask_in_place= biased_lock_mask << lock_shift,
157-
biased_lock_bit_in_place = 1 << biased_lock_shift,
158-
age_mask = right_n_bits(age_bits),
159-
age_mask_in_place = age_mask << age_shift,
160-
epoch_mask = right_n_bits(epoch_bits),
161-
epoch_mask_in_place = epoch_mask << epoch_shift,
162-
cms_mask = right_n_bits(cms_bits),
163-
cms_mask_in_place = cms_mask << cms_shift
164-
};
165-
166-
const static uintptr_t hash_mask = right_n_bits(hash_bits);
167-
const static uintptr_t hash_mask_in_place = hash_mask << hash_shift;
144+
static const int lock_shift = 0;
145+
static const int biased_lock_shift = lock_bits;
146+
static const int age_shift = lock_bits + biased_lock_bits;
147+
static const int cms_shift = age_shift + age_bits;
148+
static const int hash_shift = cms_shift + cms_bits;
149+
static const int epoch_shift = hash_shift;
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 biased_lock_mask = right_n_bits(lock_bits + biased_lock_bits);
154+
static const uintptr_t biased_lock_mask_in_place= biased_lock_mask << lock_shift;
155+
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);
157+
static const uintptr_t age_mask_in_place = age_mask << age_shift;
158+
static const uintptr_t epoch_mask = right_n_bits(epoch_bits);
159+
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+
163+
static const uintptr_t hash_mask = right_n_bits(hash_bits);
164+
static const uintptr_t hash_mask_in_place = hash_mask << hash_shift;
168165

169166
// Alignment of JavaThread pointers encoded in object header required by biased locking
170-
enum { biased_lock_alignment = 2 << (epoch_shift + epoch_bits)
171-
};
167+
static const size_t biased_lock_alignment = 2 << (epoch_shift + epoch_bits);
172168

173-
enum { locked_value = 0,
174-
unlocked_value = 1,
175-
monitor_value = 2,
176-
marked_value = 3,
177-
biased_lock_pattern = 5
178-
};
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 biased_lock_pattern = 5;
179174

180-
enum { no_hash = 0 }; // no hash value assigned
175+
static const uintptr_t no_hash = 0 ; // no hash value assigned
176+
static const uintptr_t no_hash_in_place = (address_word)no_hash << hash_shift;
177+
static const uintptr_t no_lock_in_place = unlocked_value;
181178

182-
enum { no_hash_in_place = (address_word)no_hash << hash_shift,
183-
no_lock_in_place = unlocked_value
184-
};
179+
static const uint max_age = age_mask;
185180

186-
enum { max_age = age_mask };
187-
188-
enum { max_bias_epoch = epoch_mask };
181+
static const int max_bias_epoch = epoch_mask;
189182

190183
// Creates a markWord with all bits set to zero.
191184
static markWord zero() { return markWord(uintptr_t(0)); }
@@ -201,7 +194,7 @@ class markWord {
201194
}
202195
JavaThread* biased_locker() const {
203196
assert(has_bias_pattern(), "should not call this otherwise");
204-
return (JavaThread*) ((intptr_t) (mask_bits(value(), ~(biased_lock_mask_in_place | age_mask_in_place | epoch_mask_in_place))));
197+
return (JavaThread*) mask_bits(value(), ~(biased_lock_mask_in_place | age_mask_in_place | epoch_mask_in_place));
205198
}
206199
// Indicates that the mark has the bias bit set but that it has not
207200
// yet been biased toward a particular thread
@@ -308,16 +301,16 @@ class markWord {
308301
}
309302
markWord displaced_mark_helper() const {
310303
assert(has_displaced_mark_helper(), "check");
311-
intptr_t ptr = (value() & ~monitor_value);
304+
uintptr_t ptr = (value() & ~monitor_value);
312305
return *(markWord*)ptr;
313306
}
314307
void set_displaced_mark_helper(markWord m) const {
315308
assert(has_displaced_mark_helper(), "check");
316-
intptr_t ptr = (value() & ~monitor_value);
309+
uintptr_t ptr = (value() & ~monitor_value);
317310
((markWord*)ptr)->_value = m._value;
318311
}
319312
markWord copy_set_hash(intptr_t hash) const {
320-
intptr_t tmp = value() & (~hash_mask_in_place);
313+
uintptr_t tmp = value() & (~hash_mask_in_place);
321314
tmp |= ((hash & hash_mask) << hash_shift);
322315
return markWord(tmp);
323316
}
@@ -332,11 +325,11 @@ class markWord {
332325
return from_pointer(lock);
333326
}
334327
static markWord encode(ObjectMonitor* monitor) {
335-
intptr_t tmp = (intptr_t) monitor;
328+
uintptr_t tmp = (uintptr_t) monitor;
336329
return markWord(tmp | monitor_value);
337330
}
338331
static markWord encode(JavaThread* thread, uint age, int bias_epoch) {
339-
intptr_t tmp = (intptr_t) thread;
332+
uintptr_t tmp = (uintptr_t) thread;
340333
assert(UseBiasedLocking && ((tmp & (epoch_mask_in_place | age_mask_in_place | biased_lock_mask_in_place)) == 0), "misaligned JavaThread pointer");
341334
assert(age <= max_age, "age too large");
342335
assert(bias_epoch <= max_bias_epoch, "bias epoch too large");
@@ -353,7 +346,7 @@ class markWord {
353346
uint age() const { return mask_bits(value() >> age_shift, age_mask); }
354347
markWord set_age(uint v) const {
355348
assert((v & ~age_mask) == 0, "shouldn't overflow age field");
356-
return markWord((value() & ~age_mask_in_place) | (((uintptr_t)v & age_mask) << age_shift));
349+
return markWord((value() & ~age_mask_in_place) | ((v & age_mask) << age_shift));
357350
}
358351
markWord incr_age() const { return age() == max_age ? markWord(_value) : set_age(age() + 1); }
359352

@@ -400,7 +393,7 @@ class markWord {
400393

401394
#ifdef _LP64
402395
static markWord cms_free_prototype() {
403-
return markWord(((intptr_t)prototype().value() & ~cms_mask_in_place) |
396+
return markWord((prototype().value() & ~cms_mask_in_place) |
404397
((cms_free_chunk_pattern & cms_mask) << cms_shift));
405398
}
406399
uintptr_t cms_encoding() const {
@@ -414,8 +407,8 @@ class markWord {
414407
size_t get_size() const { return (size_t)(value() >> size_shift); }
415408
static markWord set_size_and_free(size_t size) {
416409
assert((size & ~size_mask) == 0, "shouldn't overflow size field");
417-
return markWord(((intptr_t)cms_free_prototype().value() & ~size_mask_in_place) |
418-
(((intptr_t)size & size_mask) << size_shift));
410+
return markWord((cms_free_prototype().value() & ~size_mask_in_place) |
411+
((size & size_mask) << size_shift));
419412
}
420413
#endif // _LP64
421414
};

src/hotspot/share/opto/macro.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2225,8 +2225,9 @@ void PhaseMacroExpand::expand_lock_node(LockNode *lock) {
22252225
Node* x_node = transform_later(new XorXNode(o_node, mark_node));
22262226

22272227
// Get slow path - mark word does NOT match the value.
2228+
STATIC_ASSERT(markWord::age_mask_in_place <= INT_MAX);
22282229
Node* not_biased_ctrl = opt_bits_test(ctrl, region, 3, x_node,
2229-
(~markWord::age_mask_in_place), 0);
2230+
(~(int)markWord::age_mask_in_place), 0);
22302231
// region->in(3) is set to fast path - the object is biased to the current thread.
22312232
mem_phi->init_req(3, mem);
22322233

src/hotspot/share/runtime/thread.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ THREAD_LOCAL_DECL Thread* Thread::_thr_current = NULL;
173173
// Support for forcing alignment of thread objects for biased locking
174174
void* Thread::allocate(size_t size, bool throw_excpt, MEMFLAGS flags) {
175175
if (UseBiasedLocking) {
176-
const int alignment = markWord::biased_lock_alignment;
176+
const size_t alignment = markWord::biased_lock_alignment;
177177
size_t aligned_size = size + (alignment - sizeof(intptr_t));
178178
void* real_malloc_addr = throw_excpt? AllocateHeap(aligned_size, flags, CURRENT_PC)
179179
: AllocateHeap(aligned_size, flags, CURRENT_PC,
@@ -301,9 +301,9 @@ Thread::Thread() {
301301
#endif // CHECK_UNHANDLED_OOPS
302302
#ifdef ASSERT
303303
if (UseBiasedLocking) {
304-
assert((((uintptr_t) this) & (markWord::biased_lock_alignment - 1)) == 0, "forced alignment of thread object failed");
304+
assert(is_aligned(this, markWord::biased_lock_alignment), "forced alignment of thread object failed");
305305
assert(this == _real_malloc_address ||
306-
this == align_up(_real_malloc_address, (int)markWord::biased_lock_alignment),
306+
this == align_up(_real_malloc_address, markWord::biased_lock_alignment),
307307
"bug in forced alignment of thread objects");
308308
}
309309
#endif // ASSERT

0 commit comments

Comments
 (0)