@@ -153,7 +153,7 @@ void C2_MacroAssembler::fast_lock(Register objectReg, Register boxReg, Register
153
153
Label count, no_count;
154
154
155
155
assert (LockingMode != LM_LIGHTWEIGHT, " lightweight locking should use fast_lock_lightweight" );
156
- assert_different_registers (oop, box, tmp, disp_hdr);
156
+ assert_different_registers (oop, box, tmp, disp_hdr, rscratch2 );
157
157
158
158
// Load markWord from object into displaced_header.
159
159
ldr (disp_hdr, Address (oop, oopDesc::mark_offset_in_bytes ()));
@@ -206,12 +206,10 @@ void C2_MacroAssembler::fast_lock(Register objectReg, Register boxReg, Register
206
206
// Handle existing monitor.
207
207
bind (object_has_monitor);
208
208
209
- // The object's monitor m is unlocked iff m->owner == nullptr,
210
- // otherwise m->owner may contain a thread or a stack address.
211
- //
212
- // Try to CAS m->owner from null to current thread.
209
+ // Try to CAS owner (no owner => current thread's _lock_id).
210
+ ldr (rscratch2, Address (rthread, JavaThread::lock_id_offset ()));
213
211
add (tmp, disp_hdr, (in_bytes (ObjectMonitor::owner_offset ())-markWord::monitor_value));
214
- cmpxchg (tmp, zr, rthread , Assembler::xword, /* acquire*/ true ,
212
+ cmpxchg (tmp, zr, rscratch2 , Assembler::xword, /* acquire*/ true ,
215
213
/* release*/ true , /* weak*/ false , tmp3Reg); // Sets flags for result
216
214
217
215
// Store a non-null value into the box to avoid looking like a re-entrant
@@ -223,7 +221,7 @@ void C2_MacroAssembler::fast_lock(Register objectReg, Register boxReg, Register
223
221
224
222
br (Assembler::EQ, cont); // CAS success means locking succeeded
225
223
226
- cmp (tmp3Reg, rthread );
224
+ cmp (tmp3Reg, rscratch2 );
227
225
br (Assembler::NE, cont); // Check for recursive locking
228
226
229
227
// Recursive lock case
@@ -236,7 +234,9 @@ void C2_MacroAssembler::fast_lock(Register objectReg, Register boxReg, Register
236
234
br (Assembler::NE, no_count);
237
235
238
236
bind (count);
239
- increment (Address (rthread, JavaThread::held_monitor_count_offset ()));
237
+ if (LockingMode == LM_LEGACY) {
238
+ inc_held_monitor_count (rscratch1);
239
+ }
240
240
241
241
bind (no_count);
242
242
}
@@ -343,15 +343,17 @@ void C2_MacroAssembler::fast_unlock(Register objectReg, Register boxReg, Registe
343
343
br (Assembler::NE, no_count);
344
344
345
345
bind (count);
346
- decrement (Address (rthread, JavaThread::held_monitor_count_offset ()));
346
+ if (LockingMode == LM_LEGACY) {
347
+ dec_held_monitor_count (rscratch1);
348
+ }
347
349
348
350
bind (no_count);
349
351
}
350
352
351
353
void C2_MacroAssembler::fast_lock_lightweight (Register obj, Register box, Register t1,
352
354
Register t2, Register t3) {
353
355
assert (LockingMode == LM_LIGHTWEIGHT, " must be" );
354
- assert_different_registers (obj, box, t1, t2, t3);
356
+ assert_different_registers (obj, box, t1, t2, t3, rscratch2 );
355
357
356
358
// Handle inflated monitor.
357
359
Label inflated;
@@ -467,13 +469,14 @@ void C2_MacroAssembler::fast_lock_lightweight(Register obj, Register box, Regist
467
469
// Compute owner address.
468
470
lea (t2_owner_addr, owner_address);
469
471
470
- // CAS owner (null => current thread).
471
- cmpxchg (t2_owner_addr, zr, rthread, Assembler::xword, /* acquire*/ true ,
472
+ // Try to CAS owner (no owner => current thread's _lock_id).
473
+ ldr (rscratch2, Address (rthread, JavaThread::lock_id_offset ()));
474
+ cmpxchg (t2_owner_addr, zr, rscratch2, Assembler::xword, /* acquire*/ true ,
472
475
/* release*/ false , /* weak*/ false , t3_owner);
473
476
br (Assembler::EQ, monitor_locked);
474
477
475
478
// Check if recursive.
476
- cmp (t3_owner, rthread );
479
+ cmp (t3_owner, rscratch2 );
477
480
br (Assembler::NE, slow_path);
478
481
479
482
// Recursive.
@@ -486,7 +489,6 @@ void C2_MacroAssembler::fast_lock_lightweight(Register obj, Register box, Regist
486
489
}
487
490
488
491
bind (locked);
489
- increment (Address (rthread, JavaThread::held_monitor_count_offset ()));
490
492
491
493
#ifdef ASSERT
492
494
// Check that locked label is reached with Flags == EQ.
@@ -655,7 +657,6 @@ void C2_MacroAssembler::fast_unlock_lightweight(Register obj, Register box, Regi
655
657
}
656
658
657
659
bind (unlocked);
658
- decrement (Address (rthread, JavaThread::held_monitor_count_offset ()));
659
660
cmp (zr, zr); // Set Flags to EQ => fast path
660
661
661
662
#ifdef ASSERT
0 commit comments