Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/runtime/LoaderConstraints/differentLE/Test.java
41153 views
1
/*
2
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2018 SAP SE. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*/
24
25
/**
26
* @test
27
* @bug 8199852
28
* @summary Test exception messages of LinkageError. Two class loaders load
29
* two different versions of a class. Should trigger exception in
30
* SystemDictionary::check_constraints().
31
* @library /test/lib
32
* @compile D_ambgs.jasm
33
* @run driver jdk.test.lib.helpers.ClassFileInstaller test.D_ambgs
34
* @compile ../common/PreemptingClassLoader.java
35
* test/D_ambgs.java Test.java test/B.java
36
* @run driver jdk.test.lib.helpers.ClassFileInstaller test.B
37
* @run main/othervm Test
38
*/
39
40
import test.*;
41
42
import java.io.ByteArrayOutputStream;
43
import java.io.InputStream;
44
45
import java.io.*;
46
import java.nio.file.Files;
47
import java.nio.file.Path;
48
import java.nio.file.Paths;
49
50
public class Test {
51
52
// Force LinkageError.
53
//
54
// Derived from test runtime/6626217.
55
//
56
// Uses the specialized class loader PreemptingClassLoader.
57
// PreemptingClassLoader only loads files with names passed to it in its
58
// constructor. If it does not find it, it delegates to the super class loader.
59
//
60
// A // interface
61
// |
62
// B // Compiled to the current working directory so that it is found by our
63
// // special class loader. B uses D, so that loading B triggers loading D.
64
//
65
// C // An abstract class.
66
// |
67
// D // Class with two different implementations D1 and D2. D2 is
68
// // compiled to the current working directory so that it is found by our
69
// // special class loader.
70
//
71
// First, the bootstrap loader will load D1. It already has loaded interface A.
72
// Then, the second class loader PreemptingClassLoader will load B. Recursive,
73
// it tries to load interface A. As it does not find it (there is no A.impl2),
74
// it asks the super classloader for A.
75
// Then it loads the D2 variant of D from the current working directory and it's
76
// superclass C. This fails as D1 is already loaded with the same superclass.
77
78
// Break the expectedErrorMessage into 2 pieces since the loader name will include
79
// its identity hash and can not be compared against.
80
static String expectedErrorMessage_part1 = "loader constraint violation: loader PreemptingClassLoader @";
81
static String expectedErrorMessage_part2 = " wants to load class test.D_ambgs. A different class " +
82
"with the same name was previously loaded by 'app'. " +
83
"(test.D_ambgs is in unnamed module of loader 'app')";
84
public static void test_access() throws Exception {
85
try {
86
// Make a Class 'D_ambgs' under the default loader.
87
// This uses the implementation from the .java file.
88
C c_1 = new D_ambgs();
89
90
// Some classes under a new Loader, loader2, including, indirectly,
91
// another version of 'D_ambgs'
92
String[] classNames = {"test.B", "test.D_ambgs"};
93
94
ClassLoader loader2 = new PreemptingClassLoader(null, classNames, false);
95
Class class2 = loader2.loadClass("test.B");
96
A iface = (A)class2.newInstance();
97
98
// Call D1.make() loaded by bootstrap loader with B loaded by Loader2.
99
D_ambgs[] x2 = c_1.make(iface);
100
101
throw new RuntimeException("Expected LinkageError was not thrown.");
102
} catch (LinkageError jle) {
103
String errorMsg = jle.getMessage();
104
if (!errorMsg.contains(expectedErrorMessage_part1) ||
105
!errorMsg.contains(expectedErrorMessage_part2)) {
106
System.out.println("Expected: " + expectedErrorMessage_part1 + "<id>" + expectedErrorMessage_part2 + "\n" +
107
"but got: " + errorMsg);
108
throw new RuntimeException("Wrong error message of LinkageError.");
109
} else {
110
System.out.println("Passed with message: " + errorMsg);
111
}
112
}
113
}
114
115
public static void main(String[] args) throws Exception {
116
test_access();
117
}
118
}
119
120