Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/vm/prims/methodHandles.hpp
+++ new/src/share/vm/prims/methodHandles.hpp
1 1 /*
2 2 * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 *
23 23 */
24 24
25 25 #ifndef SHARE_VM_PRIMS_METHODHANDLES_HPP
26 26 #define SHARE_VM_PRIMS_METHODHANDLES_HPP
27 27
28 28 #include "classfile/javaClasses.hpp"
29 29 #include "classfile/vmSymbols.hpp"
30 30 #include "runtime/frame.inline.hpp"
31 31 #include "runtime/globals.hpp"
32 32 #include "runtime/interfaceSupport.hpp"
33 33
34 34 class MacroAssembler;
35 35 class Label;
36 36 class MethodHandleEntry;
37 37
38 38 class MethodHandles: AllStatic {
39 39 // JVM support for MethodHandle, MethodType, and related types
40 40 // in java.lang.invoke and sun.invoke.
41 41 // See also javaClasses for layouts java_lang_invoke_Method{Handle,Type,Type::Form}.
42 42 public:
43 43 enum EntryKind {
44 44 _raise_exception, // stub for error generation from other stubs
45 45 _invokestatic_mh, // how a MH emulates invokestatic
46 46 _invokespecial_mh, // ditto for the other invokes...
47 47 _invokevirtual_mh,
48 48 _invokeinterface_mh,
49 49 _bound_ref_mh, // reference argument is bound
50 50 _bound_int_mh, // int argument is bound (via an Integer or Float)
51 51 _bound_long_mh, // long argument is bound (via a Long or Double)
52 52 _bound_ref_direct_mh, // same as above, with direct linkage to methodOop
53 53 _bound_int_direct_mh,
54 54 _bound_long_direct_mh,
55 55
56 56 _adapter_mh_first, // adapter sequence goes here...
57 57 _adapter_retype_only = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_RETYPE_ONLY,
58 58 _adapter_retype_raw = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_RETYPE_RAW,
59 59 _adapter_check_cast = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_CHECK_CAST,
60 60 _adapter_prim_to_prim = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_PRIM,
61 61 _adapter_ref_to_prim = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_REF_TO_PRIM,
62 62 _adapter_prim_to_ref = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_REF,
63 63 _adapter_swap_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_SWAP_ARGS,
64 64 _adapter_rot_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_ROT_ARGS,
65 65 _adapter_dup_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_DUP_ARGS,
66 66 _adapter_drop_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_DROP_ARGS,
67 67 _adapter_collect_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_COLLECT_ARGS,
68 68 _adapter_spread_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_SPREAD_ARGS,
69 69 _adapter_fold_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_FOLD_ARGS,
70 70 _adapter_unused_13 = _adapter_mh_first + 13, //hole in the CONV_OP enumeration
71 71 _adapter_mh_last = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::CONV_OP_LIMIT - 1,
72 72
73 73 // Optimized adapter types
74 74
75 75 // argument list reordering
76 76 _adapter_opt_swap_1,
77 77 _adapter_opt_swap_2,
78 78 _adapter_opt_rot_1_up,
79 79 _adapter_opt_rot_1_down,
80 80 _adapter_opt_rot_2_up,
81 81 _adapter_opt_rot_2_down,
82 82 // primitive single to single:
83 83 _adapter_opt_i2i, // i2c, i2z, i2b, i2s
84 84 // primitive double to single:
85 85 _adapter_opt_l2i,
86 86 _adapter_opt_d2f,
87 87 // primitive single to double:
88 88 _adapter_opt_i2l,
89 89 _adapter_opt_f2d,
90 90 // conversion between floating point and integer type is handled by Java
91 91
92 92 // reference to primitive:
93 93 _adapter_opt_unboxi,
94 94 _adapter_opt_unboxl,
95 95
96 96 // %% Maybe tame the following with a VM_SYMBOLS_DO type macro?
97 97
98 98 // how a blocking adapter returns (platform-dependent)
99 99 _adapter_opt_return_ref,
100 100 _adapter_opt_return_int,
101 101 _adapter_opt_return_long,
102 102 _adapter_opt_return_float,
103 103 _adapter_opt_return_double,
104 104 _adapter_opt_return_void,
105 105 _adapter_opt_return_S0_ref, // return ref to S=0 (last slot)
106 106 _adapter_opt_return_S1_ref, // return ref to S=1 (2nd-to-last slot)
107 107 _adapter_opt_return_S2_ref,
108 108 _adapter_opt_return_S3_ref,
109 109 _adapter_opt_return_S4_ref,
110 110 _adapter_opt_return_S5_ref,
111 111 _adapter_opt_return_any, // dynamically select r/i/l/f/d
112 112 _adapter_opt_return_FIRST = _adapter_opt_return_ref,
113 113 _adapter_opt_return_LAST = _adapter_opt_return_any,
114 114
115 115 // spreading (array length cases 0, 1, ...)
116 116 _adapter_opt_spread_0, // spread empty array to N=0 arguments
117 117 _adapter_opt_spread_1_ref, // spread Object[] to N=1 argument
118 118 _adapter_opt_spread_2_ref, // spread Object[] to N=2 arguments
119 119 _adapter_opt_spread_3_ref, // spread Object[] to N=3 arguments
120 120 _adapter_opt_spread_4_ref, // spread Object[] to N=4 arguments
121 121 _adapter_opt_spread_5_ref, // spread Object[] to N=5 arguments
122 122 _adapter_opt_spread_ref, // spread Object[] to N arguments
123 123 _adapter_opt_spread_byte, // spread byte[] or boolean[] to N arguments
124 124 _adapter_opt_spread_char, // spread char[], etc., to N arguments
125 125 _adapter_opt_spread_short, // spread short[], etc., to N arguments
126 126 _adapter_opt_spread_int, // spread int[], short[], etc., to N arguments
127 127 _adapter_opt_spread_long, // spread long[] to N arguments
128 128 _adapter_opt_spread_float, // spread float[] to N arguments
129 129 _adapter_opt_spread_double, // spread double[] to N arguments
130 130 _adapter_opt_spread_FIRST = _adapter_opt_spread_0,
131 131 _adapter_opt_spread_LAST = _adapter_opt_spread_double,
132 132
133 133 // blocking filter/collect conversions
134 134 // These collect N arguments and replace them (at slot S) by a return value
135 135 // which is passed to the final target, along with the unaffected arguments.
136 136 // collect_{N}_{T} collects N arguments at any position into a T value
137 137 // collect_{N}_S{S}_{T} collects N arguments at slot S into a T value
138 138 // collect_{T} collects any number of arguments at any position
139 139 // filter_S{S}_{T} is the same as collect_1_S{S}_{T} (a unary collection)
140 140 // (collect_2 is also usable as a filter, with long or double arguments)
141 141 _adapter_opt_collect_ref, // combine N arguments, replace with a reference
142 142 _adapter_opt_collect_int, // combine N arguments, replace with an int, short, etc.
143 143 _adapter_opt_collect_long, // combine N arguments, replace with a long
144 144 _adapter_opt_collect_float, // combine N arguments, replace with a float
145 145 _adapter_opt_collect_double, // combine N arguments, replace with a double
146 146 _adapter_opt_collect_void, // combine N arguments, replace with nothing
147 147 // if there is a small fixed number to push, do so without a loop:
148 148 _adapter_opt_collect_0_ref, // collect N=0 arguments, insert a reference
149 149 _adapter_opt_collect_1_ref, // collect N=1 argument, replace with a reference
150 150 _adapter_opt_collect_2_ref, // combine N=2 arguments, replace with a reference
151 151 _adapter_opt_collect_3_ref, // combine N=3 arguments, replace with a reference
152 152 _adapter_opt_collect_4_ref, // combine N=4 arguments, replace with a reference
153 153 _adapter_opt_collect_5_ref, // combine N=5 arguments, replace with a reference
154 154 // filters are an important special case because they never move arguments:
155 155 _adapter_opt_filter_S0_ref, // filter N=1 argument at S=0, replace with a reference
156 156 _adapter_opt_filter_S1_ref, // filter N=1 argument at S=1, replace with a reference
157 157 _adapter_opt_filter_S2_ref, // filter N=1 argument at S=2, replace with a reference
158 158 _adapter_opt_filter_S3_ref, // filter N=1 argument at S=3, replace with a reference
159 159 _adapter_opt_filter_S4_ref, // filter N=1 argument at S=4, replace with a reference
160 160 _adapter_opt_filter_S5_ref, // filter N=1 argument at S=5, replace with a reference
161 161 // these move arguments, but they are important for boxing
162 162 _adapter_opt_collect_2_S0_ref, // combine last N=2 arguments, replace with a reference
163 163 _adapter_opt_collect_2_S1_ref, // combine N=2 arguments at S=1, replace with a reference
164 164 _adapter_opt_collect_2_S2_ref, // combine N=2 arguments at S=2, replace with a reference
165 165 _adapter_opt_collect_2_S3_ref, // combine N=2 arguments at S=3, replace with a reference
166 166 _adapter_opt_collect_2_S4_ref, // combine N=2 arguments at S=4, replace with a reference
167 167 _adapter_opt_collect_2_S5_ref, // combine N=2 arguments at S=5, replace with a reference
168 168 _adapter_opt_collect_FIRST = _adapter_opt_collect_ref,
169 169 _adapter_opt_collect_LAST = _adapter_opt_collect_2_S5_ref,
170 170
171 171 // blocking folding conversions
172 172 // these are like collects, but retain all the N arguments for the final target
173 173 //_adapter_opt_fold_0_ref, // same as _adapter_opt_collect_0_ref
174 174 // fold_{N}_{T} processes N arguments at any position into a T value, which it inserts
175 175 // fold_{T} processes any number of arguments at any position
176 176 _adapter_opt_fold_ref, // process N arguments, prepend a reference
177 177 _adapter_opt_fold_int, // process N arguments, prepend an int, short, etc.
178 178 _adapter_opt_fold_long, // process N arguments, prepend a long
179 179 _adapter_opt_fold_float, // process N arguments, prepend a float
180 180 _adapter_opt_fold_double, // process N arguments, prepend a double
181 181 _adapter_opt_fold_void, // process N arguments, but leave the list unchanged
182 182 _adapter_opt_fold_1_ref, // process N=1 argument, prepend a reference
183 183 _adapter_opt_fold_2_ref, // process N=2 arguments, prepend a reference
184 184 _adapter_opt_fold_3_ref, // process N=3 arguments, prepend a reference
185 185 _adapter_opt_fold_4_ref, // process N=4 arguments, prepend a reference
186 186 _adapter_opt_fold_5_ref, // process N=5 arguments, prepend a reference
187 187 _adapter_opt_fold_FIRST = _adapter_opt_fold_ref,
188 188 _adapter_opt_fold_LAST = _adapter_opt_fold_5_ref,
189 189
190 190 _EK_LIMIT,
191 191 _EK_FIRST = 0
192 192 };
193 193
194 194 public:
195 195 static bool enabled() { return _enabled; }
196 196 static void set_enabled(bool z);
197 197
198 198 private:
199 199 enum { // import java_lang_invoke_AdapterMethodHandle::CONV_OP_*
200 200 CONV_OP_LIMIT = java_lang_invoke_AdapterMethodHandle::CONV_OP_LIMIT,
201 201 CONV_OP_MASK = java_lang_invoke_AdapterMethodHandle::CONV_OP_MASK,
202 202 CONV_TYPE_MASK = java_lang_invoke_AdapterMethodHandle::CONV_TYPE_MASK,
203 203 CONV_VMINFO_MASK = java_lang_invoke_AdapterMethodHandle::CONV_VMINFO_MASK,
204 204 CONV_VMINFO_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_VMINFO_SHIFT,
205 205 CONV_OP_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_OP_SHIFT,
206 206 CONV_DEST_TYPE_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_DEST_TYPE_SHIFT,
207 207 CONV_SRC_TYPE_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_SRC_TYPE_SHIFT,
208 208 CONV_STACK_MOVE_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_STACK_MOVE_SHIFT,
209 209 CONV_STACK_MOVE_MASK = java_lang_invoke_AdapterMethodHandle::CONV_STACK_MOVE_MASK
210 210 };
211 211
212 212 static bool _enabled;
213 213 static MethodHandleEntry* _entries[_EK_LIMIT];
214 214 static const char* _entry_names[_EK_LIMIT+1];
215 215 static jobject _raise_exception_method;
216 216 static address _adapter_return_handlers[CONV_TYPE_MASK+1];
217 217
218 218 // Adapters.
219 219 static MethodHandlesAdapterBlob* _adapter_code;
220 220 static int _adapter_code_size;
221 221
222 222 static bool ek_valid(EntryKind ek) { return (uint)ek < (uint)_EK_LIMIT; }
223 223 static bool conv_op_valid(int op) { return (uint)op < (uint)CONV_OP_LIMIT; }
224 224
225 225 public:
226 226 static bool have_entry(EntryKind ek) { return ek_valid(ek) && _entries[ek] != NULL; }
227 227 static MethodHandleEntry* entry(EntryKind ek) { assert(ek_valid(ek), "initialized");
228 228 return _entries[ek]; }
229 229 static const char* entry_name(EntryKind ek) { assert(ek_valid(ek), "oob");
230 230 return _entry_names[ek]; }
231 231 static EntryKind adapter_entry_kind(int op) { assert(conv_op_valid(op), "oob");
232 232 return EntryKind(_adapter_mh_first + op); }
233 233
234 234 static void init_entry(EntryKind ek, MethodHandleEntry* me) {
235 235 assert(ek_valid(ek), "oob");
236 236 assert(_entries[ek] == NULL, "no double initialization");
237 237 _entries[ek] = me;
238 238 }
239 239
240 240 // Some adapter helper functions.
241 241 static EntryKind ek_original_kind(EntryKind ek) {
242 242 if (ek <= _adapter_mh_last) return ek;
243 243 switch (ek) {
244 244 case _adapter_opt_swap_1:
245 245 case _adapter_opt_swap_2:
246 246 return _adapter_swap_args;
247 247 case _adapter_opt_rot_1_up:
248 248 case _adapter_opt_rot_1_down:
249 249 case _adapter_opt_rot_2_up:
250 250 case _adapter_opt_rot_2_down:
251 251 return _adapter_rot_args;
252 252 case _adapter_opt_i2i:
253 253 case _adapter_opt_l2i:
254 254 case _adapter_opt_d2f:
255 255 case _adapter_opt_i2l:
256 256 case _adapter_opt_f2d:
257 257 return _adapter_prim_to_prim;
258 258 case _adapter_opt_unboxi:
259 259 case _adapter_opt_unboxl:
260 260 return _adapter_ref_to_prim;
261 261 }
262 262 if (ek >= _adapter_opt_spread_FIRST && ek <= _adapter_opt_spread_LAST)
263 263 return _adapter_spread_args;
264 264 if (ek >= _adapter_opt_collect_FIRST && ek <= _adapter_opt_collect_LAST)
265 265 return _adapter_collect_args;
266 266 if (ek >= _adapter_opt_fold_FIRST && ek <= _adapter_opt_fold_LAST)
267 267 return _adapter_fold_args;
268 268 if (ek >= _adapter_opt_return_FIRST && ek <= _adapter_opt_return_LAST)
269 269 return _adapter_opt_return_any;
270 270 assert(false, "oob");
271 271 return _EK_LIMIT;
272 272 }
273 273
274 274 static bool ek_supported(MethodHandles::EntryKind ek);
275 275
276 276 static BasicType ek_bound_mh_arg_type(EntryKind ek) {
277 277 switch (ek) {
278 278 case _bound_int_mh : // fall-thru
279 279 case _bound_int_direct_mh : return T_INT;
280 280 case _bound_long_mh : // fall-thru
281 281 case _bound_long_direct_mh : return T_LONG;
282 282 default : return T_OBJECT;
283 283 }
284 284 }
285 285
286 286 static int ek_adapter_opt_swap_slots(EntryKind ek) {
287 287 switch (ek) {
288 288 case _adapter_opt_swap_1 : return 1;
289 289 case _adapter_opt_swap_2 : return 2;
290 290 case _adapter_opt_rot_1_up : return 1;
291 291 case _adapter_opt_rot_1_down : return 1;
292 292 case _adapter_opt_rot_2_up : return 2;
293 293 case _adapter_opt_rot_2_down : return 2;
294 294 default : ShouldNotReachHere(); return -1;
295 295 }
296 296 }
297 297
298 298 static int ek_adapter_opt_swap_mode(EntryKind ek) {
299 299 switch (ek) {
300 300 case _adapter_opt_swap_1 : return 0;
301 301 case _adapter_opt_swap_2 : return 0;
302 302 case _adapter_opt_rot_1_up : return 1;
303 303 case _adapter_opt_rot_1_down : return -1;
304 304 case _adapter_opt_rot_2_up : return 1;
305 305 case _adapter_opt_rot_2_down : return -1;
306 306 default : ShouldNotReachHere(); return 0;
307 307 }
308 308 }
309 309
310 310 static int ek_adapter_opt_collect_count(EntryKind ek) {
311 311 assert(ek >= _adapter_opt_collect_FIRST && ek <= _adapter_opt_collect_LAST ||
312 312 ek >= _adapter_opt_fold_FIRST && ek <= _adapter_opt_fold_LAST, "");
313 313 switch (ek) {
314 314 case _adapter_opt_collect_0_ref : return 0;
315 315 case _adapter_opt_filter_S0_ref :
316 316 case _adapter_opt_filter_S1_ref :
317 317 case _adapter_opt_filter_S2_ref :
318 318 case _adapter_opt_filter_S3_ref :
319 319 case _adapter_opt_filter_S4_ref :
320 320 case _adapter_opt_filter_S5_ref :
321 321 case _adapter_opt_fold_1_ref :
322 322 case _adapter_opt_collect_1_ref : return 1;
323 323 case _adapter_opt_collect_2_S0_ref :
324 324 case _adapter_opt_collect_2_S1_ref :
325 325 case _adapter_opt_collect_2_S2_ref :
326 326 case _adapter_opt_collect_2_S3_ref :
327 327 case _adapter_opt_collect_2_S4_ref :
328 328 case _adapter_opt_collect_2_S5_ref :
329 329 case _adapter_opt_fold_2_ref :
330 330 case _adapter_opt_collect_2_ref : return 2;
331 331 case _adapter_opt_fold_3_ref :
332 332 case _adapter_opt_collect_3_ref : return 3;
333 333 case _adapter_opt_fold_4_ref :
334 334 case _adapter_opt_collect_4_ref : return 4;
335 335 case _adapter_opt_fold_5_ref :
336 336 case _adapter_opt_collect_5_ref : return 5;
337 337 default : return -1; // sentinel value for "variable"
338 338 }
339 339 }
340 340
341 341 static int ek_adapter_opt_collect_slot(EntryKind ek) {
342 342 assert(ek >= _adapter_opt_collect_FIRST && ek <= _adapter_opt_collect_LAST ||
343 343 ek >= _adapter_opt_fold_FIRST && ek <= _adapter_opt_fold_LAST, "");
344 344 switch (ek) {
345 345 case _adapter_opt_collect_2_S0_ref :
346 346 case _adapter_opt_filter_S0_ref : return 0;
347 347 case _adapter_opt_collect_2_S1_ref :
348 348 case _adapter_opt_filter_S1_ref : return 1;
349 349 case _adapter_opt_collect_2_S2_ref :
350 350 case _adapter_opt_filter_S2_ref : return 2;
351 351 case _adapter_opt_collect_2_S3_ref :
352 352 case _adapter_opt_filter_S3_ref : return 3;
353 353 case _adapter_opt_collect_2_S4_ref :
354 354 case _adapter_opt_filter_S4_ref : return 4;
355 355 case _adapter_opt_collect_2_S5_ref :
356 356 case _adapter_opt_filter_S5_ref : return 5;
357 357 default : return -1; // sentinel value for "variable"
358 358 }
359 359 }
360 360
361 361 static BasicType ek_adapter_opt_collect_type(EntryKind ek) {
362 362 assert(ek >= _adapter_opt_collect_FIRST && ek <= _adapter_opt_collect_LAST ||
363 363 ek >= _adapter_opt_fold_FIRST && ek <= _adapter_opt_fold_LAST, "");
364 364 switch (ek) {
365 365 case _adapter_opt_fold_int :
366 366 case _adapter_opt_collect_int : return T_INT;
367 367 case _adapter_opt_fold_long :
368 368 case _adapter_opt_collect_long : return T_LONG;
369 369 case _adapter_opt_fold_float :
370 370 case _adapter_opt_collect_float : return T_FLOAT;
371 371 case _adapter_opt_fold_double :
372 372 case _adapter_opt_collect_double : return T_DOUBLE;
373 373 case _adapter_opt_fold_void :
374 374 case _adapter_opt_collect_void : return T_VOID;
375 375 default : return T_OBJECT;
376 376 }
377 377 }
378 378
379 379 static int ek_adapter_opt_return_slot(EntryKind ek) {
380 380 assert(ek >= _adapter_opt_return_FIRST && ek <= _adapter_opt_return_LAST, "");
381 381 switch (ek) {
382 382 case _adapter_opt_return_S0_ref : return 0;
383 383 case _adapter_opt_return_S1_ref : return 1;
384 384 case _adapter_opt_return_S2_ref : return 2;
385 385 case _adapter_opt_return_S3_ref : return 3;
386 386 case _adapter_opt_return_S4_ref : return 4;
387 387 case _adapter_opt_return_S5_ref : return 5;
388 388 default : return -1; // sentinel value for "variable"
389 389 }
390 390 }
391 391
392 392 static BasicType ek_adapter_opt_return_type(EntryKind ek) {
393 393 assert(ek >= _adapter_opt_return_FIRST && ek <= _adapter_opt_return_LAST, "");
394 394 switch (ek) {
395 395 case _adapter_opt_return_int : return T_INT;
396 396 case _adapter_opt_return_long : return T_LONG;
397 397 case _adapter_opt_return_float : return T_FLOAT;
398 398 case _adapter_opt_return_double : return T_DOUBLE;
399 399 case _adapter_opt_return_void : return T_VOID;
400 400 case _adapter_opt_return_any : return T_CONFLICT; // sentinel value for "variable"
401 401 default : return T_OBJECT;
402 402 }
403 403 }
404 404
405 405 static int ek_adapter_opt_spread_count(EntryKind ek) {
406 406 assert(ek >= _adapter_opt_spread_FIRST && ek <= _adapter_opt_spread_LAST, "");
407 407 switch (ek) {
408 408 case _adapter_opt_spread_0 : return 0;
409 409 case _adapter_opt_spread_1_ref : return 1;
410 410 case _adapter_opt_spread_2_ref : return 2;
411 411 case _adapter_opt_spread_3_ref : return 3;
412 412 case _adapter_opt_spread_4_ref : return 4;
413 413 case _adapter_opt_spread_5_ref : return 5;
414 414 default : return -1; // sentinel value for "variable"
415 415 }
416 416 }
417 417
418 418 static BasicType ek_adapter_opt_spread_type(EntryKind ek) {
419 419 assert(ek >= _adapter_opt_spread_FIRST && ek <= _adapter_opt_spread_LAST, "");
420 420 switch (ek) {
421 421 // (there is no _adapter_opt_spread_boolean; we use byte)
422 422 case _adapter_opt_spread_byte : return T_BYTE;
423 423 case _adapter_opt_spread_char : return T_CHAR;
424 424 case _adapter_opt_spread_short : return T_SHORT;
425 425 case _adapter_opt_spread_int : return T_INT;
426 426 case _adapter_opt_spread_long : return T_LONG;
427 427 case _adapter_opt_spread_float : return T_FLOAT;
428 428 case _adapter_opt_spread_double : return T_DOUBLE;
429 429 default : return T_OBJECT;
430 430 }
431 431 }
432 432
433 433 static methodOop raise_exception_method() {
434 434 oop rem = JNIHandles::resolve(_raise_exception_method);
435 435 assert(rem == NULL || rem->is_method(), "");
436 436 return (methodOop) rem;
437 437 }
438 438 static void set_raise_exception_method(methodOop rem) {
439 439 assert(_raise_exception_method == NULL, "");
440 440 _raise_exception_method = JNIHandles::make_global(Handle(rem));
441 441 }
442 442
443 443 static jint adapter_conversion(int conv_op, BasicType src, BasicType dest,
444 444 int stack_move = 0, int vminfo = 0) {
445 445 assert(conv_op_valid(conv_op), "oob");
446 446 jint conv = ((conv_op << CONV_OP_SHIFT)
447 447 | (src << CONV_SRC_TYPE_SHIFT)
448 448 | (dest << CONV_DEST_TYPE_SHIFT)
449 449 | (stack_move << CONV_STACK_MOVE_SHIFT)
450 450 | (vminfo << CONV_VMINFO_SHIFT)
451 451 );
452 452 assert(adapter_conversion_op(conv) == conv_op, "decode conv_op");
453 453 assert(adapter_conversion_src_type(conv) == src, "decode src");
454 454 assert(adapter_conversion_dest_type(conv) == dest, "decode dest");
455 455 assert(adapter_conversion_stack_move(conv) == stack_move, "decode stack_move");
456 456 assert(adapter_conversion_vminfo(conv) == vminfo, "decode vminfo");
457 457 return conv;
458 458 }
459 459 static int adapter_conversion_op(jint conv) {
460 460 return ((conv >> CONV_OP_SHIFT) & 0xF);
461 461 }
462 462 static BasicType adapter_conversion_src_type(jint conv) {
463 463 return (BasicType)((conv >> CONV_SRC_TYPE_SHIFT) & 0xF);
464 464 }
465 465 static BasicType adapter_conversion_dest_type(jint conv) {
466 466 return (BasicType)((conv >> CONV_DEST_TYPE_SHIFT) & 0xF);
467 467 }
468 468 static int adapter_conversion_stack_move(jint conv) {
469 469 return (conv >> CONV_STACK_MOVE_SHIFT);
470 470 }
471 471 static int adapter_conversion_vminfo(jint conv) {
472 472 return (conv >> CONV_VMINFO_SHIFT) & CONV_VMINFO_MASK;
473 473 }
474 474
475 475 // Bit mask of conversion_op values. May vary by platform.
476 476 static int adapter_conversion_ops_supported_mask();
477 477
478 478 static bool conv_op_supported(int conv_op) {
479 479 assert(conv_op_valid(conv_op), "");
480 480 return ((adapter_conversion_ops_supported_mask() & nth_bit(conv_op)) != 0);
481 481 }
482 482
483 483 // Offset in words that the interpreter stack pointer moves when an argument is pushed.
484 484 // The stack_move value must always be a multiple of this.
485 485 static int stack_move_unit() {
486 486 return frame::interpreter_frame_expression_stack_direction() * Interpreter::stackElementWords;
487 487 }
488 488
489 489 // Adapter frame traversal. (Implementation-specific.)
490 490 static frame ricochet_frame_sender(const frame& fr, RegisterMap* reg_map);
491 491 static void ricochet_frame_oops_do(const frame& fr, OopClosure* blk, const RegisterMap* reg_map);
492 492
493 493 enum { CONV_VMINFO_SIGN_FLAG = 0x80 };
494 494 // Shift values for prim-to-prim conversions.
495 495 static int adapter_prim_to_prim_subword_vminfo(BasicType dest) {
496 496 if (dest == T_BOOLEAN) return (BitsPerInt - 1); // boolean is 1 bit
497 497 if (dest == T_CHAR) return (BitsPerInt - BitsPerShort);
498 498 if (dest == T_BYTE) return (BitsPerInt - BitsPerByte ) | CONV_VMINFO_SIGN_FLAG;
499 499 if (dest == T_SHORT) return (BitsPerInt - BitsPerShort) | CONV_VMINFO_SIGN_FLAG;
500 500 return 0; // case T_INT
501 501 }
502 502 // Shift values for unboxing a primitive.
503 503 static int adapter_unbox_subword_vminfo(BasicType dest) {
504 504 if (dest == T_BOOLEAN) return (BitsPerInt - BitsPerByte ); // implemented as 1 byte
505 505 if (dest == T_CHAR) return (BitsPerInt - BitsPerShort);
506 506 if (dest == T_BYTE) return (BitsPerInt - BitsPerByte ) | CONV_VMINFO_SIGN_FLAG;
507 507 if (dest == T_SHORT) return (BitsPerInt - BitsPerShort) | CONV_VMINFO_SIGN_FLAG;
508 508 return 0; // case T_INT
509 509 }
510 510 // Here is the transformation the i2i adapter must perform:
511 511 static int truncate_subword_from_vminfo(jint value, int vminfo) {
512 512 jint tem = value << vminfo;
513 513 if ((vminfo & CONV_VMINFO_SIGN_FLAG) != 0) {
514 514 return (jint)tem >> vminfo;
515 515 } else {
516 516 return (juint)tem >> vminfo;
517 517 }
518 518 }
519 519
520 520 static inline address from_compiled_entry(EntryKind ek);
521 521 static inline address from_interpreted_entry(EntryKind ek);
522 522
523 523 // helpers for decode_method.
524 524 static methodOop decode_methodOop(methodOop m, int& decode_flags_result);
525 525 static methodHandle decode_vmtarget(oop vmtarget, int vmindex, oop mtype, KlassHandle& receiver_limit_result, int& decode_flags_result);
526 526 static methodHandle decode_MemberName(oop mname, KlassHandle& receiver_limit_result, int& decode_flags_result);
527 527 static methodHandle decode_MethodHandle(oop mh, KlassHandle& receiver_limit_result, int& decode_flags_result);
528 528 static methodHandle decode_DirectMethodHandle(oop mh, KlassHandle& receiver_limit_result, int& decode_flags_result);
529 529 static methodHandle decode_BoundMethodHandle(oop mh, KlassHandle& receiver_limit_result, int& decode_flags_result);
530 530 static methodHandle decode_AdapterMethodHandle(oop mh, KlassHandle& receiver_limit_result, int& decode_flags_result);
531 531
532 532 // Find out how many stack slots an mh pushes or pops.
533 533 // The result is *not* reported as a multiple of stack_move_unit();
534 534 // It is a signed net number of pushes (a difference in vmslots).
535 535 // To compare with a stack_move value, first multiply by stack_move_unit().
536 536 static int decode_MethodHandle_stack_pushes(oop mh);
537 537
538 538 public:
539 539 // working with member names
540 540 static void resolve_MemberName(Handle mname, TRAPS); // compute vmtarget/vmindex from name/type
541 541 static void expand_MemberName(Handle mname, int suppress, TRAPS); // expand defc/name/type if missing
542 542 static Handle new_MemberName(TRAPS); // must be followed by init_MemberName
543 543 static void init_MemberName(oop mname_oop, oop target); // compute vmtarget/vmindex from target
544 544 static void init_MemberName(oop mname_oop, methodOop m, bool do_dispatch = true);
545 545 static void init_MemberName(oop mname_oop, klassOop field_holder, AccessFlags mods, int offset);
546 546 static int find_MemberNames(klassOop k, Symbol* name, Symbol* sig,
547 547 int mflags, klassOop caller,
548 548 int skip, objArrayOop results);
549 549 // bit values for suppress argument to expand_MemberName:
550 550 enum { _suppress_defc = 1, _suppress_name = 2, _suppress_type = 4 };
551 551
552 552 // Generate MethodHandles adapters.
553 553 static void generate_adapters();
554 554
555 555 // Called from InterpreterGenerator and MethodHandlesAdapterGenerator.
556 556 static address generate_method_handle_interpreter_entry(MacroAssembler* _masm);
557 557 static void generate_method_handle_stub(MacroAssembler* _masm, EntryKind ek);
558 558
559 559 // argument list parsing
560 560 static int argument_slot(oop method_type, int arg);
561 561 static int argument_slot_count(oop method_type) { return argument_slot(method_type, -1); }
562 562 static int argument_slot_to_argnum(oop method_type, int argslot);
563 563
564 564 // Runtime support
565 565 enum { // bit-encoded flags from decode_method or decode_vmref
566 566 _dmf_has_receiver = 0x01, // target method has leading reference argument
567 567 _dmf_does_dispatch = 0x02, // method handle performs virtual or interface dispatch
568 568 _dmf_from_interface = 0x04, // peforms interface dispatch
569 569 _DMF_DIRECT_MASK = (_dmf_from_interface*2 - _dmf_has_receiver),
570 570 _dmf_binds_method = 0x08,
571 571 _dmf_binds_argument = 0x10,
572 572 _DMF_BOUND_MASK = (_dmf_binds_argument*2 - _dmf_binds_method),
573 573 _dmf_adapter_lsb = 0x20,
574 574 _DMF_ADAPTER_MASK = (_dmf_adapter_lsb << CONV_OP_LIMIT) - _dmf_adapter_lsb
575 575 };
576 576 static methodHandle decode_method(oop x, KlassHandle& receiver_limit_result, int& decode_flags_result);
577 577 enum {
578 578 // format of query to getConstant:
579 579 GC_JVM_PUSH_LIMIT = 0,
580 580 GC_JVM_STACK_MOVE_UNIT = 1,
581 581 GC_CONV_OP_IMPLEMENTED_MASK = 2,
582 582
583 583 // format of result from getTarget / encode_target:
584 584 ETF_HANDLE_OR_METHOD_NAME = 0, // all available data (immediate MH or method)
585 585 ETF_DIRECT_HANDLE = 1, // ultimate method handle (will be a DMH, may be self)
586 586 ETF_METHOD_NAME = 2, // ultimate method as MemberName
587 587 ETF_REFLECT_METHOD = 3 // ultimate method as java.lang.reflect object (sans refClass)
588 588 };
589 589 static int get_named_constant(int which, Handle name_box, TRAPS);
590 590 static oop encode_target(Handle mh, int format, TRAPS); // report vmtarget (to Java code)
591 591 static bool class_cast_needed(klassOop src, klassOop dst);
592 592
593 593 static instanceKlassHandle resolve_instance_klass(oop java_mirror_oop, TRAPS);
594 594 static instanceKlassHandle resolve_instance_klass(jclass java_mirror_jh, TRAPS) {
595 595 return resolve_instance_klass(JNIHandles::resolve(java_mirror_jh), THREAD);
596 596 }
597 597
598 598 private:
599 599 // These checkers operate on a pair of whole MethodTypes:
600 600 static const char* check_method_type_change(oop src_mtype, int src_beg, int src_end,
601 601 int insert_argnum, oop insert_type,
602 602 int change_argnum, oop change_type,
603 603 int delete_argnum,
604 604 oop dst_mtype, int dst_beg, int dst_end,
605 605 bool raw = false);
606 606 static const char* check_method_type_insertion(oop src_mtype,
607 607 int insert_argnum, oop insert_type,
608 608 oop dst_mtype) {
609 609 oop no_ref = NULL;
610 610 return check_method_type_change(src_mtype, 0, -1,
611 611 insert_argnum, insert_type,
612 612 -1, no_ref, -1, dst_mtype, 0, -1);
613 613 }
614 614 static const char* check_method_type_conversion(oop src_mtype,
615 615 int change_argnum, oop change_type,
616 616 oop dst_mtype) {
617 617 oop no_ref = NULL;
618 618 return check_method_type_change(src_mtype, 0, -1, -1, no_ref,
619 619 change_argnum, change_type,
620 620 -1, dst_mtype, 0, -1);
621 621 }
622 622 static const char* check_method_type_passthrough(oop src_mtype, oop dst_mtype, bool raw) {
623 623 oop no_ref = NULL;
624 624 return check_method_type_change(src_mtype, 0, -1,
625 625 -1, no_ref, -1, no_ref, -1,
626 626 dst_mtype, 0, -1, raw);
627 627 }
628 628
629 629 // These checkers operate on pairs of argument or return types:
630 630 static const char* check_argument_type_change(BasicType src_type, klassOop src_klass,
631 631 BasicType dst_type, klassOop dst_klass,
632 632 int argnum, bool raw = false);
633 633
634 634 static const char* check_argument_type_change(oop src_type, oop dst_type,
635 635 int argnum, bool raw = false) {
636 636 klassOop src_klass = NULL, dst_klass = NULL;
637 637 BasicType src_bt = java_lang_Class::as_BasicType(src_type, &src_klass);
638 638 BasicType dst_bt = java_lang_Class::as_BasicType(dst_type, &dst_klass);
639 639 return check_argument_type_change(src_bt, src_klass,
640 640 dst_bt, dst_klass, argnum, raw);
641 641 }
642 642
643 643 static const char* check_return_type_change(oop src_type, oop dst_type, bool raw = false) {
644 644 return check_argument_type_change(src_type, dst_type, -1, raw);
645 645 }
646 646
647 647 static const char* check_return_type_change(BasicType src_type, klassOop src_klass,
648 648 BasicType dst_type, klassOop dst_klass) {
649 649 return check_argument_type_change(src_type, src_klass, dst_type, dst_klass, -1);
650 650 }
651 651
652 652 static const char* check_method_receiver(methodOop m, klassOop passed_recv_type);
653 653
654 654 // These verifiers can block, and will throw an error if the checking fails:
655 655 static void verify_vmslots(Handle mh, TRAPS);
656 656 static void verify_vmargslot(Handle mh, int argnum, int argslot, TRAPS);
657 657
658 658 static void verify_method_type(methodHandle m, Handle mtype,
659 659 bool has_bound_oop,
660 660 KlassHandle bound_oop_type,
661 661 TRAPS);
662 662
663 663 static void verify_method_signature(methodHandle m, Handle mtype,
664 664 int first_ptype_pos,
665 665 KlassHandle insert_ptype, TRAPS);
666 666
667 667 static void verify_DirectMethodHandle(Handle mh, methodHandle m, TRAPS);
668 668 static void verify_BoundMethodHandle(Handle mh, Handle target, int argnum,
669 669 bool direct_to_method, TRAPS);
670 670 static void verify_BoundMethodHandle_with_receiver(Handle mh, methodHandle m, TRAPS);
671 671 static void verify_AdapterMethodHandle(Handle mh, int argnum, TRAPS);
672 672
673 673 public:
674 674
675 675 // Fill in the fields of a DirectMethodHandle mh. (MH.type must be pre-filled.)
676 676 static void init_DirectMethodHandle(Handle mh, methodHandle method, bool do_dispatch, TRAPS);
677 677
678 678 // Fill in the fields of a BoundMethodHandle mh. (MH.type, BMH.argument must be pre-filled.)
679 679 static void init_BoundMethodHandle(Handle mh, Handle target, int argnum, TRAPS);
680 680 static void init_BoundMethodHandle_with_receiver(Handle mh,
681 681 methodHandle original_m,
682 682 KlassHandle receiver_limit,
683 683 int decode_flags,
684 684 TRAPS);
685 685
686 686 // Fill in the fields of an AdapterMethodHandle mh. (MH.type must be pre-filled.)
687 687 static void init_AdapterMethodHandle(Handle mh, Handle target, int argnum, TRAPS);
688 688 static void ensure_vmlayout_field(Handle target, TRAPS);
689 689
690 690 #ifdef ASSERT
↓ open down ↓ |
690 lines elided |
↑ open up ↑ |
691 691 static bool spot_check_entry_names();
692 692 #endif
693 693
694 694 private:
695 695 static methodHandle dispatch_decoded_method(methodHandle m,
696 696 KlassHandle receiver_limit,
697 697 int decode_flags,
698 698 KlassHandle receiver_klass,
699 699 TRAPS);
700 700
701 +public:
702 + static bool is_float_fixed_reinterpretation_cast(BasicType src, BasicType dst);
701 703 static bool same_basic_type_for_arguments(BasicType src, BasicType dst,
702 704 bool raw = false,
703 705 bool for_return = false);
704 706 static bool same_basic_type_for_returns(BasicType src, BasicType dst, bool raw = false) {
705 707 return same_basic_type_for_arguments(src, dst, raw, true);
706 708 }
707 709
708 710 static Symbol* convert_to_signature(oop type_str, bool polymorphic, TRAPS);
709 711
710 712 #ifdef TARGET_ARCH_x86
711 713 # include "methodHandles_x86.hpp"
712 714 #endif
713 715 #ifdef TARGET_ARCH_sparc
714 716 #define TARGET_ARCH_NYI_6939861 1 //FIXME
715 717 //# include "methodHandles_sparc.hpp"
716 718 #endif
717 719 #ifdef TARGET_ARCH_zero
718 720 #define TARGET_ARCH_NYI_6939861 1 //FIXME
719 721 //# include "methodHandles_zero.hpp"
720 722 #endif
721 723 #ifdef TARGET_ARCH_arm
722 724 #define TARGET_ARCH_NYI_6939861 1 //FIXME
723 725 //# include "methodHandles_arm.hpp"
724 726 #endif
725 727 #ifdef TARGET_ARCH_ppc
726 728 #define TARGET_ARCH_NYI_6939861 1 //FIXME
727 729 //# include "methodHandles_ppc.hpp"
728 730 #endif
729 731
730 732 #ifdef TARGET_ARCH_NYI_6939861
731 733 // Here are some backward compatible declarations until the 6939861 ports are updated.
732 734 #define _adapter_flyby (_EK_LIMIT + 10)
733 735 #define _adapter_ricochet (_EK_LIMIT + 11)
734 736 #define _adapter_opt_spread_1 _adapter_opt_spread_1_ref
735 737 #define _adapter_opt_spread_more _adapter_opt_spread_ref
736 738 enum {
737 739 _INSERT_NO_MASK = -1,
738 740 _INSERT_REF_MASK = 0,
739 741 _INSERT_INT_MASK = 1,
740 742 _INSERT_LONG_MASK = 3
741 743 };
742 744 static void get_ek_bound_mh_info(EntryKind ek, BasicType& arg_type, int& arg_mask, int& arg_slots) {
743 745 arg_type = ek_bound_mh_arg_type(ek);
744 746 arg_mask = 0;
745 747 arg_slots = type2size[arg_type];;
746 748 }
747 749 static void get_ek_adapter_opt_swap_rot_info(EntryKind ek, int& swap_bytes, int& rotate) {
748 750 int swap_slots = ek_adapter_opt_swap_slots(ek);
749 751 rotate = ek_adapter_opt_swap_mode(ek);
750 752 swap_bytes = swap_slots * Interpreter::stackElementSize;
751 753 }
752 754 static int get_ek_adapter_opt_spread_info(EntryKind ek) {
753 755 return ek_adapter_opt_spread_count(ek);
754 756 }
755 757
756 758 static void insert_arg_slots(MacroAssembler* _masm,
757 759 RegisterOrConstant arg_slots,
758 760 int arg_mask,
759 761 Register argslot_reg,
760 762 Register temp_reg, Register temp2_reg, Register temp3_reg = noreg);
761 763
762 764 static void remove_arg_slots(MacroAssembler* _masm,
763 765 RegisterOrConstant arg_slots,
764 766 Register argslot_reg,
765 767 Register temp_reg, Register temp2_reg, Register temp3_reg = noreg);
766 768
767 769 static void trace_method_handle(MacroAssembler* _masm, const char* adaptername) PRODUCT_RETURN;
768 770 #endif //TARGET_ARCH_NYI_6939861
769 771 };
770 772
771 773
772 774 // Access methods for the "entry" field of a java.lang.invoke.MethodHandle.
773 775 // The field is primarily a jump target for compiled calls.
774 776 // However, we squirrel away some nice pointers for other uses,
775 777 // just before the jump target.
776 778 // Aspects of a method handle entry:
777 779 // - from_compiled_entry - stub used when compiled code calls the MH
778 780 // - from_interpreted_entry - stub used when the interpreter calls the MH
779 781 // - type_checking_entry - stub for runtime casting between MHForm siblings (NYI)
780 782 class MethodHandleEntry {
781 783 public:
782 784 class Data {
783 785 friend class MethodHandleEntry;
784 786 size_t _total_size; // size including Data and code stub
785 787 MethodHandleEntry* _type_checking_entry;
786 788 address _from_interpreted_entry;
787 789 MethodHandleEntry* method_entry() { return (MethodHandleEntry*)(this + 1); }
788 790 };
789 791
790 792 Data* data() { return (Data*)this - 1; }
791 793
792 794 address start_address() { return (address) data(); }
793 795 address end_address() { return start_address() + data()->_total_size; }
794 796
795 797 address from_compiled_entry() { return (address) this; }
796 798
797 799 address from_interpreted_entry() { return data()->_from_interpreted_entry; }
798 800 void set_from_interpreted_entry(address e) { data()->_from_interpreted_entry = e; }
799 801
800 802 MethodHandleEntry* type_checking_entry() { return data()->_type_checking_entry; }
801 803 void set_type_checking_entry(MethodHandleEntry* e) { data()->_type_checking_entry = e; }
802 804
803 805 void set_end_address(address end_addr) {
804 806 size_t total_size = end_addr - start_address();
805 807 assert(total_size > 0 && total_size < 0x1000, "reasonable end address");
806 808 data()->_total_size = total_size;
807 809 }
808 810
809 811 // Compiler support:
810 812 static int from_interpreted_entry_offset_in_bytes() {
811 813 return (int)( offset_of(Data, _from_interpreted_entry) - sizeof(Data) );
812 814 }
813 815 static int type_checking_entry_offset_in_bytes() {
814 816 return (int)( offset_of(Data, _from_interpreted_entry) - sizeof(Data) );
815 817 }
816 818
817 819 static address start_compiled_entry(MacroAssembler* _masm,
818 820 address interpreted_entry = NULL);
819 821 static MethodHandleEntry* finish_compiled_entry(MacroAssembler* masm, address start_addr);
820 822 };
821 823
822 824 address MethodHandles::from_compiled_entry(EntryKind ek) { return entry(ek)->from_compiled_entry(); }
823 825 address MethodHandles::from_interpreted_entry(EntryKind ek) { return entry(ek)->from_interpreted_entry(); }
824 826
825 827
826 828 //------------------------------------------------------------------------------
827 829 // MethodHandlesAdapterGenerator
828 830 //
829 831 class MethodHandlesAdapterGenerator : public StubCodeGenerator {
830 832 public:
831 833 MethodHandlesAdapterGenerator(CodeBuffer* code) : StubCodeGenerator(code) {}
832 834
833 835 void generate();
834 836 };
835 837
836 838 #endif // SHARE_VM_PRIMS_METHODHANDLES_HPP
↓ open down ↓ |
126 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX