src/java.base/share/classes/java/lang/invoke/MethodHandleInfo.java
author jboes
Thu, 21 Nov 2019 09:10:21 +0000
changeset 59201 b24f4caa1411
parent 58242 94bb65cb37d3
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:
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     1
/*
54206
003cc64366da 8220249: fix headings in java.compiler
jjg
parents: 47216
diff changeset
     2
 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     4
 *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    10
 *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    15
 * accompanied this code).
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    16
 *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    20
 *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    23
 * questions.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    24
 */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    25
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    26
package java.lang.invoke;
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    27
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    28
import java.lang.reflect.*;
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    29
import java.util.*;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    30
import java.lang.invoke.MethodHandleNatives.Constants;
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    31
import java.lang.invoke.MethodHandles.Lookup;
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    32
import static java.lang.invoke.MethodHandleStatics.*;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    33
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    34
/**
20535
cc85c8626435 8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents: 20534
diff changeset
    35
 * A symbolic reference obtained by cracking a direct method handle
cc85c8626435 8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents: 20534
diff changeset
    36
 * into its consitutent symbolic parts.
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    37
 * To crack a direct method handle, call {@link Lookup#revealDirect Lookup.revealDirect}.
54206
003cc64366da 8220249: fix headings in java.compiler
jjg
parents: 47216
diff changeset
    38
 * <h2><a id="directmh"></a>Direct Method Handles</h2>
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    39
 * A <em>direct method handle</em> represents a method, constructor, or field without
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    40
 * any intervening argument bindings or other transformations.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    41
 * The method, constructor, or field referred to by a direct method handle is called
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    42
 * its <em>underlying member</em>.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    43
 * Direct method handles may be obtained in any of these ways:
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    44
 * <ul>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    45
 * <li>By executing an {@code ldc} instruction on a {@code CONSTANT_MethodHandle} constant.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    46
 *     (See the Java Virtual Machine Specification, sections 4.4.8 and 5.4.3.)
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    47
 * <li>By calling one of the <a href="MethodHandles.Lookup.html#lookups">Lookup Factory Methods</a>,
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    48
 *     such as {@link Lookup#findVirtual Lookup.findVirtual},
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    49
 *     to resolve a symbolic reference into a method handle.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    50
 *     A symbolic reference consists of a class, name string, and type.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    51
 * <li>By calling the factory method {@link Lookup#unreflect Lookup.unreflect}
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    52
 *     or {@link Lookup#unreflectSpecial Lookup.unreflectSpecial}
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    53
 *     to convert a {@link Method} into a method handle.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    54
 * <li>By calling the factory method {@link Lookup#unreflectConstructor Lookup.unreflectConstructor}
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    55
 *     to convert a {@link Constructor} into a method handle.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    56
 * <li>By calling the factory method {@link Lookup#unreflectGetter Lookup.unreflectGetter}
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    57
 *     or {@link Lookup#unreflectSetter Lookup.unreflectSetter}
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    58
 *     to convert a {@link Field} into a method handle.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    59
 * </ul>
20535
cc85c8626435 8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents: 20534
diff changeset
    60
 *
54206
003cc64366da 8220249: fix headings in java.compiler
jjg
parents: 47216
diff changeset
    61
 * <h2>Restrictions on Cracking</h2>
20535
cc85c8626435 8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents: 20534
diff changeset
    62
 * Given a suitable {@code Lookup} object, it is possible to crack any direct method handle
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    63
 * to recover a symbolic reference for the underlying method, constructor, or field.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    64
 * Cracking must be done via a {@code Lookup} object equivalent to that which created
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    65
 * the target method handle, or which has enough access permissions to recreate
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    66
 * an equivalent method handle.
20534
da86f7904e6d 8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents: 19804
diff changeset
    67
 * <p>
da86f7904e6d 8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents: 19804
diff changeset
    68
 * If the underlying method is <a href="MethodHandles.Lookup.html#callsens">caller sensitive</a>,
da86f7904e6d 8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents: 19804
diff changeset
    69
 * the direct method handle will have been "bound" to a particular caller class, the
da86f7904e6d 8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents: 19804
diff changeset
    70
 * {@linkplain java.lang.invoke.MethodHandles.Lookup#lookupClass() lookup class}
da86f7904e6d 8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents: 19804
diff changeset
    71
 * of the lookup object used to create it.
da86f7904e6d 8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents: 19804
diff changeset
    72
 * Cracking this method handle with a different lookup class will fail
da86f7904e6d 8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents: 19804
diff changeset
    73
 * even if the underlying method is public (like {@code Class.forName}).
da86f7904e6d 8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents: 19804
diff changeset
    74
 * <p>
da86f7904e6d 8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents: 19804
diff changeset
    75
 * The requirement of lookup object matching provides a "fast fail" behavior
da86f7904e6d 8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents: 19804
diff changeset
    76
 * for programs which may otherwise trust erroneous revelation of a method
da86f7904e6d 8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents: 19804
diff changeset
    77
 * handle with symbolic information (or caller binding) from an unexpected scope.
da86f7904e6d 8025112: JSR 292 spec updates for security manager and caller sensitivity
jrose
parents: 19804
diff changeset
    78
 * Use {@link java.lang.invoke.MethodHandles#reflectAs} to override this limitation.
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
    79
 *
54206
003cc64366da 8220249: fix headings in java.compiler
jjg
parents: 47216
diff changeset
    80
 * <h2><a id="refkinds"></a>Reference kinds</h2>
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    81
 * The <a href="MethodHandles.Lookup.html#lookups">Lookup Factory Methods</a>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    82
 * correspond to all major use cases for methods, constructors, and fields.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    83
 * These use cases may be distinguished using small integers as follows:
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44844
diff changeset
    84
 * <table class="striped">
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44844
diff changeset
    85
 * <caption style="display:none">reference kinds</caption>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44844
diff changeset
    86
 * <thead>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    87
 * <tr><th scope="col">reference kind</th><th scope="col">descriptive name</th><th scope="col">scope</th><th scope="col">member</th><th scope="col">behavior</th></tr>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44844
diff changeset
    88
 * </thead>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44844
diff changeset
    89
 * <tbody>
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    90
 * <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    91
 *     <th scope="row">{@code 1}</th><td>{@code REF_getField}</td><td>{@code class}</td>
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    92
 *     <td>{@code FT f;}</td><td>{@code (T) this.f;}</td>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    93
 * </tr>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    94
 * <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    95
 *     <th scope="row">{@code 2}</th><td>{@code REF_getStatic}</td><td>{@code class} or {@code interface}</td>
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    96
 *     <td>{@code static}<br>{@code FT f;}</td><td>{@code (T) C.f;}</td>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    97
 * </tr>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
    98
 * <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    99
 *     <th scope="row">{@code 3}</th><td>{@code REF_putField}</td><td>{@code class}</td>
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   100
 *     <td>{@code FT f;}</td><td>{@code this.f = x;}</td>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   101
 * </tr>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   102
 * <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
   103
 *     <th scope="row">{@code 4}</th><td>{@code REF_putStatic}</td><td>{@code class}</td>
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   104
 *     <td>{@code static}<br>{@code FT f;}</td><td>{@code C.f = arg;}</td>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   105
 * </tr>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   106
 * <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
   107
 *     <th scope="row">{@code 5}</th><td>{@code REF_invokeVirtual}</td><td>{@code class}</td>
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   108
 *     <td>{@code T m(A*);}</td><td>{@code (T) this.m(arg*);}</td>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   109
 * </tr>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   110
 * <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
   111
 *     <th scope="row">{@code 6}</th><td>{@code REF_invokeStatic}</td><td>{@code class} or {@code interface}</td>
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   112
 *     <td>{@code static}<br>{@code T m(A*);}</td><td>{@code (T) C.m(arg*);}</td>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   113
 * </tr>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   114
 * <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
   115
 *     <th scope="row">{@code 7}</th><td>{@code REF_invokeSpecial}</td><td>{@code class} or {@code interface}</td>
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   116
 *     <td>{@code T m(A*);}</td><td>{@code (T) super.m(arg*);}</td>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   117
 * </tr>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   118
 * <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
   119
 *     <th scope="row">{@code 8}</th><td>{@code REF_newInvokeSpecial}</td><td>{@code class}</td>
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   120
 *     <td>{@code C(A*);}</td><td>{@code new C(arg*);}</td>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   121
 * </tr>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   122
 * <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
   123
 *     <th scope="row">{@code 9}</th><td>{@code REF_invokeInterface}</td><td>{@code interface}</td>
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   124
 *     <td>{@code T m(A*);}</td><td>{@code (T) this.m(arg*);}</td>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   125
 * </tr>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44844
diff changeset
   126
 * </tbody>
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   127
 * </table>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   128
 * @since 1.8
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
   129
 */
59201
b24f4caa1411 8234335: Remove line break in class declaration in java.base
jboes
parents: 58242
diff changeset
   130
public interface MethodHandleInfo {
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   131
    /**
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   132
     * A direct method handle reference kind,
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   133
     * as defined in the <a href="MethodHandleInfo.html#refkinds">table above</a>.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   134
     */
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   135
    public static final int
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   136
        REF_getField                = Constants.REF_getField,
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   137
        REF_getStatic               = Constants.REF_getStatic,
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   138
        REF_putField                = Constants.REF_putField,
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   139
        REF_putStatic               = Constants.REF_putStatic,
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   140
        REF_invokeVirtual           = Constants.REF_invokeVirtual,
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   141
        REF_invokeStatic            = Constants.REF_invokeStatic,
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   142
        REF_invokeSpecial           = Constants.REF_invokeSpecial,
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   143
        REF_newInvokeSpecial        = Constants.REF_newInvokeSpecial,
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   144
        REF_invokeInterface         = Constants.REF_invokeInterface;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   145
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   146
    /**
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   147
     * Returns the reference kind of the cracked method handle, which in turn
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   148
     * determines whether the method handle's underlying member was a constructor, method, or field.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   149
     * See the <a href="MethodHandleInfo.html#refkinds">table above</a> for definitions.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   150
     * @return the integer code for the kind of reference used to access the underlying member
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   151
     */
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   152
    public int getReferenceKind();
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   153
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   154
    /**
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   155
     * Returns the class in which the cracked method handle's underlying member was defined.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   156
     * @return the declaring class of the underlying member
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   157
     */
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   158
    public Class<?> getDeclaringClass();
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   159
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   160
    /**
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   161
     * Returns the name of the cracked method handle's underlying member.
32276
2d5fcc89e099 8134356: {@code} tag contains &lt; and &gt; sequences
igerasim
parents: 25859
diff changeset
   162
     * This is {@code "<init>"} if the underlying member was a constructor,
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   163
     * else it is a simple method name or field name.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   164
     * @return the simple name of the underlying member
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   165
     */
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   166
    public String getName();
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   167
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   168
    /**
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   169
     * Returns the nominal type of the cracked symbolic reference, expressed as a method type.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   170
     * If the reference is to a constructor, the return type will be {@code void}.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   171
     * If it is to a non-static method, the method type will not mention the {@code this} parameter.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   172
     * If it is to a field and the requested access is to read the field,
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   173
     * the method type will have no parameters and return the field type.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   174
     * If it is to a field and the requested access is to write the field,
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   175
     * the method type will have one parameter of the field type and return {@code void}.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   176
     * <p>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   177
     * Note that original direct method handle may include a leading {@code this} parameter,
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   178
     * or (in the case of a constructor) will replace the {@code void} return type
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   179
     * with the constructed class.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   180
     * The nominal type does not include any {@code this} parameter,
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   181
     * and (in the case of a constructor) will return {@code void}.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   182
     * @return the type of the underlying member, expressed as a method type
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   183
     */
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   184
    public MethodType getMethodType();
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   185
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   186
    // Utility methods.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   187
    // NOTE: class/name/type and reference kind constitute a symbolic reference
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   188
    // member and modifiers are an add-on, derived from Core Reflection (or the equivalent)
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
   189
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   190
    /**
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   191
     * Reflects the underlying member as a method, constructor, or field object.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   192
     * If the underlying member is public, it is reflected as if by
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   193
     * {@code getMethod}, {@code getConstructor}, or {@code getField}.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   194
     * Otherwise, it is reflected as if by
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   195
     * {@code getDeclaredMethod}, {@code getDeclaredConstructor}, or {@code getDeclaredField}.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   196
     * The underlying member must be accessible to the given lookup object.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   197
     * @param <T> the desired type of the result, either {@link Member} or a subtype
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   198
     * @param expected a class object representing the desired result type {@code T}
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   199
     * @param lookup the lookup object that created this MethodHandleInfo, or one with equivalent access privileges
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   200
     * @return a reference to the method, constructor, or field object
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 54206
diff changeset
   201
     * @throws    ClassCastException if the member is not of the expected type
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 54206
diff changeset
   202
     * @throws    NullPointerException if either argument is {@code null}
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 54206
diff changeset
   203
     * @throws    IllegalArgumentException if the underlying member is not accessible to the given lookup object
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   204
     */
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   205
    public <T extends Member> T reflectAs(Class<T> expected, Lookup lookup);
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
   206
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   207
    /**
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   208
     * Returns the access modifiers of the underlying member.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   209
     * @return the Java language modifiers for underlying member,
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   210
     *         or -1 if the member cannot be accessed
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   211
     * @see Modifier
20535
cc85c8626435 8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents: 20534
diff changeset
   212
     * @see #reflectAs
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   213
     */
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   214
    public int getModifiers();
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   215
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   216
    /**
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   217
     * Determines if the underlying member was a variable arity method or constructor.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   218
     * Such members are represented by method handles that are varargs collectors.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   219
     * @implSpec
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   220
     * This produces a result equivalent to:
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   221
     * <pre>{@code
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   222
     *     getReferenceKind() >= REF_invokeVirtual && Modifier.isTransient(getModifiers())
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   223
     * }</pre>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   224
     *
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   225
     *
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   226
     * @return {@code true} if and only if the underlying member was declared with variable arity.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   227
     */
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   228
    // spelling derived from java.lang.reflect.Executable, not MethodHandle.isVarargsCollector
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   229
    public default boolean isVarArgs()  {
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   230
        // fields are never varargs:
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   231
        if (MethodHandleNatives.refKindIsField((byte) getReferenceKind()))
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   232
            return false;
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   233
        // not in the public API: Modifier.VARARGS
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   234
        final int ACC_VARARGS = 0x00000080;  // from JVMS 4.6 (Table 4.20)
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   235
        assert(ACC_VARARGS == Modifier.TRANSIENT);
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   236
        return Modifier.isTransient(getModifiers());
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
   237
    }
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
   238
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   239
    /**
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   240
     * Returns the descriptive name of the given reference kind,
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   241
     * as defined in the <a href="MethodHandleInfo.html#refkinds">table above</a>.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   242
     * The conventional prefix "REF_" is omitted.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   243
     * @param referenceKind an integer code for a kind of reference used to access a class member
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   244
     * @return a mixed-case string such as {@code "getField"}
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 54206
diff changeset
   245
     * @throws    IllegalArgumentException if the argument is not a valid
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   246
     *            <a href="MethodHandleInfo.html#refkinds">reference kind number</a>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   247
     */
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   248
    public static String referenceKindToString(int referenceKind) {
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   249
        if (!MethodHandleNatives.refKindIsValid(referenceKind))
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   250
            throw newIllegalArgumentException("invalid reference kind", referenceKind);
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   251
        return MethodHandleNatives.refKindName((byte)referenceKind);
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   252
    }
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   253
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   254
    /**
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   255
     * Returns a string representation for a {@code MethodHandleInfo},
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   256
     * given the four parts of its symbolic reference.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   257
     * This is defined to be of the form {@code "RK C.N:MT"}, where {@code RK} is the
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   258
     * {@linkplain #referenceKindToString reference kind string} for {@code kind},
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   259
     * {@code C} is the {@linkplain java.lang.Class#getName name} of {@code defc}
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   260
     * {@code N} is the {@code name}, and
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   261
     * {@code MT} is the {@code type}.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   262
     * These four values may be obtained from the
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   263
     * {@linkplain #getReferenceKind reference kind},
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   264
     * {@linkplain #getDeclaringClass declaring class},
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   265
     * {@linkplain #getName member name},
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   266
     * and {@linkplain #getMethodType method type}
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   267
     * of a {@code MethodHandleInfo} object.
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   268
     *
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   269
     * @implSpec
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   270
     * This produces a result equivalent to:
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   271
     * <pre>{@code
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   272
     *     String.format("%s %s.%s:%s", referenceKindToString(kind), defc.getName(), name, type)
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   273
     * }</pre>
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   274
     *
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   275
     * @param kind the {@linkplain #getReferenceKind reference kind} part of the symbolic reference
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   276
     * @param defc the {@linkplain #getDeclaringClass declaring class} part of the symbolic reference
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   277
     * @param name the {@linkplain #getName member name} part of the symbolic reference
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   278
     * @param type the {@linkplain #getMethodType method type} part of the symbolic reference
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   279
     * @return a string of the form {@code "RK C.N:MT"}
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 54206
diff changeset
   280
     * @throws    IllegalArgumentException if the first argument is not a valid
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   281
     *            <a href="MethodHandleInfo.html#refkinds">reference kind number</a>
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 54206
diff changeset
   282
     * @throws    NullPointerException if any reference argument is {@code null}
19804
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   283
     */
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   284
    public static String toString(int kind, Class<?> defc, String name, MethodType type) {
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   285
        Objects.requireNonNull(name); Objects.requireNonNull(type);
83170920c07b 8008688: Make MethodHandleInfo public
rfield
parents: 16030
diff changeset
   286
        return String.format("%s %s.%s:%s", referenceKindToString(kind), defc.getName(), name, type);
16001
fd4c8d3becf8 8004970: Implement serialization in the lambda metafactory
rfield
parents: 13423
diff changeset
   287
    }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   288
}