Package java.lang.invoke

Examples of java.lang.invoke.MethodHandle


        Class< ? > class1,
        Class< ? > class2)
    {
        int rank = Math.max(RANK_MAP.get(class1), RANK_MAP.get(class2));
        String mangledName = opName + rank;
        MethodHandle mh = BINARY_CACHE.get(mangledName);
        if (mh != null) {
            return mh;
        }

        for (; rank < PRIMITIVE_ARRAY.length;) {
View Full Code Here


            // don't forget that && and || are lazy !!
            // System.out.println("fallback called with "+opName+'('+v1.getClass()+','+v2.getClass()+')');

            Class< ? extends Object> class1 = v1.getClass();
            Class< ? extends Object> class2 = v2.getClass();
            MethodHandle op = lookupBinaryOp(opName, class1, class2);

            // convert arguments
            MethodType type = type();
            MethodType opType = op.type();
            if (opType.parameterType(0) == String.class) {
                if (opType.parameterType(1) == String.class) {
                    op = MethodHandles.filterArguments(op,
                            0,
                            TO_STRING,
                            TO_STRING);
                } else {
                    op = MethodHandles.filterArguments(op, 0, TO_STRING);
                    op = MethodHandles.explicitCastArguments(op, type);
                }
            } else {
                if (opType.parameterType(1) == String.class) {
                    op = MethodHandles.filterArguments(op, 1, TO_STRING);
                }
                op = MethodHandles.explicitCastArguments(op, type);
            }

            // prepare guard
            MethodHandle guard = MethodHandles.guardWithTest(TEST1.bindTo(class1),
                    MethodHandles.guardWithTest(TEST2.bindTo(class2),
                            op,
                            fallback),
                    fallback);
View Full Code Here

  protected synchronized void resetCache() {
    this.cache = new CacheEntry[0];
  }

  private MethodHandle lookupMethodForNil() {
    MethodHandle castHandle = findMethodForNil();
    addCacheEntry(null, castHandle);
    return castHandle;
  }
View Full Code Here

    addCacheEntry(null, castHandle);
    return castHandle;
  }

  private MethodHandle lookupMethod(final Class receiverClass) {
    MethodHandle castHandle = findMethod(receiverClass);
    addCacheEntry(receiverClass, castHandle);
    return castHandle;
  }
View Full Code Here

    return false;
  }

  private MethodHandle getGuardedMethod(CacheEntry entry,
      MethodHandle fallback) {
    MethodHandle test = entry.receiverClass == null ? NIL_TEST_METHOD_HANDLE
         : MethodHandles.insertArguments(
        TYPE_TEST_METHOD_HANDLE, 1, entry.receiverClass);
    Class[] tail = ArrayExtensions.tail(type.parameterArray());
    test = MethodHandles.dropArguments(test, 1, tail);
    test = test.asType(MethodType.methodType(Boolean.TYPE,
        type.parameterArray()));
    MethodHandle guard1 = MethodHandles.guardWithTest(test,
        entry.methodHandle, fallback);
    return guard1;
  }
View Full Code Here

    cache = ArrayExtensions.copyWith_(cache, new CacheEntry(receiverClass,
        castHandle));
  }

  private void setTargetFromCache() {
    MethodHandle sum = fallback;
    for (int i = cache.length - 1; i >= 0; i--) {
      CacheEntry entry = cache[i];
      sum = getGuardedMethod(entry, sum);
    }
    setTarget(sum);
View Full Code Here

  public static CallSite constructorBootstrap(Lookup lookup, String selector,
      MethodType type, String referenceString) throws Throwable {
    Reference reference = Reference.factory.value_(referenceString);
    Constructor constructor = ImageBootstrapper.systemMapping.classMappingAtReference_(reference).identityClass().getConstructor();
    MethodHandle constructorHandle = lookup.unreflectConstructor(constructor);
    return new ConstantCallSite(constructorHandle.asType(type));
  }
View Full Code Here

        .value_(namespaceString);
    AbsoluteReference fullReference = namespace.$slash$(Symbol
        .value(selector));
    final AlmostFinalValue singletonHolder = ImageBootstrapper.systemMapping
        .resolveSingletonHolder_(fullReference);
    final MethodHandle target = lookup.findVirtual(
        AlmostFinalValue.class,
        "setValue",
        MethodType.methodType(Object.class, Object.class)).bindTo(singletonHolder);
    return new ConstantCallSite(target);
  }
View Full Code Here

      if (selector.equals("doesNotUnderstand_"))
        throw new RuntimeException("Can't find DNU method");
      return wrapDNUHandle(lookupMethod(receiverClass,
          "doesNotUnderstand_"));
    }
    MethodHandle methodHandle;
    try {
      Method method = MethodTools.searchForMethod(
          mapping.definingClass(), selector, type.parameterArray(),
          true);

      if (method != null) {
        return mapping.methodHandle().asType(type);
      }
      methodHandle = lookup.findSpecial(mapping.definingClass(),
          selector, type.dropParameterTypes(0, 1), lookup.lookupClass());
    } catch (NoSuchMethodException | IllegalAccessException r) {

      try {
        methodHandle = lookup.findStatic(mapping.definingClass(),
            selector, type);
      } catch (NoSuchMethodException | IllegalAccessException e) {

        throw new RuntimeException(e);
      }
    }
    return methodHandle.asType(type);
  }
View Full Code Here

  }

  @Override
  protected void addTargetToCache(Object receiver) {
    Class receiverClass = receiver.getClass();
    MethodHandle target = lookupMethod(receiverClass);
    setTarget(target);
  }
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.