rt/emul/compact/src/main/java/java/lang/invoke/LambdaMetafactory.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 17 Jan 2017 07:04:06 +0100
changeset 1985 cd1cc103a03c
permissions -rw-r--r--
Implementation of ClassValue for bck2brwsr
jaroslav@1692
     1
/*
jaroslav@1692
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
jaroslav@1692
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@1692
     4
 *
jaroslav@1692
     5
 * This code is free software; you can redistribute it and/or modify it
jaroslav@1692
     6
 * under the terms of the GNU General Public License version 2 only, as
jaroslav@1692
     7
 * published by the Free Software Foundation.  Oracle designates this
jaroslav@1692
     8
 * particular file as subject to the "Classpath" exception as provided
jaroslav@1692
     9
 * by Oracle in the LICENSE file that accompanied this code.
jaroslav@1692
    10
 *
jaroslav@1692
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@1692
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@1692
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jaroslav@1692
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@1692
    15
 * accompanied this code).
jaroslav@1692
    16
 *
jaroslav@1692
    17
 * You should have received a copy of the GNU General Public License version
jaroslav@1692
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@1692
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@1692
    20
 *
jaroslav@1692
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@1692
    22
 * or visit www.oracle.com if you need additional information or have any
jaroslav@1692
    23
 * questions.
jaroslav@1692
    24
 */
jaroslav@1692
    25
jaroslav@1692
    26
package java.lang.invoke;
jaroslav@1692
    27
jaroslav@1692
    28
import java.io.Serializable;
jaroslav@1692
    29
import java.util.Arrays;
jaroslav@1692
    30
jaroslav@1692
    31
/**
jaroslav@1692
    32
 * <p>Methods to facilitate the creation of simple "function objects" that
jaroslav@1692
    33
 * implement one or more interfaces by delegation to a provided {@link MethodHandle},
jaroslav@1692
    34
 * possibly after type adaptation and partial evaluation of arguments.  These
jaroslav@1692
    35
 * methods are typically used as <em>bootstrap methods</em> for {@code invokedynamic}
jaroslav@1692
    36
 * call sites, to support the <em>lambda expression</em> and <em>method
jaroslav@1692
    37
 * reference expression</em> features of the Java Programming Language.
jaroslav@1692
    38
 *
jaroslav@1692
    39
 * <p>Indirect access to the behavior specified by the provided {@code MethodHandle}
jaroslav@1692
    40
 * proceeds in order through three phases:
jaroslav@1692
    41
 * <ul>
jaroslav@1692
    42
 *     <li><em>Linkage</em> occurs when the methods in this class are invoked.
jaroslav@1692
    43
 *     They take as arguments an interface to be implemented (typically a
jaroslav@1692
    44
 *     <em>functional interface</em>, one with a single abstract method), a
jaroslav@1692
    45
 *     name and signature of a method from that interface to be implemented, a
jaroslav@1692
    46
 *     method handle describing the desired implementation behavior
jaroslav@1692
    47
 *     for that method, and possibly other additional metadata, and produce a
jaroslav@1692
    48
 *     {@link CallSite} whose target can be used to create suitable function
jaroslav@1692
    49
 *     objects.  Linkage may involve dynamically loading a new class that
jaroslav@1692
    50
 *     implements the target interface. The {@code CallSite} can be considered a
jaroslav@1692
    51
 *     "factory" for function objects and so these linkage methods are referred
jaroslav@1692
    52
 *     to as "metafactories".</li>
jaroslav@1692
    53
 *
jaroslav@1692
    54
 *     <li><em>Capture</em> occurs when the {@code CallSite}'s target is
jaroslav@1692
    55
 *     invoked, typically through an {@code invokedynamic} call site,
jaroslav@1692
    56
 *     producing a function object.  This may occur many times for
jaroslav@1692
    57
 *     a single factory {@code CallSite}.  Capture may involve allocation of a
jaroslav@1692
    58
 *     new function object, or may return an existing function object.  The
jaroslav@1692
    59
 *     behavior {@code MethodHandle} may have additional parameters beyond those
jaroslav@1692
    60
 *     of the specified interface method; these are referred to as <em>captured
jaroslav@1692
    61
 *     parameters</em>, which must be provided as arguments to the
jaroslav@1692
    62
 *     {@code CallSite} target, and which may be early-bound to the behavior
jaroslav@1692
    63
 *     {@code MethodHandle}.  The number of captured parameters and their types
jaroslav@1692
    64
 *     are determined during linkage.</li>
jaroslav@1692
    65
 *
jaroslav@1692
    66
 *     <li><em>Invocation</em> occurs when an implemented interface method
jaroslav@1692
    67
 *     is invoked on a function object.  This may occur many times for a single
jaroslav@1692
    68
 *     function object.  The method referenced by the behavior {@code MethodHandle}
jaroslav@1692
    69
 *     is invoked with the captured arguments and any additional arguments
jaroslav@1692
    70
 *     provided on invocation, as if by {@link MethodHandle#invoke(Object...)}.</li>
jaroslav@1692
    71
 * </ul>
jaroslav@1692
    72
 *
jaroslav@1692
    73
 * <p>It is sometimes useful to restrict the set of inputs or results permitted
jaroslav@1692
    74
 * at invocation.  For example, when the generic interface {@code Predicate<T>}
jaroslav@1692
    75
 * is parameterized as {@code Predicate<String>}, the input must be a
jaroslav@1692
    76
 * {@code String}, even though the method to implement allows any {@code Object}.
jaroslav@1692
    77
 * At linkage time, an additional {@link MethodType} parameter describes the
jaroslav@1692
    78
 * "instantiated" method type; on invocation, the arguments and eventual result
jaroslav@1692
    79
 * are checked against this {@code MethodType}.
jaroslav@1692
    80
 *
jaroslav@1692
    81
 * <p>This class provides two forms of linkage methods: a standard version
jaroslav@1692
    82
 * ({@link #metafactory(MethodHandles.Lookup, String, MethodType, MethodType, MethodHandle, MethodType)})
jaroslav@1692
    83
 * using an optimized protocol, and an alternate version
jaroslav@1692
    84
 * {@link #altMetafactory(MethodHandles.Lookup, String, MethodType, Object...)}).
jaroslav@1692
    85
 * The alternate version is a generalization of the standard version, providing
jaroslav@1692
    86
 * additional control over the behavior of the generated function objects via
jaroslav@1692
    87
 * flags and additional arguments.  The alternate version adds the ability to
jaroslav@1692
    88
 * manage the following attributes of function objects:
jaroslav@1692
    89
 *
jaroslav@1692
    90
 * <ul>
jaroslav@1692
    91
 *     <li><em>Bridging.</em>  It is sometimes useful to implement multiple
jaroslav@1692
    92
 *     variations of the method signature, involving argument or return type
jaroslav@1692
    93
 *     adaptation.  This occurs when multiple distinct VM signatures for a method
jaroslav@1692
    94
 *     are logically considered to be the same method by the language.  The
jaroslav@1692
    95
 *     flag {@code FLAG_BRIDGES} indicates that a list of additional
jaroslav@1692
    96
 *     {@code MethodType}s will be provided, each of which will be implemented
jaroslav@1692
    97
 *     by the resulting function object.  These methods will share the same
jaroslav@1692
    98
 *     name and instantiated type.</li>
jaroslav@1692
    99
 *
jaroslav@1692
   100
 *     <li><em>Multiple interfaces.</em>  If needed, more than one interface
jaroslav@1692
   101
 *     can be implemented by the function object.  (These additional interfaces
jaroslav@1692
   102
 *     are typically marker interfaces with no methods.)  The flag {@code FLAG_MARKERS}
jaroslav@1692
   103
 *     indicates that a list of additional interfaces will be provided, each of
jaroslav@1692
   104
 *     which should be implemented by the resulting function object.</li>
jaroslav@1692
   105
 *
jaroslav@1692
   106
 *     <li><em>Serializability.</em>  The generated function objects do not
jaroslav@1692
   107
 *     generally support serialization.  If desired, {@code FLAG_SERIALIZABLE}
jaroslav@1692
   108
 *     can be used to indicate that the function objects should be serializable.
jaroslav@1692
   109
 *     Serializable function objects will use, as their serialized form,
jaroslav@1692
   110
 *     instances of the class {@code SerializedLambda}, which requires additional
jaroslav@1692
   111
 *     assistance from the capturing class (the class described by the
jaroslav@1692
   112
 *     {@link MethodHandles.Lookup} parameter {@code caller}); see
jaroslav@1692
   113
 *     {@link SerializedLambda} for details.</li>
jaroslav@1692
   114
 * </ul>
jaroslav@1692
   115
 *
jaroslav@1692
   116
 * <p>Assume the linkage arguments are as follows:
jaroslav@1692
   117
 * <ul>
jaroslav@1692
   118
 *      <li>{@code invokedType} (describing the {@code CallSite} signature) has
jaroslav@1692
   119
 *      K parameters of types (D1..Dk) and return type Rd;</li>
jaroslav@1692
   120
 *      <li>{@code samMethodType} (describing the implemented method type) has N
jaroslav@1692
   121
 *      parameters, of types (U1..Un) and return type Ru;</li>
jaroslav@1692
   122
 *      <li>{@code implMethod} (the {@code MethodHandle} providing the
jaroslav@1692
   123
 *      implementation has M parameters, of types (A1..Am) and return type Ra
jaroslav@1692
   124
 *      (if the method describes an instance method, the method type of this
jaroslav@1692
   125
 *      method handle already includes an extra first argument corresponding to
jaroslav@1692
   126
 *      the receiver);</li>
jaroslav@1692
   127
 *      <li>{@code instantiatedMethodType} (allowing restrictions on invocation)
jaroslav@1692
   128
 *      has N parameters, of types (T1..Tn) and return type Rt.</li>
jaroslav@1692
   129
 * </ul>
jaroslav@1692
   130
 *
jaroslav@1692
   131
 * <p>Then the following linkage invariants must hold:
jaroslav@1692
   132
 * <ul>
jaroslav@1692
   133
 *     <li>Rd is an interface</li>
jaroslav@1692
   134
 *     <li>{@code implMethod} is a <em>direct method handle</em></li>
jaroslav@1692
   135
 *     <li>{@code samMethodType} and {@code instantiatedMethodType} have the same
jaroslav@1692
   136
 *     arity N, and for i=1..N, Ti and Ui are the same type, or Ti and Ui are
jaroslav@1692
   137
 *     both reference types and Ti is a subtype of Ui</li>
jaroslav@1692
   138
 *     <li>Either Rt and Ru are the same type, or both are reference types and
jaroslav@1692
   139
 *     Rt is a subtype of Ru</li>
jaroslav@1692
   140
 *     <li>K + N = M</li>
jaroslav@1692
   141
 *     <li>For i=1..K, Di = Ai</li>
jaroslav@1692
   142
 *     <li>For i=1..N, Ti is adaptable to Aj, where j=i+k</li>
jaroslav@1692
   143
 *     <li>The return type Rt is void, or the return type Ra is not void and is
jaroslav@1692
   144
 *     adaptable to Rt</li>
jaroslav@1692
   145
 * </ul>
jaroslav@1692
   146
 *
jaroslav@1692
   147
 * <p>Further, at capture time, if {@code implMethod} corresponds to an instance
jaroslav@1692
   148
 * method, and there are any capture arguments ({@code K > 0}), then the first
jaroslav@1692
   149
 * capture argument (corresponding to the receiver) must be non-null.
jaroslav@1692
   150
 *
jaroslav@1692
   151
 * <p>A type Q is considered adaptable to S as follows:
jaroslav@1692
   152
 * <table summary="adaptable types">
jaroslav@1692
   153
 *     <tr><th>Q</th><th>S</th><th>Link-time checks</th><th>Invocation-time checks</th></tr>
jaroslav@1692
   154
 *     <tr>
jaroslav@1692
   155
 *         <td>Primitive</td><td>Primitive</td>
jaroslav@1692
   156
 *         <td>Q can be converted to S via a primitive widening conversion</td>
jaroslav@1692
   157
 *         <td>None</td>
jaroslav@1692
   158
 *     </tr>
jaroslav@1692
   159
 *     <tr>
jaroslav@1692
   160
 *         <td>Primitive</td><td>Reference</td>
jaroslav@1692
   161
 *         <td>S is a supertype of the Wrapper(Q)</td>
jaroslav@1692
   162
 *         <td>Cast from Wrapper(Q) to S</td>
jaroslav@1692
   163
 *     </tr>
jaroslav@1692
   164
 *     <tr>
jaroslav@1692
   165
 *         <td>Reference</td><td>Primitive</td>
jaroslav@1692
   166
 *         <td>for parameter types: Q is a primitive wrapper and Primitive(Q)
jaroslav@1692
   167
 *         can be widened to S
jaroslav@1692
   168
 *         <br>for return types: If Q is a primitive wrapper, check that
jaroslav@1692
   169
 *         Primitive(Q) can be widened to S</td>
jaroslav@1692
   170
 *         <td>If Q is not a primitive wrapper, cast Q to the base Wrapper(S);
jaroslav@1692
   171
 *         for example Number for numeric types</td>
jaroslav@1692
   172
 *     </tr>
jaroslav@1692
   173
 *     <tr>
jaroslav@1692
   174
 *         <td>Reference</td><td>Reference</td>
jaroslav@1692
   175
 *         <td>for parameter types: S is a supertype of Q
jaroslav@1692
   176
 *         <br>for return types: none</td>
jaroslav@1692
   177
 *         <td>Cast from Q to S</td>
jaroslav@1692
   178
 *     </tr>
jaroslav@1692
   179
 * </table>
jaroslav@1692
   180
 *
jaroslav@1692
   181
 * @apiNote These linkage methods are designed to support the evaluation
jaroslav@1692
   182
 * of <em>lambda expressions</em> and <em>method references</em> in the Java
jaroslav@1692
   183
 * Language.  For every lambda expressions or method reference in the source code,
jaroslav@1692
   184
 * there is a target type which is a functional interface.  Evaluating a lambda
jaroslav@1692
   185
 * expression produces an object of its target type. The recommended mechanism
jaroslav@1692
   186
 * for evaluating lambda expressions is to desugar the lambda body to a method,
jaroslav@1692
   187
 * invoke an invokedynamic call site whose static argument list describes the
jaroslav@1692
   188
 * sole method of the functional interface and the desugared implementation
jaroslav@1692
   189
 * method, and returns an object (the lambda object) that implements the target
jaroslav@1692
   190
 * type. (For method references, the implementation method is simply the
jaroslav@1692
   191
 * referenced method; no desugaring is needed.)
jaroslav@1692
   192
 *
jaroslav@1692
   193
 * <p>The argument list of the implementation method and the argument list of
jaroslav@1692
   194
 * the interface method(s) may differ in several ways.  The implementation
jaroslav@1692
   195
 * methods may have additional arguments to accommodate arguments captured by
jaroslav@1692
   196
 * the lambda expression; there may also be differences resulting from permitted
jaroslav@1692
   197
 * adaptations of arguments, such as casting, boxing, unboxing, and primitive
jaroslav@1692
   198
 * widening. (Varargs adaptations are not handled by the metafactories; these are
jaroslav@1692
   199
 * expected to be handled by the caller.)
jaroslav@1692
   200
 *
jaroslav@1692
   201
 * <p>Invokedynamic call sites have two argument lists: a static argument list
jaroslav@1692
   202
 * and a dynamic argument list.  The static argument list is stored in the
jaroslav@1692
   203
 * constant pool; the dynamic argument is pushed on the operand stack at capture
jaroslav@1692
   204
 * time.  The bootstrap method has access to the entire static argument list
jaroslav@1692
   205
 * (which in this case, includes information describing the implementation method,
jaroslav@1692
   206
 * the target interface, and the target interface method(s)), as well as a
jaroslav@1692
   207
 * method signature describing the number and static types (but not the values)
jaroslav@1692
   208
 * of the dynamic arguments and the static return type of the invokedynamic site.
jaroslav@1692
   209
 *
jaroslav@1692
   210
 * @implNote The implementation method is described with a method handle. In
jaroslav@1692
   211
 * theory, any method handle could be used. Currently supported are direct method
jaroslav@1692
   212
 * handles representing invocation of virtual, interface, constructor and static
jaroslav@1692
   213
 * methods.
jaroslav@1692
   214
 */
jaroslav@1692
   215
public class LambdaMetafactory {
jaroslav@1692
   216
jaroslav@1692
   217
    /** Flag for alternate metafactories indicating the lambda object
jaroslav@1692
   218
     * must be serializable */
jaroslav@1692
   219
    public static final int FLAG_SERIALIZABLE = 1 << 0;
jaroslav@1692
   220
jaroslav@1692
   221
    /**
jaroslav@1692
   222
     * Flag for alternate metafactories indicating the lambda object implements
jaroslav@1692
   223
     * other marker interfaces
jaroslav@1692
   224
     * besides Serializable
jaroslav@1692
   225
     */
jaroslav@1692
   226
    public static final int FLAG_MARKERS = 1 << 1;
jaroslav@1692
   227
jaroslav@1692
   228
    /**
jaroslav@1692
   229
     * Flag for alternate metafactories indicating the lambda object requires
jaroslav@1692
   230
     * additional bridge methods
jaroslav@1692
   231
     */
jaroslav@1692
   232
    public static final int FLAG_BRIDGES = 1 << 2;
jaroslav@1692
   233
jaroslav@1692
   234
    private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class<?>[0];
jaroslav@1692
   235
    private static final MethodType[] EMPTY_MT_ARRAY = new MethodType[0];
jaroslav@1692
   236
jaroslav@1692
   237
    /**
jaroslav@1692
   238
     * Facilitates the creation of simple "function objects" that implement one
jaroslav@1692
   239
     * or more interfaces by delegation to a provided {@link MethodHandle},
jaroslav@1692
   240
     * after appropriate type adaptation and partial evaluation of arguments.
jaroslav@1692
   241
     * Typically used as a <em>bootstrap method</em> for {@code invokedynamic}
jaroslav@1692
   242
     * call sites, to support the <em>lambda expression</em> and <em>method
jaroslav@1692
   243
     * reference expression</em> features of the Java Programming Language.
jaroslav@1692
   244
     *
jaroslav@1692
   245
     * <p>This is the standard, streamlined metafactory; additional flexibility
jaroslav@1692
   246
     * is provided by {@link #altMetafactory(MethodHandles.Lookup, String, MethodType, Object...)}.
jaroslav@1692
   247
     * A general description of the behavior of this method is provided
jaroslav@1692
   248
     * {@link LambdaMetafactory above}.
jaroslav@1692
   249
     *
jaroslav@1692
   250
     * <p>When the target of the {@code CallSite} returned from this method is
jaroslav@1692
   251
     * invoked, the resulting function objects are instances of a class which
jaroslav@1692
   252
     * implements the interface named by the return type of {@code invokedType},
jaroslav@1692
   253
     * declares a method with the name given by {@code invokedName} and the
jaroslav@1692
   254
     * signature given by {@code samMethodType}.  It may also override additional
jaroslav@1692
   255
     * methods from {@code Object}.
jaroslav@1692
   256
     *
jaroslav@1692
   257
     * @param caller Represents a lookup context with the accessibility
jaroslav@1692
   258
     *               privileges of the caller.  When used with {@code invokedynamic},
jaroslav@1692
   259
     *               this is stacked automatically by the VM.
jaroslav@1692
   260
     * @param invokedName The name of the method to implement.  When used with
jaroslav@1692
   261
     *                    {@code invokedynamic}, this is provided by the
jaroslav@1692
   262
     *                    {@code NameAndType} of the {@code InvokeDynamic}
jaroslav@1692
   263
     *                    structure and is stacked automatically by the VM.
jaroslav@1692
   264
     * @param invokedType The expected signature of the {@code CallSite}.  The
jaroslav@1692
   265
     *                    parameter types represent the types of capture variables;
jaroslav@1692
   266
     *                    the return type is the interface to implement.   When
jaroslav@1692
   267
     *                    used with {@code invokedynamic}, this is provided by
jaroslav@1692
   268
     *                    the {@code NameAndType} of the {@code InvokeDynamic}
jaroslav@1692
   269
     *                    structure and is stacked automatically by the VM.
jaroslav@1692
   270
     *                    In the event that the implementation method is an
jaroslav@1692
   271
     *                    instance method and this signature has any parameters,
jaroslav@1692
   272
     *                    the first parameter in the invocation signature must
jaroslav@1692
   273
     *                    correspond to the receiver.
jaroslav@1692
   274
     * @param samMethodType Signature and return type of method to be implemented
jaroslav@1692
   275
     *                      by the function object.
jaroslav@1692
   276
     * @param implMethod A direct method handle describing the implementation
jaroslav@1692
   277
     *                   method which should be called (with suitable adaptation
jaroslav@1692
   278
     *                   of argument types, return types, and with captured
jaroslav@1692
   279
     *                   arguments prepended to the invocation arguments) at
jaroslav@1692
   280
     *                   invocation time.
jaroslav@1692
   281
     * @param instantiatedMethodType The signature and return type that should
jaroslav@1692
   282
     *                               be enforced dynamically at invocation time.
jaroslav@1692
   283
     *                               This may be the same as {@code samMethodType},
jaroslav@1692
   284
     *                               or may be a specialization of it.
jaroslav@1692
   285
     * @return a CallSite whose target can be used to perform capture, generating
jaroslav@1692
   286
     *         instances of the interface named by {@code invokedType}
jaroslav@1692
   287
     * @throws LambdaConversionException If any of the linkage invariants
jaroslav@1692
   288
     *                                   described {@link LambdaMetafactory above}
jaroslav@1692
   289
     *                                   are violated
jaroslav@1692
   290
     */
jaroslav@1692
   291
    public static CallSite metafactory(MethodHandles.Lookup caller,
jaroslav@1692
   292
                                       String invokedName,
jaroslav@1692
   293
                                       MethodType invokedType,
jaroslav@1692
   294
                                       MethodType samMethodType,
jaroslav@1692
   295
                                       MethodHandle implMethod,
jaroslav@1692
   296
                                       MethodType instantiatedMethodType)
jaroslav@1692
   297
     {
jaroslav@1692
   298
        throw new IllegalStateException();
jaroslav@1692
   299
    }
jaroslav@1692
   300
jaroslav@1692
   301
    /**
jaroslav@1692
   302
     * Facilitates the creation of simple "function objects" that implement one
jaroslav@1692
   303
     * or more interfaces by delegation to a provided {@link MethodHandle},
jaroslav@1692
   304
     * after appropriate type adaptation and partial evaluation of arguments.
jaroslav@1692
   305
     * Typically used as a <em>bootstrap method</em> for {@code invokedynamic}
jaroslav@1692
   306
     * call sites, to support the <em>lambda expression</em> and <em>method
jaroslav@1692
   307
     * reference expression</em> features of the Java Programming Language.
jaroslav@1692
   308
     *
jaroslav@1692
   309
     * <p>This is the general, more flexible metafactory; a streamlined version
jaroslav@1692
   310
     * is provided by {@link #altMetafactory(MethodHandles.Lookup, String, MethodType, Object...)}.
jaroslav@1692
   311
     * A general description of the behavior of this method is provided
jaroslav@1692
   312
     * {@link LambdaMetafactory above}.
jaroslav@1692
   313
     *
jaroslav@1692
   314
     * <p>The argument list for this method includes three fixed parameters,
jaroslav@1692
   315
     * corresponding to the parameters automatically stacked by the VM for the
jaroslav@1692
   316
     * bootstrap method in an {@code invokedynamic} invocation, and an {@code Object[]}
jaroslav@1692
   317
     * parameter that contains additional parameters.  The declared argument
jaroslav@1692
   318
     * list for this method is:
jaroslav@1692
   319
     *
jaroslav@1692
   320
     * <pre>{@code
jaroslav@1692
   321
     *  CallSite altMetafactory(MethodHandles.Lookup caller,
jaroslav@1692
   322
     *                          String invokedName,
jaroslav@1692
   323
     *                          MethodType invokedType,
jaroslav@1692
   324
     *                          Object... args)
jaroslav@1692
   325
     * }</pre>
jaroslav@1692
   326
     *
jaroslav@1692
   327
     * <p>but it behaves as if the argument list is as follows:
jaroslav@1692
   328
     *
jaroslav@1692
   329
     * <pre>{@code
jaroslav@1692
   330
     *  CallSite altMetafactory(MethodHandles.Lookup caller,
jaroslav@1692
   331
     *                          String invokedName,
jaroslav@1692
   332
     *                          MethodType invokedType,
jaroslav@1692
   333
     *                          MethodType samMethodType,
jaroslav@1692
   334
     *                          MethodHandle implMethod,
jaroslav@1692
   335
     *                          MethodType instantiatedMethodType,
jaroslav@1692
   336
     *                          int flags,
jaroslav@1692
   337
     *                          int markerInterfaceCount,  // IF flags has MARKERS set
jaroslav@1692
   338
     *                          Class... markerInterfaces, // IF flags has MARKERS set
jaroslav@1692
   339
     *                          int bridgeCount,           // IF flags has BRIDGES set
jaroslav@1692
   340
     *                          MethodType... bridges      // IF flags has BRIDGES set
jaroslav@1692
   341
     *                          )
jaroslav@1692
   342
     * }</pre>
jaroslav@1692
   343
     *
jaroslav@1692
   344
     * <p>Arguments that appear in the argument list for
jaroslav@1692
   345
     * {@link #metafactory(MethodHandles.Lookup, String, MethodType, MethodType, MethodHandle, MethodType)}
jaroslav@1692
   346
     * have the same specification as in that method.  The additional arguments
jaroslav@1692
   347
     * are interpreted as follows:
jaroslav@1692
   348
     * <ul>
jaroslav@1692
   349
     *     <li>{@code flags} indicates additional options; this is a bitwise
jaroslav@1692
   350
     *     OR of desired flags.  Defined flags are {@link #FLAG_BRIDGES},
jaroslav@1692
   351
     *     {@link #FLAG_MARKERS}, and {@link #FLAG_SERIALIZABLE}.</li>
jaroslav@1692
   352
     *     <li>{@code markerInterfaceCount} is the number of additional interfaces
jaroslav@1692
   353
     *     the function object should implement, and is present if and only if the
jaroslav@1692
   354
     *     {@code FLAG_MARKERS} flag is set.</li>
jaroslav@1692
   355
     *     <li>{@code markerInterfaces} is a variable-length list of additional
jaroslav@1692
   356
     *     interfaces to implement, whose length equals {@code markerInterfaceCount},
jaroslav@1692
   357
     *     and is present if and only if the {@code FLAG_MARKERS} flag is set.</li>
jaroslav@1692
   358
     *     <li>{@code bridgeCount} is the number of additional method signatures
jaroslav@1692
   359
     *     the function object should implement, and is present if and only if
jaroslav@1692
   360
     *     the {@code FLAG_BRIDGES} flag is set.</li>
jaroslav@1692
   361
     *     <li>{@code bridges} is a variable-length list of additional
jaroslav@1692
   362
     *     methods signatures to implement, whose length equals {@code bridgeCount},
jaroslav@1692
   363
     *     and is present if and only if the {@code FLAG_BRIDGES} flag is set.</li>
jaroslav@1692
   364
     * </ul>
jaroslav@1692
   365
     *
jaroslav@1692
   366
     * <p>Each class named by {@code markerInterfaces} is subject to the same
jaroslav@1692
   367
     * restrictions as {@code Rd}, the return type of {@code invokedType},
jaroslav@1692
   368
     * as described {@link LambdaMetafactory above}.  Each {@code MethodType}
jaroslav@1692
   369
     * named by {@code bridges} is subject to the same restrictions as
jaroslav@1692
   370
     * {@code samMethodType}, as described {@link LambdaMetafactory above}.
jaroslav@1692
   371
     *
jaroslav@1692
   372
     * <p>When FLAG_SERIALIZABLE is set in {@code flags}, the function objects
jaroslav@1692
   373
     * will implement {@code Serializable}, and will have a {@code writeReplace}
jaroslav@1692
   374
     * method that returns an appropriate {@link SerializedLambda}.  The
jaroslav@1692
   375
     * {@code caller} class must have an appropriate {@code $deserializeLambda$}
jaroslav@1692
   376
     * method, as described in {@link SerializedLambda}.
jaroslav@1692
   377
     *
jaroslav@1692
   378
     * <p>When the target of the {@code CallSite} returned from this method is
jaroslav@1692
   379
     * invoked, the resulting function objects are instances of a class with
jaroslav@1692
   380
     * the following properties:
jaroslav@1692
   381
     * <ul>
jaroslav@1692
   382
     *     <li>The class implements the interface named by the return type
jaroslav@1692
   383
     *     of {@code invokedType} and any interfaces named by {@code markerInterfaces}</li>
jaroslav@1692
   384
     *     <li>The class declares methods with the name given by {@code invokedName},
jaroslav@1692
   385
     *     and the signature given by {@code samMethodType} and additional signatures
jaroslav@1692
   386
     *     given by {@code bridges}</li>
jaroslav@1692
   387
     *     <li>The class may override methods from {@code Object}, and may
jaroslav@1692
   388
     *     implement methods related to serialization.</li>
jaroslav@1692
   389
     * </ul>
jaroslav@1692
   390
     *
jaroslav@1692
   391
     * @param caller Represents a lookup context with the accessibility
jaroslav@1692
   392
     *               privileges of the caller.  When used with {@code invokedynamic},
jaroslav@1692
   393
     *               this is stacked automatically by the VM.
jaroslav@1692
   394
     * @param invokedName The name of the method to implement.  When used with
jaroslav@1692
   395
     *                    {@code invokedynamic}, this is provided by the
jaroslav@1692
   396
     *                    {@code NameAndType} of the {@code InvokeDynamic}
jaroslav@1692
   397
     *                    structure and is stacked automatically by the VM.
jaroslav@1692
   398
     * @param invokedType The expected signature of the {@code CallSite}.  The
jaroslav@1692
   399
     *                    parameter types represent the types of capture variables;
jaroslav@1692
   400
     *                    the return type is the interface to implement.   When
jaroslav@1692
   401
     *                    used with {@code invokedynamic}, this is provided by
jaroslav@1692
   402
     *                    the {@code NameAndType} of the {@code InvokeDynamic}
jaroslav@1692
   403
     *                    structure and is stacked automatically by the VM.
jaroslav@1692
   404
     *                    In the event that the implementation method is an
jaroslav@1692
   405
     *                    instance method and this signature has any parameters,
jaroslav@1692
   406
     *                    the first parameter in the invocation signature must
jaroslav@1692
   407
     *                    correspond to the receiver.
jaroslav@1692
   408
     * @param  args       An {@code Object[]} array containing the required
jaroslav@1692
   409
     *                    arguments {@code samMethodType}, {@code implMethod},
jaroslav@1692
   410
     *                    {@code instantiatedMethodType}, {@code flags}, and any
jaroslav@1692
   411
     *                    optional arguments, as described
jaroslav@1692
   412
     *                    {@link #altMetafactory(MethodHandles.Lookup, String, MethodType, Object...)} above}
jaroslav@1692
   413
     * @return a CallSite whose target can be used to perform capture, generating
jaroslav@1692
   414
     *         instances of the interface named by {@code invokedType}
jaroslav@1692
   415
     * @throws LambdaConversionException If any of the linkage invariants
jaroslav@1692
   416
     *                                   described {@link LambdaMetafactory above}
jaroslav@1692
   417
     *                                   are violated
jaroslav@1692
   418
     */
jaroslav@1692
   419
    public static CallSite altMetafactory(MethodHandles.Lookup caller,
jaroslav@1692
   420
                                          String invokedName,
jaroslav@1692
   421
                                          MethodType invokedType,
jaroslav@1692
   422
                                          Object... args)
jaroslav@1692
   423
    {
jaroslav@1692
   424
        throw new IllegalStateException();
jaroslav@1692
   425
    }
jaroslav@1692
   426
}