annotate src/cpu/x86/vm/methodHandles_x86.cpp @ 1108:85f13cdfbc1d

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