diff --git a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/LockSharedStrings.java b/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/LockSharedStrings.java deleted file mode 100644 index e3aaef65f72..00000000000 --- a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/LockSharedStrings.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2015, 2022, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -/* - * @test - * @summary Test locking on shared strings - * @requires vm.cds.write.archived.java.heap - * @requires vm.gc == null - * @library /test/hotspot/jtreg/runtime/cds/appcds /test/lib - * @compile LockStringTest.java LockStringValueTest.java - * @build jdk.test.whitebox.WhiteBox - * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox - * @run driver LockSharedStrings - */ - -public class LockSharedStrings { - public static void main(String[] args) throws Exception { - SharedStringsUtils.run(args, LockSharedStrings::test); - } - - public static void test(String[] args) throws Exception { - SharedStringsUtils.buildJarAndWhiteBox("LockStringTest", "LockStringValueTest"); - - SharedStringsUtils.dumpWithWhiteBox( - TestCommon.list("LockStringTest", "LockStringValueTest"), - "ExtraSharedInput.txt", "-Xlog:cds,cds+hashtables"); - - String[] extraMatch = new String[] {"LockStringTest: PASS"}; - SharedStringsUtils.runWithArchiveAndWhiteBox(extraMatch, "LockStringTest"); - - extraMatch = new String[] {"LockStringValueTest: PASS"}; - SharedStringsUtils.runWithArchiveAndWhiteBox(extraMatch, "LockStringValueTest", - "--add-opens=java.base/java.lang=ALL-UNNAMED"); - } -} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/LockStringTest.java b/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/LockStringTest.java deleted file mode 100644 index 5bba2602abf..00000000000 --- a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/LockStringTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2015, 2022, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -import jdk.test.whitebox.WhiteBox; - -public class LockStringTest extends Thread { - static String lock; - static boolean done; - static WhiteBox wb = WhiteBox.getWhiteBox(); - - public static void main(String[] args) throws Exception { - - if (!wb.areSharedStringsMapped()) { - System.out.println("The shared strings are not mapped"); - System.out.println("LockStringTest: PASS"); - return; - } - - if (!wb.isSharedClass(LockStringTest.class)) { - throw new RuntimeException("Failed: LockStringTest class is not shared."); - } - - // Note: This class is archived. All string literals (including the ones used in this class) - // in all archived classes are interned into the CDS shared string table. - - doTest("StringLock", false); - doTest("", true); - - // The following string has a 0 hashCode. Calling String.hashCode() could cause - // the String.hash field to be written into, if so make sure we don't functionally - // break. - doTest("\u0121\u0151\u00a2\u0001\u0001\udbb2", true); - } - - private static void doTest(String s, boolean hasZeroHashCode) throws Exception { - lock = s; - done = false; - - if (!wb.isSharedInternedString(lock)) { - throw new RuntimeException("Failed: String \"" + lock + "\" is not shared."); - } - - if (hasZeroHashCode && lock.hashCode() != 0) { - throw new RuntimeException("Shared string \"" + lock + "\" should have 0 hashCode, but is instead " + lock.hashCode()); - } - - String copy = new String(lock); - if (lock.hashCode() != copy.hashCode()) { - throw new RuntimeException("Shared string \"" + lock + "\" does not have the same hashCode as its non-shared copy"); - } - - new LockStringTest().start(); - - synchronized(lock) { - while (!done) { - lock.wait(); - } - } - System.gc(); - System.out.println("LockStringTest: PASS"); - } - - public void run() { - String shared = "LiveOak"; - synchronized (lock) { - for (int i = 0; i < 100; i++) { - new String(shared); - System.gc(); - try { - sleep(5); - } catch (InterruptedException e) {} - } - done = true; - lock.notify(); - } - } -} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/LockStringValueTest.java b/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/LockStringValueTest.java deleted file mode 100644 index 200890b907d..00000000000 --- a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/LockStringValueTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2015, 2022, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -import java.lang.reflect.*; -import jdk.test.whitebox.WhiteBox; - -/* - * Lock the 'value' field of a known shared string, java.lang.Object - */ -public class LockStringValueTest { - public static void main(String args[]) { - String s = "LiveOak"; - WhiteBox wb = WhiteBox.getWhiteBox(); - - if (!wb.areSharedStringsMapped()) { - System.out.println("The shared strings are not mapped"); - System.out.println("LockStringValueTest: PASS"); - return; - } - - if (!wb.isSharedInternedString(s)) { - throw new RuntimeException("LockStringValueTest Failed: String is not shared."); - } - - Class c = s.getClass(); - try { - Field f = c.getDeclaredField("value"); - f.setAccessible(true); - Object v = f.get(s); - lock(v); - } catch (NoSuchFieldException nfe) { - } catch (IllegalAccessException iae) {} - } - - public static void lock(Object o) { - synchronized (o) { - System.out.println("LockStringValueTest: PASS"); - } - } -} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/SharedStringsStress.java b/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/SharedStringsStress.java index a52f07176b7..f941cf3af07 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/SharedStringsStress.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/SharedStringsStress.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2024, 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 @@ -37,7 +37,6 @@ import java.io.PrintWriter; import jdk.test.lib.cds.CDSOptions; import jdk.test.lib.cds.CDSTestUtils; import jdk.test.lib.process.OutputAnalyzer; -import jdk.test.lib.process.ProcessTools; public class SharedStringsStress { static { @@ -69,37 +68,17 @@ public class SharedStringsStress { String vmOptionsPrefix[] = SharedStringsUtils.getChildVMOptionsPrefix(); String appJar = JarBuilder.build("SharedStringsStress", "HelloString"); - String test_cases[][] = { - // default heap size - {}, + OutputAnalyzer dumpOutput = TestCommon.dump(appJar, TestCommon.list("HelloString"), + TestCommon.concat(vmOptionsPrefix, + "-XX:SharedArchiveConfigFile=" + sharedArchiveConfigFile, + "-Xlog:gc+region+cds", + "-Xlog:gc+region=trace")); + TestCommon.checkDump(dumpOutput); + dumpOutput.shouldContain("string table array (primary)"); + dumpOutput.shouldContain("string table array (secondary)"); - // Test for handling of heap fragmentation. With sharedArchiveConfigFile, we will dump about - // 18MB of shared objects on 64 bit VM (smaller on 32-bit). - // - // During dump time, an extra copy of these objects are allocated, - // so we need about 36MB, plus a few MB for other system data. So 64MB total heap - // should be enough. - // - // The VM should executed a full GC to maximize contiguous free space and - // avoid fragmentation. - {"-Xmx64m"}, - }; - - for (String[] extra_opts: test_cases) { - vmOptionsPrefix = TestCommon.concat(vmOptionsPrefix, extra_opts); - - OutputAnalyzer dumpOutput = TestCommon.dump(appJar, TestCommon.list("HelloString"), - TestCommon.concat(vmOptionsPrefix, - "-XX:SharedArchiveConfigFile=" + sharedArchiveConfigFile, - "-Xlog:gc+region+cds", - "-Xlog:gc+region=trace")); - TestCommon.checkDump(dumpOutput); - dumpOutput.shouldContain("string table array (primary)"); - dumpOutput.shouldContain("string table array (secondary)"); - - OutputAnalyzer execOutput = TestCommon.exec(appJar, - TestCommon.concat(vmOptionsPrefix, "-Xlog:cds", "HelloString")); - TestCommon.checkExec(execOutput); - } + OutputAnalyzer execOutput = TestCommon.exec(appJar, + TestCommon.concat(vmOptionsPrefix, "-Xlog:cds", "HelloString")); + TestCommon.checkExec(execOutput); } }