Examples of CallSiteDescriptor


Examples of org.dynalang.dynalink.CallSiteDescriptor

    }

    @Override
    public GuardedInvocation getGuardedInvocation(LinkRequest request, final LinkerServices linkerServices)
            throws Exception {
        final CallSiteDescriptor callSiteDescriptor = request.getCallSiteDescriptor();
        final int l = callSiteDescriptor.getNameTokenCount();
        // All names conforming to the dynalang MOP should have at least two tokens, the first one being "dyn"
        if(l < 2 || "dyn" != callSiteDescriptor.getNameToken(CallSiteDescriptor.SCHEME)) {
            return null;
        }

        final Object receiver = request.getReceiver();
        if(receiver == null) {
View Full Code Here

Examples of org.dynalang.dynalink.CallSiteDescriptor

    @Override
    public GuardedInvocation getGuardedInvocation(LinkRequest request, final LinkerServices linkerServices)
            throws Exception {
        final LinkRequest ncrequest = request.withoutRuntimeContext();
        // BeansLinker already checked that the name is at least 2 elements long and the first element is "dyn".
        final CallSiteDescriptor callSiteDescriptor = ncrequest.getCallSiteDescriptor();
        final String op = callSiteDescriptor.getNameToken(CallSiteDescriptor.OPERATOR);
        // Either dyn:callMethod:name(this[,args]) or dyn:callMethod(this,name[,args]).
        if("callMethod" == op) {
            return getCallPropWithThis(callSiteDescriptor, linkerServices);
        }
        List<String> operations = CallSiteDescriptorFactory.tokenizeOperators(callSiteDescriptor);
View Full Code Here

Examples of org.dynalang.dynalink.CallSiteDescriptor

        testEarlyBoundArrayLengthGetter(arrayClass, "getLength", true);
    }

    private static void testEarlyBoundArrayLengthGetter(Class<?> arrayClass, String op, boolean early) throws Throwable {
        final BeansLinker bl = new BeansLinker();
        final CallSiteDescriptor csd =
                createCallSiteDescriptor("dyn:" + op, MethodType.methodType(int.class, arrayClass));
        final Object array = Array.newInstance(arrayClass.getComponentType(), 2);
        final GuardedInvocation inv = getGuardedInvocation(bl, csd, array);
        if(early) {
            // early bound, as call site guarantees we'll pass an array
            assertNull(inv.getGuard());
        }
        final MethodHandle mh = inv.getInvocation();
        assertNotNull(mh);
        assertEquals(csd.getMethodType(), mh.type());
        assertEquals(2, mh.invokeWithArguments(array));
    }
View Full Code Here

Examples of org.dynalang.dynalink.CallSiteDescriptor

        testArrayLengthPropertyGetter(String[].class);
    }

    public void testEarlyBoundCollectionLengthGetter() throws Throwable {
        final BeansLinker bl = new BeansLinker();
        final CallSiteDescriptor csd =
                createCallSiteDescriptor("dyn:getLength", MethodType.methodType(int.class, List.class));
        final GuardedInvocation inv = getGuardedInvocation(bl, csd, Collections.EMPTY_LIST);
        assertNull(inv.getGuard());
        final MethodHandle mh = inv.getInvocation();
        assertNotNull(mh);
        assertEquals(csd.getMethodType(), mh.type());
        assertEquals(0, mh.invokeWithArguments(new Object[] { Collections.EMPTY_LIST }));
        assertEquals(2, mh.invokeWithArguments(new Object[] { Arrays.asList(new Object[] { "a", "b" }) }));
    }
View Full Code Here

Examples of org.dynalang.dynalink.CallSiteDescriptor

        assertEquals(2, mh.invokeWithArguments(new Object[] { Arrays.asList(new Object[] { "a", "b" }) }));
    }

    public void testEarlyBoundMapLengthGetter() throws Throwable {
        final BeansLinker bl = new BeansLinker();
        final CallSiteDescriptor csd =
                createCallSiteDescriptor("dyn:getLength", MethodType.methodType(int.class, Map.class));
        final GuardedInvocation inv = getGuardedInvocation(bl, csd, Collections.EMPTY_MAP);
        assertNull(inv.getGuard());
        final MethodHandle mh = inv.getInvocation();
        assertNotNull(mh);
        assertEquals(csd.getMethodType(), mh.type());
        assertEquals(0, mh.invokeWithArguments(Collections.EMPTY_MAP));
        assertEquals(1, mh.invokeWithArguments(Collections.singletonMap("a", "b")));
    }
View Full Code Here

Examples of org.dynalang.dynalink.CallSiteDescriptor

    static CallSiteDescriptor getCanonicalPublicDescriptor(final CallSiteDescriptor desc) {
        synchronized(publicDescs) {
            final WeakReference<CallSiteDescriptor> ref = publicDescs.get(desc);
            if(ref != null) {
                final CallSiteDescriptor canonical = ref.get();
                if(canonical != null) {
                    return canonical;
                }
            }
            publicDescs.put(desc, new WeakReference<>(desc));
View Full Code Here

Examples of org.dynalang.dynalink.CallSiteDescriptor

                throws Exception {
            final GuardedInvocation gi = super.getGuardedInvocation(request, linkerServices);
            if(gi != null) {
                return gi;
            }
            final CallSiteDescriptor desc = request.getCallSiteDescriptor();
            final String op = desc.getNameToken(CallSiteDescriptor.OPERATOR);
            if("new" == op && constructor != null) {
                final MethodHandle ctorInvocation = constructor.getInvocation(desc, linkerServices);
                if(ctorInvocation != null) {
                    return new GuardedInvocation(ctorInvocation, getClassGuard(desc.getMethodType()));
                }
            }
            return null;
        }
View Full Code Here

Examples of org.dynalang.dynalink.CallSiteDescriptor

    public GuardedInvocation getGuardedInvocation(LinkRequest linkRequest, LinkerServices linkerServices) {
        final Object receiver = linkRequest.getReceiver();
        if(!(receiver instanceof DynamicMethod)) {
            return null;
        }
        final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor();
        if(desc.getNameTokenCount() != 2 && desc.getNameToken(CallSiteDescriptor.SCHEME) != "dyn") {
            return null;
        }
        final String operator = desc.getNameToken(CallSiteDescriptor.OPERATOR);
        if(operator == "call") {
            final MethodHandle invocation = ((DynamicMethod)receiver).getInvocation(
                    CallSiteDescriptorFactory.dropParameterTypes(desc, 0, 1), linkerServices);
            if(invocation == null) {
                return null;
            }
            return new GuardedInvocation(MethodHandles.dropArguments(invocation, 0,
                    desc.getMethodType().parameterType(0)), Guards.getIdentityGuard(receiver));
        }
        return null;
    }
View Full Code Here

Examples of org.dynalang.dynalink.CallSiteDescriptor

     */
    public void testPrintLn() throws Throwable {
        final BeansLinker linker = new BeansLinker();
        final LinkerServices linkerServices = LinkerServicesFactory.getLinkerServices(linker);
        final Object out = System.out;
        final CallSiteDescriptor desc = CallSiteDescriptorFactory.create(MethodHandles.publicLookup(),
                "dyn:callMethod:println", MethodType.methodType(Object.class, Object.class, Object.class));
        final LinkRequest req = new LinkRequestImpl(desc, false, out, "helloWorld");
        linker.getGuardedInvocation(req, linkerServices).getInvocation().invokeWithArguments(out, "helloWorld");
    }
View Full Code Here

Examples of org.dynalang.dynalink.linker.CallSiteDescriptor

    }

    private static Object invokeDynamically(RelinkableCallSite callSite,
            Object[] args) throws Throwable {
        final Class<?> receiverClass = args[0].getClass();
        final CallSiteDescriptor descriptor = callSite.getCallSiteDescriptor();
        final Class<?>[] signature =
                descriptor.getMethodType().parameterArray();
        final Class<?>[] reflectSignature = new Class<?>[signature.length - 1];
        System.arraycopy(signature, 1, reflectSignature, 0,
                reflectSignature.length);
        final Method m =
                receiverClass.getMethod(descriptor.getNameToken(0), reflectSignature);
        final MethodHandle unreflected = MethodHandles.lookup().unreflect(m);
        return unreflected.invokeWithArguments(args);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.