Search in sources :

Example 16 with ConstantCallSite

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();
}
Also used : MethodHandles(java.lang.invoke.MethodHandles) ConstantCallSite(java.lang.invoke.ConstantCallSite)

Example 17 with ConstantCallSite

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);
}
Also used : ConstantCallSite(java.lang.invoke.ConstantCallSite) WrongMethodTypeException(java.lang.invoke.WrongMethodTypeException) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 18 with ConstantCallSite

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());
}
Also used : MethodType(java.lang.invoke.MethodType) ConstantCallSite(java.lang.invoke.ConstantCallSite) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 19 with ConstantCallSite

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);
}
Also used : ConstantCallSite(java.lang.invoke.ConstantCallSite) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 20 with ConstantCallSite

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());
}
Also used : ConstantCallSite(java.lang.invoke.ConstantCallSite) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Aggregations

ConstantCallSite (java.lang.invoke.ConstantCallSite)28 MethodHandle (java.lang.invoke.MethodHandle)25 Test (org.testng.annotations.Test)9 MethodType (java.lang.invoke.MethodType)5 MethodHandles (java.lang.invoke.MethodHandles)4 Lookup (java.lang.invoke.MethodHandles.Lookup)3 AbsoluteReference (st.gravel.support.compiler.ast.AbsoluteReference)3 WrongMethodTypeException (java.lang.invoke.WrongMethodTypeException)2 Constructor (java.lang.reflect.Constructor)2 DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)1 BytecodeExpressions.constantString (com.facebook.presto.bytecode.expression.BytecodeExpressions.constantString)1 CompiledObject (com.github.anba.es6draft.compiler.CompiledObject)1 TypedArrayObject (com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject)1 GeneratorObject (com.github.anba.es6draft.runtime.objects.iteration.GeneratorObject)1 HTMLDDAObject (com.github.anba.es6draft.runtime.types.HTMLDDAObject)1 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)1 StringObject (com.github.anba.es6draft.runtime.types.builtins.StringObject)1 CrossPackageHelper (differentpackage.CrossPackageHelper)1 NonNull (dyvil.annotation.internal.NonNull)1 MutableCallSite (java.lang.invoke.MutableCallSite)1