< prev index next >

src/hotspot/cpu/riscv/c1_MacroAssembler_riscv.cpp

Print this page
@@ -70,74 +70,87 @@
      bnez(t0, slow_case, true /* is_far */);
    }
  
    // Load object header
    ld(hdr, Address(obj, hdr_offset));
-   // and mark it as unlocked
-   ori(hdr, hdr, markWord::unlocked_value);
-   // save unlocked object header into the displaced header location on the stack
-   sd(hdr, Address(disp_hdr, 0));
-   // test if object header is still the same (i.e. unlocked), and if so, store the
-   // displaced header address in the object header - if it is not the same, get the
-   // object header instead
-   la(t1, Address(obj, hdr_offset));
-   cmpxchgptr(hdr, disp_hdr, t1, t0, done, /*fallthough*/NULL);
-   // if the object header was the same, we're done
-   // if the object header was not the same, it is now in the hdr register
-   // => test if it is a stack pointer into the same stack (recursive locking), i.e.:
-   //
-   // 1) (hdr & aligned_mask) == 0
-   // 2) sp <= hdr
-   // 3) hdr <= sp + page_size
-   //
-   // these 3 tests can be done by evaluating the following expression:
-   //
-   // (hdr -sp) & (aligned_mask - page_size)
-   //
-   // assuming both the stack pointer and page_size have their least
-   // significant 2 bits cleared and page_size is a power of 2
-   sub(hdr, hdr, sp);
-   mv(t0, aligned_mask - (int)os::vm_page_size());
-   andr(hdr, hdr, t0);
-   // for recursive locking, the result is zero => save it in the displaced header
-   // location (NULL in the displaced hdr location indicates recursive locking)
-   sd(hdr, Address(disp_hdr, 0));
-   // otherwise we don't care about the result and handle locking via runtime call
-   bnez(hdr, slow_case, /* is_far */ true);
-   // done
-   bind(done);
+ 
+   if (UseFastLocking) {
+     fast_lock(obj, hdr, t0, t1, slow_case);
+   } else {
+     // and mark it as unlocked
+     jori(hdr, hdr, markWord::unlocked_value);
+     // save unlocked object header into the displaced header location on the stack
+     sd(hdr, Address(disp_hdr, 0));
+     // test if object header is still the same (i.e. unlocked), and if so, store the
+     // displaced header address in the object header - if it is not the same, get the
+     // object header instead
+     la(t1, Address(obj, hdr_offset));
+     cmpxchgptr(hdr, disp_hdr, t1, t0, done, /*fallthough*/NULL);
+     // if the object header was the same, we're done
+     // if the object header was not the same, it is now in the hdr register
+     // => test if it is a stack pointer into the same stack (recursive locking), i.e.:
+     //
+     // 1) (hdr & aligned_mask) == 0
+     // 2) sp <= hdr
+     // 3) hdr <= sp + page_size
+     //
+     // these 3 tests can be done by evaluating the following expression:
+     //
+     // (hdr -sp) & (aligned_mask - page_size)
+     //
+     // assuming both the stack pointer and page_size have their least
+     // significant 2 bits cleared and page_size is a power of 2
+     sub(hdr, hdr, sp);
+     mv(t0, aligned_mask - (int)os::vm_page_size());
+     andr(hdr, hdr, t0);
+     // for recursive locking, the result is zero => save it in the displaced header
+     // location (NULL in the displaced hdr location indicates recursive locking)
+     sd(hdr, Address(disp_hdr, 0));
+     // otherwise we don't care about the result and handle locking via runtime call
+     bnez(hdr, slow_case, /* is_far */ true);
+     // done
+     bind(done);
+   }
    increment(Address(xthread, JavaThread::held_monitor_count_offset()));
    return null_check_offset;
  }
  
  void C1_MacroAssembler::unlock_object(Register hdr, Register obj, Register disp_hdr, Label& slow_case) {
    const int aligned_mask = BytesPerWord - 1;
    const int hdr_offset = oopDesc::mark_offset_in_bytes();
    assert(hdr != obj && hdr != disp_hdr && obj != disp_hdr, "registers must be different");
    Label done;
  
-   // load displaced header
-   ld(hdr, Address(disp_hdr, 0));
-   // if the loaded hdr is NULL we had recursive locking
-   // if we had recursive locking, we are done
-   beqz(hdr, done);
-   // load object
-   ld(obj, Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()));
-   verify_oop(obj);
-   // test if object header is pointing to the displaced header, and if so, restore
-   // the displaced header in the object - if the object header is not pointing to
-   // the displaced header, get the object header instead
-   // if the object header was not pointing to the displaced header,
-   // we do unlocking via runtime call
-   if (hdr_offset) {
-     la(t0, Address(obj, hdr_offset));
-     cmpxchgptr(disp_hdr, hdr, t0, t1, done, &slow_case);
+   if (UseFastLocking) {
+     // load object
+     ld(obj, Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()));
+     verify_oop(obj);
+     ld(hdr, Address(obj, oopDesc::mark_offset_in_bytes()));
+     fast_unlock(obj, hdr, t0, t1, slow_case);
    } else {
-     cmpxchgptr(disp_hdr, hdr, obj, t1, done, &slow_case);
+     // load displaced header
+     ld(hdr, Address(disp_hdr, 0));
+     // if the loaded hdr is NULL we had recursive locking
+     // if we had recursive locking, we are done
+     beqz(hdr, done);
+     // load object
+     ld(obj, Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()));
+     verify_oop(obj);
+     // test if object header is pointing to the displaced header, and if so, restore
+     // the displaced header in the object - if the object header is not pointing to
+     // the displaced header, get the object header instead
+     // if the object header was not pointing to the displaced header,
+     // we do unlocking via runtime call
+     if (hdr_offset) {
+       la(t0, Address(obj, hdr_offset));
+       cmpxchgptr(disp_hdr, hdr, t0, t1, done, &slow_case);
+     } else {
+       cmpxchgptr(disp_hdr, hdr, obj, t1, done, &slow_case);
+     }
+     // done
+     bind(done);
    }
-   // done
-   bind(done);
    decrement(Address(xthread, JavaThread::held_monitor_count_offset()));
  }
  
  // Defines obj, preserves var_size_in_bytes
  void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register tmp1, Register tmp2, Label& slow_case) {

@@ -303,11 +316,11 @@
    assert(!MacroAssembler::needs_explicit_null_check(oopDesc::klass_offset_in_bytes()), "must add explicit null check");
    assert_different_registers(receiver, iCache, t0, t2);
    cmp_klass(receiver, iCache, t0, t2 /* call-clobbered t2 as a tmp */, L);
  }
  
- void C1_MacroAssembler::build_frame(int framesize, int bang_size_in_bytes) {
+ void C1_MacroAssembler::build_frame(int framesize, int bang_size_in_bytes, int max_monitors) {
    assert(bang_size_in_bytes >= framesize, "stack bang size incorrect");
    // Make sure there is enough stack space for this method's activation.
    // Note that we do this before creating a frame.
    generate_stack_overflow_check(bang_size_in_bytes);
    MacroAssembler::build_frame(framesize);
< prev index next >