Search in sources :

Example 36 with MethodType

use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.

the class MethodTypeTest method testMake_String_ClassLoader.

/**
     * Test of make method, of class MethodType.
     */
@Test
public void testMake_String_ClassLoader() {
    System.out.println("make (from bytecode signature)");
    ClassLoader loader = null;
    MethodType[] instances = { mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi };
    String obj = "Ljava/lang/Object;";
    assertEquals(obj, concat(Object.class));
    String[] expResults = { "(ILjava/lang/String;)V", concat("(", obj, 2, ")", Object.class), "()V", "()" + obj, concat("(", String.class, Integer.class, ")I"), concat("(", String.class, "I)", Integer.class), concat("(", String.class, Integer.class, ")", Integer.class), concat("(", String.class, "I)I") };
    for (int i = 0; i < instances.length; i++) {
        MethodType instance = instances[i];
        String result = instance.toMethodDescriptorString();
        assertEquals("#" + i, expResults[i], result);
        MethodType parsed = MethodType.fromMethodDescriptorString(result, loader);
        assertSame("--#" + i, instance, parsed);
    }
}
Also used : MethodType(java.lang.invoke.MethodType)

Example 37 with MethodType

use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.

the class MethodTypeTest method testParameterCount.

/**
     * Test of parameterCount method, of class MethodType.
     */
@Test
public void testParameterCount() {
    System.out.println("parameterCount");
    MethodType instance = mt_viS;
    int expResult = 2;
    int result = instance.parameterCount();
    assertEquals(expResult, result);
}
Also used : MethodType(java.lang.invoke.MethodType)

Example 38 with MethodType

use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.

the class MethodTypeTest method testDistinct.

/** Make sure the method types are all distinct. */
@Test
public void testDistinct() {
    List<MethodType> gallery2 = new ArrayList<>();
    for (MethodType mt : GALLERY) {
        assertFalse(mt.toString(), gallery2.contains(mt));
        gallery2.add(mt);
    }
    // check self-equality also:
    assertEquals(Arrays.asList(GALLERY), gallery2);
}
Also used : MethodType(java.lang.invoke.MethodType)

Example 39 with MethodType

use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.

the class ThrowExceptionsTest method makeStackOverflow.

private static MethodHandle makeStackOverflow() {
    MethodType cellType = methodType(void.class);
    // recursion point
    MethodHandle[] cell = { null };
    MethodHandle getCell = insertArguments(arrayElementGetter(cell.getClass()), 0, cell, 0);
    MethodHandle invokeCell = foldArguments(exactInvoker(cellType), getCell);
    assert (invokeCell.type() == cellType);
    cell[0] = invokeCell;
    // make it conformable to any type:
    invokeCell = dropArguments(invokeCell, 0, Object[].class).asVarargsCollector(Object[].class);
    return invokeCell;
}
Also used : MethodType(java.lang.invoke.MethodType)

Example 40 with MethodType

use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.

the class VMAnonymousClass method test.

private static void test(String pkg) throws Throwable {
    byte[] bytes = dumpClass(pkg);
    // Define VM anonymous class in privileged context (on BCP).
    Class anonClass = unsafe.defineAnonymousClass(Object.class, bytes, null);
    MethodType t = MethodType.methodType(Object.class, int.class);
    MethodHandle target = MethodHandles.lookup().findStatic(anonClass, "get", t);
    // Wrap target into LF (convert) to get "target" referenced from LF
    MethodHandle wrappedMH = target.asType(MethodType.methodType(Object.class, Integer.class));
    // Invoke enough times to provoke LF compilation to bytecode.
    for (int i = 0; i < 100; i++) {
        Object r = wrappedMH.invokeExact((Integer) 1);
    }
}
Also used : MethodType(java.lang.invoke.MethodType) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

MethodType (java.lang.invoke.MethodType)103 MethodHandle (java.lang.invoke.MethodHandle)37 MethodHandles (java.lang.invoke.MethodHandles)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)3 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)3 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)3 CallSite (java.lang.invoke.CallSite)3 LambdaReceiver_A (LambdaReceiver_anotherpkg.LambdaReceiver_A)2 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)2 ConnectorSession (com.facebook.presto.spi.ConnectorSession)2 PrestoException (com.facebook.presto.spi.PrestoException)2 Map (java.util.Map)2 InitializeInvokerException (cn.moyada.dubbo.faker.core.exception.InitializeInvokerException)1 Session (com.facebook.presto.Session)1 BytecodeNode (com.facebook.presto.bytecode.BytecodeNode)1 ClassDefinition (com.facebook.presto.bytecode.ClassDefinition)1 Parameter (com.facebook.presto.bytecode.Parameter)1 Scope (com.facebook.presto.bytecode.Scope)1