Skip to content

Commit 61f3d70

Browse files
committed
8352084: Add more test code in TestSetupAOT.java
Reviewed-by: erikj, kvn, lmesnik
1 parent 6e164ea commit 61f3d70

File tree

5 files changed

+184
-26
lines changed

5 files changed

+184
-26
lines changed

make/RunTests.gmk

+14-11
Original file line numberDiff line numberDiff line change
@@ -732,14 +732,16 @@ endef
732732
#
733733
SetupAOT = $(NamedParamsMacroTemplate)
734734
define SetupAOTBody
735-
$1_AOT_JDK_CONF := $$($1_TEST_SUPPORT_DIR)/aot/jdk.aotconf
736-
$1_AOT_JDK_CACHE := $$($1_TEST_SUPPORT_DIR)/aot/jdk.aotcache
737-
$1_AOT_JDK_LOG := $$($1_TEST_SUPPORT_DIR)/aot/TestSetupAOT.log
735+
$1_AOT_JDK_OUTPUT_DIR := $$($1_TEST_SUPPORT_DIR)/aot
736+
$1_AOT_JDK_CONF := $$($1_AOT_JDK_OUTPUT_DIR)/jdk.aotconf
737+
$1_AOT_JDK_CACHE := $$($1_AOT_JDK_OUTPUT_DIR)/jdk.aotcache
738+
$1_AOT_JDK_LOG := $$($1_AOT_JDK_OUTPUT_DIR)/TestSetupAOT.log
738739

739-
# We execute the training run with $(TEST_IMAGE_DIR)/setup_aot/TestSetupAOT.class
740+
# We execute the training run with the TestSetupAOT class from $(TEST_IMAGE_DIR)/setup_aot/TestSetupAOT.jar
740741
# to touch a fair number of classes inside the JDK. Note that we can't specify a classpath,
741742
# or else the AOT cache cannot be used with jtreg test cases that use a different value
742-
# for their classpaths. Instead, we run in the $(TEST_IMAGE_DIR)/setup_aot/ directory.
743+
# for their classpaths. Instead, we cd in the $$($1_AOT_JDK_OUTPUT_DIR) directory,
744+
# extract the TestSetupAOT.jar there, and run in that directory without specifying a classpath.
743745
# The "java" launcher will have an implicit classpath of ".", so it can pick up the TestSetupAOT
744746
# class from the JVM's current directory.
745747
#
@@ -748,19 +750,20 @@ define SetupAOTBody
748750
# only classes from the JDK.
749751

750752
$$($1_AOT_JDK_CACHE): $$(JDK_IMAGE_DIR)/release
751-
$$(call MakeDir, $$($1_TEST_SUPPORT_DIR)/aot)
753+
$$(call MakeDir, $$($1_AOT_JDK_OUTPUT_DIR))
752754

753755
$$(call LogWarn, AOT: Create cache configuration) \
754-
$$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/aot, ( \
755-
$(CD) $(TEST_IMAGE_DIR)/setup_aot; \
756+
$$(call ExecuteWithLog, $$($1_AOT_JDK_OUTPUT_DIR), ( \
757+
cd $$($1_AOT_JDK_OUTPUT_DIR); \
758+
$(JAR) --extract --file $(TEST_IMAGE_DIR)/setup_aot/TestSetupAOT.jar; \
756759
$$(FIXPATH) $(JDK_UNDER_TEST)/bin/java $$($1_VM_OPTIONS) \
757-
-Xlog:cds,cds+class=debug:file=$$($1_AOT_JDK_CONF).log -Xlog:cds*=error \
760+
-Xlog:class+load,cds,cds+class=debug:file=$$($1_AOT_JDK_CONF).log -Xlog:cds*=error \
758761
-XX:AOTMode=record -XX:AOTConfiguration=$$($1_AOT_JDK_CONF) \
759-
TestSetupAOT > $$($1_AOT_JDK_LOG) \
762+
TestSetupAOT $$($1_AOT_JDK_OUTPUT_DIR) > $$($1_AOT_JDK_LOG) \
760763
))
761764

762765
$$(call LogWarn, AOT: Generate AOT cache $$($1_AOT_JDK_CACHE) with flags: $$($1_VM_OPTIONS))
763-
$$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/aot, ( \
766+
$$(call ExecuteWithLog, $$($1_AOT_JDK_OUTPUT_DIR), ( \
764767
$$(FIXPATH) $(JDK_UNDER_TEST)/bin/java \
765768
$$($1_VM_OPTIONS) -Xlog:cds,cds+class=debug:file=$$($1_AOT_JDK_CACHE).log -Xlog:cds*=error \
766769
-XX:ExtraSharedClassListFile=$(JDK_UNDER_TEST)/lib/classlist \

make/test/BuildTestSetupAOT.gmk

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ include JavaCompilation.gmk
3737

3838
SETUP_AOT_BASEDIR := $(TOPDIR)/test/setup_aot
3939
SETUP_AOT_SUPPORT := $(SUPPORT_OUTPUTDIR)/test/setup_aot
40-
SETUP_AOT_CLASS := $(SETUP_AOT_SUPPORT)/classes/TestSetupAOT.class
40+
SETUP_AOT_JAR := $(SETUP_AOT_SUPPORT)/TestSetupAOT.jar
4141

4242
$(eval $(call SetupJavaCompilation, BUILD_SETUP_AOT, \
4343
TARGET_RELEASE := $(TARGET_RELEASE_NEWJDK_UPGRADED), \
4444
SRC := $(SETUP_AOT_BASEDIR), \
4545
BIN := $(SETUP_AOT_SUPPORT)/classes, \
46+
JAR := $(SETUP_AOT_JAR), \
4647
))
4748

4849
TARGETS += $(BUILD_SETUP_AOT)
@@ -53,9 +54,8 @@ TARGETS += $(BUILD_SETUP_AOT)
5354

5455
# Copy to hotspot jtreg test image
5556
$(eval $(call SetupCopyFiles, COPY_SETUP_AOT, \
56-
SRC := $(SETUP_AOT_SUPPORT)/classes, \
5757
DEST := $(TEST_IMAGE_DIR)/setup_aot, \
58-
FILES := TestSetupAOT.class, \
58+
FILES := $(SETUP_AOT_JAR), \
5959
))
6060

6161
IMAGES_TARGETS += $(COPY_SETUP_AOT)

test/hotspot/jtreg/runtime/cds/appcds/applications/JavacBench.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
* @test id=static
2727
* @summary Run JavacBenchApp with the classic static archive workflow
2828
* @requires vm.cds
29-
* @library /test/lib
29+
* @library /test/lib /test/setup_aot
3030
* @run driver JavacBench STATIC
3131
*/
3232

3333
/*
3434
* @test id=dynamic
3535
* @summary Run JavacBenchApp with the classic dynamic archive workflow
3636
* @requires vm.cds
37-
* @library /test/lib
37+
* @library /test/lib /test/setup_aot
3838
* @build jdk.test.whitebox.WhiteBox
3939
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
4040
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. JavacBench DYNAMIC
@@ -45,7 +45,7 @@
4545
* @requires vm.cds.supports.aot.class.linking
4646
* @summary Run JavacBenchApp with AOT cache (JEP 483)
4747
* @requires vm.cds
48-
* @library /test/lib
48+
* @library /test/lib /test/setup_aot
4949
* @run driver JavacBench AOT
5050
*/
5151

test/setup_aot/TestSetupAOT.java

+164-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@
2323
* questions.
2424
*/
2525

26+
import java.io.File;
27+
import java.util.Arrays;
28+
import java.util.List;
29+
import java.util.Locale;
30+
import java.util.logging.Level;
31+
import java.util.logging.Logger;
2632
import java.util.spi.ToolProvider;
33+
import java.util.stream.Stream;
34+
import static java.util.stream.Collectors.*;
2735

2836
// This program is executed by make/RunTests.gmk to support running HotSpot tests
2937
// in the "AOT mode", for example:
@@ -44,16 +52,163 @@
4452
// the customized AOT cache contains *only* classes from the JDK itself.
4553

4654
public class TestSetupAOT {
55+
private static final Logger LOGGER = Logger.getLogger("Hello");
56+
4757
public static void main(String[] args) throws Throwable {
48-
String[] tools = {
49-
"javac", "javap", "jlink", "jar",
50-
};
51-
// TODO: we should do more substantial work than just running with "--help".
52-
// E.g., use javac to compile a program.
53-
for (String tool : tools) {
54-
ToolProvider t = ToolProvider.findFirst(tool)
55-
.orElseThrow(() -> new RuntimeException(tool + " not found"));
56-
t.run(System.out, System.out, "--help");
58+
runJDKTools(args);
59+
invokedynamicTests(args);
60+
LOGGER.log(Level.FINE, "Done");
61+
}
62+
63+
static void runJDKTools(String[] args) throws Throwable {
64+
String tmpDir = args[0];
65+
System.out.println("Working Directory = " + System.getProperty("user.dir"));
66+
System.out.println("Temp output dir = " + tmpDir);
67+
68+
// ------------------------------
69+
// javac
70+
71+
execTool("javac", "--help");
72+
73+
JavacBenchApp.main(new String[] {"5"});
74+
75+
// ------------------------------
76+
// javap
77+
78+
execTool("javap", "--help");
79+
execTool("javap", "-c", "-private", "-v", "-verify",
80+
"java.lang.System",
81+
"java/util/stream/IntStream",
82+
"jdk.internal.module.ModuleBootstrap");
83+
84+
// ------------------------------
85+
// jlink
86+
87+
String jlinkOutput = tmpDir + File.separator + "jlinkOutput";
88+
89+
execTool("jlink", "--help");
90+
execTool("jlink", "--list-plugins");
91+
92+
deleteAll(jlinkOutput);
93+
execTool("jlink", "--add-modules", "java.base", "--strip-debug", "--output", jlinkOutput);
94+
deleteAll(jlinkOutput);
95+
96+
// ------------------------------
97+
// jar
98+
99+
String jarOutput = tmpDir + File.separator + "tmp.jar";
100+
101+
execTool("jar", "--help");
102+
103+
deleteAll(jarOutput);
104+
execTool("jar", "cvf", jarOutput, "TestSetupAOT.class");
105+
execTool("jar", "uvf", jarOutput, "TestSetupAOT.class");
106+
execTool("jar", "tvf", jarOutput);
107+
execTool("jar", "--describe-module", "--file=" + jarOutput);
108+
deleteAll(jarOutput);
109+
110+
// ------------------------------
111+
// jdeps
112+
113+
execTool("jdeps", "--help");
114+
execTool("jdeps", "-v", "TestSetupAOT.class");
115+
}
116+
117+
static void deleteAll(String f) {
118+
deleteAll(new File(f));
119+
}
120+
121+
static void deleteAll(File f) {
122+
File[] files = f.listFiles();
123+
if (files != null) {
124+
for (File file : files) {
125+
deleteAll(file);
126+
}
57127
}
128+
System.out.println("Deleting: " + f);
129+
f.delete();
130+
}
131+
132+
static void execTool(String tool, String... args) throws Throwable {
133+
System.out.println("== Running tool ======================================================");
134+
System.out.print(tool);
135+
for (String s : args) {
136+
System.out.print(" " + s);
137+
}
138+
System.out.println();
139+
System.out.println("======================================================================");
140+
141+
ToolProvider t = ToolProvider.findFirst(tool)
142+
.orElseThrow(() -> new RuntimeException(tool + " not found"));
143+
t.run(System.out, System.out, args);
144+
}
145+
146+
147+
// Run some operations with java.util.stream, lambda expressions and string concatenation. This
148+
// will lead to AOT resolution of invokedynamic call sites.
149+
static void invokedynamicTests(String args[]) {
150+
List<String> strings = Arrays.asList("Hello", "World!");
151+
152+
String helloWorld = strings.parallelStream()
153+
.filter(s -> s.contains("o"))
154+
.map(s -> s.toLowerCase(Locale.ROOT))
155+
.collect(joining(","));
156+
157+
Stream.of(helloWorld.split("([,x-z]{1,3})([\\s]*)"))
158+
.map(String::toString)
159+
.forEach(System.out::println);
160+
161+
// Common concatenation patterns
162+
int i = args.length * 12357; // Seed with this so javac will not perform constant folding.
163+
String s = String.valueOf(i);
164+
165+
String SS = s + s;
166+
String CS = "string" + s;
167+
String SC = s + "string";
168+
String SCS = s + "string" + s;
169+
String CSS = "string" + s + s;
170+
String CSC = "string" + s + "string";
171+
String SSC = s + s + "string";
172+
String CSCS = "string" + s + "string" + s;
173+
String SCSC = s + "string" + s + "string";
174+
String CSCSC = "string" + s + "string" + s + "string";
175+
String SCSCS = s + "string" + s + "string" + s;
176+
String SSCSS = s + s + "string" + s + s;
177+
String S5 = s + s + s + s + s;
178+
String S6 = s + s + s + s + s + s;
179+
String S7 = s + s + s + s + s + s + s;
180+
String S8 = s + s + s + s + s + s + s + s;
181+
String S9 = s + s + s + s + s + s + s + s + s;
182+
String S10 = s + s + s + s + s + s + s + s + s + s;
183+
184+
String CI = "string" + i;
185+
String IC = i + "string";
186+
String SI = s + i;
187+
String IS = i + s;
188+
String CIS = "string" + i + s;
189+
String CSCI = "string" + s + "string" + i;
190+
String CIC = "string" + i + "string";
191+
String CICI = "string" + i + "string" + i;
192+
193+
float f = 0.1f;
194+
String CF = "string" + f;
195+
String CFS = "string" + f + s;
196+
String CSCF = "string" + s + "string" + f;
197+
198+
char c = 'a';
199+
String CC = "string" + c;
200+
String CCS = "string" + c + s;
201+
String CSCC = "string" + s + "string" + c;
202+
203+
long l = i + 12345678;
204+
String CJ = "string" + l;
205+
String JC = l + "string";
206+
String CJC = "string" + l + "string";
207+
String CJCJ = "string" + l + "string" + l;
208+
String CJCJC = "string" + l + "string" + l + "string";
209+
double d = i / 2.0;
210+
String CD = "string" + d;
211+
String CDS = "string" + d + s;
212+
String CSCD = "string" + s + "string" + d;
58213
}
59214
}

0 commit comments

Comments
 (0)