jdk/src/share/classes/java/dyn/BootstrapMethod.java
author jrose
Wed, 08 Sep 2010 18:40:11 -0700
changeset 7051 1c545d70a157
permissions -rw-r--r--
6964498: JSR 292 invokedynamic sites need local bootstrap methods Summary: Add JVM_CONSTANT_InvokeDynamic records to constant pool to determine per-instruction BSMs; add MethodHandleProvider. Reviewed-by: twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7051
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
     1
/*
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
     4
 *
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    10
 *
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    15
 * accompanied this code).
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    16
 *
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    20
 *
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    23
 * questions.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    24
 */
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    25
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    26
package java.dyn;
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    27
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    28
import java.lang.annotation.*;
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    29
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    30
/**
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    31
 * Annotation on InvokeDynamic method calls which requests the JVM to use a specific
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    32
 * <a href="package-summary.html#bsm">bootstrap method</a>
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    33
 * to link the call.  This annotation is not retained as such in the class file,
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    34
 * but is transformed into a constant-pool entry for the invokedynamic instruction which
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    35
 * specifies the desired bootstrap method.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    36
 * <p>
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    37
 * If only the <code>value</code> is given, it must name a subclass of {@link CallSite}
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    38
 * with a constructor which accepts a class, string, and method type.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    39
 * If the <code>value</code> and <code>name</code> are both given, there must be
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    40
 * a static method in the given class of the given name which accepts a class, string,
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    41
 * and method type, and returns a reference coercible to {@link CallSite}.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    42
 * <p>
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    43
 * This annotation can be placed either on the return type of a single {@link InvokeDynamic}
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    44
 * call (see examples) or else it can be placed on an enclosing class or method, where it
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    45
 * determines a default bootstrap method for any {@link InvokeDynamic} calls which are not
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    46
 * specifically annotated with a bootstrap method.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    47
 * Every {@link InvokeDynamic} call must be given a bootstrap method.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    48
 * <p>
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    49
 * Examples:
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    50
<blockquote><pre>
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    51
&#064;BootstrapMethod(value=MyLanguageRuntime.class, name="bootstrapDynamic")
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    52
String x = (String) InvokeDynamic.greet();
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    53
//BSM => MyLanguageRuntime.bootstrapDynamic(Here.class, "greet", methodType(String.class))
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    54
&#064;BootstrapMethod(MyCallSite.class)
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    55
void example() throws Throwable {
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    56
    InvokeDynamic.greet();
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    57
    //BSM => new MyCallSite(Here.class, "greet", methodType(void.class))
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    58
}
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    59
</pre></blockquote>
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    60
 * <p>
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    61
 */
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    62
@Target({ElementType.TYPE_USE,
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    63
            // For defaulting every indy site within a class or method; cf. @SuppressWarnings:
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    64
            ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    65
            })
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    66
@Retention(RetentionPolicy.SOURCE)
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    67
public @interface BootstrapMethod {
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    68
    /** The class containing the bootstrap method. */
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    69
    Class<?> value();
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    70
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    71
    /** The name of the bootstrap method.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    72
     *  If this is the empty string, an instance of the bootstrap class is created,
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    73
     *  and a constructor is invoked.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    74
     *  Otherwise, there must be a static method of the required name.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    75
     */
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    76
    String name() default "";  // empty string denotes a constructor with 'new'
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    77
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    78
    /** The argument types of the bootstrap method, as passed out by the JVM.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    79
     *  There is usually no reason to override the default.
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    80
     */
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    81
    Class<?>[] arguments() default {Class.class, String.class, MethodType.class};
1c545d70a157 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
diff changeset
    82
}