8152667: MHs.iteratedLoop(...) throws unexpected WMTE, disallows Iterator subclasses, generates inconsistent loop result type

Reviewed-by: redestad
This commit is contained in:
Michael Haupt 2016-04-22 13:36:22 +02:00
parent 741bd9b060
commit 5b392c0abc
2 changed files with 94 additions and 10 deletions

View file

@ -4572,17 +4572,24 @@ assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum"));
*/
public static MethodHandle iteratedLoop(MethodHandle iterator, MethodHandle init, MethodHandle body) {
checkIteratedLoop(iterator, body);
final boolean voidInit = init == null || init.type().returnType() == void.class;
Class<?> resultType = init == null ?
body == null ? void.class : body.type().returnType() :
init.type().returnType();
boolean voidResult = resultType == void.class;
MethodHandle initIterator;
if (iterator == null) {
MethodHandle initit = MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_initIterator);
initIterator = initit.asType(initit.type().changeParameterType(0,
body.type().parameterType(voidResult ? 1 : 2)));
} else {
initIterator = iterator.asType(iterator.type().changeReturnType(Iterator.class));
}
MethodHandle initit = MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_initIterator);
MethodHandle initIterator = iterator == null ?
initit.asType(initit.type().changeParameterType(0, body.type().parameterType(voidInit ? 1 : 2))) :
iterator;
Class<?> itype = initIterator.type().returnType();
Class<?> ttype = body.type().parameterType(0);
MethodHandle returnVar =
dropArguments(voidInit ? zero(void.class) : identity(init.type().returnType()), 0, itype);
dropArguments(voidResult ? zero(void.class) : identity(resultType), 0, Iterator.class);
MethodHandle initnx = MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_iterateNext);
MethodHandle nextVal = initnx.asType(initnx.type().changeReturnType(ttype));