< prev index next >

src/hotspot/cpu/riscv/interp_masm_riscv.cpp

Print this page
@@ -776,73 +776,46 @@
  //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, .. (param regs)
  //      t0, t1 (temp regs)
  void InterpreterMacroAssembler::lock_object(Register lock_reg)
  {
    assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
+ 
+   const Register obj_reg = c_rarg3; // Will contain the oop
+   const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
+ 
+   // Load object pointer into obj_reg c_rarg3
+   ld(obj_reg, Address(lock_reg, obj_offset));
+ 
    if (UseHeavyMonitors) {
      call_VM(noreg,
              CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
-             lock_reg);
+             obj_reg);
    } else {
      Label done;
  
      const Register swap_reg = x10;
      const Register tmp = c_rarg2;
-     const Register obj_reg = c_rarg3; // Will contain the oop
- 
-     const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
-     const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
-     const int mark_offset = lock_offset +
-                             BasicLock::displaced_header_offset_in_bytes();
  
      Label slow_case;
  
-     // Load object pointer into obj_reg c_rarg3
-     ld(obj_reg, Address(lock_reg, obj_offset));
- 
      if (DiagnoseSyncOnValueBasedClasses != 0) {
        load_klass(tmp, obj_reg);
        lwu(tmp, Address(tmp, Klass::access_flags_offset()));
        andi(tmp, tmp, JVM_ACC_IS_VALUE_BASED_CLASS);
        bnez(tmp, slow_case);
      }
  
-     // Load (object->mark() | 1) into swap_reg
-     ld(t0, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
-     ori(swap_reg, t0, 1);
- 
-     // Save (object->mark() | 1) into BasicLock's displaced header
-     sd(swap_reg, Address(lock_reg, mark_offset));
- 
-     assert(lock_offset == 0,
-            "displached header must be first word in BasicObjectLock");
- 
-     cmpxchg_obj_header(swap_reg, lock_reg, obj_reg, t0, done, /*fallthrough*/NULL);
- 
-     // Test if the oopMark is an obvious stack pointer, i.e.,
-     //  1) (mark & 7) == 0, and
-     //  2) sp <= mark < mark + os::pagesize()
-     //
-     // These 3 tests can be done by evaluating the following
-     // expression: ((mark - sp) & (7 - os::vm_page_size())),
-     // assuming both stack pointer and pagesize have their
-     // least significant 3 bits clear.
-     // NOTE: the oopMark is in swap_reg x10 as the result of cmpxchg
-     sub(swap_reg, swap_reg, sp);
-     mv(t0, (int64_t)(7 - os::vm_page_size()));
-     andr(swap_reg, swap_reg, t0);
- 
-     // Save the test result, for recursive case, the result is zero
-     sd(swap_reg, Address(lock_reg, mark_offset));
-     beqz(swap_reg, done);
+     ld(tmp, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
+     fast_lock(obj_reg, tmp, t0, swap_reg, t1, slow_case);
+     j(done);
  
      bind(slow_case);
  
      // Call the runtime routine for slow case
      call_VM(noreg,
              CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
-             lock_reg);
+             obj_reg);
  
      bind(done);
    }
  }
  

@@ -860,47 +833,42 @@
  //      t0, t1 (temp regs)
  void InterpreterMacroAssembler::unlock_object(Register lock_reg)
  {
    assert(lock_reg == c_rarg1, "The argument is only for looks. It must be rarg1");
  
+   const Register obj_reg = c_rarg3; // Will contain the oop
+ 
+   // Load oop into obj_reg(c_rarg3)
+   ld(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()));
+ 
+   // Free entry
+   sd(zr, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()));
+ 
    if (UseHeavyMonitors) {
-     call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
+     call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), obj_reg);
    } else {
-     Label done;
+     Label done, slow_case;
  
      const Register swap_reg   = x10;
      const Register header_reg = c_rarg2;  // Will contain the old oopMark
-     const Register obj_reg    = c_rarg3;  // Will contain the oop
  
      save_bcp(); // Save in case of exception
  
-     // Convert from BasicObjectLock structure to object and BasicLock
-     // structure Store the BasicLock address into x10
-     la(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes()));
- 
-     // Load oop into obj_reg(c_rarg3)
-     ld(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()));
+     // Check for non-symmetric locking. This is allowed by the spec and the interpreter
+     // must handle it.
+     ld(header_reg, Address(xthread, Thread::lock_stack_current_offset()));
+     bne(header_reg, obj_reg, slow_case);
  
-     // Free entry
-     sd(zr, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()));
- 
-     // Load the old header from BasicLock structure
-     ld(header_reg, Address(swap_reg,
-                            BasicLock::displaced_header_offset_in_bytes()));
- 
-     // Test for recursion
-     beqz(header_reg, done);
- 
-     // Atomic swap back the old header
-     cmpxchg_obj_header(swap_reg, header_reg, obj_reg, t0, done, /*fallthrough*/NULL);
+     ld(header_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
+     fast_unlock(obj_reg, header_reg, swap_reg, t0, slow_case);
+     j(done);
  
      // Call the runtime routine for slow case.
-     sd(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes())); // restore obj
-     call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
+     bind(slow_case);
+     call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), obj_reg);
  
      bind(done);
- 
      restore_bcp();
    }
  }
  
  
< prev index next >