use of java.lang.invoke.ConstantCallSite in project graal by oracle.
the class HotSpotMethodSubstitutionTest method testCallSiteGetTargetSnippet.
public static String testCallSiteGetTargetSnippet(int i) throws Exception {
ConstantCallSite site;
MethodHandles.Lookup lookup = MethodHandles.lookup();
switch(i) {
case 1:
site = GraalDirectives.opaque(new ConstantCallSite(lookup.findVirtual(String.class, "replace", MethodType.methodType(String.class, char.class, char.class))));
break;
default:
site = GraalDirectives.opaque(new ConstantCallSite(lookup.findStatic(java.util.Arrays.class, "asList", MethodType.methodType(java.util.List.class, Object[].class))));
}
return site.getTarget().toString();
}
use of java.lang.invoke.ConstantCallSite in project openj9 by eclipse.
the class ConstantCallSiteTest method testBasicNegative_ConstantCallSite.
/**
* A basic negative test for ConstantCallSite
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void testBasicNegative_ConstantCallSite() throws Throwable {
MethodHandle mh = MethodHandles.lookup().findStatic(SamePackageExample.class, "addPublicStatic", MethodType.methodType(int.class, int.class, int.class));
ConstantCallSite ccs = new ConstantCallSite(mh);
boolean wmtHit = false;
try {
int result = (int) ccs.dynamicInvoker().invokeExact(1, 2, 3);
AssertJUnit.assertEquals(3, result);
} catch (WrongMethodTypeException e) {
wmtHit = true;
}
AssertJUnit.assertTrue(wmtHit);
}
use of java.lang.invoke.ConstantCallSite in project openj9 by eclipse.
the class ConstantCallSiteTest method testType_ConstantCallSite.
/**
* Test for ConstantCallSite.type()
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void testType_ConstantCallSite() throws Throwable {
MethodType mt = MethodType.methodType(int.class, int.class, int.class);
MethodHandle mh = MethodHandles.lookup().findStatic(SamePackageExample.class, "addPublicStatic", mt);
ConstantCallSite ccs = new ConstantCallSite(mh);
AssertJUnit.assertEquals(mt, ccs.type());
}
use of java.lang.invoke.ConstantCallSite in project openj9 by eclipse.
the class ConstantCallSiteTest method testUnconstructedCCS.
@Test(groups = { "level.extended" })
public void testUnconstructedCCS() throws Throwable {
ConstantCallSiteTest ccs = new ConstantCallSiteTest();
MethodHandle hookMH = MethodHandles.lookup().bind(ccs, "hook", MethodType.methodType(MethodHandle.class, ConstantCallSite.class));
try {
ConstantCallSite cs = new MyConstantCallSite(MethodType.methodType(void.class), hookMH);
} catch (NullPointerException e) {
}
;
boolean illegalState = false;
try {
ccs.unconstructedCS.dynamicInvoker();
} catch (IllegalStateException e) {
illegalState = true;
}
AssertJUnit.assertTrue(illegalState);
illegalState = false;
try {
ccs.unconstructedCS.getTarget();
} catch (IllegalStateException e) {
illegalState = true;
}
AssertJUnit.assertTrue(illegalState);
illegalState = false;
try {
ccs.unconstructedCS.type();
} catch (IllegalStateException e) {
illegalState = true;
}
AssertJUnit.assertFalse(illegalState);
}
use of java.lang.invoke.ConstantCallSite in project openj9 by eclipse.
the class ConstantCallSiteTest method testBasic_ConstantCallSite.
/**
* A basic sanity test for ConstantCallSite
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void testBasic_ConstantCallSite() throws Throwable {
MethodHandle mh = MethodHandles.lookup().findStatic(SamePackageExample.class, "addPublicStatic", MethodType.methodType(int.class, int.class, int.class));
ConstantCallSite ccs = new ConstantCallSite(mh);
int result = (int) ccs.dynamicInvoker().invokeExact(1, 2);
AssertJUnit.assertEquals(3, result);
AssertJUnit.assertEquals(mh, ccs.getTarget());
AssertJUnit.assertEquals(mh.type(), ccs.type());
}
Aggregations