author | hseigel |
Wed, 20 Feb 2019 13:21:36 -0500 | |
changeset 53853 | 7ca9e625d6b2 |
parent 52361 | cefc50af3ee7 |
child 54607 | b6db97903b69 |
permissions | -rw-r--r-- |
48138 | 1 |
/* |
53853 | 2 |
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
48138 | 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 |
import java.io.File; |
|
26 |
import java.io.FileOutputStream; |
|
27 |
import jdk.test.lib.process.OutputAnalyzer; |
|
28 |
import java.nio.file.Files; |
|
29 |
||
30 |
import java.util.*; |
|
31 |
import jdk.internal.org.objectweb.asm.*; |
|
32 |
||
33 |
/** |
|
34 |
* The testsets contained in this class are executed by ./VerifierTest_*.java, so that |
|
35 |
* individual testsets can be executed in parallel to shorten the total time required. |
|
36 |
*/ |
|
37 |
public class VerifierTest implements Opcodes { |
|
38 |
// Test verification settings for dumping & runtime |
|
39 |
static final String VFY_ALL = "-Xverify:all"; |
|
40 |
static final String VFY_REMOTE = "-Xverify:remote"; // default |
|
53853 | 41 |
static final String VFY_NONE = "-XX:-BytecodeVerificationRemote, -XX:-BytecodeVerificationLocal"; |
48138 | 42 |
|
43 |
static final String ERR = |
|
44 |
"ERROR: class VerifierTestC was loaded unexpectedly"; |
|
45 |
static final String MAP_FAIL = |
|
46 |
"shared archive file was created with less restrictive verification setting"; |
|
47 |
static final String VFY_ERR = "java.lang.VerifyError"; |
|
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
48 |
static final String PASS_RESULT = "Hi, how are you?"; |
49769
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
49 |
static final String VFY_INFO_MESSAGE = |
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
50 |
"All non-system classes will be verified (-Xverify:remote) during CDS dump time."; |
51370
fbb62267e5e9
8208705: [TESTBUG] The -Xlog:cds,cds+hashtables vm option is not always required for appcds tests
ccheung
parents:
49931
diff
changeset
|
51 |
static final String CDS_LOGGING = "-Xlog:cds,cds+hashtables"; |
48138 | 52 |
|
53 |
enum Testset1Part { |
|
54 |
A, B |
|
55 |
} |
|
56 |
||
57 |
public static void main(String[] args) throws Exception { |
|
58 |
String subCaseId = args[0]; |
|
59 |
String jarName_verifier_test_tmp = "verifier_test_tmp" + "_" + subCaseId; |
|
60 |
String jarName_verifier_test = "verifier_test" + "_" + subCaseId; |
|
61 |
String jarName_greet = "greet" + "_" + subCaseId; |
|
62 |
String jarName_hi = "hi" + "_" + subCaseId; |
|
63 |
||
64 |
||
65 |
JarBuilder.build(jarName_verifier_test_tmp, "VerifierTest0", "VerifierTestA", |
|
66 |
"VerifierTestB", "VerifierTestC", "VerifierTestD", "VerifierTestE", |
|
67 |
"UnverifiableBase", "UnverifiableIntf", "UnverifiableIntfSub"); |
|
68 |
JarBuilder.build(jarName_greet, "Greet"); |
|
69 |
JarBuilder.build(jarName_hi, "Hi", "Hi$MyClass"); |
|
70 |
||
71 |
File dir = new File(System.getProperty("test.classes", ".")); |
|
72 |
File jarSrcFile = new File(dir, jarName_verifier_test_tmp + ".jar"); |
|
73 |
File jarFile = new File(dir, jarName_verifier_test + ".jar"); |
|
74 |
String jar = jarFile.getPath(); |
|
75 |
||
76 |
if (!jarFile.exists() || jarFile.lastModified() < jarSrcFile.lastModified()) { |
|
77 |
createTestJarFile(jarSrcFile, jarFile); |
|
78 |
} else { |
|
79 |
System.out.println("Already up-to-date: " + jarFile); |
|
80 |
} |
|
81 |
||
82 |
String noAppClasses[] = TestCommon.list(""); |
|
83 |
String appClasses[] = TestCommon.list("UnverifiableBase", |
|
84 |
"UnverifiableIntf", |
|
85 |
"UnverifiableIntfSub", |
|
86 |
"VerifierTestA", |
|
87 |
"VerifierTestB", |
|
88 |
"VerifierTestC", |
|
89 |
"VerifierTestD", |
|
90 |
"VerifierTestE", |
|
91 |
"VerifierTest0"); |
|
92 |
||
93 |
||
94 |
switch (subCaseId) { |
|
95 |
case "0": testset_0(jar, noAppClasses, appClasses); return; |
|
96 |
case "1A": testset_1(jar, noAppClasses, appClasses, Testset1Part.A); return; |
|
97 |
case "1B": testset_1(jar, noAppClasses, appClasses, Testset1Part.B); return; |
|
98 |
case "2": testset_2(jarName_greet, jarName_hi); return; |
|
99 |
default: |
|
100 |
throw new RuntimeException("Unknown option: " + subCaseId); |
|
101 |
} |
|
102 |
} |
|
103 |
||
104 |
static void testset_0(String jar, String[] noAppClasses, String[] appClasses) throws Exception { |
|
52361
cefc50af3ee7
8213000: Obsolete the IgnoreUnverifiableClassesDuringDump vm option
ccheung
parents:
51370
diff
changeset
|
105 |
// Unverifiable classes won't be included in the CDS archive. |
cefc50af3ee7
8213000: Obsolete the IgnoreUnverifiableClassesDuringDump vm option
ccheung
parents:
51370
diff
changeset
|
106 |
// Dumping should not fail. |
cefc50af3ee7
8213000: Obsolete the IgnoreUnverifiableClassesDuringDump vm option
ccheung
parents:
51370
diff
changeset
|
107 |
OutputAnalyzer output = TestCommon.dump(jar, appClasses); |
cefc50af3ee7
8213000: Obsolete the IgnoreUnverifiableClassesDuringDump vm option
ccheung
parents:
51370
diff
changeset
|
108 |
output.shouldHaveExitValue(0); |
cefc50af3ee7
8213000: Obsolete the IgnoreUnverifiableClassesDuringDump vm option
ccheung
parents:
51370
diff
changeset
|
109 |
if (output.getStdout().contains("Loading clases to share")) { |
cefc50af3ee7
8213000: Obsolete the IgnoreUnverifiableClassesDuringDump vm option
ccheung
parents:
51370
diff
changeset
|
110 |
// last entry in appClasses[] is a verifiable class |
cefc50af3ee7
8213000: Obsolete the IgnoreUnverifiableClassesDuringDump vm option
ccheung
parents:
51370
diff
changeset
|
111 |
for (int i = 0; i < (appClasses.length - 1); i++) { |
cefc50af3ee7
8213000: Obsolete the IgnoreUnverifiableClassesDuringDump vm option
ccheung
parents:
51370
diff
changeset
|
112 |
output.shouldContain("Verification failed for " + appClasses[i]); |
cefc50af3ee7
8213000: Obsolete the IgnoreUnverifiableClassesDuringDump vm option
ccheung
parents:
51370
diff
changeset
|
113 |
output.shouldContain("Removed error class: " + appClasses[i]); |
cefc50af3ee7
8213000: Obsolete the IgnoreUnverifiableClassesDuringDump vm option
ccheung
parents:
51370
diff
changeset
|
114 |
} |
cefc50af3ee7
8213000: Obsolete the IgnoreUnverifiableClassesDuringDump vm option
ccheung
parents:
51370
diff
changeset
|
115 |
} |
48138 | 116 |
} |
117 |
||
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
118 |
static void checkRuntimeOutput(OutputAnalyzer output, String expected) throws Exception { |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
119 |
output.shouldContain(expected); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
120 |
if (expected.equals(PASS_RESULT) || |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
121 |
expected.equals(VFY_ERR)) { |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
122 |
output.shouldHaveExitValue(0); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
123 |
} else { |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
124 |
output.shouldNotHaveExitValue(0); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
125 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
126 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
127 |
|
48138 | 128 |
static void testset_1(String jar, String[] noAppClasses, String[] appClasses, Testset1Part part) |
129 |
throws Exception |
|
130 |
{ |
|
131 |
String config[][] = { |
|
132 |
// {dump_list, dumptime_verification_setting, |
|
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
133 |
// runtime_verification_setting, expected_output_str}, |
48138 | 134 |
|
135 |
// Dump app/ext with -Xverify:remote |
|
136 |
{"app", VFY_REMOTE, VFY_REMOTE, VFY_ERR}, |
|
137 |
{"app", VFY_REMOTE, VFY_ALL, MAP_FAIL}, |
|
138 |
{"app", VFY_REMOTE, VFY_NONE, ERR }, |
|
139 |
// Dump app/ext with -Xverify:all |
|
140 |
{"app", VFY_ALL, VFY_REMOTE, VFY_ERR }, |
|
141 |
{"app", VFY_ALL, VFY_ALL, VFY_ERR }, |
|
142 |
{"app", VFY_ALL, VFY_NONE, ERR }, |
|
53853 | 143 |
// Dump app/ext with verifier turned off |
49769
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
144 |
{"app", VFY_NONE, VFY_REMOTE, VFY_ERR}, |
48138 | 145 |
{"app", VFY_NONE, VFY_ALL, MAP_FAIL}, |
146 |
{"app", VFY_NONE, VFY_NONE, ERR }, |
|
147 |
// Dump sys only with -Xverify:remote |
|
148 |
{"noApp", VFY_REMOTE, VFY_REMOTE, VFY_ERR}, |
|
149 |
{"noApp", VFY_REMOTE, VFY_ALL, VFY_ERR}, |
|
150 |
{"noApp", VFY_REMOTE, VFY_NONE, ERR}, |
|
151 |
// Dump sys only with -Xverify:all |
|
152 |
{"noApp", VFY_ALL, VFY_REMOTE, VFY_ERR}, |
|
153 |
{"noApp", VFY_ALL, VFY_ALL, VFY_ERR}, |
|
154 |
{"noApp", VFY_ALL, VFY_NONE, ERR}, |
|
53853 | 155 |
// Dump sys only with verifier turned off |
48138 | 156 |
{"noApp", VFY_NONE, VFY_REMOTE, VFY_ERR}, |
157 |
{"noApp", VFY_NONE, VFY_ALL, VFY_ERR}, |
|
158 |
{"noApp", VFY_NONE, VFY_NONE, ERR}, |
|
159 |
}; |
|
160 |
||
161 |
int loop_start, loop_stop; |
|
162 |
||
163 |
// Further break down testset_1 into two parts (to be invoked from VerifierTest_1A.java |
|
164 |
// and VerifierTest_1B.java) to improve parallel test execution time. |
|
165 |
switch (part) { |
|
166 |
case A: |
|
167 |
loop_start = 0; |
|
168 |
loop_stop = 9; |
|
169 |
break; |
|
170 |
case B: |
|
171 |
default: |
|
172 |
assert part == Testset1Part.B; |
|
173 |
loop_start = 9; |
|
174 |
loop_stop = config.length; |
|
175 |
break; |
|
176 |
} |
|
177 |
||
178 |
String prev_dump_setting = ""; |
|
179 |
for (int i = loop_start; i < loop_stop; i ++) { |
|
180 |
String dump_list[] = config[i][0].equals("app") ? appClasses : |
|
181 |
noAppClasses; |
|
182 |
String dump_setting = config[i][1]; |
|
183 |
String runtime_setting = config[i][2]; |
|
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
184 |
String expected_output_str = config[i][3]; |
48138 | 185 |
System.out.println("Test case [" + i + "]: dumping " + config[i][0] + |
186 |
" with " + dump_setting + |
|
187 |
", run with " + runtime_setting); |
|
188 |
if (!dump_setting.equals(prev_dump_setting)) { |
|
53853 | 189 |
String dump_arg1; |
190 |
String dump_arg2; |
|
191 |
// Need to break this into two separate arguments. |
|
192 |
if (dump_setting.equals(VFY_NONE)) { |
|
193 |
dump_arg1 = "-XX:-BytecodeVerificationRemote"; |
|
194 |
dump_arg2 = "-XX:-BytecodeVerificationLocal"; |
|
195 |
} else { |
|
196 |
// Redundant args should be harmless. |
|
197 |
dump_arg1 = dump_arg2 = dump_setting; |
|
198 |
} |
|
199 |
||
48138 | 200 |
OutputAnalyzer dumpOutput = TestCommon.dump( |
53853 | 201 |
jar, dump_list, dump_arg1, dump_arg2, |
51370
fbb62267e5e9
8208705: [TESTBUG] The -Xlog:cds,cds+hashtables vm option is not always required for appcds tests
ccheung
parents:
49931
diff
changeset
|
202 |
CDS_LOGGING, |
48138 | 203 |
// FIXME: the following options are for working around a GC |
204 |
// issue - assert failure when dumping archive with the -Xverify:all |
|
205 |
"-Xms256m", |
|
206 |
"-Xmx256m"); |
|
49769
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
207 |
if (dump_setting.equals(VFY_NONE) && |
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
208 |
runtime_setting.equals(VFY_REMOTE)) { |
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
209 |
dumpOutput.shouldContain(VFY_INFO_MESSAGE); |
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
210 |
} |
48138 | 211 |
} |
53853 | 212 |
String runtime_arg1; |
213 |
String runtime_arg2; |
|
214 |
if (runtime_setting.equals(VFY_NONE)) { |
|
215 |
runtime_arg1 = "-XX:-BytecodeVerificationRemote"; |
|
216 |
runtime_arg2 = "-XX:-BytecodeVerificationLocal"; |
|
217 |
} else { |
|
218 |
// Redundant args should be harmless. |
|
219 |
runtime_arg1 = runtime_arg2 = runtime_setting; |
|
220 |
} |
|
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
221 |
TestCommon.run("-cp", jar, |
53853 | 222 |
runtime_arg1, runtime_arg2, |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
223 |
"VerifierTest0") |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
224 |
.ifNoMappingFailure(output -> checkRuntimeOutput(output, expected_output_str)); |
48138 | 225 |
prev_dump_setting = dump_setting; |
226 |
} |
|
227 |
} |
|
228 |
||
229 |
static void testset_2(String jarName_greet, String jarName_hi) throws Exception { |
|
230 |
String appClasses[]; |
|
231 |
String jar; |
|
232 |
||
233 |
// The following section is for testing the scenarios where |
|
234 |
// the classes are verifiable during dump time. |
|
235 |
appClasses = TestCommon.list("Hi", |
|
236 |
"Greet", |
|
237 |
"Hi$MyClass"); |
|
238 |
jar = TestCommon.getTestJar(jarName_hi + ".jar") + File.pathSeparator + |
|
239 |
TestCommon.getTestJar(jarName_greet + ".jar"); |
|
240 |
String config2[][] = { |
|
241 |
// {dump_list, dumptime_verification_setting, |
|
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
242 |
// runtime_verification_setting, expected_output_str}, |
48138 | 243 |
|
244 |
// Dump app/ext with -Xverify:remote |
|
245 |
{"app", VFY_REMOTE, VFY_REMOTE, PASS_RESULT}, |
|
246 |
{"app", VFY_REMOTE, VFY_ALL, MAP_FAIL}, |
|
247 |
{"app", VFY_REMOTE, VFY_NONE, PASS_RESULT }, |
|
248 |
// Dump app/ext with -Xverify:all |
|
249 |
{"app", VFY_ALL, VFY_REMOTE, PASS_RESULT }, |
|
250 |
{"app", VFY_ALL, VFY_ALL, PASS_RESULT }, |
|
251 |
{"app", VFY_ALL, VFY_NONE, PASS_RESULT }, |
|
53853 | 252 |
// Dump app/ext with verifier turned off |
49769
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
253 |
{"app", VFY_NONE, VFY_REMOTE, PASS_RESULT}, |
48138 | 254 |
{"app", VFY_NONE, VFY_ALL, MAP_FAIL}, |
255 |
{"app", VFY_NONE, VFY_NONE, PASS_RESULT }, |
|
256 |
}; |
|
49769
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
257 |
String prev_dump_setting = ""; |
48138 | 258 |
for (int i = 0; i < config2.length; i ++) { |
259 |
// config2[i][0] is always set to "app" in this test |
|
260 |
String dump_setting = config2[i][1]; |
|
261 |
String runtime_setting = config2[i][2]; |
|
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
262 |
String expected_output_str = config2[i][3]; |
48138 | 263 |
System.out.println("Test case [" + i + "]: dumping " + config2[i][0] + |
264 |
" with " + dump_setting + |
|
265 |
", run with " + runtime_setting); |
|
49769
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
266 |
if (!dump_setting.equals(prev_dump_setting)) { |
53853 | 267 |
String dump_arg1; |
268 |
String dump_arg2; |
|
269 |
if (dump_setting.equals(VFY_NONE)) { |
|
270 |
dump_arg1 = "-XX:-BytecodeVerificationRemote"; |
|
271 |
dump_arg2 = "-XX:-BytecodeVerificationLocal"; |
|
272 |
} else { |
|
273 |
// Redundant args should be harmless. |
|
274 |
dump_arg1 = dump_arg2 = dump_setting; |
|
275 |
} |
|
49769
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
276 |
OutputAnalyzer dumpOutput = TestCommon.dump( |
53853 | 277 |
jar, appClasses, dump_arg1, dump_arg2, |
51370
fbb62267e5e9
8208705: [TESTBUG] The -Xlog:cds,cds+hashtables vm option is not always required for appcds tests
ccheung
parents:
49931
diff
changeset
|
278 |
CDS_LOGGING, |
49769
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
279 |
// FIXME: the following options are for working around a GC |
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
280 |
// issue - assert failure when dumping archive with the -Xverify:all |
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
281 |
"-Xms256m", |
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
282 |
"-Xmx256m"); |
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
283 |
if (dump_setting.equals(VFY_NONE) && |
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
284 |
runtime_setting.equals(VFY_REMOTE)) { |
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
285 |
dumpOutput.shouldContain(VFY_INFO_MESSAGE); |
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
286 |
} |
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
287 |
} |
53853 | 288 |
String runtime_arg1; |
289 |
String runtime_arg2; |
|
290 |
if (runtime_setting.equals(VFY_NONE)) { |
|
291 |
runtime_arg1 = "-XX:-BytecodeVerificationRemote"; |
|
292 |
runtime_arg2 = "-XX:-BytecodeVerificationLocal"; |
|
293 |
} else { |
|
294 |
// Redundant args should be harmless. |
|
295 |
runtime_arg1 = runtime_arg2 = runtime_setting; |
|
296 |
} |
|
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
297 |
TestCommon.run("-cp", jar, |
53853 | 298 |
runtime_arg1, runtime_arg2, |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
299 |
"Hi") |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48973
diff
changeset
|
300 |
.ifNoMappingFailure(output -> checkRuntimeOutput(output, expected_output_str)); |
49769
b8c9bec06921
8197972: Always verify non-system classes during CDS dump time
ccheung
parents:
48979
diff
changeset
|
301 |
prev_dump_setting = dump_setting; |
48138 | 302 |
} |
303 |
} |
|
304 |
||
305 |
static void createTestJarFile(File jarSrcFile, File jarFile) throws Exception { |
|
306 |
jarFile.delete(); |
|
307 |
Files.copy(jarSrcFile.toPath(), jarFile.toPath()); |
|
308 |
||
309 |
File dir = new File(System.getProperty("test.classes", ".")); |
|
310 |
File outdir = new File(dir, "verifier_test_classes"); |
|
311 |
outdir.mkdir(); |
|
312 |
||
313 |
writeClassFile(new File(outdir, "UnverifiableBase.class"), makeUnverifiableBase()); |
|
314 |
writeClassFile(new File(outdir, "UnverifiableIntf.class"), makeUnverifiableIntf()); |
|
315 |
||
316 |
JarBuilder.update(jarFile.getPath(), outdir.getPath()); |
|
317 |
} |
|
318 |
||
319 |
static void writeClassFile(File file, byte bytecodes[]) throws Exception { |
|
320 |
try (FileOutputStream fos = new FileOutputStream(file)) { |
|
321 |
fos.write(bytecodes); |
|
322 |
} |
|
323 |
} |
|
324 |
||
325 |
// This was obtained using JDK8: java jdk.internal.org.objectweb.asm.util.ASMifier tmpclasses/UnverifiableBase.class |
|
326 |
static byte[] makeUnverifiableBase() throws Exception { |
|
327 |
ClassWriter cw = new ClassWriter(0); |
|
328 |
FieldVisitor fv; |
|
329 |
MethodVisitor mv; |
|
330 |
AnnotationVisitor av0; |
|
331 |
||
48973
7b9fcae23a16
8196920: VerifierTest_1A.java and VerifierTest_1B.java fail: assert(receiver_klass->is_subtype_of(static_receiver_klass)) failed: actual receiver must be subclass of static receiver klass
ccheung
parents:
48138
diff
changeset
|
332 |
cw.visit(V1_8, ACC_SUPER, "UnverifiableBase", null, "java/lang/Object", null); |
48138 | 333 |
{ |
334 |
fv = cw.visitField(ACC_FINAL + ACC_STATIC, "x", "LVerifierTest;", null, null); |
|
335 |
fv.visitEnd(); |
|
336 |
} |
|
337 |
{ |
|
338 |
mv = cw.visitMethod(0, "<init>", "()V", null, null); |
|
339 |
mv.visitCode(); |
|
340 |
mv.visitVarInsn(ALOAD, 0); |
|
341 |
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); |
|
342 |
mv.visitInsn(RETURN); |
|
343 |
mv.visitMaxs(1, 1); |
|
344 |
mv.visitEnd(); |
|
345 |
} |
|
346 |
{ |
|
347 |
mv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null); |
|
348 |
mv.visitCode(); |
|
48973
7b9fcae23a16
8196920: VerifierTest_1A.java and VerifierTest_1B.java fail: assert(receiver_klass->is_subtype_of(static_receiver_klass)) failed: actual receiver must be subclass of static receiver klass
ccheung
parents:
48138
diff
changeset
|
349 |
mv.visitTypeInsn(NEW, "VerifierTest0"); |
48138 | 350 |
mv.visitInsn(DUP); |
351 |
mv.visitMethodInsn(INVOKESPECIAL, "VerifierTest0", "<init>", "()V", false); |
|
352 |
mv.visitFieldInsn(PUTSTATIC, "UnverifiableBase", "x", "LVerifierTest;"); |
|
353 |
mv.visitInsn(RETURN); |
|
354 |
mv.visitMaxs(2, 0); |
|
355 |
mv.visitEnd(); |
|
356 |
} |
|
48973
7b9fcae23a16
8196920: VerifierTest_1A.java and VerifierTest_1B.java fail: assert(receiver_klass->is_subtype_of(static_receiver_klass)) failed: actual receiver must be subclass of static receiver klass
ccheung
parents:
48138
diff
changeset
|
357 |
addBadMethod(cw); |
48138 | 358 |
cw.visitEnd(); |
359 |
||
360 |
return cw.toByteArray(); |
|
361 |
} |
|
362 |
||
363 |
// This was obtained using JDK8: java jdk.internal.org.objectweb.asm.util.ASMifier tmpclasses/UnverifiableIntf.class |
|
364 |
static byte[] makeUnverifiableIntf() throws Exception { |
|
365 |
ClassWriter cw = new ClassWriter(0); |
|
366 |
FieldVisitor fv; |
|
367 |
MethodVisitor mv; |
|
368 |
AnnotationVisitor av0; |
|
369 |
||
48973
7b9fcae23a16
8196920: VerifierTest_1A.java and VerifierTest_1B.java fail: assert(receiver_klass->is_subtype_of(static_receiver_klass)) failed: actual receiver must be subclass of static receiver klass
ccheung
parents:
48138
diff
changeset
|
370 |
cw.visit(V1_8, ACC_ABSTRACT + ACC_INTERFACE, "UnverifiableIntf", null, "java/lang/Object", null); |
48138 | 371 |
|
372 |
{ |
|
373 |
fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "x", "LVerifierTest0;", null, null); |
|
374 |
fv.visitEnd(); |
|
375 |
} |
|
376 |
{ |
|
377 |
mv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null); |
|
378 |
mv.visitCode(); |
|
48973
7b9fcae23a16
8196920: VerifierTest_1A.java and VerifierTest_1B.java fail: assert(receiver_klass->is_subtype_of(static_receiver_klass)) failed: actual receiver must be subclass of static receiver klass
ccheung
parents:
48138
diff
changeset
|
379 |
mv.visitTypeInsn(NEW, "VerifierTest0"); |
48138 | 380 |
mv.visitInsn(DUP); |
381 |
mv.visitMethodInsn(INVOKESPECIAL, "VerifierTest0", "<init>", "()V", false); |
|
382 |
mv.visitFieldInsn(PUTSTATIC, "UnverifiableIntf", "x", "LVerifierTest0;"); |
|
383 |
mv.visitInsn(RETURN); |
|
384 |
mv.visitMaxs(2, 0); |
|
385 |
mv.visitEnd(); |
|
386 |
} |
|
48973
7b9fcae23a16
8196920: VerifierTest_1A.java and VerifierTest_1B.java fail: assert(receiver_klass->is_subtype_of(static_receiver_klass)) failed: actual receiver must be subclass of static receiver klass
ccheung
parents:
48138
diff
changeset
|
387 |
addBadMethod(cw); |
48138 | 388 |
cw.visitEnd(); |
389 |
||
390 |
return cw.toByteArray(); |
|
391 |
} |
|
392 |
||
48973
7b9fcae23a16
8196920: VerifierTest_1A.java and VerifierTest_1B.java fail: assert(receiver_klass->is_subtype_of(static_receiver_klass)) failed: actual receiver must be subclass of static receiver klass
ccheung
parents:
48138
diff
changeset
|
393 |
// Add a bad method to make the class fail verification. |
7b9fcae23a16
8196920: VerifierTest_1A.java and VerifierTest_1B.java fail: assert(receiver_klass->is_subtype_of(static_receiver_klass)) failed: actual receiver must be subclass of static receiver klass
ccheung
parents:
48138
diff
changeset
|
394 |
static void addBadMethod(ClassWriter cw) throws Exception { |
7b9fcae23a16
8196920: VerifierTest_1A.java and VerifierTest_1B.java fail: assert(receiver_klass->is_subtype_of(static_receiver_klass)) failed: actual receiver must be subclass of static receiver klass
ccheung
parents:
48138
diff
changeset
|
395 |
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "bad", "()V", null, null); |
7b9fcae23a16
8196920: VerifierTest_1A.java and VerifierTest_1B.java fail: assert(receiver_klass->is_subtype_of(static_receiver_klass)) failed: actual receiver must be subclass of static receiver klass
ccheung
parents:
48138
diff
changeset
|
396 |
mv.visitCode(); |
7b9fcae23a16
8196920: VerifierTest_1A.java and VerifierTest_1B.java fail: assert(receiver_klass->is_subtype_of(static_receiver_klass)) failed: actual receiver must be subclass of static receiver klass
ccheung
parents:
48138
diff
changeset
|
397 |
mv.visitInsn(ARETURN); // java.lang.VerifyError: Operand stack underflow |
7b9fcae23a16
8196920: VerifierTest_1A.java and VerifierTest_1B.java fail: assert(receiver_klass->is_subtype_of(static_receiver_klass)) failed: actual receiver must be subclass of static receiver klass
ccheung
parents:
48138
diff
changeset
|
398 |
mv.visitMaxs(2, 2); |
7b9fcae23a16
8196920: VerifierTest_1A.java and VerifierTest_1B.java fail: assert(receiver_klass->is_subtype_of(static_receiver_klass)) failed: actual receiver must be subclass of static receiver klass
ccheung
parents:
48138
diff
changeset
|
399 |
mv.visitEnd(); |
7b9fcae23a16
8196920: VerifierTest_1A.java and VerifierTest_1B.java fail: assert(receiver_klass->is_subtype_of(static_receiver_klass)) failed: actual receiver must be subclass of static receiver klass
ccheung
parents:
48138
diff
changeset
|
400 |
} |
48138 | 401 |
} |