1 /* |
1 /* |
2 * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
24 */ |
24 */ |
25 |
25 |
26 package java.dyn; |
26 package java.dyn; |
27 |
27 |
28 /** |
28 /** |
29 * {@code InvokeDynamic} is a class with neither methods nor instances, |
29 * This is a place-holder class. Some HotSpot implementations need to see it. |
30 * which serves only as a syntactic marker in Java source code for |
30 */ |
31 * an {@code invokedynamic} instruction. |
31 final class InvokeDynamic { |
32 * (See <a href="package-summary.html#jvm_mods">the package information</a> for specifics on this instruction.) |
32 private InvokeDynamic() { throw new InternalError(); } // do not instantiate |
33 * <p> |
|
34 * The {@code invokedynamic} instruction is incomplete without a target method. |
|
35 * The target method is a property of the reified {@linkplain CallSite call site object} |
|
36 * which is linked to each active {@code invokedynamic} instruction. |
|
37 * The call site object is initially produced by a |
|
38 * {@linkplain BootstrapMethod bootstrap method} |
|
39 * associated with the class whose bytecodes include the dynamic call site. |
|
40 * <p> |
|
41 * The type {@code InvokeDynamic} has no particular meaning as a |
|
42 * class or interface supertype, or an object type; it can never be instantiated. |
|
43 * Logically, it denotes a source of all dynamically typed methods. |
|
44 * It may be viewed as a pure syntactic marker of static calls. |
|
45 * It may be imported for ease of use. |
|
46 * <p> |
|
47 * Here are some examples: |
|
48 <blockquote><pre><!-- see indy-demo/src/JavaDocExamples.java --> |
|
49 @BootstrapMethod(value=Here.class, name="bootstrapDynamic") |
|
50 static void example() throws Throwable { |
|
51 Object x; String s; int i; |
|
52 x = InvokeDynamic.greet("world"); // greet(Ljava/lang/String;)Ljava/lang/Object; |
|
53 s = (String) InvokeDynamic.hail(x); // hail(Ljava/lang/Object;)Ljava/lang/String; |
|
54 InvokeDynamic.cogito(); // cogito()V |
|
55 i = (int) InvokeDynamic.#"op:+"(2, 3); // "op:+"(II)I |
|
56 } |
33 } |
57 static MethodHandle bootstrapDynamic(Class caller, String name, MethodType type) { ... } |
|
58 </pre></blockquote> |
|
59 * Each of the above calls generates a single invokedynamic instruction |
|
60 * with the name-and-type descriptors indicated in the comments. |
|
61 * <p> |
|
62 * The argument types are taken directly from the actual arguments, |
|
63 * while the return type corresponds to the target of the assignment. |
|
64 * (Currently, the return type must be given as a false type parameter. |
|
65 * This type parameter is an irregular use of the generic type syntax, |
|
66 * and is likely to change in favor of a convention based on target typing.) |
|
67 * <p> |
|
68 * The final example uses a special syntax for uttering non-Java names. |
|
69 * Any name legal to the JVM may be given between the double quotes. |
|
70 * <p> |
|
71 * None of these calls is complete without a bootstrap method, |
|
72 * which must be declared for the enclosing class or method. |
|
73 * @author John Rose, JSR 292 EG |
|
74 */ |
|
75 @MethodHandle.PolymorphicSignature |
|
76 public final class InvokeDynamic { |
|
77 private InvokeDynamic() { throw new InternalError(); } // do not instantiate |
|
78 |
|
79 // no statically defined static methods |
|
80 } |
|