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/VolatileCallSiteTest.java
6007 views
1
/*******************************************************************************
2
* Copyright (c) 2001, 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.invoke.VolatileCallSite;
30
import java.lang.invoke.WrongMethodTypeException;
31
32
/**
33
* @author mesbah
34
* This class contains tests for VolatileCallSite API
35
*/
36
public class VolatileCallSiteTest {
37
/**
38
* Test for VolatileCallSite.type()
39
* @throws Throwable
40
*/
41
@Test(groups = { "level.extended" })
42
public void testType_VolatileCallSite() throws Throwable {
43
MethodType mt = MethodType.methodType(String.class);
44
MethodHandle mh = MethodHandles.lookup().findStatic(SamePackageExample.class, "returnOne",mt);
45
VolatileCallSite vcs = new VolatileCallSite(mh);
46
47
AssertJUnit.assertEquals(mt,vcs.type());
48
}
49
50
/**
51
* Test for validating default MethodHandle behavior of VolatileCallSite
52
* using VolatileCallSite.dynamicInvoker.invoke()
53
* @throws Throwable
54
*/
55
@Test(groups = { "level.extended" })
56
public void testIllegalState_dynamicInvoker_VolatileCallSite() throws Throwable {
57
MethodType mt = MethodType.methodType(void.class);
58
VolatileCallSite vcs = new VolatileCallSite(mt);
59
boolean iseHit = false;
60
61
try {
62
vcs.dynamicInvoker().invoke();
63
}
64
catch ( IllegalStateException e ) {
65
iseHit = true;
66
}
67
68
AssertJUnit.assertTrue(iseHit);
69
}
70
71
/**
72
* Test for validating default MethodHandle behavior of VolatileCallSite
73
* using VolatileCallSite.getTarget().invoke()
74
* @throws Throwable
75
*/
76
@Test(groups = { "level.extended" })
77
public void testIllegalState_getTarget_VolatileCallSite() throws Throwable {
78
MethodType mt = MethodType.methodType(void.class);
79
VolatileCallSite vcs = new VolatileCallSite(mt);
80
boolean iseHit = false;
81
82
try {
83
vcs.getTarget().invoke();
84
}
85
catch ( IllegalStateException e ) {
86
iseHit = true;
87
}
88
89
AssertJUnit.assertTrue(iseHit);
90
}
91
92
/**
93
* Basic sanity test for VolatileCallSite
94
* @throws Throwable
95
*/
96
@Test(groups = { "level.extended" })
97
public void testBasic_VolatileCallSite() throws Throwable {
98
MethodType mt = MethodType.methodType(double.class,String.class);
99
VolatileCallSite vcs = new VolatileCallSite(mt);
100
MethodHandle mh = MethodHandles.lookup().findStatic(Double.class, "parseDouble",vcs.type());
101
vcs.setTarget(mh);
102
double d = (double)vcs.dynamicInvoker().invokeExact("1.1");
103
104
AssertJUnit.assertEquals(1.1,d);
105
}
106
107
/**
108
* Basic negative test for VolatileCallSite
109
* @throws Throwable
110
*/
111
@Test(groups = { "level.extended" })
112
public void testBasicNegative_VolatileCallSite() throws Throwable {
113
MethodHandle mh = MethodHandles.lookup().findStatic(Math.class, "sin",MethodType.methodType(double.class,double.class));
114
VolatileCallSite vcs = new VolatileCallSite(mh);
115
116
boolean wmtThrown = false;
117
118
try {
119
String s = (String)vcs.dynamicInvoker().invokeExact(0.0);
120
}
121
catch ( WrongMethodTypeException e ) {
122
wmtThrown = true;
123
}
124
125
AssertJUnit.assertTrue(wmtThrown);
126
}
127
}
128
129