Package org.dynalang.dynalink

Examples of org.dynalang.dynalink.MonomorphicCallSite


        }
    }

    public static CallSite bootstrap(MethodHandles.Lookup lookup, String name,
            MethodType callSiteType) {
        final CallSite cs = new MonomorphicCallSite(lookup, name, callSiteType);
        MethodHandle boundInvoker =
                MethodHandles.insertArguments(INVOKE_DYNAMICALLY, 0, cs);
        MethodHandle collectedArgsInvoker =
                boundInvoker.asCollector(Object.class, callSiteType
                        .parameterCount()
                        - boundInvoker.type().parameterCount() + 1);
        MethodHandle convertedArgsInvoker =
                MethodHandles.convertArguments(collectedArgsInvoker,
                        callSiteType);
        cs.setTarget(convertedArgsInvoker);
        return cs;
    }
View Full Code Here


        assertEquals(4, mh.invokeWithArguments(new Test1(), 1, new int[] { 2 }));
    }

    public void testStringFormat() throws Throwable {
        DynamicLinker linker = new DynamicLinkerFactory().createLinker();
        MonomorphicCallSite callSite = new MonomorphicCallSite(CallSiteDescriptorFactory.create(
                MethodHandles.publicLookup(), "dyn:callMethod:format", MethodType.methodType(Object.class,
                        Object.class, Object.class, Object.class, Object.class)));
        linker.link(callSite);
        System.out.println(callSite.dynamicInvoker().invokeWithArguments(StaticClass.forClass(String.class),
                "%4.0f %4.0f", 12f, 1f));
    }
View Full Code Here

    private static Object getProperty(String name, Object obj) throws Throwable {
        return getInvoker("dyn:getProp:" + name, Object.class, Object.class).invoke(obj);
    }

    private static MethodHandle getInvoker(String name, Class<?> retType, Class<?>... paramTypes) {
        return linker.link(new MonomorphicCallSite(CallSiteDescriptorFactory.create(
                MethodHandles.publicLookup(), name, MethodType.methodType(retType, paramTypes)))).dynamicInvoker();
    }
View Full Code Here

        }
        List<Class<?>> argTypes = new ArrayList<>(argCount);
        for(int i = 0; i < argCount; ++i) {
            argTypes.add(Object.class);
        }
        return linker.link(new MonomorphicCallSite(CallSiteDescriptorFactory.create(MethodHandles.publicLookup(),
                operation, MethodType.methodType(Object.class, argTypes)))).dynamicInvoker().invokeWithArguments(args);
    }
View Full Code Here

        return T1.class.cast(getInvoker("dyn:new", T1.class, StaticClass.class, Object.class, Object.class).invoke(
                StaticClass.forClass(T1.class), arg1, arg2));
    }

    private static MethodHandle getInvoker(String name, Class<?> retType, Class<?>... paramTypes) {
        return linker.link(new MonomorphicCallSite(CallSiteDescriptorFactory.create(
                MethodHandles.publicLookup(), name, MethodType.methodType(retType, paramTypes)))).dynamicInvoker();
    }
View Full Code Here

TOP

Related Classes of org.dynalang.dynalink.MonomorphicCallSite

Copyright © 2018 www.massapicom. 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.