/* * Copyright (c) 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 id=default_gc * @requires vm.gc != "Z" * @summary Sanity test of combinations of the AOT Code Caching diagnostic flags * @requires vm.cds.supports.aot.code.caching * @requires vm.compiler1.enabled & vm.compiler2.enabled * @comment Both C1 and C2 JIT compilers are required because the test verifies * compiler's runtime blobs generation. * @requires vm.opt.VerifyOops == null | vm.opt.VerifyOops == false * @comment VerifyOops flag switch off AOT code generation. Skip it. * @library /test/lib /test/setup_aot * @build AOTCodeFlags JavacBenchApp * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar app.jar * JavacBenchApp * JavacBenchApp$ClassFile * JavacBenchApp$FileManager * JavacBenchApp$SourceFile * @run driver/timeout=1500 AOTCodeFlags */ /** * @test id=Z * @requires vm.gc.Z * @summary Sanity test of combinations of the AOT Code Caching diagnostic flags * @requires vm.cds.supports.aot.code.caching * @requires vm.compiler1.enabled & vm.compiler2.enabled * @comment Both C1 and C2 JIT compilers are required because the test verifies * compiler's runtime blobs generation. * @requires vm.opt.VerifyOops == null | vm.opt.VerifyOops == false * @comment VerifyOops flag switch off AOT code generation. Skip it. * @library /test/lib /test/setup_aot * @build AOTCodeFlags JavacBenchApp * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar app.jar * JavacBenchApp * JavacBenchApp$ClassFile * JavacBenchApp$FileManager * JavacBenchApp$SourceFile * @run driver/timeout=1500 AOTCodeFlags Z */ /** * @test id=shenandoah * @requires vm.gc.Shenandoah * @summary Sanity test of combinations of the AOT Code Caching diagnostic flags * @requires vm.cds.supports.aot.code.caching * @requires vm.compiler1.enabled & vm.compiler2.enabled * @comment Both C1 and C2 JIT compilers are required because the test verifies * compiler's runtime blobs generation. * @requires vm.opt.VerifyOops == null | vm.opt.VerifyOops == false * @comment VerifyOops flag switch off AOT code generation. Skip it. * @library /test/lib /test/setup_aot * @build AOTCodeFlags JavacBenchApp * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar app.jar * JavacBenchApp * JavacBenchApp$ClassFile * JavacBenchApp$FileManager * JavacBenchApp$SourceFile * @run driver/timeout=1500 AOTCodeFlags Shenandoah */ /** * @test id=parallel * @requires vm.gc.Parallel * @summary Sanity test of combinations of the AOT Code Caching diagnostic flags * @requires vm.cds.supports.aot.code.caching * @requires vm.compiler1.enabled & vm.compiler2.enabled * @comment Both C1 and C2 JIT compilers are required because the test verifies * compiler's runtime blobs generation. * @requires vm.opt.VerifyOops == null | vm.opt.VerifyOops == false * @comment VerifyOops flag switch off AOT code generation. Skip it. * @library /test/lib /test/setup_aot * @build AOTCodeFlags JavacBenchApp * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar app.jar * JavacBenchApp * JavacBenchApp$ClassFile * JavacBenchApp$FileManager * JavacBenchApp$SourceFile * @run driver/timeout=1500 AOTCodeFlags Parallel */ import java.util.ArrayList; import java.util.List; import jdk.test.lib.cds.CDSAppTester; import jdk.test.lib.process.OutputAnalyzer; public class AOTCodeFlags { private static String gcName = null; public static void main(String... args) throws Exception { Tester t = new Tester(args.length == 0 ? null : args[0]); // Run only 2 modes (0 - no AOT code, 1 - AOT adapters) until JDK-8357398 is fixed for (int mode = 0; mode < 4; mode++) { t.setTestMode(mode); t.run(new String[] {"AOT", "--two-step-training"}); } } static class Tester extends CDSAppTester { private int testMode; private String gcName; public Tester(String name) { super("AOTCodeFlags"); testMode = 0; gcName = name; } boolean isAdapterCachingOn() { return (testMode & 0x1) != 0; } boolean isStubCachingOn() { return (testMode & 0x2) != 0; } public void setTestMode(int mode) { testMode = mode; } public List getVMArgsForTestMode() { List list = new ArrayList(); list.add("-XX:+UnlockDiagnosticVMOptions"); list.add(isAdapterCachingOn() ? "-XX:+AOTAdapterCaching" : "-XX:-AOTAdapterCaching"); list.add(isStubCachingOn() ? "-XX:+AOTStubCaching" : "-XX:-AOTStubCaching"); return list; } public List getGCArgs() { List args = new ArrayList(); args.add("-Xmx100M"); if (gcName == null) { return args; } switch (gcName) { case "G1": case "Z": case "Shenandoah": case "Parallel": args.add("-XX:+Use" + gcName + "GC"); return args; default: throw new RuntimeException("Unexpected GC name " + gcName); } } @Override public String classpath(RunMode runMode) { return "app.jar"; } @Override public String[] vmArgs(RunMode runMode) { switch (runMode) { case RunMode.ASSEMBLY: case RunMode.PRODUCTION: { List args = getVMArgsForTestMode(); args.addAll(List.of("-Xlog:aot+codecache+init=debug", "-Xlog:aot+codecache+exit=debug")); args.addAll(getGCArgs()); return args.toArray(new String[0]); } } List args = getGCArgs(); return args.toArray(new String[args.size()]); } @Override public String[] appCommandLine(RunMode runMode) { return new String[] { "JavacBenchApp", "10" }; } @Override public void checkExecution(OutputAnalyzer out, RunMode runMode) throws Exception { if (!isAdapterCachingOn() && !isStubCachingOn()) { // this is equivalent to completely disable AOT code cache switch (runMode) { case RunMode.ASSEMBLY: case RunMode.PRODUCTION: out.shouldNotMatch("Adapters:\\s+total"); out.shouldNotMatch("Shared Blobs:\\s+total"); out.shouldNotMatch("C1 Blobs:\\s+total"); out.shouldNotMatch("C2 Blobs:\\s+total"); break; } } else { if (isAdapterCachingOn()) { switch (runMode) { case RunMode.ASSEMBLY: case RunMode.PRODUCTION: // AOTAdapterCaching is on, non-zero adapters should be stored/loaded out.shouldMatch("Adapters:\\s+total=[1-9][0-9]+"); break; } } else { switch (runMode) { case RunMode.ASSEMBLY: case RunMode.PRODUCTION: // AOTAdapterCaching is off, no adapters should be stored/loaded out.shouldMatch("Adapters:\\s+total=0"); break; } } if (isStubCachingOn()) { switch (runMode) { case RunMode.ASSEMBLY: case RunMode.PRODUCTION: // AOTStubCaching is on, non-zero stubs should be stored/loaded out.shouldMatch("Shared Blobs:\\s+total=[1-9][0-9]+"); out.shouldMatch("C1 Blobs:\\s+total=[1-9][0-9]+"); // we do not currently load or store C2 stubs // because we are seeing weird memory errors // when loading them -- see JDK-8357593 out.shouldMatch("C2 Blobs:\\s+total=0"); break; } } else { switch (runMode) { case RunMode.ASSEMBLY: case RunMode.PRODUCTION: // AOTStubCaching is off, no stubs should be stored/loaded out.shouldMatch("Shared Blobs:\\s+total=0"); out.shouldMatch("C1 Blobs:\\s+total=0"); out.shouldMatch("C2 Blobs:\\s+total=0"); break; } } } } } }