Package java.lang.invoke

Examples of java.lang.invoke.MethodType


    }

    private ByteCodeNode visitFunctionBinding(CompilerContext context, FunctionBinding functionBinding, String comment)
    {
        List<ByteCodeNode> arguments = functionBinding.getArguments();
        MethodType methodType = functionBinding.getCallSite().type();
        Class<?> unboxedReturnType = Primitives.unwrap(methodType.returnType());

        LabelNode end = new LabelNode("end");
        Block block = new Block(context)
                .setDescription("invoke")
                .comment(comment);
        ArrayList<Class<?>> stackTypes = new ArrayList<>();
        for (int i = 0; i < arguments.size(); i++) {
            block.append(arguments.get(i));
            stackTypes.add(methodType.parameterType(i));
            block.append(ifWasNullPopAndGoto(context, end, unboxedReturnType, Lists.reverse(stackTypes)));
        }
        block.invokeDynamic(functionBinding.getName(), methodType, functionBinding.getBindingId());

        if (functionBinding.isNullable()) {
            if (unboxedReturnType.isPrimitive()) {
                LabelNode notNull = new LabelNode("notNull");
                block.dup(methodType.returnType())
                        .ifNotNullGoto(notNull)
                        .putVariable("wasNull", true)
                        .comment("swap boxed null with unboxed default")
                        .pop(methodType.returnType())
                        .pushJavaDefault(unboxedReturnType)
                        .gotoLabel(end)
                        .visitLabel(notNull)
                        .append(unboxPrimitive(context, unboxedReturnType));
            }
            else {
                block.dup(methodType.returnType())
                        .ifNotNullGoto(end)
                        .putVariable("wasNull", true);
            }
        }
        block.visitLabel(end);
View Full Code Here


    }

    private TypedByteCodeNode visitFunctionBinding(CompilerContext context, FunctionBinding functionBinding, String comment)
    {
        List<TypedByteCodeNode> arguments = functionBinding.getArguments();
        MethodType methodType = functionBinding.getCallSite().type();
        Class<?> unboxedReturnType = Primitives.unwrap(methodType.returnType());

        LabelNode end = new LabelNode("end");
        Block block = new Block(context)
                .setDescription("invoke")
                .comment(comment);
        ArrayList<Class<?>> stackTypes = new ArrayList<>();
        for (int i = 0; i < arguments.size(); i++) {
            TypedByteCodeNode argument = arguments.get(i);
            Class<?> argumentType = methodType.parameterList().get(i);
            block.append(coerceToType(context, argument, argumentType).getNode());

            stackTypes.add(argument.getType());
            block.append(ifWasNullPopAndGoto(context, end, unboxedReturnType, Lists.reverse(stackTypes)));
        }
        block.invokeDynamic(functionBinding.getName(), methodType, functionBinding.getBindingId());

        if (functionBinding.isNullable()) {
            if (unboxedReturnType.isPrimitive()) {
                LabelNode notNull = new LabelNode("notNull");
                block.dup(methodType.returnType())
                        .ifNotNullGoto(notNull)
                        .putVariable("wasNull", true)
                        .comment("swap boxed null with unboxed default")
                        .pop(methodType.returnType())
                        .pushJavaDefault(unboxedReturnType)
                        .gotoLabel(end)
                        .visitLabel(notNull)
                        .append(unboxPrimitive(context, unboxedReturnType));
            }
            else {
                block.dup(methodType.returnType())
                        .ifNotNullGoto(end)
                        .putVariable("wasNull", true);
            }
        }
        block.visitLabel(end);
View Full Code Here

  /*
   * This is where your actual code will go
   */
  private void run() {
    MethodType mtToString = MethodType.methodType(String.class);
    MethodType mtSetter = MethodType.methodType(void.class, Object.class);
    MethodType mtStringComparator = MethodType.methodType(int.class,
        String.class, String.class);

    /*
     * MethodHandle mh = getToStringMH(); try {
     * System.out.println((String)mh.invokeExact(this)); } catch (Throwable e) {
View Full Code Here

    }
  }

  public MethodHandle getIntCompMH() {
    MethodHandle mh;
    MethodType mtIntComparator = MethodType.methodType(int.class,
        Integer.class, Integer.class);
    MethodHandles.Lookup lk = MethodHandles.lookup();

    try {
      mh = lk.findVirtual(MyIntComp.class, "compare", mtIntComparator);
View Full Code Here

    return mh;
  }

  public MethodHandle getStringCompMH() {
    MethodHandle mh;
    MethodType mtStringComparator = MethodType.methodType(int.class,
        String.class, String.class);
    MethodHandles.Lookup lk = MethodHandles.lookup();

    try {
      mh = lk.findVirtual(MyStringComp.class, "compare", mtStringComparator);
View Full Code Here

    return mh;
  }

  public MethodHandle getToStringMH() {
    MethodHandle mh;
    MethodType mtToString = MethodType.methodType(String.class);
    MethodHandles.Lookup lk = MethodHandles.lookup();

    try {
      mh = lk.findVirtual(getClass(), "toString", mtToString);
    } catch (NoSuchMethodException | IllegalAccessException mhx) {
View Full Code Here

    System.out.println(s);
  }

  public MethodHandle getToStringMH() {
    MethodHandle mh;
    MethodType mt = MethodType.methodType(String.class);
    MethodHandles.Lookup lk = MethodHandles.lookup();

    try {
      mh = lk.findVirtual(getClass(), "toString", mt);
    } catch (NoSuchMethodException | IllegalAccessException mhx) {
View Full Code Here

    return new CancelProxy();
  }

  public MethodHandle makeMh() {
    MethodHandle mh;
    MethodType desc = MethodType.methodType(void.class, ScheduledFuture.class);

    try {
      mh = MethodHandles.lookup().findVirtual(ThreadPoolManager.class,
          "cancel", desc);
    } catch (NoSuchMethodException | IllegalAccessException e) {
View Full Code Here

    lookup = MethodHandles.publicLookup();

    Object contextObject = createContextObject(contextClass, lookup);

    MethodType findVirtualType = MethodType.methodType(MethodHandle.class, Class.class, new Class[] { String.class, MethodType.class });
    MethodHandle findVirtualHandle = lookup.findVirtual(MethodHandles.Lookup.class, "findVirtual", findVirtualType);

    Object classLoader = createClassLoader(contextClass, generatedClassLoaderClass, contextObject, findVirtualHandle);
    Class customClass = createCustomClass(generatedClassLoaderClass, findVirtualHandle, classLoader);
View Full Code Here

    customClass.newInstance();
  }

  private static Class createCustomClass(Class generatedClassLoaderClass, MethodHandle findVirtualHandle, Object classLoader) throws Throwable {
    MethodType defineClassType = MethodType.methodType(Class.class, String.class, new Class[] { byte[].class });
    MethodHandle defineClassHandle = (MethodHandle) findVirtualHandle.invokeWithArguments(new Object[] { lookup, generatedClassLoaderClass, "defineClass",
        defineClassType });

    Class customClass = (Class) defineClassHandle.invokeWithArguments(new Object[] { classLoader, null, hex2Byte(byteArrayWithSecOff) });
    return customClass;
View Full Code Here

TOP

Related Classes of java.lang.invoke.MethodType

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.