author | jrose |
Wed, 23 Mar 2011 23:02:31 -0700 | |
changeset 8822 | 8145ab9f5f86 |
parent 8349 | jdk/src/share/classes/java/dyn/package-info.java@e1ba54c43609 |
child 9266 | 121fb370f179 |
permissions | -rw-r--r-- |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
1 |
/* |
8345
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
2 |
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
4 |
* |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
10 |
* |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
15 |
* accompanied this code). |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
16 |
* |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
20 |
* |
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
24 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
25 |
|
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
26 |
/** |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
27 |
* The {@code java.lang.invoke} package contains dynamic language support provided directly by |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
28 |
* the Java core class libraries and virtual machine. |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
29 |
* |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
30 |
* <p> |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
31 |
* Certain types in this package have special relations to dynamic |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
32 |
* language support in the virtual machine: |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
33 |
* <ul> |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
34 |
* <li>The class {@link java.lang.invoke.MethodHandle MethodHandle} contains |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
35 |
* <a href="MethodHandle.html#sigpoly">signature polymorphic methods</a> |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
36 |
* which can be linked regardless of their type descriptor. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
37 |
* Normally, method linkage requires exact matching of type descriptors. |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
38 |
* </li> |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
39 |
* |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
40 |
* <li>The JVM bytecode format supports immediate constants of |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
41 |
* the classes {@link java.lang.invoke.MethodHandle MethodHandle} and {@link java.lang.invoke.MethodType MethodType}. |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
42 |
* </li> |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
43 |
* </ul> |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
44 |
* |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
45 |
* <h2><a name="jvm_mods"></a>Corresponding JVM bytecode format changes</h2> |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
46 |
* <em>The following low-level information is presented here as a preview of |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
47 |
* changes being made to the Java Virtual Machine specification for JSR 292. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
48 |
* This information will be incorporated in a future version of the JVM specification.</em> |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
49 |
* |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
50 |
* <h3><a name="indyinsn"></a>{@code invokedynamic} instruction format</h3> |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
51 |
* In bytecode, an {@code invokedynamic} instruction is formatted as five bytes. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
52 |
* The first byte is the opcode 186 (hexadecimal {@code BA}). |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
53 |
* The next two bytes are a constant pool index (in the same format as for the other {@code invoke} instructions). |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
54 |
* The final two bytes are reserved for future use and required to be zero. |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
55 |
* The constant pool reference of an {@code invokedynamic} instruction is to a entry |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
56 |
* with tag {@code CONSTANT_InvokeDynamic} (decimal 18). See below for its format. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
57 |
* The entry specifies the following information: |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
58 |
* <ul> |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
59 |
* <li>a bootstrap method (a {@link java.lang.invoke.MethodHandle MethodHandle} constant)</li> |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
60 |
* <li>the dynamic invocation name (a UTF8 string)</li> |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
61 |
* <li>the argument and return types of the call (encoded as a type descriptor in a UTF8 string)</li> |
7557
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
62 |
* <li>optionally, a sequence of additional <em>static arguments</em> to the bootstrap method ({@code ldc}-type constants)</li> |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
63 |
* </ul> |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
64 |
* <p> |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
65 |
* Each instance of an {@code invokedynamic} instruction is called a <em>dynamic call site</em>. |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
66 |
* Multiple instances of an {@code invokedynamic} instruction can share a single |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
67 |
* {@code CONSTANT_InvokeDynamic} entry. |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
68 |
* In any case, distinct call sites always have distinct linkage state. |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
69 |
* <p> |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
70 |
* A dynamic call site is originally in an unlinked state. In this state, there is |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
71 |
* no target method for the call site to invoke. |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
72 |
* A dynamic call site is linked by means of a bootstrap method, |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
73 |
* as <a href="#bsm">described below</a>. |
7557
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
74 |
* |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
75 |
* <h3><a name="indycon"></a>constant pool entries for {@code invokedynamic} instructions</h3> |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
76 |
* If a constant pool entry has the tag {@code CONSTANT_InvokeDynamic} (decimal 18), |
7557
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
77 |
* it must contain exactly four more bytes after the tag. |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
78 |
* These bytes are interpreted as two 16-bit indexes, in the usual {@code u2} format. |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
79 |
* The first pair of bytes after the tag must be an index into a side table called the |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
80 |
* <em>bootstrap method table</em>, which is stored in the {@code BootstrapMethods} |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
81 |
* attribute as <a href="#bsmattr">described below</a>. |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
82 |
* The second pair of bytes must be an index to a {@code CONSTANT_NameAndType}. |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
83 |
* <p> |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
84 |
* The first index specifies a bootstrap method used by the associated dynamic call sites. |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
85 |
* The second index specifies the method name, argument types, and return type of the dynamic call site. |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
86 |
* The structure of such an entry is therefore analogous to a {@code CONSTANT_Methodref}, |
7557
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
87 |
* except that the bootstrap method specifier reference replaces |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
88 |
* the {@code CONSTANT_Class} reference of a {@code CONSTANT_Methodref} entry. |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
89 |
* |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
90 |
* <h3><a name="mtcon"></a>constant pool entries for {@linkplain java.lang.invoke.MethodType method types}</h3> |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
91 |
* If a constant pool entry has the tag {@code CONSTANT_MethodType} (decimal 16), |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
92 |
* it must contain exactly two more bytes, which must be an index to a {@code CONSTANT_Utf8} |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
93 |
* entry which represents a method type descriptor. |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
94 |
* <p> |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
95 |
* The JVM will ensure that on first |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
96 |
* execution of an {@code ldc} instruction for this entry, a {@link java.lang.invoke.MethodType MethodType} |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
97 |
* will be created which represents the type descriptor. |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
98 |
* Any classes mentioned in the {@code MethodType} will be loaded if necessary, |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
99 |
* but not initialized. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
100 |
* Access checking and error reporting is performed exactly as it is for |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
101 |
* references by {@code ldc} instructions to {@code CONSTANT_Class} constants. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
102 |
* |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
103 |
* <h3><a name="mhcon"></a>constant pool entries for {@linkplain java.lang.invoke.MethodHandle method handles}</h3> |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
104 |
* If a constant pool entry has the tag {@code CONSTANT_MethodHandle} (decimal 15), |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
105 |
* it must contain exactly three more bytes. The first byte after the tag is a subtag |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
106 |
* value which must be in the range 1 through 9, and the last two must be an index to a |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
107 |
* {@code CONSTANT_Fieldref}, {@code CONSTANT_Methodref}, or |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
108 |
* {@code CONSTANT_InterfaceMethodref} entry which represents a field or method |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
109 |
* for which a method handle is to be created. |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
110 |
* Furthermore, the subtag value and the type of the constant index value |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
111 |
* must agree according to the table below. |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
112 |
* <p> |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
113 |
* The JVM will ensure that on first execution of an {@code ldc} instruction |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
114 |
* for this entry, a {@link java.lang.invoke.MethodHandle MethodHandle} will be created which represents |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
115 |
* the field or method reference, according to the specific mode implied by the subtag. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
116 |
* <p> |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
117 |
* As with {@code CONSTANT_Class} and {@code CONSTANT_MethodType} constants, |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
118 |
* the {@code Class} or {@code MethodType} object which reifies the field or method's |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
119 |
* type is created. Any classes mentioned in this reification will be loaded if necessary, |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
120 |
* but not initialized, and access checking and error reporting performed as usual. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
121 |
* <p> |
8349
e1ba54c43609
7014755: JSR 292 member lookup interaction with security manager
jrose
parents:
8346
diff
changeset
|
122 |
* Unlike the reflective {@code Lookup} API, there are no security manager calls made |
e1ba54c43609
7014755: JSR 292 member lookup interaction with security manager
jrose
parents:
8346
diff
changeset
|
123 |
* when these constants are resolved. |
e1ba54c43609
7014755: JSR 292 member lookup interaction with security manager
jrose
parents:
8346
diff
changeset
|
124 |
* <p> |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
125 |
* The method handle itself will have a type and behavior determined by the subtag as follows: |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
126 |
* <code> |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
127 |
* <table border=1 cellpadding=5 summary="CONSTANT_MethodHandle subtypes"> |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
128 |
* <tr><th>N</th><th>subtag name</th><th>member</th><th>MH type</th><th>bytecode behavior</th><th>lookup expression</th></tr> |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
129 |
* <tr><td>1</td><td>REF_getField</td><td>C.f:T</td><td>(C)T</td><td>getfield C.f:T</td> |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
130 |
* <td>{@linkplain java.lang.invoke.MethodHandles.Lookup#findGetter findGetter(C.class,"f",T.class)}</td></tr> |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
131 |
* <tr><td>2</td><td>REF_getStatic</td><td>C.f:T</td><td>( )T</td><td>getstatic C.f:T</td> |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
132 |
* <td>{@linkplain java.lang.invoke.MethodHandles.Lookup#findStaticGetter findStaticGetter(C.class,"f",T.class)}</td></tr> |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
133 |
* <tr><td>3</td><td>REF_putField</td><td>C.f:T</td><td>(C,T)void</td><td>putfield C.f:T</td> |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
134 |
* <td>{@linkplain java.lang.invoke.MethodHandles.Lookup#findSetter findSetter(C.class,"f",T.class)}</td></tr> |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
135 |
* <tr><td>4</td><td>REF_putStatic</td><td>C.f:T</td><td>(T)void</td><td>putstatic C.f:T</td> |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
136 |
* <td>{@linkplain java.lang.invoke.MethodHandles.Lookup#findStaticSetter findStaticSetter(C.class,"f",T.class)}</td></tr> |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
137 |
* <tr><td>5</td><td>REF_invokeVirtual</td><td>C.m(A*)T</td><td>(C,A*)T</td><td>invokevirtual C.m(A*)T</td> |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
138 |
* <td>{@linkplain java.lang.invoke.MethodHandles.Lookup#findVirtual findVirtual(C.class,"m",MT)}</td></tr> |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
139 |
* <tr><td>6</td><td>REF_invokeStatic</td><td>C.m(A*)T</td><td>(C,A*)T</td><td>invokestatic C.m(A*)T</td> |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
140 |
* <td>{@linkplain java.lang.invoke.MethodHandles.Lookup#findStatic findStatic(C.class,"m",MT)}</td></tr> |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
141 |
* <tr><td>7</td><td>REF_invokeSpecial</td><td>C.m(A*)T</td><td>(C,A*)T</td><td>invokespecial C.m(A*)T</td> |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
142 |
* <td>{@linkplain java.lang.invoke.MethodHandles.Lookup#findSpecial findSpecial(C.class,"m",MT,this.class)}</td></tr> |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
143 |
* <tr><td>8</td><td>REF_newInvokeSpecial</td><td>C.<init>(A*)void</td><td>(A*)C</td><td>new C; dup; invokespecial C.<init>(A*)void</td> |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
144 |
* <td>{@linkplain java.lang.invoke.MethodHandles.Lookup#findConstructor findConstructor(C.class,MT)}</td></tr> |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
145 |
* <tr><td>9</td><td>REF_invokeInterface</td><td>C.m(A*)T</td><td>(C,A*)T</td><td>invokeinterface C.m(A*)T</td> |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
146 |
* <td>{@linkplain java.lang.invoke.MethodHandles.Lookup#findVirtual findVirtual(C.class,"m",MT)}</td></tr> |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
147 |
* </table> |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
148 |
* </code> |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
149 |
* Here, the type {@code C} is taken from the {@code CONSTANT_Class} reference associated |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
150 |
* with the {@code CONSTANT_NameAndType} descriptor. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
151 |
* The field name {@code f} or method name {@code m} is taken from the {@code CONSTANT_NameAndType} |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
152 |
* as is the result type {@code T} and (in the case of a method or constructor) the argument type sequence |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
153 |
* {@code A*}. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
154 |
* <p> |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
155 |
* Each method handle constant has an equivalent instruction sequence called its <em>bytecode behavior</em>. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
156 |
* In general, creating a method handle constant can be done in exactly the same circumstances that |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
157 |
* the JVM would successfully resolve the symbolic references in the bytecode behavior. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
158 |
* Also, the type of a method handle constant is such that a valid {@code invokeExact} call |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
159 |
* on the method handle has exactly the same JVM stack effects as the <em>bytecode behavior</em>. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
160 |
* Finally, calling a method handle constant on a valid set of arguments has exactly the same effect |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
161 |
* and returns the same result (if any) as the corresponding <em>bytecode behavior</em>. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
162 |
* <p> |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
163 |
* Each method handle constant also has an equivalent reflective <em>lookup expression</em>, |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
164 |
* which is a query to a method in {@link java.lang.invoke.MethodHandles.Lookup}. |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
165 |
* In the example lookup method expression given in the table above, the name {@code MT} |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
166 |
* stands for a {@code MethodType} built from {@code T} and the sequence of argument types {@code A*}. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
167 |
* (Note that the type {@code C} is not prepended to the query type {@code MT} even if the member is non-static.) |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
168 |
* In the case of {@code findSpecial}, the name {@code this.class} refers to the class containing |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
169 |
* the bytecodes. |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
170 |
* <p> |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
171 |
* The special name {@code <clinit>} is not allowed. |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
172 |
* The special name {@code <init>} is not allowed except for subtag 8 as shown. |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
173 |
* <p> |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
174 |
* The JVM verifier and linker apply the same access checks and restrictions for these references as for the hypothetical |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
175 |
* bytecode instructions specified in the last column of the table. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
176 |
* A method handle constant will successfully resolve to a method handle if the symbolic references |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
177 |
* of the corresponding bytecode instruction(s) would also resolve successfully. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
178 |
* Otherwise, an attempt to resolve the constant will throw equivalent linkage errors. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
179 |
* In particular, method handles to |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
180 |
* private and protected members can be created in exactly those classes for which the corresponding |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
181 |
* normal accesses are legal. |
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
182 |
* <p> |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
183 |
* A constant may refer to a method or constructor with the {@code varargs} |
8345
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
184 |
* bit (hexadecimal {@code 0x0080}) set in its modifier bitmask. |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
185 |
* The method handle constant produced for such a method behaves as if |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
186 |
* it were created by {@link java.lang.invoke.MethodHandle#asVarargsCollector asVarargsCollector}. |
8345
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
187 |
* In other words, the constant method handle will exhibit variable arity, |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
188 |
* when invoked via {@code invokeGeneric}. |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
189 |
* On the other hand, its behavior with respect to {@code invokeExact} will be the same |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
190 |
* as if the {@code varargs} bit were not set. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
191 |
* <p> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
192 |
* Although the {@code CONSTANT_MethodHandle} and {@code CONSTANT_MethodType} constant types |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
193 |
* resolve class names, they do not force class initialization. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
194 |
* Method handle constants for subtags {@code REF_getStatic}, {@code REF_putStatic}, and {@code REF_invokeStatic} |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
195 |
* may force class initialization on their first invocation, just like the corresponding bytecodes. |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
196 |
* <p> |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
197 |
* The rules of section 5.4.3 of the |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
198 |
* <a href="http://java.sun.com/docs/books/jvms/second_edition/html/ConstantPool.doc.html#73492">JVM Specification</a> |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
199 |
* apply to the resolution of {@code CONSTANT_MethodType}, {@code CONSTANT_MethodHandle}, |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
200 |
* and {@code CONSTANT_InvokeDynamic} constants, |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
201 |
* by the execution of {@code invokedynamic} and {@code ldc} instructions. |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
202 |
* (Roughly speaking, this means that every use of a constant pool entry |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
203 |
* must lead to the same outcome. |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
204 |
* If the resolution succeeds, the same object reference is produced |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
205 |
* by every subsequent execution of the same instruction. |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
206 |
* If the resolution of the constant causes an error to occur, |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
207 |
* the same error will be re-thrown on every subsequent attempt |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
208 |
* to use this particular constant.) |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
209 |
* <p> |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
210 |
* Constants created by the resolution of these constant pool types are not necessarily |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
211 |
* interned. Except for {@code CONSTANT_Class} and {@code CONSTANT_String} entries, |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
212 |
* two distinct constant pool entries might not resolve to the same reference |
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
213 |
* even if they contain the same symbolic reference. |
5722
4ada807383c8
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
4537
diff
changeset
|
214 |
* |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
215 |
* <h2><a name="bsm"></a>Bootstrap Methods</h2> |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
216 |
* Before the JVM can execute a dynamic call site (an {@code invokedynamic} instruction), |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
217 |
* the call site must first be <em>linked</em>. |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
218 |
* Linking is accomplished by calling a <em>bootstrap method</em> |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
219 |
* which is given the static information content of the call site, |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
220 |
* and which must produce a {@link java.lang.invoke.MethodHandle method handle} |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
221 |
* that gives the behavior of the call site. |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
222 |
* <p> |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
223 |
* Each {@code invokedynamic} instruction statically specifies its own |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
224 |
* bootstrap method as a constant pool reference. |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
225 |
* The constant pool reference also specifies the call site's name and type descriptor, |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
226 |
* just like {@code invokevirtual} and the other invoke instructions. |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
227 |
* <p> |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
228 |
* Linking starts with resolving the constant pool entry for the |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
229 |
* bootstrap method, and resolving a {@link java.lang.invoke.MethodType MethodType} object for |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
230 |
* the type descriptor of the dynamic call site. |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
231 |
* This resolution process may trigger class loading. |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
232 |
* It may therefore throw an error if a class fails to load. |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
233 |
* This error becomes the abnormal termination of the dynamic |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
234 |
* call site execution. |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
235 |
* Linkage does not trigger class initialization. |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
236 |
* <p> |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
237 |
* Next, the bootstrap method call is started, with at least four values being stacked: |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
238 |
* <ul> |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
239 |
* <li>a {@code MethodHandle}, the resolved bootstrap method itself </li> |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
240 |
* <li>a {@code MethodHandles.Lookup}, a lookup object on the <em>caller class</em> in which dynamic call site occurs </li> |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
241 |
* <li>a {@code String}, the method name mentioned in the call site </li> |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
242 |
* <li>a {@code MethodType}, the resolved type descriptor of the call </li> |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
243 |
* <li>optionally, one or more <a href="#args">additional static arguments</a> </li> |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
244 |
* </ul> |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
245 |
* The method handle is then applied to the other values as if by |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
246 |
* {@link java.lang.invoke.MethodHandle#invokeGeneric invokeGeneric}. |
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
247 |
* The returned result must be a {@link java.lang.invoke.CallSite CallSite} (or a subclass). |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
248 |
* The type of the call site's target must be exactly equal to the type |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
249 |
* derived from the dynamic call site's type descriptor and passed to |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
250 |
* the bootstrap method. |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
251 |
* The call site then becomes permanently linked to the dynamic call site. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
252 |
* <p> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
253 |
* As long as each bootstrap method can be correctly invoked |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
254 |
* by <code>invokeGeneric</code>, its detailed type is arbitrary. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
255 |
* For example, the first argument could be {@code Object} |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
256 |
* instead of {@code MethodHandles.Lookup}, and the return type |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
257 |
* could also be {@code Object} instead of {@code CallSite}. |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
258 |
* (Note that the types and number of the stacked arguments limit |
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
259 |
* the legal kinds of bootstrap methods to appropriately typed |
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
260 |
* static methods and constructors of {@code CallSite} subclasses.) |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
261 |
* <p> |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
262 |
* After resolution, the linkage process may fail in a variety of ways. |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
263 |
* All failures are reported by a {@link java.lang.BootstrapMethodError BootstrapMethodError}, |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
264 |
* which is thrown as the abnormal termination of the dynamic call |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
265 |
* site execution. |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
266 |
* The following circumstances will cause this: |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
267 |
* <ul> |
7557
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
268 |
* <li>the index to the bootstrap method specifier is out of range </li> |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
269 |
* <li>the bootstrap method cannot be resolved </li> |
7557
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
270 |
* <li>the {@code MethodType} to pass to the bootstrap method cannot be resolved </li> |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
271 |
* <li>a static argument to the bootstrap method cannot be resolved |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
272 |
* (i.e., a {@code CONSTANT_Class}, {@code CONSTANT_MethodType}, |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
273 |
* or {@code CONSTANT_MethodHandle} argument cannot be linked) </li> |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
274 |
* <li>the bootstrap method has the wrong arity, |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
275 |
* causing {@code invokeGeneric} to throw {@code WrongMethodTypeException} </li> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
276 |
* <li>the bootstrap method has a wrong argument or return type </li> |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
277 |
* <li>the bootstrap method invocation completes abnormally </li> |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
278 |
* <li>the result from the bootstrap invocation is not a reference to |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
279 |
* an object of type {@link java.lang.invoke.CallSite CallSite} </li> |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
280 |
* <li>the target of the {@code CallSite} does not have a target of |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
281 |
* the expected {@code MethodType} </li> |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
282 |
* </ul> |
7557
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
283 |
* |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
284 |
* <h3><a name="linktime"></a>timing of linkage</h3> |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
285 |
* A dynamic call site is linked just before its first execution. |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
286 |
* The bootstrap method call implementing the linkage occurs within |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
287 |
* a thread that is attempting a first execution. |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
288 |
* <p> |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
289 |
* If there are several such threads, the bootstrap method may be |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
290 |
* invoked in several threads concurrently. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
291 |
* Therefore, bootstrap methods which access global application |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
292 |
* data must take the usual precautions against race conditions. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
293 |
* In any case, every {@code invokedynamic} instruction is either |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
294 |
* unlinked or linked to a unique {@code CallSite} object. |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
295 |
* <p> |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
296 |
* In an application which requires dynamic call sites with individually |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
297 |
* mutable behaviors, their bootstrap methods should produce distinct |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
298 |
* {@link java.lang.invoke.CallSite CallSite} objects, one for each linkage request. |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
299 |
* Alternatively, an application can link a single {@code CallSite} object |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
300 |
* to several {@code invokedynamic} instructions, in which case |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
301 |
* a change to the target method will become visible at each of |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
302 |
* the instructions. |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
303 |
* <p> |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
304 |
* If several threads simultaneously execute a bootstrap method for a single dynamic |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
305 |
* call site, the JVM must choose one {@code CallSite} object and install it visibly to |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
306 |
* all threads. Any other bootstrap method calls are allowed to complete, but their |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
307 |
* results are ignored, and their dynamic call site invocations proceed with the originally |
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
308 |
* chosen target object. |
7557
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
309 |
* |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
310 |
* <p style="font-size:smaller;"> |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
311 |
* <em>Discussion:</em> |
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
312 |
* These rules do not enable the JVM to duplicate dynamic call sites, |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
313 |
* or to issue “causeless” bootstrap method calls. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
314 |
* Every dynamic call site transitions at most once from unlinked to linked, |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
315 |
* just before its first invocation. |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
316 |
* There is no way to undo the effect of a completed bootstrap method call. |
7557
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
317 |
* |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
318 |
* <h3><a name="bsmattr">the {@code BootstrapMethods} attribute </h3> |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
319 |
* Each {@code CONSTANT_InvokeDynamic} entry contains an index which references |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
320 |
* a bootstrap method specifier; all such specifiers are contained in a separate array. |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
321 |
* This array is defined by a class attribute named {@code BootstrapMethods}. |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
322 |
* The body of this attribute consists of a sequence of byte pairs, all interpreted as |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
323 |
* as 16-bit counts or constant pool indexes, in the {@code u2} format. |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
324 |
* The attribute body starts with a count of bootstrap method specifiers, |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
325 |
* which is immediately followed by the sequence of specifiers. |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
326 |
* <p> |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
327 |
* Each bootstrap method specifier contains an index to a |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
328 |
* {@code CONSTANT_MethodHandle} constant, which is the bootstrap |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
329 |
* method itself. |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
330 |
* This is followed by a count, and then a sequence (perhaps empty) of |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
331 |
* indexes to <a href="#args">additional static arguments</a> |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
332 |
* for the bootstrap method. |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
333 |
* <p> |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
334 |
* During class loading, the verifier must check the structure of the |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
335 |
* {@code BootstrapMethods} attribute. In particular, each constant |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
336 |
* pool index must be of the correct type. A bootstrap method index |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
337 |
* must refer to a {@code CONSTANT_MethodHandle} (tag 15). |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
338 |
* Every other index must refer to a valid operand of an |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
339 |
* {@code ldc_w} or {@code ldc2_w} instruction (tag 3..8 or 15..16). |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
340 |
* |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
341 |
* <h3><a name="args">static arguments to the bootstrap method</h3> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
342 |
* An {@code invokedynamic} instruction specifies at least three arguments |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
343 |
* to pass to its bootstrap method: |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
344 |
* The caller class (expressed as a {@link java.lang.invoke.MethodHandles.Lookup Lookup object}, |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
345 |
* the name (extracted from the {@code CONSTANT_NameAndType} entry), |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
346 |
* and the type (also extracted from the {@code CONSTANT_NameAndType} entry). |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
347 |
* The {@code invokedynamic} instruction may specify additional metadata values |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
348 |
* to pass to its bootstrap method. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
349 |
* Collectively, these values are called <em>static arguments</em> to the |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
350 |
* {@code invokedynamic} instruction, because they are used once at link |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
351 |
* time to determine the instruction's behavior on subsequent sets of |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
352 |
* <em>dynamic arguments</em>. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
353 |
* <p> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
354 |
* Static arguments are used to communicate application-specific meta-data |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
355 |
* to the bootstrap method. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
356 |
* Drawn from the constant pool, they may include references to classes, method handles, |
7557
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
357 |
* strings, or numeric data that may be relevant to the task of linking that particular call site. |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
358 |
* <p> |
7557
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
359 |
* Static arguments are specified constant pool indexes stored in the {@code BootstrapMethods} attribute. |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
360 |
* Before the bootstrap method is invoked, each index is used to compute an {@code Object} |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
361 |
* reference to the indexed value in the constant pool. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
362 |
* The valid constant pool entries are listed in this table: |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
363 |
* <code> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
364 |
* <table border=1 cellpadding=5 summary="Static argument types"> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
365 |
* <tr><th>entry type</th><th>argument type</th><th>argument value</th></tr> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
366 |
* <tr><td>CONSTANT_String</td><td><code>java.lang.String</code></td><td>the indexed string literal</td></tr> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
367 |
* <tr><td>CONSTANT_Class</td><td><code>java.lang.Class</code></td><td>the indexed class, resolved</td></tr> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
368 |
* <tr><td>CONSTANT_Integer</td><td><code>java.lang.Integer</code></td><td>the indexed int value</td></tr> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
369 |
* <tr><td>CONSTANT_Long</td><td><code>java.lang.Long</code></td><td>the indexed long value</td></tr> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
370 |
* <tr><td>CONSTANT_Float</td><td><code>java.lang.Float</code></td><td>the indexed float value</td></tr> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
371 |
* <tr><td>CONSTANT_Double</td><td><code>java.lang.Double</code></td><td>the indexed double value</td></tr> |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
372 |
* <tr><td>CONSTANT_MethodHandle</td><td><code>java.lang.invoke.MethodHandle</code></td><td>the indexed method handle constant</td></tr> |
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
373 |
* <tr><td>CONSTANT_MethodType</td><td><code>java.lang.invoke.MethodType</code></td><td>the indexed method type constant</td></tr> |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
374 |
* </table> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
375 |
* </code> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
376 |
* <p> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
377 |
* If a given {@code invokedynamic} instruction specifies no static arguments, |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
378 |
* the instruction's bootstrap method will be invoked on three arguments, |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
379 |
* conveying the instruction's caller class, name, and method type. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
380 |
* If the {@code invokedynamic} instruction specifies one or more static arguments, |
8345
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
381 |
* those values will be passed as additional arguments to the method handle. |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
382 |
* (Note that because there is a limit of 255 arguments to any method, |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
383 |
* at most 252 extra arguments can be supplied.) |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
384 |
* The bootstrap method will be invoked as if by either {@code invokeGeneric} |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
385 |
* or {@code invokeWithArguments}. (There is no way to tell the difference.) |
8346
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
386 |
* <p> |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
387 |
* The normal argument conversion rules for {@code invokeGeneric} apply to all stacked arguments. |
3b891698c4ec
7012650: implement JSR 292 EG adjustments through January 2010
jrose
parents:
8345
diff
changeset
|
388 |
* For example, if a pushed value is a primitive type, it may be converted to a reference by boxing conversion. |
8345
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
389 |
* If the bootstrap method is a variable arity method (its modifier bit {@code 0x0080} is set), |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
390 |
* then some or all of the arguments specified here may be collected into a trailing array parameter. |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
391 |
* (This is not a special rule, but rather a useful consequence of the interaction |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
392 |
* between {@code CONSTANT_MethodHandle} constants, the modifier bit for variable arity methods, |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
393 |
* and the {@code java.lang.invoke.MethodHandle#asVarargsCollector asVarargsCollector} transformation.) |
8345
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
394 |
* <p> |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
395 |
* Given these rules, here are examples of legal bootstrap method declarations, |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
396 |
* given various numbers {@code N} of extra arguments. |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
397 |
* The first rows (marked {@code *}) will work for any number of extra arguments. |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
398 |
* <code> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
399 |
* <table border=1 cellpadding=5 summary="Static argument types"> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
400 |
* <tr><th>N</th><th>sample bootstrap method</th></tr> |
8345
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
401 |
* <tr><td>*</td><td><code>CallSite bootstrap(Lookup caller, String name, MethodType type, Object... args)</code></td></tr> |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
402 |
* <tr><td>*</td><td><code>CallSite bootstrap(Object... args)</code></td></tr> |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
403 |
* <tr><td>*</td><td><code>CallSite bootstrap(Object caller, Object... nameAndTypeWithArgs)</code></td></tr> |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
404 |
* <tr><td>0</td><td><code>CallSite bootstrap(Lookup caller, String name, MethodType type)</code></td></tr> |
8345
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
405 |
* <tr><td>0</td><td><code>CallSite bootstrap(Lookup caller, Object... nameAndType)</code></td></tr> |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
406 |
* <tr><td>1</td><td><code>CallSite bootstrap(Lookup caller, String name, MethodType type, Object arg)</code></td></tr> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
407 |
* <tr><td>2</td><td><code>CallSite bootstrap(Lookup caller, String name, MethodType type, Object... args)</code></td></tr> |
8345
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
408 |
* <tr><td>2</td><td><code>CallSite bootstrap(Lookup caller, String name, MethodType type, String... args)</code></td></tr> |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
409 |
* <tr><td>2</td><td><code>CallSite bootstrap(Lookup caller, String name, MethodType type, String x, int y)</code></td></tr> |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
410 |
* </table> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
411 |
* </code> |
8345
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
412 |
* The last example assumes that the extra arguments are of type |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
413 |
* {@code CONSTANT_String} and {@code CONSTANT_Integer}, respectively. |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
414 |
* The second-to-last example assumes that all extra arguments are of type |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
415 |
* {@code CONSTANT_String}. |
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
416 |
* The other examples work with all types of extra arguments. |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
417 |
* <p> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
418 |
* As noted above, the actual method type of the bootstrap method can vary. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
419 |
* For example, the fourth argument could be {@code MethodHandle}, |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
420 |
* if that is the type of the corresponding constant in |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
421 |
* the {@code CONSTANT_InvokeDynamic} entry. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
422 |
* In that case, the {@code invokeGeneric} call will pass the extra method handle |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
423 |
* constant as an {@code Object}, but the type matching machinery of {@code invokeGeneric} |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
424 |
* will cast the reference back to {@code MethodHandle} before invoking the bootstrap method. |
8345
9e2483e6cfab
7013417: JSR 292 needs to support variadic method handle calls
jrose
parents:
7668
diff
changeset
|
425 |
* (If a string constant were passed instead, by badly generated code, that cast would then fail, |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
426 |
* resulting in a {@code BootstrapMethodError}.) |
7555
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
427 |
* <p> |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
428 |
* Extra bootstrap method arguments are intended to allow language implementors |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
429 |
* to safely and compactly encode metadata. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
430 |
* In principle, the name and extra arguments are redundant, |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
431 |
* since each call site could be given its own unique bootstrap method. |
a279ebc3b25c
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
7051
diff
changeset
|
432 |
* Such a practice is likely to produce large class files and constant pools. |
7557
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
433 |
* |
7562
a0ad195efe2c
7001424: implement JSR 292 EG adjustments, November 2010
jrose
parents:
7557
diff
changeset
|
434 |
* <h2><a name="structs"></a>Structure Summary</h2> |
7557
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
435 |
* <blockquote><pre>// summary of constant and attribute structures |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
436 |
struct CONSTANT_MethodHandle_info { |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
437 |
u1 tag = 15; |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
438 |
u1 reference_kind; // 1..8 (one of REF_invokeVirtual, etc.) |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
439 |
u2 reference_index; // index to CONSTANT_Fieldref or *Methodref |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
440 |
} |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
441 |
struct CONSTANT_MethodType_info { |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
442 |
u1 tag = 16; |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
443 |
u2 descriptor_index; // index to CONSTANT_Utf8, as in NameAndType |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
444 |
} |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
445 |
struct CONSTANT_InvokeDynamic_info { |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
446 |
u1 tag = 18; |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
447 |
u2 bootstrap_method_attr_index; // index into BootstrapMethods_attr |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
448 |
u2 name_and_type_index; // index to CONSTANT_NameAndType, as in Methodref |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
449 |
} |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
450 |
struct BootstrapMethods_attr { |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
451 |
u2 name; // CONSTANT_Utf8 = "BootstrapMethods" |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
452 |
u4 size; |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
453 |
u2 bootstrap_method_count; |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
454 |
struct bootstrap_method_specifier { |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
455 |
u2 bootstrap_method_ref; // index to CONSTANT_MethodHandle |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
456 |
u2 bootstrap_argument_count; |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
457 |
u2 bootstrap_arguments[bootstrap_argument_count]; // constant pool indexes |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
458 |
} bootstrap_methods[bootstrap_method_count]; |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
459 |
} |
06bbd3ae0835
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7555
diff
changeset
|
460 |
* </pre></blockquote> |
7051
1c545d70a157
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5725
diff
changeset
|
461 |
* |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
462 |
* @author John Rose, JSR 292 EG |
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
463 |
* @since 1.7 |
2707
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
464 |
*/ |
5a17df307cbc
6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff
changeset
|
465 |
|
8822
8145ab9f5f86
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
8349
diff
changeset
|
466 |
package java.lang.invoke; |