Skip to content

Commit

Permalink
fix monitor count
Browse files Browse the repository at this point in the history
  • Loading branch information
pchilano committed Oct 7, 2024
1 parent 05f6208 commit c57132f
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 51 deletions.
2 changes: 2 additions & 0 deletions src/hotspot/cpu/x86/assembler_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2844,6 +2844,7 @@ void Assembler::leal(Register dst, Address src) {
emit_operand(dst, src, 0);
}

#ifdef _LP64
void Assembler::lea(Register dst, Label& L) {
assert(dst == r10, "invalid destination register");
if (L.is_bound()) {
Expand All @@ -2863,6 +2864,7 @@ void Assembler::lea(Register dst, Label& L) {
emit_int32(0);
}
}
#endif

void Assembler::lfence() {
emit_int24(0x0F, (unsigned char)0xAE, (unsigned char)0xE8);
Expand Down
8 changes: 3 additions & 5 deletions src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,10 @@ void C2_MacroAssembler::fast_lock(Register objReg, Register boxReg, Register tmp
jccb(Assembler::notZero, NO_COUNT); // jump if ZFlag == 0

bind(COUNT);
#ifdef _LP64
// Count monitors in fast path
increment(Address(thread, JavaThread::held_monitor_count_offset()));

#endif
xorl(tmpReg, tmpReg); // Set ZF == 1

bind(NO_COUNT);
Expand Down Expand Up @@ -526,10 +527,7 @@ void C2_MacroAssembler::fast_unlock(Register objReg, Register boxReg, Register t

if (LockingMode == LM_LEGACY) {
// Count monitors in fast path
#ifndef _LP64
get_thread(tmpReg);
decrementl(Address(tmpReg, JavaThread::held_monitor_count_offset()));
#else // _LP64
#ifdef _LP64
decrementq(Address(r15_thread, JavaThread::held_monitor_count_offset()));
#endif
}
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/cpu/x86/globalDefinitions_x86.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ const bool CCallingConventionRequiresIntsAsLongs = false;

#define SUPPORTS_NATIVE_CX8

#ifdef _LP64
#define SUPPORT_MONITOR_COUNT
#endif

#define CPU_MULTI_COPY_ATOMIC

Expand Down
16 changes: 2 additions & 14 deletions src/hotspot/cpu/x86/macroAssembler_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3033,25 +3033,13 @@ void MacroAssembler::pop_cont_fastpath() {
}

void MacroAssembler::inc_held_monitor_count() {
#ifndef _LP64
Register thread = rax;
push(thread);
get_thread(thread);
incrementl(Address(thread, JavaThread::held_monitor_count_offset()));
pop(thread);
#else // LP64
#ifdef _LP64
incrementq(Address(r15_thread, JavaThread::held_monitor_count_offset()));
#endif
}

void MacroAssembler::dec_held_monitor_count() {
#ifndef _LP64
Register thread = rax;
push(thread);
get_thread(thread);
decrementl(Address(thread, JavaThread::held_monitor_count_offset()));
pop(thread);
#else // LP64
#ifdef _LP64
decrementq(Address(r15_thread, JavaThread::held_monitor_count_offset()));
#endif
}
Expand Down
2 changes: 0 additions & 2 deletions src/hotspot/cpu/zero/globalDefinitions_zero.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
// The default padding size for data structures to avoid false sharing.
#define DEFAULT_PADDING_SIZE DEFAULT_CACHE_LINE_SIZE

#define SUPPORT_MONITOR_COUNT

#include <ffi.h>

// Indicates whether the C calling conventions require that
Expand Down
6 changes: 0 additions & 6 deletions src/hotspot/cpu/zero/zeroInterpreter_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,6 @@ int ZeroInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) {
success = false;
}
}
if (success) {
THREAD->inc_held_monitor_count();
}
}
if (!success) {
CALL_VM_NOCHECK(InterpreterRuntime::monitorenter(thread, monitor));
Expand Down Expand Up @@ -499,9 +496,6 @@ int ZeroInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) {
success = false;
}
}
if (success) {
THREAD->dec_held_monitor_count();
}
}
if (!success) {
InterpreterRuntime::monitorexit(monitor);
Expand Down
18 changes: 0 additions & 18 deletions src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,6 @@ void BytecodeInterpreter::run(interpreterState istate) {
success = false;
}
}
if (success) {
THREAD->inc_held_monitor_count();
}
}
if (!success) {
CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
Expand Down Expand Up @@ -745,9 +742,6 @@ void BytecodeInterpreter::run(interpreterState istate) {
success = false;
}
}
if (success) {
THREAD->inc_held_monitor_count();
}
}
if (!success) {
CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
Expand Down Expand Up @@ -1680,9 +1674,6 @@ void BytecodeInterpreter::run(interpreterState istate) {
success = false;
}
}
if (success) {
THREAD->inc_held_monitor_count();
}
}
if (!success) {
CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
Expand Down Expand Up @@ -1720,9 +1711,6 @@ void BytecodeInterpreter::run(interpreterState istate) {
success = false;
}
}
if (success) {
THREAD->dec_held_monitor_count();
}
}
if (!success) {
InterpreterRuntime::monitorexit(most_recent);
Expand Down Expand Up @@ -3163,9 +3151,6 @@ void BytecodeInterpreter::run(interpreterState istate) {
success = false;
}
}
if (success) {
THREAD->dec_held_monitor_count();
}
}
if (!success) {
InterpreterRuntime::monitorexit(end);
Expand Down Expand Up @@ -3242,9 +3227,6 @@ void BytecodeInterpreter::run(interpreterState istate) {
}
}
}
if (dec_monitor_count) {
THREAD->dec_held_monitor_count();
}
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/hotspot/share/runtime/javaThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2009,16 +2009,17 @@ void JavaThread::trace_stack() {
// Slow-path increment of the held monitor counts. JNI locking is always
// this slow-path.
void JavaThread::inc_held_monitor_count(intx i, bool jni) {
#ifdef SUPPORT_MONITOR_COUNT

#ifdef LOOM_MONITOR_SUPPORT
if (LockingMode != LM_LEGACY) {
// Nothing to do. Just do some sanity check.
assert(_held_monitor_count == 0, "counter should not be used");
assert(_jni_monitor_count == 0, "counter should not be used");
return;
}
#endif
#endif // LOOM_MONITOR_SUPPORT

#ifdef SUPPORT_MONITOR_COUNT
assert(_held_monitor_count >= 0, "Must always be non-negative: " INTX_FORMAT, _held_monitor_count);
_held_monitor_count += i;
if (jni) {
Expand All @@ -2027,22 +2028,23 @@ void JavaThread::inc_held_monitor_count(intx i, bool jni) {
}
assert(_held_monitor_count >= _jni_monitor_count, "Monitor count discrepancy detected - held count "
INTX_FORMAT " is less than JNI count " INTX_FORMAT, _held_monitor_count, _jni_monitor_count);
#endif
#endif // SUPPORT_MONITOR_COUNT
}

// Slow-path decrement of the held monitor counts. JNI unlocking is always
// this slow-path.
void JavaThread::dec_held_monitor_count(intx i, bool jni) {
#ifdef SUPPORT_MONITOR_COUNT

#ifdef LOOM_MONITOR_SUPPORT
if (LockingMode != LM_LEGACY) {
// Nothing to do. Just do some sanity check.
assert(_held_monitor_count == 0, "counter should not be used");
assert(_jni_monitor_count == 0, "counter should not be used");
return;
}
#endif
#endif // LOOM_MONITOR_SUPPORT

#ifdef SUPPORT_MONITOR_COUNT
_held_monitor_count -= i;
assert(_held_monitor_count >= 0, "Must always be non-negative: " INTX_FORMAT, _held_monitor_count);
if (jni) {
Expand All @@ -2055,7 +2057,7 @@ void JavaThread::dec_held_monitor_count(intx i, bool jni) {
// JNI count is directly set to zero.
assert(_held_monitor_count >= _jni_monitor_count || is_exiting(), "Monitor count discrepancy detected - held count "
INTX_FORMAT " is less than JNI count " INTX_FORMAT, _held_monitor_count, _jni_monitor_count);
#endif
#endif // SUPPORT_MONITOR_COUNT
}

frame JavaThread::vthread_last_frame() {
Expand Down

0 comments on commit c57132f

Please sign in to comment.