< prev index next >

src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp

Print this page
*** 116,13 ***
    // Handle existing monitor.
    bind(object_has_monitor);
    // The object's monitor m is unlocked iff m->owner == nullptr,
    // otherwise m->owner may contain a thread or a stack address.
    //
!   // Try to CAS m->owner from null to current thread.
    add(tmp, disp_hdr, (in_bytes(ObjectMonitor::owner_offset()) - markWord::monitor_value));
!   cmpxchg(/*memory address*/tmp, /*expected value*/zr, /*new value*/xthread, Assembler::int64,
            Assembler::aq, Assembler::rl, /*result*/tmp3Reg); // cas succeeds if tmp3Reg == zr(expected)
  
    // Store a non-null value into the box to avoid looking like a re-entrant
    // lock. The fast-path monitor unlock code checks for
    // markWord::monitor_value so use markWord::unused_mark which has the
--- 116,15 ---
    // Handle existing monitor.
    bind(object_has_monitor);
    // The object's monitor m is unlocked iff m->owner == nullptr,
    // otherwise m->owner may contain a thread or a stack address.
    //
!   // Try to CAS m->owner from null to current thread id.
+   Register tid = flag;
+   mv(tid, Address(xthread, JavaThread::lock_id_offset()));
    add(tmp, disp_hdr, (in_bytes(ObjectMonitor::owner_offset()) - markWord::monitor_value));
!   cmpxchg(/*memory address*/tmp, /*expected value*/zr, /*new value*/tid, Assembler::int64,
            Assembler::aq, Assembler::rl, /*result*/tmp3Reg); // cas succeeds if tmp3Reg == zr(expected)
  
    // Store a non-null value into the box to avoid looking like a re-entrant
    // lock. The fast-path monitor unlock code checks for
    // markWord::monitor_value so use markWord::unused_mark which has the

*** 130,11 ***
    mv(tmp, (address)markWord::unused_mark().value());
    sd(tmp, Address(box, BasicLock::displaced_header_offset_in_bytes()));
  
    beqz(tmp3Reg, locked); // CAS success means locking succeeded
  
!   bne(tmp3Reg, xthread, slow_path); // Check for recursive locking
  
    // Recursive lock case
    increment(Address(disp_hdr, in_bytes(ObjectMonitor::recursions_offset()) - markWord::monitor_value), 1, tmp2Reg, tmp3Reg);
  
    bind(locked);
--- 132,11 ---
    mv(tmp, (address)markWord::unused_mark().value());
    sd(tmp, Address(box, BasicLock::displaced_header_offset_in_bytes()));
  
    beqz(tmp3Reg, locked); // CAS success means locking succeeded
  
!   bne(tmp3Reg, tid, slow_path); // Check for recursive locking
  
    // Recursive lock case
    increment(Address(disp_hdr, in_bytes(ObjectMonitor::recursions_offset()) - markWord::monitor_value), 1, tmp2Reg, tmp3Reg);
  
    bind(locked);

*** 165,11 ***
    Register oop = objectReg;
    Register box = boxReg;
    Register disp_hdr = tmp1Reg;
    Register tmp = tmp2Reg;
    Label object_has_monitor;
!   // Finish fast lock successfully. MUST branch to with flag == 0
    Label unlocked;
    // Finish fast lock unsuccessfully. slow_path MUST branch to with flag != 0
    Label slow_path;
  
    assert(LockingMode != LM_LIGHTWEIGHT, "lightweight locking should use fast_unlock_lightweight");
--- 167,11 ---
    Register oop = objectReg;
    Register box = boxReg;
    Register disp_hdr = tmp1Reg;
    Register tmp = tmp2Reg;
    Label object_has_monitor;
!   // Finish fast lock successfully. MUST branch to vwith flag == 0
    Label unlocked;
    // Finish fast lock unsuccessfully. slow_path MUST branch to with flag != 0
    Label slow_path;
  
    assert(LockingMode != LM_LIGHTWEIGHT, "lightweight locking should use fast_unlock_lightweight");

*** 330,17 ***
      const Register tmp3_owner = tmp3;
  
      // Compute owner address.
      la(tmp2_owner_addr, Address(tmp1_tagged_monitor, (in_bytes(ObjectMonitor::owner_offset()) - monitor_tag)));
  
!     // CAS owner (null => current thread).
!     cmpxchg(/*addr*/ tmp2_owner_addr, /*expected*/ zr, /*new*/ xthread, Assembler::int64,
              /*acquire*/ Assembler::aq, /*release*/ Assembler::relaxed, /*result*/ tmp3_owner);
      beqz(tmp3_owner, locked);
  
      // Check if recursive.
!     bne(tmp3_owner, xthread, slow_path);
  
      // Recursive.
      increment(Address(tmp1_tagged_monitor, in_bytes(ObjectMonitor::recursions_offset()) - monitor_tag), 1, tmp2, tmp3);
    }
  
--- 332,19 ---
      const Register tmp3_owner = tmp3;
  
      // Compute owner address.
      la(tmp2_owner_addr, Address(tmp1_tagged_monitor, (in_bytes(ObjectMonitor::owner_offset()) - monitor_tag)));
  
!     // CAS owner (null => current thread id).
!     Register tid = flag;
+     mv(tid, Address(xthread, JavaThread::lock_id_offset()));
+     cmpxchg(/*addr*/ tmp2_owner_addr, /*expected*/ zr, /*new*/ tid, Assembler::int64,
              /*acquire*/ Assembler::aq, /*release*/ Assembler::relaxed, /*result*/ tmp3_owner);
      beqz(tmp3_owner, locked);
  
      // Check if recursive.
!     bne(tmp3_owner, tid, slow_path);
  
      // Recursive.
      increment(Address(tmp1_tagged_monitor, in_bytes(ObjectMonitor::recursions_offset()) - monitor_tag), 1, tmp2, tmp3);
    }
  

*** 487,11 ***
      beqz(t0, release);
  
      // The owner may be anonymous and we removed the last obj entry in
      // the lock-stack. This loses the information about the owner.
      // Write the thread to the owner field so the runtime knows the owner.
!     sd(xthread, Address(tmp2_owner_addr));
      j(slow_path);
  
      bind(release);
      // Set owner to null.
      membar(MacroAssembler::LoadStore | MacroAssembler::StoreStore);
--- 491,13 ---
      beqz(t0, release);
  
      // The owner may be anonymous and we removed the last obj entry in
      // the lock-stack. This loses the information about the owner.
      // Write the thread to the owner field so the runtime knows the owner.
!     Register tid = flag;
+     mv(tid, Address(xthread, JavaThread::lock_id_offset()));
+     sd(tid, Address(tmp2_owner_addr));
      j(slow_path);
  
      bind(release);
      // Set owner to null.
      membar(MacroAssembler::LoadStore | MacroAssembler::StoreStore);
< prev index next >