author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 54432 | 532e88de77eb |
permissions | -rw-r--r-- |
47554
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
1 |
/* |
50036
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
47554
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
4 |
* |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
8 |
* |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
13 |
* accompanied this code). |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
14 |
* |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
18 |
* |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
21 |
* questions. |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
22 |
*/ |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
23 |
|
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
24 |
/* |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
25 |
* @test |
50036
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
26 |
* @bug 8186092 8199852 |
47554
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
27 |
* @compile ../common/Foo.java |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
28 |
* ../common/J.java |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
29 |
* I.java |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
30 |
* ../common/C.jasm |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
31 |
* Task.java |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
32 |
* ../common/PreemptingClassLoader.java |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
33 |
* @run main/othervm Test |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
34 |
*/ |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
35 |
|
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
36 |
public class Test { |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
37 |
|
51097
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
38 |
// Break expected error messages into 3 parts since the loader name includes its identity |
50634
c349d409262a
8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents:
50036
diff
changeset
|
39 |
// hash which is unique and can't be compared against. |
51097
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
40 |
static String expectedErrorMessage1_part1 = "loader constraint violation for class test.Task: when " + |
54432
532e88de77eb
8221470: Print methods in exception messages in java-like Syntax.
goetz
parents:
51097
diff
changeset
|
41 |
"selecting overriding method 'test.Foo test.Task.m()' the " + |
51097
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
42 |
"class loader PreemptingClassLoader @"; |
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
43 |
static String expectedErrorMessage1_part2 = " of the selected method's type test.Task, and the class " + |
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
44 |
"loader 'app' for its super type test.J have different Class objects " + |
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
45 |
"for the type test.Foo used in the signature (test.Task is in unnamed " + |
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
46 |
"module of loader PreemptingClassLoader @"; |
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
47 |
static String expectedErrorMessage1_part3 = ", parent loader 'app'; test.J is in unnamed module of loader 'app')"; |
50036
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
48 |
|
51097
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
49 |
static String expectedErrorMessage2_part1 = "loader constraint violation for class test.Task: when " + |
54432
532e88de77eb
8221470: Print methods in exception messages in java-like Syntax.
goetz
parents:
51097
diff
changeset
|
50 |
"selecting overriding method 'test.Foo test.Task.m()' the " + |
51097
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
51 |
"class loader 'VtableLdrCnstrnt_Test_Loader' @"; |
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
52 |
static String expectedErrorMessage2_part2 = " of the selected method's type test.Task, and the class " + |
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
53 |
"loader 'app' for its super type test.J have different Class objects " + |
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
54 |
"for the type test.Foo used in the signature (test.Task is in unnamed " + |
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
55 |
"module of loader 'VtableLdrCnstrnt_Test_Loader' @"; |
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
56 |
static String expectedErrorMessage2_part3 = ", parent loader 'app'; test.J is in unnamed module of loader 'app')"; |
50036
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
57 |
|
47554
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
58 |
// Test that the error message is correct when a loader constraint error is |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
59 |
// detected during vtable creation. |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
60 |
// |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
61 |
// In this test, during vtable creation for class Task, method "Task.m()LFoo;" |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
62 |
// overrides "J.m()LFoo;". But, Task's class Foo and super type J's class Foo |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
63 |
// are different. So, a LinkageError exception should be thrown because the |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
64 |
// loader constraint check will fail. |
50634
c349d409262a
8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents:
50036
diff
changeset
|
65 |
public static void test(String loaderName, |
c349d409262a
8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents:
50036
diff
changeset
|
66 |
String expectedErrorMessage_part1, |
51097
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
67 |
String expectedErrorMessage_part2, |
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
68 |
String expectedErrorMessage_part3) throws Exception { |
50036
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
69 |
Class<?> c = test.Foo.class; // Forces standard class loader to load Foo. |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
70 |
String[] classNames = {"test.Task", "test.Foo", "test.I"}; |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
71 |
ClassLoader l = new PreemptingClassLoader(loaderName, classNames); |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
72 |
l.loadClass("test.Foo"); |
47554
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
73 |
try { |
50036
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
74 |
l.loadClass("test.Task").newInstance(); |
47554
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
75 |
throw new RuntimeException("Expected LinkageError exception not thrown"); |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
76 |
} catch (LinkageError e) { |
50036
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
77 |
String errorMsg = e.getMessage(); |
50634
c349d409262a
8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents:
50036
diff
changeset
|
78 |
if (!errorMsg.contains(expectedErrorMessage_part1) || |
51097
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
79 |
!errorMsg.contains(expectedErrorMessage_part2) || |
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
80 |
!errorMsg.contains(expectedErrorMessage_part3)) { |
50634
c349d409262a
8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents:
50036
diff
changeset
|
81 |
System.out.println("Expected: " + expectedErrorMessage_part1 + "<id>" + expectedErrorMessage_part2 + "\n" + |
50036
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
82 |
"but got: " + errorMsg); |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
83 |
throw new RuntimeException("Wrong LinkageError exception thrown: " + errorMsg); |
47554
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
84 |
} |
50036
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
85 |
System.out.println("Passed with message: " + errorMsg); |
47554
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
86 |
} |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
87 |
} |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
88 |
|
50036
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
89 |
public static void main(String args[]) throws Exception { |
51097
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
90 |
test(null, expectedErrorMessage1_part1, |
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
91 |
expectedErrorMessage1_part2, expectedErrorMessage1_part3); |
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
92 |
test("VtableLdrCnstrnt_Test_Loader", expectedErrorMessage2_part1, |
bef02342d179
8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents:
50634
diff
changeset
|
93 |
expectedErrorMessage2_part2, expectedErrorMessage2_part3); |
50036
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
94 |
} |
47554
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
95 |
} |