Package java.lang.invoke

Examples of java.lang.invoke.MethodType$ConcurrentWeakInternSet


        for (int i = 0; i < numArgs; i++) {
            argTypes[i] = processType(atpos(argTypesSmo, i, tc).get_str(tc));
        }

        int numExtraArgs = (int) extraArgsSmo.elems(tc);
        MethodType bsmMT = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class,
                java.lang.String.class, MethodType.class);

        Object[] extraArgs = new Object[numExtraArgs];
        for (int i = 0; i < numExtraArgs; i++) {
            SixModelObject extra = atpos(extraArgsSmo, i, tc);
            if (istype(extra, jastPushI, tc) != 0) {
                extraArgs[i] = getattr_i(extra, jastPushI, "$!value", 0, tc);
                bsmMT = bsmMT.appendParameterTypes(long.class);
            }
            else if (istype(extra, jastPushN, tc) != 0) {
                extraArgs[i] = getattr_n(extra, jastPushN, "$!value", 0, tc);
                bsmMT = bsmMT.appendParameterTypes(double.class);
            }
            else if (istype(extra, jastPushS, tc) != 0) {
                extraArgs[i] = getattr_s(extra, jastPushS, "$!value", 0, tc);
                bsmMT = bsmMT.appendParameterTypes(String.class);
            }
            else if (istype(extra, jastPushIdx, tc) != 0) {
                extraArgs[i] = (int) getattr_i(extra, jastPushIdx, "$!value", 0, tc);
                bsmMT = bsmMT.appendParameterTypes(int.class);
            }
            else {
                throw new RuntimeException("Unrecognized extra argument for invokedynamic");
            }
        }

        Handle bsmHandle = new Handle(Opcodes.H_INVOKESTATIC, bsmType, bsmName, bsmMT.toMethodDescriptorString());
        m.visitInvokeDynamicInsn(name, Type.getMethodDescriptor(retType, argTypes), bsmHandle, extraArgs);
    }
View Full Code Here


    }

    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

                ImmutableList.of(
                        invoke(context, castFirst, "cast(first)"),
                        invoke(context, castSecond, "cast(second)")),
                ImmutableList.of(firstType, secondType));

        MethodType methodType = functionBinding.getCallSite().type();
        Class<?> unboxedReturnType = Primitives.unwrap(methodType.returnType());

        LabelNode end = new LabelNode("end");

        Block equalsCall = new Block(context)
                .setDescription("invoke")
                .comment("equal");
        ArrayList<Class<?>> stackTypes = new ArrayList<>();
        for (int i = 0; i < functionBinding.getArguments().size(); i++) {
            equalsCall.append(functionBinding.getArguments().get(i));
            stackTypes.add(methodType.parameterType(i));
            equalsCall.append(ByteCodeUtils.ifWasNullPopAndGoto(context, end, unboxedReturnType, Lists.reverse(stackTypes)));
        }

        equalsCall.invokeDynamic(functionBinding.getName(), functionBinding.getCallSite().type(), functionBinding.getBindingId())
            .visitLabel(end);
View Full Code Here

    }

    private ByteCodeNode invoke(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());

        block.visitLabel(end);
View Full Code Here

    }

    public static ByteCodeNode generateFunctionCall(Signature signature, 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 " + signature)
                .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(ByteCodeUtils.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(ByteCodeUtils.unboxPrimitive(context, unboxedReturnType));
            }
            else {
                block.dup(methodType.returnType())
                        .ifNotNullGoto(end)
                        .putVariable("wasNull", true);
            }
        }
        block.visitLabel(end);
View Full Code Here

                    OperatorType.EQUAL,
                    generatorContext.generateGetSession(),
                    ImmutableList.of(generatorContext.generate(operand), getTempVariableNode),
                    ImmutableList.of(value.getType(), operand.getType()));

            MethodType methodType = functionBinding.getCallSite().type();
            Class<?> unboxedReturnType = Primitives.unwrap(methodType.returnType());

            LabelNode end = new LabelNode("end");
            Block equalsCall = new Block(context)
                    .setDescription("invoke")
                    .comment(operand.toString());
            ArrayList<Class<?>> stackTypes = new ArrayList<>();
            for (int i = 0; i < functionBinding.getArguments().size(); i++) {
                equalsCall.append(functionBinding.getArguments().get(i));
                stackTypes.add(methodType.parameterType(i));
                equalsCall.append(ByteCodeUtils.ifWasNullPopAndGoto(context, end, unboxedReturnType, Lists.reverse(stackTypes)));
            }
            equalsCall.invokeDynamic(functionBinding.getName(), methodType, functionBinding.getBindingId());
            equalsCall.visitLabel(end);
View Full Code Here

  private static MethodHandle loadMethodHandle(Class c, String name, Class returnType, Class params[], boolean isStatic) {
    MethodHandle res = null;

    try {
      MethodType desc = MethodType.methodType(returnType, params);

      if (isStatic)
        res = methodHandlesLookup.findStatic(c, name, desc);
      else
        res = methodHandlesLookup.findVirtual(c, name, desc);
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) });
View Full Code Here

    return customClass;
  }

  private static Object createClassLoader(Class contextClass, Class generatedClassLoaderClass, Object contextObject,
      MethodHandle findVirtualHandle) throws Throwable {
    MethodType createClassLoaderType = MethodType.methodType(generatedClassLoaderClass, ClassLoader.class);
    MethodHandle createClassLoaderHandle = (MethodHandle) findVirtualHandle.invokeWithArguments(new Object[] { lookup, contextClass,
        "createClassLoader", createClassLoaderType });
   
    Object classLoader = createClassLoaderHandle.invokeWithArguments(new Object[] { contextObject, null });
    return classLoader;
View Full Code Here

TOP

Related Classes of java.lang.invoke.MethodType$ConcurrentWeakInternSet

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.