Package java.lang.invoke

Examples of java.lang.invoke.MethodType


        String[] newArgNames = new String[argNames.length - 1 + names.length];
        System.arraycopy(names, 0, newArgNames, newArgNames.length - names.length, names.length);
        System.arraycopy(argNames, 0, newArgNames, 0, argNames.length - 1);

        MethodType newMethodType = methodType
                .dropParameterTypes(methodType.parameterCount() - 1, methodType.parameterCount())
                .appendParameterTypes(types);

        return new Signature(newMethodType, newArgNames);
    }
View Full Code Here


        int newCount = 0;
        int gatherCount = 0;
        Class type = null;
        Pattern pattern = Pattern.compile(oldPattern);

        MethodType newType = type();

        for (int i = 0; i < argNames.length; i++) {
            if (pattern.matcher(argName(i)).matches()) {
                gatherCount++;
                newType = newType.dropParameterTypes(newCount, newCount + 1);
                Class argType = argType(i);
                if (start == -1) start = i;
                if (type == null) {
                    type = argType;
                } else {
                    if (argType != type) {
                        throw new InvalidTransformException("arguments matching " + pattern + " are not all of the same type");
                    }
                }
            } else {
                newCount++;
            }
        }

        if (start != -1) {
            String[] newNames = new String[newCount + 1];

            // pre
            System.arraycopy(argNames, 0, newNames, 0, start);

            // vararg
            newNames[start] = newName;
            newType = newType.insertParameterTypes(start, Array.newInstance(type, 0).getClass());

            // post
            if (newCount + 1 > start) { // args not at end
                System.arraycopy(argNames, start + gatherCount, newNames, start + 1, newCount - start);
            }
View Full Code Here

      returnType = method.getReturnType();
      genericReturnType = method.getGenericReturnType();
      merge(method);
     
      if (HASMETHODHANDLES) {
        MethodType newType;
        if (Modifier.isStatic(method.getModifiers())) {
          newType = MethodType.genericMethodType(parameters.size(),
              method.isVarArgs());
        } else {
          newType = MethodType.genericMethodType(
              parameters.size() + 1, method.isVarArgs());
        }
        if (method.getReturnType() == Void.class) {
          newType = newType.changeReturnType(void.class);
        }
        methodHandle = new ConstantCallSite(MethodHandles.lookup()
            .unreflect(method).asType(newType)
            .asSpreader(Object[].class, newType.parameterCount()))
            .dynamicInvoker();
      }
    }
View Full Code Here

        String incMethodName = "incCount" + modifier.substring(0, 1).toUpperCase() + modifier.substring(1);

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

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

          mh.invokeExact(stats);
        }
View Full Code Here

                binding.getType().returnType());
    }

    public static ByteCodeNode generateInvocation(CompilerContext context, FunctionInfo function, List<ByteCodeNode> arguments, Binding binding)
    {
        MethodType methodType = binding.getType();

        Signature signature = function.getSignature();
        Class<?> unboxedReturnType = Primitives.unwrap(methodType.returnType());

        LabelNode end = new LabelNode("end");
        Block block = new Block(context)
                .setDescription("invoke " + signature);

        List<Class<?>> stackTypes = new ArrayList<>();

        int index = 0;
        for (Class<?> type : methodType.parameterArray()) {
            stackTypes.add(type);
            if (type == ConnectorSession.class) {
                block.getVariable("session");
            }
            else {
                block.append(arguments.get(index));
                if (!function.getNullableArguments().get(index)) {
                    block.append(ifWasNullPopAndGoto(context, end, unboxedReturnType, Lists.reverse(stackTypes)));
                }
                else {
                    block.append(boxPrimitiveIfNecessary(context, type));
                    block.putVariable("wasNull", false);
                }
                index++;
            }
        }
        block.append(invoke(context, binding, function.getSignature()));

        if (function.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

        }
        setSpecialized(prof);
    }

    public void setSpecialized(TypeProfile allProfiles) {
        MethodType type = this.type();
        MethodHandle elsePath = slowPath;
        elsePath = filterArguments(elsePath, 0, computeProfiler(true));
        TypeProfile[] cases = allProfiles.cases();
        int casesToCode = cases.length;
        for(int i = casesToCode - 1; i >= 0; i--) {
View Full Code Here

        }
        setSpecialized(prof);
    }

    public void setSpecialized(TypeProfile allProfiles) {
        MethodType type = this.type();
        MethodHandle elsePath = slowPath;
        elsePath = filterArguments(elsePath, 0, computeProfiler(true));
        TypeProfile[] cases = allProfiles.cases();
        int casesToCode = cases.length;
        for(int i = casesToCode - 1; i >= 0; i--) {
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

    private MethodHandle createRelinkAndInvokeMethod(final RelinkableCallSite callSite, int relinkCount) {
        // Make a bound MH of invoke() for this linker and call site
        final MethodHandle boundRelinker = MethodHandles.insertArguments(RELINK, 0, this, callSite, Integer.valueOf(
                relinkCount));
        // Make a MH that gathers all arguments to the invocation into an Object[]
        final MethodType type = callSite.getDescriptor().getMethodType();
        final MethodHandle collectingRelinker = boundRelinker.asCollector(Object[].class, type.parameterCount());
        return MethodHandles.foldArguments(MethodHandles.exactInvoker(type), collectingRelinker.asType(
                type.changeReturnType(MethodHandle.class)));
    }
View Full Code Here

        }

        // If our call sites have a runtime context, and the linker produced a context-stripped invocation, adapt the
        // produced invocation into contextual invocation (by dropping the context...)
        if(runtimeContextArgCount > 0) {
            final MethodType origType = callSiteDescriptor.getMethodType();
            final MethodHandle invocation = guardedInvocation.getInvocation();
            if(invocation.type().parameterCount() == origType.parameterCount() - runtimeContextArgCount) {
                final List<Class<?>> prefix = origType.parameterList().subList(1, runtimeContextArgCount + 1);
                final MethodHandle guard = guardedInvocation.getGuard();
                guardedInvocation = guardedInvocation.dropArguments(1, prefix);
            }
        }
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.