jdk/src/share/classes/java/lang/invoke/ToGeneric.java
changeset 9646 5ebbe5ab084f
parent 8822 8145ab9f5f86
child 9731 d0f7a3e441c4
equal deleted inserted replaced
9645:dabb5e4edc4c 9646:5ebbe5ab084f
    94         if (primsAtEndOrder != null) {
    94         if (primsAtEndOrder != null) {
    95             // reordering is required; build on top of a simpler ToGeneric
    95             // reordering is required; build on top of a simpler ToGeneric
    96             ToGeneric va2 = ToGeneric.of(primsAtEnd);
    96             ToGeneric va2 = ToGeneric.of(primsAtEnd);
    97             this.adapter = va2.adapter;
    97             this.adapter = va2.adapter;
    98             if (true) throw new UnsupportedOperationException("NYI: primitive parameters must follow references; entryType = "+entryType);
    98             if (true) throw new UnsupportedOperationException("NYI: primitive parameters must follow references; entryType = "+entryType);
    99             this.entryPoint = MethodHandleImpl.convertArguments(
    99             this.entryPoint = MethodHandleImpl.permuteArguments(
   100                     va2.entryPoint, primsAtEnd, entryType, primsAtEndOrder);
   100                     va2.entryPoint, primsAtEnd, entryType, primsAtEndOrder);
   101             // example: for entryType of (int,Object,Object), the reordered
   101             // example: for entryType of (int,Object,Object), the reordered
   102             // type is (Object,Object,int) and the order is {1,2,0},
   102             // type is (Object,Object,int) and the order is {1,2,0},
   103             // and putPAE is (mh,int0,obj1,obj2) => mh.invokeExact(obj1,obj2,int0)
   103             // and putPAE is (mh,int0,obj1,obj2) => mh.invokeExact(obj1,obj2,int0)
   104             return;
   104             return;
   126                     if (midType.parameterType(i) != eptWithInts.parameterType(i)) {
   126                     if (midType.parameterType(i) != eptWithInts.parameterType(i)) {
   127                         assert(midType.parameterType(i) == long.class);
   127                         assert(midType.parameterType(i) == long.class);
   128                         assert(eptWithInts.parameterType(i) == int.class);
   128                         assert(eptWithInts.parameterType(i) == int.class);
   129                         MethodType nextType = midType.changeParameterType(i, int.class);
   129                         MethodType nextType = midType.changeParameterType(i, int.class);
   130                         rawEntryPoint = MethodHandleImpl.convertArguments(
   130                         rawEntryPoint = MethodHandleImpl.convertArguments(
   131                                 rawEntryPoint, nextType, midType, null);
   131                                 rawEntryPoint, nextType, midType, 0);
   132                         midType = nextType;
   132                         midType = nextType;
   133                     }
   133                     }
   134                 }
   134                 }
   135                 assert(midType == eptWithInts);
   135                 assert(midType == eptWithInts);
   136             } else {
   136             } else {
   148                     +" from "+rawEntryPoint.type().dropParameterTypes(0, 1));
   148                     +" from "+rawEntryPoint.type().dropParameterTypes(0, 1));
   149         this.returnConversion = computeReturnConversion(entryType, rawEntryTypeInit, false);
   149         this.returnConversion = computeReturnConversion(entryType, rawEntryTypeInit, false);
   150         this.rawEntryType = rawEntryTypeInit;
   150         this.rawEntryType = rawEntryTypeInit;
   151         this.adapter = ad;
   151         this.adapter = ad;
   152         this.invoker = makeRawArgumentFilter(invoker0, rawEntryTypeInit, entryType);
   152         this.invoker = makeRawArgumentFilter(invoker0, rawEntryTypeInit, entryType);
       
   153     }
       
   154 
       
   155     static {
       
   156         assert(MethodHandleNatives.workaroundWithoutRicochetFrames());  // this class is deprecated
   153     }
   157     }
   154 
   158 
   155     /** A generic argument list will be created by a call of type 'raw'.
   159     /** A generic argument list will be created by a call of type 'raw'.
   156      *  The values need to be reboxed for to match 'cooked'.
   160      *  The values need to be reboxed for to match 'cooked'.
   157      *  Do this on the fly.
   161      *  Do this on the fly.
   169                 filteredInvoker =
   173                 filteredInvoker =
   170                         AdapterMethodHandle.makeCheckCast(
   174                         AdapterMethodHandle.makeCheckCast(
   171                             invoker.type().generic(), invoker, 0, MethodHandle.class);
   175                             invoker.type().generic(), invoker, 0, MethodHandle.class);
   172                 if (filteredInvoker == null)  throw new UnsupportedOperationException("NYI");
   176                 if (filteredInvoker == null)  throw new UnsupportedOperationException("NYI");
   173             }
   177             }
   174             MethodHandle reboxer = ValueConversions.rebox(dst, false);
   178             MethodHandle reboxer = ValueConversions.rebox(dst);
   175             filteredInvoker = FilterGeneric.makeArgumentFilter(1+i, reboxer, filteredInvoker);
   179             filteredInvoker = FilterGeneric.makeArgumentFilter(1+i, reboxer, filteredInvoker);
   176             if (filteredInvoker == null)  throw new InternalError();
   180             if (filteredInvoker == null)  throw new InternalError();
   177         }
   181         }
   178         if (filteredInvoker == null)  return invoker;
   182         if (filteredInvoker == null)  return invoker;
   179         return AdapterMethodHandle.makeRetypeOnly(invoker.type(), filteredInvoker);
   183         return AdapterMethodHandle.makeRetypeOnly(invoker.type(), filteredInvoker);
   197         if (mustCast || !tret.isPrimitive()) {
   201         if (mustCast || !tret.isPrimitive()) {
   198             assert(!tret.isPrimitive());
   202             assert(!tret.isPrimitive());
   199             assert(!rret.isPrimitive());
   203             assert(!rret.isPrimitive());
   200             if (rret == Object.class && !mustCast)
   204             if (rret == Object.class && !mustCast)
   201                 return null;
   205                 return null;
   202             return ValueConversions.cast(tret, false);
   206             return ValueConversions.cast(tret);
   203         } else if (tret == rret) {
   207         } else if (tret == rret) {
   204             return ValueConversions.unbox(tret, false);
   208             return ValueConversions.unbox(tret);
   205         } else {
   209         } else {
   206             assert(rret.isPrimitive());
   210             assert(rret.isPrimitive());
   207             assert(tret == double.class ? rret == long.class : rret == int.class);
   211             assert(tret == double.class ? rret == long.class : rret == int.class);
   208             return ValueConversions.unboxRaw(tret, false);
   212             return ValueConversions.unboxRaw(tret);
   209         }
   213         }
   210     }
   214     }
   211 
   215 
   212     Adapter makeInstance(MethodType type, MethodHandle genericTarget) {
   216     Adapter makeInstance(MethodType type, MethodHandle genericTarget) {
   213         genericTarget.getClass();  // check for NPE
   217         genericTarget.getClass();  // check for NPE
   309         }
   313         }
   310         return null;
   314         return null;
   311     }
   315     }
   312 
   316 
   313     static Adapter buildAdapterFromBytecodes(MethodType entryPointType) {
   317     static Adapter buildAdapterFromBytecodes(MethodType entryPointType) {
   314         throw new UnsupportedOperationException("NYI");
   318         throw new UnsupportedOperationException("NYI: "+entryPointType);
   315     }
   319     }
   316 
   320 
   317     /**
   321     /**
   318      * The invoke method takes some particular but unconstrained spread
   322      * The invoke method takes some particular but unconstrained spread
   319      * of raw argument types, and returns a raw return type (in L/I/J/F/D).
   323      * of raw argument types, and returns a raw return type (in L/I/J/F/D).