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