Skip to content
Permalink
Browse files
8273656: Improve java.lang.invoke.MethodType.parameterList() and its …
…usage

Reviewed-by: jvernee, vlivanov, mchung
  • Loading branch information
stsypanov authored and JornVernee committed Sep 15, 2021
1 parent 8fbcc82 commit 4c673df31e46644b21fefa51e0ea01f7d9b94856
Showing with 7 additions and 7 deletions.
  1. +6 −6 src/java.base/share/classes/java/lang/invoke/MethodHandles.java
  2. +1 −1 src/java.base/share/classes/java/lang/invoke/MethodType.java
@@ -5882,8 +5882,8 @@ private static void filterReturnValueChecks(MethodType targetType, MethodType fi
BoundMethodHandle result = target.rebind();
LambdaForm lform = result.editor().collectReturnValueForm(filterType.basicType());
MethodType newType = targetType.changeReturnType(filterType.returnType());
if (filterType.parameterList().size() > 1) {
for (int i = 0 ; i < filterType.parameterList().size() - 1 ; i++) {
if (filterType.parameterCount() > 1) {
for (int i = 0 ; i < filterType.parameterCount() - 1 ; i++) {
newType = newType.appendParameterTypes(filterType.parameterType(i));
}
}
@@ -6735,7 +6735,7 @@ private static void loopChecks1a(int i, MethodHandle in, MethodHandle st) {
filter(t -> t.parameterCount() > skipSize).
map(MethodType::parameterList).
reduce((p, q) -> p.size() >= q.size() ? p : q).orElse(empty);
return longest.size() == 0 ? empty : longest.subList(skipSize, longest.size());
return longest.isEmpty() ? empty : longest.subList(skipSize, longest.size());
}

private static List<Class<?>> longestParameterList(List<List<Class<?>>> lists) {
@@ -7019,7 +7019,7 @@ private static void whileLoopChecks(MethodHandle init, MethodHandle pred, Method
List<Class<?>> outerList = innerList;
if (returnType == void.class) {
// OK
} else if (innerList.size() == 0 || innerList.get(0) != returnType) {
} else if (innerList.isEmpty() || innerList.get(0) != returnType) {
// leading V argument missing => error
MethodType expected = bodyType.insertParameterTypes(0, returnType);
throw misMatchedTypes("body function", bodyType, expected);
@@ -7349,7 +7349,7 @@ private static void countedLoopChecks(MethodHandle start, MethodHandle end, Meth
List<Class<?>> innerList = bodyType.parameterList();
// strip leading V value if present
int vsize = (returnType == void.class ? 0 : 1);
if (vsize != 0 && (innerList.size() == 0 || innerList.get(0) != returnType)) {
if (vsize != 0 && (innerList.isEmpty() || innerList.get(0) != returnType)) {
// argument list has no "V" => error
MethodType expected = bodyType.insertParameterTypes(0, returnType);
throw misMatchedTypes("body function", bodyType, expected);
@@ -7573,7 +7573,7 @@ public static MethodHandle iteratedLoop(MethodHandle iterator, MethodHandle init
List<Class<?>> internalParamList = bodyType.parameterList();
// strip leading V value if present
int vsize = (returnType == void.class ? 0 : 1);
if (vsize != 0 && (internalParamList.size() == 0 || internalParamList.get(0) != returnType)) {
if (vsize != 0 && (internalParamList.isEmpty() || internalParamList.get(0) != returnType)) {
// argument list has no "V" => error
MethodType expected = bodyType.insertParameterTypes(0, returnType);
throw misMatchedTypes("body function", bodyType, expected);
@@ -792,7 +792,7 @@ public int parameterCount() {
* @return the parameter types (as an immutable list)
*/
public List<Class<?>> parameterList() {
return Collections.unmodifiableList(Arrays.asList(ptypes.clone()));
return List.of(ptypes);
}

/**

1 comment on commit 4c673df

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 4c673df Sep 15, 2021

Please sign in to comment.