diff --git a/src/hotspot/cpu/zero/globalDefinitions_zero.hpp b/src/hotspot/cpu/zero/globalDefinitions_zero.hpp index 271d95ee72c..128aaec7350 100644 --- a/src/hotspot/cpu/zero/globalDefinitions_zero.hpp +++ b/src/hotspot/cpu/zero/globalDefinitions_zero.hpp @@ -32,7 +32,7 @@ #define SUPPORT_MONITOR_COUNT -#ifdef __APPLE__ +#if defined(__APPLE__) && !defined(FFI_GO_CLOSURES) #define FFI_GO_CLOSURES 0 #endif diff --git a/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp b/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp index d92b43f0ea5..6c9c3f81777 100644 --- a/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp +++ b/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp @@ -331,19 +331,26 @@ int ZeroInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) { if (method->is_synchronized()) { monitor = (BasicObjectLock*) istate->stack_base(); oop lockee = monitor->obj(); - markWord disp = lockee->mark().set_unlocked(); - monitor->lock()->set_displaced_header(disp); - bool call_vm = (LockingMode == LM_MONITOR); bool inc_monitor_count = true; - if (call_vm || lockee->cas_set_mark(markWord::from_pointer(monitor), disp) != disp) { - // Is it simple recursive case? - if (!call_vm && thread->is_lock_owned((address) disp.clear_lock_bits().to_pointer())) { - monitor->lock()->set_displaced_header(markWord::from_pointer(nullptr)); - } else { - inc_monitor_count = false; - CALL_VM_NOCHECK(InterpreterRuntime::monitorenter(thread, monitor)); - if (HAS_PENDING_EXCEPTION) - goto unwind_and_return; + if (LockingMode == LM_LIGHTWEIGHT) { + inc_monitor_count = false; + CALL_VM_NOCHECK(InterpreterRuntime::monitorenter_obj(thread, lockee)); + if (HAS_PENDING_EXCEPTION) + goto unwind_and_return; + } else { + markWord disp = lockee->mark().set_unlocked(); + monitor->lock()->set_displaced_header(disp); + bool call_vm = (LockingMode == LM_MONITOR); + if (call_vm || lockee->cas_set_mark(markWord::from_pointer(monitor), disp) != disp) { + // Is it simple recursive case? + if (!call_vm && thread->is_lock_owned((address) disp.clear_lock_bits().to_pointer())) { + monitor->lock()->set_displaced_header(markWord::from_pointer(nullptr)); + } else { + inc_monitor_count = false; + CALL_VM_NOCHECK(InterpreterRuntime::monitorenter(thread, monitor)); + if (HAS_PENDING_EXCEPTION) + goto unwind_and_return; + } } } if (inc_monitor_count) { @@ -479,18 +486,23 @@ int ZeroInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) { // Unlock if necessary if (monitor) { - BasicLock *lock = monitor->lock(); - markWord header = lock->displaced_header(); - oop rcvr = monitor->obj(); - monitor->set_obj(nullptr); - bool dec_monitor_count = true; - if (header.to_pointer() != nullptr) { - markWord old_header = markWord::encode(lock); - if (rcvr->cas_set_mark(header, old_header) != old_header) { - monitor->set_obj(rcvr); - dec_monitor_count = false; - InterpreterRuntime::monitorexit(monitor); + if (LockingMode == LM_LIGHTWEIGHT) { + dec_monitor_count = false; + InterpreterRuntime::monitorexit(monitor); + } else { + BasicLock *lock = monitor->lock(); + markWord header = lock->displaced_header(); + oop rcvr = monitor->obj(); + monitor->set_obj(nullptr); + + if (header.to_pointer() != nullptr) { + markWord old_header = markWord::encode(lock); + if (rcvr->cas_set_mark(header, old_header) != old_header) { + monitor->set_obj(rcvr); + dec_monitor_count = false; + InterpreterRuntime::monitorexit(monitor); + } } } if (dec_monitor_count) { diff --git a/src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp b/src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp index 92587394a8e..a8a269f956d 100644 --- a/src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp +++ b/src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp @@ -617,22 +617,27 @@ void BytecodeInterpreter::run(interpreterState istate) { VERIFY_OOP(rcvr); } - // The initial monitor is ours for the taking. - BasicObjectLock* mon = &istate->monitor_base()[-1]; - mon->set_obj(rcvr); - - // Traditional lightweight locking. - markWord displaced = rcvr->mark().set_unlocked(); - mon->lock()->set_displaced_header(displaced); - bool call_vm = (LockingMode == LM_MONITOR); bool inc_monitor_count = true; - if (call_vm || rcvr->cas_set_mark(markWord::from_pointer(mon), displaced) != displaced) { - // Is it simple recursive case? - if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) { - mon->lock()->set_displaced_header(markWord::from_pointer(nullptr)); - } else { - inc_monitor_count = false; - CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception); + if (LockingMode == LM_LIGHTWEIGHT) { + inc_monitor_count = false; + CALL_VM(InterpreterRuntime::monitorenter_obj(THREAD, rcvr), handle_exception); + } else { + // The initial monitor is ours for the taking. + BasicObjectLock* mon = &istate->monitor_base()[-1]; + mon->set_obj(rcvr); + + // Traditional lightweight locking. + markWord displaced = rcvr->mark().set_unlocked(); + mon->lock()->set_displaced_header(displaced); + bool call_vm = (LockingMode == LM_MONITOR); + if (call_vm || rcvr->cas_set_mark(markWord::from_pointer(mon), displaced) != displaced) { + // Is it simple recursive case? + if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) { + mon->lock()->set_displaced_header(markWord::from_pointer(nullptr)); + } else { + inc_monitor_count = false; + CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception); + } } } if (inc_monitor_count) { @@ -714,24 +719,30 @@ void BytecodeInterpreter::run(interpreterState istate) { // we expect to find newly allocated monitor at the "top" of the monitor stack. oop lockee = STACK_OBJECT(-1); VERIFY_OOP(lockee); - // derefing's lockee ought to provoke implicit null check - // find a free monitor - BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base(); - assert(entry->obj() == nullptr, "Frame manager didn't allocate the monitor"); - entry->set_obj(lockee); - - // traditional lightweight locking - markWord displaced = lockee->mark().set_unlocked(); - entry->lock()->set_displaced_header(displaced); - bool call_vm = (LockingMode == LM_MONITOR); + bool inc_monitor_count = true; - if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) { - // Is it simple recursive case? - if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) { - entry->lock()->set_displaced_header(markWord::from_pointer(nullptr)); - } else { - inc_monitor_count = false; - CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception); + if (LockingMode == LM_LIGHTWEIGHT) { + inc_monitor_count = false; + CALL_VM(InterpreterRuntime::monitorenter_obj(THREAD, lockee), handle_exception); + } else { + // derefing's lockee ought to provoke implicit null check + // find a free monitor + BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base(); + assert(entry->obj() == nullptr, "Frame manager didn't allocate the monitor"); + entry->set_obj(lockee); + + // traditional lightweight locking + markWord displaced = lockee->mark().set_unlocked(); + entry->lock()->set_displaced_header(displaced); + bool call_vm = (LockingMode == LM_MONITOR); + if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) { + // Is it simple recursive case? + if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) { + entry->lock()->set_displaced_header(markWord::from_pointer(nullptr)); + } else { + inc_monitor_count = false; + CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception); + } } } if (inc_monitor_count) { @@ -1648,20 +1659,26 @@ run: most_recent++; } if (entry != nullptr) { - entry->set_obj(lockee); - // traditional lightweight locking - markWord displaced = lockee->mark().set_unlocked(); - entry->lock()->set_displaced_header(displaced); - bool call_vm = (LockingMode == LM_MONITOR); bool inc_monitor_count = true; - if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) { - // Is it simple recursive case? - if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) { - entry->lock()->set_displaced_header(markWord::from_pointer(nullptr)); - } else { - inc_monitor_count = false; - CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception); + if (LockingMode == LM_LIGHTWEIGHT) { + inc_monitor_count = false; + CALL_VM(InterpreterRuntime::monitorenter_obj(THREAD, lockee), handle_exception); + } else { + entry->set_obj(lockee); + + // traditional lightweight locking + markWord displaced = lockee->mark().set_unlocked(); + entry->lock()->set_displaced_header(displaced); + bool call_vm = (LockingMode == LM_MONITOR); + if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) { + // Is it simple recursive case? + if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) { + entry->lock()->set_displaced_header(markWord::from_pointer(nullptr)); + } else { + inc_monitor_count = false; + CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception); + } } } if (inc_monitor_count) { @@ -1683,20 +1700,26 @@ run: BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base(); while (most_recent != limit ) { if ((most_recent)->obj() == lockee) { - BasicLock* lock = most_recent->lock(); - markWord header = lock->displaced_header(); - most_recent->set_obj(nullptr); - - // If it isn't recursive we either must swap old header or call the runtime bool dec_monitor_count = true; - bool call_vm = (LockingMode == LM_MONITOR); - if (header.to_pointer() != nullptr || call_vm) { - markWord old_header = markWord::encode(lock); - if (call_vm || lockee->cas_set_mark(header, old_header) != old_header) { - // restore object for the slow case - most_recent->set_obj(lockee); - dec_monitor_count = false; - InterpreterRuntime::monitorexit(most_recent); + if (LockingMode == LM_LIGHTWEIGHT) { + dec_monitor_count = false; + InterpreterRuntime::monitorexit(most_recent); + } else { + BasicLock *lock = most_recent->lock(); + markWord header = lock->displaced_header(); + most_recent->set_obj(nullptr); + + // If it isn't recursive we either must swap old header or call the runtime + bool dec_monitor_count = true; + bool call_vm = (LockingMode == LM_MONITOR); + if (header.to_pointer() != nullptr || call_vm) { + markWord old_header = markWord::encode(lock); + if (call_vm || lockee->cas_set_mark(header, old_header) != old_header) { + // restore object for the slow case + most_recent->set_obj(lockee); + dec_monitor_count = false; + InterpreterRuntime::monitorexit(most_recent); + } } } if (dec_monitor_count) { @@ -3125,19 +3148,24 @@ run: while (end < base) { oop lockee = end->obj(); if (lockee != nullptr) { - BasicLock* lock = end->lock(); - markWord header = lock->displaced_header(); - end->set_obj(nullptr); - - // If it isn't recursive we either must swap old header or call the runtime bool dec_monitor_count = true; - if (header.to_pointer() != nullptr) { - markWord old_header = markWord::encode(lock); - if (lockee->cas_set_mark(header, old_header) != old_header) { - // restore object for the slow case - end->set_obj(lockee); - dec_monitor_count = false; - InterpreterRuntime::monitorexit(end); + if (LockingMode == LM_LIGHTWEIGHT) { + dec_monitor_count = false; + InterpreterRuntime::monitorexit(end); + } else { + BasicLock *lock = end->lock(); + markWord header = lock->displaced_header(); + end->set_obj(nullptr); + + // If it isn't recursive we either must swap old header or call the runtime + if (header.to_pointer() != nullptr) { + markWord old_header = markWord::encode(lock); + if (lockee->cas_set_mark(header, old_header) != old_header) { + // restore object for the slow case + end->set_obj(lockee); + dec_monitor_count = false; + InterpreterRuntime::monitorexit(end); + } } } if (dec_monitor_count) { @@ -3189,7 +3217,7 @@ run: illegal_state_oop = Handle(THREAD, THREAD->pending_exception()); THREAD->clear_pending_exception(); } - } else if (LockingMode == LM_MONITOR) { + } else if (LockingMode != LM_LEGACY) { InterpreterRuntime::monitorexit(base); if (THREAD->has_pending_exception()) { if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception()); diff --git a/src/hotspot/share/runtime/globals.hpp b/src/hotspot/share/runtime/globals.hpp index 7331008e772..e53f7a28fb5 100644 --- a/src/hotspot/share/runtime/globals.hpp +++ b/src/hotspot/share/runtime/globals.hpp @@ -1979,7 +1979,7 @@ const int ObjectAlignmentInBytes = 8; "Mark all threads after a safepoint, and clear on a modify " \ "fence. Add cleanliness checks.") \ \ - product(int, LockingMode, LM_LEGACY, EXPERIMENTAL, \ + product(int, LockingMode, LM_LIGHTWEIGHT, EXPERIMENTAL, \ "Select locking mode: " \ "0: monitors only (LM_MONITOR), " \ "1: monitors & legacy stack-locking (LM_LEGACY, default), " \ diff --git a/src/java.base/share/native/libfallbackLinker/fallbackLinker.c b/src/java.base/share/native/libfallbackLinker/fallbackLinker.c index d2058ce0899..25a8faba333 100644 --- a/src/java.base/share/native/libfallbackLinker/fallbackLinker.c +++ b/src/java.base/share/native/libfallbackLinker/fallbackLinker.c @@ -25,6 +25,12 @@ #include "jdk_internal_foreign_abi_fallback_LibFallback.h" +// This is similar to globalDefinitions_zero.hpp, which is not accessible +// from JDK libraries. Copy-paste it here. +#if defined(__APPLE__) && !defined(FFI_GO_CLOSURES) +#define FFI_GO_CLOSURES 0 +#endif + #include #include