< prev index next >

src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp

Print this page

 109   } else {
 110     assert(LockingMode == LM_LIGHTWEIGHT, "");
 111     Label slow;
 112     lightweight_lock(oop, disp_hdr, tmp, tmp3Reg, slow);
 113 
 114     // Indicate success on completion.
 115     mv(flag, zr);
 116     j(count);
 117     bind(slow);
 118     mv(flag, 1); // Set non-zero flag to indicate 'failure' -> take slow-path
 119     j(no_count);
 120   }
 121 
 122   // Handle existing monitor.
 123   bind(object_has_monitor);
 124   // The object's monitor m is unlocked iff m->owner == nullptr,
 125   // otherwise m->owner may contain a thread or a stack address.
 126   //
 127   // Try to CAS m->owner from null to current thread.
 128   add(tmp, disp_hdr, (in_bytes(ObjectMonitor::owner_offset()) - markWord::monitor_value));
 129   cmpxchg(/*memory address*/tmp, /*expected value*/zr, /*new value*/xthread, Assembler::int64, Assembler::aq,


 130           Assembler::rl, /*result*/flag); // cas succeeds if flag == zr(expected)
 131 
 132   if (LockingMode != LM_LIGHTWEIGHT) {
 133     // Store a non-null value into the box to avoid looking like a re-entrant
 134     // lock. The fast-path monitor unlock code checks for
 135     // markWord::monitor_value so use markWord::unused_mark which has the
 136     // relevant bit set, and also matches ObjectSynchronizer::slow_enter.
 137     mv(tmp, (address)markWord::unused_mark().value());
 138     sd(tmp, Address(box, BasicLock::displaced_header_offset_in_bytes()));
 139   }
 140 
 141   beqz(flag, cont); // CAS success means locking succeeded
 142 
 143   bne(flag, xthread, cont); // Check for recursive locking
 144 
 145   // Recursive lock case
 146   mv(flag, zr);
 147   increment(Address(disp_hdr, in_bytes(ObjectMonitor::recursions_offset()) - markWord::monitor_value), 1, t0, tmp);
 148 
 149   bind(cont);
 150   // zero flag indicates success
 151   // non-zero flag indicates failure
 152   bnez(flag, no_count);
 153 
 154   bind(count);
 155   increment(Address(xthread, JavaThread::held_monitor_count_offset()), 1, t0, tmp);
 156 
 157   bind(no_count);
 158 }
 159 
 160 void C2_MacroAssembler::fast_unlock(Register objectReg, Register boxReg,
 161                                     Register tmp1Reg, Register tmp2Reg) {
 162   // Use cr register to indicate the fast_unlock result: zero for success; non-zero for failure.
 163   Register flag = t1;

 204 
 205     // Indicate success on completion.
 206     mv(flag, zr);
 207     j(count);
 208     bind(slow);
 209     mv(flag, 1); // Set non-zero flag to indicate 'failure' -> take slow path
 210     j(no_count);
 211   }
 212 
 213   assert(oopDesc::mark_offset_in_bytes() == 0, "offset of _mark is not 0");
 214 
 215   // Handle existing monitor.
 216   bind(object_has_monitor);
 217   STATIC_ASSERT(markWord::monitor_value <= INT_MAX);
 218   add(tmp, tmp, -(int)markWord::monitor_value); // monitor
 219 
 220   if (LockingMode == LM_LIGHTWEIGHT) {
 221     // If the owner is anonymous, we need to fix it -- in an outline stub.
 222     Register tmp2 = disp_hdr;
 223     ld(tmp2, Address(tmp, ObjectMonitor::owner_offset()));
 224     test_bit(t0, tmp2, exact_log2(ObjectMonitor::ANONYMOUS_OWNER));
 225     C2HandleAnonOMOwnerStub* stub = new (Compile::current()->comp_arena()) C2HandleAnonOMOwnerStub(tmp, tmp2);
 226     Compile::current()->output()->add_stub(stub);
 227     bnez(t0, stub->entry(), /* is_far */ true);
 228     bind(stub->continuation());
 229   }
 230 
 231   ld(disp_hdr, Address(tmp, ObjectMonitor::recursions_offset()));
 232 
 233   Label notRecursive;
 234   beqz(disp_hdr, notRecursive); // Will be 0 if not recursive.
 235 
 236   // Recursive lock
 237   addi(disp_hdr, disp_hdr, -1);
 238   sd(disp_hdr, Address(tmp, ObjectMonitor::recursions_offset()));
 239   mv(flag, zr);
 240   j(cont);
 241 
 242   bind(notRecursive);
 243   ld(flag, Address(tmp, ObjectMonitor::EntryList_offset()));
 244   ld(disp_hdr, Address(tmp, ObjectMonitor::cxq_offset()));
 245   orr(flag, flag, disp_hdr); // Will be 0 if both are 0.
 246   bnez(flag, cont);
 247   // need a release store here

 109   } else {
 110     assert(LockingMode == LM_LIGHTWEIGHT, "");
 111     Label slow;
 112     lightweight_lock(oop, disp_hdr, tmp, tmp3Reg, slow);
 113 
 114     // Indicate success on completion.
 115     mv(flag, zr);
 116     j(count);
 117     bind(slow);
 118     mv(flag, 1); // Set non-zero flag to indicate 'failure' -> take slow-path
 119     j(no_count);
 120   }
 121 
 122   // Handle existing monitor.
 123   bind(object_has_monitor);
 124   // The object's monitor m is unlocked iff m->owner == nullptr,
 125   // otherwise m->owner may contain a thread or a stack address.
 126   //
 127   // Try to CAS m->owner from null to current thread.
 128   add(tmp, disp_hdr, (in_bytes(ObjectMonitor::owner_offset()) - markWord::monitor_value));
 129   Register tid = t0;
 130   mv(tid, Address(xthread, JavaThread::lock_id_offset()));
 131   cmpxchg(/*memory address*/tmp, /*expected value*/zr, /*new value*/tid, Assembler::int64, Assembler::aq,
 132           Assembler::rl, /*result*/flag); // cas succeeds if flag == zr(expected)
 133 
 134   if (LockingMode != LM_LIGHTWEIGHT) {
 135     // Store a non-null value into the box to avoid looking like a re-entrant
 136     // lock. The fast-path monitor unlock code checks for
 137     // markWord::monitor_value so use markWord::unused_mark which has the
 138     // relevant bit set, and also matches ObjectSynchronizer::slow_enter.
 139     mv(tmp, (address)markWord::unused_mark().value());
 140     sd(tmp, Address(box, BasicLock::displaced_header_offset_in_bytes()));
 141   }
 142 
 143   beqz(flag, cont); // CAS success means locking succeeded
 144 
 145   bne(flag, tid, cont); // Check for recursive locking
 146 
 147   // Recursive lock case
 148   mv(flag, zr);
 149   increment(Address(disp_hdr, in_bytes(ObjectMonitor::recursions_offset()) - markWord::monitor_value), 1, t0, tmp);
 150 
 151   bind(cont);
 152   // zero flag indicates success
 153   // non-zero flag indicates failure
 154   bnez(flag, no_count);
 155 
 156   bind(count);
 157   increment(Address(xthread, JavaThread::held_monitor_count_offset()), 1, t0, tmp);
 158 
 159   bind(no_count);
 160 }
 161 
 162 void C2_MacroAssembler::fast_unlock(Register objectReg, Register boxReg,
 163                                     Register tmp1Reg, Register tmp2Reg) {
 164   // Use cr register to indicate the fast_unlock result: zero for success; non-zero for failure.
 165   Register flag = t1;

 206 
 207     // Indicate success on completion.
 208     mv(flag, zr);
 209     j(count);
 210     bind(slow);
 211     mv(flag, 1); // Set non-zero flag to indicate 'failure' -> take slow path
 212     j(no_count);
 213   }
 214 
 215   assert(oopDesc::mark_offset_in_bytes() == 0, "offset of _mark is not 0");
 216 
 217   // Handle existing monitor.
 218   bind(object_has_monitor);
 219   STATIC_ASSERT(markWord::monitor_value <= INT_MAX);
 220   add(tmp, tmp, -(int)markWord::monitor_value); // monitor
 221 
 222   if (LockingMode == LM_LIGHTWEIGHT) {
 223     // If the owner is anonymous, we need to fix it -- in an outline stub.
 224     Register tmp2 = disp_hdr;
 225     ld(tmp2, Address(tmp, ObjectMonitor::owner_offset()));
 226     mv(t0, (int64_t)ObjectMonitor::ANONYMOUS_OWNER);
 227     C2HandleAnonOMOwnerStub* stub = new (Compile::current()->comp_arena()) C2HandleAnonOMOwnerStub(tmp, tmp2);
 228     Compile::current()->output()->add_stub(stub);
 229     beq(t0, tmp2, stub->entry(), /* is_far */ true);
 230     bind(stub->continuation());
 231   }
 232 
 233   ld(disp_hdr, Address(tmp, ObjectMonitor::recursions_offset()));
 234 
 235   Label notRecursive;
 236   beqz(disp_hdr, notRecursive); // Will be 0 if not recursive.
 237 
 238   // Recursive lock
 239   addi(disp_hdr, disp_hdr, -1);
 240   sd(disp_hdr, Address(tmp, ObjectMonitor::recursions_offset()));
 241   mv(flag, zr);
 242   j(cont);
 243 
 244   bind(notRecursive);
 245   ld(flag, Address(tmp, ObjectMonitor::EntryList_offset()));
 246   ld(disp_hdr, Address(tmp, ObjectMonitor::cxq_offset()));
 247   orr(flag, flag, disp_hdr); // Will be 0 if both are 0.
 248   bnez(flag, cont);
 249   // need a release store here
< prev index next >