Print this page
rev 1022 : 6829192: JSR 292 needs to support 64-bit x86
Summary: changes for method handles and invokedynamic
Reviewed-by: ?, ?
Split |
Close |
Expand all |
Collapse all |
--- old/src/cpu/x86/vm/methodHandles_x86.cpp
+++ new/src/cpu/x86/vm/methodHandles_x86.cpp
1 1 /*
2 2 * Copyright 1997-2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 21 * have any questions.
22 22 *
23 23 */
24 24
25 25 #include "incls/_precompiled.incl"
26 26 #include "incls/_methodHandles_x86.cpp.incl"
27 27
28 28 #define __ _masm->
29 29
30 30 address MethodHandleEntry::start_compiled_entry(MacroAssembler* _masm,
31 31 address interpreted_entry) {
32 32 // Just before the actual machine code entry point, allocate space
33 33 // for a MethodHandleEntry::Data record, so that we can manage everything
34 34 // from one base pointer.
35 35 __ align(wordSize);
36 36 address target = __ pc() + sizeof(Data);
37 37 while (__ pc() < target) {
38 38 __ nop();
39 39 __ align(wordSize);
40 40 }
41 41
42 42 MethodHandleEntry* me = (MethodHandleEntry*) __ pc();
43 43 me->set_end_address(__ pc()); // set a temporary end_address
44 44 me->set_from_interpreted_entry(interpreted_entry);
45 45 me->set_type_checking_entry(NULL);
46 46
47 47 return (address) me;
48 48 }
49 49
50 50 MethodHandleEntry* MethodHandleEntry::finish_compiled_entry(MacroAssembler* _masm,
51 51 address start_addr) {
52 52 MethodHandleEntry* me = (MethodHandleEntry*) start_addr;
53 53 assert(me->end_address() == start_addr, "valid ME");
54 54
55 55 // Fill in the real end_address:
56 56 __ align(wordSize);
57 57 me->set_end_address(__ pc());
58 58
59 59 return me;
60 60 }
61 61
62 62 #ifdef ASSERT
63 63 static void verify_argslot(MacroAssembler* _masm, Register rax_argslot,
64 64 const char* error_message) {
65 65 // Verify that argslot lies within (rsp, rbp].
66 66 Label L_ok, L_bad;
67 67 __ cmpptr(rax_argslot, rbp);
68 68 __ jcc(Assembler::above, L_bad);
69 69 __ cmpptr(rsp, rax_argslot);
70 70 __ jcc(Assembler::below, L_ok);
71 71 __ bind(L_bad);
72 72 __ stop(error_message);
73 73 __ bind(L_ok);
74 74 }
75 75 #endif
76 76
77 77
78 78 // Code generation
79 79 address MethodHandles::generate_method_handle_interpreter_entry(MacroAssembler* _masm) {
80 80 // rbx: methodOop
81 81 // rcx: receiver method handle (must load from sp[MethodTypeForm.vmslots])
82 82 // rsi/r13: sender SP (must preserve; see prepare_to_jump_from_interpreted)
83 83 // rdx: garbage temp, blown away
84 84
85 85 Register rbx_method = rbx;
86 86 Register rcx_recv = rcx;
87 87 Register rax_mtype = rax;
88 88 Register rdx_temp = rdx;
89 89
90 90 // emit WrongMethodType path first, to enable jccb back-branch from main path
91 91 Label wrong_method_type;
92 92 __ bind(wrong_method_type);
93 93 __ push(rax_mtype); // required mtype
94 94 __ push(rcx_recv); // bad mh (1st stacked argument)
95 95 __ jump(ExternalAddress(Interpreter::throw_WrongMethodType_entry()));
96 96
97 97 // here's where control starts out:
98 98 __ align(CodeEntryAlignment);
99 99 address entry_point = __ pc();
100 100
101 101 // fetch the MethodType from the method handle into rax (the 'check' register)
102 102 {
103 103 Register tem = rbx_method;
104 104 for (jint* pchase = methodOopDesc::method_type_offsets_chain(); (*pchase) != -1; pchase++) {
105 105 __ movptr(rax_mtype, Address(tem, *pchase));
106 106 tem = rax_mtype; // in case there is another indirection
107 107 }
108 108 }
109 109 Register rbx_temp = rbx_method; // done with incoming methodOop
110 110
111 111 // given the MethodType, find out where the MH argument is buried
112 112 __ movptr(rdx_temp, Address(rax_mtype,
113 113 __ delayed_value(java_dyn_MethodType::form_offset_in_bytes, rbx_temp)));
114 114 __ movl(rdx_temp, Address(rdx_temp,
115 115 __ delayed_value(java_dyn_MethodTypeForm::vmslots_offset_in_bytes, rbx_temp)));
116 116 __ movptr(rcx_recv, __ argument_address(rdx_temp));
117 117
118 118 __ check_method_handle_type(rax_mtype, rcx_recv, rdx_temp, wrong_method_type);
119 119 __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
120 120
121 121 return entry_point;
122 122 }
123 123
124 124 // Helper to insert argument slots into the stack.
125 125 // arg_slots must be a multiple of stack_move_unit() and <= 0
126 126 void MethodHandles::insert_arg_slots(MacroAssembler* _masm,
127 127 RegisterOrConstant arg_slots,
128 128 int arg_mask,
129 129 Register rax_argslot,
130 130 Register rbx_temp, Register rdx_temp) {
131 131 assert_different_registers(rax_argslot, rbx_temp, rdx_temp,
132 132 (!arg_slots.is_register() ? rsp : arg_slots.as_register()));
133 133
134 134 #ifdef ASSERT
135 135 verify_argslot(_masm, rax_argslot, "insertion point must fall within current frame");
136 136 if (arg_slots.is_register()) {
137 137 Label L_ok, L_bad;
138 138 __ cmpptr(arg_slots.as_register(), (int32_t) NULL_WORD);
139 139 __ jcc(Assembler::greater, L_bad);
140 140 __ testl(arg_slots.as_register(), -stack_move_unit() - 1);
141 141 __ jcc(Assembler::zero, L_ok);
142 142 __ bind(L_bad);
143 143 __ stop("assert arg_slots <= 0 and clear low bits");
144 144 __ bind(L_ok);
145 145 } else {
146 146 assert(arg_slots.as_constant() <= 0, "");
147 147 assert(arg_slots.as_constant() % -stack_move_unit() == 0, "");
148 148 }
149 149 #endif //ASSERT
150 150
151 151 #ifdef _LP64
152 152 if (arg_slots.is_register()) {
153 153 // clean high bits of stack motion register (was loaded as an int)
154 154 __ movslq(arg_slots.as_register(), arg_slots.as_register());
155 155 }
156 156 #endif
157 157
158 158 // Make space on the stack for the inserted argument(s).
159 159 // Then pull down everything shallower than rax_argslot.
160 160 // The stacked return address gets pulled down with everything else.
161 161 // That is, copy [rsp, argslot) downward by -size words. In pseudo-code:
162 162 // rsp -= size;
163 163 // for (rdx = rsp + size; rdx < argslot; rdx++)
164 164 // rdx[-size] = rdx[0]
165 165 // argslot -= size;
166 166 __ mov(rdx_temp, rsp); // source pointer for copy
167 167 __ lea(rsp, Address(rsp, arg_slots, Address::times_ptr));
168 168 {
169 169 Label loop;
170 170 __ bind(loop);
171 171 // pull one word down each time through the loop
172 172 __ movptr(rbx_temp, Address(rdx_temp, 0));
173 173 __ movptr(Address(rdx_temp, arg_slots, Address::times_ptr), rbx_temp);
174 174 __ addptr(rdx_temp, wordSize);
175 175 __ cmpptr(rdx_temp, rax_argslot);
176 176 __ jcc(Assembler::less, loop);
177 177 }
178 178
179 179 // Now move the argslot down, to point to the opened-up space.
180 180 __ lea(rax_argslot, Address(rax_argslot, arg_slots, Address::times_ptr));
181 181
182 182 if (TaggedStackInterpreter && arg_mask != _INSERT_NO_MASK) {
183 183 // The caller has specified a bitmask of tags to put into the opened space.
184 184 // This only works when the arg_slots value is an assembly-time constant.
185 185 int constant_arg_slots = arg_slots.as_constant() / stack_move_unit();
186 186 int tag_offset = Interpreter::tag_offset_in_bytes() - Interpreter::value_offset_in_bytes();
187 187 for (int slot = 0; slot < constant_arg_slots; slot++) {
188 188 BasicType slot_type = ((arg_mask & (1 << slot)) == 0 ? T_OBJECT : T_INT);
189 189 int slot_offset = Interpreter::stackElementSize() * slot;
190 190 Address tag_addr(rax_argslot, slot_offset + tag_offset);
191 191 __ movptr(tag_addr, frame::tag_for_basic_type(slot_type));
192 192 }
193 193 // Note that the new argument slots are tagged properly but contain
194 194 // garbage at this point. The value portions must be initialized
195 195 // by the caller. (Especially references!)
196 196 }
197 197 }
198 198
199 199 // Helper to remove argument slots from the stack.
200 200 // arg_slots must be a multiple of stack_move_unit() and >= 0
201 201 void MethodHandles::remove_arg_slots(MacroAssembler* _masm,
202 202 RegisterOrConstant arg_slots,
203 203 Register rax_argslot,
204 204 Register rbx_temp, Register rdx_temp) {
205 205 assert_different_registers(rax_argslot, rbx_temp, rdx_temp,
206 206 (!arg_slots.is_register() ? rsp : arg_slots.as_register()));
207 207
208 208 #ifdef ASSERT
209 209 {
210 210 // Verify that [argslot..argslot+size) lies within (rsp, rbp).
211 211 Label L_ok, L_bad;
212 212 __ lea(rbx_temp, Address(rax_argslot, arg_slots, Address::times_ptr));
213 213 __ cmpptr(rbx_temp, rbp);
214 214 __ jcc(Assembler::above, L_bad);
215 215 __ cmpptr(rsp, rax_argslot);
216 216 __ jcc(Assembler::below, L_ok);
217 217 __ bind(L_bad);
218 218 __ stop("deleted argument(s) must fall within current frame");
219 219 __ bind(L_ok);
220 220 }
221 221 if (arg_slots.is_register()) {
222 222 Label L_ok, L_bad;
223 223 __ cmpptr(arg_slots.as_register(), (int32_t) NULL_WORD);
224 224 __ jcc(Assembler::less, L_bad);
225 225 __ testl(arg_slots.as_register(), -stack_move_unit() - 1);
226 226 __ jcc(Assembler::zero, L_ok);
227 227 __ bind(L_bad);
228 228 __ stop("assert arg_slots >= 0 and clear low bits");
229 229 __ bind(L_ok);
230 230 } else {
231 231 assert(arg_slots.as_constant() >= 0, "");
232 232 assert(arg_slots.as_constant() % -stack_move_unit() == 0, "");
233 233 }
234 234 #endif //ASSERT
235 235
236 236 #ifdef _LP64
237 237 if (false) { // not needed, since register is positive
238 238 // clean high bits of stack motion register (was loaded as an int)
239 239 if (arg_slots.is_register())
240 240 __ movslq(arg_slots.as_register(), arg_slots.as_register());
241 241 }
242 242 #endif
243 243
244 244 // Pull up everything shallower than rax_argslot.
245 245 // Then remove the excess space on the stack.
246 246 // The stacked return address gets pulled up with everything else.
247 247 // That is, copy [rsp, argslot) upward by size words. In pseudo-code:
248 248 // for (rdx = argslot-1; rdx >= rsp; --rdx)
249 249 // rdx[size] = rdx[0]
250 250 // argslot += size;
251 251 // rsp += size;
252 252 __ lea(rdx_temp, Address(rax_argslot, -wordSize)); // source pointer for copy
253 253 {
254 254 Label loop;
255 255 __ bind(loop);
256 256 // pull one word up each time through the loop
257 257 __ movptr(rbx_temp, Address(rdx_temp, 0));
258 258 __ movptr(Address(rdx_temp, arg_slots, Address::times_ptr), rbx_temp);
259 259 __ addptr(rdx_temp, -wordSize);
260 260 __ cmpptr(rdx_temp, rsp);
261 261 __ jcc(Assembler::greaterEqual, loop);
262 262 }
263 263
264 264 // Now move the argslot up, to point to the just-copied block.
265 265 __ lea(rsp, Address(rsp, arg_slots, Address::times_ptr));
266 266 // And adjust the argslot address to point at the deletion point.
267 267 __ lea(rax_argslot, Address(rax_argslot, arg_slots, Address::times_ptr));
268 268 }
269 269
270 270 #ifndef PRODUCT
271 271 void trace_method_handle_stub(const char* adaptername,
272 272 oopDesc* mh,
273 273 intptr_t* entry_sp,
274 274 intptr_t* saved_sp,
275 275 intptr_t* saved_bp) {
276 276 // called as a leaf from native code: do not block the JVM!
277 277 intptr_t* last_sp = (intptr_t*) saved_bp[frame::interpreter_frame_last_sp_offset];
278 278 intptr_t* base_sp = (intptr_t*) saved_bp[frame::interpreter_frame_monitor_block_top_offset];
279 279 printf("MH %s mh="INTPTR_FORMAT" sp=("INTPTR_FORMAT"+"INTX_FORMAT") stack_size="INTX_FORMAT" bp="INTPTR_FORMAT"\n",
280 280 adaptername, (intptr_t)mh, (intptr_t)entry_sp, (intptr_t)(saved_sp - entry_sp), (intptr_t)(base_sp - last_sp), (intptr_t)saved_bp);
281 281 if (last_sp != saved_sp)
282 282 printf("*** last_sp="INTPTR_FORMAT"\n", (intptr_t)last_sp);
283 283 }
284 284 #endif //PRODUCT
285 285
286 286 // Generate an "entry" field for a method handle.
287 287 // This determines how the method handle will respond to calls.
288 288 void MethodHandles::generate_method_handle_stub(MacroAssembler* _masm, MethodHandles::EntryKind ek) {
289 289 // Here is the register state during an interpreted call,
290 290 // as set up by generate_method_handle_interpreter_entry():
291 291 // - rbx: garbage temp (was MethodHandle.invoke methodOop, unused)
292 292 // - rcx: receiver method handle
293 293 // - rax: method handle type (only used by the check_mtype entry point)
294 294 // - rsi/r13: sender SP (must preserve; see prepare_to_jump_from_interpreted)
295 295 // - rdx: garbage temp, can blow away
296 296
297 297 Register rcx_recv = rcx;
298 298 Register rax_argslot = rax;
299 299 Register rbx_temp = rbx;
300 300 Register rdx_temp = rdx;
301 301
302 302 // This guy is set up by prepare_to_jump_from_interpreted (from interpreted calls)
303 303 // and gen_c2i_adapter (from compiled calls):
304 304 Register saved_last_sp = LP64_ONLY(r13) NOT_LP64(rsi);
305 305
306 306 guarantee(java_dyn_MethodHandle::vmentry_offset_in_bytes() != 0, "must have offsets");
307 307
308 308 // some handy addresses
309 309 Address rbx_method_fie( rbx, methodOopDesc::from_interpreted_offset() );
310 310
311 311 Address rcx_mh_vmtarget( rcx_recv, java_dyn_MethodHandle::vmtarget_offset_in_bytes() );
312 312 Address rcx_dmh_vmindex( rcx_recv, sun_dyn_DirectMethodHandle::vmindex_offset_in_bytes() );
313 313
314 314 Address rcx_bmh_vmargslot( rcx_recv, sun_dyn_BoundMethodHandle::vmargslot_offset_in_bytes() );
315 315 Address rcx_bmh_argument( rcx_recv, sun_dyn_BoundMethodHandle::argument_offset_in_bytes() );
316 316
317 317 Address rcx_amh_vmargslot( rcx_recv, sun_dyn_AdapterMethodHandle::vmargslot_offset_in_bytes() );
318 318 Address rcx_amh_argument( rcx_recv, sun_dyn_AdapterMethodHandle::argument_offset_in_bytes() );
319 319 Address rcx_amh_conversion( rcx_recv, sun_dyn_AdapterMethodHandle::conversion_offset_in_bytes() );
320 320 Address vmarg; // __ argument_address(vmargslot)
321 321
322 322 int tag_offset = -1;
323 323 if (TaggedStackInterpreter) {
324 324 tag_offset = Interpreter::tag_offset_in_bytes() - Interpreter::value_offset_in_bytes();
325 325 assert(tag_offset = wordSize, "stack grows as expected");
326 326 }
327 327
328 328 const int java_mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes();
329 329
330 330 if (have_entry(ek)) {
331 331 __ nop(); // empty stubs make SG sick
332 332 return;
333 333 }
334 334
335 335 address interp_entry = __ pc();
336 336 if (UseCompressedOops) __ unimplemented("UseCompressedOops");
337 337
338 338 #ifndef PRODUCT
339 339 if (TraceMethodHandles) {
340 340 __ push(rax); __ push(rbx); __ push(rcx); __ push(rdx); __ push(rsi); __ push(rdi);
341 341 __ lea(rax, Address(rsp, wordSize*6)); // entry_sp
342 342 // arguments:
343 343 __ push(rbp); // interpreter frame pointer
344 344 __ push(rsi); // saved_sp
345 345 __ push(rax); // entry_sp
346 346 __ push(rcx); // mh
347 347 __ push(rcx);
348 348 __ movptr(Address(rsp, 0), (intptr_t)entry_name(ek));
349 349 __ call_VM_leaf(CAST_FROM_FN_PTR(address, trace_method_handle_stub), 5);
350 350 __ pop(rdi); __ pop(rsi); __ pop(rdx); __ pop(rcx); __ pop(rbx); __ pop(rax);
351 351 }
352 352 #endif //PRODUCT
353 353
354 354 switch ((int) ek) {
355 355 case _raise_exception:
356 356 {
357 357 // Not a real MH entry, but rather shared code for raising an exception.
358 358 // Extra local arguments are pushed on stack, as required type at TOS+8,
359 359 // failing object (or NULL) at TOS+4, failing bytecode type at TOS.
360 360 // Beyond those local arguments are the PC, of course.
361 361 Register rdx_code = rdx_temp;
362 362 Register rcx_fail = rcx_recv;
363 363 Register rax_want = rax_argslot;
364 364 Register rdi_pc = rdi;
365 365 __ pop(rdx_code); // TOS+0
366 366 __ pop(rcx_fail); // TOS+4
367 367 __ pop(rax_want); // TOS+8
368 368 __ pop(rdi_pc); // caller PC
369 369
370 370 __ mov(rsp, rsi); // cut the stack back to where the caller started
371 371
372 372 // Repush the arguments as if coming from the interpreter.
373 373 if (TaggedStackInterpreter) __ push(frame::tag_for_basic_type(T_INT));
374 374 __ push(rdx_code);
375 375 if (TaggedStackInterpreter) __ push(frame::tag_for_basic_type(T_OBJECT));
376 376 __ push(rcx_fail);
377 377 if (TaggedStackInterpreter) __ push(frame::tag_for_basic_type(T_OBJECT));
378 378 __ push(rax_want);
379 379
380 380 Register rbx_method = rbx_temp;
381 381 Label no_method;
382 382 // FIXME: fill in _raise_exception_method with a suitable sun.dyn method
383 383 __ movptr(rbx_method, ExternalAddress((address) &_raise_exception_method));
384 384 __ testptr(rbx_method, rbx_method);
385 385 __ jcc(Assembler::zero, no_method);
386 386 int jobject_oop_offset = 0;
387 387 __ movptr(rbx_method, Address(rbx_method, jobject_oop_offset)); // dereference the jobject
388 388 __ testptr(rbx_method, rbx_method);
389 389 __ jcc(Assembler::zero, no_method);
390 390 __ verify_oop(rbx_method);
391 391 __ push(rdi_pc); // and restore caller PC
392 392 __ jmp(rbx_method_fie);
393 393
394 394 // If we get here, the Java runtime did not do its job of creating the exception.
395 395 // Do something that is at least causes a valid throw from the interpreter.
396 396 __ bind(no_method);
397 397 __ pop(rax_want);
398 398 if (TaggedStackInterpreter) __ pop(rcx_fail);
399 399 __ pop(rcx_fail);
400 400 __ push(rax_want);
401 401 __ push(rcx_fail);
402 402 __ jump(ExternalAddress(Interpreter::throw_WrongMethodType_entry()));
403 403 }
404 404 break;
405 405
406 406 case _invokestatic_mh:
407 407 case _invokespecial_mh:
408 408 {
409 409 Register rbx_method = rbx_temp;
410 410 __ movptr(rbx_method, rcx_mh_vmtarget); // target is a methodOop
411 411 __ verify_oop(rbx_method);
412 412 // same as TemplateTable::invokestatic or invokespecial,
413 413 // minus the CP setup and profiling:
414 414 if (ek == _invokespecial_mh) {
415 415 // Must load & check the first argument before entering the target method.
416 416 __ load_method_handle_vmslots(rax_argslot, rcx_recv, rdx_temp);
417 417 __ movptr(rcx_recv, __ argument_address(rax_argslot, -1));
418 418 __ null_check(rcx_recv);
419 419 __ verify_oop(rcx_recv);
420 420 }
421 421 __ jmp(rbx_method_fie);
422 422 }
423 423 break;
424 424
425 425 case _invokevirtual_mh:
426 426 {
427 427 // same as TemplateTable::invokevirtual,
428 428 // minus the CP setup and profiling:
429 429
430 430 // pick out the vtable index and receiver offset from the MH,
431 431 // and then we can discard it:
432 432 __ load_method_handle_vmslots(rax_argslot, rcx_recv, rdx_temp);
433 433 Register rbx_index = rbx_temp;
434 434 __ movl(rbx_index, rcx_dmh_vmindex);
435 435 // Note: The verifier allows us to ignore rcx_mh_vmtarget.
436 436 __ movptr(rcx_recv, __ argument_address(rax_argslot, -1));
437 437 __ null_check(rcx_recv, oopDesc::klass_offset_in_bytes());
438 438
439 439 // get receiver klass
440 440 Register rax_klass = rax_argslot;
↓ open down ↓ |
440 lines elided |
↑ open up ↑ |
441 441 __ load_klass(rax_klass, rcx_recv);
442 442 __ verify_oop(rax_klass);
443 443
444 444 // get target methodOop & entry point
445 445 const int base = instanceKlass::vtable_start_offset() * wordSize;
446 446 assert(vtableEntry::size() * wordSize == wordSize, "adjust the scaling in the code below");
447 447 Address vtable_entry_addr(rax_klass,
448 448 rbx_index, Address::times_ptr,
449 449 base + vtableEntry::method_offset_in_bytes());
450 450 Register rbx_method = rbx_temp;
451 - __ movl(rbx_method, vtable_entry_addr);
451 + __ movptr(rbx_method, vtable_entry_addr);
452 452
453 453 __ verify_oop(rbx_method);
454 454 __ jmp(rbx_method_fie);
455 455 }
456 456 break;
457 457
458 458 case _invokeinterface_mh:
459 459 {
460 460 // same as TemplateTable::invokeinterface,
461 461 // minus the CP setup and profiling:
462 462
463 463 // pick out the interface and itable index from the MH.
464 464 __ load_method_handle_vmslots(rax_argslot, rcx_recv, rdx_temp);
465 465 Register rdx_intf = rdx_temp;
466 466 Register rbx_index = rbx_temp;
467 467 __ movptr(rdx_intf, rcx_mh_vmtarget);
468 468 __ movl(rbx_index, rcx_dmh_vmindex);
469 469 __ movptr(rcx_recv, __ argument_address(rax_argslot, -1));
470 470 __ null_check(rcx_recv, oopDesc::klass_offset_in_bytes());
471 471
472 472 // get receiver klass
473 473 Register rax_klass = rax_argslot;
474 474 __ load_klass(rax_klass, rcx_recv);
475 475 __ verify_oop(rax_klass);
476 476
477 477 Register rdi_temp = rdi;
478 478 Register rbx_method = rbx_index;
479 479
480 480 // get interface klass
481 481 Label no_such_interface;
482 482 __ verify_oop(rdx_intf);
483 483 __ lookup_interface_method(rax_klass, rdx_intf,
484 484 // note: next two args must be the same:
485 485 rbx_index, rbx_method,
486 486 rdi_temp,
487 487 no_such_interface);
488 488
489 489 __ verify_oop(rbx_method);
490 490 __ jmp(rbx_method_fie);
491 491 __ hlt();
492 492
493 493 __ bind(no_such_interface);
494 494 // Throw an exception.
495 495 // For historical reasons, it will be IncompatibleClassChangeError.
496 496 __ pushptr(Address(rdx_intf, java_mirror_offset)); // required interface
497 497 __ push(rcx_recv); // bad receiver
498 498 __ push((int)Bytecodes::_invokeinterface); // who is complaining?
499 499 __ jump(ExternalAddress(from_interpreted_entry(_raise_exception)));
500 500 }
501 501 break;
502 502
503 503 case _bound_ref_mh:
504 504 case _bound_int_mh:
505 505 case _bound_long_mh:
506 506 case _bound_ref_direct_mh:
507 507 case _bound_int_direct_mh:
508 508 case _bound_long_direct_mh:
509 509 {
510 510 bool direct_to_method = (ek >= _bound_ref_direct_mh);
511 511 BasicType arg_type = T_ILLEGAL;
512 512 if (ek == _bound_long_mh || ek == _bound_long_direct_mh) {
513 513 arg_type = T_LONG;
514 514 } else if (ek == _bound_int_mh || ek == _bound_int_direct_mh) {
515 515 arg_type = T_INT;
516 516 } else {
517 517 assert(ek == _bound_ref_mh || ek == _bound_ref_direct_mh, "must be ref");
518 518 arg_type = T_OBJECT;
519 519 }
520 520 int arg_slots = type2size[arg_type];
521 521 int arg_mask = (arg_type == T_OBJECT ? _INSERT_REF_MASK :
522 522 arg_slots == 1 ? _INSERT_INT_MASK : _INSERT_LONG_MASK);
523 523
524 524 // make room for the new argument:
525 525 __ movl(rax_argslot, rcx_bmh_vmargslot);
526 526 __ lea(rax_argslot, __ argument_address(rax_argslot));
527 527 insert_arg_slots(_masm, arg_slots * stack_move_unit(), arg_mask,
528 528 rax_argslot, rbx_temp, rdx_temp);
529 529
530 530 // store bound argument into the new stack slot:
531 531 __ movptr(rbx_temp, rcx_bmh_argument);
532 532 Address prim_value_addr(rbx_temp, java_lang_boxing_object::value_offset_in_bytes(arg_type));
533 533 if (arg_type == T_OBJECT) {
534 534 __ movptr(Address(rax_argslot, 0), rbx_temp);
535 535 } else {
536 536 __ load_sized_value(rbx_temp, prim_value_addr,
537 537 type2aelembytes(arg_type), is_signed_subword_type(arg_type));
538 538 __ movptr(Address(rax_argslot, 0), rbx_temp);
539 539 #ifndef _LP64
540 540 if (arg_slots == 2) {
541 541 __ movl(rbx_temp, prim_value_addr.plus_disp(wordSize));
542 542 __ movl(Address(rax_argslot, Interpreter::stackElementSize()), rbx_temp);
543 543 }
544 544 #endif //_LP64
545 545 break;
546 546 }
547 547
548 548 if (direct_to_method) {
549 549 Register rbx_method = rbx_temp;
550 550 __ movptr(rbx_method, rcx_mh_vmtarget);
551 551 __ verify_oop(rbx_method);
552 552 __ jmp(rbx_method_fie);
553 553 } else {
554 554 __ movptr(rcx_recv, rcx_mh_vmtarget);
555 555 __ verify_oop(rcx_recv);
556 556 __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
557 557 }
558 558 }
559 559 break;
560 560
561 561 case _adapter_retype_only:
562 562 case _adapter_retype_raw:
563 563 // immediately jump to the next MH layer:
564 564 __ movptr(rcx_recv, rcx_mh_vmtarget);
565 565 __ verify_oop(rcx_recv);
566 566 __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
567 567 // This is OK when all parameter types widen.
568 568 // It is also OK when a return type narrows.
569 569 break;
570 570
571 571 case _adapter_check_cast:
572 572 {
573 573 // temps:
574 574 Register rbx_klass = rbx_temp; // interesting AMH data
575 575
576 576 // check a reference argument before jumping to the next layer of MH:
577 577 __ movl(rax_argslot, rcx_amh_vmargslot);
578 578 vmarg = __ argument_address(rax_argslot);
579 579
580 580 // What class are we casting to?
581 581 __ movptr(rbx_klass, rcx_amh_argument); // this is a Class object!
582 582 __ movptr(rbx_klass, Address(rbx_klass, java_lang_Class::klass_offset_in_bytes()));
583 583
584 584 Label done;
585 585 __ movptr(rdx_temp, vmarg);
586 586 __ testl(rdx_temp, rdx_temp);
587 587 __ jcc(Assembler::zero, done); // no cast if null
588 588 __ load_klass(rdx_temp, rdx_temp);
589 589
590 590 // live at this point:
591 591 // - rbx_klass: klass required by the target method
592 592 // - rdx_temp: argument klass to test
593 593 // - rcx_recv: adapter method handle
594 594 __ check_klass_subtype(rdx_temp, rbx_klass, rax_argslot, done);
595 595
596 596 // If we get here, the type check failed!
597 597 // Call the wrong_method_type stub, passing the failing argument type in rax.
598 598 Register rax_mtype = rax_argslot;
599 599 __ movl(rax_argslot, rcx_amh_vmargslot); // reload argslot field
600 600 __ movptr(rdx_temp, vmarg);
601 601
602 602 __ pushptr(rcx_amh_argument); // required class
603 603 __ push(rdx_temp); // bad object
604 604 __ push((int)Bytecodes::_checkcast); // who is complaining?
605 605 __ jump(ExternalAddress(from_interpreted_entry(_raise_exception)));
606 606
607 607 __ bind(done);
608 608 // get the new MH:
609 609 __ movptr(rcx_recv, rcx_mh_vmtarget);
610 610 __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
611 611 }
612 612 break;
613 613
614 614 case _adapter_prim_to_prim:
615 615 case _adapter_ref_to_prim:
616 616 // handled completely by optimized cases
617 617 __ stop("init_AdapterMethodHandle should not issue this");
618 618 break;
619 619
620 620 case _adapter_opt_i2i: // optimized subcase of adapt_prim_to_prim
621 621 //case _adapter_opt_f2i: // optimized subcase of adapt_prim_to_prim
622 622 case _adapter_opt_l2i: // optimized subcase of adapt_prim_to_prim
623 623 case _adapter_opt_unboxi: // optimized subcase of adapt_ref_to_prim
624 624 {
625 625 // perform an in-place conversion to int or an int subword
626 626 __ movl(rax_argslot, rcx_amh_vmargslot);
627 627 vmarg = __ argument_address(rax_argslot);
628 628
629 629 switch (ek) {
630 630 case _adapter_opt_i2i:
631 631 __ movl(rdx_temp, vmarg);
632 632 break;
633 633 case _adapter_opt_l2i:
634 634 {
635 635 // just delete the extra slot; on a little-endian machine we keep the first
636 636 __ lea(rax_argslot, __ argument_address(rax_argslot, 1));
637 637 remove_arg_slots(_masm, -stack_move_unit(),
638 638 rax_argslot, rbx_temp, rdx_temp);
639 639 vmarg = Address(rax_argslot, -Interpreter::stackElementSize());
640 640 __ movl(rdx_temp, vmarg);
641 641 }
642 642 break;
643 643 case _adapter_opt_unboxi:
644 644 {
645 645 // Load the value up from the heap.
646 646 __ movptr(rdx_temp, vmarg);
647 647 int value_offset = java_lang_boxing_object::value_offset_in_bytes(T_INT);
648 648 #ifdef ASSERT
649 649 for (int bt = T_BOOLEAN; bt < T_INT; bt++) {
650 650 if (is_subword_type(BasicType(bt)))
651 651 assert(value_offset == java_lang_boxing_object::value_offset_in_bytes(BasicType(bt)), "");
652 652 }
653 653 #endif
654 654 __ null_check(rdx_temp, value_offset);
655 655 __ movl(rdx_temp, Address(rdx_temp, value_offset));
656 656 // We load this as a word. Because we are little-endian,
657 657 // the low bits will be correct, but the high bits may need cleaning.
658 658 // The vminfo will guide us to clean those bits.
659 659 }
660 660 break;
661 661 default:
662 662 assert(false, "");
663 663 }
664 664 goto finish_int_conversion;
665 665 }
666 666
667 667 finish_int_conversion:
668 668 {
669 669 Register rbx_vminfo = rbx_temp;
670 670 __ movl(rbx_vminfo, rcx_amh_conversion);
671 671 assert(CONV_VMINFO_SHIFT == 0, "preshifted");
672 672
673 673 // get the new MH:
674 674 __ movptr(rcx_recv, rcx_mh_vmtarget);
675 675 // (now we are done with the old MH)
676 676
677 677 // original 32-bit vmdata word must be of this form:
678 678 // | MBZ:16 | signBitCount:8 | srcDstTypes:8 | conversionOp:8 |
679 679 __ xchgl(rcx, rbx_vminfo); // free rcx for shifts
680 680 __ shll(rdx_temp /*, rcx*/);
681 681 Label zero_extend, done;
682 682 __ testl(rcx, CONV_VMINFO_SIGN_FLAG);
683 683 __ jcc(Assembler::zero, zero_extend);
684 684
685 685 // this path is taken for int->byte, int->short
686 686 __ sarl(rdx_temp /*, rcx*/);
687 687 __ jmp(done);
688 688
689 689 __ bind(zero_extend);
690 690 // this is taken for int->char
691 691 __ shrl(rdx_temp /*, rcx*/);
692 692
693 693 __ bind(done);
694 694 __ movptr(vmarg, rdx_temp);
695 695 __ xchgl(rcx, rbx_vminfo); // restore rcx_recv
696 696
697 697 __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
698 698 }
699 699 break;
700 700
701 701 case _adapter_opt_i2l: // optimized subcase of adapt_prim_to_prim
702 702 case _adapter_opt_unboxl: // optimized subcase of adapt_ref_to_prim
703 703 {
704 704 // perform an in-place int-to-long or ref-to-long conversion
705 705 __ movl(rax_argslot, rcx_amh_vmargslot);
706 706
707 707 // on a little-endian machine we keep the first slot and add another after
708 708 __ lea(rax_argslot, __ argument_address(rax_argslot, 1));
709 709 insert_arg_slots(_masm, stack_move_unit(), _INSERT_INT_MASK,
710 710 rax_argslot, rbx_temp, rdx_temp);
711 711 Address vmarg1(rax_argslot, -Interpreter::stackElementSize());
712 712 Address vmarg2 = vmarg1.plus_disp(Interpreter::stackElementSize());
713 713
714 714 switch (ek) {
715 715 case _adapter_opt_i2l:
716 716 {
717 717 __ movl(rdx_temp, vmarg1);
718 718 __ sarl(rdx_temp, 31); // __ extend_sign()
719 719 __ movl(vmarg2, rdx_temp); // store second word
720 720 }
721 721 break;
722 722 case _adapter_opt_unboxl:
723 723 {
724 724 // Load the value up from the heap.
725 725 __ movptr(rdx_temp, vmarg1);
726 726 int value_offset = java_lang_boxing_object::value_offset_in_bytes(T_LONG);
727 727 assert(value_offset == java_lang_boxing_object::value_offset_in_bytes(T_DOUBLE), "");
728 728 __ null_check(rdx_temp, value_offset);
729 729 __ movl(rbx_temp, Address(rdx_temp, value_offset + 0*BytesPerInt));
730 730 __ movl(rdx_temp, Address(rdx_temp, value_offset + 1*BytesPerInt));
731 731 __ movl(vmarg1, rbx_temp);
732 732 __ movl(vmarg2, rdx_temp);
733 733 }
734 734 break;
735 735 default:
736 736 assert(false, "");
737 737 }
738 738
739 739 __ movptr(rcx_recv, rcx_mh_vmtarget);
740 740 __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
741 741 }
742 742 break;
743 743
744 744 case _adapter_opt_f2d: // optimized subcase of adapt_prim_to_prim
745 745 case _adapter_opt_d2f: // optimized subcase of adapt_prim_to_prim
746 746 {
747 747 // perform an in-place floating primitive conversion
748 748 __ movl(rax_argslot, rcx_amh_vmargslot);
749 749 __ lea(rax_argslot, __ argument_address(rax_argslot, 1));
750 750 if (ek == _adapter_opt_f2d) {
751 751 insert_arg_slots(_masm, stack_move_unit(), _INSERT_INT_MASK,
752 752 rax_argslot, rbx_temp, rdx_temp);
753 753 }
754 754 Address vmarg(rax_argslot, -Interpreter::stackElementSize());
755 755
756 756 #ifdef _LP64
757 757 if (ek == _adapter_opt_f2d) {
758 758 __ movflt(xmm0, vmarg);
759 759 __ cvtss2sd(xmm0, xmm0);
760 760 __ movdbl(vmarg, xmm0);
761 761 } else {
762 762 __ movdbl(xmm0, vmarg);
763 763 __ cvtsd2ss(xmm0, xmm0);
764 764 __ movflt(vmarg, xmm0);
765 765 }
766 766 #else //_LP64
767 767 if (ek == _adapter_opt_f2d) {
768 768 __ fld_s(vmarg); // load float to ST0
769 769 __ fstp_s(vmarg); // store single
770 770 } else if (!TaggedStackInterpreter) {
771 771 __ fld_d(vmarg); // load double to ST0
772 772 __ fstp_s(vmarg); // store single
773 773 } else {
774 774 Address vmarg_tag = vmarg.plus_disp(tag_offset);
775 775 Address vmarg2 = vmarg.plus_disp(Interpreter::stackElementSize());
776 776 // vmarg2_tag does not participate in this code
777 777 Register rbx_tag = rbx_temp;
778 778 __ movl(rbx_tag, vmarg_tag); // preserve tag
779 779 __ movl(rdx_temp, vmarg2); // get second word of double
780 780 __ movl(vmarg_tag, rdx_temp); // align with first word
781 781 __ fld_d(vmarg); // load double to ST0
782 782 __ movl(vmarg_tag, rbx_tag); // restore tag
783 783 __ fstp_s(vmarg); // store single
784 784 }
785 785 #endif //_LP64
786 786
787 787 if (ek == _adapter_opt_d2f) {
788 788 remove_arg_slots(_masm, -stack_move_unit(),
789 789 rax_argslot, rbx_temp, rdx_temp);
790 790 }
791 791
792 792 __ movptr(rcx_recv, rcx_mh_vmtarget);
793 793 __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
794 794 }
795 795 break;
796 796
797 797 case _adapter_prim_to_ref:
798 798 __ unimplemented(entry_name(ek)); // %%% FIXME: NYI
799 799 break;
800 800
801 801 case _adapter_swap_args:
802 802 case _adapter_rot_args:
803 803 // handled completely by optimized cases
804 804 __ stop("init_AdapterMethodHandle should not issue this");
805 805 break;
806 806
807 807 case _adapter_opt_swap_1:
808 808 case _adapter_opt_swap_2:
809 809 case _adapter_opt_rot_1_up:
810 810 case _adapter_opt_rot_1_down:
811 811 case _adapter_opt_rot_2_up:
812 812 case _adapter_opt_rot_2_down:
813 813 {
814 814 int rotate = 0, swap_slots = 0;
815 815 switch ((int)ek) {
816 816 case _adapter_opt_swap_1: swap_slots = 1; break;
817 817 case _adapter_opt_swap_2: swap_slots = 2; break;
818 818 case _adapter_opt_rot_1_up: swap_slots = 1; rotate++; break;
819 819 case _adapter_opt_rot_1_down: swap_slots = 1; rotate--; break;
820 820 case _adapter_opt_rot_2_up: swap_slots = 2; rotate++; break;
821 821 case _adapter_opt_rot_2_down: swap_slots = 2; rotate--; break;
822 822 default: assert(false, "");
823 823 }
824 824
825 825 // the real size of the move must be doubled if TaggedStackInterpreter:
826 826 int swap_bytes = (int)( swap_slots * Interpreter::stackElementWords() * wordSize );
827 827
828 828 // 'argslot' is the position of the first argument to swap
829 829 __ movl(rax_argslot, rcx_amh_vmargslot);
830 830 __ lea(rax_argslot, __ argument_address(rax_argslot));
831 831
832 832 // 'vminfo' is the second
833 833 Register rbx_destslot = rbx_temp;
834 834 __ movl(rbx_destslot, rcx_amh_conversion);
835 835 assert(CONV_VMINFO_SHIFT == 0, "preshifted");
836 836 __ andl(rbx_destslot, CONV_VMINFO_MASK);
837 837 __ lea(rbx_destslot, __ argument_address(rbx_destslot));
838 838 DEBUG_ONLY(verify_argslot(_masm, rbx_destslot, "swap point must fall within current frame"));
839 839
840 840 if (!rotate) {
841 841 for (int i = 0; i < swap_bytes; i += wordSize) {
842 842 __ movptr(rdx_temp, Address(rax_argslot , i));
843 843 __ push(rdx_temp);
844 844 __ movptr(rdx_temp, Address(rbx_destslot, i));
845 845 __ movptr(Address(rax_argslot, i), rdx_temp);
846 846 __ pop(rdx_temp);
847 847 __ movptr(Address(rbx_destslot, i), rdx_temp);
848 848 }
849 849 } else {
850 850 // push the first chunk, which is going to get overwritten
851 851 for (int i = swap_bytes; (i -= wordSize) >= 0; ) {
852 852 __ movptr(rdx_temp, Address(rax_argslot, i));
853 853 __ push(rdx_temp);
854 854 }
855 855
856 856 if (rotate > 0) {
857 857 // rotate upward
858 858 __ subptr(rax_argslot, swap_bytes);
859 859 #ifdef ASSERT
860 860 {
861 861 // Verify that argslot > destslot, by at least swap_bytes.
862 862 Label L_ok;
863 863 __ cmpptr(rax_argslot, rbx_destslot);
864 864 __ jcc(Assembler::aboveEqual, L_ok);
865 865 __ stop("source must be above destination (upward rotation)");
866 866 __ bind(L_ok);
867 867 }
868 868 #endif
869 869 // work argslot down to destslot, copying contiguous data upwards
870 870 // pseudo-code:
871 871 // rax = src_addr - swap_bytes
872 872 // rbx = dest_addr
873 873 // while (rax >= rbx) *(rax + swap_bytes) = *(rax + 0), rax--;
874 874 Label loop;
875 875 __ bind(loop);
876 876 __ movptr(rdx_temp, Address(rax_argslot, 0));
877 877 __ movptr(Address(rax_argslot, swap_bytes), rdx_temp);
878 878 __ addptr(rax_argslot, -wordSize);
879 879 __ cmpptr(rax_argslot, rbx_destslot);
880 880 __ jcc(Assembler::aboveEqual, loop);
881 881 } else {
882 882 __ addptr(rax_argslot, swap_bytes);
883 883 #ifdef ASSERT
884 884 {
885 885 // Verify that argslot < destslot, by at least swap_bytes.
886 886 Label L_ok;
887 887 __ cmpptr(rax_argslot, rbx_destslot);
888 888 __ jcc(Assembler::belowEqual, L_ok);
889 889 __ stop("source must be below destination (downward rotation)");
890 890 __ bind(L_ok);
891 891 }
892 892 #endif
893 893 // work argslot up to destslot, copying contiguous data downwards
894 894 // pseudo-code:
895 895 // rax = src_addr + swap_bytes
896 896 // rbx = dest_addr
897 897 // while (rax <= rbx) *(rax - swap_bytes) = *(rax + 0), rax++;
898 898 Label loop;
899 899 __ bind(loop);
900 900 __ movptr(rdx_temp, Address(rax_argslot, 0));
901 901 __ movptr(Address(rax_argslot, -swap_bytes), rdx_temp);
902 902 __ addptr(rax_argslot, wordSize);
903 903 __ cmpptr(rax_argslot, rbx_destslot);
904 904 __ jcc(Assembler::belowEqual, loop);
905 905 }
906 906
907 907 // pop the original first chunk into the destination slot, now free
908 908 for (int i = 0; i < swap_bytes; i += wordSize) {
909 909 __ pop(rdx_temp);
910 910 __ movptr(Address(rbx_destslot, i), rdx_temp);
911 911 }
912 912 }
913 913
914 914 __ movptr(rcx_recv, rcx_mh_vmtarget);
915 915 __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
916 916 }
917 917 break;
918 918
919 919 case _adapter_dup_args:
920 920 {
921 921 // 'argslot' is the position of the first argument to duplicate
922 922 __ movl(rax_argslot, rcx_amh_vmargslot);
923 923 __ lea(rax_argslot, __ argument_address(rax_argslot));
924 924
925 925 // 'stack_move' is negative number of words to duplicate
926 926 Register rdx_stack_move = rdx_temp;
927 927 __ movl(rdx_stack_move, rcx_amh_conversion);
928 928 __ sarl(rdx_stack_move, CONV_STACK_MOVE_SHIFT);
929 929
930 930 int argslot0_num = 0;
931 931 Address argslot0 = __ argument_address(RegisterOrConstant(argslot0_num));
932 932 assert(argslot0.base() == rsp, "");
933 933 int pre_arg_size = argslot0.disp();
934 934 assert(pre_arg_size % wordSize == 0, "");
935 935 assert(pre_arg_size > 0, "must include PC");
936 936
937 937 // remember the old rsp+1 (argslot[0])
938 938 Register rbx_oldarg = rbx_temp;
939 939 __ lea(rbx_oldarg, argslot0);
940 940
941 941 // move rsp down to make room for dups
942 942 __ lea(rsp, Address(rsp, rdx_stack_move, Address::times_ptr));
943 943
944 944 // compute the new rsp+1 (argslot[0])
945 945 Register rdx_newarg = rdx_temp;
946 946 __ lea(rdx_newarg, argslot0);
947 947
948 948 __ push(rdi); // need a temp
949 949 // (preceding push must be done after arg addresses are taken!)
950 950
951 951 // pull down the pre_arg_size data (PC)
952 952 for (int i = -pre_arg_size; i < 0; i += wordSize) {
953 953 __ movptr(rdi, Address(rbx_oldarg, i));
954 954 __ movptr(Address(rdx_newarg, i), rdi);
955 955 }
956 956
957 957 // copy from rax_argslot[0...] down to new_rsp[1...]
958 958 // pseudo-code:
959 959 // rbx = old_rsp+1
960 960 // rdx = new_rsp+1
961 961 // rax = argslot
962 962 // while (rdx < rbx) *rdx++ = *rax++
963 963 Label loop;
964 964 __ bind(loop);
965 965 __ movptr(rdi, Address(rax_argslot, 0));
966 966 __ movptr(Address(rdx_newarg, 0), rdi);
967 967 __ addptr(rax_argslot, wordSize);
968 968 __ addptr(rdx_newarg, wordSize);
969 969 __ cmpptr(rdx_newarg, rbx_oldarg);
970 970 __ jcc(Assembler::less, loop);
971 971
972 972 __ pop(rdi); // restore temp
973 973
974 974 __ movptr(rcx_recv, rcx_mh_vmtarget);
975 975 __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
976 976 }
977 977 break;
978 978
979 979 case _adapter_drop_args:
980 980 {
981 981 // 'argslot' is the position of the first argument to nuke
982 982 __ movl(rax_argslot, rcx_amh_vmargslot);
983 983 __ lea(rax_argslot, __ argument_address(rax_argslot));
984 984
985 985 __ push(rdi); // need a temp
986 986 // (must do previous push after argslot address is taken)
987 987
988 988 // 'stack_move' is number of words to drop
989 989 Register rdi_stack_move = rdi;
990 990 __ movl(rdi_stack_move, rcx_amh_conversion);
991 991 __ sarl(rdi_stack_move, CONV_STACK_MOVE_SHIFT);
992 992 remove_arg_slots(_masm, rdi_stack_move,
993 993 rax_argslot, rbx_temp, rdx_temp);
994 994
995 995 __ pop(rdi); // restore temp
996 996
997 997 __ movptr(rcx_recv, rcx_mh_vmtarget);
998 998 __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
999 999 }
1000 1000 break;
1001 1001
1002 1002 case _adapter_collect_args:
1003 1003 __ unimplemented(entry_name(ek)); // %%% FIXME: NYI
1004 1004 break;
1005 1005
1006 1006 case _adapter_spread_args:
1007 1007 // handled completely by optimized cases
1008 1008 __ stop("init_AdapterMethodHandle should not issue this");
1009 1009 break;
1010 1010
1011 1011 case _adapter_opt_spread_0:
1012 1012 case _adapter_opt_spread_1:
1013 1013 case _adapter_opt_spread_more:
1014 1014 {
1015 1015 // spread an array out into a group of arguments
1016 1016 int length_constant = -1;
1017 1017 switch (ek) {
1018 1018 case _adapter_opt_spread_0: length_constant = 0; break;
1019 1019 case _adapter_opt_spread_1: length_constant = 1; break;
1020 1020 }
1021 1021
1022 1022 // find the address of the array argument
1023 1023 __ movl(rax_argslot, rcx_amh_vmargslot);
1024 1024 __ lea(rax_argslot, __ argument_address(rax_argslot));
1025 1025
1026 1026 // grab some temps
1027 1027 { __ push(rsi); __ push(rdi); }
1028 1028 // (preceding pushes must be done after argslot address is taken!)
1029 1029 #define UNPUSH_RSI_RDI \
1030 1030 { __ pop(rdi); __ pop(rsi); }
1031 1031
1032 1032 // arx_argslot points both to the array and to the first output arg
1033 1033 vmarg = Address(rax_argslot, 0);
1034 1034
1035 1035 // Get the array value.
1036 1036 Register rsi_array = rsi;
1037 1037 Register rdx_array_klass = rdx_temp;
1038 1038 BasicType elem_type = T_OBJECT;
1039 1039 int length_offset = arrayOopDesc::length_offset_in_bytes();
1040 1040 int elem0_offset = arrayOopDesc::base_offset_in_bytes(elem_type);
1041 1041 __ movptr(rsi_array, vmarg);
1042 1042 Label skip_array_check;
1043 1043 if (length_constant == 0) {
1044 1044 __ testptr(rsi_array, rsi_array);
1045 1045 __ jcc(Assembler::zero, skip_array_check);
1046 1046 }
1047 1047 __ null_check(rsi_array, oopDesc::klass_offset_in_bytes());
1048 1048 __ load_klass(rdx_array_klass, rsi_array);
1049 1049
1050 1050 // Check the array type.
1051 1051 Register rbx_klass = rbx_temp;
1052 1052 __ movptr(rbx_klass, rcx_amh_argument); // this is a Class object!
1053 1053 __ movptr(rbx_klass, Address(rbx_klass, java_lang_Class::klass_offset_in_bytes()));
1054 1054
1055 1055 Label ok_array_klass, bad_array_klass, bad_array_length;
1056 1056 __ check_klass_subtype(rdx_array_klass, rbx_klass, rdi, ok_array_klass);
1057 1057 // If we get here, the type check failed!
1058 1058 __ jmp(bad_array_klass);
1059 1059 __ bind(ok_array_klass);
1060 1060
1061 1061 // Check length.
1062 1062 if (length_constant >= 0) {
1063 1063 __ cmpl(Address(rsi_array, length_offset), length_constant);
1064 1064 } else {
1065 1065 Register rbx_vminfo = rbx_temp;
1066 1066 __ movl(rbx_vminfo, rcx_amh_conversion);
1067 1067 assert(CONV_VMINFO_SHIFT == 0, "preshifted");
1068 1068 __ andl(rbx_vminfo, CONV_VMINFO_MASK);
1069 1069 __ cmpl(rbx_vminfo, Address(rsi_array, length_offset));
1070 1070 }
1071 1071 __ jcc(Assembler::notEqual, bad_array_length);
1072 1072
1073 1073 Register rdx_argslot_limit = rdx_temp;
1074 1074
1075 1075 // Array length checks out. Now insert any required stack slots.
1076 1076 if (length_constant == -1) {
1077 1077 // Form a pointer to the end of the affected region.
1078 1078 __ lea(rdx_argslot_limit, Address(rax_argslot, Interpreter::stackElementSize()));
1079 1079 // 'stack_move' is negative number of words to insert
1080 1080 Register rdi_stack_move = rdi;
1081 1081 __ movl(rdi_stack_move, rcx_amh_conversion);
1082 1082 __ sarl(rdi_stack_move, CONV_STACK_MOVE_SHIFT);
1083 1083 Register rsi_temp = rsi_array; // spill this
1084 1084 insert_arg_slots(_masm, rdi_stack_move, -1,
1085 1085 rax_argslot, rbx_temp, rsi_temp);
1086 1086 // reload the array (since rsi was killed)
1087 1087 __ movptr(rsi_array, vmarg);
1088 1088 } else if (length_constant > 1) {
1089 1089 int arg_mask = 0;
1090 1090 int new_slots = (length_constant - 1);
1091 1091 for (int i = 0; i < new_slots; i++) {
1092 1092 arg_mask <<= 1;
1093 1093 arg_mask |= _INSERT_REF_MASK;
1094 1094 }
1095 1095 insert_arg_slots(_masm, new_slots * stack_move_unit(), arg_mask,
1096 1096 rax_argslot, rbx_temp, rdx_temp);
1097 1097 } else if (length_constant == 1) {
1098 1098 // no stack resizing required
1099 1099 } else if (length_constant == 0) {
1100 1100 remove_arg_slots(_masm, -stack_move_unit(),
1101 1101 rax_argslot, rbx_temp, rdx_temp);
1102 1102 }
1103 1103
1104 1104 // Copy from the array to the new slots.
1105 1105 // Note: Stack change code preserves integrity of rax_argslot pointer.
1106 1106 // So even after slot insertions, rax_argslot still points to first argument.
1107 1107 if (length_constant == -1) {
1108 1108 // [rax_argslot, rdx_argslot_limit) is the area we are inserting into.
1109 1109 Register rsi_source = rsi_array;
1110 1110 __ lea(rsi_source, Address(rsi_array, elem0_offset));
1111 1111 Label loop;
1112 1112 __ bind(loop);
1113 1113 __ movptr(rbx_temp, Address(rsi_source, 0));
1114 1114 __ movptr(Address(rax_argslot, 0), rbx_temp);
1115 1115 __ addptr(rsi_source, type2aelembytes(elem_type));
1116 1116 if (TaggedStackInterpreter) {
1117 1117 __ movptr(Address(rax_argslot, tag_offset),
1118 1118 frame::tag_for_basic_type(elem_type));
1119 1119 }
1120 1120 __ addptr(rax_argslot, Interpreter::stackElementSize());
1121 1121 __ cmpptr(rax_argslot, rdx_argslot_limit);
1122 1122 __ jcc(Assembler::less, loop);
1123 1123 } else if (length_constant == 0) {
1124 1124 __ bind(skip_array_check);
1125 1125 // nothing to copy
1126 1126 } else {
1127 1127 int elem_offset = elem0_offset;
1128 1128 int slot_offset = 0;
1129 1129 for (int index = 0; index < length_constant; index++) {
1130 1130 __ movptr(rbx_temp, Address(rsi_array, elem_offset));
1131 1131 __ movptr(Address(rax_argslot, slot_offset), rbx_temp);
1132 1132 elem_offset += type2aelembytes(elem_type);
1133 1133 if (TaggedStackInterpreter) {
1134 1134 __ movptr(Address(rax_argslot, slot_offset + tag_offset),
1135 1135 frame::tag_for_basic_type(elem_type));
1136 1136 }
1137 1137 slot_offset += Interpreter::stackElementSize();
1138 1138 }
1139 1139 }
1140 1140
1141 1141 // Arguments are spread. Move to next method handle.
1142 1142 UNPUSH_RSI_RDI;
1143 1143 __ movptr(rcx_recv, rcx_mh_vmtarget);
1144 1144 __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
1145 1145
1146 1146 __ bind(bad_array_klass);
1147 1147 UNPUSH_RSI_RDI;
1148 1148 __ pushptr(Address(rdx_array_klass, java_mirror_offset)); // required type
1149 1149 __ pushptr(vmarg); // bad array
1150 1150 __ push((int)Bytecodes::_aaload); // who is complaining?
1151 1151 __ jump(ExternalAddress(from_interpreted_entry(_raise_exception)));
1152 1152
1153 1153 __ bind(bad_array_length);
1154 1154 UNPUSH_RSI_RDI;
1155 1155 __ push(rcx_recv); // AMH requiring a certain length
1156 1156 __ pushptr(vmarg); // bad array
1157 1157 __ push((int)Bytecodes::_arraylength); // who is complaining?
1158 1158 __ jump(ExternalAddress(from_interpreted_entry(_raise_exception)));
1159 1159
1160 1160 #undef UNPUSH_RSI_RDI
1161 1161 }
1162 1162 break;
1163 1163
1164 1164 case _adapter_flyby:
1165 1165 case _adapter_ricochet:
1166 1166 __ unimplemented(entry_name(ek)); // %%% FIXME: NYI
1167 1167 break;
1168 1168
1169 1169 default: ShouldNotReachHere();
1170 1170 }
1171 1171 __ hlt();
1172 1172
1173 1173 address me_cookie = MethodHandleEntry::start_compiled_entry(_masm, interp_entry);
1174 1174 __ unimplemented(entry_name(ek)); // %%% FIXME: NYI
1175 1175
1176 1176 init_entry(ek, MethodHandleEntry::finish_compiled_entry(_masm, me_cookie));
1177 1177 }
↓ open down ↓ |
716 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX