diff --git a/src/hotspot/share/prims/whitebox.cpp b/src/hotspot/share/prims/whitebox.cpp index 35e0b83d25f..1a440584fe1 100644 --- a/src/hotspot/share/prims/whitebox.cpp +++ b/src/hotspot/share/prims/whitebox.cpp @@ -2215,25 +2215,10 @@ WB_ENTRY(jboolean, WB_CDSMemoryMappingFailed(JNIEnv* env, jobject wb)) return FileMapInfo::memory_mapping_failed(); WB_END -WB_ENTRY(jboolean, WB_IsSharedInternedString(JNIEnv* env, jobject wb, jobject str)) - if (!HeapShared::is_loading_mapping_mode()) { - return false; - } - ResourceMark rm(THREAD); - oop str_oop = JNIHandles::resolve(str); - int length; - jchar* chars = java_lang_String::as_unicode_string(str_oop, length, CHECK_(false)); - return StringTable::lookup_shared(chars, length) == str_oop; -WB_END - WB_ENTRY(jboolean, WB_IsSharedClass(JNIEnv* env, jobject wb, jclass clazz)) return (jboolean)AOTMetaspace::in_aot_cache(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz))); WB_END -WB_ENTRY(jboolean, WB_AreSharedStringsMapped(JNIEnv* env)) - return AOTMappedHeapLoader::is_mapped(); -WB_END - WB_ENTRY(void, WB_LinkClass(JNIEnv* env, jobject wb, jclass clazz)) Klass *k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)); if (!k->is_instance_klass()) { @@ -3058,9 +3043,7 @@ static JNINativeMethod methods[] = { {CC"getCDSGenericHeaderMinVersion", CC"()I", (void*)&WB_GetCDSGenericHeaderMinVersion}, {CC"getCurrentCDSVersion", CC"()I", (void*)&WB_GetCDSCurrentVersion}, {CC"isSharingEnabled", CC"()Z", (void*)&WB_IsSharingEnabled}, - {CC"isSharedInternedString", CC"(Ljava/lang/String;)Z", (void*)&WB_IsSharedInternedString }, {CC"isSharedClass", CC"(Ljava/lang/Class;)Z", (void*)&WB_IsSharedClass }, - {CC"areSharedStringsMapped", CC"()Z", (void*)&WB_AreSharedStringsMapped }, {CC"linkClass", CC"(Ljava/lang/Class;)V", (void*)&WB_LinkClass}, {CC"areOpenArchiveHeapObjectsMapped", CC"()Z", (void*)&WB_AreOpenArchiveHeapObjectsMapped}, {CC"isCDSIncluded", CC"()Z", (void*)&WB_IsCDSIncluded }, diff --git a/test/hotspot/jtreg/runtime/cds/DumpSymbolAndStringTable.java b/test/hotspot/jtreg/runtime/cds/DumpSymbolAndStringTable.java index 735d5a3070b..f606f242cf6 100644 --- a/test/hotspot/jtreg/runtime/cds/DumpSymbolAndStringTable.java +++ b/test/hotspot/jtreg/runtime/cds/DumpSymbolAndStringTable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2026, 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 @@ -24,70 +24,26 @@ /* * @test * @bug 8059510 8213445 - * @summary Test jcmd VM.symboltable, VM.stringtable and VM.systemdictionary options + * @summary Test jcmd VM.symboltable and VM.stringtable * @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:+WhiteBoxAPI DumpSymbolAndStringTable + * @run main/othervm DumpSymbolAndStringTable */ import jdk.test.lib.cds.CDSTestUtils; import jdk.test.lib.dcmd.PidJcmdExecutor; import jdk.test.lib.process.OutputAnalyzer; -import jdk.test.whitebox.WhiteBox; public class DumpSymbolAndStringTable { - public static void main(String[] args) throws Exception { - WhiteBox wb = WhiteBox.getWhiteBox(); - boolean sharingEnabled = wb.isSharingEnabled(); + public static final String s = "MY_INTERNED_STRING"; + public static void main(String[] args) throws Exception { ProcessBuilder pb = new ProcessBuilder(); + pb.command(new PidJcmdExecutor().getCommandLine("VM.symboltable", "-verbose")); OutputAnalyzer output = CDSTestUtils.executeAndLog(pb, "jcmd-symboltable"); - final String sharedSymbolsHeader = "Shared symbols:\n"; - try { - output.shouldContain("24 2: DumpSymbolAndStringTable\n"); - if (sharingEnabled) { - output.shouldContain(sharedSymbolsHeader); - output.shouldContain("17 65535: java.lang.runtime\n"); - } - } catch (RuntimeException e) { - output.shouldContain("Unknown diagnostic command"); - } + output.shouldContain("18 1: MY_INTERNED_STRING\n"); // This symbol should have been interned pb.command(new PidJcmdExecutor().getCommandLine("VM.stringtable", "-verbose")); output = CDSTestUtils.executeAndLog(pb, "jcmd-stringtable"); - final String sharedStringsHeader = "Shared strings:\n"; - try { - output.shouldContain("24: DumpSymbolAndStringTable\n"); - if (sharingEnabled && wb.canWriteJavaHeapArchive()) { - output.shouldContain(sharedStringsHeader); - if (!wb.isSharedInternedString("MILLI_OF_SECOND")) { - throw new RuntimeException("'MILLI_OF_SECOND' should be a shared string"); - } - } - } catch (RuntimeException e) { - output.shouldContain("Unknown diagnostic command"); - } - - pb.command(new PidJcmdExecutor().getCommandLine("VM.systemdictionary")); - output = CDSTestUtils.executeAndLog(pb, "jcmd-systemdictionary"); - try { - output.shouldContain("System Dictionary for 'app' class loader statistics:"); - output.shouldContain("Number of buckets"); - output.shouldContain("Number of entries"); - output.shouldContain("Maximum bucket size"); - } catch (RuntimeException e) { - output.shouldContain("Unknown diagnostic command"); - } - - pb.command(new PidJcmdExecutor().getCommandLine("VM.systemdictionary", "-verbose")); - output = CDSTestUtils.executeAndLog(pb, "jcmd-systemdictionary"); - try { - output.shouldContain("Dictionary for loader data: 0x"); - output.shouldContain("^java.lang.String"); - } catch (RuntimeException e) { - output.shouldContain("Unknown diagnostic command"); - } + output.shouldContain("18: MY_INTERNED_STRING\n"); // This string should have been interned } } diff --git a/test/hotspot/jtreg/runtime/cds/SharedStrings.java b/test/hotspot/jtreg/runtime/cds/SharedStrings.java deleted file mode 100644 index db0bc3264b2..00000000000 --- a/test/hotspot/jtreg/runtime/cds/SharedStrings.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2015, 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 - * 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 Check to make sure that shared strings in the bootstrap CDS archive - * are actually shared - * @requires vm.cds.write.mapped.java.heap - * @requires vm.flagless - * @library /test/lib - * @build SharedStringsWb jdk.test.whitebox.WhiteBox - * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar whitebox.jar jdk.test.whitebox.WhiteBox - * @run driver SharedStrings - */ - -import jdk.test.lib.cds.CDSTestUtils; -import jdk.test.lib.process.ProcessTools; -import jdk.test.lib.process.OutputAnalyzer; -import jdk.test.lib.helpers.ClassFileInstaller; - -public class SharedStrings { - public static void main(String[] args) throws Exception { - // Note: This is a basic sanity test for Shared Strings feature. - // This also serves as a reference on how to use this feature, - // hence the command lines are spelled out instead of using the - // test utils methods. - ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder( - "-XX:+UnlockDiagnosticVMOptions", - "-XX:SharedArchiveFile=./SharedStrings.jsa", - "-Xlog:cds,aot+hashtables", - // Needed for bootclasspath match, for CDS to work with WhiteBox API - "-Xbootclasspath/a:" + ClassFileInstaller.getJarPath("whitebox.jar"), - "-Xshare:dump"); - - OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, "dump"); - CDSTestUtils.checkDump(out, "Shared string table stats"); - - - pb = ProcessTools.createLimitedTestJavaProcessBuilder( - "-XX:+UnlockDiagnosticVMOptions", - "-XX:SharedArchiveFile=./SharedStrings.jsa", - // needed for access to white box test API - "-Xbootclasspath/a:" + ClassFileInstaller.getJarPath("whitebox.jar"), - "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", - "-Xshare:on", "-showversion", "SharedStringsWb"); - - out = CDSTestUtils.executeAndLog(pb, "exec"); - CDSTestUtils.checkExec(out); - } -} diff --git a/test/hotspot/jtreg/runtime/cds/SharedStringsWb.java b/test/hotspot/jtreg/runtime/cds/SharedStringsWb.java deleted file mode 100644 index 5a4d24e4fdf..00000000000 --- a/test/hotspot/jtreg/runtime/cds/SharedStringsWb.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2013, 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; - -// This class is used by the test SharedStrings.java -// It should be launched in CDS mode -public class SharedStringsWb { - public static void main(String[] args) throws Exception { - WhiteBox wb = WhiteBox.getWhiteBox(); - - if (!wb.areSharedStringsMapped()) { - System.out.println("Shared strings are not mapped, assuming PASS"); - return; - } - - // The string below is known to be added to CDS archive - String s = ""; - String internedS = s.intern(); - - // Check that it's a valid string - if (s.getClass() != String.class || !(s instanceof String)) { - throw new RuntimeException("Shared string is not a valid String: FAIL"); - } - - if (wb.isSharedInternedString(internedS)) { - System.out.println("Found shared string, result: PASS"); - } else { - throw new RuntimeException("String is not shared, result: FAIL"); - } - } -} - - diff --git a/test/hotspot/jtreg/runtime/cds/appcds/cacheObject/MirrorWithReferenceFieldsApp.java b/test/hotspot/jtreg/runtime/cds/appcds/cacheObject/MirrorWithReferenceFieldsApp.java deleted file mode 100644 index 9e4558002cc..00000000000 --- a/test/hotspot/jtreg/runtime/cds/appcds/cacheObject/MirrorWithReferenceFieldsApp.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2018, 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 - * 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.io.File; -import java.net.URL; -import jdk.test.whitebox.WhiteBox; - -// -// - Test static final String field with initial value in cached mirror should be also archived. -// - GC should not crash when reference fields in cached mirror are updated at runtime -// - Reference fields are updated to point to runtime created objects -// - Reference fields are nullified -// -public class MirrorWithReferenceFieldsApp { - - // Static String field with initial value - static final String archived_field = "abc"; - - // Static object field - static Object non_archived_field_1; - - // Instance field - Integer non_archived_field_2; - - public MirrorWithReferenceFieldsApp() { - non_archived_field_1 = new Object(); - non_archived_field_2 = Integer.valueOf(1); - } - - public static void main(String args[]) throws Exception { - WhiteBox wb = WhiteBox.getWhiteBox(); - - if (!wb.areOpenArchiveHeapObjectsMapped()) { - System.out.println("Archived open_archive_heap objects are not mapped."); - System.out.println("This may happen during normal operation. Test Skipped."); - return; - } - - MirrorWithReferenceFieldsApp m = new MirrorWithReferenceFieldsApp(); - m.test(wb); - } - - public void test(WhiteBox wb) { - Class c = MirrorWithReferenceFieldsApp.class; - if (wb.isSharedClass(c)) { - if (wb.isSharedInternedString(archived_field)) { - System.out.println("archived_field is archived as excepted"); - } else { - throw new RuntimeException( - "FAILED. archived_field is not archived."); - } - - // GC should not crash - System.gc(); - System.gc(); - System.gc(); - - non_archived_field_1 = null; - non_archived_field_2 = null; - - System.gc(); - System.gc(); - System.gc(); - - System.out.println("Done."); - } - } -} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/cacheObject/MirrorWithReferenceFieldsTest.java b/test/hotspot/jtreg/runtime/cds/appcds/cacheObject/MirrorWithReferenceFieldsTest.java deleted file mode 100644 index 4c670ccba9b..00000000000 --- a/test/hotspot/jtreg/runtime/cds/appcds/cacheObject/MirrorWithReferenceFieldsTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2018, 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 archived mirror with reference fields - * @requires vm.cds.write.archived.java.heap - * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds - * @build jdk.test.whitebox.WhiteBox - * @compile MirrorWithReferenceFieldsApp.java - * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar app.jar MirrorWithReferenceFieldsApp - * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar WhiteBox.jar jdk.test.whitebox.WhiteBox - * @run driver MirrorWithReferenceFieldsTest - */ - -import jdk.test.lib.process.OutputAnalyzer; -import jdk.test.lib.helpers.ClassFileInstaller; -import jdk.test.whitebox.WhiteBox; - -public class MirrorWithReferenceFieldsTest { - public static void main(String[] args) throws Exception { - String wbJar = ClassFileInstaller.getJarPath("WhiteBox.jar"); - String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar; - String appJar = ClassFileInstaller.getJarPath("app.jar"); - - String classlist[] = new String[] { - "MirrorWithReferenceFieldsApp", - }; - - TestCommon.testDump(appJar, classlist, use_whitebox_jar); - OutputAnalyzer output = TestCommon.exec(appJar, use_whitebox_jar, - "-XX:+UnlockDiagnosticVMOptions", - "-XX:+WhiteBoxAPI", - "-XX:+VerifyAfterGC", - "MirrorWithReferenceFieldsApp"); - try { - TestCommon.checkExec(output, "Done"); - } catch (Exception e) { - output.shouldContain("Archived open_archive_heap objects are not mapped"); - } - } -} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/cacheObject/RedefineClassApp.java b/test/hotspot/jtreg/runtime/cds/appcds/cacheObject/RedefineClassApp.java index e247a8158f7..0bac9f4e77d 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/cacheObject/RedefineClassApp.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/cacheObject/RedefineClassApp.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -55,11 +55,6 @@ public class RedefineClassApp { static Instrumentation instrumentation; public static void main(String args[]) throws Throwable { - if (!wb.areSharedStringsMapped()) { - System.out.println("Shared strings are ignored."); - return; - } - File bootJar = new File(args[0]); File appJar = new File(args[1]); diff --git a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/ExerciseGC.java b/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/ExerciseGC.java deleted file mode 100644 index 7cad887a5d9..00000000000 --- a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/ExerciseGC.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2015, 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 - * 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 Exercise GC with shared strings - * @requires vm.cds.write.mapped.java.heap - * @library /test/hotspot/jtreg/runtime/cds/appcds /test/lib - * @build HelloStringGC jdk.test.whitebox.WhiteBox - * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox - * @run driver ExerciseGC - */ -public class ExerciseGC { - public static void main(String[] args) throws Exception { - SharedStringsUtils.run(args, ExerciseGC::test); - } - public static void test(String[] args) throws Exception { - SharedStringsUtils.buildJarAndWhiteBox("HelloStringGC"); - - SharedStringsUtils.dumpWithWhiteBox(TestCommon.list("HelloStringGC"), - "SharedStringsBasic.txt", "-Xlog:cds,aot+hashtables"); - - SharedStringsUtils.runWithArchiveAndWhiteBox("HelloStringGC", - "-XX:+UnlockDiagnosticVMOptions", "-XX:+VerifyBeforeGC"); - } -} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/HelloStringGC.java b/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/HelloStringGC.java deleted file mode 100644 index 0f8dbf7e753..00000000000 --- a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/HelloStringGC.java +++ /dev/null @@ -1,69 +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 HelloStringGC { - public static String[] array01 = new String[1000]; - public static String[] array02 = new String[1000]; - - public static void main(String args[]) throws RuntimeException { - String testString1 = "shared_test_string_unique_14325"; - String testString2 = "test123"; - - WhiteBox wb = WhiteBox.getWhiteBox(); - if (wb.areSharedStringsMapped() && !wb.isSharedInternedString(testString1)) { - throw new RuntimeException("testString1 is not shared"); - } - - for (int i=0; i<5; i++) { - allocSomeStrings(testString1, testString2); - array01 = null; - array02 = null; - System.gc(); - sleep(300); - array01 = new String[1000]; - array02 = new String[1000]; - } - - wb.fullGC(); - - System.out.println("HelloStringGC: PASS"); - } - - private static void allocSomeStrings(String s1, String s2) { - for (int i = 0; i < 1000; i ++) { - array01[i] = new String(s1); - array02[i] = new String(s2); - } - } - - private static void sleep(int ms) { - try { - Thread.sleep(ms); - } catch (InterruptedException e) { - } - } - -} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/HelloStringPlus.java b/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/HelloStringPlus.java deleted file mode 100644 index da111ced43a..00000000000 --- a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/HelloStringPlus.java +++ /dev/null @@ -1,76 +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. - * - */ - -// A test class to be launched in AppCDS mode, has basic+ -// coverage of string operations - -import jdk.test.whitebox.WhiteBox; - -public class HelloStringPlus { - public static void main(String args[]) { - // Let's reference the string that is in archive - String testString1 = "shared_test_string_unique_14325"; - System.out.println("Hello String: " + testString1); - - WhiteBox wb = WhiteBox.getWhiteBox(); - if (wb.areSharedStringsMapped() && !wb.isSharedInternedString(testString1)) { - throw new RuntimeException("testString1 is not shared"); - } - - // Check other basic string operations - // Interning and equality - String[] testArray = new String[] {"shared_", "test_", "string_", "intern_", "12345"}; - String toBeInterned = ""; - - StringBuilder sb = new StringBuilder(); - for (String s : testArray) { - sb.append(s); - } - toBeInterned = sb.toString(); - - System.out.println("About to intern a string: " + toBeInterned); - toBeInterned.intern(); - - // check equality - if (testString1.equals(toBeInterned)) - throw new RuntimeException("Equality test 1 failed"); - - if (!testString1.equals("shared_test_string" + '_' + "unique_14325")) - throw new RuntimeException("Equality test 2 failed"); - - // Chech the hash code functionality; no special assertions, just make sure - // no crashe or exception occurs - System.out.println("testString1.hashCode() = " + testString1.hashCode()); - - // Check intern() method for "" string - String empty = ""; - String empty_interned = empty.intern(); - if (wb.areSharedStringsMapped() && !wb.isSharedInternedString(empty)) { - throw new RuntimeException("Empty string should be shared"); - } - if (empty_interned != empty) { - throw new RuntimeException("Different string is returned from intern() for empty string"); - } - } -} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/InternSharedString.java b/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/InternSharedString.java deleted file mode 100644 index 89136ebdc4d..00000000000 --- a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/InternSharedString.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2015, 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 - * 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 shared strings together with string intern operation - * @requires vm.gc == null - * @requires vm.cds.write.mapped.java.heap - * @library /test/hotspot/jtreg/runtime/cds/appcds /test/lib - * @compile InternStringTest.java - * @build jdk.test.whitebox.WhiteBox - * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox - * @run driver InternSharedString - */ - -// This test requires the vm.cds.write.mapped.java.heap specifically as it has expectations -// about using the mechanism for dumping the entire string table, which the streaming solution -// does not do. - -public class InternSharedString { - public static void main(String[] args) throws Exception { - SharedStringsUtils.run(args, InternSharedString::test); - } - - public static void test(String[] args) throws Exception { - SharedStringsUtils.buildJarAndWhiteBox("InternStringTest"); - - SharedStringsUtils.dumpWithWhiteBox(TestCommon.list("InternStringTest"), - "ExtraSharedInput.txt", "-Xlog:cds,aot+hashtables"); - - String[] extraMatches = new String[] { - InternStringTest.passed_output1, - InternStringTest.passed_output2, - InternStringTest.passed_output3 }; - - SharedStringsUtils.runWithArchiveAndWhiteBox(extraMatches, "InternStringTest"); - } -} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/InternStringTest.java b/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/InternStringTest.java deleted file mode 100644 index bea24c87888..00000000000 --- a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/InternStringTest.java +++ /dev/null @@ -1,85 +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 InternStringTest { - public static String passed_output1 = "Found shared string."; - public static String passed_output2 = "Shared strings are equal."; - public static String passed_output3 = "Found shared string containing latin1 supplement chars."; - public static String passed_output4 = "Found shared string containing non-western chars."; - public static final String latin1Sup = "XXXX \u00a3 YYYY"; // \u00a3 = The pound sign - public static final String nonWestern = "XXXX \u5678 YYYY"; // \u5678 = Unicode Han Character 'ton (metric or English)' - - public static void main(String[] args) throws Exception { - WhiteBox wb = WhiteBox.getWhiteBox(); - - // All string literals are shared. - String shared1 = "LiveOak"; - String interned1 = shared1.intern(); - if (wb.areSharedStringsMapped()) { - if (wb.isSharedInternedString(interned1)) { - System.out.println(passed_output1); - } else { - throw new RuntimeException("Failed: String is not shared."); - } - } - - // Test 2: shared_string1.intern() == shared_string2.intern() - String shared2 = "LiveOak"; - String interned2 = shared2.intern(); - if (interned1 == interned2) { - System.out.println(passed_output2); - } else { - throw new RuntimeException("Not equal!"); - } - - // Test 3: interned strings with a char in latin1 supplement block [\u0080-\u00ff] - { - String a = "X" + latin1Sup.substring(1); - String b = a.intern(); - - if (wb.areSharedStringsMapped()) { - if (wb.isSharedInternedString(b)) { - System.out.println(passed_output3); - } else { - throw new RuntimeException("Failed: expected shared string with latin1-supplement chars."); - } - } - } - - // Test 5: interned strings with non-western characters - { - String a = "X" + nonWestern.substring(1); - String b = a.intern(); - if (wb.areSharedStringsMapped()) { - if (wb.isSharedInternedString(b)) { - System.out.println(passed_output4); - } else { - throw new RuntimeException("Failed: expected shared string with non-western chars."); - } - } - } - } -} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/SharedStringsBasicPlus.java b/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/SharedStringsBasicPlus.java deleted file mode 100644 index 6145ea7719b..00000000000 --- a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/SharedStringsBasicPlus.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2015, 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 - * 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 Basic plus test for shared strings - * @requires vm.cds.write.mapped.java.heap - * @library /test/hotspot/jtreg/runtime/cds/appcds /test/lib - * @build HelloStringPlus jdk.test.whitebox.WhiteBox - * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox - * @run driver SharedStringsBasicPlus - */ - -// This test requires the vm.cds.write.mapped.java.heap specifically as it has expectations -// about using the mechanism for dumping the entire string table, which the streaming solution -// does not do. - -public class SharedStringsBasicPlus { - public static void main(String[] args) throws Exception { - SharedStringsUtils.run(args, SharedStringsBasicPlus::test); - } - - public static void test(String[] args) throws Exception { - SharedStringsUtils.buildJarAndWhiteBox("HelloStringPlus"); - - SharedStringsUtils.dumpWithWhiteBox( TestCommon.list("HelloStringPlus"), - "SharedStringsBasic.txt", "-Xlog:cds,aot+hashtables"); - - SharedStringsUtils.runWithArchiveAndWhiteBox("HelloStringPlus"); - } -} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/SharedStringsUtils.java b/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/SharedStringsUtils.java index e15cfafa3cb..15686d76ab3 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/SharedStringsUtils.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/SharedStringsUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -47,7 +47,7 @@ public class SharedStringsUtils { // SharedStringsUtils.run() is for running the main test body multiple times, each with a different // set of extra VM options that are passed to the child processes. // - // See ./ExerciseGC.java for an example. + // See ./LargePages.java for an example. public static void run(String args[], Test t) throws Exception { int numSetOfChildVMOptions = vmOptionCombos.length; for (int i=0; i< numSetOfChildVMOptions; i++) { diff --git a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/SharedStringsWb.java b/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/SharedStringsWb.java deleted file mode 100644 index 755d64bf51b..00000000000 --- a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/SharedStringsWb.java +++ /dev/null @@ -1,42 +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 SharedStringsWb { - public static void main(String[] args) throws Exception { - WhiteBox wb = WhiteBox.getWhiteBox(); - String s = "shared_test_string_unique_14325"; - s = s.intern(); - if (wb.areSharedStringsMapped()) { - if (wb.isSharedInternedString(s)) { - System.out.println("Found shared string."); - } else { - throw new RuntimeException("String is not shared."); - } - } - } -} - - diff --git a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/SharedStringsWbTest.java b/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/SharedStringsWbTest.java deleted file mode 100644 index 20dbad30441..00000000000 --- a/test/hotspot/jtreg/runtime/cds/appcds/sharedStrings/SharedStringsWbTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2016, 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 - * 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 White box test for shared strings - * @requires vm.cds.write.mapped.java.heap - * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds - * @build jdk.test.whitebox.WhiteBox SharedStringsWb - * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox - * @run driver SharedStringsWbTest - */ - -// This test requires the vm.cds.write.mapped.java.heap specifically as it has expectations -// about using the mechanism for dumping the entire string table, which the streaming solution -// does not do. - -import java.io.*; -import jdk.test.whitebox.WhiteBox; - -public class SharedStringsWbTest { - public static void main(String[] args) throws Exception { - SharedStringsUtils.run(args, SharedStringsWbTest::test); - } - - public static void test(String[] args) throws Exception { - SharedStringsUtils.buildJarAndWhiteBox("SharedStringsWb"); - - SharedStringsUtils.dumpWithWhiteBox(TestCommon.list("SharedStringsWb"), - "SharedStringsBasic.txt", "-Xlog:cds,aot+hashtables"); - - SharedStringsUtils.runWithArchiveAndWhiteBox("SharedStringsWb"); - } -} diff --git a/test/lib/jdk/test/whitebox/WhiteBox.java b/test/lib/jdk/test/whitebox/WhiteBox.java index cc570caef7c..c915cee41b0 100644 --- a/test/lib/jdk/test/whitebox/WhiteBox.java +++ b/test/lib/jdk/test/whitebox/WhiteBox.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2026, 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 @@ -799,8 +799,6 @@ public class WhiteBox { public native boolean cdsMemoryMappingFailed(); public native boolean isSharingEnabled(); public native boolean isSharedClass(Class c); - public native boolean areSharedStringsMapped(); - public native boolean isSharedInternedString(String s); public native boolean isCDSIncluded(); public native boolean isJFRIncluded(); public native boolean isDTraceIncluded();