Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/linkage/LinkageErrors.java
41152 views
1
/*
2
* Copyright (c) 2016, 2018, 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
* @test
26
* @bug 8132879
27
* @compile CallSites.jasm
28
* @run main/othervm -Xverify:all -Xbatch
29
* -XX:CompileCommand=dontinline,compiler.linkage.LinkageErrors::test*
30
* compiler.linkage.LinkageErrors
31
*/
32
33
package compiler.linkage;
34
35
import java.lang.invoke.MethodHandle;
36
import java.lang.invoke.MethodHandles;
37
import java.lang.invoke.MethodType;
38
39
interface I {
40
void m1(int i);
41
static void s1() {}
42
}
43
44
class A implements I {
45
public void m1(int i) {}
46
}
47
48
class X {
49
public void m1(int i) {}
50
public final void f1(int i) {}
51
public static void s1(int i) {}
52
}
53
54
public class LinkageErrors {
55
final static MethodHandles.Lookup L = MethodHandles.lookup();
56
57
static void testICCE(MethodHandle mh) {
58
try {
59
mh.invokeExact();
60
throw new AssertionError("No exception thrown");
61
} catch (IncompatibleClassChangeError e) {
62
return; // expected
63
} catch (AssertionError e) {
64
throw e; // rethrow
65
} catch (Throwable e) {
66
throw new AssertionError("Unexpected exception", e);
67
}
68
}
69
70
static void testNSME(MethodHandle mh) {
71
try {
72
mh.invokeExact();
73
throw new AssertionError("No exception thrown");
74
} catch (NoSuchMethodError e) {
75
return; // expected
76
} catch (AssertionError e) {
77
throw e; // rethrow
78
} catch (Throwable e) {
79
throw new AssertionError("Unexpected exception", e);
80
}
81
}
82
83
public static void main(String args[]) throws Throwable {
84
Class<?> test = Class.forName("compiler.linkage.CallSites");
85
86
// Non-existent method lookups.
87
MethodHandle testI1 = L.findStatic(test, "testI1", MethodType.methodType(void.class, I.class));
88
MethodHandle testX1 = L.findStatic(test, "testX1", MethodType.methodType(void.class, X.class));
89
90
MethodHandle testI1_A = testI1.bindTo(new A());
91
MethodHandle testI1_null = testI1.bindTo(null);
92
MethodHandle testX1_X = testX1.bindTo(new X());
93
MethodHandle testX1_null = testX1.bindTo(null);
94
95
// invokestatic of instance methods.
96
MethodHandle testI2 = L.findStatic(test, "testI2", MethodType.methodType(void.class));
97
MethodHandle testX2 = L.findStatic(test, "testX2", MethodType.methodType(void.class));
98
99
MethodHandle testI3 = L.findStatic(test, "testI3", MethodType.methodType(void.class, I.class));
100
MethodHandle testX3 = L.findStatic(test, "testX3", MethodType.methodType(void.class, X.class));
101
102
// Virtual invocation of static methods.
103
MethodHandle testI3_A = testI3.bindTo(new A());
104
MethodHandle testI3_null = testI3.bindTo(null);
105
MethodHandle testX3_X = testX3.bindTo(new X());
106
MethodHandle testX3_null = testX3.bindTo(null);
107
108
for (int i = 0; i < 20_000; i++) {
109
testNSME(testI1_A);
110
testNSME(testI1_null);
111
testNSME(testX1_X);
112
testNSME(testX1_null);
113
114
testICCE(testI2);
115
testICCE(testX2);
116
117
testICCE(testI3_A);
118
testICCE(testI3_null);
119
testICCE(testX3_X);
120
testICCE(testX3_null);
121
}
122
123
System.out.println("TEST PASSED");
124
}
125
}
126
127