mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8154754: MethodHandles.countedLoop errors in deriving loop arguments, result type, and local state
Reviewed-by: redestad
This commit is contained in:
parent
e53e280d37
commit
cafabcafce
2 changed files with 104 additions and 8 deletions
|
@ -4476,16 +4476,24 @@ assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum"));
|
|||
* @since 9
|
||||
*/
|
||||
public static MethodHandle countedLoop(MethodHandle start, MethodHandle end, MethodHandle init, MethodHandle body) {
|
||||
MethodHandle defaultResultHandle = init == null || init.type().returnType() == void.class ?
|
||||
zero(void.class) :
|
||||
identity(init.type().returnType());
|
||||
MethodHandle adaptedBody = body == null ? dropArguments(defaultResultHandle, 0, int.class) : body;
|
||||
Class<?> resultType;
|
||||
MethodHandle actualInit;
|
||||
if (init == null) {
|
||||
resultType = body == null ? void.class : body.type().returnType();
|
||||
actualInit = empty(methodType(resultType));
|
||||
} else {
|
||||
resultType = init.type().returnType();
|
||||
actualInit = init;
|
||||
}
|
||||
MethodHandle defaultResultHandle = resultType == void.class ? zero(void.class) : identity(resultType);
|
||||
MethodHandle actualBody = body == null ? dropArguments(defaultResultHandle, 0, int.class) : body;
|
||||
MethodHandle returnVar = dropArguments(defaultResultHandle, 0, int.class, int.class);
|
||||
MethodHandle actualEnd = end == null ? constant(int.class, 0) : end;
|
||||
MethodHandle[] indexVar = {start, MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_countedLoopStep)};
|
||||
MethodHandle[] loopLimit = {end, null, MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_countedLoopPred),
|
||||
returnVar};
|
||||
MethodHandle[] bodyClause = {init,
|
||||
filterArgument(dropArguments(adaptedBody, 1, int.class), 0,
|
||||
MethodHandle[] loopLimit = {actualEnd, null,
|
||||
MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_countedLoopPred), returnVar};
|
||||
MethodHandle[] bodyClause = {actualInit,
|
||||
filterArgument(dropArguments(actualBody, 1, int.class), 0,
|
||||
MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_decrementCounter))};
|
||||
return loop(indexVar, loopLimit, bodyClause);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue