1 /* 2 * Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 /* 26 * @test 27 * @summary Tests how CDS works when critical library classes are replaced with JVMTI ClassFileLoadHook 28 * @library /test/lib 29 * @requires vm.cds.write.archived.java.heap 30 * @modules java.base/jdk.internal.misc 31 * @build jdk.test.whitebox.WhiteBox 32 * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar whitebox.jar jdk.test.whitebox.WhiteBox 33 * @run main/othervm/native ReplaceCriticalClassesForSubgraphs 34 */ 35 36 import java.util.ArrayList; 37 import java.util.Arrays; 38 import jdk.internal.misc.PreviewFeatures; 39 40 public class ReplaceCriticalClassesForSubgraphs extends ReplaceCriticalClasses { 41 public static void main(String args[]) throws Throwable { 42 ReplaceCriticalClassesForSubgraphs rcc = new ReplaceCriticalClassesForSubgraphs(); 43 rcc.process(args); 44 } 45 46 public String[] getTests() { 47 ArrayList<String> tests = new ArrayList<String>(Arrays.asList( 48 // Try to replace classes that are used by the archived subgraph graphs. (CDS should be disabled) 49 "-early -notshared -subgraph java/lang/module/ResolvedModule jdk.internal.module.ArchivedModuleGraph", 50 "-early -notshared -subgraph java/lang/Integer java.lang.Integer$IntegerCache", 51 52 // CDS should not be disabled -- these critical classes cannot be replaced because 53 // JvmtiExport::early_class_hook_env() is false. 54 "-subgraph java/lang/module/Configuration java.lang.module.Configuration", 55 "-subgraph java/lang/ModuleLayer java.lang.ModuleLayer", 56 57 // Tests for archived full module graph. We cannot use whitebox, which requires appending to bootclasspath. 58 // VM will disable full module graph if bootclasspath is appended. 59 "-nowhitebox -early -notshared -subgraph java/lang/Module jdk.internal.module.ArchivedBootLayer", 60 "-nowhitebox -early -notshared -subgraph java/lang/ModuleLayer jdk.internal.module.ArchivedBootLayer", 61 "-nowhitebox -subgraph java/lang/Module jdk.internal.module.ArchivedBootLayer", 62 "-nowhitebox -subgraph java/lang/ModuleLayer jdk.internal.module.ArchivedBootLayer")); 63 64 // IntegerCache does not exist in preview mode so it should not be expected in the output 65 if (!PreviewFeatures.isEnabled()) { 66 // CDS should not be disabled -- these critical classes cannot be replaced because 67 // JvmtiExport::early_class_hook_env() is false. 68 tests.add("-subgraph java/lang/Integer java.lang.Integer$IntegerCache"); 69 } 70 71 return tests.toArray(new String[0]); 72 } 73 } --- EOF ---