src/cpu/x86/vm/methodHandles_x86.cpp

Mon, 04 Jan 2010 18:38:08 +0100

author
twisti
date
Mon, 04 Jan 2010 18:38:08 +0100
changeset 1570
e66fd840cb6b
parent 1568
aa62b9388fce
child 1712
855c5171834c
permissions
-rw-r--r--

6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
Summary: During the work for 6829187 we have fixed a number of basic bugs which are logically grouped with 6815692 and 6858164 but which must be reviewed and pushed separately.
Reviewed-by: kvn, never

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

mercurial