Package java.lang.invoke

Examples of java.lang.invoke.MethodType


  protected abstract void resetCache();

  private MethodHandle getFallbackMethod() {
    try {
      final MethodType fallbackType = MethodType.genericMethodType(
          type.parameterCount()).insertParameterTypes(0,
          BaseCallSite.class);
      final MethodHandle fallbackHandle = MethodHandles.insertArguments(
          MethodHandles.lookup().findStatic(BaseCallSite.class,
              "invocationFallback", fallbackType), 0, this);
View Full Code Here


    CompiledClass current = jvmClasses.get(key);

    Object[] astConstants = jvmClass.astConstants();
    if (astConstants.length == 0)
      return this;
    MethodType type = MethodType.genericMethodType(astConstants.length)
        .changeReturnType(void.class);
    MethodHandle findStatic;
    try {
      findStatic = MethodHandles.lookup().findStatic(current.javaClass,
          "_astinit", type);
View Full Code Here

  public static void timeMH(IndyDemo indyDemo) throws Throwable {
    long start = System.currentTimeMillis();
    int REFLECTION_TIMES = 10000;
    MethodHandles.Lookup lookup = MethodHandles.lookup();
    MethodType type = MethodType.methodType(Integer.TYPE);
    for (int i = 0; i < REFLECTION_TIMES; i++) {
      MethodHandle someMethod = lookup.findVirtual(IndyDemo.class, "someMethod", type);
      int result = (int) someMethod.invokeExact(indyDemo);
    }
    System.out.println("methodhandle: " + (TIMES/ REFLECTION_TIMES)*(System.currentTimeMillis() - start));
View Full Code Here

  }

  public static void timeMHCached(IndyDemo indyDemo) throws Throwable {
    long start = System.currentTimeMillis();
    MethodHandles.Lookup lookup = MethodHandles.lookup();
    MethodType type = MethodType.methodType(Integer.TYPE);
    MethodHandle someMethod = lookup.findVirtual(IndyDemo.class, "someMethod", type);
    for (int i = 0; i < TIMES; i++) {
      int result = (int) someMethod.invokeExact(indyDemo);
    }
    System.out.println("methodhandle cached: " + (System.currentTimeMillis() - start));
View Full Code Here

    private static MethodHandle fixMethodHandleType(Field field, MethodHandle mh) throws IllegalAccessException {
        if (mh == null)
            return null;

        final MethodType origType = mh.type();
        final Class<?>[] params = origType.parameterArray();

        params[0] = Object.class;
        for (int i = 1; i < params.length; i++) {
            if (!params[i].isPrimitive())
                params[i] = Object.class;
        }

        Class<?> rtype = origType.returnType();
        if (field instanceof Field.ArrayField && rtype.isArray()) {
            if (!rtype.getComponentType().isPrimitive())
                rtype = Object[].class;
        } else if (!rtype.isPrimitive())
            rtype = Object.class;

        final MethodType mt = MethodType.methodType(rtype, params);
        return mh.asType(mt);
    }
View Full Code Here

            site = new JRubyCallSite(lookup, type, CallType.VARIABLE, file, line, method, true, false, true);
        } else {
            throw new RuntimeException("wrong invokedynamic target: " + name);
        }
       
        MethodType fallbackType = type.insertParameterTypes(0, JRubyCallSite.class);
        MethodHandle myFallback = insertArguments(
                lookup.findStatic(InvocationLinker.class, "invocationFallback",
                fallbackType),
                0,
                site);
View Full Code Here

           
            // drop standard preamble args plus extra args
            newTarget = dropArguments(newTarget, 0, IRubyObject.class, ThreadContext.class, IRubyObject.class, IRubyObject.class);
           
            // drop extra arguments, if any
            MethodType dropped = target.type().dropParameterTypes(0, 3);
            if (dropped.parameterCount() > 1) {
                Class[] drops = new Class[dropped.parameterCount() - 1];
                Arrays.fill(drops, IRubyObject.class);
                newTarget = dropArguments(newTarget, 4, drops);
            }
           
            // fold using target
View Full Code Here

        // Scala singletons have slightly different JI logic, so skip for now
        if (method instanceof SingletonMethodInvoker) return null;
       
        // the "apparent" type from the NativeCall, excluding receiver
        MethodType apparentType = methodType(nativeCall.getNativeReturn(), nativeCall.getNativeSignature());

        if (isStatic) {
            nativeTarget = findStatic(nativeCall.getNativeTarget(), nativeCall.getNativeName(), apparentType);
        } else {
            nativeTarget = findVirtual(nativeCall.getNativeTarget(), nativeCall.getNativeName(), apparentType);
        }
       
        // the actual native type with receiver
        MethodType nativeType = nativeTarget.type();
        Class[] nativeParams = nativeType.parameterArray();
        Class nativeReturn = nativeType.returnType();

        // convert arguments
        MethodHandle[] argConverters = new MethodHandle[nativeType.parameterCount()];
        for (int i = 0; i < argConverters.length; i++) {
            MethodHandle converter;
            if (!isStatic && i == 0) {
                // handle non-static receiver specially
                converter = Binder
View Full Code Here

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        int argCount = getArgCount(nativeCall.getNativeSignature(), isStatic);
        MethodType inboundType = STANDARD_NATIVE_TYPES_BLOCK[argCount];

        int[] permute;
        MethodType convert;
        if (nativeSig.length > 0 && nativeSig[0] == ThreadContext.class) {
            if (nativeSig[nativeSig.length - 1] == Block.class) {
                convert = isStatic ? TARGET_TC_SELF_ARGS_BLOCK[argCount] : TARGET_SELF_TC_ARGS_BLOCK[argCount];
                permute = isStatic ? TC_SELF_ARGS_BLOCK_PERMUTES[argCount] : SELF_TC_ARGS_BLOCK_PERMUTES[argCount];
            } else {
View Full Code Here

    public static CallSite getConstantBootstrap(Lookup lookup, String name, MethodType type, int scopeIndex) throws NoSuchMethodException, IllegalAccessException {
        RubyConstantCallSite site;

        site = new RubyConstantCallSite(type, name);
       
        MethodType fallbackType = methodType(IRubyObject.class, RubyConstantCallSite.class, AbstractScript.class, ThreadContext.class, int.class);
        MethodHandle myFallback = insertArguments(
                lookup.findStatic(InvokeDynamicSupport.class, "constantFallback",
                fallbackType),
                0,
                site);
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.