jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java
changeset 26475 acf0c98309d3
parent 26474 655d08549e43
child 26476 2b814465aaa3
equal deleted inserted replaced
26474:655d08549e43 26475:acf0c98309d3
   299         return (T) x;
   299         return (T) x;
   300     }
   300     }
   301 
   301 
   302     private static ClassCastException newClassCastException(Class<?> t, Object obj) {
   302     private static ClassCastException newClassCastException(Class<?> t, Object obj) {
   303         return new ClassCastException("Cannot cast " + obj.getClass().getName() + " to " + t.getName());
   303         return new ClassCastException("Cannot cast " + obj.getClass().getName() + " to " + t.getName());
   304     }
       
   305 
       
   306     static MethodHandle makeReferenceIdentity(Class<?> refType) {
       
   307         MethodType lambdaType = MethodType.genericMethodType(1).invokerType();
       
   308         Name[] names = arguments(1, lambdaType);
       
   309         names[names.length - 1] = new Name(ValueConversions.identity(), names[1]);
       
   310         LambdaForm form = new LambdaForm("identity", lambdaType.parameterCount(), names);
       
   311         return SimpleMethodHandle.make(MethodType.methodType(refType, refType), form);
       
   312     }
   304     }
   313 
   305 
   314     static Object[] computeValueConversions(MethodType srcType, MethodType dstType,
   306     static Object[] computeValueConversions(MethodType srcType, MethodType dstType,
   315                                             boolean strict, boolean monobox) {
   307                                             boolean strict, boolean monobox) {
   316         final int INARG_COUNT = srcType.parameterCount();
   308         final int INARG_COUNT = srcType.parameterCount();
  1059         SELECT_ALTERNATIVE,
  1051         SELECT_ALTERNATIVE,
  1060         GUARD_WITH_CATCH,
  1052         GUARD_WITH_CATCH,
  1061         NEW_ARRAY,
  1053         NEW_ARRAY,
  1062         ARRAY_LOAD,
  1054         ARRAY_LOAD,
  1063         ARRAY_STORE,
  1055         ARRAY_STORE,
       
  1056         IDENTITY,
  1064         NONE // no intrinsic associated
  1057         NONE // no intrinsic associated
  1065     }
  1058     }
  1066 
  1059 
  1067     /** Mark arbitrary method handle as intrinsic.
  1060     /** Mark arbitrary method handle as intrinsic.
  1068      * InvokerBytecodeGenerator uses this info to produce more efficient bytecode shape. */
  1061      * InvokerBytecodeGenerator uses this info to produce more efficient bytecode shape. */
  1095 
  1088 
  1096         @Override
  1089         @Override
  1097         String internalProperties() {
  1090         String internalProperties() {
  1098             return super.internalProperties() +
  1091             return super.internalProperties() +
  1099                     "\n& Intrinsic="+intrinsicName;
  1092                     "\n& Intrinsic="+intrinsicName;
       
  1093         }
       
  1094 
       
  1095         @Override
       
  1096         public MethodHandle asCollector(Class<?> arrayType, int arrayLength) {
       
  1097             if (intrinsicName == Intrinsic.IDENTITY) {
       
  1098                 MethodType resultType = type().asCollectorType(arrayType, arrayLength);
       
  1099                 MethodHandle newArray = MethodHandleImpl.varargsArray(arrayType, arrayLength);
       
  1100                 return newArray.asType(resultType);
       
  1101             }
       
  1102             return super.asCollector(arrayType, arrayLength);
  1100         }
  1103         }
  1101     }
  1104     }
  1102 
  1105 
  1103     static MethodHandle makeIntrinsic(MethodHandle target, Intrinsic intrinsicName) {
  1106     static MethodHandle makeIntrinsic(MethodHandle target, Intrinsic intrinsicName) {
  1104         if (intrinsicName == target.intrinsicName())
  1107         if (intrinsicName == target.intrinsicName())