65 static void test() throws Throwable {
66 // THE FOLLOWING LINE IS PSEUDOCODE FOR A JVM INSTRUCTION
67 InvokeDynamic[#bootstrapDynamic].baz("baz arg", 2, 3.14);
68 }
69 private static void printArgs(Object... args) {
70 System.out.println(java.util.Arrays.deepToString(args));
71 }
72 private static final MethodHandle printArgs;
73 static {
74 MethodHandles.Lookup lookup = MethodHandles.lookup();
75 Class thisClass = lookup.lookupClass(); // (who am I?)
76 printArgs = lookup.findStatic(thisClass,
77 "printArgs", MethodType.methodType(void.class, Object[].class));
78 }
79 private static CallSite bootstrapDynamic(MethodHandles.Lookup caller, String name, MethodType type) {
80 // ignore caller and name, but match the type:
81 return new ConstantCallSite(printArgs.asType(type));
82 }
83 }</pre></blockquote>
84 * @author John Rose, JSR 292 EG
85 */
86 abstract
87 public class CallSite {
88
89 // The actual payload of this call site:
90 /*package-private*/
91 MethodHandle target; // Note: This field is known to the JVM. Do not change.
92
93 /**
94 * Make a blank call site object with the given method type.
95 * An initial target method is supplied which will throw
96 * an {@link IllegalStateException} if called.
97 * <p>
98 * Before this {@code CallSite} object is returned from a bootstrap method,
99 * it is usually provided with a more useful target method,
100 * via a call to {@link CallSite#setTarget(MethodHandle) setTarget}.
101 * @throws NullPointerException if the proposed type is null
102 */
103 /*package-private*/
104 CallSite(MethodType type) {
|
65 static void test() throws Throwable {
66 // THE FOLLOWING LINE IS PSEUDOCODE FOR A JVM INSTRUCTION
67 InvokeDynamic[#bootstrapDynamic].baz("baz arg", 2, 3.14);
68 }
69 private static void printArgs(Object... args) {
70 System.out.println(java.util.Arrays.deepToString(args));
71 }
72 private static final MethodHandle printArgs;
73 static {
74 MethodHandles.Lookup lookup = MethodHandles.lookup();
75 Class thisClass = lookup.lookupClass(); // (who am I?)
76 printArgs = lookup.findStatic(thisClass,
77 "printArgs", MethodType.methodType(void.class, Object[].class));
78 }
79 private static CallSite bootstrapDynamic(MethodHandles.Lookup caller, String name, MethodType type) {
80 // ignore caller and name, but match the type:
81 return new ConstantCallSite(printArgs.asType(type));
82 }
83 }</pre></blockquote>
84 * @author John Rose, JSR 292 EG
85 * @since 1.7
86 */
87 abstract
88 public class CallSite {
89
90 // The actual payload of this call site:
91 /*package-private*/
92 MethodHandle target; // Note: This field is known to the JVM. Do not change.
93
94 /**
95 * Make a blank call site object with the given method type.
96 * An initial target method is supplied which will throw
97 * an {@link IllegalStateException} if called.
98 * <p>
99 * Before this {@code CallSite} object is returned from a bootstrap method,
100 * it is usually provided with a more useful target method,
101 * via a call to {@link CallSite#setTarget(MethodHandle) setTarget}.
102 * @throws NullPointerException if the proposed type is null
103 */
104 /*package-private*/
105 CallSite(MethodType type) {
|