34 */
35
36 import java.io.File;
37 import jdk.test.lib.cds.CDSTestUtils;
38 import jdk.test.lib.helpers.ClassFileInstaller;
39 import jdk.test.lib.process.OutputAnalyzer;
40 import jdk.test.lib.process.ProcessTools;
41
42 public class AOTFlags {
43 static String appJar = ClassFileInstaller.getJarPath("hello.jar");
44 static String aotConfigFile = "hello.aotconfig";
45 static String aotCacheFile = "hello.aot";
46 static String helloClass = "Hello";
47
48 public static void main(String[] args) throws Exception {
49 positiveTests();
50 negativeTests();
51 }
52
53 static void positiveTests() throws Exception {
54 //----------------------------------------------------------------------
55 printTestCase("Training Run");
56 ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
57 "-XX:AOTMode=record",
58 "-XX:AOTConfiguration=" + aotConfigFile,
59 "-Xlog:aot=debug",
60 "-cp", appJar, helloClass);
61
62 OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, "train");
63 out.shouldContain("Hello World");
64 out.shouldContain("AOTConfiguration recorded: " + aotConfigFile);
65 out.shouldHaveExitValue(0);
66
67 //----------------------------------------------------------------------
68 printTestCase("Assembly Phase (AOTClassLinking unspecified -> should be enabled by default)");
69 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
70 "-XX:AOTMode=create",
71 "-XX:AOTConfiguration=" + aotConfigFile,
72 "-XX:AOTCache=" + aotCacheFile,
73 "-Xlog:aot",
74 "-cp", appJar);
75 out = CDSTestUtils.executeAndLog(pb, "asm");
76 out.shouldContain("AOTCache creation is complete");
77 out.shouldMatch("hello[.]aot");
78 out.shouldHaveExitValue(0);
79
80 //----------------------------------------------------------------------
81 printTestCase("Production Run with AOTCache");
82 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
83 "-XX:AOTCache=" + aotCacheFile,
84 "-Xlog:aot",
85 "-cp", appJar, helloClass);
86 out = CDSTestUtils.executeAndLog(pb, "prod");
87 out.shouldContain("Using AOT-linked classes: true (static archive: has aot-linked classes)");
88 out.shouldContain("Opened AOT cache hello.aot.");
89 out.shouldContain("Hello World");
90 out.shouldHaveExitValue(0);
91
92 //----------------------------------------------------------------------
93 printTestCase("AOTMode=off");
94 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
95 "-XX:AOTCache=" + aotCacheFile,
96 "--show-version",
97 "-Xlog:aot",
98 "-XX:AOTMode=off",
99 "-cp", appJar, helloClass);
100 out = CDSTestUtils.executeAndLog(pb, "prod");
101 out.shouldNotContain(", sharing");
102 out.shouldNotContain("Opened AOT cache hello.aot.");
103 out.shouldContain("Hello World");
104 out.shouldHaveExitValue(0);
105
106 //----------------------------------------------------------------------
107 printTestCase("AOTMode=auto");
108 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
109 "-XX:AOTCache=" + aotCacheFile,
121 printTestCase("AOTMode=on");
122 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
123 "-XX:AOTCache=" + aotCacheFile,
124 "--show-version",
125 "-Xlog:aot",
126 "-XX:AOTMode=on",
127 "-cp", appJar, helloClass);
128 out = CDSTestUtils.executeAndLog(pb, "prod");
129 out.shouldContain(", sharing");
130 out.shouldContain("Opened AOT cache hello.aot.");
131 out.shouldContain("Hello World");
132 out.shouldHaveExitValue(0);
133
134 //----------------------------------------------------------------------
135 printTestCase("Assembly Phase with -XX:-AOTClassLinking");
136 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
137 "-XX:AOTMode=create",
138 "-XX:-AOTClassLinking",
139 "-XX:AOTConfiguration=" + aotConfigFile,
140 "-XX:AOTCache=" + aotCacheFile,
141 "-Xlog:aot",
142 "-cp", appJar);
143 out = CDSTestUtils.executeAndLog(pb, "asm");
144 out.shouldContain("AOTCache creation is complete");
145 out.shouldMatch("hello[.]aot");
146 out.shouldHaveExitValue(0);
147
148 //----------------------------------------------------------------------
149 printTestCase("Production Run with AOTCache, which was created with -XX:-AOTClassLinking");
150 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
151 "-XX:AOTCache=" + aotCacheFile,
152 "-Xlog:aot",
153 "-cp", appJar, helloClass);
154 out = CDSTestUtils.executeAndLog(pb, "prod");
155 out.shouldContain("Using AOT-linked classes: false (static archive: no aot-linked classes)");
156 out.shouldContain("Opened AOT cache hello.aot.");
157 out.shouldContain("Hello World");
158 out.shouldHaveExitValue(0);
159
160 //----------------------------------------------------------------------
161 printTestCase("Training run with -XX:-AOTClassLinking, but assembly run with -XX:+AOTClassLinking");
162 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
163 "-XX:AOTMode=record",
164 "-XX:-AOTClassLinking",
165 "-XX:AOTConfiguration=" + aotConfigFile,
166 "-Xlog:aot=debug",
167 "-cp", appJar, helloClass);
168 out = CDSTestUtils.executeAndLog(pb, "train");
169 out.shouldContain("Hello World");
170 out.shouldContain("AOTConfiguration recorded: " + aotConfigFile);
171 out.shouldHaveExitValue(0);
172
173 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
174 "-XX:AOTMode=create",
175 "-XX:+AOTClassLinking",
176 "-XX:AOTConfiguration=" + aotConfigFile,
177 "-XX:AOTCache=" + aotCacheFile,
178 "-Xlog:aot=debug",
179 "-cp", appJar);
180 out = CDSTestUtils.executeAndLog(pb, "asm");
181 out.shouldContain("Writing AOTCache file:");
182 out.shouldMatch("aot.*hello[.]aot");
183 out.shouldHaveExitValue(0);
184
185 //----------------------------------------------------------------------
186 printTestCase("One step training run (JEP-514");
187
188 // Set all AOTMode/AOTCacheOutput/AOTConfiguration
189 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
190 "-XX:AOTMode=record",
191 "-XX:AOTCacheOutput=" + aotCacheFile,
192 "-XX:AOTConfiguration=" + aotConfigFile,
193 "-Xlog:aot=debug",
194 "-cp", appJar, helloClass);
195 out = CDSTestUtils.executeAndLog(pb, "ontstep-train");
196 out.shouldContain("Hello World");
197 out.shouldContain("AOTConfiguration recorded: " + aotConfigFile);
198 out.shouldContain("AOTCache creation is complete: hello.aot");
199 out.shouldHaveExitValue(0);
200
201 // Set AOTCacheOutput/AOTConfiguration only; Ergo for: AOTMode=record
202 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
203 "-XX:AOTCacheOutput=" + aotCacheFile,
204 "-XX:AOTConfiguration=" + aotConfigFile,
205 "-Xlog:aot=debug",
206 "-cp", appJar, helloClass);
207 out = CDSTestUtils.executeAndLog(pb, "ontstep-train");
208 out.shouldContain("Hello World");
209 out.shouldContain("AOTConfiguration recorded: " + aotConfigFile);
210 out.shouldContain("AOTCache creation is complete: hello.aot");
211 out.shouldHaveExitValue(0);
212
213 // Set AOTCacheOutput/AOTConfiguration/AOTMode=auto; Ergo changes: AOTMode=record
214 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
215 "-XX:AOTMode=auto",
216 "-XX:AOTCacheOutput=" + aotCacheFile,
217 "-XX:AOTConfiguration=" + aotConfigFile,
218 "-Xlog:aot=debug",
219 "-cp", appJar, helloClass);
220 out = CDSTestUtils.executeAndLog(pb, "ontstep-train");
221 out.shouldContain("Hello World");
222 out.shouldContain("AOTConfiguration recorded: " + aotConfigFile);
223 out.shouldContain("AOTCache creation is complete: hello.aot");
224 out.shouldHaveExitValue(0);
225
226 // Set AOTCacheOutput only; Ergo for: AOTMode=record, AOTConfiguration=<temp>
227 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
228 "-XX:AOTCacheOutput=" + aotCacheFile,
229 "-Xlog:aot=debug",
230 "-cp", appJar, helloClass);
231 out = CDSTestUtils.executeAndLog(pb, "ontstep-train");
232 out.shouldContain("Hello World");
233 out.shouldContain("Temporary AOTConfiguration recorded: " + aotCacheFile + ".config");
234 out.shouldContain("AOTCache creation is complete: hello.aot");
235 out.shouldHaveExitValue(0);
236
237 // Set AOTCacheOutput/AOTMode=auto only; Ergo for: AOTMode=record, AOTConfiguration=<temp>
238 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
239 "-XX:AOTMode=auto",
240 "-XX:AOTCacheOutput=" + aotCacheFile,
241 "-Xlog:aot=debug",
242 "-cp", appJar, helloClass);
243 out = CDSTestUtils.executeAndLog(pb, "ontstep-train");
244 out.shouldContain("Hello World");
245 out.shouldContain("Temporary AOTConfiguration recorded: " + aotCacheFile + ".config");
246 out.shouldContain("AOTCache creation is complete: hello.aot");
247 out.shouldHaveExitValue(0);
248
249 // Quoating of space characters in child JVM process
250 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
251 "-XX:AOTCacheOutput=" + aotCacheFile,
252 "-Dmy.prop=My string -Xshare:off here", // -Xshare:off should not be treated as a single VM opt for the child JVM
253 "-Xlog:aot=debug",
254 "-cp", appJar, helloClass);
255 out = CDSTestUtils.executeAndLog(pb, "ontstep-train");
256 out.shouldContain("Hello World");
257 out.shouldContain("AOTCache creation is complete: hello.aot");
258 out.shouldMatch("Picked up JAVA_TOOL_OPTIONS:.* -Dmy.prop=My' 'string' '-Xshare:off' 'here");
259 out.shouldHaveExitValue(0);
260 }
261
262 static void negativeTests() throws Exception {
263 //----------------------------------------------------------------------
264 printTestCase("Mixing old and new options");
265 String mixOldNewErrSuffix = " cannot be used at the same time with -Xshare:on, -Xshare:auto, "
266 + "-Xshare:off, -Xshare:dump, DumpLoadedClassList, SharedClassListFile, "
267 + "or SharedArchiveFile";
268
|
34 */
35
36 import java.io.File;
37 import jdk.test.lib.cds.CDSTestUtils;
38 import jdk.test.lib.helpers.ClassFileInstaller;
39 import jdk.test.lib.process.OutputAnalyzer;
40 import jdk.test.lib.process.ProcessTools;
41
42 public class AOTFlags {
43 static String appJar = ClassFileInstaller.getJarPath("hello.jar");
44 static String aotConfigFile = "hello.aotconfig";
45 static String aotCacheFile = "hello.aot";
46 static String helloClass = "Hello";
47
48 public static void main(String[] args) throws Exception {
49 positiveTests();
50 negativeTests();
51 }
52
53 static void positiveTests() throws Exception {
54 String hasTrainingDataPattern = "MethodTrainingData *= *[1-9]";
55 String noTrainingDataPattern = "MethodTrainingData *= *0";
56 String hasAOTCodePattern = "Shared file region .ac. .: *[1-9]";
57 String noAOTCodePattern = "Shared file region .ac. .: *0";
58 String hasMappedAOTCodePattern = "Mapped [0-9]+ bytes at address 0x[0-9a-f]+ from AOT Code Cache";
59
60 //----------------------------------------------------------------------
61 printTestCase("Training Run");
62 ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
63 "-XX:AOTMode=record",
64 "-XX:AOTConfiguration=" + aotConfigFile,
65 "-Xlog:aot=debug",
66 "-cp", appJar, helloClass);
67
68 OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, "train");
69 out.shouldContain("Hello World");
70 out.shouldContain("AOTConfiguration recorded: " + aotConfigFile);
71 out.shouldMatch(hasTrainingDataPattern);
72 out.shouldMatch(noAOTCodePattern);
73 out.shouldHaveExitValue(0);
74
75 //----------------------------------------------------------------------
76 printTestCase("Assembly Phase (AOTClassLinking unspecified -> should be enabled by default)");
77 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
78 "-XX:AOTMode=create",
79 "-XX:AOTConfiguration=" + aotConfigFile,
80 "-XX:AOTCache=" + aotCacheFile,
81 "-Xlog:aot",
82 "-cp", appJar);
83 out = CDSTestUtils.executeAndLog(pb, "asm");
84 out.shouldContain("AOTCache creation is complete");
85 out.shouldMatch("hello[.]aot");
86 out.shouldMatch(hasTrainingDataPattern);
87 out.shouldMatch(hasAOTCodePattern);
88 out.shouldHaveExitValue(0);
89
90 //----------------------------------------------------------------------
91 printTestCase("Production Run with AOTCache");
92 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
93 "-XX:AOTCache=" + aotCacheFile,
94 "-Xlog:aot",
95 "-Xlog:aot+codecache*",
96 "-cp", appJar, helloClass);
97 out = CDSTestUtils.executeAndLog(pb, "prod");
98 out.shouldContain("Using AOT-linked classes: true (static archive: has aot-linked classes)");
99 out.shouldContain("Opened AOT cache hello.aot.");
100 out.shouldContain("Hello World");
101 out.shouldMatch(hasMappedAOTCodePattern);
102 out.shouldHaveExitValue(0);
103
104 //----------------------------------------------------------------------
105 printTestCase("AOTMode=off");
106 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
107 "-XX:AOTCache=" + aotCacheFile,
108 "--show-version",
109 "-Xlog:aot",
110 "-XX:AOTMode=off",
111 "-cp", appJar, helloClass);
112 out = CDSTestUtils.executeAndLog(pb, "prod");
113 out.shouldNotContain(", sharing");
114 out.shouldNotContain("Opened AOT cache hello.aot.");
115 out.shouldContain("Hello World");
116 out.shouldHaveExitValue(0);
117
118 //----------------------------------------------------------------------
119 printTestCase("AOTMode=auto");
120 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
121 "-XX:AOTCache=" + aotCacheFile,
133 printTestCase("AOTMode=on");
134 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
135 "-XX:AOTCache=" + aotCacheFile,
136 "--show-version",
137 "-Xlog:aot",
138 "-XX:AOTMode=on",
139 "-cp", appJar, helloClass);
140 out = CDSTestUtils.executeAndLog(pb, "prod");
141 out.shouldContain(", sharing");
142 out.shouldContain("Opened AOT cache hello.aot.");
143 out.shouldContain("Hello World");
144 out.shouldHaveExitValue(0);
145
146 //----------------------------------------------------------------------
147 printTestCase("Assembly Phase with -XX:-AOTClassLinking");
148 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
149 "-XX:AOTMode=create",
150 "-XX:-AOTClassLinking",
151 "-XX:AOTConfiguration=" + aotConfigFile,
152 "-XX:AOTCache=" + aotCacheFile,
153 "-Xlog:aot=debug",
154 "-cp", appJar);
155 out = CDSTestUtils.executeAndLog(pb, "asm");
156 out.shouldContain("AOTCache creation is complete");
157 out.shouldMatch("hello[.]aot");
158 out.shouldMatch(noTrainingDataPattern);
159 out.shouldMatch(noAOTCodePattern);
160 out.shouldHaveExitValue(0);
161
162 //----------------------------------------------------------------------
163 printTestCase("Production Run with AOTCache, which was created with -XX:-AOTClassLinking");
164 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
165 "-XX:AOTCache=" + aotCacheFile,
166 "-Xlog:aot",
167 "-Xlog:aot+codecache*",
168 "-cp", appJar, helloClass);
169 out = CDSTestUtils.executeAndLog(pb, "prod");
170 out.shouldContain("Using AOT-linked classes: false (static archive: no aot-linked classes)");
171 out.shouldContain("Opened AOT cache hello.aot.");
172 out.shouldContain("Hello World");
173 out.shouldNotMatch(hasMappedAOTCodePattern);
174 out.shouldHaveExitValue(0);
175
176 //----------------------------------------------------------------------
177 printTestCase("Training run with -XX:-AOTClassLinking, but assembly run with -XX:+AOTClassLinking");
178 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
179 "-XX:AOTMode=record",
180 "-XX:-AOTClassLinking",
181 "-XX:AOTConfiguration=" + aotConfigFile,
182 "-Xlog:aot=debug",
183 "-cp", appJar, helloClass);
184 out = CDSTestUtils.executeAndLog(pb, "train");
185 out.shouldContain("Hello World");
186 out.shouldContain("AOTConfiguration recorded: " + aotConfigFile);
187 out.shouldHaveExitValue(0);
188
189 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
190 "-XX:AOTMode=create",
191 "-XX:+AOTClassLinking",
192 "-XX:AOTConfiguration=" + aotConfigFile,
193 "-XX:AOTCache=" + aotCacheFile,
194 "-Xlog:aot=debug",
195 "-cp", appJar);
196 out = CDSTestUtils.executeAndLog(pb, "asm");
197 out.shouldContain("AOTCache creation is complete");
198 out.shouldMatch("hello[.]aot");
199 out.shouldHaveExitValue(0);
200
201 //----------------------------------------------------------------------
202 printTestCase("One step training run (JEP-514");
203
204 // Set all AOTMode/AOTCacheOutput/AOTConfiguration
205 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
206 "-XX:AOTMode=record",
207 "-XX:AOTCacheOutput=" + aotCacheFile,
208 "-XX:AOTConfiguration=" + aotConfigFile,
209 "-Xlog:aot=debug",
210 "-cp", appJar, helloClass);
211 out = CDSTestUtils.executeAndLog(pb, "ontstep-train");
212 out.shouldContain("Hello World");
213 out.shouldContain("AOTConfiguration recorded: " + aotConfigFile);
214 out.shouldContain("AOTCache creation is complete: hello.aot");
215 out.shouldHaveExitValue(0);
216
217 // Set AOTCacheOutput/AOTConfiguration only; Ergo for: AOTMode=record
218 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
219 "-XX:AOTCacheOutput=" + aotCacheFile,
220 "-XX:AOTConfiguration=" + aotConfigFile,
221 "-Xlog:aot=debug",
222 "-cp", appJar, helloClass);
223 out = CDSTestUtils.executeAndLog(pb, "ontstep-train");
224 out.shouldContain("Hello World");
225 out.shouldContain("AOTConfiguration recorded: " + aotConfigFile);
226 out.shouldContain("AOTCache creation is complete: hello.aot");
227 out.shouldHaveExitValue(0);
228
229 // Set AOTCacheOutput only; Ergo for: AOTMode=record, AOTConfiguration=<temp>
230 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
231 "-XX:AOTCacheOutput=" + aotCacheFile,
232 "-Xlog:aot=debug",
233 "-cp", appJar, helloClass);
234 out = CDSTestUtils.executeAndLog(pb, "ontstep-train");
235 out.shouldContain("Hello World");
236 out.shouldContain("Temporary AOTConfiguration recorded: " + aotCacheFile + ".config");
237 out.shouldContain("AOTCache creation is complete: hello.aot");
238 out.shouldHaveExitValue(0);
239
240 // Quoating of space characters in child JVM process
241 pb = ProcessTools.createLimitedTestJavaProcessBuilder(
242 "-XX:AOTCacheOutput=" + aotCacheFile,
243 "-Dmy.prop=My string -Xshare:off here", // -Xshare:off should not be treated as a single VM opt for the child JVM
244 "-Xlog:aot=debug",
245 "-cp", appJar, helloClass);
246 out = CDSTestUtils.executeAndLog(pb, "ontstep-train");
247 out.shouldContain("Hello World");
248 out.shouldContain("AOTCache creation is complete: hello.aot");
249 out.shouldMatch("Picked up JAVA_TOOL_OPTIONS:.* -Dmy.prop=My' 'string' '-Xshare:off' 'here");
250 out.shouldHaveExitValue(0);
251 }
252
253 static void negativeTests() throws Exception {
254 //----------------------------------------------------------------------
255 printTestCase("Mixing old and new options");
256 String mixOldNewErrSuffix = " cannot be used at the same time with -Xshare:on, -Xshare:auto, "
257 + "-Xshare:off, -Xshare:dump, DumpLoadedClassList, SharedClassListFile, "
258 + "or SharedArchiveFile";
259
|