类java.lang.invoke.WrongMethodTypeException源码实例Demo

下面列出了怎么用java.lang.invoke.WrongMethodTypeException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: exonum-java-binding   文件: TransactionMethod.java
void invoke(Service targetService, byte[] arguments, ExecutionContext context) {
  Object argumentsObject = serializeArguments(arguments);
  try {
    methodHandle.invoke(targetService, argumentsObject, context);
  } catch (WrongMethodTypeException | ClassCastException invocationException) {
    // Invocation-specific exceptions are thrown as is — they are not thrown
    // from the _transaction method_, but from framework code (see mh#invoke spec).
    throw invocationException;
  } catch (ExecutionException serviceException) {
    // 'Service-defined' transaction exceptions
    throw serviceException;
  } catch (Throwable unexpectedServiceException) {
    // Any other _transaction_ exceptions
    throw new UnexpectedExecutionException(unexpectedServiceException);
  }
}
 
源代码2 项目: es6draft   文件: NativeCalls.java
private static MethodHandle forSpreadCall(MethodHandle mh, MethodType type) {
    int expectedParameters = mh.type().parameterCount();
    int actualParameters = type.parameterCount();
    if (!mh.isVarargsCollector() || !mh.type().parameterType(expectedParameters - 1).equals(Object[].class)) {
        throw new WrongMethodTypeException("Not Object[] var-args collector");
    }
    if (expectedParameters > actualParameters) {
        throw new WrongMethodTypeException("Too few arguments");
    }
    if (expectedParameters < actualParameters) {
        int fixedCount = actualParameters - expectedParameters;
        int firstFixed = expectedParameters - 1;
        List<Class<?>> fixed = type.parameterList().subList(firstFixed, firstFixed + fixedCount);
        mh = MethodHandles.collectArguments(mh, firstFixed, combineArraysMH);
        mh = MethodHandles.collectArguments(mh, firstFixed, toObjectArray(fixed));
    }
    return mh.asType(type);
}
 
private static void checkForWrongMethodTypeException(MethodHandle mh, MethodType mt) {
    try {
        MethodHandles.explicitCastArguments(mh, mt);
        throw new AssertionError("Expected WrongMethodTypeException is not thrown");
    } catch (WrongMethodTypeException wmte) {
        if (VERBOSE) {
            System.out.printf("Expected exception %s: %s\n",
                    wmte.getClass(), wmte.getMessage());
        }
    }
}
 
源代码4 项目: dragonwell8_jdk   文件: BigArityTest.java
private void testArities(Class<? extends Object[]> cls,
                         int minArity,
                         int maxArity,
                         int iterations) throws Throwable {
    boolean verbose = (cls == Object[].class);
    for (int arity = minArity; arity <= maxArity; arity++) {
        if (verbose)  System.out.println("arity="+arity);
        MethodHandle mh = MH_hashArguments(cls, arity);
        MethodHandle mh_VA = mh.asSpreader(cls, arity);
        assert(mh_VA.type().parameterType(0) == cls);
        testArities(cls, arity, iterations, verbose, mh, mh_VA);
        // mh_CA will collect arguments of a particular type and pass them to mh_VA
        MethodHandle mh_CA = mh_VA.asCollector(cls, arity);
        MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity);
        assert(mh_CA.type().equals(mh.type()));
        assert(mh_VA2.type().equals(mh_VA.type()));
        if (cls != Object[].class) {
            try {
                mh_VA2.invokeWithArguments(new Object[arity]);
                throw new AssertionError("should not reach");
            } catch (ClassCastException | WrongMethodTypeException ex) {
            }
        }
        int iterations_VA = iterations / 100;
        testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2);
    }
}
 
源代码5 项目: TencentKona-8   文件: ExplicitCastArgumentsTest.java
private static void checkForWrongMethodTypeException(MethodHandle mh, MethodType mt) {
    try {
        MethodHandles.explicitCastArguments(mh, mt);
        throw new AssertionError("Expected WrongMethodTypeException is not thrown");
    } catch (WrongMethodTypeException wmte) {
        if (VERBOSE) {
            System.out.printf("Expected exception %s: %s\n",
                    wmte.getClass(), wmte.getMessage());
        }
    }
}
 
源代码6 项目: TencentKona-8   文件: BigArityTest.java
private void testArities(Class<? extends Object[]> cls,
                         int minArity,
                         int maxArity,
                         int iterations) throws Throwable {
    boolean verbose = (cls == Object[].class);
    for (int arity = minArity; arity <= maxArity; arity++) {
        if (verbose)  System.out.println("arity="+arity);
        MethodHandle mh = MH_hashArguments(cls, arity);
        MethodHandle mh_VA = mh.asSpreader(cls, arity);
        assert(mh_VA.type().parameterType(0) == cls);
        testArities(cls, arity, iterations, verbose, mh, mh_VA);
        // mh_CA will collect arguments of a particular type and pass them to mh_VA
        MethodHandle mh_CA = mh_VA.asCollector(cls, arity);
        MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity);
        assert(mh_CA.type().equals(mh.type()));
        assert(mh_VA2.type().equals(mh_VA.type()));
        if (cls != Object[].class) {
            try {
                mh_VA2.invokeWithArguments(new Object[arity]);
                throw new AssertionError("should not reach");
            } catch (ClassCastException | WrongMethodTypeException ex) {
            }
        }
        int iterations_VA = iterations / 100;
        testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2);
    }
}
 
源代码7 项目: jdk8u60   文件: BigArityTest.java
private void testArities(Class<? extends Object[]> cls,
                         int minArity,
                         int maxArity,
                         int iterations) throws Throwable {
    boolean verbose = (cls == Object[].class);
    for (int arity = minArity; arity <= maxArity; arity++) {
        if (verbose)  System.out.println("arity="+arity);
        MethodHandle mh = MH_hashArguments(cls, arity);
        MethodHandle mh_VA = mh.asSpreader(cls, arity);
        assert(mh_VA.type().parameterType(0) == cls);
        testArities(cls, arity, iterations, verbose, mh, mh_VA);
        // mh_CA will collect arguments of a particular type and pass them to mh_VA
        MethodHandle mh_CA = mh_VA.asCollector(cls, arity);
        MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity);
        assert(mh_CA.type().equals(mh.type()));
        assert(mh_VA2.type().equals(mh_VA.type()));
        if (cls != Object[].class) {
            try {
                mh_VA2.invokeWithArguments(new Object[arity]);
                throw new AssertionError("should not reach");
            } catch (ClassCastException | WrongMethodTypeException ex) {
            }
        }
        int iterations_VA = iterations / 100;
        testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2);
    }
}
 
源代码8 项目: api-layer   文件: ApimlInstanceRegistry.java
protected int resolveInstanceLeaseDurationRewritten(final InstanceInfo info) {
    try {
        return (int) handlerResolveInstanceLeaseDurationMethod.invokeWithArguments(this, info);
    } catch (ClassCastException | WrongMethodTypeException e) {
        throw new IllegalArgumentException(EXCEPTION_MESSAGE, e);
    } catch (RuntimeException re) {
        throw re;
    } catch (Throwable t) {
        throw new IllegalArgumentException(EXCEPTION_MESSAGE, t);
    }
}
 
源代码9 项目: api-layer   文件: ApimlInstanceRegistry.java
@Override
public void register(InstanceInfo info, int leaseDuration, boolean isReplication) {
    try {
        register3ArgsMethodHandle.invokeWithArguments(this, info, leaseDuration, isReplication);
        handleRegistrationMethod.invokeWithArguments(this, info, leaseDuration, isReplication);
    } catch (ClassCastException | WrongMethodTypeException e) {
        throw new IllegalArgumentException(EXCEPTION_MESSAGE, e);
    } catch (RuntimeException re) {
        throw re;
    } catch (Throwable t) {
        throw new IllegalArgumentException(EXCEPTION_MESSAGE, t);
    }
}
 
源代码10 项目: api-layer   文件: ApimlInstanceRegistry.java
@Override
public void register(final InstanceInfo info, final boolean isReplication) {
    try {
        register2ArgsMethodHandle.invokeWithArguments(this, info, isReplication);
        handleRegistrationMethod.invokeWithArguments(this, info, resolveInstanceLeaseDurationRewritten(info), isReplication);
    } catch (ClassCastException | WrongMethodTypeException e) {
        throw new IllegalArgumentException(EXCEPTION_MESSAGE, e);
    } catch (RuntimeException re) {
        throw re;
    } catch (Throwable t) {
        throw new IllegalArgumentException(EXCEPTION_MESSAGE, t);
    }
}
 
源代码11 项目: api-layer   文件: ApimlInstanceRegistry.java
@Override
public boolean cancel(String appName, String serverId, boolean isReplication) {
    try {
        final boolean out = (boolean) cancelMethodHandle.invokeWithArguments(this, appName, serverId, isReplication);
        handleCancelationMethod.invokeWithArguments(this, appName, serverId, isReplication);
        return out;
    } catch (ClassCastException | WrongMethodTypeException e) {
        throw new IllegalArgumentException(EXCEPTION_MESSAGE, e);
    } catch (RuntimeException re) {
        throw re;
    } catch (Throwable t) {
        throw new IllegalArgumentException(EXCEPTION_MESSAGE, t);
    }
}
 
源代码12 项目: openjdk-jdk8u   文件: ExplicitCastArgumentsTest.java
private static void checkForWrongMethodTypeException(MethodHandle mh, MethodType mt) {
    try {
        MethodHandles.explicitCastArguments(mh, mt);
        throw new AssertionError("Expected WrongMethodTypeException is not thrown");
    } catch (WrongMethodTypeException wmte) {
        if (VERBOSE) {
            System.out.printf("Expected exception %s: %s\n",
                    wmte.getClass(), wmte.getMessage());
        }
    }
}
 
源代码13 项目: openjdk-jdk8u   文件: BigArityTest.java
private void testArities(Class<? extends Object[]> cls,
                         int minArity,
                         int maxArity,
                         int iterations) throws Throwable {
    boolean verbose = (cls == Object[].class);
    for (int arity = minArity; arity <= maxArity; arity++) {
        if (verbose)  System.out.println("arity="+arity);
        MethodHandle mh = MH_hashArguments(cls, arity);
        MethodHandle mh_VA = mh.asSpreader(cls, arity);
        assert(mh_VA.type().parameterType(0) == cls);
        testArities(cls, arity, iterations, verbose, mh, mh_VA);
        // mh_CA will collect arguments of a particular type and pass them to mh_VA
        MethodHandle mh_CA = mh_VA.asCollector(cls, arity);
        MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity);
        assert(mh_CA.type().equals(mh.type()));
        assert(mh_VA2.type().equals(mh_VA.type()));
        if (cls != Object[].class) {
            try {
                mh_VA2.invokeWithArguments(new Object[arity]);
                throw new AssertionError("should not reach");
            } catch (ClassCastException | WrongMethodTypeException ex) {
            }
        }
        int iterations_VA = iterations / 100;
        testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2);
    }
}
 
private static void checkForWrongMethodTypeException(MethodHandle mh, MethodType mt) {
    try {
        MethodHandles.explicitCastArguments(mh, mt);
        throw new AssertionError("Expected WrongMethodTypeException is not thrown");
    } catch (WrongMethodTypeException wmte) {
        if (VERBOSE) {
            System.out.printf("Expected exception %s: %s\n",
                    wmte.getClass(), wmte.getMessage());
        }
    }
}
 
源代码15 项目: openjdk-jdk8u-backup   文件: BigArityTest.java
private void testArities(Class<? extends Object[]> cls,
                         int minArity,
                         int maxArity,
                         int iterations) throws Throwable {
    boolean verbose = (cls == Object[].class);
    for (int arity = minArity; arity <= maxArity; arity++) {
        if (verbose)  System.out.println("arity="+arity);
        MethodHandle mh = MH_hashArguments(cls, arity);
        MethodHandle mh_VA = mh.asSpreader(cls, arity);
        assert(mh_VA.type().parameterType(0) == cls);
        testArities(cls, arity, iterations, verbose, mh, mh_VA);
        // mh_CA will collect arguments of a particular type and pass them to mh_VA
        MethodHandle mh_CA = mh_VA.asCollector(cls, arity);
        MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity);
        assert(mh_CA.type().equals(mh.type()));
        assert(mh_VA2.type().equals(mh_VA.type()));
        if (cls != Object[].class) {
            try {
                mh_VA2.invokeWithArguments(new Object[arity]);
                throw new AssertionError("should not reach");
            } catch (ClassCastException | WrongMethodTypeException ex) {
            }
        }
        int iterations_VA = iterations / 100;
        testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2);
    }
}
 
源代码16 项目: openjdk-jdk9   文件: ExplicitCastArgumentsTest.java
private static void checkForWrongMethodTypeException(MethodHandle mh, MethodType mt) {
    try {
        MethodHandles.explicitCastArguments(mh, mt);
        throw new AssertionError("Expected WrongMethodTypeException is not thrown");
    } catch (WrongMethodTypeException wmte) {
        if (VERBOSE) {
            System.out.printf("Expected exception %s: %s\n",
                    wmte.getClass(), wmte.getMessage());
        }
    }
}
 
源代码17 项目: openjdk-jdk9   文件: BigArityTest.java
private void testArities(Class<? extends Object[]> cls,
                         int minArity,
                         int maxArity,
                         int iterations) throws Throwable {
    boolean verbose = (cls == Object[].class);
    for (int arity = minArity; arity <= maxArity; arity++) {
        if (verbose)  System.out.println("arity="+arity);
        MethodHandle mh = MH_hashArguments(cls, arity);
        MethodHandle mh_VA = mh.asSpreader(cls, arity);
        MethodHandle mh_VA_h = mh.asSpreader(0, cls, arity-1);
        assert(mh_VA.type().parameterType(0) == cls);
        assert(mh_VA_h.type().parameterType(0) == cls);
        testArities(cls, arity, iterations, verbose, mh, mh_VA, mh_VA_h);
        // mh_CA will collect arguments of a particular type and pass them to mh_VA
        MethodHandle mh_CA = mh_VA.asCollector(cls, arity);
        MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity);
        MethodHandle mh_VA2_h = mh_CA.asSpreader(0, cls, arity-1);
        assert(mh_CA.type().equals(mh.type()));
        assert(mh_VA2.type().equals(mh_VA.type()));
        if (cls != Object[].class) {
            try {
                mh_VA2.invokeWithArguments(new Object[arity]);
                throw new AssertionError("should not reach");
            } catch (ClassCastException | WrongMethodTypeException ex) {
            }
        }
        int iterations_VA = iterations / 100;
        testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2, mh_VA2_h);
    }
}
 
源代码18 项目: jdk8u-jdk   文件: ExplicitCastArgumentsTest.java
private static void checkForWrongMethodTypeException(MethodHandle mh, MethodType mt) {
    try {
        MethodHandles.explicitCastArguments(mh, mt);
        throw new AssertionError("Expected WrongMethodTypeException is not thrown");
    } catch (WrongMethodTypeException wmte) {
        if (VERBOSE) {
            System.out.printf("Expected exception %s: %s\n",
                    wmte.getClass(), wmte.getMessage());
        }
    }
}
 
源代码19 项目: jdk8u-jdk   文件: BigArityTest.java
private void testArities(Class<? extends Object[]> cls,
                         int minArity,
                         int maxArity,
                         int iterations) throws Throwable {
    boolean verbose = (cls == Object[].class);
    for (int arity = minArity; arity <= maxArity; arity++) {
        if (verbose)  System.out.println("arity="+arity);
        MethodHandle mh = MH_hashArguments(cls, arity);
        MethodHandle mh_VA = mh.asSpreader(cls, arity);
        assert(mh_VA.type().parameterType(0) == cls);
        testArities(cls, arity, iterations, verbose, mh, mh_VA);
        // mh_CA will collect arguments of a particular type and pass them to mh_VA
        MethodHandle mh_CA = mh_VA.asCollector(cls, arity);
        MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity);
        assert(mh_CA.type().equals(mh.type()));
        assert(mh_VA2.type().equals(mh_VA.type()));
        if (cls != Object[].class) {
            try {
                mh_VA2.invokeWithArguments(new Object[arity]);
                throw new AssertionError("should not reach");
            } catch (ClassCastException | WrongMethodTypeException ex) {
            }
        }
        int iterations_VA = iterations / 100;
        testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2);
    }
}
 
源代码20 项目: hottub   文件: ExplicitCastArgumentsTest.java
private static void checkForWrongMethodTypeException(MethodHandle mh, MethodType mt) {
    try {
        MethodHandles.explicitCastArguments(mh, mt);
        throw new AssertionError("Expected WrongMethodTypeException is not thrown");
    } catch (WrongMethodTypeException wmte) {
        if (VERBOSE) {
            System.out.printf("Expected exception %s: %s\n",
                    wmte.getClass(), wmte.getMessage());
        }
    }
}
 
源代码21 项目: hottub   文件: BigArityTest.java
private void testArities(Class<? extends Object[]> cls,
                         int minArity,
                         int maxArity,
                         int iterations) throws Throwable {
    boolean verbose = (cls == Object[].class);
    for (int arity = minArity; arity <= maxArity; arity++) {
        if (verbose)  System.out.println("arity="+arity);
        MethodHandle mh = MH_hashArguments(cls, arity);
        MethodHandle mh_VA = mh.asSpreader(cls, arity);
        assert(mh_VA.type().parameterType(0) == cls);
        testArities(cls, arity, iterations, verbose, mh, mh_VA);
        // mh_CA will collect arguments of a particular type and pass them to mh_VA
        MethodHandle mh_CA = mh_VA.asCollector(cls, arity);
        MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity);
        assert(mh_CA.type().equals(mh.type()));
        assert(mh_VA2.type().equals(mh_VA.type()));
        if (cls != Object[].class) {
            try {
                mh_VA2.invokeWithArguments(new Object[arity]);
                throw new AssertionError("should not reach");
            } catch (ClassCastException | WrongMethodTypeException ex) {
            }
        }
        int iterations_VA = iterations / 100;
        testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2);
    }
}
 
源代码22 项目: openjdk-8-source   文件: BigArityTest.java
private void testArities(Class<? extends Object[]> cls,
                         int minArity,
                         int maxArity,
                         int iterations) throws Throwable {
    boolean verbose = (cls == Object[].class);
    for (int arity = minArity; arity <= maxArity; arity++) {
        if (verbose)  System.out.println("arity="+arity);
        MethodHandle mh = MH_hashArguments(cls, arity);
        MethodHandle mh_VA = mh.asSpreader(cls, arity);
        assert(mh_VA.type().parameterType(0) == cls);
        testArities(cls, arity, iterations, verbose, mh, mh_VA);
        // mh_CA will collect arguments of a particular type and pass them to mh_VA
        MethodHandle mh_CA = mh_VA.asCollector(cls, arity);
        MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity);
        assert(mh_CA.type().equals(mh.type()));
        assert(mh_VA2.type().equals(mh_VA.type()));
        if (cls != Object[].class) {
            try {
                mh_VA2.invokeWithArguments(new Object[arity]);
                throw new AssertionError("should not reach");
            } catch (ClassCastException | WrongMethodTypeException ex) {
            }
        }
        int iterations_VA = iterations / 100;
        testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2);
    }
}
 
源代码23 项目: Wizardry   文件: ModuleOverrideHandler.java
/**
 * Invokes the override implementation.
 *
 * @param args passed arguments
 * @return the return value from the override call.
 * @throws Throwable any occurred exception thrown by the override implementation or by the Java Method Handler.
 */
Object invoke(Object[] args) throws Throwable {
	int idxContextParamRing = baseMethod.getIdxContextParamRing();
	int idxContextParamSuper = baseMethod.getIdxContextParamSuper();

	Object passedArgs[] = args;
	int countExtra = 1;
	if (idxContextParamRing >= 0)
		countExtra++;
	if (idxContextParamSuper >= 0)
		countExtra++;

	// Add extra arguments like this pointer a.s.o.
	passedArgs = new Object[args.length + countExtra];
	int i = 0;
	int j = 0;
	while (i < passedArgs.length) {
		if (i == 0) {
			passedArgs[i] = object;
		} else if (i == idxContextParamRing + 1) {
			passedArgs[i] = spellRingWithOverride;
		} else if (i == idxContextParamSuper + 1) {
			passedArgs[i] = new ModuleOverrideSuper(prev);
		} else {
			passedArgs[i] = args[j];
			j++;
		}
		i++;
	}

	try {
		return baseMethod.getMethodHandle().invokeWithArguments(passedArgs);
	} catch (WrongMethodTypeException | ClassCastException e) {
		// NOTE: If this happens, then correctness of checks like "areMethodsCompatible()" a.s.o. need to be debugged.
		throw new IllegalStateException("Couldn't invoke call. See cause.", e);
	}
}
 
源代码24 项目: openjdk-8   文件: BigArityTest.java
private void testArities(Class<? extends Object[]> cls,
                         int minArity,
                         int maxArity,
                         int iterations) throws Throwable {
    boolean verbose = (cls == Object[].class);
    for (int arity = minArity; arity <= maxArity; arity++) {
        if (verbose)  System.out.println("arity="+arity);
        MethodHandle mh = MH_hashArguments(cls, arity);
        MethodHandle mh_VA = mh.asSpreader(cls, arity);
        assert(mh_VA.type().parameterType(0) == cls);
        testArities(cls, arity, iterations, verbose, mh, mh_VA);
        // mh_CA will collect arguments of a particular type and pass them to mh_VA
        MethodHandle mh_CA = mh_VA.asCollector(cls, arity);
        MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity);
        assert(mh_CA.type().equals(mh.type()));
        assert(mh_VA2.type().equals(mh_VA.type()));
        if (cls != Object[].class) {
            try {
                mh_VA2.invokeWithArguments(new Object[arity]);
                throw new AssertionError("should not reach");
            } catch (ClassCastException | WrongMethodTypeException ex) {
            }
        }
        int iterations_VA = iterations / 100;
        testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2);
    }
}
 
源代码25 项目: jdk8u_jdk   文件: ExplicitCastArgumentsTest.java
private static void checkForWrongMethodTypeException(MethodHandle mh, MethodType mt) {
    try {
        MethodHandles.explicitCastArguments(mh, mt);
        throw new AssertionError("Expected WrongMethodTypeException is not thrown");
    } catch (WrongMethodTypeException wmte) {
        if (VERBOSE) {
            System.out.printf("Expected exception %s: %s\n",
                    wmte.getClass(), wmte.getMessage());
        }
    }
}
 
源代码26 项目: jdk8u_jdk   文件: BigArityTest.java
private void testArities(Class<? extends Object[]> cls,
                         int minArity,
                         int maxArity,
                         int iterations) throws Throwable {
    boolean verbose = (cls == Object[].class);
    for (int arity = minArity; arity <= maxArity; arity++) {
        if (verbose)  System.out.println("arity="+arity);
        MethodHandle mh = MH_hashArguments(cls, arity);
        MethodHandle mh_VA = mh.asSpreader(cls, arity);
        assert(mh_VA.type().parameterType(0) == cls);
        testArities(cls, arity, iterations, verbose, mh, mh_VA);
        // mh_CA will collect arguments of a particular type and pass them to mh_VA
        MethodHandle mh_CA = mh_VA.asCollector(cls, arity);
        MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity);
        assert(mh_CA.type().equals(mh.type()));
        assert(mh_VA2.type().equals(mh_VA.type()));
        if (cls != Object[].class) {
            try {
                mh_VA2.invokeWithArguments(new Object[arity]);
                throw new AssertionError("should not reach");
            } catch (ClassCastException | WrongMethodTypeException ex) {
            }
        }
        int iterations_VA = iterations / 100;
        testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2);
    }
}
 
源代码27 项目: jdk8u-jdk   文件: BigArityTest.java
private void testArities(Class<? extends Object[]> cls,
                         int minArity,
                         int maxArity,
                         int iterations) throws Throwable {
    boolean verbose = (cls == Object[].class);
    for (int arity = minArity; arity <= maxArity; arity++) {
        if (verbose)  System.out.println("arity="+arity);
        MethodHandle mh = MH_hashArguments(cls, arity);
        MethodHandle mh_VA = mh.asSpreader(cls, arity);
        assert(mh_VA.type().parameterType(0) == cls);
        testArities(cls, arity, iterations, verbose, mh, mh_VA);
        // mh_CA will collect arguments of a particular type and pass them to mh_VA
        MethodHandle mh_CA = mh_VA.asCollector(cls, arity);
        MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity);
        assert(mh_CA.type().equals(mh.type()));
        assert(mh_VA2.type().equals(mh_VA.type()));
        if (cls != Object[].class) {
            try {
                mh_VA2.invokeWithArguments(new Object[arity]);
                throw new AssertionError("should not reach");
            } catch (ClassCastException | WrongMethodTypeException ex) {
            }
        }
        int iterations_VA = iterations / 100;
        testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2);
    }
}
 
源代码28 项目: jdk8u-dev-jdk   文件: BigArityTest.java
private void testArities(Class<? extends Object[]> cls,
                         int minArity,
                         int maxArity,
                         int iterations) throws Throwable {
    boolean verbose = (cls == Object[].class);
    for (int arity = minArity; arity <= maxArity; arity++) {
        if (verbose)  System.out.println("arity="+arity);
        MethodHandle mh = MH_hashArguments(cls, arity);
        MethodHandle mh_VA = mh.asSpreader(cls, arity);
        assert(mh_VA.type().parameterType(0) == cls);
        testArities(cls, arity, iterations, verbose, mh, mh_VA);
        // mh_CA will collect arguments of a particular type and pass them to mh_VA
        MethodHandle mh_CA = mh_VA.asCollector(cls, arity);
        MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity);
        assert(mh_CA.type().equals(mh.type()));
        assert(mh_VA2.type().equals(mh_VA.type()));
        if (cls != Object[].class) {
            try {
                mh_VA2.invokeWithArguments(new Object[arity]);
                throw new AssertionError("should not reach");
            } catch (ClassCastException | WrongMethodTypeException ex) {
            }
        }
        int iterations_VA = iterations / 100;
        testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2);
    }
}
 
源代码29 项目: proxy2   文件: MethodBuilder.java
/**
 * Create a method handle that will apply all transformations specified by the current method builder
 * and then call the {@code method} method. 
 * This method uses a cache if the method is a virtual method (either on class or interface)
 * 
 * @param lookup the lookup object used to find the @code method}
 * @param method the method called at the end of the transformation.
 * @return a new method handle constructed by applying all transformations on the target method.
 * @throws NoSuchMethodException throws is a method is not visible.
 * @throws NoSuchFieldException throws if a field is not visible.
 * @throws IllegalAccessException throws if a type or a member of a type is not visible.
 */
public MethodHandle unreflect(Lookup lookup, Method method) throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
  MethodHandle target = lookup.unreflect(method);
  MethodType targetType = target.type();
  if (!targetType.equals(sig)) {
    throw new WrongMethodTypeException("target type " + targetType + " is not equals to current type " + sig);
  }
  
  int modifiers = method.getModifiers();
  if (!Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers)) { // can be virtual
    target = new InliningCacheCallSite(target).dynamicInvoker();
  }
  return call(target);
}
 
源代码30 项目: tutorials   文件: MethodHandlesTest.java
@Test(expected = WrongMethodTypeException.class)
public void givenSumMethodHandleAndIncompatibleArguments_whenInvokingExact_thenException() throws Throwable {
    MethodHandles.Lookup lookup = MethodHandles.lookup();
    MethodType mt = MethodType.methodType(int.class, int.class, int.class);
    MethodHandle sumMH = lookup.findStatic(Integer.class, "sum", mt);

    sumMH.invokeExact(Integer.valueOf(1), 11);
}
 
 类所在包
 同包方法