jdk/src/share/classes/java/dyn/MethodType.java
author jrose
Fri, 11 Feb 2011 01:26:28 -0800
changeset 8346 3b891698c4ec
parent 7668 d4a77089c587
child 8348 3b2ac15dfc16
permissions -rw-r--r--
7012650: implement JSR 292 EG adjustments through January 2010 Summary: misc. EG changes and polishes (excluding 7013417) Reviewed-by: twisti
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
/*
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
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: 4537
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: 4537
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: 4537
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
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
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    26
package java.dyn;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    27
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    28
import java.util.Arrays;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    29
import java.util.Collections;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    30
import java.util.HashMap;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    31
import java.util.List;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    32
import sun.dyn.Access;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    33
import sun.dyn.Invokers;
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
    34
import sun.dyn.MethodHandleImpl;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    35
import sun.dyn.MethodTypeImpl;
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
    36
import sun.dyn.util.BytecodeDescriptor;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    37
import static sun.dyn.MemberName.newIllegalArgumentException;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    38
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    39
/**
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    40
 * A method type represents the arguments and return type accepted and
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    41
 * returned by a method handle, or the arguments and return type passed
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    42
 * and expected  by a method handle caller.  Method types must be properly
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    43
 * matched between a method handle and all its callers,
7052
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5725
diff changeset
    44
 * and the JVM's operations enforce this matching at, specifically
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
    45
 * during calls to {@link MethodHandle#invokeExact MethodHandle.invokeExact}
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
    46
 * and {@link MethodHandle#invokeGeneric MethodHandle.invokeGeneric}, and during execution
7052
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5725
diff changeset
    47
 * of {@code invokedynamic} instructions.
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    48
 * <p>
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    49
 * The structure is a return type accompanied by any number of parameter types.
7052
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5725
diff changeset
    50
 * The types (primitive, {@code void}, and reference) are represented by {@link Class} objects.
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5725
diff changeset
    51
 * (For ease of exposition, we treat {@code void} as if it were a type.
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5725
diff changeset
    52
 * In fact, it denotes the absence of a return type.)
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    53
 * <p>
7052
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5725
diff changeset
    54
 * All instances of {@code MethodType} are immutable.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    55
 * Two instances are completely interchangeable if they compare equal.
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    56
 * Equality depends on pairwise correspondence of the return and parameter types and on nothing else.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    57
 * <p>
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    58
 * This type can be created only by factory methods.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    59
 * All factory methods may cache values, though caching is not guaranteed.
7562
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    60
 * Some factory methods are static, while others are virtual methods which
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    61
 * modify precursor method types, e.g., by changing a selected parameter.
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    62
 * <p>
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    63
 * Factory methods which operate on groups of parameter types
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    64
 * are systematically presented in two versions, so that both Java arrays and
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    65
 * Java lists can be used to work with groups of parameter types.
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    66
 * The query methods {@code parameterArray} and {@code parameterList}
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    67
 * also provide a choice between arrays and lists.
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    68
 * <p>
7052
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5725
diff changeset
    69
 * {@code MethodType} objects are sometimes derived from bytecode instructions
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5725
diff changeset
    70
 * such as {@code invokedynamic}, specifically from the type descriptor strings associated
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5725
diff changeset
    71
 * with the instructions in a class file's constant pool.
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5725
diff changeset
    72
 * <p>
7562
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    73
 * Like classes and strings, method types can also be represented directly
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
    74
 * in a class file's constant pool as constants.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
    75
 * A method type may be loaded by an {@code ldc} instruction which refers
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
    76
 * to a suitable {@code CONSTANT_MethodType} constant pool entry.
7562
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    77
 * The entry refers to a {@code CONSTANT_Utf8} spelling for the descriptor string.
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    78
 * For more details, see the <a href="package-summary.html#mtcon">package summary</a>.
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    79
 * <p>
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    80
 * When the JVM materializes a {@code MethodType} from a descriptor string,
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    81
 * all classes named in the descriptor must be accessible, and will be loaded.
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    82
 * (But the classes need not be initialized, as is the case with a {@code CONSTANT_Class}.)
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    83
 * This loading may occur at any time before the {@code MethodType} object is first derived.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    84
 * @author John Rose, JSR 292 EG
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    85
 */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    86
public final
7562
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
    87
class MethodType {
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    88
    private final Class<?>   rtype;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    89
    private final Class<?>[] ptypes;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    90
    private MethodTypeForm form; // erased form, plus cached data about primitives
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    91
    private MethodType wrapAlt;  // alternative wrapped/unwrapped version
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    92
    private Invokers invokers;   // cache of handy higher-order adapters
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    93
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    94
    private static final Access IMPL_TOKEN = Access.getToken();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    95
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    96
    // share a cache with a friend in this package
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    97
    Invokers getInvokers() { return invokers; }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    98
    void setInvokers(Invokers inv) { invokers = inv; }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    99
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   100
    static {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   101
        // This hack allows the implementation package special access to
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   102
        // the internals of MethodType.  In particular, the MTImpl has all sorts
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   103
        // of cached information useful to the implementation code.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   104
        MethodTypeImpl.setMethodTypeFriend(IMPL_TOKEN, new MethodTypeImpl.MethodTypeFriend() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   105
            public Class<?>[] ptypes(MethodType mt)        { return mt.ptypes; }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   106
            public MethodTypeImpl form(MethodType mt)      { return mt.form; }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   107
            public void setForm(MethodType mt, MethodTypeImpl form) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   108
                assert(mt.form == null);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   109
                mt.form = (MethodTypeForm) form;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   110
            }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   111
            public MethodType makeImpl(Class<?> rtype, Class<?>[] ptypes, boolean trusted) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   112
                return MethodType.makeImpl(rtype, ptypes, trusted);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   113
            }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   114
            public MethodTypeImpl newMethodTypeForm(MethodType mt) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   115
                return new MethodTypeForm(mt);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   116
            }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   117
            public Invokers getInvokers(MethodType mt)    { return mt.invokers; }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   118
            public void setInvokers(MethodType mt, Invokers inv) { mt.invokers = inv; }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   119
        });
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   120
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   121
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   122
    private MethodType(Class<?> rtype, Class<?>[] ptypes) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   123
        checkRtype(rtype);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   124
        checkPtypes(ptypes);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   125
        this.rtype = rtype;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   126
        this.ptypes = ptypes;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   127
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   128
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   129
    private static void checkRtype(Class<?> rtype) {
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   130
        rtype.equals(rtype);  // null check
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   131
    }
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   132
    private static int checkPtype(Class<?> ptype) {
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   133
        ptype.getClass();  //NPE
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   134
        if (ptype == void.class)
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   135
            throw newIllegalArgumentException("parameter type cannot be void");
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   136
        if (ptype == double.class || ptype == long.class)  return 1;
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   137
        return 0;
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   138
    }
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   139
    /** Return number of extra slots (count of long/double args). */
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   140
    private static int checkPtypes(Class<?>[] ptypes) {
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   141
        int slots = 0;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   142
        for (Class<?> ptype : ptypes) {
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   143
            slots += checkPtype(ptype);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   144
        }
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   145
        checkSlotCount(ptypes.length + slots);
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   146
        return slots;
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   147
    }
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   148
    private static void checkSlotCount(int count) {
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   149
        if ((count & 0xFF) != count)
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   150
            throw newIllegalArgumentException("bad parameter count "+count);
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   151
    }
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   152
    private static IndexOutOfBoundsException newIndexOutOfBoundsException(Object num) {
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   153
        if (num instanceof Integer)  num = "bad index: "+num;
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   154
        return new IndexOutOfBoundsException(num.toString());
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   155
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   156
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   157
    static final HashMap<MethodType,MethodType> internTable
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   158
            = new HashMap<MethodType, MethodType>();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   159
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   160
    static final Class<?>[] NO_PTYPES = {};
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   161
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   162
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   163
     * Find or create an instance of the given method type.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   164
     * @param rtype  the return type
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   165
     * @param ptypes the parameter types
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   166
     * @return a method type with the given components
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   167
     * @throws NullPointerException if {@code rtype} or {@code ptypes} or any element of {@code ptypes} is null
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   168
     * @throws IllegalArgumentException if any element of {@code ptypes} is {@code void.class}
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   169
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   170
    public static
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   171
    MethodType methodType(Class<?> rtype, Class<?>[] ptypes) {
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   172
        return makeImpl(rtype, ptypes, false);
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   173
    }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   174
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   175
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   176
     * Finds or creates a method type with the given components.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   177
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   178
     * @return a method type with the given components
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   179
     * @throws NullPointerException if {@code rtype} or {@code ptypes} or any element of {@code ptypes} is null
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   180
     * @throws IllegalArgumentException if any element of {@code ptypes} is {@code void.class}
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   181
     */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   182
    public static
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   183
    MethodType methodType(Class<?> rtype, List<Class<?>> ptypes) {
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   184
        boolean notrust = false;  // random List impl. could return evil ptypes array
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   185
        return makeImpl(rtype, ptypes.toArray(NO_PTYPES), notrust);
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   186
    }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   187
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   188
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   189
     * Finds or creates a method type with the given components.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   190
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   191
     * The leading parameter type is prepended to the remaining array.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   192
     * @return a method type with the given components
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   193
     * @throws NullPointerException if {@code rtype} or {@code ptype0} or {@code ptypes} or any element of {@code ptypes} is null
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   194
     * @throws IllegalArgumentException if {@code ptype0} or {@code ptypes} or any element of {@code ptypes} is {@code void.class}
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   195
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   196
    public static
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   197
    MethodType methodType(Class<?> rtype, Class<?> ptype0, Class<?>... ptypes) {
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   198
        Class<?>[] ptypes1 = new Class<?>[1+ptypes.length];
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   199
        ptypes1[0] = ptype0;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   200
        System.arraycopy(ptypes, 0, ptypes1, 1, ptypes.length);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   201
        return makeImpl(rtype, ptypes1, true);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   202
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   203
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   204
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   205
     * Finds or creates a method type with the given components.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   206
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   207
     * The resulting method has no parameter types.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   208
     * @return a method type with the given return value
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   209
     * @throws NullPointerException if {@code rtype} is null
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   210
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   211
    public static
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   212
    MethodType methodType(Class<?> rtype) {
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   213
        return makeImpl(rtype, NO_PTYPES, true);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   214
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   215
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   216
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   217
     * Finds or creates a method type with the given components.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   218
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   219
     * The resulting method has the single given parameter type.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   220
     * @return a method type with the given return value and parameter type
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   221
     * @throws NullPointerException if {@code rtype} or {@code ptype0} is null
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   222
     * @throws IllegalArgumentException if {@code ptype0} is {@code void.class}
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   223
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   224
    public static
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   225
    MethodType methodType(Class<?> rtype, Class<?> ptype0) {
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   226
        return makeImpl(rtype, new Class<?>[]{ ptype0 }, true);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   227
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   228
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   229
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   230
     * Finds or creates a method type with the given components.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   231
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   232
     * The resulting method has the same parameter types as {@code ptypes},
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   233
     * and the specified return type.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   234
     * @throws NullPointerException if {@code rtype} or {@code ptypes} is null
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   235
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   236
    public static
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   237
    MethodType methodType(Class<?> rtype, MethodType ptypes) {
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   238
        return makeImpl(rtype, ptypes.ptypes, true);
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   239
    }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   240
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   241
    /**
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   242
     * Sole factory method to find or create an interned method type.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   243
     * @param rtype desired return type
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   244
     * @param ptypes desired parameter types
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   245
     * @param trusted whether the ptypes can be used without cloning
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   246
     * @return the unique method type of the desired structure
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   247
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   248
    private static
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   249
    MethodType makeImpl(Class<?> rtype, Class<?>[] ptypes, boolean trusted) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   250
        if (ptypes == null || ptypes.length == 0) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   251
            ptypes = NO_PTYPES; trusted = true;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   252
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   253
        MethodType mt1 = new MethodType(rtype, ptypes);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   254
        MethodType mt0;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   255
        synchronized (internTable) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   256
            mt0 = internTable.get(mt1);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   257
            if (mt0 != null)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   258
                return mt0;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   259
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   260
        if (!trusted)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   261
            // defensively copy the array passed in by the user
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   262
            mt1 = new MethodType(rtype, ptypes.clone());
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   263
        // promote the object to the Real Thing, and reprobe
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   264
        MethodTypeImpl.initForm(IMPL_TOKEN, mt1);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   265
        synchronized (internTable) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   266
            mt0 = internTable.get(mt1);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   267
            if (mt0 != null)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   268
                return mt0;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   269
            internTable.put(mt1, mt1);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   270
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   271
        return mt1;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   272
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   273
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   274
    // Entry point from JVM.  TODO: Change the name & signature.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   275
    private static MethodType makeImpl(Class<?> rtype, Class<?>[] ptypes,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   276
            boolean ignore1, boolean ignore2) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   277
        return makeImpl(rtype, ptypes, true);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   278
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   279
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   280
    private static final MethodType[] objectOnlyTypes = new MethodType[20];
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   281
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   282
    /**
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   283
     * Finds or creates a method type whose components are {@code Object} with an optional trailing {@code Object[]} array.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   284
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   285
     * All parameters and the return type will be {@code Object},
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   286
     * except the final varargs parameter if any, which will be {@code Object[]}.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   287
     * @param objectArgCount number of parameters (excluding the varargs parameter if any)
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   288
     * @param varargs whether there will be a varargs parameter, of type {@code Object[]}
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   289
     * @return a totally generic method type, given only its count of parameters and varargs
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   290
     * @throws IllegalArgumentException if {@code objectArgCount} is negative or greater than 255
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   291
     * @see #genericMethodType(int)
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   292
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   293
    public static
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   294
    MethodType genericMethodType(int objectArgCount, boolean varargs) {
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   295
        MethodType mt;
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   296
        checkSlotCount(objectArgCount);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   297
        int ivarargs = (!varargs ? 0 : 1);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   298
        int ootIndex = objectArgCount*2 + ivarargs;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   299
        if (ootIndex < objectOnlyTypes.length) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   300
            mt = objectOnlyTypes[ootIndex];
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   301
            if (mt != null)  return mt;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   302
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   303
        Class<?>[] ptypes = new Class<?>[objectArgCount + ivarargs];
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   304
        Arrays.fill(ptypes, Object.class);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   305
        if (ivarargs != 0)  ptypes[objectArgCount] = Object[].class;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   306
        mt = makeImpl(Object.class, ptypes, true);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   307
        if (ootIndex < objectOnlyTypes.length) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   308
            objectOnlyTypes[ootIndex] = mt;     // cache it here also!
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   309
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   310
        return mt;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   311
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   312
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   313
    /**
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   314
     * Finds or creates a method type whose components are all {@code Object}.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   315
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   316
     * All parameters and the return type will be Object.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   317
     * @param objectArgCount number of parameters
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   318
     * @return a totally generic method type, given only its count of parameters
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   319
     * @throws IllegalArgumentException if {@code objectArgCount} is negative or greater than 255
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   320
     * @see #genericMethodType(int, boolean)
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   321
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   322
    public static
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   323
    MethodType genericMethodType(int objectArgCount) {
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   324
        return genericMethodType(objectArgCount, false);
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   325
    }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   326
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   327
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   328
     * Finds or creates a method type with a single different parameter type.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   329
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   330
     * @param num    the index (zero-based) of the parameter type to change
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   331
     * @param nptype a new parameter type to replace the old one with
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   332
     * @return the same type, except with the selected parameter changed
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   333
     * @throws IndexOutOfBoundsException if {@code num} is not a valid index into {@code parameterArray()}
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   334
     * @throws IllegalArgumentException if {@code nptype} is {@code void.class}
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   335
     * @throws NullPointerException if {@code nptype} is null
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   336
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   337
    public MethodType changeParameterType(int num, Class<?> nptype) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   338
        if (parameterType(num) == nptype)  return this;
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   339
        checkPtype(nptype);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   340
        Class<?>[] nptypes = ptypes.clone();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   341
        nptypes[num] = nptype;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   342
        return makeImpl(rtype, nptypes, true);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   343
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   344
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   345
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   346
     * Finds or creates a method type with additional parameter types.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   347
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   348
     * @param num    the position (zero-based) of the inserted parameter type(s)
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   349
     * @param ptypesToInsert zero or more new parameter types to insert into the parameter list
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   350
     * @return the same type, except with the selected parameter(s) inserted
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   351
     * @throws IndexOutOfBoundsException if {@code num} is negative or greater than {@code parameterCount()}
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   352
     * @throws IllegalArgumentException if any element of {@code ptypesToInsert} is {@code void.class}
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   353
     *                                  or if the resulting method type would have more than 255 parameter slots
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   354
     * @throws NullPointerException if {@code ptypesToInsert} or any of its elements is null
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   355
     */
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   356
    public MethodType insertParameterTypes(int num, Class<?>... ptypesToInsert) {
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   357
        int len = ptypes.length;
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   358
        if (num < 0 || num > len)
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   359
            throw newIndexOutOfBoundsException(num);
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   360
        int ins = checkPtypes(ptypesToInsert);
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   361
        checkSlotCount(parameterSlotCount() + ptypesToInsert.length + ins);
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   362
        int ilen = ptypesToInsert.length;
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   363
        if (ilen == 0)  return this;
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   364
        Class<?>[] nptypes = Arrays.copyOfRange(ptypes, 0, len+ilen);
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   365
        System.arraycopy(nptypes, num, nptypes, num+ilen, len-num);
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   366
        System.arraycopy(ptypesToInsert, 0, nptypes, num, ilen);
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   367
        return makeImpl(rtype, nptypes, true);
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   368
    }
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   369
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   370
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   371
     * Finds or creates a method type with additional parameter types.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   372
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   373
     * @param ptypesToInsert zero or more new parameter types to insert after the end of the parameter list
7555
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 7052
diff changeset
   374
     * @return the same type, except with the selected parameter(s) appended
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   375
     * @throws IllegalArgumentException if any element of {@code ptypesToInsert} is {@code void.class}
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   376
     *                                  or if the resulting method type would have more than 255 parameter slots
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   377
     * @throws NullPointerException if {@code ptypesToInsert} or any of its elements is null
7555
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 7052
diff changeset
   378
     */
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 7052
diff changeset
   379
    public MethodType appendParameterTypes(Class<?>... ptypesToInsert) {
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 7052
diff changeset
   380
        return insertParameterTypes(parameterCount(), ptypesToInsert);
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 7052
diff changeset
   381
    }
a279ebc3b25c 6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents: 7052
diff changeset
   382
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   383
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   384
     * Finds or creates a method type with additional parameter types.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   385
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   386
     * @param num    the position (zero-based) of the inserted parameter type(s)
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   387
     * @param ptypesToInsert zero or more new parameter types to insert into the parameter list
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   388
     * @return the same type, except with the selected parameter(s) inserted
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   389
     * @throws IndexOutOfBoundsException if {@code num} is negative or greater than {@code parameterCount()}
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   390
     * @throws IllegalArgumentException if any element of {@code ptypesToInsert} is {@code void.class}
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   391
     *                                  or if the resulting method type would have more than 255 parameter slots
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   392
     * @throws NullPointerException if {@code ptypesToInsert} or any of its elements is null
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   393
     */
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   394
    public MethodType insertParameterTypes(int num, List<Class<?>> ptypesToInsert) {
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   395
        return insertParameterTypes(num, ptypesToInsert.toArray(NO_PTYPES));
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   396
    }
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   397
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   398
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   399
     * Finds or creates a method type with additional parameter types.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   400
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   401
     * @param ptypesToInsert zero or more new parameter types to insert after the end of the parameter list
7562
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
   402
     * @return the same type, except with the selected parameter(s) appended
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   403
     * @throws IllegalArgumentException if any element of {@code ptypesToInsert} is {@code void.class}
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   404
     *                                  or if the resulting method type would have more than 255 parameter slots
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   405
     * @throws NullPointerException if {@code ptypesToInsert} or any of its elements is null
7562
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
   406
     */
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
   407
    public MethodType appendParameterTypes(List<Class<?>> ptypesToInsert) {
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
   408
        return insertParameterTypes(parameterCount(), ptypesToInsert);
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
   409
    }
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
   410
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   411
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   412
     * Finds or creates a method type with some parameter types omitted.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   413
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   414
     * @param start  the index (zero-based) of the first parameter type to remove
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   415
     * @param end    the index (greater than {@code start}) of the first parameter type after not to remove
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   416
     * @return the same type, except with the selected parameter(s) removed
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   417
     * @throws IndexOutOfBoundsException if {@code start} is negative or greater than {@code parameterCount()}
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   418
     *                                  or if {@code end} is negative or greater than {@code parameterCount()}
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   419
     *                                  or if {@code start} is greater than {@code end}
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   420
     */
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   421
    public MethodType dropParameterTypes(int start, int end) {
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   422
        int len = ptypes.length;
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   423
        if (!(0 <= start && start <= end && end <= len))
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   424
            throw newIndexOutOfBoundsException("start="+start+" end="+end);
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   425
        if (start == end)  return this;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   426
        Class<?>[] nptypes;
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   427
        if (start == 0) {
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   428
            if (end == len) {
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   429
                // drop all parameters
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   430
                nptypes = NO_PTYPES;
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   431
            } else {
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   432
                // drop initial parameter(s)
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   433
                nptypes = Arrays.copyOfRange(ptypes, end, len);
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   434
            }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   435
        } else {
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   436
            if (end == len) {
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   437
                // drop trailing parameter(s)
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   438
                nptypes = Arrays.copyOfRange(ptypes, 0, start);
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   439
            } else {
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   440
                int tail = len - end;
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   441
                nptypes = Arrays.copyOfRange(ptypes, 0, start + tail);
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   442
                System.arraycopy(ptypes, end, nptypes, start, tail);
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   443
            }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   444
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   445
        return makeImpl(rtype, nptypes, true);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   446
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   447
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   448
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   449
     * Finds or creates a method type with a different return type.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   450
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   451
     * @param nrtype a return parameter type to replace the old one with
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   452
     * @return the same type, except with the return type change
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   453
     * @throws NullPointerException if {@code nrtype} is null
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   454
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   455
    public MethodType changeReturnType(Class<?> nrtype) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   456
        if (returnType() == nrtype)  return this;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   457
        return makeImpl(nrtype, ptypes, true);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   458
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   459
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   460
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   461
     * Reports if this type contains a primitive argument or return value.
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   462
     * The return type {@code void} counts as a primitive.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   463
     * @return true if any of the types are primitives
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   464
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   465
    public boolean hasPrimitives() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   466
        return form.hasPrimitives();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   467
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   468
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   469
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   470
     * Reports if this type contains a wrapper argument or return value.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   471
     * Wrappers are types which box primitive values, such as {@link Integer}.
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   472
     * The reference type {@code java.lang.Void} counts as a wrapper.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   473
     * @return true if any of the types are wrappers
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   474
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   475
    public boolean hasWrappers() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   476
        return unwrap() != this;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   477
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   478
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   479
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   480
     * Erases all reference types to {@code Object}.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   481
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   482
     * All primitive types (including {@code void}) will remain unchanged.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   483
     * @return a version of the original type with all reference types replaced
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   484
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   485
    public MethodType erase() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   486
        return form.erasedType();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   487
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   488
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   489
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   490
     * Converts all types, both reference and primitive, to {@code Object}.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   491
     * Convenience method for {@link #genericMethodType(int) genericMethodType}.
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   492
     * The expression {@code type.wrap().erase()} produces the same value
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   493
     * as {@code type.generic()}.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   494
     * @return a version of the original type with all types replaced
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   495
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   496
    public MethodType generic() {
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   497
        return genericMethodType(parameterCount());
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   498
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   499
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   500
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   501
     * Converts all primitive types to their corresponding wrapper types.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   502
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   503
     * All reference types (including wrapper types) will remain unchanged.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   504
     * A {@code void} return type is changed to the type {@code java.lang.Void}.
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   505
     * The expression {@code type.wrap().erase()} produces the same value
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   506
     * as {@code type.generic()}.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   507
     * @return a version of the original type with all primitive types replaced
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   508
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   509
    public MethodType wrap() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   510
        return hasPrimitives() ? wrapWithPrims(this) : this;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   511
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   512
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   513
    /**
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   514
     * Convert all wrapper types to their corresponding primitive types.
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   515
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   516
     * All primitive types (including {@code void}) will remain unchanged.
2763
172d44ffd1e5 6839802: java.dyn needs to be on the CORE_PKGS list
jrose
parents: 2707
diff changeset
   517
     * A return type of {@code java.lang.Void} is changed to {@code void}.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   518
     * @return a version of the original type with all wrapper types replaced
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   519
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   520
    public MethodType unwrap() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   521
        MethodType noprims = !hasPrimitives() ? this : wrapWithPrims(this);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   522
        return unwrapWithNoPrims(noprims);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   523
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   524
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   525
    private static MethodType wrapWithPrims(MethodType pt) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   526
        assert(pt.hasPrimitives());
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   527
        MethodType wt = pt.wrapAlt;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   528
        if (wt == null) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   529
            // fill in lazily
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   530
            wt = MethodTypeImpl.canonicalize(pt, MethodTypeImpl.WRAP, MethodTypeImpl.WRAP);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   531
            assert(wt != null);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   532
            pt.wrapAlt = wt;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   533
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   534
        return wt;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   535
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   536
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   537
    private static MethodType unwrapWithNoPrims(MethodType wt) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   538
        assert(!wt.hasPrimitives());
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   539
        MethodType uwt = wt.wrapAlt;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   540
        if (uwt == null) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   541
            // fill in lazily
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   542
            uwt = MethodTypeImpl.canonicalize(wt, MethodTypeImpl.UNWRAP, MethodTypeImpl.UNWRAP);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   543
            if (uwt == null)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   544
                uwt = wt;    // type has no wrappers or prims at all
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   545
            wt.wrapAlt = uwt;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   546
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   547
        return uwt;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   548
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   549
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   550
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   551
     * Returns the parameter type at the specified index, within this method type.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   552
     * @param num the index (zero-based) of the desired parameter type
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   553
     * @return the selected parameter type
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   554
     * @throws IndexOutOfBoundsException if {@code num} is not a valid index into {@code parameterArray()}
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   555
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   556
    public Class<?> parameterType(int num) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   557
        return ptypes[num];
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   558
    }
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   559
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   560
     * Returns the number of parameter types in this method type.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   561
     * @return the number of parameter types
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   562
     */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   563
    public int parameterCount() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   564
        return ptypes.length;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   565
    }
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   566
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   567
     * Returns the return type of this method type.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   568
     * @return the return type
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   569
     */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   570
    public Class<?> returnType() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   571
        return rtype;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   572
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   573
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   574
    /**
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   575
     * Presents the parameter types as a list (a convenience method).
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   576
     * The list will be immutable.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   577
     * @return the parameter types (as an immutable list)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   578
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   579
    public List<Class<?>> parameterList() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   580
        return Collections.unmodifiableList(Arrays.asList(ptypes));
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   581
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   582
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   583
    /**
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   584
     * Presents the parameter types as an array (a convenience method).
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   585
     * Changes to the array will not result in changes to the type.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   586
     * @return the parameter types (as a fresh copy if necessary)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   587
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   588
    public Class<?>[] parameterArray() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   589
        return ptypes.clone();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   590
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   591
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   592
    /**
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   593
     * Compares the specified object with this type for equality.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   594
     * That is, it returns <tt>true</tt> if and only if the specified object
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   595
     * is also a method type with exactly the same parameters and return type.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   596
     * @param x object to compare
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   597
     * @see Object#equals(Object)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   598
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   599
    @Override
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   600
    public boolean equals(Object x) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   601
        return this == x || x instanceof MethodType && equals((MethodType)x);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   602
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   603
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   604
    private boolean equals(MethodType that) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   605
        return this.rtype == that.rtype
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   606
            && Arrays.equals(this.ptypes, that.ptypes);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   607
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   608
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   609
    /**
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   610
     * Returns the hash code value for this method type.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   611
     * It is defined to be the same as the hashcode of a List
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   612
     * whose elements are the return type followed by the
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   613
     * parameter types.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   614
     * @return the hash code value for this method type
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   615
     * @see Object#hashCode()
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   616
     * @see #equals(Object)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   617
     * @see List#hashCode()
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   618
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   619
    @Override
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   620
    public int hashCode() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   621
      int hashCode = 31 + rtype.hashCode();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   622
      for (Class<?> ptype : ptypes)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   623
          hashCode = 31*hashCode + ptype.hashCode();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   624
      return hashCode;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   625
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   626
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   627
    /**
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   628
     * Returns a string representation of the method type,
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   629
     * of the form {@code "(PT0,PT1...)RT"}.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   630
     * The string representation of a method type is a
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   631
     * parenthesis enclosed, comma separated list of type names,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   632
     * followed immediately by the return type.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   633
     * <p>
7562
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
   634
     * Each type is represented by its
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
   635
     * {@link java.lang.Class#getSimpleName simple name}.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   636
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   637
    @Override
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   638
    public String toString() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   639
        StringBuilder sb = new StringBuilder();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   640
        sb.append("(");
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   641
        for (int i = 0; i < ptypes.length; i++) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   642
            if (i > 0)  sb.append(",");
7562
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
   643
            sb.append(ptypes[i].getSimpleName());
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   644
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   645
        sb.append(")");
7562
a0ad195efe2c 7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents: 7555
diff changeset
   646
        sb.append(rtype.getSimpleName());
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   647
        return sb.toString();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   648
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   649
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   650
    /// Queries which have to do with the bytecode architecture
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   651
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   652
    /** Reports the number of JVM stack slots required to invoke a method
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   653
     * of this type.  Note that (for historic reasons) the JVM requires
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   654
     * a second stack slot to pass long and double arguments.
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   655
     * So this method returns {@link #parameterCount() parameterCount} plus the
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   656
     * number of long and double parameters (if any).
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   657
     * <p>
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   658
     * This method is included for the benfit of applications that must
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   659
     * generate bytecodes that process method handles and invokedynamic.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   660
     * @return the number of JVM stack slots for this type's parameters
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   661
     * @deprecated Will be removed for PFD.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   662
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   663
    public int parameterSlotCount() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   664
        return form.parameterSlotCount();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   665
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   666
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   667
    /** Reports the number of JVM stack slots which carry all parameters including and after
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   668
     * the given position, which must be in the range of 0 to
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   669
     * {@code parameterCount} inclusive.  Successive parameters are
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   670
     * more shallowly stacked, and parameters are indexed in the bytecodes
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   671
     * according to their trailing edge.  Thus, to obtain the depth
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   672
     * in the outgoing call stack of parameter {@code N}, obtain
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   673
     * the {@code parameterSlotDepth} of its trailing edge
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   674
     * at position {@code N+1}.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   675
     * <p>
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   676
     * Parameters of type {@code long} and {@code double} occupy
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   677
     * two stack slots (for historical reasons) and all others occupy one.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   678
     * Therefore, the number returned is the number of arguments
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   679
     * <em>including</em> and <em>after</em> the given parameter,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   680
     * <em>plus</em> the number of long or double arguments
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   681
     * at or after after the argument for the given parameter.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   682
     * <p>
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   683
     * This method is included for the benfit of applications that must
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   684
     * generate bytecodes that process method handles and invokedynamic.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   685
     * @param num an index (zero-based, inclusive) within the parameter types
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   686
     * @return the index of the (shallowest) JVM stack slot transmitting the
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   687
     *         given parameter
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   688
     * @throws IllegalArgumentException if {@code num} is negative or greater than {@code parameterCount()}
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   689
     * @deprecated Will be removed for PFD.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   690
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   691
    public int parameterSlotDepth(int num) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   692
        if (num < 0 || num > ptypes.length)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   693
            parameterType(num);  // force a range check
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   694
        return form.parameterToArgSlot(num-1);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   695
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   696
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   697
    /** Reports the number of JVM stack slots required to receive a return value
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   698
     * from a method of this type.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   699
     * If the {@link #returnType() return type} is void, it will be zero,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   700
     * else if the return type is long or double, it will be two, else one.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   701
     * <p>
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   702
     * This method is included for the benfit of applications that must
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   703
     * generate bytecodes that process method handles and invokedynamic.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   704
     * @return the number of JVM stack slots (0, 1, or 2) for this type's return value
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   705
     * @deprecated Will be removed for PFD.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   706
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   707
    public int returnSlotCount() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   708
        return form.returnSlotCount();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   709
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   710
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   711
    /**
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   712
     * Find or create an instance of a method type, given the spelling of its bytecode descriptor.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   713
     * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}.
7052
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5725
diff changeset
   714
     * Any class or interface name embedded in the descriptor string
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   715
     * will be resolved by calling {@link ClassLoader#loadClass(java.lang.String)}
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   716
     * on the given loader (or if it is null, on the system class loader).
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   717
     * <p>
7052
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5725
diff changeset
   718
     * Note that it is possible to encounter method types which cannot be
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   719
     * constructed by this method, because their component types are
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   720
     * not all reachable from a common class loader.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   721
     * <p>
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   722
     * This method is included for the benfit of applications that must
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   723
     * generate bytecodes that process method handles and {@code invokedynamic}.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   724
     * @param descriptor a bytecode-level type descriptor string "(T...)T"
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   725
     * @param loader the class loader in which to look up the types
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   726
     * @return a method type matching the bytecode-level type descriptor
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   727
     * @throws IllegalArgumentException if the string is not well-formed
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   728
     * @throws TypeNotPresentException if a named type cannot be found
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   729
     */
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   730
    public static MethodType fromMethodDescriptorString(String descriptor, ClassLoader loader)
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   731
        throws IllegalArgumentException, TypeNotPresentException
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   732
    {
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   733
        List<Class<?>> types = BytecodeDescriptor.parseMethod(descriptor, loader);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   734
        Class<?> rtype = types.remove(types.size() - 1);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   735
        Class<?>[] ptypes = types.toArray(NO_PTYPES);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   736
        return makeImpl(rtype, ptypes, true);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   737
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   738
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   739
    /**
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   740
     * Produces a bytecode descriptor representation of the method type.
7052
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5725
diff changeset
   741
     * <p>
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   742
     * Note that this is not a strict inverse of {@link #fromMethodDescriptorString fromMethodDescriptorString}.
7052
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5725
diff changeset
   743
     * Two distinct classes which share a common name but have different class loaders
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5725
diff changeset
   744
     * will appear identical when viewed within descriptor strings.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   745
     * <p>
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   746
     * This method is included for the benfit of applications that must
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   747
     * generate bytecodes that process method handles and {@code invokedynamic}.
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   748
     * {@link #fromMethodDescriptorString(java.lang.String, java.lang.ClassLoader) fromMethodDescriptorString},
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   749
     * because the latter requires a suitable class loader argument.
8346
3b891698c4ec 7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents: 7668
diff changeset
   750
     * @return the bytecode type descriptor representation
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   751
     */
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   752
    public String toMethodDescriptorString() {
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   753
        return BytecodeDescriptor.unparse(this);
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2763
diff changeset
   754
    }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   755
}