< prev index next >

test/hotspot/jtreg/runtime/cds/appcds/AOTFlags.java

Print this page

 32  * @run driver AOTFlags
 33  */
 34 
 35 import jdk.test.lib.cds.CDSTestUtils;
 36 import jdk.test.lib.helpers.ClassFileInstaller;
 37 import jdk.test.lib.process.OutputAnalyzer;
 38 import jdk.test.lib.process.ProcessTools;
 39 
 40 public class AOTFlags {
 41     static String appJar = ClassFileInstaller.getJarPath("hello.jar");
 42     static String aotConfigFile = "hello.aotconfig";
 43     static String aotCacheFile = "hello.aot";
 44     static String helloClass = "Hello";
 45 
 46     public static void main(String[] args) throws Exception {
 47         positiveTests();
 48         negativeTests();
 49     }
 50 
 51     static void positiveTests() throws Exception {






 52         //----------------------------------------------------------------------
 53         printTestCase("Training Run");
 54         ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
 55             "-XX:AOTMode=record",
 56             "-XX:AOTConfiguration=" + aotConfigFile,
 57             "-Xlog:cds=debug",
 58             "-cp", appJar, helloClass);
 59 
 60         OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, "train");
 61         out.shouldContain("Hello World");
 62         out.shouldContain("AOTConfiguration recorded: " + aotConfigFile);


 63         out.shouldHaveExitValue(0);
 64 
 65         //----------------------------------------------------------------------
 66         printTestCase("Assembly Phase (AOTClassLinking unspecified -> should be enabled by default)");
 67         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
 68             "-XX:AOTMode=create",
 69             "-XX:AOTConfiguration=" + aotConfigFile,
 70             "-XX:AOTCache=" + aotCacheFile,
 71             "-Xlog:cds",
 72             "-cp", appJar);
 73         out = CDSTestUtils.executeAndLog(pb, "asm");
 74         out.shouldContain("Dumping shared data to file:");
 75         out.shouldMatch("cds.*hello[.]aot");


 76         out.shouldHaveExitValue(0);
 77 
 78         //----------------------------------------------------------------------
 79         printTestCase("Production Run with AOTCache");
 80         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
 81             "-XX:AOTCache=" + aotCacheFile,
 82             "-Xlog:cds",

 83             "-cp", appJar, helloClass);
 84         out = CDSTestUtils.executeAndLog(pb, "prod");
 85         out.shouldContain("Using AOT-linked classes: true (static archive: has aot-linked classes)");
 86         out.shouldContain("Opened AOT cache hello.aot.");
 87         out.shouldContain("Hello World");

 88         out.shouldHaveExitValue(0);
 89 
 90         //----------------------------------------------------------------------
 91         printTestCase("AOTMode=off");
 92         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
 93             "-XX:AOTCache=" + aotCacheFile,
 94             "--show-version",
 95             "-Xlog:cds",
 96             "-XX:AOTMode=off",
 97             "-cp", appJar, helloClass);
 98         out = CDSTestUtils.executeAndLog(pb, "prod");
 99         out.shouldNotContain(", sharing");
100         out.shouldNotContain("Opened AOT cache hello.aot.");
101         out.shouldContain("Hello World");
102         out.shouldHaveExitValue(0);
103 
104         //----------------------------------------------------------------------
105         printTestCase("AOTMode=auto");
106         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
107             "-XX:AOTCache=" + aotCacheFile,

119         printTestCase("AOTMode=on");
120         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
121             "-XX:AOTCache=" + aotCacheFile,
122             "--show-version",
123             "-Xlog:cds",
124             "-XX:AOTMode=on",
125             "-cp", appJar, helloClass);
126         out = CDSTestUtils.executeAndLog(pb, "prod");
127         out.shouldContain(", sharing");
128         out.shouldContain("Opened AOT cache hello.aot.");
129         out.shouldContain("Hello World");
130         out.shouldHaveExitValue(0);
131 
132         //----------------------------------------------------------------------
133         printTestCase("Assembly Phase with -XX:-AOTClassLinking");
134         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
135             "-XX:AOTMode=create",
136             "-XX:-AOTClassLinking",
137             "-XX:AOTConfiguration=" + aotConfigFile,
138             "-XX:AOTCache=" + aotCacheFile,
139             "-Xlog:cds",
140             "-cp", appJar);
141         out = CDSTestUtils.executeAndLog(pb, "asm");
142         out.shouldContain("Dumping shared data to file:");
143         out.shouldMatch("cds.*hello[.]aot");


144         out.shouldHaveExitValue(0);
145 
146         //----------------------------------------------------------------------
147         printTestCase("Production Run with AOTCache, which was created with -XX:-AOTClassLinking");
148         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
149             "-XX:AOTCache=" + aotCacheFile,
150             "-Xlog:cds",

151             "-cp", appJar, helloClass);
152         out = CDSTestUtils.executeAndLog(pb, "prod");
153         out.shouldContain("Using AOT-linked classes: false (static archive: no aot-linked classes)");
154         out.shouldContain("Opened AOT cache hello.aot.");
155         out.shouldContain("Hello World");


























156         out.shouldHaveExitValue(0);
157     }
158 
159     static void negativeTests() throws Exception {
160        //----------------------------------------------------------------------
161         printTestCase("Mixing old and new options");
162         String mixOldNewErrSuffix = " cannot be used at the same time with -Xshare:on, -Xshare:auto, "
163             + "-Xshare:off, -Xshare:dump, DumpLoadedClassList, SharedClassListFile, "
164             + "or SharedArchiveFile";
165 
166         ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
167             "-Xshare:off",
168             "-XX:AOTConfiguration=" + aotConfigFile,
169             "-cp", appJar, helloClass);
170 
171         OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, "neg");
172         out.shouldContain("Option AOTConfiguration" + mixOldNewErrSuffix);
173         out.shouldNotHaveExitValue(0);
174 
175         pb = ProcessTools.createLimitedTestJavaProcessBuilder(

285         out.shouldNotHaveExitValue(0);
286 
287         //----------------------------------------------------------------------
288         printTestCase("Classpath mismatch when creating archive");
289 
290         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
291             "-XX:AOTMode=create",
292             "-XX:AOTConfiguration=" + aotConfigFile,
293             "-XX:AOTCache=" + aotCacheFile,
294             "-cp", "noSuchJar.jar");
295 
296         out = CDSTestUtils.executeAndLog(pb, "neg");
297         out.shouldContain("class path and/or module path are not compatible with the ones " +
298                           "specified when the AOTConfiguration file was recorded");
299         out.shouldContain("Unable to use create AOT cache");
300         out.shouldHaveExitValue(1);
301     }
302 
303     static int testNum = 0;
304     static void printTestCase(String s) {
305         System.out.println("vvvvvvv TEST CASE " + testNum + ": " + s + " starts here vvvvvvv");
306         testNum++;
307     }
308 }

 32  * @run driver AOTFlags
 33  */
 34 
 35 import jdk.test.lib.cds.CDSTestUtils;
 36 import jdk.test.lib.helpers.ClassFileInstaller;
 37 import jdk.test.lib.process.OutputAnalyzer;
 38 import jdk.test.lib.process.ProcessTools;
 39 
 40 public class AOTFlags {
 41     static String appJar = ClassFileInstaller.getJarPath("hello.jar");
 42     static String aotConfigFile = "hello.aotconfig";
 43     static String aotCacheFile = "hello.aot";
 44     static String helloClass = "Hello";
 45 
 46     public static void main(String[] args) throws Exception {
 47         positiveTests();
 48         negativeTests();
 49     }
 50 
 51     static void positiveTests() throws Exception {
 52         String hasTrainingDataPattern = "MethodTrainingData *= *[1-9]";
 53         String noTrainingDataPattern = "MethodTrainingData *= *0";
 54         String hasCachedCodePattern = "Shared file region .cc. .: *[1-9]";
 55         String noCachedCodePattern = "Shared file region .cc. .: *0";
 56         String hasMappedCachedCodePattern = "Mapped [0-9]+ bytes at address 0x[0-9a-f]+ from AOT Code Cache";
 57 
 58         //----------------------------------------------------------------------
 59         printTestCase("Training Run");
 60         ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
 61             "-XX:AOTMode=record",
 62             "-XX:AOTConfiguration=" + aotConfigFile,
 63             "-Xlog:cds=debug",
 64             "-cp", appJar, helloClass);
 65 
 66         OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, "train");
 67         out.shouldContain("Hello World");
 68         out.shouldContain("AOTConfiguration recorded: " + aotConfigFile);
 69         out.shouldMatch(hasTrainingDataPattern);
 70         out.shouldMatch(noCachedCodePattern);
 71         out.shouldHaveExitValue(0);
 72 
 73         //----------------------------------------------------------------------
 74         printTestCase("Assembly Phase (AOTClassLinking unspecified -> should be enabled by default)");
 75         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
 76             "-XX:AOTMode=create",
 77             "-XX:AOTConfiguration=" + aotConfigFile,
 78             "-XX:AOTCache=" + aotCacheFile,
 79             "-Xlog:cds",
 80             "-cp", appJar);
 81         out = CDSTestUtils.executeAndLog(pb, "asm");
 82         out.shouldContain("Dumping shared data to file:");
 83         out.shouldMatch("cds.*hello[.]aot");
 84         out.shouldMatch(hasTrainingDataPattern);
 85         out.shouldMatch(hasCachedCodePattern);
 86         out.shouldHaveExitValue(0);
 87 
 88         //----------------------------------------------------------------------
 89         printTestCase("Production Run with AOTCache");
 90         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
 91             "-XX:AOTCache=" + aotCacheFile,
 92             "-Xlog:cds",
 93             "-Xlog:scc*",
 94             "-cp", appJar, helloClass);
 95         out = CDSTestUtils.executeAndLog(pb, "prod");
 96         out.shouldContain("Using AOT-linked classes: true (static archive: has aot-linked classes)");
 97         out.shouldContain("Opened AOT cache hello.aot.");
 98         out.shouldContain("Hello World");
 99         out.shouldMatch(hasMappedCachedCodePattern);
100         out.shouldHaveExitValue(0);
101 
102         //----------------------------------------------------------------------
103         printTestCase("AOTMode=off");
104         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
105             "-XX:AOTCache=" + aotCacheFile,
106             "--show-version",
107             "-Xlog:cds",
108             "-XX:AOTMode=off",
109             "-cp", appJar, helloClass);
110         out = CDSTestUtils.executeAndLog(pb, "prod");
111         out.shouldNotContain(", sharing");
112         out.shouldNotContain("Opened AOT cache hello.aot.");
113         out.shouldContain("Hello World");
114         out.shouldHaveExitValue(0);
115 
116         //----------------------------------------------------------------------
117         printTestCase("AOTMode=auto");
118         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
119             "-XX:AOTCache=" + aotCacheFile,

131         printTestCase("AOTMode=on");
132         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
133             "-XX:AOTCache=" + aotCacheFile,
134             "--show-version",
135             "-Xlog:cds",
136             "-XX:AOTMode=on",
137             "-cp", appJar, helloClass);
138         out = CDSTestUtils.executeAndLog(pb, "prod");
139         out.shouldContain(", sharing");
140         out.shouldContain("Opened AOT cache hello.aot.");
141         out.shouldContain("Hello World");
142         out.shouldHaveExitValue(0);
143 
144         //----------------------------------------------------------------------
145         printTestCase("Assembly Phase with -XX:-AOTClassLinking");
146         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
147             "-XX:AOTMode=create",
148             "-XX:-AOTClassLinking",
149             "-XX:AOTConfiguration=" + aotConfigFile,
150             "-XX:AOTCache=" + aotCacheFile,
151             "-Xlog:cds=debug",
152             "-cp", appJar);
153         out = CDSTestUtils.executeAndLog(pb, "asm");
154         out.shouldContain("Dumping shared data to file:");
155         out.shouldMatch("cds.*hello[.]aot");
156         out.shouldMatch(noTrainingDataPattern);
157         out.shouldMatch(noCachedCodePattern);
158         out.shouldHaveExitValue(0);
159 
160         //----------------------------------------------------------------------
161         printTestCase("Production Run with AOTCache, which was created with -XX:-AOTClassLinking");
162         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
163             "-XX:AOTCache=" + aotCacheFile,
164             "-Xlog:cds",
165             "-Xlog:scc*",
166             "-cp", appJar, helloClass);
167         out = CDSTestUtils.executeAndLog(pb, "prod");
168         out.shouldContain("Using AOT-linked classes: false (static archive: no aot-linked classes)");
169         out.shouldContain("Opened AOT cache hello.aot.");
170         out.shouldContain("Hello World");
171         out.shouldNotMatch(hasMappedCachedCodePattern);
172         out.shouldHaveExitValue(0);
173 
174         //----------------------------------------------------------------------
175         printTestCase("Training run with -XX:-AOTClassLinking, but assembly run with -XX:+AOTClassLinking");
176         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
177             "-XX:AOTMode=record",
178             "-XX:-AOTClassLinking",
179             "-XX:AOTConfiguration=" + aotConfigFile,
180             "-Xlog:cds=debug",
181             "-cp", appJar, helloClass);
182         out = CDSTestUtils.executeAndLog(pb, "train");
183         out.shouldContain("Hello World");
184         out.shouldContain("AOTConfiguration recorded: " + aotConfigFile);
185         out.shouldHaveExitValue(0);
186 
187         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
188             "-XX:AOTMode=create",
189             "-XX:+AOTClassLinking",
190             "-XX:AOTConfiguration=" + aotConfigFile,
191             "-XX:AOTCache=" + aotCacheFile,
192             "-Xlog:cds=debug",
193             "-cp", appJar);
194         out = CDSTestUtils.executeAndLog(pb, "asm");
195         out.shouldContain("Dumping shared data to file:");
196         out.shouldMatch("cds.*hello[.]aot");
197         out.shouldHaveExitValue(0);
198     }
199 
200     static void negativeTests() throws Exception {
201        //----------------------------------------------------------------------
202         printTestCase("Mixing old and new options");
203         String mixOldNewErrSuffix = " cannot be used at the same time with -Xshare:on, -Xshare:auto, "
204             + "-Xshare:off, -Xshare:dump, DumpLoadedClassList, SharedClassListFile, "
205             + "or SharedArchiveFile";
206 
207         ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
208             "-Xshare:off",
209             "-XX:AOTConfiguration=" + aotConfigFile,
210             "-cp", appJar, helloClass);
211 
212         OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, "neg");
213         out.shouldContain("Option AOTConfiguration" + mixOldNewErrSuffix);
214         out.shouldNotHaveExitValue(0);
215 
216         pb = ProcessTools.createLimitedTestJavaProcessBuilder(

326         out.shouldNotHaveExitValue(0);
327 
328         //----------------------------------------------------------------------
329         printTestCase("Classpath mismatch when creating archive");
330 
331         pb = ProcessTools.createLimitedTestJavaProcessBuilder(
332             "-XX:AOTMode=create",
333             "-XX:AOTConfiguration=" + aotConfigFile,
334             "-XX:AOTCache=" + aotCacheFile,
335             "-cp", "noSuchJar.jar");
336 
337         out = CDSTestUtils.executeAndLog(pb, "neg");
338         out.shouldContain("class path and/or module path are not compatible with the ones " +
339                           "specified when the AOTConfiguration file was recorded");
340         out.shouldContain("Unable to use create AOT cache");
341         out.shouldHaveExitValue(1);
342     }
343 
344     static int testNum = 0;
345     static void printTestCase(String s) {
346         System.out.println("vvvvvvv TEST CASE " + testNum + ": " + s + ": starts here vvvvvvv");
347         testNum++;
348     }
349 }
< prev index next >