Skip to content

Commit ed3c9eb

Browse files
author
duke
committedMar 13, 2025
Automatic merge of jdk:master into master
2 parents 73cb69f + a7ad414 commit ed3c9eb

File tree

4 files changed

+124
-5
lines changed

4 files changed

+124
-5
lines changed
 

‎src/hotspot/share/cds/cdsConfig.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ bool CDSConfig::is_dumping_final_static_archive() {
561561

562562
bool CDSConfig::allow_only_single_java_thread() {
563563
// See comments in JVM_StartThread()
564-
return is_dumping_static_archive();
564+
return is_dumping_classic_static_archive() || is_dumping_final_static_archive();
565565
}
566566

567567
bool CDSConfig::is_using_archive() {

‎src/hotspot/share/cds/metaspaceShared.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,10 @@ void MetaspaceShared::preload_and_dump(TRAPS) {
823823

824824
if (CDSConfig::new_aot_flags_used()) {
825825
if (CDSConfig::is_dumping_preimage_static_archive()) {
826+
// We are in the JVM that runs the training run. Continue execution,
827+
// so that it can finish all clean-up and return the correct exit
828+
// code to the OS.
826829
tty->print_cr("AOTConfiguration recorded: %s", AOTConfiguration);
827-
vm_exit(0);
828830
} else {
829831
// The JLI launcher only recognizes the "old" -Xshare:dump flag.
830832
// When the new -XX:AOTMode=create flag is used, we can't return
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright (c) 2025, 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 -XX:AOTMode=record should not interfere with app execution: (1) thread creation; (2) exit code
28+
* @bug 8351327
29+
* @requires vm.cds.supports.aot.class.linking
30+
* @comment work around JDK-8345635
31+
* @requires !vm.jvmci.enabled
32+
* @library /test/jdk/lib/testlibrary /test/lib
33+
* @build TrainingRun
34+
* @run driver jdk.test.lib.helpers.ClassFileInstaller -jar app.jar MyTestApp
35+
* @run driver TrainingRun AOT
36+
*/
37+
38+
import jdk.test.lib.cds.CDSAppTester;
39+
import jdk.test.lib.helpers.ClassFileInstaller;
40+
import jdk.test.lib.process.OutputAnalyzer;
41+
42+
public class TrainingRun {
43+
static final String appJar = ClassFileInstaller.getJarPath("app.jar");
44+
static final String mainClass = "MyTestApp";
45+
46+
public static void main(String[] args) throws Exception {
47+
(new Tester()).run(args);
48+
}
49+
50+
static class Tester extends CDSAppTester {
51+
public Tester() {
52+
super(mainClass);
53+
54+
// CDSAppTester usually wants the app to return exit value 0, but this test
55+
// checks whether the training run can return 2.
56+
setCheckExitValue(false);
57+
}
58+
59+
@Override
60+
public String classpath(RunMode runMode) {
61+
return appJar;
62+
}
63+
64+
@Override
65+
public String[] appCommandLine(RunMode runMode) {
66+
return new String[] {
67+
mainClass,
68+
};
69+
}
70+
71+
@Override
72+
public void checkExecution(OutputAnalyzer out, RunMode runMode) {
73+
if (runMode.isApplicationExecuted()) {
74+
out.shouldHaveExitValue(2);
75+
out.shouldContain("Hello: x is 1");
76+
}
77+
}
78+
}
79+
}
80+
81+
class MyTestApp {
82+
volatile static int x = 0;
83+
84+
public static void main(String args[]) throws Exception {
85+
Thread t = new Thread(() -> {
86+
x = 1;
87+
});
88+
t.start();
89+
t.join();
90+
91+
if (x != 1) {
92+
throw new RuntimeException("x should be 1 but is " + x);
93+
}
94+
System.out.println("Hello: x is " + x);
95+
System.out.println("I am calling System.exit(2)");
96+
System.exit(2);
97+
}
98+
}

‎test/lib/jdk/test/lib/cds/CDSAppTester.java

+22-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public CDSAppTester(String name) {
5656
throw new SkippedException("Tests based on CDSAppTester should be excluded when -Dtest.dynamic.cds.archive is specified");
5757
}
5858

59-
// Old workflow
6059
this.name = name;
6160
classListFile = name() + ".classlist";
6261
classListFileLog = classListFile + ".log";
@@ -89,7 +88,7 @@ public enum RunMode {
8988
TRAINING, // -XX:DumpLoadedClassList OR {-XX:AOTMode=create -XX:AOTConfiguration}
9089
DUMP_STATIC, // -Xshare:dump
9190
DUMP_DYNAMIC, // -XX:ArchiveClassesArExit
92-
ASSEMBLY, // JEP 483
91+
ASSEMBLY, // JEP 483 (assembly phase, app logic not executed)
9392
PRODUCTION; // Running with the CDS archive produced from the above steps
9493

9594
public boolean isStaticDump() {
@@ -98,6 +97,24 @@ public boolean isStaticDump() {
9897
public boolean isProductionRun() {
9998
return this == PRODUCTION;
10099
}
100+
101+
// When <code>CDSAppTester::checkExecution(out, runMode)</code> is called, has the application been
102+
// executed? If so, <code>out</code> should contain logs printed by the application's own logic.
103+
public boolean isApplicationExecuted() {
104+
return (this != ASSEMBLY) && (this != DUMP_STATIC);
105+
}
106+
}
107+
108+
public boolean isDumping(RunMode runMode) {
109+
if (isStaticWorkflow()) {
110+
return runMode == RunMode.DUMP_STATIC;
111+
} else if (isDynamicWorkflow()) {
112+
return runMode == RunMode.DUMP_DYNAMIC;
113+
} else if (isAOTWorkflow()) {
114+
return runMode == RunMode.TRAINING || runMode == RunMode.ASSEMBLY;
115+
} else {
116+
return false;
117+
}
101118
}
102119

103120
public final String name() {
@@ -184,7 +201,9 @@ private OutputAnalyzer recordAOTConfiguration() throws Exception {
184201
"-XX:AOTConfiguration=" + aotConfigurationFile,
185202
"-cp", classpath(runMode),
186203
logToFile(aotConfigurationFileLog,
187-
"class+load=debug"));
204+
"class+load=debug",
205+
"cds=debug",
206+
"cds+class=debug"));
188207
cmdLine = StringArrayUtils.concat(cmdLine, appCommandLine(runMode));
189208
return executeAndCheck(cmdLine, runMode, aotConfigurationFile, aotConfigurationFileLog);
190209
}

0 commit comments

Comments
 (0)
Please sign in to comment.