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  * @summary Nullable flat fields test for dynamic archive
28  * @requires vm.cds
29  * @requires vm.debug == true
30  * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes
31  * @enablePreview
32  * @modules java.base/jdk.internal.value
33  *          java.base/jdk.internal.vm.annotation
34  * @compile ../test-classes/NullableFlatFieldApp.java
35  * @compile ../../../../../../lib/jdk/test/lib/Asserts.java
36  * @build jdk.test.whitebox.WhiteBox
37  * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar nullable_flat.jar NullableFlatFieldApp
38  *  NullableFlatFieldApp$Value0 NullableFlatFieldApp$Container0
39  *  NullableFlatFieldApp$Value1a NullableFlatFieldApp$Value1b
40  *  NullableFlatFieldApp$Value2a NullableFlatFieldApp$Value2b
41  *  NullableFlatFieldApp$Container1 NullableFlatFieldApp$Container2
42  *  NullableFlatFieldApp$Value3 NullableFlatFieldApp$Container3
43  *  jdk/test/lib/Asserts
44  * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
45  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. NullableFlatFieldDynamicTest
46  */
47 
48 import jdk.test.lib.helpers.ClassFileInstaller;
49 
50 public class NullableFlatFieldDynamicTest extends DynamicArchiveTestBase {
51     public static void main(String[] args) throws Exception {
52         runTest(NullableFlatFieldDynamicTest::test);
53     }
54 
55     static void test() throws Exception {
56         String topArchiveName = getNewArchiveName("top");
57         String baseArchiveName = getNewArchiveName("base");
58         TestCommon.dumpBaseArchive(baseArchiveName, "--enable-preview", "-Xlog:cds");
59         doTest(baseArchiveName, topArchiveName);
60     }
61 
62     private static void doTest(String baseArchiveName, String topArchiveName) throws Exception {
63         String appJar = ClassFileInstaller.getJarPath("nullable_flat.jar");
64         String mainClass = "NullableFlatFieldApp";
65         dump2(baseArchiveName, topArchiveName,
66              "--enable-preview",
67              "-XX:+UseNullableValueFlattening",
68              "-XX:+UnlockDiagnosticVMOptions",
69              "-XX:+PrintInlineLayout",
70              "-Xlog:cds",
71              "-Xlog:cds+dynamic=debug",
72              "-cp", appJar, mainClass)
73             .assertNormalExit(output -> {
74                     output.shouldContain("Written dynamic archive 0x");
75                 });
76         run2(baseArchiveName, topArchiveName,
77             "--enable-preview",
78             "-XX:+UseNullableValueFlattening",
79             "-XX:+UnlockDiagnosticVMOptions",
80             "-XX:+PrintInlineLayout",
81             "-Xlog:class+load",
82             "-Xlog:cds+dynamic=debug,cds=debug",
83             "-cp", appJar, mainClass)
84             .assertNormalExit(output -> {
85                     output.shouldContain("NullableFlatFieldApp source: shared objects file")
86                           .shouldHaveExitValue(0);
87               });
88     }
89 }