src/java.base/share/classes/java/lang/invoke/MethodHandles.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File jdk Sdiff src/java.base/share/classes/java/lang/invoke

src/java.base/share/classes/java/lang/invoke/MethodHandles.java

Print this page
rev 10592 : 8050052: Small cleanups in java.lang.invoke code
Reviewed-by: ?
rev 10593 : 8050053: Improve caching of different invokers
Reviewed-by: vlivanov, ?
Contributed-by: john.r.rose@oracle.com
rev 10594 : 8050166: Get rid of some package-private methods on arguments in j.l.i.MethodHandle
Reviewed-by: vlivanov, ?
Contributed-by: john.r.rose@oracle.com
rev 10595 : 8050173: Add j.l.i.MethodHandle.copyWith(MethodType, LambdaForm)
Reviewed-by: vlivanov, ?
Contributed-by: john.r.rose@oracle.com
rev 10596 : [mq]: 07.8050173.viewAsType.1
rev 10600 : imported patch 11.8050877.conv
rev 10601 : imported patch 12.8050884.identity
rev 10602 : imported patch 13.8050887.zero
rev 10603 : 8057654: Extract checks performed during MethodHandle construction into separate methods
Reviewed-by: vlivanov, ?
Contributed-by: john.r.rose@oracle.com
rev 10605 : [mq]: 15.8057656.mt_cast.1


2007      *     widening and/or narrowing.)
2008      * <li>If <em>T0</em> is a reference and <em>T1</em> a primitive, an unboxing
2009      *     conversion will be applied at runtime, possibly followed
2010      *     by a Java casting conversion (JLS 5.5) on the primitive value,
2011      *     possibly followed by a conversion from byte to boolean by testing
2012      *     the low-order bit.
2013      * <li>If <em>T0</em> is a reference and <em>T1</em> a primitive,
2014      *     and if the reference is null at runtime, a zero value is introduced.
2015      * </ul>
2016      * @param target the method handle to invoke after arguments are retyped
2017      * @param newType the expected type of the new method handle
2018      * @return a method handle which delegates to the target after performing
2019      *           any necessary argument conversions, and arranges for any
2020      *           necessary return value conversions
2021      * @throws NullPointerException if either argument is null
2022      * @throws WrongMethodTypeException if the conversion cannot be made
2023      * @see MethodHandle#asType
2024      */
2025     public static
2026     MethodHandle explicitCastArguments(MethodHandle target, MethodType newType) {
2027         if (!target.type().isCastableTo(newType)) {
2028             throw new WrongMethodTypeException("cannot explicitly cast "+target+" to "+newType);



2029         }
2030         return MethodHandleImpl.makePairwiseConvert(target, newType, false);
2031     }
2032 
2033     /**
2034      * Produces a method handle which adapts the calling sequence of the
2035      * given method handle to a new type, by reordering the arguments.
2036      * The resulting method handle is guaranteed to report a type
2037      * which is equal to the desired new type.
2038      * <p>
2039      * The given array controls the reordering.
2040      * Call {@code #I} the number of incoming parameters (the value
2041      * {@code newType.parameterCount()}, and call {@code #O} the number
2042      * of outgoing parameters (the value {@code target.type().parameterCount()}).
2043      * Then the length of the reordering array must be {@code #O},
2044      * and each element must be a non-negative number less than {@code #I}.
2045      * For every {@code N} less than {@code #O}, the {@code N}-th
2046      * outgoing argument will be taken from the {@code I}-th incoming
2047      * argument, where {@code I} is {@code reorder[N]}.
2048      * <p>




2007      *     widening and/or narrowing.)
2008      * <li>If <em>T0</em> is a reference and <em>T1</em> a primitive, an unboxing
2009      *     conversion will be applied at runtime, possibly followed
2010      *     by a Java casting conversion (JLS 5.5) on the primitive value,
2011      *     possibly followed by a conversion from byte to boolean by testing
2012      *     the low-order bit.
2013      * <li>If <em>T0</em> is a reference and <em>T1</em> a primitive,
2014      *     and if the reference is null at runtime, a zero value is introduced.
2015      * </ul>
2016      * @param target the method handle to invoke after arguments are retyped
2017      * @param newType the expected type of the new method handle
2018      * @return a method handle which delegates to the target after performing
2019      *           any necessary argument conversions, and arranges for any
2020      *           necessary return value conversions
2021      * @throws NullPointerException if either argument is null
2022      * @throws WrongMethodTypeException if the conversion cannot be made
2023      * @see MethodHandle#asType
2024      */
2025     public static
2026     MethodHandle explicitCastArguments(MethodHandle target, MethodType newType) {
2027         MethodType oldType = target.type();
2028         // use the asTypeCache when possible:
2029         if (oldType == newType)  return target;
2030         if (oldType.explicitCastEquivalentToAsType(newType)) {
2031             return target.asType(newType);
2032         }
2033         return MethodHandleImpl.makePairwiseConvert(target, newType, false);
2034     }
2035 
2036     /**
2037      * Produces a method handle which adapts the calling sequence of the
2038      * given method handle to a new type, by reordering the arguments.
2039      * The resulting method handle is guaranteed to report a type
2040      * which is equal to the desired new type.
2041      * <p>
2042      * The given array controls the reordering.
2043      * Call {@code #I} the number of incoming parameters (the value
2044      * {@code newType.parameterCount()}, and call {@code #O} the number
2045      * of outgoing parameters (the value {@code target.type().parameterCount()}).
2046      * Then the length of the reordering array must be {@code #O},
2047      * and each element must be a non-negative number less than {@code #I}.
2048      * For every {@code N} less than {@code #O}, the {@code N}-th
2049      * outgoing argument will be taken from the {@code I}-th incoming
2050      * argument, where {@code I} is {@code reorder[N]}.
2051      * <p>


src/java.base/share/classes/java/lang/invoke/MethodHandles.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File