< prev index next >

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

Print this page

  23  * questions.
  24  */
  25 
  26 package java.lang.invoke;
  27 
  28 import java.lang.constant.ClassDesc;
  29 import java.lang.constant.Constable;
  30 import java.lang.constant.MethodTypeDesc;
  31 import java.lang.ref.Reference;
  32 import java.lang.ref.ReferenceQueue;
  33 import java.lang.ref.WeakReference;
  34 import java.util.Arrays;
  35 import java.util.Collections;
  36 import java.util.List;
  37 import java.util.NoSuchElementException;
  38 import java.util.Objects;
  39 import java.util.Optional;
  40 import java.util.StringJoiner;
  41 import java.util.concurrent.ConcurrentHashMap;
  42 import java.util.concurrent.ConcurrentMap;

  43 import java.util.stream.Stream;
  44 
  45 import jdk.internal.vm.annotation.Stable;
  46 import sun.invoke.util.BytecodeDescriptor;
  47 import sun.invoke.util.VerifyType;
  48 import sun.invoke.util.Wrapper;
  49 import sun.security.util.SecurityConstants;
  50 
  51 import static java.lang.invoke.MethodHandleStatics.UNSAFE;
  52 import static java.lang.invoke.MethodHandleStatics.newIllegalArgumentException;
  53 import static java.lang.invoke.MethodType.fromDescriptor;
  54 
  55 /**
  56  * A method type represents the arguments and return type accepted and
  57  * returned by a method handle, or the arguments and return type passed
  58  * and expected  by a method handle caller.  Method types must be properly
  59  * matched between a method handle and all its callers,
  60  * and the JVM's operations enforce this matching at, specifically
  61  * during calls to {@link MethodHandle#invokeExact MethodHandle.invokeExact}
  62  * and {@link MethodHandle#invoke MethodHandle.invoke}, and during execution

 872     public int hashCode() {
 873         int hashCode = 31 + rtype.hashCode();
 874         for (Class<?> ptype : ptypes)
 875             hashCode = 31 * hashCode + ptype.hashCode();
 876         return hashCode;
 877     }
 878 
 879     /**
 880      * Returns a string representation of the method type,
 881      * of the form {@code "(PT0,PT1...)RT"}.
 882      * The string representation of a method type is a
 883      * parenthesis enclosed, comma separated list of type names,
 884      * followed immediately by the return type.
 885      * <p>
 886      * Each type is represented by its
 887      * {@link java.lang.Class#getSimpleName simple name}.
 888      */
 889     @Override
 890     public String toString() {
 891         StringJoiner sj = new StringJoiner(",", "(",
 892                 ")" + rtype.getSimpleName());
 893         for (int i = 0; i < ptypes.length; i++) {
 894             sj.add(ptypes[i].getSimpleName());
 895         }
 896         return sj.toString();
 897     }
 898 







 899     /** True if my parameter list is effectively identical to the given full list,
 900      *  after skipping the given number of my own initial parameters.
 901      *  In other words, after disregarding {@code skipPos} parameters,
 902      *  my remaining parameter list is no longer than the {@code fullList}, and
 903      *  is equal to the same-length initial sublist of {@code fullList}.
 904      */
 905     /*non-public*/
 906     boolean effectivelyIdenticalParameters(int skipPos, List<Class<?>> fullList) {
 907         int myLen = ptypes.length, fullLen = fullList.size();
 908         if (skipPos > myLen || myLen - skipPos > fullLen)
 909             return false;
 910         List<Class<?>> myList = Arrays.asList(ptypes);
 911         if (skipPos != 0) {
 912             myList = myList.subList(skipPos, myLen);
 913             myLen -= skipPos;
 914         }
 915         if (fullLen == myLen)
 916             return myList.equals(fullList);
 917         else
 918             return myList.equals(fullList.subList(0, myLen));

  23  * questions.
  24  */
  25 
  26 package java.lang.invoke;
  27 
  28 import java.lang.constant.ClassDesc;
  29 import java.lang.constant.Constable;
  30 import java.lang.constant.MethodTypeDesc;
  31 import java.lang.ref.Reference;
  32 import java.lang.ref.ReferenceQueue;
  33 import java.lang.ref.WeakReference;
  34 import java.util.Arrays;
  35 import java.util.Collections;
  36 import java.util.List;
  37 import java.util.NoSuchElementException;
  38 import java.util.Objects;
  39 import java.util.Optional;
  40 import java.util.StringJoiner;
  41 import java.util.concurrent.ConcurrentHashMap;
  42 import java.util.concurrent.ConcurrentMap;
  43 import java.util.stream.Collectors;
  44 import java.util.stream.Stream;
  45 
  46 import jdk.internal.vm.annotation.Stable;
  47 import sun.invoke.util.BytecodeDescriptor;
  48 import sun.invoke.util.VerifyType;
  49 import sun.invoke.util.Wrapper;
  50 import sun.security.util.SecurityConstants;
  51 
  52 import static java.lang.invoke.MethodHandleStatics.UNSAFE;
  53 import static java.lang.invoke.MethodHandleStatics.newIllegalArgumentException;
  54 import static java.lang.invoke.MethodType.fromDescriptor;
  55 
  56 /**
  57  * A method type represents the arguments and return type accepted and
  58  * returned by a method handle, or the arguments and return type passed
  59  * and expected  by a method handle caller.  Method types must be properly
  60  * matched between a method handle and all its callers,
  61  * and the JVM's operations enforce this matching at, specifically
  62  * during calls to {@link MethodHandle#invokeExact MethodHandle.invokeExact}
  63  * and {@link MethodHandle#invoke MethodHandle.invoke}, and during execution

 873     public int hashCode() {
 874         int hashCode = 31 + rtype.hashCode();
 875         for (Class<?> ptype : ptypes)
 876             hashCode = 31 * hashCode + ptype.hashCode();
 877         return hashCode;
 878     }
 879 
 880     /**
 881      * Returns a string representation of the method type,
 882      * of the form {@code "(PT0,PT1...)RT"}.
 883      * The string representation of a method type is a
 884      * parenthesis enclosed, comma separated list of type names,
 885      * followed immediately by the return type.
 886      * <p>
 887      * Each type is represented by its
 888      * {@link java.lang.Class#getSimpleName simple name}.
 889      */
 890     @Override
 891     public String toString() {
 892         StringJoiner sj = new StringJoiner(",", "(",
 893                 ")" + toSimpleName(rtype));
 894         for (int i = 0; i < ptypes.length; i++) {
 895             sj.add(toSimpleName(ptypes[i]));
 896         }
 897         return sj.toString();
 898     }
 899 
 900     static String toSimpleName(Class<?> c) {
 901         if (c.isPrimitiveClass() && c.isPrimaryType()) {
 902             return c.getSimpleName() + ".ref";
 903         } else {
 904             return c.getSimpleName();
 905         }
 906     }
 907     /** True if my parameter list is effectively identical to the given full list,
 908      *  after skipping the given number of my own initial parameters.
 909      *  In other words, after disregarding {@code skipPos} parameters,
 910      *  my remaining parameter list is no longer than the {@code fullList}, and
 911      *  is equal to the same-length initial sublist of {@code fullList}.
 912      */
 913     /*non-public*/
 914     boolean effectivelyIdenticalParameters(int skipPos, List<Class<?>> fullList) {
 915         int myLen = ptypes.length, fullLen = fullList.size();
 916         if (skipPos > myLen || myLen - skipPos > fullLen)
 917             return false;
 918         List<Class<?>> myList = Arrays.asList(ptypes);
 919         if (skipPos != 0) {
 920             myList = myList.subList(skipPos, myLen);
 921             myLen -= skipPos;
 922         }
 923         if (fullLen == myLen)
 924             return myList.equals(fullList);
 925         else
 926             return myList.equals(fullList.subList(0, myLen));
< prev index next >