< prev index next >

src/hotspot/cpu/riscv/interp_masm_riscv.cpp

Print this page
@@ -807,45 +807,51 @@
        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, count, /*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 - (int)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, count);
+     if (UseFastLocking) {
+       ld(tmp, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
+       fast_lock(obj_reg, tmp, t0, t1, slow_case);
+       j(count);
+     } else {
+       // 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, count, /*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 - (int)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, count);
+     }
  
      bind(slow_case);
  
      // Call the runtime routine for slow case
      call_VM(noreg,
              CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
-             lock_reg);
+             UseFastLocking ? obj_reg : lock_reg);
  
      j(done);
  
      bind(count);
      increment(Address(xthread, JavaThread::held_monitor_count_offset()));

@@ -879,29 +885,51 @@
      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()));
+     if (UseFastLocking) {
+       Label slow_case;
+       // Load oop into obj_reg(c_rarg3)
+       ld(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()));
  
-     // 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()));
  
-     // Free entry
-     sd(zr, 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.
+       Register tmp = header_reg;
+       ld(tmp, Address(xthread, JavaThread::lock_stack_current_offset()));
+       ld(tmp, Address(tmp, -oopSize));
+       bne(tmp, obj_reg, slow_case);
  
-     // Load the old header from BasicLock structure
-     ld(header_reg, Address(swap_reg,
-                            BasicLock::displaced_header_offset_in_bytes()));
+       ld(header_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
+       fast_unlock(obj_reg, header_reg, swap_reg, t0, slow_case);
+       j(count);
+ 
+       bind(slow_case);
+     } else {
+       // 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()));
  
-     // Test for recursion
-     beqz(header_reg, count);
+       // Load oop into obj_reg(c_rarg3)
+       ld(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()));
  
-     // Atomic swap back the old header
-     cmpxchg_obj_header(swap_reg, header_reg, obj_reg, t0, count, /*fallthrough*/NULL);
+       // 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, count);
+ 
+       // Atomic swap back the old header
+       cmpxchg_obj_header(swap_reg, header_reg, obj_reg, t0, count, /*fallthrough*/NULL);
+     }
  
      // 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);
  
< prev index next >