jdk/src/share/classes/sun/dyn/MethodTypeImpl.java
changeset 5722 4ada807383c8
parent 4537 7c3c7f8d5195
child 5725 16c1792b2ee6
equal deleted inserted replaced
5371:ff9031a745d9 5722:4ada807383c8
    86             throw new InternalError();  // just once
    86             throw new InternalError();  // just once
    87         METHOD_TYPE_FRIEND = am;
    87         METHOD_TYPE_FRIEND = am;
    88     }
    88     }
    89     static private MethodTypeFriend METHOD_TYPE_FRIEND;
    89     static private MethodTypeFriend METHOD_TYPE_FRIEND;
    90 
    90 
       
    91     static MethodType makeImpl(Access token, Class<?> rtype, Class<?>[] ptypes, boolean trusted) {
       
    92         Access.check(token);
       
    93         return METHOD_TYPE_FRIEND.makeImpl(rtype, ptypes, trusted);
       
    94     }
       
    95 
    91     protected MethodTypeImpl(MethodType erasedType) {
    96     protected MethodTypeImpl(MethodType erasedType) {
    92         this.erasedType = erasedType;
    97         this.erasedType = erasedType;
    93 
    98 
    94         Class<?>[] ptypes = METHOD_TYPE_FRIEND.ptypes(erasedType);
    99         Class<?>[] ptypes = METHOD_TYPE_FRIEND.ptypes(erasedType);
    95         int ptypeCount = ptypes.length;
   100         int ptypeCount = ptypes.length;
   231         int lac = longPrimitiveParameterCount();
   236         int lac = longPrimitiveParameterCount();
   232         if (pac == argc && (lac == 0 || lac == argc))
   237         if (pac == argc && (lac == 0 || lac == argc))
   233             return primsAtEnd = t;
   238             return primsAtEnd = t;
   234 
   239 
   235         // known to have a mix of 2 or 3 of ref, int, long
   240         // known to have a mix of 2 or 3 of ref, int, long
   236         return primsAtEnd = reorderParameters(t, primsAtEndOrder(t), null);
   241         int[] reorder = primsAtEndOrder(t);
   237 
   242         ct = reorderParameters(t, reorder, null);
       
   243         //System.out.println("t="+t+" / reorder="+java.util.Arrays.toString(reorder)+" => "+ct);
       
   244         return primsAtEnd = ct;
   238     }
   245     }
   239 
   246 
   240     /** Compute a new ordering of parameters so that all references
   247     /** Compute a new ordering of parameters so that all references
   241      *  are before all ints or longs, and all ints are before all longs.
   248      *  are before all ints or longs, and all ints are before all longs.
   242      *  For this ordering, doubles count as longs, and all other primitive
   249      *  For this ordering, doubles count as longs, and all other primitive
   271             int ord;
   278             int ord;
   272             if (!pt.isPrimitive())             ord = rfill++;
   279             if (!pt.isPrimitive())             ord = rfill++;
   273             else if (!hasTwoArgSlots(pt))      ord = ifill++;
   280             else if (!hasTwoArgSlots(pt))      ord = ifill++;
   274             else                               ord = lfill++;
   281             else                               ord = lfill++;
   275             if (ord != i)  changed = true;
   282             if (ord != i)  changed = true;
   276             paramOrder[i] = ord;
   283             assert(paramOrder[ord] == 0);
       
   284             paramOrder[ord] = i;
   277         }
   285         }
   278         assert(rfill == argc - pac && ifill == argc - lac && lfill == argc);
   286         assert(rfill == argc - pac && ifill == argc - lac && lfill == argc);
   279         if (!changed) {
   287         if (!changed) {
   280             form.primsAtEnd = form.erasedType;
   288             form.primsAtEnd = form.erasedType;
   281             return null;
   289             return null;
   290      */
   298      */
   291     public static MethodType reorderParameters(MethodType mt, int[] newParamOrder, Class<?>[] moreParams) {
   299     public static MethodType reorderParameters(MethodType mt, int[] newParamOrder, Class<?>[] moreParams) {
   292         if (newParamOrder == null)  return mt;  // no-op reordering
   300         if (newParamOrder == null)  return mt;  // no-op reordering
   293         Class<?>[] ptypes = METHOD_TYPE_FRIEND.ptypes(mt);
   301         Class<?>[] ptypes = METHOD_TYPE_FRIEND.ptypes(mt);
   294         Class<?>[] ntypes = new Class<?>[newParamOrder.length];
   302         Class<?>[] ntypes = new Class<?>[newParamOrder.length];
   295         int ordMax = ptypes.length + (moreParams == null ? 0 : moreParams.length);
   303         int maxParam = ptypes.length + (moreParams == null ? 0 : moreParams.length);
   296         boolean changed = (ntypes.length != ptypes.length);
   304         boolean changed = (ntypes.length != ptypes.length);
   297         for (int i = 0; i < newParamOrder.length; i++) {
   305         for (int i = 0; i < newParamOrder.length; i++) {
   298             int ord = newParamOrder[i];
   306             int param = newParamOrder[i];
   299             if (ord != i)  changed = true;
   307             if (param != i)  changed = true;
   300             Class<?> nt;
   308             Class<?> nt;
   301             if (ord < ptypes.length)   nt = ptypes[ord];
   309             if (param < ptypes.length)   nt = ptypes[param];
   302             else if (ord == ordMax)    nt = mt.returnType();
   310             else if (param == maxParam)  nt = mt.returnType();
   303             else                       nt = moreParams[ord - ptypes.length];
   311             else                         nt = moreParams[param - ptypes.length];
   304             ntypes[i] = nt;
   312             ntypes[i] = nt;
   305         }
   313         }
   306         if (!changed)  return mt;
   314         if (!changed)  return mt;
   307         return METHOD_TYPE_FRIEND.makeImpl(mt.returnType(), ntypes, true);
   315         return METHOD_TYPE_FRIEND.makeImpl(mt.returnType(), ntypes, true);
   308     }
   316     }