8300237: Minor improvements in MethodHandles
Reviewed-by: redestad
This commit is contained in:
parent
85d8bacb0f
commit
754f6e6116
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -59,6 +59,7 @@ import java.security.ProtectionDomain;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -6744,25 +6745,19 @@ assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum"));
|
||||
}
|
||||
|
||||
private static List<Class<?>> longestParameterList(Stream<MethodHandle> mhs, int skipSize) {
|
||||
final List<Class<?>> empty = List.of();
|
||||
final List<Class<?>> longest = mhs.filter(Objects::nonNull).
|
||||
return mhs.filter(Objects::nonNull)
|
||||
// take only those that can contribute to a common suffix because they are longer than the prefix
|
||||
map(MethodHandle::type).
|
||||
filter(t -> t.parameterCount() > skipSize).
|
||||
map(MethodType::parameterList).
|
||||
reduce((p, q) -> p.size() >= q.size() ? p : q).orElse(empty);
|
||||
return longest.isEmpty() ? empty : longest.subList(skipSize, longest.size());
|
||||
}
|
||||
|
||||
private static List<Class<?>> longestParameterList(List<List<Class<?>>> lists) {
|
||||
final List<Class<?>> empty = List.of();
|
||||
return lists.stream().reduce((p, q) -> p.size() >= q.size() ? p : q).orElse(empty);
|
||||
.map(MethodHandle::type)
|
||||
.filter(t -> t.parameterCount() > skipSize)
|
||||
.max(Comparator.comparingInt(MethodType::parameterCount))
|
||||
.map(methodType -> List.of(Arrays.copyOfRange(methodType.ptypes(), skipSize, methodType.parameterCount())))
|
||||
.orElse(List.of());
|
||||
}
|
||||
|
||||
private static List<Class<?>> buildCommonSuffix(List<MethodHandle> init, List<MethodHandle> step, List<MethodHandle> pred, List<MethodHandle> fini, int cpSize) {
|
||||
final List<Class<?>> longest1 = longestParameterList(Stream.of(step, pred, fini).flatMap(List::stream), cpSize);
|
||||
final List<Class<?>> longest2 = longestParameterList(init.stream(), 0);
|
||||
return longestParameterList(List.of(longest1, longest2));
|
||||
return longest1.size() >= longest2.size() ? longest1 : longest2;
|
||||
}
|
||||
|
||||
private static void loopChecks1b(List<MethodHandle> init, List<Class<?>> commonSuffix) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user