Mercurial > hg > graal-jvmci-8
annotate src/share/vm/prims/methodHandles.hpp @ 1913:3b2dea75431e
6984311: JSR 292 needs optional bootstrap method parameters
Summary: Allow CONSTANT_InvokeDynamic nodes to have any number of extra operands.
Reviewed-by: twisti
author | jrose |
---|---|
date | Sat, 30 Oct 2010 13:08:23 -0700 |
parents | 5beba6174298 |
children | f95d63e2154a |
rev | line source |
---|---|
710 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1507
diff
changeset
|
2 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. |
710 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1507
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1507
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1507
diff
changeset
|
21 * questions. |
710 | 22 * |
23 */ | |
24 | |
25 class MacroAssembler; | |
26 class Label; | |
27 class MethodHandleEntry; | |
28 | |
29 class MethodHandles: AllStatic { | |
30 // JVM support for MethodHandle, MethodType, and related types | |
31 // in java.dyn and java.dyn.hotspot. | |
32 // See also javaClasses for layouts java_dyn_Method{Handle,Type,Type::Form}. | |
33 public: | |
34 enum EntryKind { | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
35 _raise_exception, // stub for error generation from other stubs |
710 | 36 _invokestatic_mh, // how a MH emulates invokestatic |
37 _invokespecial_mh, // ditto for the other invokes... | |
38 _invokevirtual_mh, | |
39 _invokeinterface_mh, | |
40 _bound_ref_mh, // reference argument is bound | |
41 _bound_int_mh, // int argument is bound (via an Integer or Float) | |
42 _bound_long_mh, // long argument is bound (via a Long or Double) | |
43 _bound_ref_direct_mh, // same as above, with direct linkage to methodOop | |
44 _bound_int_direct_mh, | |
45 _bound_long_direct_mh, | |
46 | |
47 _adapter_mh_first, // adapter sequence goes here... | |
48 _adapter_retype_only = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_RETYPE_ONLY, | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
49 _adapter_retype_raw = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_RETYPE_RAW, |
710 | 50 _adapter_check_cast = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_CHECK_CAST, |
51 _adapter_prim_to_prim = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_PRIM_TO_PRIM, | |
52 _adapter_ref_to_prim = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_REF_TO_PRIM, | |
53 _adapter_prim_to_ref = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_PRIM_TO_REF, | |
54 _adapter_swap_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_SWAP_ARGS, | |
55 _adapter_rot_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_ROT_ARGS, | |
56 _adapter_dup_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_DUP_ARGS, | |
57 _adapter_drop_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_DROP_ARGS, | |
58 _adapter_collect_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_COLLECT_ARGS, | |
59 _adapter_spread_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_SPREAD_ARGS, | |
60 _adapter_flyby = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_FLYBY, | |
61 _adapter_ricochet = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_RICOCHET, | |
62 _adapter_mh_last = _adapter_mh_first + sun_dyn_AdapterMethodHandle::CONV_OP_LIMIT - 1, | |
63 | |
64 // Optimized adapter types | |
65 | |
66 // argument list reordering | |
67 _adapter_opt_swap_1, | |
68 _adapter_opt_swap_2, | |
69 _adapter_opt_rot_1_up, | |
70 _adapter_opt_rot_1_down, | |
71 _adapter_opt_rot_2_up, | |
72 _adapter_opt_rot_2_down, | |
73 // primitive single to single: | |
74 _adapter_opt_i2i, // i2c, i2z, i2b, i2s | |
75 // primitive double to single: | |
76 _adapter_opt_l2i, | |
77 _adapter_opt_d2f, | |
78 // primitive single to double: | |
79 _adapter_opt_i2l, | |
80 _adapter_opt_f2d, | |
81 // conversion between floating point and integer type is handled by Java | |
82 | |
83 // reference to primitive: | |
84 _adapter_opt_unboxi, | |
85 _adapter_opt_unboxl, | |
86 | |
87 // spreading (array length cases 0, 1, >=2) | |
88 _adapter_opt_spread_0, | |
89 _adapter_opt_spread_1, | |
90 _adapter_opt_spread_more, | |
91 | |
92 _EK_LIMIT, | |
93 _EK_FIRST = 0 | |
94 }; | |
95 | |
96 public: | |
97 static bool enabled() { return _enabled; } | |
98 static void set_enabled(bool z); | |
99 | |
100 private: | |
101 enum { // import sun_dyn_AdapterMethodHandle::CONV_OP_* | |
102 CONV_OP_LIMIT = sun_dyn_AdapterMethodHandle::CONV_OP_LIMIT, | |
103 CONV_OP_MASK = sun_dyn_AdapterMethodHandle::CONV_OP_MASK, | |
104 CONV_VMINFO_MASK = sun_dyn_AdapterMethodHandle::CONV_VMINFO_MASK, | |
105 CONV_VMINFO_SHIFT = sun_dyn_AdapterMethodHandle::CONV_VMINFO_SHIFT, | |
106 CONV_OP_SHIFT = sun_dyn_AdapterMethodHandle::CONV_OP_SHIFT, | |
107 CONV_DEST_TYPE_SHIFT = sun_dyn_AdapterMethodHandle::CONV_DEST_TYPE_SHIFT, | |
108 CONV_SRC_TYPE_SHIFT = sun_dyn_AdapterMethodHandle::CONV_SRC_TYPE_SHIFT, | |
109 CONV_STACK_MOVE_SHIFT = sun_dyn_AdapterMethodHandle::CONV_STACK_MOVE_SHIFT, | |
110 CONV_STACK_MOVE_MASK = sun_dyn_AdapterMethodHandle::CONV_STACK_MOVE_MASK | |
111 }; | |
112 | |
113 static bool _enabled; | |
114 static MethodHandleEntry* _entries[_EK_LIMIT]; | |
115 static const char* _entry_names[_EK_LIMIT+1]; | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
116 static jobject _raise_exception_method; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
117 |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
118 // Adapters. |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
119 static MethodHandlesAdapterBlob* _adapter_code; |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
120 static int _adapter_code_size; |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
121 |
710 | 122 static bool ek_valid(EntryKind ek) { return (uint)ek < (uint)_EK_LIMIT; } |
123 static bool conv_op_valid(int op) { return (uint)op < (uint)CONV_OP_LIMIT; } | |
124 | |
125 public: | |
126 static bool have_entry(EntryKind ek) { return ek_valid(ek) && _entries[ek] != NULL; } | |
127 static MethodHandleEntry* entry(EntryKind ek) { assert(ek_valid(ek), "initialized"); | |
128 return _entries[ek]; } | |
129 static const char* entry_name(EntryKind ek) { assert(ek_valid(ek), "oob"); | |
130 return _entry_names[ek]; } | |
131 static EntryKind adapter_entry_kind(int op) { assert(conv_op_valid(op), "oob"); | |
132 return EntryKind(_adapter_mh_first + op); } | |
133 | |
134 static void init_entry(EntryKind ek, MethodHandleEntry* me) { | |
135 assert(ek_valid(ek), "oob"); | |
136 assert(_entries[ek] == NULL, "no double initialization"); | |
137 _entries[ek] = me; | |
138 } | |
139 | |
1304 | 140 // Some adapter helper functions. |
141 static void get_ek_bound_mh_info(EntryKind ek, BasicType& arg_type, int& arg_mask, int& arg_slots) { | |
142 switch (ek) { | |
143 case _bound_int_mh : // fall-thru | |
144 case _bound_int_direct_mh : arg_type = T_INT; arg_mask = _INSERT_INT_MASK; break; | |
145 case _bound_long_mh : // fall-thru | |
146 case _bound_long_direct_mh: arg_type = T_LONG; arg_mask = _INSERT_LONG_MASK; break; | |
147 case _bound_ref_mh : // fall-thru | |
148 case _bound_ref_direct_mh : arg_type = T_OBJECT; arg_mask = _INSERT_REF_MASK; break; | |
149 default: ShouldNotReachHere(); | |
150 } | |
151 arg_slots = type2size[arg_type]; | |
152 } | |
153 | |
154 static void get_ek_adapter_opt_swap_rot_info(EntryKind ek, int& swap_bytes, int& rotate) { | |
155 int swap_slots = 0; | |
156 switch (ek) { | |
157 case _adapter_opt_swap_1: swap_slots = 1; rotate = 0; break; | |
158 case _adapter_opt_swap_2: swap_slots = 2; rotate = 0; break; | |
159 case _adapter_opt_rot_1_up: swap_slots = 1; rotate = 1; break; | |
160 case _adapter_opt_rot_1_down: swap_slots = 1; rotate = -1; break; | |
161 case _adapter_opt_rot_2_up: swap_slots = 2; rotate = 1; break; | |
162 case _adapter_opt_rot_2_down: swap_slots = 2; rotate = -1; break; | |
163 default: ShouldNotReachHere(); | |
164 } | |
165 // Return the size of the stack slots to move in bytes. | |
1506 | 166 swap_bytes = swap_slots * Interpreter::stackElementSize; |
1304 | 167 } |
168 | |
169 static int get_ek_adapter_opt_spread_info(EntryKind ek) { | |
170 switch (ek) { | |
171 case _adapter_opt_spread_0: return 0; | |
172 case _adapter_opt_spread_1: return 1; | |
173 default : return -1; | |
174 } | |
175 } | |
176 | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
177 static methodOop raise_exception_method() { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
178 oop rem = JNIHandles::resolve(_raise_exception_method); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
179 assert(rem == NULL || rem->is_method(), ""); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
180 return (methodOop) rem; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
181 } |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
182 static void set_raise_exception_method(methodOop rem) { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
183 assert(_raise_exception_method == NULL, ""); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
184 _raise_exception_method = JNIHandles::make_global(Handle(rem)); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
185 } |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
186 |
710 | 187 static jint adapter_conversion(int conv_op, BasicType src, BasicType dest, |
188 int stack_move = 0, int vminfo = 0) { | |
189 assert(conv_op_valid(conv_op), "oob"); | |
190 jint conv = ((conv_op << CONV_OP_SHIFT) | |
191 | (src << CONV_SRC_TYPE_SHIFT) | |
192 | (dest << CONV_DEST_TYPE_SHIFT) | |
193 | (stack_move << CONV_STACK_MOVE_SHIFT) | |
194 | (vminfo << CONV_VMINFO_SHIFT) | |
195 ); | |
196 assert(adapter_conversion_op(conv) == conv_op, "decode conv_op"); | |
197 assert(adapter_conversion_src_type(conv) == src, "decode src"); | |
198 assert(adapter_conversion_dest_type(conv) == dest, "decode dest"); | |
199 assert(adapter_conversion_stack_move(conv) == stack_move, "decode stack_move"); | |
200 assert(adapter_conversion_vminfo(conv) == vminfo, "decode vminfo"); | |
201 return conv; | |
202 } | |
203 static int adapter_conversion_op(jint conv) { | |
204 return ((conv >> CONV_OP_SHIFT) & 0xF); | |
205 } | |
206 static BasicType adapter_conversion_src_type(jint conv) { | |
207 return (BasicType)((conv >> CONV_SRC_TYPE_SHIFT) & 0xF); | |
208 } | |
209 static BasicType adapter_conversion_dest_type(jint conv) { | |
210 return (BasicType)((conv >> CONV_DEST_TYPE_SHIFT) & 0xF); | |
211 } | |
212 static int adapter_conversion_stack_move(jint conv) { | |
213 return (conv >> CONV_STACK_MOVE_SHIFT); | |
214 } | |
215 static int adapter_conversion_vminfo(jint conv) { | |
216 return (conv >> CONV_VMINFO_SHIFT) & CONV_VMINFO_MASK; | |
217 } | |
218 | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
219 // Bit mask of conversion_op values. May vary by platform. |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
220 static int adapter_conversion_ops_supported_mask(); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
221 |
710 | 222 // Offset in words that the interpreter stack pointer moves when an argument is pushed. |
223 // The stack_move value must always be a multiple of this. | |
224 static int stack_move_unit() { | |
1506 | 225 return frame::interpreter_frame_expression_stack_direction() * Interpreter::stackElementWords; |
710 | 226 } |
227 | |
228 enum { CONV_VMINFO_SIGN_FLAG = 0x80 }; | |
1849
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1793
diff
changeset
|
229 // Shift values for prim-to-prim conversions. |
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1793
diff
changeset
|
230 static int adapter_prim_to_prim_subword_vminfo(BasicType dest) { |
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1793
diff
changeset
|
231 if (dest == T_BOOLEAN) return (BitsPerInt - 1); // boolean is 1 bit |
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1793
diff
changeset
|
232 if (dest == T_CHAR) return (BitsPerInt - BitsPerShort); |
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1793
diff
changeset
|
233 if (dest == T_BYTE) return (BitsPerInt - BitsPerByte ) | CONV_VMINFO_SIGN_FLAG; |
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1793
diff
changeset
|
234 if (dest == T_SHORT) return (BitsPerInt - BitsPerShort) | CONV_VMINFO_SIGN_FLAG; |
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1793
diff
changeset
|
235 return 0; // case T_INT |
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1793
diff
changeset
|
236 } |
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1793
diff
changeset
|
237 // Shift values for unboxing a primitive. |
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1793
diff
changeset
|
238 static int adapter_unbox_subword_vminfo(BasicType dest) { |
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1793
diff
changeset
|
239 if (dest == T_BOOLEAN) return (BitsPerInt - BitsPerByte ); // implemented as 1 byte |
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1793
diff
changeset
|
240 if (dest == T_CHAR) return (BitsPerInt - BitsPerShort); |
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1793
diff
changeset
|
241 if (dest == T_BYTE) return (BitsPerInt - BitsPerByte ) | CONV_VMINFO_SIGN_FLAG; |
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1793
diff
changeset
|
242 if (dest == T_SHORT) return (BitsPerInt - BitsPerShort) | CONV_VMINFO_SIGN_FLAG; |
710 | 243 return 0; // case T_INT |
244 } | |
245 // Here is the transformation the i2i adapter must perform: | |
246 static int truncate_subword_from_vminfo(jint value, int vminfo) { | |
247 jint tem = value << vminfo; | |
248 if ((vminfo & CONV_VMINFO_SIGN_FLAG) != 0) { | |
249 return (jint)tem >> vminfo; | |
250 } else { | |
251 return (juint)tem >> vminfo; | |
252 } | |
253 } | |
254 | |
255 static inline address from_compiled_entry(EntryKind ek); | |
256 static inline address from_interpreted_entry(EntryKind ek); | |
257 | |
258 // helpers for decode_method. | |
259 static methodOop decode_methodOop(methodOop m, int& decode_flags_result); | |
260 static methodOop decode_vmtarget(oop vmtarget, int vmindex, oop mtype, klassOop& receiver_limit_result, int& decode_flags_result); | |
261 static methodOop decode_MemberName(oop mname, klassOop& receiver_limit_result, int& decode_flags_result); | |
262 static methodOop decode_MethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result); | |
263 static methodOop decode_DirectMethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result); | |
264 static methodOop decode_BoundMethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result); | |
265 static methodOop decode_AdapterMethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result); | |
266 | |
267 // Find out how many stack slots an mh pushes or pops. | |
268 // The result is *not* reported as a multiple of stack_move_unit(); | |
269 // It is a signed net number of pushes (a difference in vmslots). | |
270 // To compare with a stack_move value, first multiply by stack_move_unit(). | |
271 static int decode_MethodHandle_stack_pushes(oop mh); | |
272 | |
273 public: | |
274 // working with member names | |
275 static void resolve_MemberName(Handle mname, TRAPS); // compute vmtarget/vmindex from name/type | |
276 static void expand_MemberName(Handle mname, int suppress, TRAPS); // expand defc/name/type if missing | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
277 static Handle new_MemberName(TRAPS); // must be followed by init_MemberName |
710 | 278 static void init_MemberName(oop mname_oop, oop target); // compute vmtarget/vmindex from target |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
279 static void init_MemberName(oop mname_oop, methodOop m, bool do_dispatch = true); |
710 | 280 static void init_MemberName(oop mname_oop, klassOop field_holder, AccessFlags mods, int offset); |
281 static int find_MemberNames(klassOop k, symbolOop name, symbolOop sig, | |
282 int mflags, klassOop caller, | |
283 int skip, objArrayOop results); | |
284 // bit values for suppress argument to expand_MemberName: | |
285 enum { _suppress_defc = 1, _suppress_name = 2, _suppress_type = 4 }; | |
286 | |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
287 // Generate MethodHandles adapters. |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
288 static void generate_adapters(); |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
289 |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
290 // Called from InterpreterGenerator and MethodHandlesAdapterGenerator. |
710 | 291 static address generate_method_handle_interpreter_entry(MacroAssembler* _masm); |
292 static void generate_method_handle_stub(MacroAssembler* _masm, EntryKind ek); | |
293 | |
294 // argument list parsing | |
295 static int argument_slot(oop method_type, int arg); | |
296 static int argument_slot_count(oop method_type) { return argument_slot(method_type, -1); } | |
297 static int argument_slot_to_argnum(oop method_type, int argslot); | |
298 | |
299 // Runtime support | |
300 enum { // bit-encoded flags from decode_method or decode_vmref | |
301 _dmf_has_receiver = 0x01, // target method has leading reference argument | |
302 _dmf_does_dispatch = 0x02, // method handle performs virtual or interface dispatch | |
303 _dmf_from_interface = 0x04, // peforms interface dispatch | |
304 _DMF_DIRECT_MASK = (_dmf_from_interface*2 - _dmf_has_receiver), | |
305 _dmf_binds_method = 0x08, | |
306 _dmf_binds_argument = 0x10, | |
307 _DMF_BOUND_MASK = (_dmf_binds_argument*2 - _dmf_binds_method), | |
308 _dmf_adapter_lsb = 0x20, | |
309 _DMF_ADAPTER_MASK = (_dmf_adapter_lsb << CONV_OP_LIMIT) - _dmf_adapter_lsb | |
310 }; | |
311 static methodOop decode_method(oop x, klassOop& receiver_limit_result, int& decode_flags_result); | |
312 enum { | |
313 // format of query to getConstant: | |
314 GC_JVM_PUSH_LIMIT = 0, | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
315 GC_JVM_STACK_MOVE_UNIT = 1, |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
316 GC_CONV_OP_IMPLEMENTED_MASK = 2, |
710 | 317 |
318 // format of result from getTarget / encode_target: | |
319 ETF_HANDLE_OR_METHOD_NAME = 0, // all available data (immediate MH or method) | |
320 ETF_DIRECT_HANDLE = 1, // ultimate method handle (will be a DMH, may be self) | |
321 ETF_METHOD_NAME = 2, // ultimate method as MemberName | |
322 ETF_REFLECT_METHOD = 3 // ultimate method as java.lang.reflect object (sans refClass) | |
323 }; | |
324 static int get_named_constant(int which, Handle name_box, TRAPS); | |
325 static oop encode_target(Handle mh, int format, TRAPS); // report vmtarget (to Java code) | |
326 static bool class_cast_needed(klassOop src, klassOop dst); | |
327 | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
328 static instanceKlassHandle resolve_instance_klass(oop java_mirror_oop, TRAPS); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
329 static instanceKlassHandle resolve_instance_klass(jclass java_mirror_jh, TRAPS) { |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
330 return resolve_instance_klass(JNIHandles::resolve(java_mirror_jh), THREAD); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
331 } |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
332 |
710 | 333 private: |
334 // These checkers operate on a pair of whole MethodTypes: | |
335 static const char* check_method_type_change(oop src_mtype, int src_beg, int src_end, | |
336 int insert_argnum, oop insert_type, | |
337 int change_argnum, oop change_type, | |
338 int delete_argnum, | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
339 oop dst_mtype, int dst_beg, int dst_end, |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
340 bool raw = false); |
710 | 341 static const char* check_method_type_insertion(oop src_mtype, |
342 int insert_argnum, oop insert_type, | |
343 oop dst_mtype) { | |
344 oop no_ref = NULL; | |
345 return check_method_type_change(src_mtype, 0, -1, | |
346 insert_argnum, insert_type, | |
347 -1, no_ref, -1, dst_mtype, 0, -1); | |
348 } | |
349 static const char* check_method_type_conversion(oop src_mtype, | |
350 int change_argnum, oop change_type, | |
351 oop dst_mtype) { | |
352 oop no_ref = NULL; | |
353 return check_method_type_change(src_mtype, 0, -1, -1, no_ref, | |
354 change_argnum, change_type, | |
355 -1, dst_mtype, 0, -1); | |
356 } | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
357 static const char* check_method_type_passthrough(oop src_mtype, oop dst_mtype, bool raw) { |
710 | 358 oop no_ref = NULL; |
359 return check_method_type_change(src_mtype, 0, -1, | |
360 -1, no_ref, -1, no_ref, -1, | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
361 dst_mtype, 0, -1, raw); |
710 | 362 } |
363 | |
364 // These checkers operate on pairs of argument or return types: | |
365 static const char* check_argument_type_change(BasicType src_type, klassOop src_klass, | |
366 BasicType dst_type, klassOop dst_klass, | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
367 int argnum, bool raw = false); |
710 | 368 |
369 static const char* check_argument_type_change(oop src_type, oop dst_type, | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
370 int argnum, bool raw = false) { |
710 | 371 klassOop src_klass = NULL, dst_klass = NULL; |
372 BasicType src_bt = java_lang_Class::as_BasicType(src_type, &src_klass); | |
373 BasicType dst_bt = java_lang_Class::as_BasicType(dst_type, &dst_klass); | |
374 return check_argument_type_change(src_bt, src_klass, | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
375 dst_bt, dst_klass, argnum, raw); |
710 | 376 } |
377 | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
378 static const char* check_return_type_change(oop src_type, oop dst_type, bool raw = false) { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
379 return check_argument_type_change(src_type, dst_type, -1, raw); |
710 | 380 } |
381 | |
382 static const char* check_return_type_change(BasicType src_type, klassOop src_klass, | |
383 BasicType dst_type, klassOop dst_klass) { | |
384 return check_argument_type_change(src_type, src_klass, dst_type, dst_klass, -1); | |
385 } | |
386 | |
387 static const char* check_method_receiver(methodOop m, klassOop passed_recv_type); | |
388 | |
389 // These verifiers can block, and will throw an error if the checking fails: | |
390 static void verify_vmslots(Handle mh, TRAPS); | |
391 static void verify_vmargslot(Handle mh, int argnum, int argslot, TRAPS); | |
392 | |
393 static void verify_method_type(methodHandle m, Handle mtype, | |
394 bool has_bound_oop, | |
395 KlassHandle bound_oop_type, | |
396 TRAPS); | |
397 | |
398 static void verify_method_signature(methodHandle m, Handle mtype, | |
399 int first_ptype_pos, | |
400 KlassHandle insert_ptype, TRAPS); | |
401 | |
402 static void verify_DirectMethodHandle(Handle mh, methodHandle m, TRAPS); | |
403 static void verify_BoundMethodHandle(Handle mh, Handle target, int argnum, | |
404 bool direct_to_method, TRAPS); | |
405 static void verify_BoundMethodHandle_with_receiver(Handle mh, methodHandle m, TRAPS); | |
406 static void verify_AdapterMethodHandle(Handle mh, int argnum, TRAPS); | |
407 | |
408 public: | |
409 | |
410 // Fill in the fields of a DirectMethodHandle mh. (MH.type must be pre-filled.) | |
411 static void init_DirectMethodHandle(Handle mh, methodHandle method, bool do_dispatch, TRAPS); | |
412 | |
413 // Fill in the fields of a BoundMethodHandle mh. (MH.type, BMH.argument must be pre-filled.) | |
414 static void init_BoundMethodHandle(Handle mh, Handle target, int argnum, TRAPS); | |
415 static void init_BoundMethodHandle_with_receiver(Handle mh, | |
416 methodHandle original_m, | |
417 KlassHandle receiver_limit, | |
418 int decode_flags, | |
419 TRAPS); | |
420 | |
421 // Fill in the fields of an AdapterMethodHandle mh. (MH.type must be pre-filled.) | |
422 static void init_AdapterMethodHandle(Handle mh, Handle target, int argnum, TRAPS); | |
423 | |
424 #ifdef ASSERT | |
425 static bool spot_check_entry_names(); | |
426 #endif | |
427 | |
428 private: | |
429 static methodHandle dispatch_decoded_method(methodHandle m, | |
430 KlassHandle receiver_limit, | |
431 int decode_flags, | |
432 KlassHandle receiver_klass, | |
433 TRAPS); | |
434 | |
435 static bool same_basic_type_for_arguments(BasicType src, BasicType dst, | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
436 bool raw = false, |
710 | 437 bool for_return = false); |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
438 static bool same_basic_type_for_returns(BasicType src, BasicType dst, bool raw = false) { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
710
diff
changeset
|
439 return same_basic_type_for_arguments(src, dst, raw, true); |
710 | 440 } |
441 | |
442 enum { // arg_mask values | |
443 _INSERT_NO_MASK = -1, | |
444 _INSERT_REF_MASK = 0, | |
445 _INSERT_INT_MASK = 1, | |
446 _INSERT_LONG_MASK = 3 | |
447 }; | |
448 static void insert_arg_slots(MacroAssembler* _masm, | |
449 RegisterOrConstant arg_slots, | |
450 int arg_mask, | |
1304 | 451 Register argslot_reg, |
1503 | 452 Register temp_reg, Register temp2_reg, Register temp3_reg = noreg); |
710 | 453 |
454 static void remove_arg_slots(MacroAssembler* _masm, | |
455 RegisterOrConstant arg_slots, | |
1304 | 456 Register argslot_reg, |
1503 | 457 Register temp_reg, Register temp2_reg, Register temp3_reg = noreg); |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
458 |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
459 static void trace_method_handle(MacroAssembler* _masm, const char* adaptername) PRODUCT_RETURN; |
710 | 460 }; |
461 | |
462 | |
463 // Access methods for the "entry" field of a java.dyn.MethodHandle. | |
464 // The field is primarily a jump target for compiled calls. | |
465 // However, we squirrel away some nice pointers for other uses, | |
466 // just before the jump target. | |
467 // Aspects of a method handle entry: | |
468 // - from_compiled_entry - stub used when compiled code calls the MH | |
469 // - from_interpreted_entry - stub used when the interpreter calls the MH | |
470 // - type_checking_entry - stub for runtime casting between MHForm siblings (NYI) | |
471 class MethodHandleEntry { | |
472 public: | |
473 class Data { | |
474 friend class MethodHandleEntry; | |
475 size_t _total_size; // size including Data and code stub | |
476 MethodHandleEntry* _type_checking_entry; | |
477 address _from_interpreted_entry; | |
478 MethodHandleEntry* method_entry() { return (MethodHandleEntry*)(this + 1); } | |
479 }; | |
480 | |
481 Data* data() { return (Data*)this - 1; } | |
482 | |
483 address start_address() { return (address) data(); } | |
484 address end_address() { return start_address() + data()->_total_size; } | |
485 | |
486 address from_compiled_entry() { return (address) this; } | |
487 | |
488 address from_interpreted_entry() { return data()->_from_interpreted_entry; } | |
489 void set_from_interpreted_entry(address e) { data()->_from_interpreted_entry = e; } | |
490 | |
491 MethodHandleEntry* type_checking_entry() { return data()->_type_checking_entry; } | |
492 void set_type_checking_entry(MethodHandleEntry* e) { data()->_type_checking_entry = e; } | |
493 | |
494 void set_end_address(address end_addr) { | |
495 size_t total_size = end_addr - start_address(); | |
496 assert(total_size > 0 && total_size < 0x1000, "reasonable end address"); | |
497 data()->_total_size = total_size; | |
498 } | |
499 | |
500 // Compiler support: | |
501 static int from_interpreted_entry_offset_in_bytes() { | |
502 return (int)( offset_of(Data, _from_interpreted_entry) - sizeof(Data) ); | |
503 } | |
504 static int type_checking_entry_offset_in_bytes() { | |
505 return (int)( offset_of(Data, _from_interpreted_entry) - sizeof(Data) ); | |
506 } | |
507 | |
508 static address start_compiled_entry(MacroAssembler* _masm, | |
509 address interpreted_entry = NULL); | |
510 static MethodHandleEntry* finish_compiled_entry(MacroAssembler* masm, address start_addr); | |
511 }; | |
512 | |
513 address MethodHandles::from_compiled_entry(EntryKind ek) { return entry(ek)->from_compiled_entry(); } | |
514 address MethodHandles::from_interpreted_entry(EntryKind ek) { return entry(ek)->from_interpreted_entry(); } | |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
515 |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
516 |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
517 //------------------------------------------------------------------------------ |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
518 // MethodHandlesAdapterGenerator |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
519 // |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
520 class MethodHandlesAdapterGenerator : public StubCodeGenerator { |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
521 public: |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
522 MethodHandlesAdapterGenerator(CodeBuffer* code) : StubCodeGenerator(code) {} |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
523 |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
524 void generate(); |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1039
diff
changeset
|
525 }; |