jdk/src/share/classes/java/lang/invoke/MethodTypeForm.java
author sherman
Tue, 30 Aug 2011 11:53:11 -0700
changeset 10419 12c063b39232
parent 10082 761643c9bebd
child 13423 17843fff200d
permissions -rw-r--r--
7084245: Update usages of InternalError to use exception chaining Summary: to use new InternalError constructor with cause chainning Reviewed-by: alanb, ksrini, xuelei, neugens Contributed-by: sebastian.sickelmann@gmx.de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     1
/*
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
     2
 * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     4
 *
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2707
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2707
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    10
 *
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    15
 * accompanied this code).
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    16
 *
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2707
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2707
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2707
diff changeset
    23
 * questions.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    24
 */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    25
8822
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
    26
package java.lang.invoke;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    27
8822
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
    28
import sun.invoke.util.Wrapper;
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
    29
import static java.lang.invoke.MethodHandleStatics.*;
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    30
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    31
/**
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    32
 * Shared information for a group of method types, which differ
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    33
 * only by reference types, and therefore share a common erasure
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    34
 * and wrapping.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    35
 * <p>
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    36
 * For an empirical discussion of the structure of method types,
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    37
 * see <a href="http://groups.google.com/group/jvm-languages/browse_thread/thread/ac9308ae74da9b7e/">
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    38
 * the thread "Avoiding Boxing" on jvm-languages</a>.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    39
 * There are approximately 2000 distinct erased method types in the JDK.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    40
 * There are a little over 10 times that number of unerased types.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    41
 * No more than half of these are likely to be loaded at once.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    42
 * @author John Rose
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    43
 */
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    44
class MethodTypeForm {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    45
    final int[] argToSlotTable, slotToArgTable;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    46
    final long argCounts;               // packed slot & value counts
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    47
    final long primCounts;              // packed prim & double counts
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    48
    final int vmslots;                  // total number of parameter slots
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
    49
    private Object vmlayout;            // vm-specific information for calls
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    50
    final MethodType erasedType;        // the canonical erasure
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    51
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    52
    /*lazy*/ MethodType primsAsBoxes;   // replace prims by wrappers
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    53
    /*lazy*/ MethodType primArgsAsBoxes; // wrap args only; make raw return
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    54
    /*lazy*/ MethodType primsAsInts;    // replace prims by int/long
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    55
    /*lazy*/ MethodType primsAsLongs;   // replace prims by long
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    56
    /*lazy*/ MethodType primsAtEnd;     // reorder primitives to the end
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    57
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    58
    // Cached adapter information:
9645
dabb5e4edc4c 7034977: JSR 292 MethodHandle.invokeGeneric should be renamed MethodHandle.invoke
jrose
parents: 8822
diff changeset
    59
    /*lazy*/ MethodHandle genericInvoker; // hook for inexact invoke
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    60
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    61
    public MethodType erasedType() {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    62
        return erasedType;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    63
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    64
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    65
    protected MethodTypeForm(MethodType erasedType) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    66
        this.erasedType = erasedType;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    67
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    68
        Class<?>[] ptypes = erasedType.ptypes();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    69
        int ptypeCount = ptypes.length;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    70
        int pslotCount = ptypeCount;            // temp. estimate
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    71
        int rtypeCount = 1;                     // temp. estimate
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    72
        int rslotCount = 1;                     // temp. estimate
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    73
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    74
        int[] argToSlotTab = null, slotToArgTab = null;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    75
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    76
        // Walk the argument types, looking for primitives.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    77
        int pac = 0, lac = 0, prc = 0, lrc = 0;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    78
        Class<?> epts[] = ptypes;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    79
        for (int i = 0; i < epts.length; i++) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    80
            Class<?> pt = epts[i];
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    81
            if (pt != Object.class) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    82
                assert(pt.isPrimitive());
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    83
                ++pac;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    84
                if (hasTwoArgSlots(pt))  ++lac;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    85
            }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    86
        }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    87
        pslotCount += lac;                  // #slots = #args + #longs
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    88
        Class<?> rt = erasedType.returnType();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    89
        if (rt != Object.class) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    90
            ++prc;          // even void.class counts as a prim here
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    91
            if (hasTwoArgSlots(rt))  ++lrc;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    92
            // adjust #slots, #args
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    93
            if (rt == void.class)
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    94
                rtypeCount = rslotCount = 0;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    95
            else
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    96
                rslotCount += lrc;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    97
        }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    98
        if (lac != 0) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
    99
            int slot = ptypeCount + lac;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   100
            slotToArgTab = new int[slot+1];
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   101
            argToSlotTab = new int[1+ptypeCount];
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   102
            argToSlotTab[0] = slot;  // argument "-1" is past end of slots
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   103
            for (int i = 0; i < epts.length; i++) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   104
                Class<?> pt = epts[i];
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   105
                if (hasTwoArgSlots(pt))  --slot;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   106
                --slot;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   107
                slotToArgTab[slot] = i+1; // "+1" see argSlotToParameter note
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   108
                argToSlotTab[1+i]  = slot;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   109
            }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   110
            assert(slot == 0);  // filled the table
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   111
        }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   112
        this.primCounts = pack(lrc, prc, lac, pac);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   113
        this.argCounts = pack(rslotCount, rtypeCount, pslotCount, ptypeCount);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   114
        if (slotToArgTab == null) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   115
            int slot = ptypeCount; // first arg is deepest in stack
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   116
            slotToArgTab = new int[slot+1];
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   117
            argToSlotTab = new int[1+ptypeCount];
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   118
            argToSlotTab[0] = slot;  // argument "-1" is past end of slots
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   119
            for (int i = 0; i < ptypeCount; i++) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   120
                --slot;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   121
                slotToArgTab[slot] = i+1; // "+1" see argSlotToParameter note
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   122
                argToSlotTab[1+i]  = slot;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   123
            }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   124
        }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   125
        this.argToSlotTable = argToSlotTab;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   126
        this.slotToArgTable = slotToArgTab;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   127
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   128
        if (pslotCount >= 256)  throw newIllegalArgumentException("too many arguments");
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   129
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   130
        // send a few bits down to the JVM:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   131
        this.vmslots = parameterSlotCount();
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   132
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   133
        // short circuit some no-op canonicalizations:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   134
        if (!hasPrimitives()) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   135
            primsAsBoxes = erasedType;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   136
            primArgsAsBoxes = erasedType;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   137
            primsAsInts  = erasedType;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   138
            primsAsLongs = erasedType;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   139
            primsAtEnd   = erasedType;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   140
        }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   141
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   142
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   143
    /** Turn all primitive types to corresponding wrapper types.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   144
     */
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   145
    public MethodType primsAsBoxes() {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   146
        MethodType ct = primsAsBoxes;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   147
        if (ct != null)  return ct;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   148
        MethodType t = erasedType;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   149
        ct = canonicalize(erasedType, WRAP, WRAP);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   150
        if (ct == null)  ct = t;  // no prims to box
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   151
        return primsAsBoxes = ct;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   152
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   153
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   154
    /** Turn all primitive argument types to corresponding wrapper types.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   155
     *  Subword and void return types are promoted to int.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   156
     */
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   157
    public MethodType primArgsAsBoxes() {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   158
        MethodType ct = primArgsAsBoxes;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   159
        if (ct != null)  return ct;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   160
        MethodType t = erasedType;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   161
        ct = canonicalize(erasedType, RAW_RETURN, WRAP);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   162
        if (ct == null)  ct = t;  // no prims to box
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   163
        return primArgsAsBoxes = ct;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   164
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   165
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   166
    /** Turn all primitive types to either int or long.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   167
     *  Floating point return types are not changed, because
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   168
     *  they may require special calling sequences.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   169
     *  A void return value is turned to int.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   170
     */
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   171
    public MethodType primsAsInts() {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   172
        MethodType ct = primsAsInts;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   173
        if (ct != null)  return ct;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   174
        MethodType t = erasedType;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   175
        ct = canonicalize(t, RAW_RETURN, INTS);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   176
        if (ct == null)  ct = t;  // no prims to int-ify
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   177
        return primsAsInts = ct;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   178
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   179
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   180
    /** Turn all primitive types to either int or long.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   181
     *  Floating point return types are not changed, because
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   182
     *  they may require special calling sequences.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   183
     *  A void return value is turned to int.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   184
     */
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   185
    public MethodType primsAsLongs() {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   186
        MethodType ct = primsAsLongs;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   187
        if (ct != null)  return ct;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   188
        MethodType t = erasedType;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   189
        ct = canonicalize(t, RAW_RETURN, LONGS);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   190
        if (ct == null)  ct = t;  // no prims to int-ify
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   191
        return primsAsLongs = ct;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   192
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   193
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   194
    /** Stably sort parameters into 3 buckets: ref, int, long. */
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   195
    public MethodType primsAtEnd() {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   196
        MethodType ct = primsAtEnd;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   197
        if (ct != null)  return ct;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   198
        MethodType t = erasedType;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   199
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   200
        int pac = primitiveParameterCount();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   201
        if (pac == 0)
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   202
            return primsAtEnd = t;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   203
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   204
        int argc = parameterCount();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   205
        int lac = longPrimitiveParameterCount();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   206
        if (pac == argc && (lac == 0 || lac == argc))
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   207
            return primsAtEnd = t;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   208
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   209
        // known to have a mix of 2 or 3 of ref, int, long
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   210
        int[] reorder = primsAtEndOrder(t);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   211
        ct = reorderParameters(t, reorder, null);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   212
        //System.out.println("t="+t+" / reorder="+java.util.Arrays.toString(reorder)+" => "+ct);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   213
        return primsAtEnd = ct;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   214
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   215
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   216
    /** Compute a new ordering of parameters so that all references
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   217
     *  are before all ints or longs, and all ints are before all longs.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   218
     *  For this ordering, doubles count as longs, and all other primitive
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   219
     *  values count as ints.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   220
     *  As a special case, if the parameters are already in the specified
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   221
     *  order, this method returns a null reference, rather than an array
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   222
     *  specifying a null permutation.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   223
     *  <p>
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   224
     *  For example, the type {@code (int,boolean,int,Object,String)void}
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   225
     *  produces the order {@code {3,4,0,1,2}}, the type
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   226
     *  {@code (long,int,String)void} produces {@code {2,1,2}}, and
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   227
     *  the type {@code (Object,int)Object} produces {@code null}.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   228
     */
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   229
    public static int[] primsAtEndOrder(MethodType mt) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   230
        MethodTypeForm form = mt.form();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   231
        if (form.primsAtEnd == form.erasedType)
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   232
            // quick check shows no reordering is necessary
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   233
            return null;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   234
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   235
        int argc = form.parameterCount();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   236
        int[] paramOrder = new int[argc];
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   237
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   238
        // 3-way bucket sort:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   239
        int pac = form.primitiveParameterCount();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   240
        int lac = form.longPrimitiveParameterCount();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   241
        int rfill = 0, ifill = argc - pac, lfill = argc - lac;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   242
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   243
        Class<?>[] ptypes = mt.ptypes();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   244
        boolean changed = false;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   245
        for (int i = 0; i < ptypes.length; i++) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   246
            Class<?> pt = ptypes[i];
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   247
            int ord;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   248
            if (!pt.isPrimitive())             ord = rfill++;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   249
            else if (!hasTwoArgSlots(pt))      ord = ifill++;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   250
            else                               ord = lfill++;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   251
            if (ord != i)  changed = true;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   252
            assert(paramOrder[ord] == 0);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   253
            paramOrder[ord] = i;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   254
        }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   255
        assert(rfill == argc - pac && ifill == argc - lac && lfill == argc);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   256
        if (!changed) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   257
            form.primsAtEnd = form.erasedType;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   258
            return null;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   259
        }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   260
        return paramOrder;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   261
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   262
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   263
    /** Put the existing parameters of mt into a new order, given by newParamOrder.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   264
     *  The third argument is logically appended to mt.parameterArray,
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   265
     *  so that elements of newParamOrder can index either pre-existing or
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   266
     *  new parameter types.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   267
     */
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   268
    public static MethodType reorderParameters(MethodType mt, int[] newParamOrder, Class<?>[] moreParams) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   269
        if (newParamOrder == null)  return mt;  // no-op reordering
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   270
        Class<?>[] ptypes = mt.ptypes();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   271
        Class<?>[] ntypes = new Class<?>[newParamOrder.length];
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   272
        int maxParam = ptypes.length + (moreParams == null ? 0 : moreParams.length);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   273
        boolean changed = (ntypes.length != ptypes.length);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   274
        for (int i = 0; i < newParamOrder.length; i++) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   275
            int param = newParamOrder[i];
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   276
            if (param != i)  changed = true;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   277
            Class<?> nt;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   278
            if (param < ptypes.length)   nt = ptypes[param];
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   279
            else if (param == maxParam)  nt = mt.returnType();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   280
            else                         nt = moreParams[param - ptypes.length];
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   281
            ntypes[i] = nt;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   282
        }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   283
        if (!changed)  return mt;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   284
        return MethodType.makeImpl(mt.returnType(), ntypes, true);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   285
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   286
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   287
    private static boolean hasTwoArgSlots(Class<?> type) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   288
        return type == long.class || type == double.class;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   289
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   290
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   291
    private static long pack(int a, int b, int c, int d) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   292
        assert(((a|b|c|d) & ~0xFFFF) == 0);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   293
        long hw = ((a << 16) | b), lw = ((c << 16) | d);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   294
        return (hw << 32) | lw;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   295
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   296
    private static char unpack(long packed, int word) { // word==0 => return a, ==3 => return d
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   297
        assert(word <= 3);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   298
        return (char)(packed >> ((3-word) * 16));
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   299
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   300
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   301
    public int parameterCount() {                      // # outgoing values
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   302
        return unpack(argCounts, 3);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   303
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   304
    public int parameterSlotCount() {                  // # outgoing interpreter slots
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   305
        return unpack(argCounts, 2);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   306
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   307
    public int returnCount() {                         // = 0 (V), or 1
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   308
        return unpack(argCounts, 1);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   309
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   310
    public int returnSlotCount() {                     // = 0 (V), 2 (J/D), or 1
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   311
        return unpack(argCounts, 0);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   312
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   313
    public int primitiveParameterCount() {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   314
        return unpack(primCounts, 3);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   315
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   316
    public int longPrimitiveParameterCount() {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   317
        return unpack(primCounts, 2);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   318
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   319
    public int primitiveReturnCount() {                // = 0 (obj), or 1
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   320
        return unpack(primCounts, 1);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   321
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   322
    public int longPrimitiveReturnCount() {            // = 1 (J/D), or 0
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   323
        return unpack(primCounts, 0);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   324
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   325
    public boolean hasPrimitives() {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   326
        return primCounts != 0;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   327
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   328
//    public boolean hasNonVoidPrimitives() {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   329
//        if (primCounts == 0)  return false;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   330
//        if (primitiveParameterCount() != 0)  return true;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   331
//        return (primitiveReturnCount() != 0 && returnCount() != 0);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   332
//    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   333
    public boolean hasLongPrimitives() {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   334
        return (longPrimitiveParameterCount() | longPrimitiveReturnCount()) != 0;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   335
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   336
    public int parameterToArgSlot(int i) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   337
        return argToSlotTable[1+i];
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   338
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   339
    public int argSlotToParameter(int argSlot) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   340
        // Note:  Empty slots are represented by zero in this table.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   341
        // Valid arguments slots contain incremented entries, so as to be non-zero.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   342
        // We return -1 the caller to mean an empty slot.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   343
        return slotToArgTable[argSlot] - 1;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   344
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   345
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   346
    static MethodTypeForm findForm(MethodType mt) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   347
        MethodType erased = canonicalize(mt, ERASE, ERASE);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   348
        if (erased == null) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   349
            // It is already erased.  Make a new MethodTypeForm.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   350
            return new MethodTypeForm(mt);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   351
        } else {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   352
            // Share the MethodTypeForm with the erased version.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   353
            return erased.form();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   354
        }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   355
    }
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   356
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   357
    /** Codes for {@link #canonicalize(java.lang.Class, int)}.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   358
     * ERASE means change every reference to {@code Object}.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   359
     * WRAP means convert primitives (including {@code void} to their
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   360
     * corresponding wrapper types.  UNWRAP means the reverse of WRAP.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   361
     * INTS means convert all non-void primitive types to int or long,
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   362
     * according to size.  LONGS means convert all non-void primitives
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   363
     * to long, regardless of size.  RAW_RETURN means convert a type
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   364
     * (assumed to be a return type) to int if it is smaller than an int,
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   365
     * or if it is void.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   366
     */
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   367
    public static final int NO_CHANGE = 0, ERASE = 1, WRAP = 2, UNWRAP = 3, INTS = 4, LONGS = 5, RAW_RETURN = 6;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   368
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   369
    /** Canonicalize the types in the given method type.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   370
     * If any types change, intern the new type, and return it.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   371
     * Otherwise return null.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   372
     */
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   373
    public static MethodType canonicalize(MethodType mt, int howRet, int howArgs) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   374
        Class<?>[] ptypes = mt.ptypes();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   375
        Class<?>[] ptc = MethodTypeForm.canonicalizes(ptypes, howArgs);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   376
        Class<?> rtype = mt.returnType();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   377
        Class<?> rtc = MethodTypeForm.canonicalize(rtype, howRet);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   378
        if (ptc == null && rtc == null) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   379
            // It is already canonical.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   380
            return null;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   381
        }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   382
        // Find the erased version of the method type:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   383
        if (rtc == null)  rtc = rtype;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   384
        if (ptc == null)  ptc = ptypes;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   385
        return MethodType.makeImpl(rtc, ptc, true);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   386
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   387
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   388
    /** Canonicalize the given return or param type.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   389
     *  Return null if the type is already canonicalized.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   390
     */
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   391
    static Class<?> canonicalize(Class<?> t, int how) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   392
        Class<?> ct;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   393
        if (t == Object.class) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   394
            // no change, ever
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   395
        } else if (!t.isPrimitive()) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   396
            switch (how) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   397
                case UNWRAP:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   398
                    ct = Wrapper.asPrimitiveType(t);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   399
                    if (ct != t)  return ct;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   400
                    break;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   401
                case RAW_RETURN:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   402
                case ERASE:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   403
                    return Object.class;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   404
            }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   405
        } else if (t == void.class) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   406
            // no change, usually
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   407
            switch (how) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   408
                case RAW_RETURN:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   409
                    return int.class;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   410
                case WRAP:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   411
                    return Void.class;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   412
            }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   413
        } else {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   414
            // non-void primitive
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   415
            switch (how) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   416
                case WRAP:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   417
                    return Wrapper.asWrapperType(t);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   418
                case INTS:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   419
                    if (t == int.class || t == long.class)
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   420
                        return null;  // no change
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   421
                    if (t == double.class)
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   422
                        return long.class;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   423
                    return int.class;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   424
                case LONGS:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   425
                    if (t == long.class)
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   426
                        return null;  // no change
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   427
                    return long.class;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   428
                case RAW_RETURN:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   429
                    if (t == int.class || t == long.class ||
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   430
                        t == float.class || t == double.class)
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   431
                        return null;  // no change
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   432
                    // everything else returns as an int
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   433
                    return int.class;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   434
            }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   435
        }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   436
        // no change; return null to signify
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   437
        return null;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   438
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   439
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   440
    /** Canonicalize each param type in the given array.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   441
     *  Return null if all types are already canonicalized.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   442
     */
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   443
    static Class<?>[] canonicalizes(Class<?>[] ts, int how) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   444
        Class<?>[] cs = null;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   445
        for (int imax = ts.length, i = 0; i < imax; i++) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   446
            Class<?> c = canonicalize(ts[i], how);
9731
d0f7a3e441c4 7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents: 9646
diff changeset
   447
            if (c == void.class)
d0f7a3e441c4 7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents: 9646
diff changeset
   448
                c = null;  // a Void parameter was unwrapped to void; ignore
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   449
            if (c != null) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   450
                if (cs == null)
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   451
                    cs = ts.clone();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   452
                cs[i] = c;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   453
            }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   454
        }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   455
        return cs;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   456
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   457
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   458
    /*non-public*/ void notifyGenericMethodType() {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   459
        if (genericInvoker != null)  return;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   460
        try {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   461
            // Trigger adapter creation.
9645
dabb5e4edc4c 7034977: JSR 292 MethodHandle.invokeGeneric should be renamed MethodHandle.invoke
jrose
parents: 8822
diff changeset
   462
            genericInvoker = InvokeGeneric.generalInvokerOf(erasedType);
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   463
        } catch (Exception ex) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 10082
diff changeset
   464
            Error err = new InternalError("Exception while resolving inexact invoke", ex);
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   465
            err.initCause(ex);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   466
            throw err;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   467
        }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   468
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   469
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   470
    @Override
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   471
    public String toString() {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   472
        return "Form"+erasedType;
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   473
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 5506
diff changeset
   474
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   475
}