Search in sources :

Example 11 with CallSite

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

the class LambdaReceiver method main.

public static void main(String[] args) throws Throwable {
    l = MethodHandles.lookup();
    h = l.findVirtual(LambdaReceiver_A.class, "f", mt(int.class));
    MethodType X = mt(int.class, LambdaReceiver.class);
    MethodType A = mt(int.class, LambdaReceiver_A.class);
    MethodType mti = mt(IA.class);
    CallSite cs = LambdaMetafactory.metafactory(l, "m", mti, A, h, X);
    IA p = (IA) cs.dynamicInvoker().invoke();
    LambdaReceiver_A lra = new LambdaReceiver_A();
    try {
        p.m(lra);
    } catch (ClassCastException cce) {
        return;
    }
    throw new AssertionError("CCE expected");
}
Also used : MethodType(java.lang.invoke.MethodType) LambdaReceiver_A(LambdaReceiver_anotherpkg.LambdaReceiver_A) CallSite(java.lang.invoke.CallSite)

Example 12 with CallSite

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

the class LambdaReceiverBridge method main.

public static void main(String[] args) throws Throwable {
    l = MethodHandles.lookup();
    h = l.findVirtual(LambdaReceiver_A.class, "f", mt(int.class));
    MethodType X = mt(int.class, LambdaReceiverBridge.class);
    MethodType A = mt(int.class, LambdaReceiver_A.class);
    MethodType mti = mt(IA.class);
    CallSite cs = LambdaMetafactory.altMetafactory(l, "m", mti, X, h, X, LambdaMetafactory.FLAG_BRIDGES, 1, A);
    IA p = (IA) cs.dynamicInvoker().invoke();
    LambdaReceiver_A lra = new LambdaReceiver_A();
    try {
        p.m(lra);
    } catch (ClassCastException cce) {
        return;
    }
    throw new AssertionError("CCE expected");
}
Also used : MethodType(java.lang.invoke.MethodType) LambdaReceiver_A(LambdaReceiver_anotherpkg.LambdaReceiver_A) CallSite(java.lang.invoke.CallSite)

Example 13 with CallSite

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

the class SerializedLambdaTest method testAltStdNonser.

// alt MF: nonserializable supertype
public void testAltStdNonser() throws Throwable {
    MethodHandle fooMH = MethodHandles.lookup().findStatic(SerializedLambdaTest.class, "foo", predicateMT);
    // Alt metafactory, non-serializable target: not serializable
    CallSite cs = LambdaMetafactory.altMetafactory(MethodHandles.lookup(), "test", MethodType.methodType(Predicate.class), predicateMT, fooMH, stringPredicateMT, 0);
    assertNotSerial((Predicate<String>) cs.getTarget().invokeExact(), fooAsserter);
}
Also used : CallSite(java.lang.invoke.CallSite) MethodHandle(java.lang.invoke.MethodHandle) Predicate(java.util.function.Predicate) BiPredicate(java.util.function.BiPredicate)

Example 14 with CallSite

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

the class SerializedLambdaTest method testDirectStdSer.

// standard MF: serializable supertype
public void testDirectStdSer() throws Throwable {
    MethodHandle fooMH = MethodHandles.lookup().findStatic(SerializedLambdaTest.class, "foo", predicateMT);
    // Standard metafactory, serializable target: not serializable
    CallSite cs = LambdaMetafactory.metafactory(MethodHandles.lookup(), "test", MethodType.methodType(SerPredicate.class), predicateMT, fooMH, stringPredicateMT);
    assertNotSerial((SerPredicate<String>) cs.getTarget().invokeExact(), fooAsserter);
}
Also used : CallSite(java.lang.invoke.CallSite) MethodHandle(java.lang.invoke.MethodHandle)

Example 15 with CallSite

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

the class SerializedLambdaTest method testAltStdSer.

// alt MF: serializable supertype
public void testAltStdSer() throws Throwable {
    MethodHandle fooMH = MethodHandles.lookup().findStatic(SerializedLambdaTest.class, "foo", predicateMT);
    // Alt metafactory, serializable target, no FLAG_SERIALIZABLE: not serializable
    CallSite cs = LambdaMetafactory.altMetafactory(MethodHandles.lookup(), "test", MethodType.methodType(SerPredicate.class), predicateMT, fooMH, stringPredicateMT, 0);
    assertNotSerial((SerPredicate<String>) cs.getTarget().invokeExact(), fooAsserter);
    // Alt metafactory, serializable marker, no FLAG_SERIALIZABLE: not serializable
    cs = LambdaMetafactory.altMetafactory(MethodHandles.lookup(), "test", MethodType.methodType(Predicate.class), predicateMT, fooMH, stringPredicateMT, LambdaMetafactory.FLAG_MARKERS, 1, Serializable.class);
    assertNotSerial((Predicate<String>) cs.getTarget().invokeExact(), fooAsserter);
}
Also used : Serializable(java.io.Serializable) CallSite(java.lang.invoke.CallSite) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

CallSite (java.lang.invoke.CallSite)18 MethodHandle (java.lang.invoke.MethodHandle)15 MethodType (java.lang.invoke.MethodType)6 MethodHandles (java.lang.invoke.MethodHandles)5 LambdaReceiver_A (LambdaReceiver_anotherpkg.LambdaReceiver_A)2 Method (java.lang.reflect.Method)2 BiConsumer (java.util.function.BiConsumer)2 BiPredicate (java.util.function.BiPredicate)2 Predicate (java.util.function.Predicate)2 Supplier (java.util.function.Supplier)2 Method (org.elasticsearch.painless.Definition.Method)2 SystemClock (android.os.SystemClock)1 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileDescriptor (java.io.FileDescriptor)1 PrintStream (java.io.PrintStream)1 Serializable (java.io.Serializable)1 Field (java.lang.reflect.Field)1 Socket (java.net.Socket)1