Package java.lang.invoke

Examples of java.lang.invoke.MethodHandle


            FunctionInfo function = metadata.getFunction(node.getName(), argumentTypes, false);
            // do not optimize non-deterministic functions
            if (optimize && !function.isDeterministic()) {
                return new FunctionCall(node.getName(), node.getWindow().orNull(), node.isDistinct(), toExpressions(argumentValues));
            }
            MethodHandle handle = function.getScalarFunction();
            if (handle.type().parameterCount() > 0 && handle.type().parameterType(0) == Session.class) {
                handle = handle.bindTo(session);
            }
            try {
                return handle.invokeWithArguments(argumentValues);
            }
            catch (Throwable throwable) {
                Throwables.propagateIfInstanceOf(throwable, RuntimeException.class);
                Throwables.propagateIfInstanceOf(throwable, Error.class);
                throw new RuntimeException(throwable.getMessage(), throwable);
View Full Code Here


   * multiple attributes over separate classes.
   * <p>Please save instances created by this method in a static final field, because
   * on each call, this does reflection for creating a {@link MethodHandle}.
   */
  public static <A extends AttributeImpl> AttributeFactory getStaticImplementation(AttributeFactory delegate, Class<A> clazz) {
    final MethodHandle constr = findAttributeImplCtor(clazz);
    return new StaticImplementationAttributeFactory<A>(delegate, clazz) {
      @Override
      protected A createInstance() {
        try {
          return (A) constr.invokeExact();
        } catch (Throwable t) {
          rethrow(t);
          throw new AssertionError();
        }
      }
View Full Code Here

      // Please note: we have the slight chance that another thread may do the same, but who cares?
      assert cached == null;
      final Class<? extends AttributeImpl> implClazz = findImplClass(attClass);
      // if the attribute impl is from our own ClassLoader, we optimize to use pre-allocated MethodHandle to instantiate the object
      if (useMethodHandles && implClazz.getClassLoader() == myClassLoader) {
        final MethodHandle constr = findAttributeImplCtor(implClazz);
        attClassImplMap.put(attClass, constr);
        return invokeMethodHandle(constr);
      } else {
        // otherwise, to not refer to the class forever (because the MethodHandle strongly
        // references the class), so it can never be unloaded, we use slower reflection:
View Full Code Here

                    final Method getter = field instanceof Field.ArrayField ? getIndexedGetter(type, field) : getGetter(type, field);
                    final Method setter = field instanceof Field.ArrayField ? getIndexedSetter(type, field) : getSetter(type, field);
                    final java.lang.reflect.Field f = (getter == null ? getField(type, field) : null);
                    final boolean indexed = f == null && field instanceof Field.ArrayField;

                    final MethodHandle getterHandle;
                    final MethodHandle setterHandle;
                    if (mode == Mode.METHOD_HANDLE) {
                        getterHandle = DynamicMethodHandleRecord.getGetterMethodHandle(field, f, getter);
                        setterHandle = DynamicMethodHandleRecord.getSetterMethodHandle(field, f, setter);
                    } else {
                        getterHandle = null;
View Full Code Here

        VerifyArgument.notNull(method, "method");

        final Expression actualTarget;

        if (target == null && method instanceof DynamicMethod) {
            final MethodHandle handle = ((DynamicMethod) method).getHandle();
            if (handle == null) {
                throw Error.dynamicMethodCallRequiresTargetOrMethodHandle();
            }
            actualTarget = constant(handle, Types.MethodHandle);
        }
View Full Code Here

        System.out.println();
        System.out.println(outer);

        final Delegate delegate = outer.compileDelegate();
        final MethodHandle handle = delegate.getMethodHandle();

        System.out.printf("\n[%s]\n", handle.getClass().getSimpleName());

        final int result = (int) handle.invokeExact();

        System.out.println(result);

        assertEquals(expectedResult, result);
    }
View Full Code Here

                    constant(5))))
            .compileToMethod(typeInitializer);

        final Type<Runnable> generatedType = typeBuilder.createType();

        final MethodHandle getter = MethodHandles.lookup().findStaticGetter(
            generatedType.getErasedClass(),
            "Numbers",
            int[].class);

        final int[] numbers = (int[])getter.invokeExact();

        assertArrayEquals(new int[] { 1, 2, 3, 4, 5 }, numbers);
    }
View Full Code Here

                    ScalarFunction scalarFunction = method.getAnnotation(ScalarFunction.class);
                    if (scalarFunction == null) {
                        continue;
                    }
                    checkValidMethod(method);
                    MethodHandle methodHandle = lookup().unreflect(method);
                    String name = scalarFunction.value();
                    if (name.isEmpty()) {
                        name = camelToSnake(method.getName());
                    }
                    String description = getDescription(method);
View Full Code Here

                    ScalarFunction scalarFunction = method.getAnnotation(ScalarFunction.class);
                    if (scalarFunction == null) {
                        continue;
                    }
                    checkValidMethod(method);
                    MethodHandle methodHandle = lookup().unreflect(method);
                    String name = scalarFunction.value();
                    if (name.isEmpty()) {
                        name = camelToSnake(method.getName());
                    }
                    String description = getDescription(method);
View Full Code Here

            FunctionInfo function = metadata.getFunction(node.getName(), argumentTypes);
            // do not optimize non-deterministic functions
            if (optimize && !function.isDeterministic()) {
                return new FunctionCall(node.getName(), node.getWindow().orNull(), node.isDistinct(), toExpressions(argumentValues));
            }
            MethodHandle handle = function.getScalarFunction();
            if (handle.type().parameterCount() > 0 && handle.type().parameterType(0) == Session.class) {
                handle = handle.bindTo(session);
            }
            try {
                return handle.invokeWithArguments(argumentValues);
            }
            catch (Throwable throwable) {
                Throwables.propagateIfInstanceOf(throwable, RuntimeException.class);
                Throwables.propagateIfInstanceOf(throwable, Error.class);
                throw new RuntimeException(throwable.getMessage(), throwable);
View Full Code Here

TOP

Related Classes of java.lang.invoke.MethodHandle

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.