java.lang.invoke.CallSite Java Examples

The following examples show how to use java.lang.invoke.CallSite. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Method.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Handle generateBootstrapMethod(Handle h) {
    String bootstrapName = "bootstrapMethod";
    MethodType bootstrapType = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class);

    MethodVisitor bmv = cv.visitMethod(ACC_PUBLIC | ACC_STATIC, bootstrapName, bootstrapType.toMethodDescriptorString(), null, null);
    bmv.visitCode();

    String constCallSite = "java/lang/invoke/ConstantCallSite";
    bmv.visitTypeInsn(NEW, constCallSite);
    bmv.visitInsn(DUP);

    bmv.visitLdcInsn(h);

    bmv.visitMethodInsn(INVOKESPECIAL, constCallSite, "<init>", "(Ljava/lang/invoke/MethodHandle;)V", false);
    bmv.visitInsn(ARETURN);

    bmv.visitMaxs(0,0);
    bmv.visitEnd();

    return new Handle(H_INVOKESTATIC, ownerClassName, bootstrapName, bootstrapType.toMethodDescriptorString());
}
 
Example #2
Source File: LambdaReceiverBridge.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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");
}
 
Example #3
Source File: LambdaReceiver.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
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");
}
 
Example #4
Source File: DynamicLinkerFactoryTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void testAutoLoadedLinkerInvoked(final Object target, final String methodName) {
    final DynamicLinkerFactory factory = newDynamicLinkerFactory(false);
    final DynamicLinker linker = factory.createLinker();

    // we should still get one error due to untrusted dynamic linker exporter!
    checkOneAutoLoadingError(factory);

    final MethodType mt = MethodType.methodType(Object.class, Object.class);
    final CallSiteDescriptor testDescriptor = new CallSiteDescriptor(MethodHandles.publicLookup(),
            GET.withNamespace(StandardNamespace.METHOD).named(methodName), mt);
    final CallSite cs = linker.link(new SimpleRelinkableCallSite(testDescriptor));

    TrustedGuardingDynamicLinkerExporter.enable();
    try {
        cs.getTarget().invoke(target);
        // The linker was loaded and it observed our invocation
        Assert.assertTrue(TrustedGuardingDynamicLinkerExporter.isLastCallSiteDescriptor(testDescriptor));
    } catch (final Throwable th) {
        throw new RuntimeException(th);
    } finally {
        TrustedGuardingDynamicLinkerExporter.disable();
    }

}
 
Example #5
Source File: LambdaCapture.java    From presto with Apache License 2.0 6 votes vote down vote up
public static CallSite lambdaCapture(
        MethodHandles.Lookup callerLookup,
        String name,
        MethodType type,
        MethodType samMethodType,
        MethodHandle implMethod,
        MethodType instantiatedMethodType)
{
    try {
        // delegate to metafactory, we may choose to generate code ourselves in the future.
        return LambdaMetafactory.metafactory(
                callerLookup,
                name,
                type,
                samMethodType,
                implMethod,
                instantiatedMethodType);
    }
    catch (LambdaConversionException e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
 
Example #6
Source File: LambdaReceiverBridge.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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");
}
 
Example #7
Source File: DynamicLinkerFactoryTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void prelinkTransformerTest() throws Throwable {
    final DynamicLinkerFactory factory = newDynamicLinkerFactory(true);
    final boolean[] reachedPrelinkTransformer = { false };

    factory.setPrelinkTransformer((final GuardedInvocation inv, final LinkRequest linkRequest, final LinkerServices linkerServices) -> {
        reachedPrelinkTransformer[0] = true;
        // just identity transformer!
        return inv;
    });

    final MethodType mt = MethodType.methodType(Object.class, Object.class, String.class);
    final DynamicLinker linker = factory.createLinker();
    final CallSite cs = linker.link(new SimpleRelinkableCallSite(new CallSiteDescriptor(
            MethodHandles.publicLookup(), GET_PROPERTY, mt)));
    Assert.assertFalse(reachedPrelinkTransformer[0]);
    Assert.assertEquals(cs.getTarget().invoke(new Object(), "class"), Object.class);
    Assert.assertTrue(reachedPrelinkTransformer[0]);
}
 
Example #8
Source File: CompiledFunction.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static void relinkComposableInvoker(final CallSite cs, final CompiledFunction inv, final boolean constructor) {
    final HandleAndAssumptions handleAndAssumptions = inv.getValidOptimisticInvocation(new Supplier<MethodHandle>() {
        @Override
        public MethodHandle get() {
            return inv.getInvokerOrConstructor(constructor);
        }
    });
    final MethodHandle handle = handleAndAssumptions.handle;
    final SwitchPoint assumptions = handleAndAssumptions.assumptions;
    final MethodHandle target;
    if(assumptions == null) {
        target = handle;
    } else {
        final MethodHandle relink = MethodHandles.insertArguments(RELINK_COMPOSABLE_INVOKER, 0, cs, inv, constructor);
        target = assumptions.guardWithTest(handle, MethodHandles.foldArguments(cs.dynamicInvoker(), relink));
    }
    cs.setTarget(target.asType(cs.type()));
}
 
Example #9
Source File: BeanLinkerTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "flags")
public void systemLoadLibraryTest(final boolean publicLookup) {
    final CallSite cs1 = createGetMethodCallSite(publicLookup, "loadLibrary");
    final CallSite cs2 = createCallSite(publicLookup, CALL, MethodType.methodType(void.class, Object.class, Object.class, String.class));

    try {
        final Object method = cs1.getTarget().invoke(StaticClass.forClass(System.class));
        cs2.getTarget().invoke(method, StaticClass.forClass(System.class), "foo");
        throw new RuntimeException("should not reach here in any case!");
    } catch (final Throwable th) {
        if (publicLookup) {
            Assert.assertTrue(th instanceof IllegalAccessError);
        } else {
            Assert.assertTrue(th instanceof AccessControlException);
        }
    }
}
 
Example #10
Source File: LambdaReceiver.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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");
}
 
Example #11
Source File: LambdaReceiver.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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");
}
 
Example #12
Source File: LambdaReceiver.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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");
}
 
Example #13
Source File: LambdaReceiverBridge.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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");
}
 
Example #14
Source File: LambdaReceiverBridge.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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");
}
 
Example #15
Source File: LambdaReceiver.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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");
}
 
Example #16
Source File: LambdaMetafactoryUtils.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T createLambda(Object instance, Method instanceMethod, Class<?> functionalIntfCls) {
  try {
    Method intfMethod = findAbstractMethod(functionalIntfCls);
    MethodHandle methodHandle = LOOKUP.unreflect(instanceMethod);

    MethodType intfMethodType = MethodType.methodType(intfMethod.getReturnType(), intfMethod.getParameterTypes());
    MethodType instanceMethodType = MethodType
        .methodType(instanceMethod.getReturnType(), instanceMethod.getParameterTypes());
    CallSite callSite = LambdaMetafactory.metafactory(
        LOOKUP,
        intfMethod.getName(),
        MethodType.methodType(functionalIntfCls, instance.getClass()),
        intfMethodType,
        methodHandle,
        instanceMethodType);

    return (T) callSite.getTarget().bindTo(instance).invoke();
  } catch (Throwable e) {
    throw new IllegalStateException("Failed to create lambda from " + instanceMethod, e);
  }
}
 
Example #17
Source File: CompiledFunction.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void relinkComposableInvoker(final CallSite cs, final CompiledFunction inv, final boolean constructor) {
    final HandleAndAssumptions handleAndAssumptions = inv.getValidOptimisticInvocation(new Supplier<MethodHandle>() {
        @Override
        public MethodHandle get() {
            return inv.getInvokerOrConstructor(constructor);
        }
    });
    final MethodHandle handle = handleAndAssumptions.handle;
    final SwitchPoint assumptions = handleAndAssumptions.assumptions;
    final MethodHandle target;
    if(assumptions == null) {
        target = handle;
    } else {
        final MethodHandle relink = MethodHandles.insertArguments(RELINK_COMPOSABLE_INVOKER, 0, cs, inv, constructor);
        target = assumptions.guardWithTest(handle, MethodHandles.foldArguments(cs.dynamicInvoker(), relink));
    }
    cs.setTarget(target.asType(cs.type()));
}
 
Example #18
Source File: SerializedLambdaTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #19
Source File: Bootstrap.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Boostrapper for math calls that may overflow
 * @param lookup         lookup
 * @param name           name of operation
 * @param type           method type
 * @param programPoint   program point to bind to callsite
 *
 * @return callsite for a math intrinsic node
 */
public static CallSite mathBootstrap(final Lookup lookup, final String name, final MethodType type, final int programPoint) {
    final MethodHandle mh;
    switch (name) {
    case "iadd":
        mh = JSType.ADD_EXACT.methodHandle();
        break;
    case "isub":
        mh = JSType.SUB_EXACT.methodHandle();
        break;
    case "imul":
        mh = JSType.MUL_EXACT.methodHandle();
        break;
    case "idiv":
        mh = JSType.DIV_EXACT.methodHandle();
        break;
    case "irem":
        mh = JSType.REM_EXACT.methodHandle();
        break;
    case "ineg":
        mh = JSType.NEGATE_EXACT.methodHandle();
        break;
    default:
        throw new AssertionError("unsupported math intrinsic");
    }
    return new ConstantCallSite(MH.insertArguments(mh, mh.type().parameterCount() - 1, programPoint));
}
 
Example #20
Source File: SerializedLambdaTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #21
Source File: SerializedLambdaTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #22
Source File: CompiledFunction.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private MethodHandle createComposableInvoker(final boolean isConstructor) {
    final MethodHandle handle = getInvokerOrConstructor(isConstructor);

    // If compiled function is not optimistic, it can't ever change its invoker/constructor, so just return them
    // directly.
    if(!canBeDeoptimized()) {
        return handle;
    }

    // Otherwise, we need a new level of indirection; need to introduce a mutable call site that can relink itself
    // to the compiled function's changed target whenever the optimistic assumptions are invalidated.
    final CallSite cs = new MutableCallSite(handle.type());
    relinkComposableInvoker(cs, this, isConstructor);
    return cs.dynamicInvoker();
}
 
Example #23
Source File: SerializedLambdaTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #24
Source File: IndyInterface.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * backing bootstrap method with all parameters
 */
private static CallSite realBootstrap(Lookup caller, String name, int callID, MethodType type, boolean safe, boolean thisCall, boolean spreadCall) {
    // since indy does not give us the runtime types
    // we produce first a dummy call site, which then changes the target to one when INDY_OPTIMIZE_THRESHOLD is reached,
    // that does the method selection including the direct call to the
    // real method.
    CacheableCallSite mc = new CacheableCallSite(type);
    final Class<?> sender = caller.lookupClass();
    MethodHandle mh = makeAdapter(mc, sender, name, callID, type, safe, thisCall, spreadCall);
    mc.setTarget(mh);
    mc.setDefaultTarget(mh);
    mc.setFallbackTarget(makeFallBack(mc, sender, name, callID, type, safe, thisCall, spreadCall));

    return mc;
}
 
Example #25
Source File: SerializedLambdaTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #26
Source File: SerializedLambdaTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #27
Source File: SerializedLambdaTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #28
Source File: SerializedLambdaTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #29
Source File: BeanLinkerTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "flags")
public void systemGetPropertyTest(final boolean publicLookup) {
    final CallSite cs1 = createGetMethodCallSite(publicLookup, "getProperty");
    final CallSite cs2 = createCallSite(publicLookup, CALL, MethodType.methodType(String.class, Object.class, Object.class, String.class));

    try {
        final Object method = cs1.getTarget().invoke(StaticClass.forClass(System.class));
        cs2.getTarget().invoke(method, StaticClass.forClass(System.class), "java.home");
        throw new RuntimeException("should not reach here in any case!");
    } catch (final Throwable th) {
        Assert.assertTrue(th instanceof SecurityException);
    }
}
 
Example #30
Source File: Bootstrap.java    From presto with Apache License 2.0 5 votes vote down vote up
public static CallSite bootstrap(MethodHandles.Lookup callerLookup, String name, MethodType type, long bindingId)
{
    ClassLoader classLoader = callerLookup.lookupClass().getClassLoader();
    checkArgument(classLoader instanceof DynamicClassLoader, "Expected %s's classloader to be of type %s", callerLookup.lookupClass().getName(), DynamicClassLoader.class.getName());

    DynamicClassLoader dynamicClassLoader = (DynamicClassLoader) classLoader;
    MethodHandle target = dynamicClassLoader.getCallSiteBindings().get(bindingId);
    checkArgument(target != null, "Binding %s for function %s%s not found", bindingId, name, type.parameterList());

    return new ConstantCallSite(target);
}