Package java.lang.invoke

Examples of java.lang.invoke.MethodHandle.invokeExact()


                .invokeStatic(LOOKUP, BinderTest.class, "setZeroToFooReturnIntAndRaise");

        assertEquals(MethodType.methodType(int.class, String[].class), handle.type());
        String[] stringAry = new String[1];
        try {
            assertEquals(1, (int)handle.invokeExact(stringAry));
        } catch (BlahException be) {
            assertTrue("should not have reached here", false);
        }
        assertEquals("foofinally", stringAry[0]);
    }
View Full Code Here


                .from(void.class, Object[].class, int.class, Object.class)
                .arraySet();

        assertEquals(MethodType.methodType(void.class, Object[].class, int.class, Object.class), handle.type());
        Object[] ary = new Object[1];
        handle.invokeExact(ary, 0, (Object)"foo");
        assertEquals(ary[0], "foo");
    }

    @Test
    public void testArrayGet() throws Throwable {
View Full Code Here

                .from(Object.class, Object[].class, int.class)
                .arrayGet();

        assertEquals(MethodType.methodType(Object.class, Object[].class, int.class), handle.type());
        Object[] ary = new Object[] {"foo"};
        assertEquals(handle.invokeExact(ary, 0), "foo");
    }
   
    @Test
    public void testBranch() throws Throwable {
        MethodHandle handle = Binder
View Full Code Here

                                .from(String.class, String.class)
                                .invokeStatic(LOOKUP, BinderTest.class, "addBaz")
                );
       
        assertEquals(MethodType.methodType(String.class, String.class), handle.type());
        assertEquals("foobar", (String)handle.invokeExact("foo"));
        assertEquals("quuxbaz", (String)handle.invokeExact("quux"));
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
View Full Code Here

                                .invokeStatic(LOOKUP, BinderTest.class, "addBaz")
                );
       
        assertEquals(MethodType.methodType(String.class, String.class), handle.type());
        assertEquals("foobar", (String)handle.invokeExact("foo"));
        assertEquals("quuxbaz", (String)handle.invokeExact("quux"));
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public static MethodHandle intLongHandle() throws Exception {
View Full Code Here

                .appendArg("flo", float.class)
                .appendArg("dub", double.class)
                .permuteWith(stringObjectIntTarget, "obj", "num");
       
        assertEquals(MethodType.methodType(String.class, Object.class, int.class, float.class, double.class), handle.type());
        assertEquals("foo1", (String)handle.invokeExact((Object)"foo", 1, 1.0f, 1.0));
    }
   
    @Test
    public void testPermuteWithSmartHandle() throws Throwable {
        SmartHandle target = new SmartHandle(stringObjectInt, stringObjectIntTarget);
View Full Code Here

        {
          MethodType mt = MethodType.methodType(void.class);

          MethodHandle mh = MethodHandles.lookup().findVirtual(JITStats.class, incMethodName, mt);

          mh.invokeExact(stats);
        }
        catch (Throwable t)
        {
          logger.error("Exception: {}", t.getMessage(), t);
        }
View Full Code Here

    public static SephObject pump(SephObject marker, SephObject receiver, SThread thread) throws Throwable {
        SephObject result = receiver;
        while(marker == result) {
            MethodHandle mh = thread.tail;
            result = (SephObject)mh.invokeExact();
        }
        return result;
    }

    public static CallSite genMH(SephObject marker) {
View Full Code Here

        try {
            tmp = (SephObject)so.activationFor(0, false).invokeExact((SephObject)Ground.instance, thread, (LexicalScope)null);
            while(tmp == SThread.TAIL_MARKER) {
                MethodHandle tail = thread.tail;
                thread.tail = null;
                tmp = (SephObject)tail.invokeExact();
            }
        } catch(Throwable e) {
            throw new RuntimeException(e);
        }
        return tmp;
View Full Code Here

    public final static ControlDefaultBehavior instance = new ControlDefaultBehavior();

    public static SephObject evaluateArgument(Object possibleArgument, LexicalScope scope, SThread thread, boolean fully) {
        try {
            MethodHandle mh = (MethodHandle)possibleArgument;
            return (SephObject)mh.invokeExact(thread, scope, true, fully);
        } catch(Throwable e) {
            e.printStackTrace();
            return null;
        }
    }
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.