|
1 /* |
|
2 * Copyright (c) 2014, 2019, 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 test the -XX:+PrintSharedArchiveAndExit flag |
|
28 * @requires vm.cds |
|
29 * @library /test/lib |
|
30 * @modules jdk.jartool/sun.tools.jar |
|
31 * @compile test-classes/Hello.java |
|
32 * @compile test-classes/HelloMore.java |
|
33 * @run main/othervm/timeout=3600 PrintSharedArchiveAndExit |
|
34 */ |
|
35 |
|
36 import java.io.File; |
|
37 import jdk.test.lib.process.OutputAnalyzer; |
|
38 |
|
39 public class PrintSharedArchiveAndExit { |
|
40 private static void check(OutputAnalyzer output, int ret, boolean checkContain, String... matches) throws Exception { |
|
41 // Tests specific to this test |
|
42 TestCommon.checkExecReturn(output, ret, checkContain, matches); |
|
43 |
|
44 // In all test case, we should never print out the following due to |
|
45 // PrintSharedArchiveAndExit. JVM should have been terminated |
|
46 // before reaching these outputs. |
|
47 TestCommon.checkExecReturn(output, ret, false, |
|
48 "Usage:", // JVM help message |
|
49 "java version", // JVM version |
|
50 "Hello World"); // output from the Hello.class in hello.jar |
|
51 } |
|
52 |
|
53 private static void log(String msg) { |
|
54 System.out.println(">---------------------------------------------------------------------"); |
|
55 System.out.println(msg); |
|
56 System.out.println("<---------------------------------------------------------------------"); |
|
57 } |
|
58 |
|
59 public static void main(String[] args) throws Exception { |
|
60 String appJar = JarBuilder.getOrCreateHelloJar(); |
|
61 String appJar2 = JarBuilder.build("PrintSharedArchiveAndExit-more", "HelloMore"); |
|
62 |
|
63 String cp = appJar + File.pathSeparator + appJar2; |
|
64 String lastCheckMsg = "checking shared classpath entry: " + appJar2; // the last JAR to check |
|
65 |
|
66 TestCommon.testDump(cp, TestCommon.list("Hello", "HelloMore")); |
|
67 |
|
68 log("Normal execution -- all the JAR paths should be checked"); |
|
69 TestCommon.run( |
|
70 "-cp", cp, |
|
71 "-XX:+PrintSharedArchiveAndExit") |
|
72 .ifNoMappingFailure(output -> check(output, 0, true, lastCheckMsg)); |
|
73 |
|
74 TestCommon.run( |
|
75 "-cp", cp, |
|
76 "-XX:+PrintSharedArchiveAndExit", |
|
77 "-XX:+PrintSharedDictionary") // Test PrintSharedDictionary as well. |
|
78 .ifNoMappingFailure(output -> check(output, 0, true, lastCheckMsg, "java.lang.Object")); |
|
79 |
|
80 log("Normal execution -- Make sure -version, help message and app main()\n" + |
|
81 "class are not invoked. These are checked inside check()."); |
|
82 TestCommon.run("-cp", cp, "-XX:+PrintSharedArchiveAndExit", "-version") |
|
83 .ifNoMappingFailure(output -> check(output, 0, true, lastCheckMsg)); |
|
84 |
|
85 TestCommon.run("-cp", cp, "-XX:+PrintSharedArchiveAndExit", "-help") |
|
86 .ifNoMappingFailure(output -> check(output, 0, true, lastCheckMsg)); |
|
87 |
|
88 TestCommon.run("-cp", cp, "-XX:+PrintSharedArchiveAndExit", "Hello") |
|
89 .ifNoMappingFailure(output -> check(output, 0, true, lastCheckMsg)); |
|
90 |
|
91 log("Execution with simple errors -- with 'simple' errors like missing or modified\n" + |
|
92 "JAR files, the VM should try to continue to print the remaining information.\n" + |
|
93 "Use an invalid Boot CP -- all the JAR paths should be checked"); |
|
94 TestCommon.run( |
|
95 "-cp", cp, |
|
96 "-Xbootclasspath/a:foo.jar", |
|
97 "-XX:+PrintSharedArchiveAndExit") |
|
98 .ifNoMappingFailure(output -> check(output, 1, true, lastCheckMsg, "[BOOT classpath mismatch, ")); |
|
99 |
|
100 log("Use an App CP shorter than the one at dump time -- all the JAR paths should be checked"); |
|
101 TestCommon.run( |
|
102 "-cp", ".", |
|
103 "-XX:+PrintSharedArchiveAndExit") |
|
104 .ifNoMappingFailure(output -> check(output, 1, true, lastCheckMsg, "Run time APP classpath is shorter than the one at dump time: .")); |
|
105 |
|
106 log("Use an invalid App CP -- all the JAR paths should be checked.\n" + |
|
107 "Non-existing jar files will be ignored."); |
|
108 String invalidCP = "non-existing-dir" + File.pathSeparator + cp; |
|
109 TestCommon.run( |
|
110 "-cp", invalidCP, |
|
111 "-XX:+PrintSharedArchiveAndExit") |
|
112 .ifNoMappingFailure(output -> check(output, 0, true, lastCheckMsg)); |
|
113 |
|
114 log("Changed modification time of hello.jar -- all the JAR paths should be checked"); |
|
115 (new File(appJar)).setLastModified(System.currentTimeMillis() + 2000); |
|
116 TestCommon.run( |
|
117 "-cp", cp, |
|
118 "-XX:+PrintSharedArchiveAndExit") |
|
119 .ifNoMappingFailure(output -> check(output, 1, true, lastCheckMsg, "[Timestamp mismatch]")); |
|
120 |
|
121 log("Even if hello.jar is out of date, we should still be able to print the dictionary."); |
|
122 TestCommon.run( |
|
123 "-cp", cp, |
|
124 "-XX:+PrintSharedArchiveAndExit", |
|
125 "-XX:+PrintSharedDictionary") // Test PrintSharedDictionary as well. |
|
126 .ifNoMappingFailure(output -> check(output, 1, true, lastCheckMsg, "java.lang.Object")); |
|
127 |
|
128 |
|
129 log("Remove hello.jar -- all the JAR paths should be checked"); |
|
130 (new File(appJar)).delete(); |
|
131 TestCommon.run( |
|
132 "-cp", cp, |
|
133 "-XX:+PrintSharedArchiveAndExit") |
|
134 .ifNoMappingFailure(output -> check(output, 1, true, lastCheckMsg, "[Required classpath entry does not exist: " + appJar + "]")); |
|
135 |
|
136 log("Execution with major errors -- with 'major' errors like the JSA file\n" + |
|
137 "is missing, we should stop immediately to avoid crashing the JVM."); |
|
138 TestCommon.run( |
|
139 "-cp", cp, |
|
140 "-XX:+PrintSharedArchiveAndExit", |
|
141 "-XX:SharedArchiveFile=./no-such-fileappcds.jsa") |
|
142 .ifNoMappingFailure(output -> check(output, 1, false, lastCheckMsg)); |
|
143 } |
|
144 } |