1+ /*
2+ * Copyright (c) 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+ * @key randomness
28+ * @summary AOTCacheConsistency This test checks that there is a CRC validation of the AOT Cache regions.
29+ * @bug 8382166
30+ * @requires vm.cds.supports.aot.class.linking
31+ * @library /test/lib
32+ * @build jdk.test.whitebox.WhiteBox AOTCacheConsistency HelloWorld
33+ * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
34+ * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar app.jar HelloWorld
35+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI AOTCacheConsistency
36+ */
37+
38+ import jdk .test .lib .cds .CDSArchiveUtils ;
39+ import jdk .test .lib .cds .SimpleCDSAppTester ;
40+ import jdk .test .lib .process .OutputAnalyzer ;
41+ import java .io .File ;
42+
43+ public class AOTCacheConsistency {
44+ public static void main (String args []) throws Exception {
45+ // Train and run the app
46+ SimpleCDSAppTester tester = SimpleCDSAppTester .of ("AOTCacheConsistency" )
47+ .classpath ("app.jar" )
48+ .appCommandLine ("HelloWorld" )
49+ .setProductionChecker ((OutputAnalyzer out ) -> {
50+ out .shouldContain ("HelloWorld" );
51+ })
52+ .runAOTWorkflow ();
53+
54+ String aotCache = tester .aotCacheFile ();
55+
56+ String [] regions = CDSArchiveUtils .getRegions ();
57+ String orig = aotCache + ".orig" ;
58+ CDSArchiveUtils .copyArchiveFile (new File (aotCache ), orig ); // save original copy
59+
60+ // Modify each of the region individually. The production should fail to run
61+ // with these args;
62+ String extraVMArgs [] = {"-XX:+VerifySharedSpaces" , "-XX:AOTMode=on" };
63+ tester .setCheckExitValue (false );
64+
65+ for (int i = 0 ; i < regions .length ; i ++) {
66+ File f = CDSArchiveUtils .copyArchiveFile (new File (orig ), aotCache );
67+ System .out .println ("\n =======\n Testing region " + i + " = " + regions [i ]);
68+ if (CDSArchiveUtils .modifyRegionContent (i , f )) {
69+ tester .setProductionChecker ((OutputAnalyzer out ) -> {
70+ out .shouldContain ("Checksum verification failed." );
71+ });
72+ tester .rerunProduction (extraVMArgs );
73+ }
74+ }
75+ }
76+ }
0 commit comments