diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/ObjectSynchronizer.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/ObjectSynchronizer.java index d0fcb48c013..f8e71aa3761 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/ObjectSynchronizer.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/ObjectSynchronizer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2023, 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 @@ -43,8 +43,10 @@ public class ObjectSynchronizer { } private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { - Type type = db.lookupType("ObjectSynchronizer"); - inUseList = type.getAddressField("_in_use_list").getValue(); + Type objectSynchronizerType = db.lookupType("ObjectSynchronizer"); + Type monitorListType = db.lookupType("MonitorList"); + Address monitorListAddr = objectSynchronizerType.getField("_in_use_list").getStaticFieldAddress(); + inUseListHead = monitorListType.getAddressField("_head").getAddress(monitorListAddr); } public long identityHashValueFor(Oop obj) { @@ -70,11 +72,7 @@ public class ObjectSynchronizer { } public static Iterator objectMonitorIterator() { - if (inUseList != null) { - return new ObjectMonitorIterator(); - } else { - return null; - } + return new ObjectMonitorIterator(); } private static class ObjectMonitorIterator implements Iterator { @@ -83,21 +81,23 @@ public class ObjectSynchronizer { // are not returned by this Iterator. ObjectMonitorIterator() { - mon = new ObjectMonitor(inUseList); + mon = inUseListHead == null ? null : new ObjectMonitor(inUseListHead); } public boolean hasNext() { - return (mon.nextOM() != null); + return (mon != null); } public Object next() { - // advance to next entry - Address monAddr = mon.nextOM(); - if (monAddr == null) { + ObjectMonitor ret = mon; + if (ret == null) { throw new NoSuchElementException(); } - mon = new ObjectMonitor(monAddr); - return mon; + // advance to next entry + Address nextMon = mon.nextOM(); + mon = nextMon == null ? null : new ObjectMonitor(nextMon); + + return ret; } public void remove() { @@ -107,6 +107,6 @@ public class ObjectSynchronizer { private ObjectMonitor mon; } - private static Address inUseList; + private static Address inUseListHead; } diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/MonitorCacheDumpPanel.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/MonitorCacheDumpPanel.java index ed3ccb2c496..ffedbc51598 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/MonitorCacheDumpPanel.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/ui/MonitorCacheDumpPanel.java @@ -94,11 +94,6 @@ public class MonitorCacheDumpPanel extends JPanel { private void dumpOn(PrintStream tty) { Iterator i = ObjectSynchronizer.objectMonitorIterator(); - if (i == null) { - tty.println("This version of HotSpot VM doesn't support monitor cache dump."); - tty.println("You need 1.4.0_04, 1.4.1_01 or later versions"); - return; - } ObjectMonitor mon; while (i.hasNext()) { mon = (ObjectMonitor)i.next(); diff --git a/test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/DynamicSharedSymbols.java b/test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/DynamicSharedSymbols.java index 24305c5a166..f07c775a003 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/DynamicSharedSymbols.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/DynamicSharedSymbols.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2023, 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 @@ -38,7 +38,7 @@ import jtreg.SkippedException; * @build JCmdTestLingeredApp Hello jdk.test.lib.apps.LingeredApp * @build jdk.test.whitebox.WhiteBox * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar loadclass.jar JCmdTestLingeredApp - * jdk.test.lib.apps.LingeredApp jdk.test.lib.apps.LingeredApp$1 + * jdk.test.lib.apps.LingeredApp jdk.test.lib.apps.LingeredApp$1 jdk.test.lib.apps.LingeredApp$SteadyStateLock * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar WhiteBox.jar jdk.test.whitebox.WhiteBox * @run main/othervm/timeout=500 -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:./WhiteBox.jar DynamicSharedSymbols */ diff --git a/test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestDumpBase.java b/test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestDumpBase.java index a18de9ea61e..ad7b8e97b81 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestDumpBase.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/jcmd/JCmdTestDumpBase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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 @@ -64,7 +64,8 @@ public abstract class JCmdTestDumpBase { private static final String TEST_CLASSES[] = {"JCmdTestLingeredApp", "jdk/test/lib/apps/LingeredApp", - "jdk/test/lib/apps/LingeredApp$1"}; + "jdk/test/lib/apps/LingeredApp$1", + "jdk/test/lib/apps/LingeredApp$SteadyStateLock"}; private static final String BOOT_CLASSES[] = {"Hello"}; protected static String testJar = null; diff --git a/test/hotspot/jtreg/serviceability/sa/TestObjectMonitorIterate.java b/test/hotspot/jtreg/serviceability/sa/TestObjectMonitorIterate.java index e2d79b1ce9d..666fa169363 100644 --- a/test/hotspot/jtreg/serviceability/sa/TestObjectMonitorIterate.java +++ b/test/hotspot/jtreg/serviceability/sa/TestObjectMonitorIterate.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2021, NTT DATA. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -82,6 +82,7 @@ public class TestObjectMonitorIterate { Long.toString(lingeredAppPid)); SATestUtils.addPrivilegesIfNeeded(processBuilder); OutputAnalyzer SAOutput = ProcessTools.executeProcess(processBuilder); + SAOutput.shouldContain("SteadyStateLock"); SAOutput.shouldHaveExitValue(0); System.out.println(SAOutput.getOutput()); } diff --git a/test/lib/jdk/test/lib/apps/LingeredApp.java b/test/lib/jdk/test/lib/apps/LingeredApp.java index 11c2181ebf9..b519083999e 100644 --- a/test/lib/jdk/test/lib/apps/LingeredApp.java +++ b/test/lib/jdk/test/lib/apps/LingeredApp.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, 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 @@ -587,6 +587,7 @@ public class LingeredApp { } } + static class SteadyStateLock {}; /** * This part is the application itself. First arg is optional "forceCrash". @@ -616,7 +617,7 @@ public class LingeredApp { Path path = Paths.get(theLockFileName); try { - Object steadyStateObj = new Object(); + Object steadyStateObj = new SteadyStateLock(); synchronized(steadyStateObj) { startSteadyStateThread(steadyStateObj); if (forceCrash) {