author | goetz |
Mon, 07 May 2018 11:38:21 +0200 | |
changeset 50036 | e0dbf14885b8 |
parent 47554 | bc112140e089 |
child 50634 | c349d409262a |
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 |
|
50036
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
38 |
static String expectedErrorMessage1 = |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
39 |
"loader constraint violation for class test.Task: " + |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
40 |
"when selecting overriding method test.Task.m()Ltest/Foo; " + |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
41 |
"the class loader \"<unnamed>\" (instance of PreemptingClassLoader, " + |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
42 |
"child of \"app\" jdk.internal.loader.ClassLoaders$AppClassLoader) " + |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
43 |
"of the selected method's type test.Task, " + |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
44 |
"and the class loader \"app\" (instance of jdk.internal.loader.ClassLoaders$AppClassLoader) " + |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
45 |
"for its super type test.J " + |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
46 |
"have different Class objects for the type test.Foo used in the signature"; |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
47 |
|
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
48 |
static String expectedErrorMessage2 = |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
49 |
"loader constraint violation for class test.Task: " + |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
50 |
"when selecting overriding method test.Task.m()Ltest/Foo; " + |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
51 |
"the class loader \"VtableLdrCnstrnt_Test_Loader\" (instance of PreemptingClassLoader, " + |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
52 |
"child of \"app\" jdk.internal.loader.ClassLoaders$AppClassLoader) " + |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
53 |
"of the selected method's type test.Task, " + |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
54 |
"and the class loader \"app\" (instance of jdk.internal.loader.ClassLoaders$AppClassLoader) " + |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
55 |
"for its super type test.J " + |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
56 |
"have different Class objects for the type test.Foo used in the signature"; |
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. |
50036
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
65 |
public static void test(String loaderName, String expectedErrorMessage) throws Exception { |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
66 |
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
|
67 |
String[] classNames = {"test.Task", "test.Foo", "test.I"}; |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
68 |
ClassLoader l = new PreemptingClassLoader(loaderName, classNames); |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
69 |
l.loadClass("test.Foo"); |
47554
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
70 |
try { |
50036
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
71 |
l.loadClass("test.Task").newInstance(); |
47554
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
72 |
throw new RuntimeException("Expected LinkageError exception not thrown"); |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
73 |
} catch (LinkageError e) { |
50036
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
74 |
String errorMsg = e.getMessage(); |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
75 |
if (!errorMsg.equals(expectedErrorMessage)) { |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
76 |
System.out.println("Expected: " + expectedErrorMessage + "\n" + |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
77 |
"but got: " + errorMsg); |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
78 |
throw new RuntimeException("Wrong LinkageError exception thrown: " + errorMsg); |
47554
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
79 |
} |
50036
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
80 |
System.out.println("Passed with message: " + errorMsg); |
47554
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
81 |
} |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
82 |
} |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
83 |
|
50036
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
84 |
public static void main(String args[]) throws Exception { |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
85 |
test(null, expectedErrorMessage1); |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
86 |
test("VtableLdrCnstrnt_Test_Loader", expectedErrorMessage2); |
e0dbf14885b8
8199852: Print more information about class loaders in LinkageErrors.
goetz
parents:
47554
diff
changeset
|
87 |
} |
47554
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
88 |
} |
bc112140e089
8186092: Unnecessary loader constraints produced when there are multiple defaults
hseigel
parents:
diff
changeset
|
89 |