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