Skip to content

First try of removing LockingMode #25660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/hotspot/share/prims/whitebox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
#include "runtime/javaCalls.hpp"
#include "runtime/javaThread.inline.hpp"
#include "runtime/jniHandles.inline.hpp"
#include "runtime/lightweightSynchronizer.hpp"
#include "runtime/lockStack.hpp"
#include "runtime/os.hpp"
#include "runtime/stackFrameStream.inline.hpp"
Expand Down Expand Up @@ -1902,6 +1903,20 @@ WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj))
return (jboolean) obj_oop->mark().has_monitor();
WB_END

WB_ENTRY(void, WB_ForceInflateMonitorLockedObject(JNIEnv* env, jobject wb, jobject obj))
oop obj_oop = JNIHandles::resolve(obj);
if (obj_oop->mark().has_monitor()) {
return; // Already inflated
}
ObjectSynchronizer::InflateCause cause = ObjectSynchronizer::InflateCause::inflate_cause_vm_internal;
JavaThread* current = JavaThread::current();
if (LockingMode == LM_LIGHTWEIGHT) {
LightweightSynchronizer::inflate_fast_locked_object(obj_oop, cause, current, current);
} else {
ObjectSynchronizer::inflate(current, obj_oop, cause);
}
WB_END

WB_ENTRY(jboolean, WB_IsAsanEnabled(JNIEnv* env))
return (jboolean) WhiteBox::is_asan_enabled();
WB_END
Expand Down Expand Up @@ -2906,6 +2921,7 @@ static JNINativeMethod methods[] = {
(void*)&WB_AddModuleExportsToAll },
{CC"deflateIdleMonitors", CC"()Z", (void*)&WB_DeflateIdleMonitors },
{CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated },
{CC"forceInflateMonitorLockedObject0", CC"(Ljava/lang/Object;)V", (void*)&WB_ForceInflateMonitorLockedObject },
{CC"isAsanEnabled", CC"()Z", (void*)&WB_IsAsanEnabled },
{CC"isUbsanEnabled", CC"()Z", (void*)&WB_IsUbsanEnabled },
{CC"getInUseMonitorCount", CC"()J", (void*)&WB_getInUseMonitorCount },
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/runtime/arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,7 @@ bool Arguments::check_vm_args_consistency() {

#ifndef _LP64
if (LockingMode == LM_LEGACY) {
FLAG_SET_CMDLINE(LockingMode, LM_LIGHTWEIGHT);
LockingMode = LM_LIGHTWEIGHT;
// Self-forwarding in bit 3 of the mark-word conflicts
// with 4-byte-aligned stack-locks.
warning("Legacy locking not supported on this platform");
Expand Down
7 changes: 0 additions & 7 deletions src/hotspot/share/runtime/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1953,13 +1953,6 @@ const int ObjectAlignmentInBytes = 8;
"Mark all threads after a safepoint, and clear on a modify " \
"fence. Add cleanliness checks.") \
\
product(int, LockingMode, LM_LIGHTWEIGHT, \
"(Deprecated) Select locking mode: " \
"0: (Deprecated) monitors only (LM_MONITOR), " \
"1: (Deprecated) monitors & legacy stack-locking (LM_LEGACY), " \
"2: monitors & new lightweight locking (LM_LIGHTWEIGHT, default)") \
range(0, 2) \
\
product(bool, UseObjectMonitorTable, false, DIAGNOSTIC, \
"With Lightweight Locking mode, use a table to record inflated " \
"monitors rather than the first word of the object.") \
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/utilities/globalDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ int LogMinObjAlignmentInBytes = -1;
// Oop encoding heap max
uint64_t OopEncodingHeapMax = 0;

int LockingMode = LM_LIGHTWEIGHT;

// Something to help porters sleep at night

#ifdef ASSERT
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/utilities/globalDefinitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,8 @@ enum LockingMode {
LM_LIGHTWEIGHT = 2
};

extern int LockingMode;

//----------------------------------------------------------------------------------------------------
// Special constants for debugging

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -222,29 +222,18 @@ private JavaThread owningThreadFromMonitor(Address o) {

public JavaThread owningThreadFromMonitor(ObjectMonitor monitor) {
if (monitor.isOwnedAnonymous()) {
if (VM.getVM().getCommandLineFlag("LockingMode").getInt() == LockingMode.getLightweight()) {
OopHandle object = monitor.object();
for (int i = 0; i < getNumberOfThreads(); i++) {
JavaThread thread = getJavaThreadAt(i);
if (thread.isLockOwned(object)) {
return thread;
}
}
// We should have found the owner, however, as the VM could be in any state, including the middle
// of performing GC, it is not always possible to do so. Just return null if we can't locate it.
System.out.println("Warning: We failed to find a thread that owns an anonymous lock. This is likely");
System.out.println("due to the JVM currently running a GC. Locking information may not be accurate.");
return null;
} else {
assert(VM.getVM().getCommandLineFlag("LockingMode").getInt() == LockingMode.getLegacy());
Address o = (Address)monitor.stackLocker();
for (int i = 0; i < getNumberOfThreads(); i++) {
JavaThread thread = getJavaThreadAt(i);
if (thread.isLockOwned(o))
return thread;
}
return null;
OopHandle object = monitor.object();
for (int i = 0; i < getNumberOfThreads(); i++) {
JavaThread thread = getJavaThreadAt(i);
if (thread.isLockOwned(object)) {
return thread;
}
}
// We should have found the owner, however, as the VM could be in any state, including the middle
// of performing GC, it is not always possible to do so. Just return null if we can't locate it.
System.out.println("Warning: We failed to find a thread that owns an anonymous lock. This is likely");
System.out.println("due to the JVM currently running a GC. Locking information may not be accurate.");
return null;
} else {
return owningThreadFromMonitor(monitor.owner());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -26,9 +26,6 @@
* @bug 8337660
* @summary Test that C2 does not remove blocks with BoxLock nodes that are
* otherwise empty.
* @run main/othervm -Xbatch -XX:LockingMode=1
* -XX:CompileOnly=compiler.locks.TestSynchronizeWithEmptyBlock::*
* compiler.locks.TestSynchronizeWithEmptyBlock
* @run main/othervm -Xbatch
* -XX:CompileOnly=compiler.locks.TestSynchronizeWithEmptyBlock::*
* compiler.locks.TestSynchronizeWithEmptyBlock
Expand Down
6 changes: 3 additions & 3 deletions test/hotspot/jtreg/gtest/LockStackGtests.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,10 +23,10 @@
*/

/* @test
* @summary Run LockStack gtests with LockingMode=2
* @summary Run LockStack gtests
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.xml
* @requires vm.flagless
* @run main/native GTestWrapper --gtest_filter=LockStackTest* -XX:LockingMode=2
* @run main/native GTestWrapper --gtest_filter=LockStackTest*
*/
11 changes: 8 additions & 3 deletions test/hotspot/jtreg/runtime/Monitor/ConcurrentDeflation.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,6 +24,7 @@
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.Platform;
import jdk.test.lib.process.ProcessTools;
import jdk.test.whitebox.WhiteBox;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
Expand All @@ -33,11 +34,14 @@
* @test
* @bug 8318757
* @summary Test concurrent monitor deflation by MonitorDeflationThread and thread dumping
* @library /test/lib
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:GuaranteedAsyncDeflationInterval=2000 -XX:LockingMode=0 ConcurrentDeflation
* @library /test/lib /
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:GuaranteedAsyncDeflationInterval=2000 -XX:+WhiteBoxAPI ConcurrentDeflation
*/

public class ConcurrentDeflation {
static final WhiteBox WB = WhiteBox.getWhiteBox();
public static final long TOTAL_RUN_TIME_NS = 10_000_000_000L;
public static Object[] monitors = new Object[1000];
public static int monitorCount;
Expand Down Expand Up @@ -73,6 +77,7 @@ static private void createMonitors() {
index = index++ % 1000;
monitors[index] = new Object();
synchronized (monitors[index]) {
WB.forceInflateMonitorLockedObject(monitors[index]);
monitorCount++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,6 @@
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -Xint
* -XX:LockingMode=0
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 1
*
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -Xint
* -XX:LockingMode=1
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 1
*
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -Xint
* -XX:LockingMode=2
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 1
*/
Expand All @@ -63,21 +48,6 @@
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -Xint
* -XX:LockingMode=0
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 2
*
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -Xint
* -XX:LockingMode=1
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 2
*
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -Xint
* -XX:LockingMode=2
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 2
*/
Expand All @@ -94,21 +64,6 @@
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:TieredStopAtLevel=1
* -XX:LockingMode=0
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 1
*
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:TieredStopAtLevel=1
* -XX:LockingMode=1
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 1
*
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:TieredStopAtLevel=1
* -XX:LockingMode=2
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 1
*/
Expand All @@ -125,21 +80,6 @@
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:TieredStopAtLevel=1
* -XX:LockingMode=0
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 2
*
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:TieredStopAtLevel=1
* -XX:LockingMode=1
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 2
*
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:TieredStopAtLevel=1
* -XX:LockingMode=2
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 2
*/
Expand All @@ -156,21 +96,6 @@
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:-EliminateNestedLocks
* -XX:LockingMode=0
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 1
*
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:-EliminateNestedLocks
* -XX:LockingMode=1
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 1
*
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:-EliminateNestedLocks
* -XX:LockingMode=2
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 1
*/
Expand All @@ -182,25 +107,10 @@
* @summary Tests recursive locking in C2 in alternate A and B mode.
* @library /testlibrary /test/lib
* @build jdk.test.whitebox.WhiteBox
*
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:LockingMode=0
* -XX:-EliminateNestedLocks
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 2
*
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:LockingMode=1
* -XX:-EliminateNestedLocks
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 2
*
* @run main/othervm/timeout=240 -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:LockingMode=2
* -XX:-EliminateNestedLocks
* -Xms256m -Xmx256m
* TestRecursiveLocking 120 2
Expand Down
Loading