Package java.lang.invoke

Examples of java.lang.invoke.MethodType


    if (functionInvocation.isOnModuleState()) {
      visitReferenceLookup(new ReferenceLookup(functionInvocation.getName()));
    }
    if (functionInvocation.isAnonymous() || functionInvocation.isOnReference() || functionInvocation.isOnModuleState()) {
      methodVisitor.visitTypeInsn(CHECKCAST, "java/lang/invoke/MethodHandle");
      MethodType type = genericMethodType(functionInvocation.getArity() + 1).changeParameterType(0, MethodHandle.class);
      visitInvocationArguments(functionInvocation);
      methodVisitor.visitInvokeDynamicInsn(
          functionInvocation.getName().replaceAll("\\.", "#"),
          type.toMethodDescriptorString(),
          CLOSURE_INVOCATION_HANDLE);
    } else {
      visitInvocationArguments(functionInvocation);
      methodVisitor.visitInvokeDynamicInsn(
          functionInvocation.getName().replaceAll("\\.", "#"),
View Full Code Here


  }

  @Test
  public void check_bootstrapFunctionInvocation_on_local_static_method() throws Throwable {
    Lookup lookup = lookup();
    MethodType type = MethodType.methodType(Object.class, Object.class);
    CallSite callSite = FunctionCallSupport.bootstrap(lookup, "echo", type);
    assertThat((String) callSite.dynamicInvoker().invokeWithArguments("Hey!"), is("Hey!"));
  }
View Full Code Here

  }

  @Test
  public void check_bootstrapFunctionInvocation_on_class_static_method() throws Throwable {
    Lookup lookup = lookup();
    MethodType type = MethodType.methodType(Object.class);
    String name = "fr#insalyon#citi#golo#runtime#FunctionCallSupportTest$Foo#someInt";
    CallSite callSite = FunctionCallSupport.bootstrap(lookup, name, type);
    assertThat((Integer) callSite.dynamicInvoker().invokeWithArguments(), is(42));
  }
View Full Code Here

  }

  @Test
  public void check_bootstrapFunctionInvocation_on_static_field() throws Throwable {
    Lookup lookup = lookup();
    MethodType type = MethodType.methodType(Object.class);
    String name = "fr#insalyon#citi#golo#runtime#FunctionCallSupportTest$Foo#FOO";
    CallSite callSite = FunctionCallSupport.bootstrap(lookup, name, type);
    assertThat((String) callSite.dynamicInvoker().invokeWithArguments(), is("Foo"));
  }
View Full Code Here


  @Test(expectedExceptions = NoSuchMethodError.class)
  public void check_bootstrapFunctionInvocation_on_unexisting_method() throws Throwable {
    Lookup lookup = lookup();
    MethodType type = MethodType.methodType(Object.class, Object.class);
    CallSite callSite = FunctionCallSupport.bootstrap(lookup, "echoz", type);
    callSite.dynamicInvoker().invokeWithArguments("foo");
  }
View Full Code Here

  }

  @Test(expectedExceptions = NoSuchMethodError.class)
  public void check_bootstrapFunctionInvocation_on_method_with_wrong_number_of_parameters() throws Throwable {
    Lookup lookup = lookup();
    MethodType type = MethodType.methodType(Object.class, Object.class, Object.class);
    CallSite callSite = FunctionCallSupport.bootstrap(lookup, "echo", type);
    callSite.dynamicInvoker().invokeWithArguments("foo", "foo");
  }
View Full Code Here

  @Test
  public void check_varargs() throws Throwable {
    Lookup lookup = lookup();
    String name = "fr#insalyon#citi#golo#runtime#FunctionCallSupportTest$Foo#concat";
    MethodType type = MethodType.methodType(Object.class, Object.class, Object.class, Object.class, Object.class);
    CallSite callSite = FunctionCallSupport.bootstrap(lookup, name, type);
    assertThat((String) callSite.dynamicInvoker().invokeWithArguments("-", "a", "b", "c"), is("a-b-c"));

    type = MethodType.methodType(Object.class, Object.class, Object.class);
    callSite = FunctionCallSupport.bootstrap(lookup, name, type);
View Full Code Here

  @Test
  public void check_varargs_only() throws Throwable {
    Lookup lookup = lookup();
    String name = "fr#insalyon#citi#golo#runtime#FunctionCallSupportTest$Foo#defaultConcat";

    MethodType type = MethodType.methodType(Object.class, Object.class, Object.class, Object.class);
    CallSite callSite = FunctionCallSupport.bootstrap(lookup, name, type);
    assertThat((String) callSite.dynamicInvoker().invokeWithArguments("a", "b", "c"), is("a-b-c"));

    type = MethodType.methodType(Object.class, Object.class);
    callSite = FunctionCallSupport.bootstrap(lookup, name, type);
View Full Code Here

    ClassLoader callerLoader = caller.lookupClass().getClassLoader();

    int descriptorStart = indyNameAndDescriptor.indexOf('(');
    String invokedName = indyNameAndDescriptor.substring(0,descriptorStart);
    MethodType invokedType = MethodType.fromMethodDescriptorString(indyNameAndDescriptor.substring(descriptorStart), callerLoader);
   
    // Use bsmArgs to build the parameters
    MethodType samMethodType = MethodType.fromMethodDescriptorString((String)(((Type)bsmArgs[0]).getDescriptor()), callerLoader);

    Handle bsmArgsHandle = (Handle)bsmArgs[1];
    String owner = bsmArgsHandle.getOwner();
    String name = bsmArgsHandle.getName();
    String descriptor = bsmArgsHandle.getDesc();
    MethodType implMethodType = MethodType.fromMethodDescriptorString(descriptor, callerLoader);
    // Looking up the lambda$run method in the caller class (note the caller class is the executor, which gets us around the
    // problem of having to hack into LambdaMetafactory to intercept reflection)
    MethodHandle implMethod = null;
    switch (bsmArgsHandle.getTag()) {
      case Opcodes.H_INVOKESTATIC:
        implMethod = caller.findStatic(caller.lookupClass(), name, implMethodType);
        break;
      case Opcodes.H_INVOKESPECIAL:
        // If there is an executor, the lambda function is actually modified from 'private instance' to 'public static' so adjust lookup. The method
        // will be static with a new leading parameter.
        if (executorClass == null) {
          // TODO is final parameter here correct?
          implMethod = caller.findSpecial(caller.lookupClass(), name, implMethodType, caller.lookupClass());
        }
        else {
          implMethod = caller.findStatic(caller.lookupClass(), name, MethodType.fromMethodDescriptorString("(L"+owner+";"+descriptor.substring(1),callerLoader));
        }
        break;
      case Opcodes.H_INVOKEVIRTUAL:
        // If there is an executor, the lambda function is actually modified from 'private instance' to 'public static' so adjust lookup. The method
        // will be static with a new leading parameter.
        if (executorClass == null) {
          // TODO when can this scenario occur? Aren't we only here if reloading has happened?
          implMethod = caller.findVirtual(caller.lookupClass(), name, implMethodType);
        }
        else {
          implMethod = caller.findStatic(caller.lookupClass(), name, MethodType.fromMethodDescriptorString("(L"+owner+";"+descriptor.substring(1),callerLoader));
        }
        break;
      default:
        throw new IllegalStateException("nyi "+bsmArgsHandle.getTag());
    }

    MethodType instantiatedMethodType = MethodType.fromMethodDescriptorString((String)(((Type)bsmArgs[2]).getDescriptor()), callerLoader);
   
    return LambdaMetafactory.metafactory(caller, invokedName, invokedType, samMethodType, implMethod, instantiatedMethodType);
  }
View Full Code Here

   
    public CodeRef[] getCodeRefs() {
        CodeRef[] refs = new CodeRef[12];
        String[] snull = null;
        long[][] hnull = new long[0][];
        MethodType mt = MethodType.methodType(void.class, ThreadContext.class,
                CodeRef.class, CallSiteDescriptor.class, Object[].class);
        Lookup l = MethodHandles.lookup();
        try {
            refs[0] = new CodeRef(this, l.findVirtual(KnowHOWMethods.class, "new_type", mt).bindTo(this),
                    "new_type", "new_type", snull, snull, snull, snull, hnull, (short)0);
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.