Mercurial > hg > graal-jvmci-8
comparison src/share/vm/prims/methodHandles.hpp @ 6266:1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
6984705: JSR 292 method handle creation should not go through JNI
Summary: remove assembly code for JDK 7 chained method handles
Reviewed-by: jrose, twisti, kvn, mhaupt
Contributed-by: John Rose <john.r.rose@oracle.com>, Christian Thalinger <christian.thalinger@oracle.com>, Michael Haupt <michael.haupt@oracle.com>
author | twisti |
---|---|
date | Tue, 24 Jul 2012 10:51:00 -0700 |
parents | 15d394228cfa |
children | da91efe96a93 |
comparison
equal
deleted
inserted
replaced
6241:aba91a731143 | 6266:1d7922586cf6 |
---|---|
31 #include "runtime/globals.hpp" | 31 #include "runtime/globals.hpp" |
32 #include "runtime/interfaceSupport.hpp" | 32 #include "runtime/interfaceSupport.hpp" |
33 | 33 |
34 class MacroAssembler; | 34 class MacroAssembler; |
35 class Label; | 35 class Label; |
36 class MethodHandleEntry; | |
37 | 36 |
38 class MethodHandles: AllStatic { | 37 class MethodHandles: AllStatic { |
39 // JVM support for MethodHandle, MethodType, and related types | 38 // JVM support for MethodHandle, MethodType, and related types |
40 // in java.lang.invoke and sun.invoke. | 39 // in java.lang.invoke and sun.invoke. |
41 // See also javaClasses for layouts java_lang_invoke_Method{Handle,Type,Type::Form}. | 40 // See also javaClasses for layouts java_lang_invoke_Method{Handle,Type,Type::Form}. |
42 public: | 41 public: |
43 enum EntryKind { | |
44 _raise_exception, // stub for error generation from other stubs | |
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 + java_lang_invoke_AdapterMethodHandle::OP_RETYPE_ONLY, | |
58 _adapter_retype_raw = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_RETYPE_RAW, | |
59 _adapter_check_cast = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_CHECK_CAST, | |
60 _adapter_prim_to_prim = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_PRIM, | |
61 _adapter_ref_to_prim = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_REF_TO_PRIM, | |
62 _adapter_prim_to_ref = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_REF, | |
63 _adapter_swap_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_SWAP_ARGS, | |
64 _adapter_rot_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_ROT_ARGS, | |
65 _adapter_dup_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_DUP_ARGS, | |
66 _adapter_drop_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_DROP_ARGS, | |
67 _adapter_collect_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_COLLECT_ARGS, | |
68 _adapter_spread_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_SPREAD_ARGS, | |
69 _adapter_fold_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_FOLD_ARGS, | |
70 _adapter_unused_13 = _adapter_mh_first + 13, //hole in the CONV_OP enumeration | |
71 _adapter_mh_last = _adapter_mh_first + java_lang_invoke_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 // %% Maybe tame the following with a VM_SYMBOLS_DO type macro? | |
97 | |
98 // how a blocking adapter returns (platform-dependent) | |
99 _adapter_opt_return_ref, | |
100 _adapter_opt_return_int, | |
101 _adapter_opt_return_long, | |
102 _adapter_opt_return_float, | |
103 _adapter_opt_return_double, | |
104 _adapter_opt_return_void, | |
105 _adapter_opt_return_S0_ref, // return ref to S=0 (last slot) | |
106 _adapter_opt_return_S1_ref, // return ref to S=1 (2nd-to-last slot) | |
107 _adapter_opt_return_S2_ref, | |
108 _adapter_opt_return_S3_ref, | |
109 _adapter_opt_return_S4_ref, | |
110 _adapter_opt_return_S5_ref, | |
111 _adapter_opt_return_any, // dynamically select r/i/l/f/d | |
112 _adapter_opt_return_FIRST = _adapter_opt_return_ref, | |
113 _adapter_opt_return_LAST = _adapter_opt_return_any, | |
114 | |
115 // spreading (array length cases 0, 1, ...) | |
116 _adapter_opt_spread_0, // spread empty array to N=0 arguments | |
117 _adapter_opt_spread_1_ref, // spread Object[] to N=1 argument | |
118 _adapter_opt_spread_2_ref, // spread Object[] to N=2 arguments | |
119 _adapter_opt_spread_3_ref, // spread Object[] to N=3 arguments | |
120 _adapter_opt_spread_4_ref, // spread Object[] to N=4 arguments | |
121 _adapter_opt_spread_5_ref, // spread Object[] to N=5 arguments | |
122 _adapter_opt_spread_ref, // spread Object[] to N arguments | |
123 _adapter_opt_spread_byte, // spread byte[] or boolean[] to N arguments | |
124 _adapter_opt_spread_char, // spread char[], etc., to N arguments | |
125 _adapter_opt_spread_short, // spread short[], etc., to N arguments | |
126 _adapter_opt_spread_int, // spread int[], short[], etc., to N arguments | |
127 _adapter_opt_spread_long, // spread long[] to N arguments | |
128 _adapter_opt_spread_float, // spread float[] to N arguments | |
129 _adapter_opt_spread_double, // spread double[] to N arguments | |
130 _adapter_opt_spread_FIRST = _adapter_opt_spread_0, | |
131 _adapter_opt_spread_LAST = _adapter_opt_spread_double, | |
132 | |
133 // blocking filter/collect conversions | |
134 // These collect N arguments and replace them (at slot S) by a return value | |
135 // which is passed to the final target, along with the unaffected arguments. | |
136 // collect_{N}_{T} collects N arguments at any position into a T value | |
137 // collect_{N}_S{S}_{T} collects N arguments at slot S into a T value | |
138 // collect_{T} collects any number of arguments at any position | |
139 // filter_S{S}_{T} is the same as collect_1_S{S}_{T} (a unary collection) | |
140 // (collect_2 is also usable as a filter, with long or double arguments) | |
141 _adapter_opt_collect_ref, // combine N arguments, replace with a reference | |
142 _adapter_opt_collect_int, // combine N arguments, replace with an int, short, etc. | |
143 _adapter_opt_collect_long, // combine N arguments, replace with a long | |
144 _adapter_opt_collect_float, // combine N arguments, replace with a float | |
145 _adapter_opt_collect_double, // combine N arguments, replace with a double | |
146 _adapter_opt_collect_void, // combine N arguments, replace with nothing | |
147 // if there is a small fixed number to push, do so without a loop: | |
148 _adapter_opt_collect_0_ref, // collect N=0 arguments, insert a reference | |
149 _adapter_opt_collect_1_ref, // collect N=1 argument, replace with a reference | |
150 _adapter_opt_collect_2_ref, // combine N=2 arguments, replace with a reference | |
151 _adapter_opt_collect_3_ref, // combine N=3 arguments, replace with a reference | |
152 _adapter_opt_collect_4_ref, // combine N=4 arguments, replace with a reference | |
153 _adapter_opt_collect_5_ref, // combine N=5 arguments, replace with a reference | |
154 // filters are an important special case because they never move arguments: | |
155 _adapter_opt_filter_S0_ref, // filter N=1 argument at S=0, replace with a reference | |
156 _adapter_opt_filter_S1_ref, // filter N=1 argument at S=1, replace with a reference | |
157 _adapter_opt_filter_S2_ref, // filter N=1 argument at S=2, replace with a reference | |
158 _adapter_opt_filter_S3_ref, // filter N=1 argument at S=3, replace with a reference | |
159 _adapter_opt_filter_S4_ref, // filter N=1 argument at S=4, replace with a reference | |
160 _adapter_opt_filter_S5_ref, // filter N=1 argument at S=5, replace with a reference | |
161 // these move arguments, but they are important for boxing | |
162 _adapter_opt_collect_2_S0_ref, // combine last N=2 arguments, replace with a reference | |
163 _adapter_opt_collect_2_S1_ref, // combine N=2 arguments at S=1, replace with a reference | |
164 _adapter_opt_collect_2_S2_ref, // combine N=2 arguments at S=2, replace with a reference | |
165 _adapter_opt_collect_2_S3_ref, // combine N=2 arguments at S=3, replace with a reference | |
166 _adapter_opt_collect_2_S4_ref, // combine N=2 arguments at S=4, replace with a reference | |
167 _adapter_opt_collect_2_S5_ref, // combine N=2 arguments at S=5, replace with a reference | |
168 _adapter_opt_collect_FIRST = _adapter_opt_collect_ref, | |
169 _adapter_opt_collect_LAST = _adapter_opt_collect_2_S5_ref, | |
170 | |
171 // blocking folding conversions | |
172 // these are like collects, but retain all the N arguments for the final target | |
173 //_adapter_opt_fold_0_ref, // same as _adapter_opt_collect_0_ref | |
174 // fold_{N}_{T} processes N arguments at any position into a T value, which it inserts | |
175 // fold_{T} processes any number of arguments at any position | |
176 _adapter_opt_fold_ref, // process N arguments, prepend a reference | |
177 _adapter_opt_fold_int, // process N arguments, prepend an int, short, etc. | |
178 _adapter_opt_fold_long, // process N arguments, prepend a long | |
179 _adapter_opt_fold_float, // process N arguments, prepend a float | |
180 _adapter_opt_fold_double, // process N arguments, prepend a double | |
181 _adapter_opt_fold_void, // process N arguments, but leave the list unchanged | |
182 _adapter_opt_fold_1_ref, // process N=1 argument, prepend a reference | |
183 _adapter_opt_fold_2_ref, // process N=2 arguments, prepend a reference | |
184 _adapter_opt_fold_3_ref, // process N=3 arguments, prepend a reference | |
185 _adapter_opt_fold_4_ref, // process N=4 arguments, prepend a reference | |
186 _adapter_opt_fold_5_ref, // process N=5 arguments, prepend a reference | |
187 _adapter_opt_fold_FIRST = _adapter_opt_fold_ref, | |
188 _adapter_opt_fold_LAST = _adapter_opt_fold_5_ref, | |
189 | |
190 _adapter_opt_profiling, | |
191 | |
192 _EK_LIMIT, | |
193 _EK_FIRST = 0 | |
194 }; | |
195 | |
196 public: | 42 public: |
197 static bool enabled() { return _enabled; } | 43 static bool enabled() { return _enabled; } |
198 static void set_enabled(bool z); | 44 static void set_enabled(bool z); |
199 | 45 |
200 private: | 46 private: |
201 enum { // import java_lang_invoke_AdapterMethodHandle::CONV_OP_* | |
202 CONV_OP_LIMIT = java_lang_invoke_AdapterMethodHandle::CONV_OP_LIMIT, | |
203 CONV_OP_MASK = java_lang_invoke_AdapterMethodHandle::CONV_OP_MASK, | |
204 CONV_TYPE_MASK = java_lang_invoke_AdapterMethodHandle::CONV_TYPE_MASK, | |
205 CONV_VMINFO_MASK = java_lang_invoke_AdapterMethodHandle::CONV_VMINFO_MASK, | |
206 CONV_VMINFO_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_VMINFO_SHIFT, | |
207 CONV_OP_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_OP_SHIFT, | |
208 CONV_DEST_TYPE_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_DEST_TYPE_SHIFT, | |
209 CONV_SRC_TYPE_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_SRC_TYPE_SHIFT, | |
210 CONV_STACK_MOVE_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_STACK_MOVE_SHIFT, | |
211 CONV_STACK_MOVE_MASK = java_lang_invoke_AdapterMethodHandle::CONV_STACK_MOVE_MASK | |
212 }; | |
213 | |
214 static bool _enabled; | 47 static bool _enabled; |
215 static MethodHandleEntry* _entries[_EK_LIMIT]; | |
216 static const char* _entry_names[_EK_LIMIT+1]; | |
217 static jobject _raise_exception_method; | |
218 static address _adapter_return_handlers[CONV_TYPE_MASK+1]; | |
219 | 48 |
220 // Adapters. | 49 // Adapters. |
221 static MethodHandlesAdapterBlob* _adapter_code; | 50 static MethodHandlesAdapterBlob* _adapter_code; |
222 | 51 |
223 static bool ek_valid(EntryKind ek) { return (uint)ek < (uint)_EK_LIMIT; } | |
224 static bool conv_op_valid(int op) { return (uint)op < (uint)CONV_OP_LIMIT; } | |
225 | |
226 public: | |
227 static bool have_entry(EntryKind ek) { return ek_valid(ek) && _entries[ek] != NULL; } | |
228 static MethodHandleEntry* entry(EntryKind ek) { assert(ek_valid(ek), "initialized"); | |
229 return _entries[ek]; } | |
230 static const char* entry_name(EntryKind ek) { assert(ek_valid(ek), "oob"); | |
231 return _entry_names[ek]; } | |
232 static EntryKind adapter_entry_kind(int op) { assert(conv_op_valid(op), "oob"); | |
233 return EntryKind(_adapter_mh_first + op); } | |
234 | |
235 static void init_entry(EntryKind ek, MethodHandleEntry* me) { | |
236 assert(ek_valid(ek), "oob"); | |
237 assert(_entries[ek] == NULL, "no double initialization"); | |
238 _entries[ek] = me; | |
239 } | |
240 | |
241 // Some adapter helper functions. | |
242 static EntryKind ek_original_kind(EntryKind ek) { | |
243 if (ek <= _adapter_mh_last) return ek; | |
244 switch (ek) { | |
245 case _adapter_opt_swap_1: | |
246 case _adapter_opt_swap_2: | |
247 return _adapter_swap_args; | |
248 case _adapter_opt_rot_1_up: | |
249 case _adapter_opt_rot_1_down: | |
250 case _adapter_opt_rot_2_up: | |
251 case _adapter_opt_rot_2_down: | |
252 return _adapter_rot_args; | |
253 case _adapter_opt_i2i: | |
254 case _adapter_opt_l2i: | |
255 case _adapter_opt_d2f: | |
256 case _adapter_opt_i2l: | |
257 case _adapter_opt_f2d: | |
258 return _adapter_prim_to_prim; | |
259 case _adapter_opt_unboxi: | |
260 case _adapter_opt_unboxl: | |
261 return _adapter_ref_to_prim; | |
262 } | |
263 if (ek >= _adapter_opt_spread_FIRST && ek <= _adapter_opt_spread_LAST) | |
264 return _adapter_spread_args; | |
265 if (ek >= _adapter_opt_collect_FIRST && ek <= _adapter_opt_collect_LAST) | |
266 return _adapter_collect_args; | |
267 if (ek >= _adapter_opt_fold_FIRST && ek <= _adapter_opt_fold_LAST) | |
268 return _adapter_fold_args; | |
269 if (ek >= _adapter_opt_return_FIRST && ek <= _adapter_opt_return_LAST) | |
270 return _adapter_opt_return_any; | |
271 if (ek == _adapter_opt_profiling) | |
272 return _adapter_retype_only; | |
273 assert(false, "oob"); | |
274 return _EK_LIMIT; | |
275 } | |
276 | |
277 static bool ek_supported(MethodHandles::EntryKind ek); | |
278 | |
279 static BasicType ek_bound_mh_arg_type(EntryKind ek) { | |
280 switch (ek) { | |
281 case _bound_int_mh : // fall-thru | |
282 case _bound_int_direct_mh : return T_INT; | |
283 case _bound_long_mh : // fall-thru | |
284 case _bound_long_direct_mh : return T_LONG; | |
285 default : return T_OBJECT; | |
286 } | |
287 } | |
288 | |
289 static int ek_adapter_opt_swap_slots(EntryKind ek) { | |
290 switch (ek) { | |
291 case _adapter_opt_swap_1 : return 1; | |
292 case _adapter_opt_swap_2 : return 2; | |
293 case _adapter_opt_rot_1_up : return 1; | |
294 case _adapter_opt_rot_1_down : return 1; | |
295 case _adapter_opt_rot_2_up : return 2; | |
296 case _adapter_opt_rot_2_down : return 2; | |
297 default : ShouldNotReachHere(); return -1; | |
298 } | |
299 } | |
300 | |
301 static int ek_adapter_opt_swap_mode(EntryKind ek) { | |
302 switch (ek) { | |
303 case _adapter_opt_swap_1 : return 0; | |
304 case _adapter_opt_swap_2 : return 0; | |
305 case _adapter_opt_rot_1_up : return 1; | |
306 case _adapter_opt_rot_1_down : return -1; | |
307 case _adapter_opt_rot_2_up : return 1; | |
308 case _adapter_opt_rot_2_down : return -1; | |
309 default : ShouldNotReachHere(); return 0; | |
310 } | |
311 } | |
312 | |
313 static int ek_adapter_opt_collect_count(EntryKind ek) { | |
314 assert(ek >= _adapter_opt_collect_FIRST && ek <= _adapter_opt_collect_LAST || | |
315 ek >= _adapter_opt_fold_FIRST && ek <= _adapter_opt_fold_LAST, ""); | |
316 switch (ek) { | |
317 case _adapter_opt_collect_0_ref : return 0; | |
318 case _adapter_opt_filter_S0_ref : | |
319 case _adapter_opt_filter_S1_ref : | |
320 case _adapter_opt_filter_S2_ref : | |
321 case _adapter_opt_filter_S3_ref : | |
322 case _adapter_opt_filter_S4_ref : | |
323 case _adapter_opt_filter_S5_ref : | |
324 case _adapter_opt_fold_1_ref : | |
325 case _adapter_opt_collect_1_ref : return 1; | |
326 case _adapter_opt_collect_2_S0_ref : | |
327 case _adapter_opt_collect_2_S1_ref : | |
328 case _adapter_opt_collect_2_S2_ref : | |
329 case _adapter_opt_collect_2_S3_ref : | |
330 case _adapter_opt_collect_2_S4_ref : | |
331 case _adapter_opt_collect_2_S5_ref : | |
332 case _adapter_opt_fold_2_ref : | |
333 case _adapter_opt_collect_2_ref : return 2; | |
334 case _adapter_opt_fold_3_ref : | |
335 case _adapter_opt_collect_3_ref : return 3; | |
336 case _adapter_opt_fold_4_ref : | |
337 case _adapter_opt_collect_4_ref : return 4; | |
338 case _adapter_opt_fold_5_ref : | |
339 case _adapter_opt_collect_5_ref : return 5; | |
340 default : return -1; // sentinel value for "variable" | |
341 } | |
342 } | |
343 | |
344 static int ek_adapter_opt_collect_slot(EntryKind ek) { | |
345 assert(ek >= _adapter_opt_collect_FIRST && ek <= _adapter_opt_collect_LAST || | |
346 ek >= _adapter_opt_fold_FIRST && ek <= _adapter_opt_fold_LAST, ""); | |
347 switch (ek) { | |
348 case _adapter_opt_collect_2_S0_ref : | |
349 case _adapter_opt_filter_S0_ref : return 0; | |
350 case _adapter_opt_collect_2_S1_ref : | |
351 case _adapter_opt_filter_S1_ref : return 1; | |
352 case _adapter_opt_collect_2_S2_ref : | |
353 case _adapter_opt_filter_S2_ref : return 2; | |
354 case _adapter_opt_collect_2_S3_ref : | |
355 case _adapter_opt_filter_S3_ref : return 3; | |
356 case _adapter_opt_collect_2_S4_ref : | |
357 case _adapter_opt_filter_S4_ref : return 4; | |
358 case _adapter_opt_collect_2_S5_ref : | |
359 case _adapter_opt_filter_S5_ref : return 5; | |
360 default : return -1; // sentinel value for "variable" | |
361 } | |
362 } | |
363 | |
364 static BasicType ek_adapter_opt_collect_type(EntryKind ek) { | |
365 assert(ek >= _adapter_opt_collect_FIRST && ek <= _adapter_opt_collect_LAST || | |
366 ek >= _adapter_opt_fold_FIRST && ek <= _adapter_opt_fold_LAST, ""); | |
367 switch (ek) { | |
368 case _adapter_opt_fold_int : | |
369 case _adapter_opt_collect_int : return T_INT; | |
370 case _adapter_opt_fold_long : | |
371 case _adapter_opt_collect_long : return T_LONG; | |
372 case _adapter_opt_fold_float : | |
373 case _adapter_opt_collect_float : return T_FLOAT; | |
374 case _adapter_opt_fold_double : | |
375 case _adapter_opt_collect_double : return T_DOUBLE; | |
376 case _adapter_opt_fold_void : | |
377 case _adapter_opt_collect_void : return T_VOID; | |
378 default : return T_OBJECT; | |
379 } | |
380 } | |
381 | |
382 static int ek_adapter_opt_return_slot(EntryKind ek) { | |
383 assert(ek >= _adapter_opt_return_FIRST && ek <= _adapter_opt_return_LAST, ""); | |
384 switch (ek) { | |
385 case _adapter_opt_return_S0_ref : return 0; | |
386 case _adapter_opt_return_S1_ref : return 1; | |
387 case _adapter_opt_return_S2_ref : return 2; | |
388 case _adapter_opt_return_S3_ref : return 3; | |
389 case _adapter_opt_return_S4_ref : return 4; | |
390 case _adapter_opt_return_S5_ref : return 5; | |
391 default : return -1; // sentinel value for "variable" | |
392 } | |
393 } | |
394 | |
395 static BasicType ek_adapter_opt_return_type(EntryKind ek) { | |
396 assert(ek >= _adapter_opt_return_FIRST && ek <= _adapter_opt_return_LAST, ""); | |
397 switch (ek) { | |
398 case _adapter_opt_return_int : return T_INT; | |
399 case _adapter_opt_return_long : return T_LONG; | |
400 case _adapter_opt_return_float : return T_FLOAT; | |
401 case _adapter_opt_return_double : return T_DOUBLE; | |
402 case _adapter_opt_return_void : return T_VOID; | |
403 case _adapter_opt_return_any : return T_CONFLICT; // sentinel value for "variable" | |
404 default : return T_OBJECT; | |
405 } | |
406 } | |
407 | |
408 static int ek_adapter_opt_spread_count(EntryKind ek) { | |
409 assert(ek >= _adapter_opt_spread_FIRST && ek <= _adapter_opt_spread_LAST, ""); | |
410 switch (ek) { | |
411 case _adapter_opt_spread_0 : return 0; | |
412 case _adapter_opt_spread_1_ref : return 1; | |
413 case _adapter_opt_spread_2_ref : return 2; | |
414 case _adapter_opt_spread_3_ref : return 3; | |
415 case _adapter_opt_spread_4_ref : return 4; | |
416 case _adapter_opt_spread_5_ref : return 5; | |
417 default : return -1; // sentinel value for "variable" | |
418 } | |
419 } | |
420 | |
421 static BasicType ek_adapter_opt_spread_type(EntryKind ek) { | |
422 assert(ek >= _adapter_opt_spread_FIRST && ek <= _adapter_opt_spread_LAST, ""); | |
423 switch (ek) { | |
424 // (there is no _adapter_opt_spread_boolean; we use byte) | |
425 case _adapter_opt_spread_byte : return T_BYTE; | |
426 case _adapter_opt_spread_char : return T_CHAR; | |
427 case _adapter_opt_spread_short : return T_SHORT; | |
428 case _adapter_opt_spread_int : return T_INT; | |
429 case _adapter_opt_spread_long : return T_LONG; | |
430 case _adapter_opt_spread_float : return T_FLOAT; | |
431 case _adapter_opt_spread_double : return T_DOUBLE; | |
432 default : return T_OBJECT; | |
433 } | |
434 } | |
435 | |
436 static methodOop raise_exception_method() { | |
437 oop rem = JNIHandles::resolve(_raise_exception_method); | |
438 assert(rem == NULL || rem->is_method(), ""); | |
439 return (methodOop) rem; | |
440 } | |
441 static void set_raise_exception_method(methodOop rem) { | |
442 assert(_raise_exception_method == NULL, ""); | |
443 _raise_exception_method = JNIHandles::make_global(Handle(rem)); | |
444 } | |
445 static methodOop resolve_raise_exception_method(TRAPS); | |
446 // call raise_exception_method from C code: | |
447 static void raise_exception(int code, oop actual, oop required, TRAPS); | |
448 | |
449 static jint adapter_conversion(int conv_op, BasicType src, BasicType dest, | |
450 int stack_move = 0, int vminfo = 0) { | |
451 assert(conv_op_valid(conv_op), "oob"); | |
452 jint conv = ((conv_op << CONV_OP_SHIFT) | |
453 | (src << CONV_SRC_TYPE_SHIFT) | |
454 | (dest << CONV_DEST_TYPE_SHIFT) | |
455 | (stack_move << CONV_STACK_MOVE_SHIFT) | |
456 | (vminfo << CONV_VMINFO_SHIFT) | |
457 ); | |
458 assert(adapter_conversion_op(conv) == conv_op, "decode conv_op"); | |
459 assert(adapter_conversion_src_type(conv) == src, "decode src"); | |
460 assert(adapter_conversion_dest_type(conv) == dest, "decode dest"); | |
461 assert(adapter_conversion_stack_move(conv) == stack_move, "decode stack_move"); | |
462 assert(adapter_conversion_vminfo(conv) == vminfo, "decode vminfo"); | |
463 return conv; | |
464 } | |
465 static int adapter_conversion_op(jint conv) { | |
466 return ((conv >> CONV_OP_SHIFT) & 0xF); | |
467 } | |
468 static BasicType adapter_conversion_src_type(jint conv) { | |
469 return (BasicType)((conv >> CONV_SRC_TYPE_SHIFT) & 0xF); | |
470 } | |
471 static BasicType adapter_conversion_dest_type(jint conv) { | |
472 return (BasicType)((conv >> CONV_DEST_TYPE_SHIFT) & 0xF); | |
473 } | |
474 static int adapter_conversion_stack_move(jint conv) { | |
475 return (conv >> CONV_STACK_MOVE_SHIFT); | |
476 } | |
477 static int adapter_conversion_vminfo(jint conv) { | |
478 return (conv >> CONV_VMINFO_SHIFT) & CONV_VMINFO_MASK; | |
479 } | |
480 | |
481 // Bit mask of conversion_op values. May vary by platform. | |
482 static int adapter_conversion_ops_supported_mask(); | |
483 | |
484 static bool conv_op_supported(int conv_op) { | |
485 assert(conv_op_valid(conv_op), ""); | |
486 return ((adapter_conversion_ops_supported_mask() & nth_bit(conv_op)) != 0); | |
487 } | |
488 | |
489 // Offset in words that the interpreter stack pointer moves when an argument is pushed. | |
490 // The stack_move value must always be a multiple of this. | |
491 static int stack_move_unit() { | |
492 return frame::interpreter_frame_expression_stack_direction() * Interpreter::stackElementWords; | |
493 } | |
494 | |
495 // Adapter frame traversal. (Implementation-specific.) | |
496 static frame ricochet_frame_sender(const frame& fr, RegisterMap* reg_map); | |
497 static void ricochet_frame_oops_do(const frame& fr, OopClosure* blk, const RegisterMap* reg_map); | |
498 | |
499 enum { CONV_VMINFO_SIGN_FLAG = 0x80 }; | |
500 // Shift values for prim-to-prim conversions. | |
501 static int adapter_prim_to_prim_subword_vminfo(BasicType dest) { | |
502 if (dest == T_BOOLEAN) return (BitsPerInt - 1); // boolean is 1 bit | |
503 if (dest == T_CHAR) return (BitsPerInt - BitsPerShort); | |
504 if (dest == T_BYTE) return (BitsPerInt - BitsPerByte ) | CONV_VMINFO_SIGN_FLAG; | |
505 if (dest == T_SHORT) return (BitsPerInt - BitsPerShort) | CONV_VMINFO_SIGN_FLAG; | |
506 return 0; // case T_INT | |
507 } | |
508 // Shift values for unboxing a primitive. | |
509 static int adapter_unbox_subword_vminfo(BasicType dest) { | |
510 if (dest == T_BOOLEAN) return (BitsPerInt - BitsPerByte ); // implemented as 1 byte | |
511 if (dest == T_CHAR) return (BitsPerInt - BitsPerShort); | |
512 if (dest == T_BYTE) return (BitsPerInt - BitsPerByte ) | CONV_VMINFO_SIGN_FLAG; | |
513 if (dest == T_SHORT) return (BitsPerInt - BitsPerShort) | CONV_VMINFO_SIGN_FLAG; | |
514 return 0; // case T_INT | |
515 } | |
516 // Here is the transformation the i2i adapter must perform: | |
517 static int truncate_subword_from_vminfo(jint value, int vminfo) { | |
518 int shift = vminfo & ~CONV_VMINFO_SIGN_FLAG; | |
519 jint tem = value << shift; | |
520 if ((vminfo & CONV_VMINFO_SIGN_FLAG) != 0) { | |
521 return (jint)tem >> shift; | |
522 } else { | |
523 return (juint)tem >> shift; | |
524 } | |
525 } | |
526 | |
527 static inline address from_compiled_entry(EntryKind ek); | |
528 static inline address from_interpreted_entry(EntryKind ek); | |
529 | |
530 // helpers for decode_method. | |
531 static methodOop decode_methodOop(methodOop m, int& decode_flags_result); | |
532 static methodHandle decode_vmtarget(oop vmtarget, int vmindex, oop mtype, KlassHandle& receiver_limit_result, int& decode_flags_result); | |
533 static methodHandle decode_MemberName(oop mname, KlassHandle& receiver_limit_result, int& decode_flags_result); | |
534 static methodHandle decode_MethodHandle(oop mh, KlassHandle& receiver_limit_result, int& decode_flags_result); | |
535 static methodHandle decode_DirectMethodHandle(oop mh, KlassHandle& receiver_limit_result, int& decode_flags_result); | |
536 static methodHandle decode_BoundMethodHandle(oop mh, KlassHandle& receiver_limit_result, int& decode_flags_result); | |
537 static methodHandle decode_AdapterMethodHandle(oop mh, KlassHandle& receiver_limit_result, int& decode_flags_result); | |
538 | |
539 // Find out how many stack slots an mh pushes or pops. | |
540 // The result is *not* reported as a multiple of stack_move_unit(); | |
541 // It is a signed net number of pushes (a difference in vmslots). | |
542 // To compare with a stack_move value, first multiply by stack_move_unit(). | |
543 static int decode_MethodHandle_stack_pushes(oop mh); | |
544 | |
545 public: | 52 public: |
546 // working with member names | 53 // working with member names |
547 static void resolve_MemberName(Handle mname, TRAPS); // compute vmtarget/vmindex from name/type | 54 static Handle resolve_MemberName(Handle mname, TRAPS); // compute vmtarget/vmindex from name/type |
548 static void expand_MemberName(Handle mname, int suppress, TRAPS); // expand defc/name/type if missing | 55 static void expand_MemberName(Handle mname, int suppress, TRAPS); // expand defc/name/type if missing |
549 static Handle new_MemberName(TRAPS); // must be followed by init_MemberName | 56 static Handle new_MemberName(TRAPS); // must be followed by init_MemberName |
550 static void init_MemberName(oop mname_oop, oop target); // compute vmtarget/vmindex from target | 57 static oop init_MemberName(oop mname_oop, oop target_oop); // compute vmtarget/vmindex from target |
551 static void init_MemberName(oop mname_oop, methodOop m, bool do_dispatch = true); | 58 static oop init_method_MemberName(oop mname_oop, methodOop m, bool do_dispatch, |
552 static void init_MemberName(oop mname_oop, klassOop field_holder, AccessFlags mods, int offset); | 59 klassOop receiver_limit); |
60 static oop init_field_MemberName(oop mname_oop, klassOop field_holder, | |
61 AccessFlags mods, oop type, oop name, | |
62 intptr_t offset, bool is_setter = false); | |
63 static Handle init_method_MemberName(oop mname_oop, CallInfo& info, TRAPS); | |
64 static Handle init_field_MemberName(oop mname_oop, FieldAccessInfo& info, TRAPS); | |
65 static int method_ref_kind(methodOop m, bool do_dispatch_if_possible = true); | |
553 static int find_MemberNames(klassOop k, Symbol* name, Symbol* sig, | 66 static int find_MemberNames(klassOop k, Symbol* name, Symbol* sig, |
554 int mflags, klassOop caller, | 67 int mflags, klassOop caller, |
555 int skip, objArrayOop results); | 68 int skip, objArrayOop results); |
556 // bit values for suppress argument to expand_MemberName: | 69 // bit values for suppress argument to expand_MemberName: |
557 enum { _suppress_defc = 1, _suppress_name = 2, _suppress_type = 4 }; | 70 enum { _suppress_defc = 1, _suppress_name = 2, _suppress_type = 4 }; |
558 | 71 |
559 // Generate MethodHandles adapters. | 72 // Generate MethodHandles adapters. |
560 static void generate_adapters(); | 73 static void generate_adapters(); |
561 | 74 |
562 // Called from InterpreterGenerator and MethodHandlesAdapterGenerator. | 75 // Called from MethodHandlesAdapterGenerator. |
563 static address generate_method_handle_interpreter_entry(MacroAssembler* _masm); | 76 static address generate_method_handle_interpreter_entry(MacroAssembler* _masm, vmIntrinsics::ID iid); |
564 static void generate_method_handle_stub(MacroAssembler* _masm, EntryKind ek); | 77 static void generate_method_handle_dispatch(MacroAssembler* _masm, |
565 | 78 vmIntrinsics::ID iid, |
566 // argument list parsing | 79 Register receiver_reg, |
567 static int argument_slot(oop method_type, int arg); | 80 Register member_reg, |
568 static int argument_slot_count(oop method_type) { return argument_slot(method_type, -1); } | 81 bool for_compiler_entry); |
569 static int argument_slot_to_argnum(oop method_type, int argslot); | 82 |
570 | 83 // Queries |
571 // Runtime support | 84 static bool is_signature_polymorphic(vmIntrinsics::ID iid) { |
572 enum { // bit-encoded flags from decode_method or decode_vmref | 85 return (iid >= vmIntrinsics::FIRST_MH_SIG_POLY && |
573 _dmf_has_receiver = 0x01, // target method has leading reference argument | 86 iid <= vmIntrinsics::LAST_MH_SIG_POLY); |
574 _dmf_does_dispatch = 0x02, // method handle performs virtual or interface dispatch | 87 } |
575 _dmf_from_interface = 0x04, // peforms interface dispatch | 88 |
576 _DMF_DIRECT_MASK = (_dmf_from_interface*2 - _dmf_has_receiver), | 89 static bool is_signature_polymorphic_intrinsic(vmIntrinsics::ID iid) { |
577 _dmf_binds_method = 0x08, | 90 assert(is_signature_polymorphic(iid), ""); |
578 _dmf_binds_argument = 0x10, | 91 // Most sig-poly methods are intrinsics which do not require an |
579 _DMF_BOUND_MASK = (_dmf_binds_argument*2 - _dmf_binds_method), | 92 // appeal to Java for adapter code. |
580 _dmf_adapter_lsb = 0x20, | 93 return (iid != vmIntrinsics::_invokeGeneric); |
581 _DMF_ADAPTER_MASK = (_dmf_adapter_lsb << CONV_OP_LIMIT) - _dmf_adapter_lsb | 94 } |
582 }; | 95 |
583 static methodHandle decode_method(oop x, KlassHandle& receiver_limit_result, int& decode_flags_result); | 96 static bool is_signature_polymorphic_static(vmIntrinsics::ID iid) { |
97 assert(is_signature_polymorphic(iid), ""); | |
98 return (iid >= vmIntrinsics::FIRST_MH_STATIC && | |
99 iid <= vmIntrinsics::LAST_MH_SIG_POLY); | |
100 } | |
101 | |
102 static bool has_member_arg(vmIntrinsics::ID iid) { | |
103 assert(is_signature_polymorphic(iid), ""); | |
104 return (iid >= vmIntrinsics::_linkToVirtual && | |
105 iid <= vmIntrinsics::_linkToInterface); | |
106 } | |
107 static bool has_member_arg(Symbol* klass, Symbol* name) { | |
108 if ((klass == vmSymbols::java_lang_invoke_MethodHandle()) && | |
109 is_signature_polymorphic_name(name)) { | |
110 vmIntrinsics::ID iid = signature_polymorphic_name_id(name); | |
111 return has_member_arg(iid); | |
112 } | |
113 return false; | |
114 } | |
115 | |
116 static Symbol* signature_polymorphic_intrinsic_name(vmIntrinsics::ID iid); | |
117 static int signature_polymorphic_intrinsic_ref_kind(vmIntrinsics::ID iid); | |
118 | |
119 static vmIntrinsics::ID signature_polymorphic_name_id(klassOop klass, Symbol* name); | |
120 static vmIntrinsics::ID signature_polymorphic_name_id(Symbol* name); | |
121 static bool is_signature_polymorphic_name(Symbol* name) { | |
122 return signature_polymorphic_name_id(name) != vmIntrinsics::_none; | |
123 } | |
124 static bool is_method_handle_invoke_name(klassOop klass, Symbol* name); | |
125 static bool is_signature_polymorphic_name(klassOop klass, Symbol* name) { | |
126 return signature_polymorphic_name_id(klass, name) != vmIntrinsics::_none; | |
127 } | |
128 | |
584 enum { | 129 enum { |
585 // format of query to getConstant: | 130 // format of query to getConstant: |
586 GC_JVM_PUSH_LIMIT = 0, | |
587 GC_JVM_STACK_MOVE_UNIT = 1, | |
588 GC_CONV_OP_IMPLEMENTED_MASK = 2, | |
589 GC_OP_ROT_ARGS_DOWN_LIMIT_BIAS = 3, | |
590 GC_COUNT_GWT = 4, | 131 GC_COUNT_GWT = 4, |
591 | 132 GC_LAMBDA_SUPPORT = 5 |
592 // format of result from getTarget / encode_target: | |
593 ETF_HANDLE_OR_METHOD_NAME = 0, // all available data (immediate MH or method) | |
594 ETF_DIRECT_HANDLE = 1, // ultimate method handle (will be a DMH, may be self) | |
595 ETF_METHOD_NAME = 2, // ultimate method as MemberName | |
596 ETF_REFLECT_METHOD = 3, // ultimate method as java.lang.reflect object (sans refClass) | |
597 ETF_FORCE_DIRECT_HANDLE = 64, | |
598 ETF_COMPILE_DIRECT_HANDLE = 65, | |
599 | |
600 // ad hoc constants | |
601 OP_ROT_ARGS_DOWN_LIMIT_BIAS = -1 | |
602 }; | 133 }; |
603 static int get_named_constant(int which, Handle name_box, TRAPS); | 134 static int get_named_constant(int which, Handle name_box, TRAPS); |
604 static oop encode_target(Handle mh, int format, TRAPS); // report vmtarget (to Java code) | |
605 static bool class_cast_needed(klassOop src, klassOop dst); | |
606 | |
607 static instanceKlassHandle resolve_instance_klass(oop java_mirror_oop, TRAPS); | |
608 static instanceKlassHandle resolve_instance_klass(jclass java_mirror_jh, TRAPS) { | |
609 return resolve_instance_klass(JNIHandles::resolve(java_mirror_jh), THREAD); | |
610 } | |
611 | |
612 private: | |
613 // These checkers operate on a pair of whole MethodTypes: | |
614 static const char* check_method_type_change(oop src_mtype, int src_beg, int src_end, | |
615 int insert_argnum, oop insert_type, | |
616 int change_argnum, oop change_type, | |
617 int delete_argnum, | |
618 oop dst_mtype, int dst_beg, int dst_end, | |
619 bool raw = false); | |
620 static const char* check_method_type_insertion(oop src_mtype, | |
621 int insert_argnum, oop insert_type, | |
622 oop dst_mtype) { | |
623 oop no_ref = NULL; | |
624 return check_method_type_change(src_mtype, 0, -1, | |
625 insert_argnum, insert_type, | |
626 -1, no_ref, -1, dst_mtype, 0, -1); | |
627 } | |
628 static const char* check_method_type_conversion(oop src_mtype, | |
629 int change_argnum, oop change_type, | |
630 oop dst_mtype) { | |
631 oop no_ref = NULL; | |
632 return check_method_type_change(src_mtype, 0, -1, -1, no_ref, | |
633 change_argnum, change_type, | |
634 -1, dst_mtype, 0, -1); | |
635 } | |
636 static const char* check_method_type_passthrough(oop src_mtype, oop dst_mtype, bool raw) { | |
637 oop no_ref = NULL; | |
638 return check_method_type_change(src_mtype, 0, -1, | |
639 -1, no_ref, -1, no_ref, -1, | |
640 dst_mtype, 0, -1, raw); | |
641 } | |
642 | |
643 // These checkers operate on pairs of argument or return types: | |
644 static const char* check_argument_type_change(BasicType src_type, klassOop src_klass, | |
645 BasicType dst_type, klassOop dst_klass, | |
646 int argnum, bool raw = false); | |
647 | |
648 static const char* check_argument_type_change(oop src_type, oop dst_type, | |
649 int argnum, bool raw = false) { | |
650 klassOop src_klass = NULL, dst_klass = NULL; | |
651 BasicType src_bt = java_lang_Class::as_BasicType(src_type, &src_klass); | |
652 BasicType dst_bt = java_lang_Class::as_BasicType(dst_type, &dst_klass); | |
653 return check_argument_type_change(src_bt, src_klass, | |
654 dst_bt, dst_klass, argnum, raw); | |
655 } | |
656 | |
657 static const char* check_return_type_change(oop src_type, oop dst_type, bool raw = false) { | |
658 return check_argument_type_change(src_type, dst_type, -1, raw); | |
659 } | |
660 | |
661 static const char* check_return_type_change(BasicType src_type, klassOop src_klass, | |
662 BasicType dst_type, klassOop dst_klass) { | |
663 return check_argument_type_change(src_type, src_klass, dst_type, dst_klass, -1); | |
664 } | |
665 | |
666 static const char* check_method_receiver(methodOop m, klassOop passed_recv_type); | |
667 | |
668 // These verifiers can block, and will throw an error if the checking fails: | |
669 static void verify_vmslots(Handle mh, TRAPS); | |
670 static void verify_vmargslot(Handle mh, int argnum, int argslot, TRAPS); | |
671 | |
672 static void verify_method_type(methodHandle m, Handle mtype, | |
673 bool has_bound_oop, | |
674 KlassHandle bound_oop_type, | |
675 TRAPS); | |
676 | |
677 static void verify_method_signature(methodHandle m, Handle mtype, | |
678 int first_ptype_pos, | |
679 KlassHandle insert_ptype, TRAPS); | |
680 | |
681 static void verify_DirectMethodHandle(Handle mh, methodHandle m, TRAPS); | |
682 static void verify_BoundMethodHandle(Handle mh, Handle target, int argnum, | |
683 bool direct_to_method, TRAPS); | |
684 static void verify_BoundMethodHandle_with_receiver(Handle mh, methodHandle m, TRAPS); | |
685 static void verify_AdapterMethodHandle(Handle mh, int argnum, TRAPS); | |
686 | |
687 public: | |
688 | |
689 // Fill in the fields of a DirectMethodHandle mh. (MH.type must be pre-filled.) | |
690 static void init_DirectMethodHandle(Handle mh, methodHandle method, bool do_dispatch, TRAPS); | |
691 | |
692 // Fill in the fields of a BoundMethodHandle mh. (MH.type, BMH.argument must be pre-filled.) | |
693 static void init_BoundMethodHandle(Handle mh, Handle target, int argnum, TRAPS); | |
694 static void init_BoundMethodHandle_with_receiver(Handle mh, | |
695 methodHandle original_m, | |
696 KlassHandle receiver_limit, | |
697 int decode_flags, | |
698 TRAPS); | |
699 | |
700 // Fill in the fields of an AdapterMethodHandle mh. (MH.type must be pre-filled.) | |
701 static void init_AdapterMethodHandle(Handle mh, Handle target, int argnum, TRAPS); | |
702 static void ensure_vmlayout_field(Handle target, TRAPS); | |
703 | |
704 #ifdef ASSERT | |
705 static bool spot_check_entry_names(); | |
706 #endif | |
707 | |
708 private: | |
709 static methodHandle dispatch_decoded_method(methodHandle m, | |
710 KlassHandle receiver_limit, | |
711 int decode_flags, | |
712 KlassHandle receiver_klass, | |
713 TRAPS); | |
714 | 135 |
715 public: | 136 public: |
716 static bool is_float_fixed_reinterpretation_cast(BasicType src, BasicType dst); | 137 static Symbol* lookup_signature(oop type_str, bool polymorphic, TRAPS); // use TempNewSymbol |
717 static bool same_basic_type_for_arguments(BasicType src, BasicType dst, | 138 static Symbol* lookup_basic_type_signature(Symbol* sig, bool keep_last_arg, TRAPS); // use TempNewSymbol |
718 bool raw = false, | 139 static Symbol* lookup_basic_type_signature(Symbol* sig, TRAPS) { |
719 bool for_return = false); | 140 return lookup_basic_type_signature(sig, false, THREAD); |
720 static bool same_basic_type_for_returns(BasicType src, BasicType dst, bool raw = false) { | 141 } |
721 return same_basic_type_for_arguments(src, dst, raw, true); | 142 static bool is_basic_type_signature(Symbol* sig); |
722 } | 143 |
723 | 144 static Symbol* lookup_method_type(Symbol* msig, Handle mtype, TRAPS); |
724 static Symbol* convert_to_signature(oop type_str, bool polymorphic, TRAPS); | 145 |
146 static void print_as_method_type_on(outputStream* st, Symbol* sig) { | |
147 print_as_basic_type_signature_on(st, sig, true, true); | |
148 } | |
149 static void print_as_basic_type_signature_on(outputStream* st, Symbol* sig, bool keep_arrays = false, bool keep_basic_names = false); | |
150 | |
151 // decoding CONSTANT_MethodHandle constants | |
152 enum { JVM_REF_MIN = JVM_REF_getField, JVM_REF_MAX = JVM_REF_invokeInterface }; | |
153 static bool ref_kind_is_valid(int ref_kind) { | |
154 return (ref_kind >= JVM_REF_MIN && ref_kind <= JVM_REF_MAX); | |
155 } | |
156 static bool ref_kind_is_field(int ref_kind) { | |
157 assert(ref_kind_is_valid(ref_kind), ""); | |
158 return (ref_kind <= JVM_REF_putStatic); | |
159 } | |
160 static bool ref_kind_is_getter(int ref_kind) { | |
161 assert(ref_kind_is_valid(ref_kind), ""); | |
162 return (ref_kind <= JVM_REF_getStatic); | |
163 } | |
164 static bool ref_kind_is_setter(int ref_kind) { | |
165 return ref_kind_is_field(ref_kind) && !ref_kind_is_getter(ref_kind); | |
166 } | |
167 static bool ref_kind_is_method(int ref_kind) { | |
168 return !ref_kind_is_field(ref_kind) && (ref_kind != JVM_REF_newInvokeSpecial); | |
169 } | |
170 static bool ref_kind_has_receiver(int ref_kind) { | |
171 assert(ref_kind_is_valid(ref_kind), ""); | |
172 return (ref_kind & 1) != 0; | |
173 } | |
174 static bool ref_kind_is_static(int ref_kind) { | |
175 return !ref_kind_has_receiver(ref_kind) && (ref_kind != JVM_REF_newInvokeSpecial); | |
176 } | |
177 static bool ref_kind_does_dispatch(int ref_kind) { | |
178 return (ref_kind == JVM_REF_invokeVirtual || | |
179 ref_kind == JVM_REF_invokeInterface); | |
180 } | |
181 | |
725 | 182 |
726 #ifdef TARGET_ARCH_x86 | 183 #ifdef TARGET_ARCH_x86 |
727 # include "methodHandles_x86.hpp" | 184 # include "methodHandles_x86.hpp" |
728 #endif | 185 #endif |
729 #ifdef TARGET_ARCH_sparc | 186 #ifdef TARGET_ARCH_sparc |
736 # include "methodHandles_arm.hpp" | 193 # include "methodHandles_arm.hpp" |
737 #endif | 194 #endif |
738 #ifdef TARGET_ARCH_ppc | 195 #ifdef TARGET_ARCH_ppc |
739 # include "methodHandles_ppc.hpp" | 196 # include "methodHandles_ppc.hpp" |
740 #endif | 197 #endif |
198 | |
199 | |
741 }; | 200 }; |
742 | |
743 | |
744 // Access methods for the "entry" field of a java.lang.invoke.MethodHandle. | |
745 // The field is primarily a jump target for compiled calls. | |
746 // However, we squirrel away some nice pointers for other uses, | |
747 // just before the jump target. | |
748 // Aspects of a method handle entry: | |
749 // - from_compiled_entry - stub used when compiled code calls the MH | |
750 // - from_interpreted_entry - stub used when the interpreter calls the MH | |
751 // - type_checking_entry - stub for runtime casting between MHForm siblings (NYI) | |
752 class MethodHandleEntry { | |
753 public: | |
754 class Data { | |
755 friend class MethodHandleEntry; | |
756 size_t _total_size; // size including Data and code stub | |
757 MethodHandleEntry* _type_checking_entry; | |
758 address _from_interpreted_entry; | |
759 MethodHandleEntry* method_entry() { return (MethodHandleEntry*)(this + 1); } | |
760 }; | |
761 | |
762 Data* data() { return (Data*)this - 1; } | |
763 | |
764 address start_address() { return (address) data(); } | |
765 address end_address() { return start_address() + data()->_total_size; } | |
766 | |
767 address from_compiled_entry() { return (address) this; } | |
768 | |
769 address from_interpreted_entry() { return data()->_from_interpreted_entry; } | |
770 void set_from_interpreted_entry(address e) { data()->_from_interpreted_entry = e; } | |
771 | |
772 MethodHandleEntry* type_checking_entry() { return data()->_type_checking_entry; } | |
773 void set_type_checking_entry(MethodHandleEntry* e) { data()->_type_checking_entry = e; } | |
774 | |
775 void set_end_address(address end_addr) { | |
776 size_t total_size = end_addr - start_address(); | |
777 assert(total_size > 0 && total_size < 0x1000, "reasonable end address"); | |
778 data()->_total_size = total_size; | |
779 } | |
780 | |
781 // Compiler support: | |
782 static int from_interpreted_entry_offset_in_bytes() { | |
783 return (int)( offset_of(Data, _from_interpreted_entry) - sizeof(Data) ); | |
784 } | |
785 static int type_checking_entry_offset_in_bytes() { | |
786 return (int)( offset_of(Data, _from_interpreted_entry) - sizeof(Data) ); | |
787 } | |
788 | |
789 static address start_compiled_entry(MacroAssembler* _masm, | |
790 address interpreted_entry = NULL); | |
791 static MethodHandleEntry* finish_compiled_entry(MacroAssembler* masm, address start_addr); | |
792 }; | |
793 | |
794 address MethodHandles::from_compiled_entry(EntryKind ek) { return entry(ek)->from_compiled_entry(); } | |
795 address MethodHandles::from_interpreted_entry(EntryKind ek) { return entry(ek)->from_interpreted_entry(); } | |
796 | 201 |
797 | 202 |
798 //------------------------------------------------------------------------------ | 203 //------------------------------------------------------------------------------ |
799 // MethodHandlesAdapterGenerator | 204 // MethodHandlesAdapterGenerator |
800 // | 205 // |