Package org.dynalang.dynalink

Examples of org.dynalang.dynalink.DynamicLinkerFactory


public class TestElementGetter extends TestCase {
    public void testEarlyBoundPrimitiveArrayElementGetter() throws Throwable {
        final RelinkCountingCallSite cs =
                new RelinkCountingCallSite("dyn:getElem", MethodType.methodType(Object.class, int[].class, int.class));
        new DynamicLinkerFactory().createLinker().link(cs);
        final MethodHandle invoker = cs.dynamicInvoker();
        final int[] x = new int[] { 3, 2, 1 };
        assertEquals(3, invoker.invokeWithArguments(x, 0));
        assertEquals(2, invoker.invokeWithArguments(x, 1));
        assertEquals(1, invoker.invokeWithArguments(x, 2));
View Full Code Here


    public void testEarlyBoundObjectArrayElementGetter() throws Throwable {
        final RelinkCountingCallSite cs =
                new RelinkCountingCallSite("dyn:getElem",
                        MethodType.methodType(Object.class, Object[].class, int.class));
        new DynamicLinkerFactory().createLinker().link(cs);
        final MethodHandle invoker = cs.dynamicInvoker();
        final Integer[] x = new Integer[] { 3, 2, 1 };
        final String[] y = new String[] { "a", "b", "c" };
        assertEquals(3, invoker.invokeWithArguments(x, 0));
        assertEquals(2, invoker.invokeWithArguments(x, 1));
View Full Code Here

    }

    public void testEarlyBoundListElementGetter() throws Throwable {
        final RelinkCountingCallSite cs =
                new RelinkCountingCallSite("dyn:getElem", MethodType.methodType(Object.class, List.class, int.class));
        new DynamicLinkerFactory().createLinker().link(cs);
        final MethodHandle invoker = cs.dynamicInvoker();
        final List<Integer> x = new ArrayList<Integer>(Arrays.asList(new Integer[] { 3, 2, 1 }));
        final List<String> y = new LinkedList<String>(Arrays.asList(new String[] { "a", "b", "c" }));
        assertEquals(3, invoker.invokeWithArguments(x, 0));
        assertEquals(2, invoker.invokeWithArguments(x, 1));
View Full Code Here

    }

    public void testEarlyBoundMapElementGetter() throws Throwable {
        final RelinkCountingCallSite cs =
                new RelinkCountingCallSite("dyn:getElem", MethodType.methodType(Object.class, Map.class, Object.class));
        new DynamicLinkerFactory().createLinker().link(cs);
        final MethodHandle invoker = cs.dynamicInvoker();
        final Map<Integer, Integer> x = new HashMap<Integer, Integer>();
        x.put(0, 3);
        x.put(1, 2);
        x.put(2, 1);
View Full Code Here

    public void testLateBoundMapElementGetter() throws Throwable {
        final RelinkCountingCallSite cs =
                new RelinkCountingCallSite("dyn:getElem", MethodType.methodType(Object.class, Object.class,
                        Object.class));
        new DynamicLinkerFactory().createLinker().link(cs);
        final MethodHandle invoker = cs.dynamicInvoker();
        final Map<Integer, Integer> x = new HashMap<Integer, Integer>();
        x.put(0, 3);
        x.put(1, 2);
        x.put(2, 1);
View Full Code Here

*/
public class TestPropertyGetter extends TestCase {
    public void testFixedNamePropertyGetter() throws Throwable {
        final RelinkCountingCallSite callSite =
                new RelinkCountingCallSite("dyn:getProp:foo", MethodType.methodType(Object.class, Object.class));
        new DynamicLinkerFactory().createLinker().link(callSite);
        final MethodHandle invoker = callSite.dynamicInvoker();

        final T1 t1 = new T1();
        t1.setFoo("abc");
        assertSame("abc", invoker.invokeWithArguments(t1));
View Full Code Here

    public void testVariableNamePropertyGetter() throws Throwable {
        final RelinkCountingCallSite callSite =
                new RelinkCountingCallSite("dyn:getProp", MethodType.methodType(Object.class, Object.class,
                        String.class));
        new DynamicLinkerFactory().createLinker().link(callSite);
        final MethodHandle invoker = callSite.dynamicInvoker();
        final T1 t1 = new T1();
        t1.setFoo("abc");
        assertSame("abc", invoker.invokeWithArguments(t1, "foo"));
        assertEquals(1, callSite.getRelinkCount());
View Full Code Here

        assertEquals(0, mh.invokeWithArguments(Collections.EMPTY_MAP));
        assertEquals(1, mh.invokeWithArguments(Collections.singletonMap("a", "b")));
    }

    public void testLateBoundLengthGetter() throws Throwable {
        final DynamicLinker linker = new DynamicLinkerFactory().createLinker();
        final RelinkCountingCallSite callSite =
                new RelinkCountingCallSite("dyn:getLength", MethodType.methodType(int.class, Object.class));

        linker.link(callSite);
        assertEquals(0, callSite.getRelinkCount());
View Full Code Here

public class TestPropertySetter extends TestCase {
    public void testFixedNamePropertySetter() throws Throwable {
        final RelinkCountingCallSite callSite =
                new RelinkCountingCallSite("dyn:setProp:foo", MethodType.methodType(Void.TYPE, Object.class,
                        Object.class));
        new DynamicLinkerFactory().createLinker().link(callSite);
        final MethodHandle invoker = callSite.dynamicInvoker();
        final T1 t1 = new T1();
        invoker.invokeWithArguments(t1, "abc");
        assertSame("abc", t1.foo);
        assertEquals(1, callSite.getRelinkCount());
View Full Code Here

    public void testVariableNamePropertySetter() throws Throwable {
        final RelinkCountingCallSite callSite =
                new RelinkCountingCallSite("dyn:setProp", MethodType.methodType(Void.TYPE, Object.class, String.class,
                        Object.class));
        new DynamicLinkerFactory().createLinker().link(callSite);
        final MethodHandle invoker = callSite.dynamicInvoker();
        final T1 t1 = new T1();
        invoker.invokeWithArguments(t1, "foo", "abc");
        assertSame("abc", t1.foo);
        assertEquals(1, callSite.getRelinkCount());
View Full Code Here

TOP

Related Classes of org.dynalang.dynalink.DynamicLinkerFactory

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.