RFR: 8319797: Recursive lightweight locking: Runtime implementation [v4]
David Holmes
dholmes at openjdk.org
Tue Nov 14 22:28:29 UTC 2023
On Mon, 13 Nov 2023 09:59:03 GMT, Axel Boldt-Christmas <aboldtch at openjdk.org> wrote:
>> src/hotspot/share/runtime/synchronizer.cpp line 609:
>>
>>> 607: return;
>>> 608: } else if (mark.is_fast_locked() && lock_stack.is_recursive(object)) {
>>> 609: // This lock is recursive but unstructured exit. Just inflate the lock.
>>
>> Again this seems in the wrong place - this should be a very rare case so we should not be checking it explicitly before the expected cases!
>
> In exit we must always check for recursions first. Unsure what you are proposing here.
>
> Maybe you want to call remove first, and have a branch on if the number removed is greater than 1. And in that case inflate an update the recessions field before falling through. Something like this:
> ```c++
> // Fast-locking does not use the 'lock' argument.
> LockStack& lock_stack = current->lock_stack();
> if (mark.is_fast_locked()) {
> if (lock_stack.try_recursive_exit(object)) {
> // Recursively unlocked.
> return;
> }
>
> size_t recursions = lock_stack.remove(object) - 1;
>
> if (recursions == 0) {
> while (mark.is_fast_locked()) {
> const markWord new_mark = mark.set_unlocked();
> const markWord old_mark = mark;
> mark = object->cas_set_mark(new_mark, old_mark);
> if (old_mark == mark) {
> return;
> }
> }
> }
>
> lock_stack.push(object);
> ObjectMonitor* mon = inflate(current, object, inflate_cause_vm_internal);
> if (mon->is_owner_anonymous()) {
> mon->set_owner_from_anonymous(current);
> }
> mon->set_recursions(recursions);
> }
>
>
> This make the code a little more like the emitted code. Except it is conditioned on the mark word lock bits.
> Hard to believe this will have a measurable difference. But at least to me it is more noisy.
It wasn't the recursions I was querying but the unstructured locking aspect.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/16606#discussion_r1393385025
More information about the hotspot-dev
mailing list