1 /*
2 * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2024, Red Hat, Inc. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25 /**
26 * @test id=nocoops_nocoh
27 * @summary Test Loading of default archives in all configurations
28 * @requires vm.cds
29 * @requires vm.cds.default.archive.available
30 * @requires vm.cds.write.archived.java.heap
31 * @requires vm.bits == 64
32 * @library /test/lib
33 * @modules java.base/jdk.internal.misc
34 * java.management
35 * @run driver TestDefaultArchiveLoading nocoops_nocoh
36 */
37
38 /**
39 * @test id=nocoops_coh
40 * @summary Test Loading of default archives in all configurations (requires --enable-cds-archive-coh)
41 * @requires vm.cds
42 * @requires vm.cds.default.archive.available
43 * @requires vm.cds.write.archived.java.heap
44 * @requires vm.bits == 64
45 * @library /test/lib
46 * @modules java.base/jdk.internal.misc
47 * java.management
48 * @run driver TestDefaultArchiveLoading nocoops_coh
49 */
50
51 /**
52 * @test id=coops_nocoh
53 * @summary Test Loading of default archives in all configurations
54 * @requires vm.cds
55 * @requires vm.cds.default.archive.available
56 * @requires vm.cds.write.archived.java.heap
57 * @requires vm.bits == 64
58 * @requires !vm.gc.Z
59 * @library /test/lib
60 * @modules java.base/jdk.internal.misc
61 * java.management
62 * @run driver TestDefaultArchiveLoading coops_nocoh
63 */
64
65 /**
66 * @test id=coops_coh
67 * @summary Test Loading of default archives in all configurations (requires --enable-cds-archive-coh)
68 * @requires vm.cds
69 * @requires vm.cds.default.archive.available
70 * @requires vm.cds.write.archived.java.heap
71 * @requires vm.bits == 64
72 * @requires !vm.gc.Z
73 * @library /test/lib
74 * @modules java.base/jdk.internal.misc
75 * java.management
76 * @run driver TestDefaultArchiveLoading coops_coh
77 */
78
79 import java.nio.file.Files;
80 import java.nio.file.Path;
81 import java.nio.file.Paths;
82 import jdk.test.lib.Platform;
83 import jdk.test.lib.process.OutputAnalyzer;
84 import jdk.test.lib.process.ProcessTools;
85
86 import jtreg.SkippedException;
87
88 public class TestDefaultArchiveLoading {
89
90 private static String archiveName(String archiveSuffix) {
91 return "classes" + archiveSuffix + ".jsa";
92 }
93
94 private static Path archivePath(String archiveSuffix) {
95 return Paths.get(System.getProperty("java.home"), "lib",
96 "server", archiveName(archiveSuffix));
97 }
98
99 private static boolean isArchiveAvailable(char coops, char coh,
100 String archiveSuffix) throws Exception {
101 Path archive= archivePath(archiveSuffix);
102 return Files.exists(archive);
103 }
104
105 public static void main(String[] args) throws Exception {
106
107 if (args.length != 1) {
108 throw new RuntimeException("Expected argument");
109 }
110
111 String archiveSuffix;
112 char coh, coops;
113
114 switch (args[0]) {
115 case "nocoops_nocoh":
116 coh = coops = '-';
117 archiveSuffix = "_nocoops";
118 if (!isArchiveAvailable(coops, coh, archiveSuffix)) {
119 throw new SkippedException("Skipping test due to " +
120 archivePath(archiveSuffix).toString() + " not available");
121 }
122 break;
123 case "nocoops_coh":
124 coops = '-';
125 coh = '+';
126 archiveSuffix = "_nocoops_coh";
127 if (!isArchiveAvailable(coops, coh, archiveSuffix)) {
128 throw new SkippedException("Skipping test due to " +
129 archivePath(archiveSuffix).toString() + " not available");
130 }
131 break;
132 case "coops_nocoh":
133 coops = '+';
134 coh = '-';
135 archiveSuffix = "";
136 if (!isArchiveAvailable(coops, coh, archiveSuffix)) {
137 throw new SkippedException("Skipping test due to " +
138 archivePath(archiveSuffix).toString() + " not available");
139 }
140 break;
141 case "coops_coh":
142 coh = coops = '+';
143 archiveSuffix = "_coh";
144 if (!isArchiveAvailable(coops, coh, archiveSuffix)) {
145 throw new SkippedException("Skipping test due to " +
146 archivePath(archiveSuffix).toString() + " not available");
147 }
148 break;
149 default: throw new RuntimeException("Invalid argument " + args[0]);
150 }
151
152 ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
153 "-XX:" + coh + "UseCompactObjectHeaders",
154 "-XX:" + coops + "UseCompressedOops",
155 "-Xlog:cds",
156 "-Xshare:on", // fail if we cannot load archive
157 "-version");
158
159 OutputAnalyzer output = new OutputAnalyzer(pb.start());
160 output.shouldHaveExitValue(0);
161
162 output.shouldContain(archiveName(archiveSuffix));
163 }
164 }