4805 }
4806
4807 private static void checkLoop1a(int i, MethodHandle in, MethodHandle st) {
4808 if (in.type().returnType() != st.type().returnType()) {
4809 throw misMatchedTypes("clause " + i + ": init and step return types", in.type().returnType(),
4810 st.type().returnType());
4811 }
4812 }
4813
4814 private static List<Class<?>> buildCommonSuffix(List<MethodHandle> init, List<MethodHandle> step, List<MethodHandle> pred, List<MethodHandle> fini, int cpSize) {
4815 final List<Class<?>> empty = List.of();
4816 final List<MethodHandle> nonNullInits = init.stream().filter(Objects::nonNull).collect(Collectors.toList());
4817 if (nonNullInits.isEmpty()) {
4818 final List<Class<?>> longest = Stream.of(step, pred, fini).flatMap(List::stream).filter(Objects::nonNull).
4819 // take only those that can contribute to a common suffix because they are longer than the prefix
4820 map(MethodHandle::type).filter(t -> t.parameterCount() > cpSize).map(MethodType::parameterList).
4821 reduce((p, q) -> p.size() >= q.size() ? p : q).orElse(empty);
4822 return longest.size() == 0 ? empty : longest.subList(cpSize, longest.size());
4823 } else {
4824 return nonNullInits.stream().map(MethodHandle::type).map(MethodType::parameterList).
4825 reduce((p, q) -> p.size() >= q.size() ? p : q).get();
4826 }
4827 }
4828
4829 private static void checkLoop1b(List<MethodHandle> init, List<Class<?>> commonSuffix) {
4830 if (init.stream().filter(Objects::nonNull).map(MethodHandle::type).map(MethodType::parameterList).
4831 anyMatch(pl -> !pl.equals(commonSuffix.subList(0, pl.size())))) {
4832 throw newIllegalArgumentException("found non-effectively identical init parameter type lists: " + init +
4833 " (common suffix: " + commonSuffix + ")");
4834 }
4835 }
4836
4837 private static void checkLoop1cd(List<MethodHandle> pred, List<MethodHandle> fini, Class<?> loopReturnType) {
4838 if (fini.stream().filter(Objects::nonNull).map(MethodHandle::type).map(MethodType::returnType).
4839 anyMatch(t -> t != loopReturnType)) {
4840 throw newIllegalArgumentException("found non-identical finalizer return types: " + fini + " (return type: " +
4841 loopReturnType + ")");
4842 }
4843
4844 if (!pred.stream().filter(Objects::nonNull).findFirst().isPresent()) {
4845 throw newIllegalArgumentException("no predicate found", pred);
|
4805 }
4806
4807 private static void checkLoop1a(int i, MethodHandle in, MethodHandle st) {
4808 if (in.type().returnType() != st.type().returnType()) {
4809 throw misMatchedTypes("clause " + i + ": init and step return types", in.type().returnType(),
4810 st.type().returnType());
4811 }
4812 }
4813
4814 private static List<Class<?>> buildCommonSuffix(List<MethodHandle> init, List<MethodHandle> step, List<MethodHandle> pred, List<MethodHandle> fini, int cpSize) {
4815 final List<Class<?>> empty = List.of();
4816 final List<MethodHandle> nonNullInits = init.stream().filter(Objects::nonNull).collect(Collectors.toList());
4817 if (nonNullInits.isEmpty()) {
4818 final List<Class<?>> longest = Stream.of(step, pred, fini).flatMap(List::stream).filter(Objects::nonNull).
4819 // take only those that can contribute to a common suffix because they are longer than the prefix
4820 map(MethodHandle::type).filter(t -> t.parameterCount() > cpSize).map(MethodType::parameterList).
4821 reduce((p, q) -> p.size() >= q.size() ? p : q).orElse(empty);
4822 return longest.size() == 0 ? empty : longest.subList(cpSize, longest.size());
4823 } else {
4824 return nonNullInits.stream().map(MethodHandle::type).map(MethodType::parameterList).
4825 reduce((p, q) -> p.size() >= q.size() ? p : q).getWhenPresent();
4826 }
4827 }
4828
4829 private static void checkLoop1b(List<MethodHandle> init, List<Class<?>> commonSuffix) {
4830 if (init.stream().filter(Objects::nonNull).map(MethodHandle::type).map(MethodType::parameterList).
4831 anyMatch(pl -> !pl.equals(commonSuffix.subList(0, pl.size())))) {
4832 throw newIllegalArgumentException("found non-effectively identical init parameter type lists: " + init +
4833 " (common suffix: " + commonSuffix + ")");
4834 }
4835 }
4836
4837 private static void checkLoop1cd(List<MethodHandle> pred, List<MethodHandle> fini, Class<?> loopReturnType) {
4838 if (fini.stream().filter(Objects::nonNull).map(MethodHandle::type).map(MethodType::returnType).
4839 anyMatch(t -> t != loopReturnType)) {
4840 throw newIllegalArgumentException("found non-identical finalizer return types: " + fini + " (return type: " +
4841 loopReturnType + ")");
4842 }
4843
4844 if (!pred.stream().filter(Objects::nonNull).findFirst().isPresent()) {
4845 throw newIllegalArgumentException("no predicate found", pred);
|