src/java.base/share/classes/java/lang/invoke/MemberName.java
author jboes
Thu, 21 Nov 2019 09:10:21 +0000
changeset 59201 b24f4caa1411
parent 57512 f557f260b787
permissions -rw-r--r--
8234335: Remove line break in class declaration in java.base Summary: Remove line break in class declarations where applicable Reviewed-by: rriggs, lancea
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
/*
57512
f557f260b787 8173978: Lookup.in should allow teleporting from a lookup class in a named module without dropping all access
mchung
parents: 49641
diff changeset
     2
 * Copyright (c) 2008, 2019, 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
8822
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
    26
package java.lang.invoke;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    27
8822
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
    28
import sun.invoke.util.BytecodeDescriptor;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
    29
import sun.invoke.util.VerifyAccess;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
    30
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    31
import java.lang.reflect.Constructor;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    32
import java.lang.reflect.Field;
39342
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 38774
diff changeset
    33
import java.lang.reflect.Member;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    34
import java.lang.reflect.Method;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    35
import java.lang.reflect.Modifier;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    36
import java.util.ArrayList;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    37
import java.util.Collections;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    38
import java.util.Iterator;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    39
import java.util.List;
39342
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 38774
diff changeset
    40
import java.util.Objects;
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 38774
diff changeset
    41
8822
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
    42
import static java.lang.invoke.MethodHandleNatives.Constants.*;
39342
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 38774
diff changeset
    43
import static java.lang.invoke.MethodHandleStatics.newIllegalArgumentException;
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 38774
diff changeset
    44
import static java.lang.invoke.MethodHandleStatics.newInternalError;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    45
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    46
/**
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    47
 * A {@code MemberName} is a compact symbolic datum which fully characterizes
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    48
 * a method or field reference.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    49
 * A member name refers to a field, method, constructor, or member type.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    50
 * Every member name has a simple name (a string) and a type (either a Class or MethodType).
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    51
 * A member name may also have a non-null declaring class, or it may be simply
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    52
 * a naked name/type pair.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    53
 * A member name may also have non-zero modifier flags.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    54
 * Finally, a member name may be either resolved or unresolved.
38774
b2ca0c2ec115 8156868: MethodHandles.zero(Class) doc issues
mhaupt
parents: 37819
diff changeset
    55
 * If it is resolved, the existence of the named member has been determined by the JVM.
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    56
 * <p>
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    57
 * Whether resolved or not, a member name provides no access rights or
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    58
 * invocation capability to its possessor.  It is merely a compact
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    59
 * representation of all symbolic information necessary to link to
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    60
 * and properly use the named member.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    61
 * <p>
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    62
 * When resolved, a member name's internal implementation may include references to JVM metadata.
25979
42e5d9f8087e 8054857: Fix typos in java.lang.** packages
prappo
parents: 23010
diff changeset
    63
 * This representation is stateless and only descriptive.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    64
 * It provides no private information and no capability to use the member.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    65
 * <p>
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    66
 * By contrast, a {@linkplain java.lang.reflect.Method} contains fuller information
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    67
 * about the internals of a method (except its bytecodes) and also
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    68
 * allows invocation.  A MemberName is much lighter than a Method,
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    69
 * since it contains about 7 fields to the 16 of Method (plus its sub-arrays),
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    70
 * and those seven fields omit much of the information in Method.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    71
 * @author jrose
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    72
 */
59201
b24f4caa1411 8234335: Remove line break in class declaration in java.base
jboes
parents: 57512
diff changeset
    73
/*non-public*/
b24f4caa1411 8234335: Remove line break in class declaration in java.base
jboes
parents: 57512
diff changeset
    74
final class ResolvedMethodName {
46867
dbe5f2bef304 8174749: Use hash table/oops for MemberName table
coleenp
parents: 44599
diff changeset
    75
    //@Injected JVM_Method* vmtarget;
dbe5f2bef304 8174749: Use hash table/oops for MemberName table
coleenp
parents: 44599
diff changeset
    76
    //@Injected Class<?>    vmholder;
dbe5f2bef304 8174749: Use hash table/oops for MemberName table
coleenp
parents: 44599
diff changeset
    77
};
dbe5f2bef304 8174749: Use hash table/oops for MemberName table
coleenp
parents: 44599
diff changeset
    78
59201
b24f4caa1411 8234335: Remove line break in class declaration in java.base
jboes
parents: 57512
diff changeset
    79
/*non-public*/
b24f4caa1411 8234335: Remove line break in class declaration in java.base
jboes
parents: 57512
diff changeset
    80
final class MemberName implements Member, Cloneable {
46867
dbe5f2bef304 8174749: Use hash table/oops for MemberName table
coleenp
parents: 44599
diff changeset
    81
    private Class<?> clazz;       // class in which the member is defined
20472
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
    82
    private String   name;        // may be null if not yet materialized
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
    83
    private Object   type;        // may be null if not yet materialized
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
    84
    private int      flags;       // modifier bits; see reflect.Modifier
46867
dbe5f2bef304 8174749: Use hash table/oops for MemberName table
coleenp
parents: 44599
diff changeset
    85
    private ResolvedMethodName method;    // cached resolved method information
dbe5f2bef304 8174749: Use hash table/oops for MemberName table
coleenp
parents: 44599
diff changeset
    86
    //@Injected intptr_t       vmindex;   // vtable index or offset of resolved member
40272
6af4511ee5a4 8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents: 40258
diff changeset
    87
    Object   resolution;  // if null, this guy is resolved
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    88
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    89
    /** Return the declaring class of this member.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    90
     *  In the case of a bare name and type, the declaring class will be null.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    91
     */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    92
    public Class<?> getDeclaringClass() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    93
        return clazz;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    94
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    95
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    96
    /** Utility method producing the class loader of the declaring class. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    97
    public ClassLoader getClassLoader() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    98
        return clazz.getClassLoader();
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
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   101
    /** Return the simple name of this member.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   102
     *  For a type, it is the same as {@link Class#getSimpleName}.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   103
     *  For a method or field, it is the simple name of the member.
32276
2d5fcc89e099 8134356: {@code} tag contains &lt; and &gt; sequences
igerasim
parents: 29094
diff changeset
   104
     *  For a constructor, it is always {@code "<init>"}.
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   105
     */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   106
    public String getName() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   107
        if (name == null) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   108
            expandFromVM();
20472
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   109
            if (name == null) {
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   110
                return null;
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   111
            }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   112
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   113
        return name;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   114
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   115
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   116
    public MethodType getMethodOrFieldType() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   117
        if (isInvocable())
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   118
            return getMethodType();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   119
        if (isGetter())
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   120
            return MethodType.methodType(getFieldType());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   121
        if (isSetter())
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   122
            return MethodType.methodType(void.class, getFieldType());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   123
        throw new InternalError("not a method or field: "+this);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   124
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   125
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   126
    /** Return the declared type of this member, which
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   127
     *  must be a method or constructor.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   128
     */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   129
    public MethodType getMethodType() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   130
        if (type == null) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   131
            expandFromVM();
20472
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   132
            if (type == null) {
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   133
                return null;
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   134
            }
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   135
        }
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   136
        if (!isInvocable()) {
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   137
            throw newIllegalArgumentException("not invocable, no method type");
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   138
        }
20472
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   139
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   140
        {
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   141
            // Get a snapshot of type which doesn't get changed by racing threads.
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   142
            final Object type = this.type;
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   143
            if (type instanceof MethodType) {
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   144
                return (MethodType) type;
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   145
            }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   146
        }
20472
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   147
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   148
        // type is not a MethodType yet.  Convert it thread-safely.
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   149
        synchronized (this) {
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   150
            if (type instanceof String) {
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   151
                String sig = (String) type;
32986
ea54ac8672e7 8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents: 32276
diff changeset
   152
                MethodType res = MethodType.fromDescriptor(sig, getClassLoader());
20472
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   153
                type = res;
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   154
            } else if (type instanceof Object[]) {
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   155
                Object[] typeInfo = (Object[]) type;
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   156
                Class<?>[] ptypes = (Class<?>[]) typeInfo[1];
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   157
                Class<?> rtype = (Class<?>) typeInfo[0];
44591
b9bf065070fe 8178387: Reduce memory churn when creating java.lang.invoke entities
redestad
parents: 40272
diff changeset
   158
                MethodType res = MethodType.makeImpl(rtype, ptypes, true);
20472
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   159
                type = res;
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   160
            }
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   161
            // Make sure type is a MethodType for racing threads.
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   162
            assert type instanceof MethodType : "bad method type " + type;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   163
        }
20472
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   164
        return (MethodType) type;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   165
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   166
47294
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   167
    /** Return the descriptor of this member, which
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   168
     *  must be a method or constructor.
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   169
     */
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   170
    String getMethodDescriptor() {
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   171
        if (type == null) {
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   172
            expandFromVM();
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   173
            if (type == null) {
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   174
                return null;
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   175
            }
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   176
        }
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   177
        if (!isInvocable()) {
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   178
            throw newIllegalArgumentException("not invocable, no method type");
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   179
        }
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   180
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   181
        // Get a snapshot of type which doesn't get changed by racing threads.
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   182
        final Object type = this.type;
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   183
        if (type instanceof String) {
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   184
            return (String) type;
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   185
        } else {
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   186
            return getMethodType().toMethodDescriptorString();
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   187
        }
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   188
    }
7d67bb6b0599 8186050: StackFrame should provide the method signature
mchung
parents: 47216
diff changeset
   189
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   190
    /** Return the actual type under which this method or constructor must be invoked.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   191
     *  For non-static methods or constructors, this is the type with a leading parameter,
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   192
     *  a reference to declaring class.  For static methods, it is the same as the declared type.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   193
     */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   194
    public MethodType getInvocationType() {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   195
        MethodType itype = getMethodOrFieldType();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   196
        if (isConstructor() && getReferenceKind() == REF_newInvokeSpecial)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   197
            return itype.changeReturnType(clazz);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   198
        if (!isStatic())
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   199
            return itype.insertParameterTypes(0, clazz);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   200
        return itype;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   201
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   202
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   203
    /** Utility method producing the parameter types of the method type. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   204
    public Class<?>[] getParameterTypes() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   205
        return getMethodType().parameterArray();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   206
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   207
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   208
    /** Utility method producing the return type of the method type. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   209
    public Class<?> getReturnType() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   210
        return getMethodType().returnType();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   211
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   212
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   213
    /** Return the declared type of this member, which
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   214
     *  must be a field or type.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   215
     *  If it is a type member, that type itself is returned.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   216
     */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   217
    public Class<?> getFieldType() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   218
        if (type == null) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   219
            expandFromVM();
20472
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   220
            if (type == null) {
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   221
                return null;
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   222
            }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   223
        }
20472
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   224
        if (isInvocable()) {
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   225
            throw newIllegalArgumentException("not a field or nested class, no simple type");
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   226
        }
20472
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   227
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   228
        {
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   229
            // Get a snapshot of type which doesn't get changed by racing threads.
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   230
            final Object type = this.type;
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   231
            if (type instanceof Class<?>) {
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   232
                return (Class<?>) type;
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   233
            }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   234
        }
20472
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   235
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   236
        // type is not a Class yet.  Convert it thread-safely.
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   237
        synchronized (this) {
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   238
            if (type instanceof String) {
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   239
                String sig = (String) type;
32986
ea54ac8672e7 8136893: Improve early java.lang.invoke infrastructure initialization
plevart
parents: 32276
diff changeset
   240
                MethodType mtype = MethodType.fromDescriptor("()"+sig, getClassLoader());
20472
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   241
                Class<?> res = mtype.returnType();
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   242
                type = res;
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   243
            }
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   244
            // Make sure type is a Class for racing threads.
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   245
            assert type instanceof Class<?> : "bad field type " + type;
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   246
        }
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   247
        return (Class<?>) type;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   248
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   249
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   250
    /** Utility method to produce either the method type or field type of this member. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   251
    public Object getType() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   252
        return (isInvocable() ? getMethodType() : getFieldType());
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   253
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   254
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   255
    /** Utility method to produce the signature of this member,
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   256
     *  used within the class file format to describe its type.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   257
     */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   258
    public String getSignature() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   259
        if (type == null) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   260
            expandFromVM();
20472
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   261
            if (type == null) {
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   262
                return null;
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   263
            }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   264
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   265
        if (isInvocable())
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
   266
            return BytecodeDescriptor.unparse(getMethodType());
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   267
        else
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
   268
            return BytecodeDescriptor.unparse(getFieldType());
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   269
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   270
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   271
    /** Return the modifier flags of this member.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   272
     *  @see java.lang.reflect.Modifier
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   273
     */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   274
    public int getModifiers() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   275
        return (flags & RECOGNIZED_MODIFIERS);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   276
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   277
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   278
    /** Return the reference kind of this member, or zero if none.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   279
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   280
    public byte getReferenceKind() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   281
        return (byte) ((flags >>> MN_REFERENCE_KIND_SHIFT) & MN_REFERENCE_KIND_MASK);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   282
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   283
    private boolean referenceKindIsConsistent() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   284
        byte refKind = getReferenceKind();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   285
        if (refKind == REF_NONE)  return isType();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   286
        if (isField()) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   287
            assert(staticIsConsistent());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   288
            assert(MethodHandleNatives.refKindIsField(refKind));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   289
        } else if (isConstructor()) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   290
            assert(refKind == REF_newInvokeSpecial || refKind == REF_invokeSpecial);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   291
        } else if (isMethod()) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   292
            assert(staticIsConsistent());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   293
            assert(MethodHandleNatives.refKindIsMethod(refKind));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   294
            if (clazz.isInterface())
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   295
                assert(refKind == REF_invokeInterface ||
17461
84860231159b 8008687: MethodHandle code: allow static and invokespecial calls to interface methods
bharadwaj
parents: 16906
diff changeset
   296
                       refKind == REF_invokeStatic    ||
84860231159b 8008687: MethodHandle code: allow static and invokespecial calls to interface methods
bharadwaj
parents: 16906
diff changeset
   297
                       refKind == REF_invokeSpecial   ||
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   298
                       refKind == REF_invokeVirtual && isObjectPublicMethod());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   299
        } else {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   300
            assert(false);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   301
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   302
        return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   303
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   304
    private boolean isObjectPublicMethod() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   305
        if (clazz == Object.class)  return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   306
        MethodType mtype = getMethodType();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   307
        if (name.equals("toString") && mtype.returnType() == String.class && mtype.parameterCount() == 0)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   308
            return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   309
        if (name.equals("hashCode") && mtype.returnType() == int.class && mtype.parameterCount() == 0)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   310
            return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   311
        if (name.equals("equals") && mtype.returnType() == boolean.class && mtype.parameterCount() == 1 && mtype.parameterType(0) == Object.class)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   312
            return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   313
        return false;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   314
    }
59201
b24f4caa1411 8234335: Remove line break in class declaration in java.base
jboes
parents: 57512
diff changeset
   315
b24f4caa1411 8234335: Remove line break in class declaration in java.base
jboes
parents: 57512
diff changeset
   316
    /*non-public*/
b24f4caa1411 8234335: Remove line break in class declaration in java.base
jboes
parents: 57512
diff changeset
   317
    boolean referenceKindIsConsistentWith(int originalRefKind) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   318
        int refKind = getReferenceKind();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   319
        if (refKind == originalRefKind)  return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   320
        switch (originalRefKind) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   321
        case REF_invokeInterface:
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   322
            // Looking up an interface method, can get (e.g.) Object.hashCode
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   323
            assert(refKind == REF_invokeVirtual ||
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   324
                   refKind == REF_invokeSpecial) : this;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   325
            return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   326
        case REF_invokeVirtual:
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   327
        case REF_newInvokeSpecial:
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   328
            // Looked up a virtual, can get (e.g.) final String.hashCode.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   329
            assert(refKind == REF_invokeSpecial) : this;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   330
            return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   331
        }
17461
84860231159b 8008687: MethodHandle code: allow static and invokespecial calls to interface methods
bharadwaj
parents: 16906
diff changeset
   332
        assert(false) : this+" != "+MethodHandleNatives.refKindName((byte)originalRefKind);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   333
        return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   334
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   335
    private boolean staticIsConsistent() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   336
        byte refKind = getReferenceKind();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   337
        return MethodHandleNatives.refKindIsStatic(refKind) == isStatic() || getModifiers() == 0;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   338
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   339
    private boolean vminfoIsConsistent() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   340
        byte refKind = getReferenceKind();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   341
        assert(isResolved());  // else don't call
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   342
        Object vminfo = MethodHandleNatives.getMemberVMInfo(this);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   343
        assert(vminfo instanceof Object[]);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   344
        long vmindex = (Long) ((Object[])vminfo)[0];
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   345
        Object vmtarget = ((Object[])vminfo)[1];
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   346
        if (MethodHandleNatives.refKindIsField(refKind)) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   347
            assert(vmindex >= 0) : vmindex + ":" + this;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   348
            assert(vmtarget instanceof Class);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   349
        } else {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   350
            if (MethodHandleNatives.refKindDoesDispatch(refKind))
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   351
                assert(vmindex >= 0) : vmindex + ":" + this;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   352
            else
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   353
                assert(vmindex < 0) : vmindex;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   354
            assert(vmtarget instanceof MemberName) : vmtarget + " in " + this;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   355
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   356
        return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   357
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   358
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   359
    private MemberName changeReferenceKind(byte refKind, byte oldKind) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   360
        assert(getReferenceKind() == oldKind);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   361
        assert(MethodHandleNatives.refKindIsValid(refKind));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   362
        flags += (((int)refKind - oldKind) << MN_REFERENCE_KIND_SHIFT);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   363
        return this;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   364
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   365
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   366
    private boolean testFlags(int mask, int value) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   367
        return (flags & mask) == value;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   368
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   369
    private boolean testAllFlags(int mask) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   370
        return testFlags(mask, mask);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   371
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   372
    private boolean testAnyFlags(int mask) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   373
        return !testFlags(mask, 0);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   374
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   375
26467
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   376
    /** Utility method to query if this member is a method handle invocation (invoke or invokeExact).
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   377
     */
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   378
    public boolean isMethodHandleInvoke() {
26467
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   379
        final int bits = MH_INVOKE_MODS &~ Modifier.PUBLIC;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   380
        final int negs = Modifier.STATIC;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   381
        if (testFlags(bits | negs, bits) &&
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   382
            clazz == MethodHandle.class) {
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   383
            return isMethodHandleInvokeName(name);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   384
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   385
        return false;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   386
    }
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   387
    public static boolean isMethodHandleInvokeName(String name) {
26467
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   388
        switch (name) {
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   389
        case "invoke":
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   390
        case "invokeExact":
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   391
            return true;
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   392
        default:
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   393
            return false;
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   394
        }
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   395
    }
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   396
    public boolean isVarHandleMethodInvoke() {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   397
        final int bits = MH_INVOKE_MODS &~ Modifier.PUBLIC;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   398
        final int negs = Modifier.STATIC;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   399
        if (testFlags(bits | negs, bits) &&
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   400
            clazz == VarHandle.class) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   401
            return isVarHandleMethodInvokeName(name);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   402
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   403
        return false;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   404
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   405
    public static boolean isVarHandleMethodInvokeName(String name) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   406
        try {
37343
35a2231828a7 8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents: 36935
diff changeset
   407
            VarHandle.AccessMode.valueFromMethodName(name);
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   408
            return true;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   409
        } catch (IllegalArgumentException e) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   410
            return false;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   411
        }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   412
    }
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   413
    private static final int MH_INVOKE_MODS = Modifier.NATIVE | Modifier.FINAL | Modifier.PUBLIC;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   414
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   415
    /** Utility method to query the modifier flags of this member. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   416
    public boolean isStatic() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   417
        return Modifier.isStatic(flags);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   418
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   419
    /** Utility method to query the modifier flags of this member. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   420
    public boolean isPublic() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   421
        return Modifier.isPublic(flags);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   422
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   423
    /** Utility method to query the modifier flags of this member. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   424
    public boolean isPrivate() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   425
        return Modifier.isPrivate(flags);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   426
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   427
    /** Utility method to query the modifier flags of this member. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   428
    public boolean isProtected() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   429
        return Modifier.isProtected(flags);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   430
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   431
    /** Utility method to query the modifier flags of this member. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   432
    public boolean isFinal() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   433
        return Modifier.isFinal(flags);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   434
    }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   435
    /** Utility method to query whether this member or its defining class is final. */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   436
    public boolean canBeStaticallyBound() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   437
        return Modifier.isFinal(flags | clazz.getModifiers());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   438
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   439
    /** Utility method to query the modifier flags of this member. */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   440
    public boolean isVolatile() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   441
        return Modifier.isVolatile(flags);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   442
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   443
    /** Utility method to query the modifier flags of this member. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   444
    public boolean isAbstract() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   445
        return Modifier.isAbstract(flags);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   446
    }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   447
    /** Utility method to query the modifier flags of this member. */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   448
    public boolean isNative() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   449
        return Modifier.isNative(flags);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   450
    }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   451
    // let the rest (native, volatile, transient, etc.) be tested via Modifier.isFoo
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   452
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   453
    // unofficial modifier flags, used by HotSpot:
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   454
    static final int BRIDGE    = 0x00000040;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   455
    static final int VARARGS   = 0x00000080;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   456
    static final int SYNTHETIC = 0x00001000;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   457
    static final int ANNOTATION= 0x00002000;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   458
    static final int ENUM      = 0x00004000;
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   459
    /** Utility method to query the modifier flags of this member; returns false if the member is not a method. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   460
    public boolean isBridge() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   461
        return testAllFlags(IS_METHOD | BRIDGE);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   462
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   463
    /** Utility method to query the modifier flags of this member; returns false if the member is not a method. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   464
    public boolean isVarargs() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   465
        return testAllFlags(VARARGS) && isInvocable();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   466
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   467
    /** Utility method to query the modifier flags of this member; returns false if the member is not a method. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   468
    public boolean isSynthetic() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   469
        return testAllFlags(SYNTHETIC);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   470
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   471
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   472
    static final String CONSTRUCTOR_NAME = "<init>";  // the ever-popular
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   473
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   474
    // modifiers exported by the JVM:
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   475
    static final int RECOGNIZED_MODIFIERS = 0xFFFF;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   476
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   477
    // private flags, not part of RECOGNIZED_MODIFIERS:
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   478
    static final int
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 14342
diff changeset
   479
            IS_METHOD        = MN_IS_METHOD,        // method (not constructor)
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 14342
diff changeset
   480
            IS_CONSTRUCTOR   = MN_IS_CONSTRUCTOR,   // constructor
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 14342
diff changeset
   481
            IS_FIELD         = MN_IS_FIELD,         // field
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 14342
diff changeset
   482
            IS_TYPE          = MN_IS_TYPE,          // nested type
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 14342
diff changeset
   483
            CALLER_SENSITIVE = MN_CALLER_SENSITIVE; // @CallerSensitive annotation detected
2707
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
    static final int ALL_ACCESS = Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   486
    static final int ALL_KINDS = IS_METHOD | IS_CONSTRUCTOR | IS_FIELD | IS_TYPE;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   487
    static final int IS_INVOCABLE = IS_METHOD | IS_CONSTRUCTOR;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   488
    static final int IS_FIELD_OR_METHOD = IS_METHOD | IS_FIELD;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   489
    static final int SEARCH_ALL_SUPERS = MN_SEARCH_SUPERCLASSES | MN_SEARCH_INTERFACES;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   490
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   491
    /** Utility method to query whether this member is a method or constructor. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   492
    public boolean isInvocable() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   493
        return testAnyFlags(IS_INVOCABLE);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   494
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   495
    /** Utility method to query whether this member is a method, constructor, or field. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   496
    public boolean isFieldOrMethod() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   497
        return testAnyFlags(IS_FIELD_OR_METHOD);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   498
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   499
    /** Query whether this member is a method. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   500
    public boolean isMethod() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   501
        return testAllFlags(IS_METHOD);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   502
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   503
    /** Query whether this member is a constructor. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   504
    public boolean isConstructor() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   505
        return testAllFlags(IS_CONSTRUCTOR);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   506
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   507
    /** Query whether this member is a field. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   508
    public boolean isField() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   509
        return testAllFlags(IS_FIELD);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   510
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   511
    /** Query whether this member is a type. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   512
    public boolean isType() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   513
        return testAllFlags(IS_TYPE);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   514
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   515
    /** Utility method to query whether this member is neither public, private, nor protected. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   516
    public boolean isPackage() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   517
        return !testAnyFlags(ALL_ACCESS);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   518
    }
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 14342
diff changeset
   519
    /** Query whether this member has a CallerSensitive annotation. */
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 14342
diff changeset
   520
    public boolean isCallerSensitive() {
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 14342
diff changeset
   521
        return testAllFlags(CALLER_SENSITIVE);
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 14342
diff changeset
   522
    }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   523
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   524
    /** Utility method to query whether this member is accessible from a given lookup class. */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   525
    public boolean isAccessibleFrom(Class<?> lookupClass) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34720
diff changeset
   526
        int mode = (ALL_ACCESS|MethodHandles.Lookup.PACKAGE|MethodHandles.Lookup.MODULE);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   527
        return VerifyAccess.isMemberAccessible(this.getDeclaringClass(), this.getDeclaringClass(), flags,
57512
f557f260b787 8173978: Lookup.in should allow teleporting from a lookup class in a named module without dropping all access
mchung
parents: 49641
diff changeset
   528
                                               lookupClass, null, mode);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   529
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   530
39342
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 38774
diff changeset
   531
    /**
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 38774
diff changeset
   532
     * Check if MemberName is a call to a method named {@code name} in class {@code declaredClass}.
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 38774
diff changeset
   533
     */
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 38774
diff changeset
   534
    public boolean refersTo(Class<?> declc, String n) {
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 38774
diff changeset
   535
        return clazz == declc && getName().equals(n);
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 38774
diff changeset
   536
    }
f66a89ed6fca 8143211: provide bytecode intrinsics for loop and try/finally executors
mhaupt
parents: 38774
diff changeset
   537
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   538
    /** Initialize a query.   It is not resolved. */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   539
    private void init(Class<?> defClass, String name, Object type, int flags) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   540
        // defining class is allowed to be null (for a naked name/type pair)
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   541
        //name.toString();  // null check
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   542
        //type.equals(type);  // null check
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   543
        // fill in fields:
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   544
        this.clazz = defClass;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   545
        this.name = name;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   546
        this.type = type;
13612
275711a5df25 7194612: api/java_lang/invoke/MethodHandles/Lookup/index.html#ExceptionsTests[findVirtualNSME] fails w/ -esa
jrose
parents: 13424
diff changeset
   547
        this.flags = flags;
275711a5df25 7194612: api/java_lang/invoke/MethodHandles/Lookup/index.html#ExceptionsTests[findVirtualNSME] fails w/ -esa
jrose
parents: 13424
diff changeset
   548
        assert(testAnyFlags(ALL_KINDS));
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   549
        assert(this.resolution == null);  // nobody should have touched this yet
13612
275711a5df25 7194612: api/java_lang/invoke/MethodHandles/Lookup/index.html#ExceptionsTests[findVirtualNSME] fails w/ -esa
jrose
parents: 13424
diff changeset
   550
        //assert(referenceKindIsConsistent());  // do this after resolution
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   551
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   552
20472
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   553
    /**
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   554
     * Calls down to the VM to fill in the fields.  This method is
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   555
     * synchronized to avoid racing calls.
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   556
     */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   557
    private void expandFromVM() {
20472
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   558
        if (type != null) {
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   559
            return;
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   560
        }
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   561
        if (!isResolved()) {
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   562
            return;
6adc9f6bb215 8019192: StringIndexOutOfBoundsException: in Class.getSimpleName()
twisti
parents: 19804
diff changeset
   563
        }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   564
        MethodHandleNatives.expand(this);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   565
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   566
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   567
    // Capturing information from the Core Reflection API:
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   568
    private static int flagsMods(int flags, int mods, byte refKind) {
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   569
        assert((flags & RECOGNIZED_MODIFIERS) == 0);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   570
        assert((mods & ~RECOGNIZED_MODIFIERS) == 0);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   571
        assert((refKind & ~MN_REFERENCE_KIND_MASK) == 0);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   572
        return flags | mods | (refKind << MN_REFERENCE_KIND_SHIFT);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   573
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   574
    /** Create a name for the given reflected method.  The resulting name will be in a resolved state. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   575
    public MemberName(Method m) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   576
        this(m, false);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   577
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   578
    @SuppressWarnings("LeakingThisInConstructor")
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   579
    public MemberName(Method m, boolean wantSpecial) {
29094
a4fd2b5e49f8 8073479: Replace obj.getClass hacks with Objects.requireNonNull
shade
parents: 26467
diff changeset
   580
        Objects.requireNonNull(m);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   581
        // fill in vmtarget, vmindex while we have m in hand:
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   582
        MethodHandleNatives.init(this, m);
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   583
        if (clazz == null) {  // MHN.init failed
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   584
            if (m.getDeclaringClass() == MethodHandle.class &&
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   585
                isMethodHandleInvokeName(m.getName())) {
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   586
                // The JVM did not reify this signature-polymorphic instance.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   587
                // Need a special case here.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   588
                // See comments on MethodHandleNatives.linkMethod.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   589
                MethodType type = MethodType.methodType(m.getReturnType(), m.getParameterTypes());
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   590
                int flags = flagsMods(IS_METHOD, m.getModifiers(), REF_invokeVirtual);
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   591
                init(MethodHandle.class, m.getName(), type, flags);
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   592
                if (isMethodHandleInvoke())
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   593
                    return;
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   594
            }
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   595
            if (m.getDeclaringClass() == VarHandle.class &&
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   596
                isVarHandleMethodInvokeName(m.getName())) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   597
                // The JVM did not reify this signature-polymorphic instance.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   598
                // Need a special case here.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   599
                // See comments on MethodHandleNatives.linkMethod.
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   600
                MethodType type = MethodType.methodType(m.getReturnType(), m.getParameterTypes());
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   601
                int flags = flagsMods(IS_METHOD, m.getModifiers(), REF_invokeVirtual);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   602
                init(VarHandle.class, m.getName(), type, flags);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   603
                if (isVarHandleMethodInvoke())
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   604
                    return;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   605
            }
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   606
            throw new LinkageError(m.toString());
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   607
        }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   608
        assert(isResolved() && this.clazz != null);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   609
        this.name = m.getName();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   610
        if (this.type == null)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   611
            this.type = new Object[] { m.getReturnType(), m.getParameterTypes() };
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   612
        if (wantSpecial) {
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   613
            if (isAbstract())
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   614
                throw new AbstractMethodError(this.toString());
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   615
            if (getReferenceKind() == REF_invokeVirtual)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   616
                changeReferenceKind(REF_invokeSpecial, REF_invokeVirtual);
17461
84860231159b 8008687: MethodHandle code: allow static and invokespecial calls to interface methods
bharadwaj
parents: 16906
diff changeset
   617
            else if (getReferenceKind() == REF_invokeInterface)
84860231159b 8008687: MethodHandle code: allow static and invokespecial calls to interface methods
bharadwaj
parents: 16906
diff changeset
   618
                // invokeSpecial on a default method
84860231159b 8008687: MethodHandle code: allow static and invokespecial calls to interface methods
bharadwaj
parents: 16906
diff changeset
   619
                changeReferenceKind(REF_invokeSpecial, REF_invokeInterface);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   620
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   621
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   622
    public MemberName asSpecial() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   623
        switch (getReferenceKind()) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   624
        case REF_invokeSpecial:     return this;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   625
        case REF_invokeVirtual:     return clone().changeReferenceKind(REF_invokeSpecial, REF_invokeVirtual);
17461
84860231159b 8008687: MethodHandle code: allow static and invokespecial calls to interface methods
bharadwaj
parents: 16906
diff changeset
   626
        case REF_invokeInterface:   return clone().changeReferenceKind(REF_invokeSpecial, REF_invokeInterface);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   627
        case REF_newInvokeSpecial:  return clone().changeReferenceKind(REF_invokeSpecial, REF_newInvokeSpecial);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   628
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   629
        throw new IllegalArgumentException(this.toString());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   630
    }
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   631
    /** If this MN is not REF_newInvokeSpecial, return a clone with that ref. kind.
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   632
     *  In that case it must already be REF_invokeSpecial.
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   633
     */
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   634
    public MemberName asConstructor() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   635
        switch (getReferenceKind()) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   636
        case REF_invokeSpecial:     return clone().changeReferenceKind(REF_newInvokeSpecial, REF_invokeSpecial);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   637
        case REF_newInvokeSpecial:  return this;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   638
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   639
        throw new IllegalArgumentException(this.toString());
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   640
    }
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   641
    /** If this MN is a REF_invokeSpecial, return a clone with the "normal" kind
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   642
     *  REF_invokeVirtual; also switch either to REF_invokeInterface if clazz.isInterface.
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   643
     *  The end result is to get a fully virtualized version of the MN.
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   644
     *  (Note that resolving in the JVM will sometimes devirtualize, changing
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   645
     *  REF_invokeVirtual of a final to REF_invokeSpecial, and REF_invokeInterface
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   646
     *  in some corner cases to either of the previous two; this transform
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   647
     *  undoes that change under the assumption that it occurred.)
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   648
     */
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   649
    public MemberName asNormalOriginal() {
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   650
        byte normalVirtual = clazz.isInterface() ? REF_invokeInterface : REF_invokeVirtual;
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   651
        byte refKind = getReferenceKind();
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   652
        byte newRefKind = refKind;
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   653
        MemberName result = this;
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   654
        switch (refKind) {
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   655
        case REF_invokeInterface:
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   656
        case REF_invokeVirtual:
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   657
        case REF_invokeSpecial:
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   658
            newRefKind = normalVirtual;
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   659
            break;
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   660
        }
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   661
        if (newRefKind == refKind)
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   662
            return this;
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   663
        result = clone().changeReferenceKind(newRefKind, refKind);
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   664
        assert(this.referenceKindIsConsistentWith(result.getReferenceKind()));
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   665
        return result;
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   666
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   667
    /** Create a name for the given reflected constructor.  The resulting name will be in a resolved state. */
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   668
    @SuppressWarnings("LeakingThisInConstructor")
11534
9949ffb8eb3a 7117167: Misc warnings in java.lang.invoke and sun.invoke.*
jrose
parents: 10419
diff changeset
   669
    public MemberName(Constructor<?> ctor) {
29094
a4fd2b5e49f8 8073479: Replace obj.getClass hacks with Objects.requireNonNull
shade
parents: 26467
diff changeset
   670
        Objects.requireNonNull(ctor);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   671
        // fill in vmtarget, vmindex while we have ctor in hand:
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   672
        MethodHandleNatives.init(this, ctor);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   673
        assert(isResolved() && this.clazz != null);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   674
        this.name = CONSTRUCTOR_NAME;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   675
        if (this.type == null)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   676
            this.type = new Object[] { void.class, ctor.getParameterTypes() };
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   677
    }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   678
    /** Create a name for the given reflected field.  The resulting name will be in a resolved state.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   679
     */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   680
    public MemberName(Field fld) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   681
        this(fld, false);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   682
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   683
    @SuppressWarnings("LeakingThisInConstructor")
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   684
    public MemberName(Field fld, boolean makeSetter) {
29094
a4fd2b5e49f8 8073479: Replace obj.getClass hacks with Objects.requireNonNull
shade
parents: 26467
diff changeset
   685
        Objects.requireNonNull(fld);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   686
        // fill in vmtarget, vmindex while we have fld in hand:
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   687
        MethodHandleNatives.init(this, fld);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   688
        assert(isResolved() && this.clazz != null);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   689
        this.name = fld.getName();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   690
        this.type = fld.getType();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   691
        assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   692
        byte refKind = this.getReferenceKind();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   693
        assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   694
        if (makeSetter) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   695
            changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   696
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   697
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   698
    public boolean isGetter() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   699
        return MethodHandleNatives.refKindIsGetter(getReferenceKind());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   700
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   701
    public boolean isSetter() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   702
        return MethodHandleNatives.refKindIsSetter(getReferenceKind());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   703
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   704
    public MemberName asSetter() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   705
        byte refKind = getReferenceKind();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   706
        assert(MethodHandleNatives.refKindIsGetter(refKind));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   707
        assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   708
        byte setterRefKind = (byte)(refKind + (REF_putField - REF_getField));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   709
        return clone().changeReferenceKind(setterRefKind, refKind);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   710
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   711
    /** Create a name for the given class.  The resulting name will be in a resolved state. */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   712
    public MemberName(Class<?> type) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   713
        init(type.getDeclaringClass(), type.getSimpleName(), type,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   714
                flagsMods(IS_TYPE, type.getModifiers(), REF_NONE));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   715
        initResolved(true);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   716
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   717
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   718
    /**
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   719
     * Create a name for a signature-polymorphic invoker.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   720
     * This is a placeholder for a signature-polymorphic instance
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   721
     * (of MH.invokeExact, etc.) that the JVM does not reify.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   722
     * See comments on {@link MethodHandleNatives#linkMethod}.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   723
     */
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   724
    static MemberName makeMethodHandleInvoke(String name, MethodType type) {
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   725
        return makeMethodHandleInvoke(name, type, MH_INVOKE_MODS | SYNTHETIC);
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   726
    }
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   727
    static MemberName makeMethodHandleInvoke(String name, MethodType type, int mods) {
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   728
        MemberName mem = new MemberName(MethodHandle.class, name, type, REF_invokeVirtual);
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   729
        mem.flags |= mods;  // it's not resolved, but add these modifiers anyway
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   730
        assert(mem.isMethodHandleInvoke()) : mem;
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   731
        return mem;
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   732
    }
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 17461
diff changeset
   733
36934
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   734
    static MemberName makeVarHandleMethodInvoke(String name, MethodType type) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   735
        return makeVarHandleMethodInvoke(name, type, MH_INVOKE_MODS | SYNTHETIC);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   736
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   737
    static MemberName makeVarHandleMethodInvoke(String name, MethodType type, int mods) {
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   738
        MemberName mem = new MemberName(VarHandle.class, name, type, REF_invokeVirtual);
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   739
        mem.flags |= mods;  // it's not resolved, but add these modifiers anyway
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   740
        assert(mem.isVarHandleMethodInvoke()) : mem;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   741
        return mem;
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   742
    }
590fc47a0aeb 8149644: Integrate VarHandles
psandoz
parents: 34720
diff changeset
   743
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   744
    // bare-bones constructor; the JVM will fill it in
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   745
    MemberName() { }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   746
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   747
    // locally useful cloner
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   748
    @Override protected MemberName clone() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   749
        try {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   750
            return (MemberName) super.clone();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   751
        } catch (CloneNotSupportedException ex) {
14089
0a41b980d62a 8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents: 13612
diff changeset
   752
            throw newInternalError(ex);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   753
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   754
     }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   755
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   756
    /** Get the definition of this member name.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   757
     *  This may be in a super-class of the declaring class of this member.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   758
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   759
    public MemberName getDefinition() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   760
        if (!isResolved())  throw new IllegalStateException("must be resolved: "+this);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   761
        if (isType())  return this;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   762
        MemberName res = this.clone();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   763
        res.clazz = null;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   764
        res.type = null;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   765
        res.name = null;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   766
        res.resolution = res;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   767
        res.expandFromVM();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   768
        assert(res.getName().equals(this.getName()));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   769
        return res;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   770
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   771
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   772
    @Override
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 37343
diff changeset
   773
    @SuppressWarnings("deprecation")
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   774
    public int hashCode() {
33649
5e51019fc94d 8141677: Improve java.lang.invoke.MemberName hashCode implementation
redestad
parents: 32986
diff changeset
   775
        // Avoid autoboxing getReferenceKind(), since this is used early and will force
5e51019fc94d 8141677: Improve java.lang.invoke.MemberName hashCode implementation
redestad
parents: 32986
diff changeset
   776
        // early initialization of Byte$ByteCache
5e51019fc94d 8141677: Improve java.lang.invoke.MemberName hashCode implementation
redestad
parents: 32986
diff changeset
   777
        return Objects.hash(clazz, new Byte(getReferenceKind()), name, getType());
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   778
    }
33649
5e51019fc94d 8141677: Improve java.lang.invoke.MemberName hashCode implementation
redestad
parents: 32986
diff changeset
   779
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   780
    @Override
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   781
    public boolean equals(Object that) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   782
        return (that instanceof MemberName && this.equals((MemberName)that));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   783
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   784
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   785
    /** Decide if two member names have exactly the same symbolic content.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   786
     *  Does not take into account any actual class members, so even if
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   787
     *  two member names resolve to the same actual member, they may
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   788
     *  be distinct references.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   789
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   790
    public boolean equals(MemberName that) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   791
        if (this == that)  return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   792
        if (that == null)  return false;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   793
        return this.clazz == that.clazz
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   794
                && this.getReferenceKind() == that.getReferenceKind()
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   795
                && Objects.equals(this.name, that.name)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   796
                && Objects.equals(this.getType(), that.getType());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   797
    }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   798
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   799
    // Construction from symbolic parts, for queries:
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   800
    /** Create a field or type name from the given components:
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   801
     *  Declaring class, name, type, reference kind.
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   802
     *  The declaring class may be supplied as null if this is to be a bare name and type.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   803
     *  The resulting name will in an unresolved state.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   804
     */
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   805
    public MemberName(Class<?> defClass, String name, Class<?> type, byte refKind) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   806
        init(defClass, name, type, flagsMods(IS_FIELD, 0, refKind));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   807
        initResolved(false);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   808
    }
26467
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   809
    /** Create a method or constructor name from the given components:
d69abed3a07d 8050052: Small cleanups in java.lang.invoke code
vlivanov
parents: 25991
diff changeset
   810
     *  Declaring class, name, type, reference kind.
32276
2d5fcc89e099 8134356: {@code} tag contains &lt; and &gt; sequences
igerasim
parents: 29094
diff changeset
   811
     *  It will be a constructor if and only if the name is {@code "<init>"}.
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   812
     *  The declaring class may be supplied as null if this is to be a bare name and type.
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   813
     *  The last argument is optional, a boolean which requests REF_invokeSpecial.
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   814
     *  The resulting name will in an unresolved state.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   815
     */
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   816
    public MemberName(Class<?> defClass, String name, MethodType type, byte refKind) {
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   817
        int initFlags = (name != null && name.equals(CONSTRUCTOR_NAME) ? IS_CONSTRUCTOR : IS_METHOD);
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   818
        init(defClass, name, type, flagsMods(initFlags, 0, refKind));
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   819
        initResolved(false);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   820
    }
20527
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   821
    /** Create a method, constructor, or field name from the given components:
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   822
     *  Reference kind, declaring class, name, type.
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   823
     */
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   824
    public MemberName(byte refKind, Class<?> defClass, String name, Object type) {
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   825
        int kindFlags;
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   826
        if (MethodHandleNatives.refKindIsField(refKind)) {
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   827
            kindFlags = IS_FIELD;
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   828
            if (!(type instanceof Class))
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   829
                throw newIllegalArgumentException("not a field type");
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   830
        } else if (MethodHandleNatives.refKindIsMethod(refKind)) {
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   831
            kindFlags = IS_METHOD;
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   832
            if (!(type instanceof MethodType))
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   833
                throw newIllegalArgumentException("not a method type");
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   834
        } else if (refKind == REF_newInvokeSpecial) {
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   835
            kindFlags = IS_CONSTRUCTOR;
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   836
            if (!(type instanceof MethodType) ||
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   837
                !CONSTRUCTOR_NAME.equals(name))
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   838
                throw newIllegalArgumentException("not a constructor type or name");
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   839
        } else {
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   840
            throw newIllegalArgumentException("bad reference kind "+refKind);
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   841
        }
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   842
        init(defClass, name, type, flagsMods(kindFlags, 0, refKind));
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   843
        initResolved(false);
d241258cfbcb 8024761: JSR 292 improve performance of generic invocation
jrose
parents: 20472
diff changeset
   844
    }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   845
    /** Query whether this member name is resolved to a non-static, non-final method.
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   846
     */
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   847
    public boolean hasReceiverTypeDispatch() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   848
        return MethodHandleNatives.refKindDoesDispatch(getReferenceKind());
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   849
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   850
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   851
    /** Query whether this member name is resolved.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   852
     *  A resolved member name is one for which the JVM has found
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   853
     *  a method, constructor, field, or type binding corresponding exactly to the name.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   854
     *  (Document?)
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   855
     */
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   856
    public boolean isResolved() {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   857
        return resolution == null;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   858
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   859
40272
6af4511ee5a4 8163878: Remove unnecessary bridge methods, allocations in java.lang.invoke
redestad
parents: 40258
diff changeset
   860
    void initResolved(boolean isResolved) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   861
        assert(this.resolution == null);  // not initialized yet!
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   862
        if (!isResolved)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   863
            this.resolution = this;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   864
        assert(isResolved() == isResolved);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   865
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   866
37585
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
   867
    void checkForTypeAlias(Class<?> refc) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   868
        if (isInvocable()) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   869
            MethodType type;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   870
            if (this.type instanceof MethodType)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   871
                type = (MethodType) this.type;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   872
            else
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   873
                this.type = type = getMethodType();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   874
            if (type.erase() == type)  return;
37585
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
   875
            if (VerifyAccess.isTypeVisible(type, refc))  return;
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
   876
            throw new LinkageError("bad method type alias: "+type+" not visible from "+refc);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   877
        } else {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   878
            Class<?> type;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   879
            if (this.type instanceof Class<?>)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   880
                type = (Class<?>) this.type;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   881
            else
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   882
                this.type = type = getFieldType();
37585
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
   883
            if (VerifyAccess.isTypeVisible(type, refc))  return;
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
   884
            throw new LinkageError("bad field type alias: "+type+" not visible from "+refc);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   885
        }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   886
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   887
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   888
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   889
    /** Produce a string form of this member name.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   890
     *  For types, it is simply the type's own string (as reported by {@code toString}).
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   891
     *  For fields, it is {@code "DeclaringClass.name/type"}.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   892
     *  For methods and constructors, it is {@code "DeclaringClass.name(ptype...)rtype"}.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   893
     *  If the declaring class is null, the prefix {@code "DeclaringClass."} is omitted.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   894
     *  If the member is unresolved, a prefix {@code "*."} is prepended.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   895
     */
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   896
    @SuppressWarnings("LocalVariableHidesMemberVariable")
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   897
    @Override
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   898
    public String toString() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   899
        if (isType())
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   900
            return type.toString();  // class java.lang.String
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   901
        // else it is a field, method, or constructor
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   902
        StringBuilder buf = new StringBuilder();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   903
        if (getDeclaringClass() != null) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   904
            buf.append(getName(clazz));
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   905
            buf.append('.');
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   906
        }
48514
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 47294
diff changeset
   907
        String name = this.name; // avoid expanding from VM
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   908
        buf.append(name == null ? "*" : name);
48514
9608f7f41c4e 8188145: MethodHandle resolution should follow JVMS sequence of lookup by name & type before type descriptor resolution
vlivanov
parents: 47294
diff changeset
   909
        Object type = this.type; // avoid expanding from VM
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   910
        if (!isInvocable()) {
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   911
            buf.append('/');
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   912
            buf.append(type == null ? "*" : getName(type));
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   913
        } else {
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   914
            buf.append(type == null ? "(*)*" : getName(type));
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   915
        }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   916
        byte refKind = getReferenceKind();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   917
        if (refKind != REF_NONE) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   918
            buf.append('/');
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   919
            buf.append(MethodHandleNatives.refKindName(refKind));
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   920
        }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   921
        //buf.append("#").append(System.identityHashCode(this));
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   922
        return buf.toString();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   923
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   924
    private static String getName(Object obj) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   925
        if (obj instanceof Class<?>)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   926
            return ((Class<?>)obj).getName();
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
   927
        return String.valueOf(obj);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   928
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   929
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   930
    public IllegalAccessException makeAccessException(String message, Object from) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   931
        message = message + ": "+ toString();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34720
diff changeset
   932
        if (from != null)  {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34720
diff changeset
   933
            if (from == MethodHandles.publicLookup()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34720
diff changeset
   934
                message += ", from public Lookup";
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34720
diff changeset
   935
            } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34720
diff changeset
   936
                Module m;
57512
f557f260b787 8173978: Lookup.in should allow teleporting from a lookup class in a named module without dropping all access
mchung
parents: 49641
diff changeset
   937
                Class<?> plc;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34720
diff changeset
   938
                if (from instanceof MethodHandles.Lookup) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34720
diff changeset
   939
                    MethodHandles.Lookup lookup = (MethodHandles.Lookup)from;
57512
f557f260b787 8173978: Lookup.in should allow teleporting from a lookup class in a named module without dropping all access
mchung
parents: 49641
diff changeset
   940
                    from = lookup.lookupClass();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34720
diff changeset
   941
                    m = lookup.lookupClass().getModule();
57512
f557f260b787 8173978: Lookup.in should allow teleporting from a lookup class in a named module without dropping all access
mchung
parents: 49641
diff changeset
   942
                    plc = lookup.previousLookupClass();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34720
diff changeset
   943
                } else {
57512
f557f260b787 8173978: Lookup.in should allow teleporting from a lookup class in a named module without dropping all access
mchung
parents: 49641
diff changeset
   944
                    m = ((Class<?>)from).getModule();
f557f260b787 8173978: Lookup.in should allow teleporting from a lookup class in a named module without dropping all access
mchung
parents: 49641
diff changeset
   945
                    plc = null;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34720
diff changeset
   946
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34720
diff changeset
   947
                message += ", from " + from + " (" + m + ")";
57512
f557f260b787 8173978: Lookup.in should allow teleporting from a lookup class in a named module without dropping all access
mchung
parents: 49641
diff changeset
   948
                if (plc != null) {
f557f260b787 8173978: Lookup.in should allow teleporting from a lookup class in a named module without dropping all access
mchung
parents: 49641
diff changeset
   949
                    message += ", previous lookup " +
f557f260b787 8173978: Lookup.in should allow teleporting from a lookup class in a named module without dropping all access
mchung
parents: 49641
diff changeset
   950
                        plc.getName() + " (" + plc.getModule() + ")";
f557f260b787 8173978: Lookup.in should allow teleporting from a lookup class in a named module without dropping all access
mchung
parents: 49641
diff changeset
   951
                }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34720
diff changeset
   952
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34720
diff changeset
   953
        }
8347
e5daa5772ffd 7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents: 7052
diff changeset
   954
        return new IllegalAccessException(message);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   955
    }
9752
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 9646
diff changeset
   956
    private String message() {
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 9646
diff changeset
   957
        if (isResolved())
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 9646
diff changeset
   958
            return "no access";
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 9646
diff changeset
   959
        else if (isConstructor())
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 9646
diff changeset
   960
            return "no such constructor";
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 9646
diff changeset
   961
        else if (isMethod())
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 9646
diff changeset
   962
            return "no such method";
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 9646
diff changeset
   963
        else
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 9646
diff changeset
   964
            return "no such field";
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 9646
diff changeset
   965
    }
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 9646
diff changeset
   966
    public ReflectiveOperationException makeAccessException() {
88ab34b6da6d 7032323: code changes for JSR 292 EG adjustments to API, through Public Review
jrose
parents: 9646
diff changeset
   967
        String message = message() + ": "+ toString();
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   968
        ReflectiveOperationException ex;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   969
        if (isResolved() || !(resolution instanceof NoSuchMethodError ||
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   970
                              resolution instanceof NoSuchFieldError))
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   971
            ex = new IllegalAccessException(message);
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   972
        else if (isConstructor())
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   973
            ex = new NoSuchMethodException(message);
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   974
        else if (isMethod())
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   975
            ex = new NoSuchMethodException(message);
8347
e5daa5772ffd 7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents: 7052
diff changeset
   976
        else
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   977
            ex = new NoSuchFieldException(message);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   978
        if (resolution instanceof Throwable)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   979
            ex.initCause((Throwable) resolution);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   980
        return ex;
7052
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5725
diff changeset
   981
    }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   982
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   983
    /** Actually making a query requires an access check. */
59201
b24f4caa1411 8234335: Remove line break in class declaration in java.base
jboes
parents: 57512
diff changeset
   984
    /*non-public*/
b24f4caa1411 8234335: Remove line break in class declaration in java.base
jboes
parents: 57512
diff changeset
   985
    static Factory getFactory() {
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   986
        return Factory.INSTANCE;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   987
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   988
    /** A factory type for resolving member names with the help of the VM.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   989
     *  TBD: Define access-safe public constructors for this factory.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   990
     */
59201
b24f4caa1411 8234335: Remove line break in class declaration in java.base
jboes
parents: 57512
diff changeset
   991
    /*non-public*/
b24f4caa1411 8234335: Remove line break in class declaration in java.base
jboes
parents: 57512
diff changeset
   992
    static class Factory {
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   993
        private Factory() { } // singleton pattern
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   994
        static Factory INSTANCE = new Factory();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   995
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
   996
        private static int ALLOWED_FLAGS = ALL_KINDS;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   997
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   998
        /// Queries
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   999
        List<MemberName> getMembers(Class<?> defc,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1000
                String matchName, Object matchType,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1001
                int matchFlags, Class<?> lookupClass) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1002
            matchFlags &= ALLOWED_FLAGS;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1003
            String matchSig = null;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1004
            if (matchType != null) {
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
  1005
                matchSig = BytecodeDescriptor.unparse(matchType);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1006
                if (matchSig.startsWith("("))
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1007
                    matchFlags &= ~(ALL_KINDS & ~IS_INVOCABLE);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1008
                else
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1009
                    matchFlags &= ~(ALL_KINDS & ~IS_FIELD);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1010
            }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1011
            final int BUF_MAX = 0x2000;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1012
            int len1 = matchName == null ? 10 : matchType == null ? 4 : 1;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1013
            MemberName[] buf = newMemberBuffer(len1);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1014
            int totalCount = 0;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1015
            ArrayList<MemberName[]> bufs = null;
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
  1016
            int bufCount = 0;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1017
            for (;;) {
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
  1018
                bufCount = MethodHandleNatives.getMembers(defc,
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1019
                        matchName, matchSig, matchFlags,
2764
2e45af54c0f9 6839839: access checking logic is wrong at three points in MethodHandles
jrose
parents: 2707
diff changeset
  1020
                        lookupClass,
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1021
                        totalCount, buf);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1022
                if (bufCount <= buf.length) {
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
  1023
                    if (bufCount < 0)  bufCount = 0;
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
  1024
                    totalCount += bufCount;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1025
                    break;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1026
                }
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
  1027
                // JVM returned to us with an intentional overflow!
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1028
                totalCount += buf.length;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1029
                int excess = bufCount - buf.length;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1030
                if (bufs == null)  bufs = new ArrayList<>(1);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1031
                bufs.add(buf);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1032
                int len2 = buf.length;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1033
                len2 = Math.max(len2, excess);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1034
                len2 = Math.max(len2, totalCount / 4);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1035
                buf = newMemberBuffer(Math.min(BUF_MAX, len2));
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1036
            }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1037
            ArrayList<MemberName> result = new ArrayList<>(totalCount);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1038
            if (bufs != null) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1039
                for (MemberName[] buf0 : bufs) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1040
                    Collections.addAll(result, buf0);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1041
                }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1042
            }
40256
c5e03eaf7ba2 8163370: Reduce number of classes loaded by common usage of java.lang.invoke
redestad
parents: 39754
diff changeset
  1043
            for (int i = 0; i < bufCount; i++) {
c5e03eaf7ba2 8163370: Reduce number of classes loaded by common usage of java.lang.invoke
redestad
parents: 39754
diff changeset
  1044
                result.add(buf[i]);
c5e03eaf7ba2 8163370: Reduce number of classes loaded by common usage of java.lang.invoke
redestad
parents: 39754
diff changeset
  1045
            }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1046
            // Signature matching is not the same as type matching, since
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1047
            // one signature might correspond to several types.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1048
            // So if matchType is a Class or MethodType, refilter the results.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1049
            if (matchType != null && matchType != matchSig) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1050
                for (Iterator<MemberName> it = result.iterator(); it.hasNext();) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1051
                    MemberName m = it.next();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1052
                    if (!matchType.equals(m.getType()))
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1053
                        it.remove();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1054
                }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1055
            }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1056
            return result;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1057
        }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1058
        /** Produce a resolved version of the given member.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1059
         *  Super types are searched (for inherited members) if {@code searchSupers} is true.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1060
         *  Access checking is performed on behalf of the given {@code lookupClass}.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1061
         *  If lookup fails or access is not permitted, null is returned.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1062
         *  Otherwise a fresh copy of the given member is returned, with modifier bits filled in.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1063
         */
49641
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 48514
diff changeset
  1064
        private MemberName resolve(byte refKind, MemberName ref, Class<?> lookupClass,
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 48514
diff changeset
  1065
                                   boolean speculativeResolve) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1066
            MemberName m = ref.clone();  // JVM will side-effect the ref
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1067
            assert(refKind == m.getReferenceKind());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1068
            try {
37585
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
  1069
                // There are 4 entities in play here:
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
  1070
                //   * LC: lookupClass
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
  1071
                //   * REFC: symbolic reference class (MN.clazz before resolution);
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
  1072
                //   * DEFC: resolved method holder (MN.clazz after resolution);
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
  1073
                //   * PTYPES: parameter types (MN.type)
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
  1074
                //
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
  1075
                // What we care about when resolving a MemberName is consistency between DEFC and PTYPES.
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
  1076
                // We do type alias (TA) checks on DEFC to ensure that. DEFC is not known until the JVM
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
  1077
                // finishes the resolution, so do TA checks right after MHN.resolve() is over.
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
  1078
                //
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
  1079
                // All parameters passed by a caller are checked against MH type (PTYPES) on every invocation,
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
  1080
                // so it is safe to call a MH from any context.
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
  1081
                //
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
  1082
                // REFC view on PTYPES doesn't matter, since it is used only as a starting point for resolution and doesn't
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
  1083
                // participate in method selection.
49641
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 48514
diff changeset
  1084
                m = MethodHandleNatives.resolve(m, lookupClass, speculativeResolve);
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 48514
diff changeset
  1085
                if (m == null && speculativeResolve) {
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 48514
diff changeset
  1086
                    return null;
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 48514
diff changeset
  1087
                }
37585
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
  1088
                m.checkForTypeAlias(m.getDeclaringClass());
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1089
                m.resolution = null;
37585
63061ecdf354 8152335: Improve MethodHandle consistency
vlivanov
parents: 37535
diff changeset
  1090
            } catch (ClassNotFoundException | LinkageError ex) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1091
                // JVM reports that the "bytecode behavior" would get an error
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1092
                assert(!m.isResolved());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1093
                m.resolution = ex;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1094
                return m;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1095
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1096
            assert(m.referenceKindIsConsistent());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1097
            m.initResolved(true);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1098
            assert(m.vminfoIsConsistent());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1099
            return m;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1100
        }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1101
        /** Produce a resolved version of the given member.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1102
         *  Super types are searched (for inherited members) if {@code searchSupers} is true.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1103
         *  Access checking is performed on behalf of the given {@code lookupClass}.
8347
e5daa5772ffd 7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents: 7052
diff changeset
  1104
         *  If lookup fails or access is not permitted, a {@linkplain ReflectiveOperationException} is thrown.
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1105
         *  Otherwise a fresh copy of the given member is returned, with modifier bits filled in.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1106
         */
59201
b24f4caa1411 8234335: Remove line break in class declaration in java.base
jboes
parents: 57512
diff changeset
  1107
        public <NoSuchMemberException extends ReflectiveOperationException>
b24f4caa1411 8234335: Remove line break in class declaration in java.base
jboes
parents: 57512
diff changeset
  1108
                MemberName resolveOrFail(byte refKind, MemberName m, Class<?> lookupClass,
8347
e5daa5772ffd 7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents: 7052
diff changeset
  1109
                                 Class<NoSuchMemberException> nsmClass)
e5daa5772ffd 7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents: 7052
diff changeset
  1110
                throws IllegalAccessException, NoSuchMemberException {
49641
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 48514
diff changeset
  1111
            MemberName result = resolve(refKind, m, lookupClass, false);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1112
            if (result.isResolved())
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1113
                return result;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1114
            ReflectiveOperationException ex = result.makeAccessException();
8347
e5daa5772ffd 7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents: 7052
diff changeset
  1115
            if (ex instanceof IllegalAccessException)  throw (IllegalAccessException) ex;
e5daa5772ffd 7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents: 7052
diff changeset
  1116
            throw nsmClass.cast(ex);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1117
        }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1118
        /** Produce a resolved version of the given member.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1119
         *  Super types are searched (for inherited members) if {@code searchSupers} is true.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1120
         *  Access checking is performed on behalf of the given {@code lookupClass}.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1121
         *  If lookup fails or access is not permitted, return null.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1122
         *  Otherwise a fresh copy of the given member is returned, with modifier bits filled in.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1123
         */
59201
b24f4caa1411 8234335: Remove line break in class declaration in java.base
jboes
parents: 57512
diff changeset
  1124
        public MemberName resolveOrNull(byte refKind, MemberName m, Class<?> lookupClass) {
49641
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 48514
diff changeset
  1125
            MemberName result = resolve(refKind, m, lookupClass, true);
2ad3212a7dd9 8200238: Reduce number of exceptions created when calling MemberName$Factory::resolveOrNull
redestad
parents: 48514
diff changeset
  1126
            if (result != null && result.isResolved())
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1127
                return result;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1128
            return null;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13421
diff changeset
  1129
        }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1130
        /** Return a list of all methods defined by the given class.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1131
         *  Super types are searched (for inherited members) if {@code searchSupers} is true.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1132
         *  Access checking is performed on behalf of the given {@code lookupClass}.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1133
         *  Inaccessible members are not added to the last.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1134
         */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1135
        public List<MemberName> getMethods(Class<?> defc, boolean searchSupers,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1136
                Class<?> lookupClass) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1137
            return getMethods(defc, searchSupers, null, null, lookupClass);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1138
        }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1139
        /** Return a list of matching methods defined by the given class.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1140
         *  Super types are searched (for inherited members) if {@code searchSupers} is true.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1141
         *  Returned methods will match the name (if not null) and the type (if not null).
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1142
         *  Access checking is performed on behalf of the given {@code lookupClass}.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1143
         *  Inaccessible members are not added to the last.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1144
         */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1145
        public List<MemberName> getMethods(Class<?> defc, boolean searchSupers,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1146
                String name, MethodType type, Class<?> lookupClass) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1147
            int matchFlags = IS_METHOD | (searchSupers ? SEARCH_ALL_SUPERS : 0);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1148
            return getMembers(defc, name, type, matchFlags, lookupClass);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1149
        }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1150
        /** Return a list of all constructors defined by the given class.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1151
         *  Access checking is performed on behalf of the given {@code lookupClass}.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1152
         *  Inaccessible members are not added to the last.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1153
         */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1154
        public List<MemberName> getConstructors(Class<?> defc, Class<?> lookupClass) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1155
            return getMembers(defc, null, null, IS_CONSTRUCTOR, lookupClass);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1156
        }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1157
        /** Return a list of all fields defined by the given class.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1158
         *  Super types are searched (for inherited members) if {@code searchSupers} is true.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1159
         *  Access checking is performed on behalf of the given {@code lookupClass}.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1160
         *  Inaccessible members are not added to the last.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1161
         */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1162
        public List<MemberName> getFields(Class<?> defc, boolean searchSupers,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1163
                Class<?> lookupClass) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1164
            return getFields(defc, searchSupers, null, null, lookupClass);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1165
        }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1166
        /** Return a list of all fields defined by the given class.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1167
         *  Super types are searched (for inherited members) if {@code searchSupers} is true.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1168
         *  Returned fields will match the name (if not null) and the type (if not null).
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1169
         *  Access checking is performed on behalf of the given {@code lookupClass}.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1170
         *  Inaccessible members are not added to the last.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1171
         */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1172
        public List<MemberName> getFields(Class<?> defc, boolean searchSupers,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1173
                String name, Class<?> type, Class<?> lookupClass) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1174
            int matchFlags = IS_FIELD | (searchSupers ? SEARCH_ALL_SUPERS : 0);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1175
            return getMembers(defc, name, type, matchFlags, lookupClass);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1176
        }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1177
        /** Return a list of all nested types defined by the given class.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1178
         *  Super types are searched (for inherited members) if {@code searchSupers} is true.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1179
         *  Access checking is performed on behalf of the given {@code lookupClass}.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1180
         *  Inaccessible members are not added to the last.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
  1181
         */
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1182
        public List<MemberName> getNestedTypes(Class<?> defc, boolean searchSupers,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1183
                Class<?> lookupClass) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1184
            int matchFlags = IS_TYPE | (searchSupers ? SEARCH_ALL_SUPERS : 0);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1185
            return getMembers(defc, null, null, matchFlags, lookupClass);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1186
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1187
        private static MemberName[] newMemberBuffer(int length) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1188
            MemberName[] buf = new MemberName[length];
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1189
            // fill the buffer with dummy structs for the JVM to fill in
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1190
            for (int i = 0; i < length; i++)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1191
                buf[i] = new MemberName();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1192
            return buf;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1193
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1194
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
  1195
}