Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/Jsr292/src/com/ibm/j9/jsr292/ReceiverBoundHandleTest.java
6007 views
1
/*******************************************************************************
2
* Copyright (c) 2014, 2018 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
package com.ibm.j9.jsr292;
23
24
import org.testng.annotations.Test;
25
import org.testng.AssertJUnit;
26
import java.lang.invoke.MethodHandle;
27
import java.lang.invoke.MethodHandles;
28
import java.lang.invoke.MethodType;
29
import java.lang.reflect.Field;
30
31
/**
32
* A class to check if a specific method is correctly compiled by JIT
33
*/
34
public class ReceiverBoundHandleTest {
35
36
@Test(groups = { "level.extended" })
37
public void testIfRecieverBoundHandleTestIsJitted() throws Throwable {
38
try {
39
TestClass_RBH clazz = new TestClass_RBH();
40
MethodHandle mh = MethodHandles.lookup().findVirtual(TestClass_RBH.class, "test", MethodType.methodType(void.class)).bindTo(clazz);
41
AssertJUnit.assertTrue(mh.getClass().toString().equals("class java.lang.invoke.ReceiverBoundHandle"));
42
try {
43
while (true) {
44
mh.invokeExact();
45
}
46
} catch (Error t) {
47
t.printStackTrace();
48
}
49
} catch (JittingDetector j) {
50
AssertJUnit.assertTrue(true);
51
}
52
}
53
}
54
55
class TestClass_RBH {
56
57
static long PC = 0;
58
59
static final Field throwable_walkback;
60
61
static {
62
Field f;
63
try {
64
f = Throwable.class.getDeclaredField("walkback");
65
f.setAccessible(true);
66
throwable_walkback = f;
67
} catch (NoSuchFieldException | SecurityException e) {
68
throw new RuntimeException();
69
}
70
}
71
72
public void test() throws Throwable {
73
Throwable t = new Throwable();
74
Object walkback = throwable_walkback.get(t);
75
if (walkback instanceof int[]) {
76
int[] iWalkback = (int[])walkback;
77
if (PC == 0) {
78
PC = iWalkback[0];
79
} else if (PC != iWalkback[0]) {
80
throw new JittingDetector("detected jitting");
81
}
82
} else {
83
long[] iWalkback = (long[])walkback;
84
if (PC == 0) {
85
PC = iWalkback[0];
86
} else if (PC != iWalkback[0]) {
87
throw new JittingDetector("detected jitting");
88
}
89
}
90
}
91
}
92
93