< prev index next >

src/java.base/share/classes/java/lang/invoke/MethodHandleInfo.java

Print this page




  64  * Cracking must be done via a {@code Lookup} object equivalent to that which created
  65  * the target method handle, or which has enough access permissions to recreate
  66  * an equivalent method handle.
  67  * <p>
  68  * If the underlying method is <a href="MethodHandles.Lookup.html#callsens">caller sensitive</a>,
  69  * the direct method handle will have been "bound" to a particular caller class, the
  70  * {@linkplain java.lang.invoke.MethodHandles.Lookup#lookupClass() lookup class}
  71  * of the lookup object used to create it.
  72  * Cracking this method handle with a different lookup class will fail
  73  * even if the underlying method is public (like {@code Class.forName}).
  74  * <p>
  75  * The requirement of lookup object matching provides a "fast fail" behavior
  76  * for programs which may otherwise trust erroneous revelation of a method
  77  * handle with symbolic information (or caller binding) from an unexpected scope.
  78  * Use {@link java.lang.invoke.MethodHandles#reflectAs} to override this limitation.
  79  *
  80  * <h1><a id="refkinds"></a>Reference kinds</h1>
  81  * The <a href="MethodHandles.Lookup.html#lookups">Lookup Factory Methods</a>
  82  * correspond to all major use cases for methods, constructors, and fields.
  83  * These use cases may be distinguished using small integers as follows:
  84  * <table border=1 cellpadding=5 summary="reference kinds">


  85  * <tr><th>reference kind</th><th>descriptive name</th><th>scope</th><th>member</th><th>behavior</th></tr>


  86  * <tr>
  87  *     <td>{@code 1}</td><td>{@code REF_getField}</td><td>{@code class}</td>
  88  *     <td>{@code FT f;}</td><td>{@code (T) this.f;}</td>
  89  * </tr>
  90  * <tr>
  91  *     <td>{@code 2}</td><td>{@code REF_getStatic}</td><td>{@code class} or {@code interface}</td>
  92  *     <td>{@code static}<br>{@code FT f;}</td><td>{@code (T) C.f;}</td>
  93  * </tr>
  94  * <tr>
  95  *     <td>{@code 3}</td><td>{@code REF_putField}</td><td>{@code class}</td>
  96  *     <td>{@code FT f;}</td><td>{@code this.f = x;}</td>
  97  * </tr>
  98  * <tr>
  99  *     <td>{@code 4}</td><td>{@code REF_putStatic}</td><td>{@code class}</td>
 100  *     <td>{@code static}<br>{@code FT f;}</td><td>{@code C.f = arg;}</td>
 101  * </tr>
 102  * <tr>
 103  *     <td>{@code 5}</td><td>{@code REF_invokeVirtual}</td><td>{@code class}</td>
 104  *     <td>{@code T m(A*);}</td><td>{@code (T) this.m(arg*);}</td>
 105  * </tr>
 106  * <tr>
 107  *     <td>{@code 6}</td><td>{@code REF_invokeStatic}</td><td>{@code class} or {@code interface}</td>
 108  *     <td>{@code static}<br>{@code T m(A*);}</td><td>{@code (T) C.m(arg*);}</td>
 109  * </tr>
 110  * <tr>
 111  *     <td>{@code 7}</td><td>{@code REF_invokeSpecial}</td><td>{@code class} or {@code interface}</td>
 112  *     <td>{@code T m(A*);}</td><td>{@code (T) super.m(arg*);}</td>
 113  * </tr>
 114  * <tr>
 115  *     <td>{@code 8}</td><td>{@code REF_newInvokeSpecial}</td><td>{@code class}</td>
 116  *     <td>{@code C(A*);}</td><td>{@code new C(arg*);}</td>
 117  * </tr>
 118  * <tr>
 119  *     <td>{@code 9}</td><td>{@code REF_invokeInterface}</td><td>{@code interface}</td>
 120  *     <td>{@code T m(A*);}</td><td>{@code (T) this.m(arg*);}</td>
 121  * </tr>

 122  * </table>
 123  * @since 1.8
 124  */
 125 public
 126 interface MethodHandleInfo {
 127     /**
 128      * A direct method handle reference kind,
 129      * as defined in the <a href="MethodHandleInfo.html#refkinds">table above</a>.
 130      */
 131     public static final int
 132         REF_getField                = Constants.REF_getField,
 133         REF_getStatic               = Constants.REF_getStatic,
 134         REF_putField                = Constants.REF_putField,
 135         REF_putStatic               = Constants.REF_putStatic,
 136         REF_invokeVirtual           = Constants.REF_invokeVirtual,
 137         REF_invokeStatic            = Constants.REF_invokeStatic,
 138         REF_invokeSpecial           = Constants.REF_invokeSpecial,
 139         REF_newInvokeSpecial        = Constants.REF_newInvokeSpecial,
 140         REF_invokeInterface         = Constants.REF_invokeInterface;
 141 




  64  * Cracking must be done via a {@code Lookup} object equivalent to that which created
  65  * the target method handle, or which has enough access permissions to recreate
  66  * an equivalent method handle.
  67  * <p>
  68  * If the underlying method is <a href="MethodHandles.Lookup.html#callsens">caller sensitive</a>,
  69  * the direct method handle will have been "bound" to a particular caller class, the
  70  * {@linkplain java.lang.invoke.MethodHandles.Lookup#lookupClass() lookup class}
  71  * of the lookup object used to create it.
  72  * Cracking this method handle with a different lookup class will fail
  73  * even if the underlying method is public (like {@code Class.forName}).
  74  * <p>
  75  * The requirement of lookup object matching provides a "fast fail" behavior
  76  * for programs which may otherwise trust erroneous revelation of a method
  77  * handle with symbolic information (or caller binding) from an unexpected scope.
  78  * Use {@link java.lang.invoke.MethodHandles#reflectAs} to override this limitation.
  79  *
  80  * <h1><a id="refkinds"></a>Reference kinds</h1>
  81  * The <a href="MethodHandles.Lookup.html#lookups">Lookup Factory Methods</a>
  82  * correspond to all major use cases for methods, constructors, and fields.
  83  * These use cases may be distinguished using small integers as follows:
  84  * <table class="striped">
  85  * <caption style="display:none">reference kinds</caption>
  86  * <thead>
  87  * <tr><th>reference kind</th><th>descriptive name</th><th>scope</th><th>member</th><th>behavior</th></tr>
  88  * </thead>
  89  * <tbody>
  90  * <tr>
  91  *     <td>{@code 1}</td><td>{@code REF_getField}</td><td>{@code class}</td>
  92  *     <td>{@code FT f;}</td><td>{@code (T) this.f;}</td>
  93  * </tr>
  94  * <tr>
  95  *     <td>{@code 2}</td><td>{@code REF_getStatic}</td><td>{@code class} or {@code interface}</td>
  96  *     <td>{@code static}<br>{@code FT f;}</td><td>{@code (T) C.f;}</td>
  97  * </tr>
  98  * <tr>
  99  *     <td>{@code 3}</td><td>{@code REF_putField}</td><td>{@code class}</td>
 100  *     <td>{@code FT f;}</td><td>{@code this.f = x;}</td>
 101  * </tr>
 102  * <tr>
 103  *     <td>{@code 4}</td><td>{@code REF_putStatic}</td><td>{@code class}</td>
 104  *     <td>{@code static}<br>{@code FT f;}</td><td>{@code C.f = arg;}</td>
 105  * </tr>
 106  * <tr>
 107  *     <td>{@code 5}</td><td>{@code REF_invokeVirtual}</td><td>{@code class}</td>
 108  *     <td>{@code T m(A*);}</td><td>{@code (T) this.m(arg*);}</td>
 109  * </tr>
 110  * <tr>
 111  *     <td>{@code 6}</td><td>{@code REF_invokeStatic}</td><td>{@code class} or {@code interface}</td>
 112  *     <td>{@code static}<br>{@code T m(A*);}</td><td>{@code (T) C.m(arg*);}</td>
 113  * </tr>
 114  * <tr>
 115  *     <td>{@code 7}</td><td>{@code REF_invokeSpecial}</td><td>{@code class} or {@code interface}</td>
 116  *     <td>{@code T m(A*);}</td><td>{@code (T) super.m(arg*);}</td>
 117  * </tr>
 118  * <tr>
 119  *     <td>{@code 8}</td><td>{@code REF_newInvokeSpecial}</td><td>{@code class}</td>
 120  *     <td>{@code C(A*);}</td><td>{@code new C(arg*);}</td>
 121  * </tr>
 122  * <tr>
 123  *     <td>{@code 9}</td><td>{@code REF_invokeInterface}</td><td>{@code interface}</td>
 124  *     <td>{@code T m(A*);}</td><td>{@code (T) this.m(arg*);}</td>
 125  * </tr>
 126  * </tbody>
 127  * </table>
 128  * @since 1.8
 129  */
 130 public
 131 interface MethodHandleInfo {
 132     /**
 133      * A direct method handle reference kind,
 134      * as defined in the <a href="MethodHandleInfo.html#refkinds">table above</a>.
 135      */
 136     public static final int
 137         REF_getField                = Constants.REF_getField,
 138         REF_getStatic               = Constants.REF_getStatic,
 139         REF_putField                = Constants.REF_putField,
 140         REF_putStatic               = Constants.REF_putStatic,
 141         REF_invokeVirtual           = Constants.REF_invokeVirtual,
 142         REF_invokeStatic            = Constants.REF_invokeStatic,
 143         REF_invokeSpecial           = Constants.REF_invokeSpecial,
 144         REF_newInvokeSpecial        = Constants.REF_newInvokeSpecial,
 145         REF_invokeInterface         = Constants.REF_invokeInterface;
 146 


< prev index next >