1 /*
2 * Copyright (c) 2021, 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 import java.io.File;
25
26 import jdk.test.lib.JDKToolFinder;
27 import jdk.test.lib.Platform;
28 import jdk.test.lib.process.*;
29 import jdk.test.whitebox.WhiteBox;
30
31 import tests.Helper;
32
33 import jtreg.SkippedException;
34
35 /* @test
36 * @bug 8264322
37 * @summary Test the --generate-cds-archive plugin
38 * @requires vm.cds
39 * @library ../../lib
40 * @library /test/lib
41 * @modules java.base/jdk.internal.jimage
42 * jdk.jlink/jdk.tools.jlink.internal
43 * jdk.jlink/jdk.tools.jmod
44 * jdk.jlink/jdk.tools.jimage
45 * jdk.compiler
46 * @build tests.*
47 * @build jdk.test.whitebox.WhiteBox
48 * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
49 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. CDSPluginTest
50 */
51
52 public class CDSPluginTest {
53 public static void main(String[] args) throws Throwable {
54
55 if (!Platform.isDefaultCDSArchiveSupported())
56 throw new SkippedException("not a supported platform");
57
58 Helper helper = Helper.newHelper();
59 if (helper == null) {
60 System.err.println("Test not run");
61 return;
62 }
63
64 var module = "cds";
65 helper.generateDefaultJModule(module);
66 var image = helper.generateDefaultImage(new String[] { "--generate-cds-archive" },
67 module)
68 .assertSuccess();
69
70 String subDir;
71 String sep = File.separator;
72 if (Platform.isWindows()) {
73 subDir = "bin" + sep;
74 } else {
75 subDir = "lib" + sep;
76 }
77 subDir += "server" + sep;
78
79 WhiteBox wb = WhiteBox.getWhiteBox();
80 boolean NOCOMPACT_HEADERS = Platform.is64bit() &&
81 !wb.getBooleanVMFlag("UseCompactObjectHeaders");
82 String suffix = NOCOMPACT_HEADERS ? "_nocoh.jsa" : ".jsa";
83
84 if (Platform.isAArch64() || Platform.isX64()) {
85 helper.checkImage(image, module, null, null,
86 new String[] { subDir + "classes" + suffix, subDir + "classes_nocoops" + suffix});
87 } else {
88 helper.checkImage(image, module, null, null,
89 new String[] { subDir + "classes" + suffix });
90 }
91 }
92 }