jrose@1145: /* jrose@1145: * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. jrose@1145: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jrose@1145: * jrose@1145: * This code is free software; you can redistribute it and/or modify it jrose@1145: * under the terms of the GNU General Public License version 2 only, as jrose@1145: * published by the Free Software Foundation. jrose@1145: * jrose@1145: * This code is distributed in the hope that it will be useful, but WITHOUT jrose@1145: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jrose@1145: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jrose@1145: * version 2 for more details (a copy is included in the LICENSE file that jrose@1145: * accompanied this code). jrose@1145: * jrose@1145: * You should have received a copy of the GNU General Public License version jrose@1145: * 2 along with this work; if not, write to the Free Software Foundation, jrose@1145: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jrose@1145: * jrose@1145: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, jrose@1145: * CA 95054 USA or visit www.sun.com if you need additional information or jrose@1145: * have any questions. jrose@1145: * jrose@1145: */ jrose@1145: jrose@1145: #include "incls/_precompiled.incl" jrose@1145: #include "incls/_methodHandles_x86.cpp.incl" jrose@1145: jrose@1145: #define __ _masm-> jrose@1145: jrose@1145: address MethodHandleEntry::start_compiled_entry(MacroAssembler* _masm, jrose@1145: address interpreted_entry) { jrose@1145: // Just before the actual machine code entry point, allocate space jrose@1145: // for a MethodHandleEntry::Data record, so that we can manage everything jrose@1145: // from one base pointer. jrose@1145: __ align(wordSize); jrose@1145: address target = __ pc() + sizeof(Data); jrose@1145: while (__ pc() < target) { jrose@1145: __ nop(); jrose@1145: __ align(wordSize); jrose@1145: } jrose@1145: jrose@1145: MethodHandleEntry* me = (MethodHandleEntry*) __ pc(); jrose@1145: me->set_end_address(__ pc()); // set a temporary end_address jrose@1145: me->set_from_interpreted_entry(interpreted_entry); jrose@1145: me->set_type_checking_entry(NULL); jrose@1145: jrose@1145: return (address) me; jrose@1145: } jrose@1145: jrose@1145: MethodHandleEntry* MethodHandleEntry::finish_compiled_entry(MacroAssembler* _masm, jrose@1145: address start_addr) { jrose@1145: MethodHandleEntry* me = (MethodHandleEntry*) start_addr; jrose@1145: assert(me->end_address() == start_addr, "valid ME"); jrose@1145: jrose@1145: // Fill in the real end_address: jrose@1145: __ align(wordSize); jrose@1145: me->set_end_address(__ pc()); jrose@1145: jrose@1145: return me; jrose@1145: } jrose@1145: jrose@1145: #ifdef ASSERT jrose@1145: static void verify_argslot(MacroAssembler* _masm, Register rax_argslot, jrose@1145: const char* error_message) { jrose@1145: // Verify that argslot lies within (rsp, rbp]. jrose@1145: Label L_ok, L_bad; jrose@1145: __ cmpptr(rax_argslot, rbp); jrose@1145: __ jcc(Assembler::above, L_bad); jrose@1145: __ cmpptr(rsp, rax_argslot); jrose@1145: __ jcc(Assembler::below, L_ok); jrose@1145: __ bind(L_bad); jrose@1145: __ stop(error_message); jrose@1145: __ bind(L_ok); jrose@1145: } jrose@1145: #endif jrose@1145: jrose@1145: jrose@1145: // Code generation jrose@1145: address MethodHandles::generate_method_handle_interpreter_entry(MacroAssembler* _masm) { jrose@1145: // rbx: methodOop jrose@1145: // rcx: receiver method handle (must load from sp[MethodTypeForm.vmslots]) jrose@1145: // rsi/r13: sender SP (must preserve; see prepare_to_jump_from_interpreted) jrose@1145: // rdx: garbage temp, blown away jrose@1145: jrose@1145: Register rbx_method = rbx; jrose@1145: Register rcx_recv = rcx; jrose@1145: Register rax_mtype = rax; jrose@1145: Register rdx_temp = rdx; jrose@1145: jrose@1145: // emit WrongMethodType path first, to enable jccb back-branch from main path jrose@1145: Label wrong_method_type; jrose@1145: __ bind(wrong_method_type); jrose@1145: __ push(rax_mtype); // required mtype jrose@1145: __ push(rcx_recv); // bad mh (1st stacked argument) jrose@1145: __ jump(ExternalAddress(Interpreter::throw_WrongMethodType_entry())); jrose@1145: jrose@1145: // here's where control starts out: jrose@1145: __ align(CodeEntryAlignment); jrose@1145: address entry_point = __ pc(); jrose@1145: jrose@1145: // fetch the MethodType from the method handle into rax (the 'check' register) jrose@1145: { jrose@1145: Register tem = rbx_method; jrose@1145: for (jint* pchase = methodOopDesc::method_type_offsets_chain(); (*pchase) != -1; pchase++) { jrose@1145: __ movptr(rax_mtype, Address(tem, *pchase)); jrose@1145: tem = rax_mtype; // in case there is another indirection jrose@1145: } jrose@1145: } jrose@1145: Register rbx_temp = rbx_method; // done with incoming methodOop jrose@1145: jrose@1145: // given the MethodType, find out where the MH argument is buried jrose@1145: __ movptr(rdx_temp, Address(rax_mtype, jrose@1145: __ delayed_value(java_dyn_MethodType::form_offset_in_bytes, rbx_temp))); jrose@1145: __ movl(rdx_temp, Address(rdx_temp, jrose@1145: __ delayed_value(java_dyn_MethodTypeForm::vmslots_offset_in_bytes, rbx_temp))); jrose@1145: __ movptr(rcx_recv, __ argument_address(rdx_temp)); jrose@1145: jrose@1145: __ check_method_handle_type(rax_mtype, rcx_recv, rdx_temp, wrong_method_type); jrose@1145: __ jump_to_method_handle_entry(rcx_recv, rdx_temp); jrose@1145: jrose@1145: return entry_point; jrose@1145: } jrose@1145: jrose@1145: // Helper to insert argument slots into the stack. jrose@1145: // arg_slots must be a multiple of stack_move_unit() and <= 0 jrose@1145: void MethodHandles::insert_arg_slots(MacroAssembler* _masm, jrose@1145: RegisterOrConstant arg_slots, jrose@1145: int arg_mask, jrose@1145: Register rax_argslot, jrose@1145: Register rbx_temp, Register rdx_temp) { jrose@1145: assert_different_registers(rax_argslot, rbx_temp, rdx_temp, jrose@1145: (!arg_slots.is_register() ? rsp : arg_slots.as_register())); jrose@1145: jrose@1145: #ifdef ASSERT jrose@1145: verify_argslot(_masm, rax_argslot, "insertion point must fall within current frame"); jrose@1145: if (arg_slots.is_register()) { jrose@1145: Label L_ok, L_bad; jrose@1145: __ cmpptr(arg_slots.as_register(), (int32_t) NULL_WORD); jrose@1145: __ jcc(Assembler::greater, L_bad); jrose@1145: __ testl(arg_slots.as_register(), -stack_move_unit() - 1); jrose@1145: __ jcc(Assembler::zero, L_ok); jrose@1145: __ bind(L_bad); jrose@1145: __ stop("assert arg_slots <= 0 and clear low bits"); jrose@1145: __ bind(L_ok); jrose@1145: } else { jrose@1145: assert(arg_slots.as_constant() <= 0, ""); jrose@1145: assert(arg_slots.as_constant() % -stack_move_unit() == 0, ""); jrose@1145: } jrose@1145: #endif //ASSERT jrose@1145: jrose@1145: #ifdef _LP64 jrose@1145: if (arg_slots.is_register()) { jrose@1145: // clean high bits of stack motion register (was loaded as an int) jrose@1145: __ movslq(arg_slots.as_register(), arg_slots.as_register()); jrose@1145: } jrose@1145: #endif jrose@1145: jrose@1145: // Make space on the stack for the inserted argument(s). jrose@1145: // Then pull down everything shallower than rax_argslot. jrose@1145: // The stacked return address gets pulled down with everything else. jrose@1145: // That is, copy [rsp, argslot) downward by -size words. In pseudo-code: jrose@1145: // rsp -= size; jrose@1145: // for (rdx = rsp + size; rdx < argslot; rdx++) jrose@1145: // rdx[-size] = rdx[0] jrose@1145: // argslot -= size; jrose@1145: __ mov(rdx_temp, rsp); // source pointer for copy jrose@1145: __ lea(rsp, Address(rsp, arg_slots, Address::times_ptr)); jrose@1145: { jrose@1145: Label loop; jrose@1145: __ bind(loop); jrose@1145: // pull one word down each time through the loop jrose@1145: __ movptr(rbx_temp, Address(rdx_temp, 0)); jrose@1145: __ movptr(Address(rdx_temp, arg_slots, Address::times_ptr), rbx_temp); jrose@1145: __ addptr(rdx_temp, wordSize); jrose@1145: __ cmpptr(rdx_temp, rax_argslot); jrose@1145: __ jcc(Assembler::less, loop); jrose@1145: } jrose@1145: jrose@1145: // Now move the argslot down, to point to the opened-up space. jrose@1145: __ lea(rax_argslot, Address(rax_argslot, arg_slots, Address::times_ptr)); jrose@1145: jrose@1145: if (TaggedStackInterpreter && arg_mask != _INSERT_NO_MASK) { jrose@1145: // The caller has specified a bitmask of tags to put into the opened space. jrose@1145: // This only works when the arg_slots value is an assembly-time constant. jrose@1145: int constant_arg_slots = arg_slots.as_constant() / stack_move_unit(); jrose@1145: int tag_offset = Interpreter::tag_offset_in_bytes() - Interpreter::value_offset_in_bytes(); jrose@1145: for (int slot = 0; slot < constant_arg_slots; slot++) { jrose@1145: BasicType slot_type = ((arg_mask & (1 << slot)) == 0 ? T_OBJECT : T_INT); jrose@1145: int slot_offset = Interpreter::stackElementSize() * slot; jrose@1145: Address tag_addr(rax_argslot, slot_offset + tag_offset); jrose@1145: __ movptr(tag_addr, frame::tag_for_basic_type(slot_type)); jrose@1145: } jrose@1145: // Note that the new argument slots are tagged properly but contain jrose@1145: // garbage at this point. The value portions must be initialized jrose@1145: // by the caller. (Especially references!) jrose@1145: } jrose@1145: } jrose@1145: jrose@1145: // Helper to remove argument slots from the stack. jrose@1145: // arg_slots must be a multiple of stack_move_unit() and >= 0 jrose@1145: void MethodHandles::remove_arg_slots(MacroAssembler* _masm, jrose@1145: RegisterOrConstant arg_slots, jrose@1145: Register rax_argslot, jrose@1145: Register rbx_temp, Register rdx_temp) { jrose@1145: assert_different_registers(rax_argslot, rbx_temp, rdx_temp, jrose@1145: (!arg_slots.is_register() ? rsp : arg_slots.as_register())); jrose@1145: jrose@1145: #ifdef ASSERT jrose@1145: { jrose@1145: // Verify that [argslot..argslot+size) lies within (rsp, rbp). jrose@1145: Label L_ok, L_bad; jrose@1145: __ lea(rbx_temp, Address(rax_argslot, arg_slots, Address::times_ptr)); jrose@1145: __ cmpptr(rbx_temp, rbp); jrose@1145: __ jcc(Assembler::above, L_bad); jrose@1145: __ cmpptr(rsp, rax_argslot); jrose@1145: __ jcc(Assembler::below, L_ok); jrose@1145: __ bind(L_bad); jrose@1145: __ stop("deleted argument(s) must fall within current frame"); jrose@1145: __ bind(L_ok); jrose@1145: } jrose@1145: if (arg_slots.is_register()) { jrose@1145: Label L_ok, L_bad; jrose@1145: __ cmpptr(arg_slots.as_register(), (int32_t) NULL_WORD); jrose@1145: __ jcc(Assembler::less, L_bad); jrose@1145: __ testl(arg_slots.as_register(), -stack_move_unit() - 1); jrose@1145: __ jcc(Assembler::zero, L_ok); jrose@1145: __ bind(L_bad); jrose@1145: __ stop("assert arg_slots >= 0 and clear low bits"); jrose@1145: __ bind(L_ok); jrose@1145: } else { jrose@1145: assert(arg_slots.as_constant() >= 0, ""); jrose@1145: assert(arg_slots.as_constant() % -stack_move_unit() == 0, ""); jrose@1145: } jrose@1145: #endif //ASSERT jrose@1145: jrose@1145: #ifdef _LP64 jrose@1145: if (false) { // not needed, since register is positive jrose@1145: // clean high bits of stack motion register (was loaded as an int) jrose@1145: if (arg_slots.is_register()) jrose@1145: __ movslq(arg_slots.as_register(), arg_slots.as_register()); jrose@1145: } jrose@1145: #endif jrose@1145: jrose@1145: // Pull up everything shallower than rax_argslot. jrose@1145: // Then remove the excess space on the stack. jrose@1145: // The stacked return address gets pulled up with everything else. jrose@1145: // That is, copy [rsp, argslot) upward by size words. In pseudo-code: jrose@1145: // for (rdx = argslot-1; rdx >= rsp; --rdx) jrose@1145: // rdx[size] = rdx[0] jrose@1145: // argslot += size; jrose@1145: // rsp += size; jrose@1145: __ lea(rdx_temp, Address(rax_argslot, -wordSize)); // source pointer for copy jrose@1145: { jrose@1145: Label loop; jrose@1145: __ bind(loop); jrose@1145: // pull one word up each time through the loop jrose@1145: __ movptr(rbx_temp, Address(rdx_temp, 0)); jrose@1145: __ movptr(Address(rdx_temp, arg_slots, Address::times_ptr), rbx_temp); jrose@1145: __ addptr(rdx_temp, -wordSize); jrose@1145: __ cmpptr(rdx_temp, rsp); jrose@1145: __ jcc(Assembler::greaterEqual, loop); jrose@1145: } jrose@1145: jrose@1145: // Now move the argslot up, to point to the just-copied block. jrose@1145: __ lea(rsp, Address(rsp, arg_slots, Address::times_ptr)); jrose@1145: // And adjust the argslot address to point at the deletion point. jrose@1145: __ lea(rax_argslot, Address(rax_argslot, arg_slots, Address::times_ptr)); jrose@1145: } jrose@1145: jrose@1145: #ifndef PRODUCT jrose@1145: void trace_method_handle_stub(const char* adaptername, jrose@1145: oop mh, jrose@1145: intptr_t* entry_sp, jrose@1145: intptr_t* saved_sp) { jrose@1145: // called as a leaf from native code: do not block the JVM! jrose@1145: printf("MH %s "PTR_FORMAT" "PTR_FORMAT" "INTX_FORMAT"\n", adaptername, mh, entry_sp, entry_sp - saved_sp); jrose@1145: } jrose@1145: #endif //PRODUCT jrose@1145: jrose@1145: // Generate an "entry" field for a method handle. jrose@1145: // This determines how the method handle will respond to calls. jrose@1145: void MethodHandles::generate_method_handle_stub(MacroAssembler* _masm, MethodHandles::EntryKind ek) { jrose@1145: // Here is the register state during an interpreted call, jrose@1145: // as set up by generate_method_handle_interpreter_entry(): jrose@1145: // - rbx: garbage temp (was MethodHandle.invoke methodOop, unused) jrose@1145: // - rcx: receiver method handle jrose@1145: // - rax: method handle type (only used by the check_mtype entry point) jrose@1145: // - rsi/r13: sender SP (must preserve; see prepare_to_jump_from_interpreted) jrose@1145: // - rdx: garbage temp, can blow away jrose@1145: jrose@1145: Register rcx_recv = rcx; jrose@1145: Register rax_argslot = rax; jrose@1145: Register rbx_temp = rbx; jrose@1145: Register rdx_temp = rdx; jrose@1145: jrose@1145: guarantee(java_dyn_MethodHandle::vmentry_offset_in_bytes() != 0, "must have offsets"); jrose@1145: jrose@1145: // some handy addresses jrose@1145: Address rbx_method_fie( rbx, methodOopDesc::from_interpreted_offset() ); jrose@1145: jrose@1145: Address rcx_mh_vmtarget( rcx_recv, java_dyn_MethodHandle::vmtarget_offset_in_bytes() ); jrose@1145: Address rcx_dmh_vmindex( rcx_recv, sun_dyn_DirectMethodHandle::vmindex_offset_in_bytes() ); jrose@1145: jrose@1145: Address rcx_bmh_vmargslot( rcx_recv, sun_dyn_BoundMethodHandle::vmargslot_offset_in_bytes() ); jrose@1145: Address rcx_bmh_argument( rcx_recv, sun_dyn_BoundMethodHandle::argument_offset_in_bytes() ); jrose@1145: jrose@1145: Address rcx_amh_vmargslot( rcx_recv, sun_dyn_AdapterMethodHandle::vmargslot_offset_in_bytes() ); jrose@1145: Address rcx_amh_argument( rcx_recv, sun_dyn_AdapterMethodHandle::argument_offset_in_bytes() ); jrose@1145: Address rcx_amh_conversion( rcx_recv, sun_dyn_AdapterMethodHandle::conversion_offset_in_bytes() ); jrose@1145: Address vmarg; // __ argument_address(vmargslot) jrose@1145: jrose@1145: int tag_offset = -1; jrose@1145: if (TaggedStackInterpreter) { jrose@1145: tag_offset = Interpreter::tag_offset_in_bytes() - Interpreter::value_offset_in_bytes(); jrose@1145: assert(tag_offset = wordSize, "stack grows as expected"); jrose@1145: } jrose@1145: jrose@1145: if (have_entry(ek)) { jrose@1145: __ nop(); // empty stubs make SG sick jrose@1145: return; jrose@1145: } jrose@1145: jrose@1145: address interp_entry = __ pc(); jrose@1145: if (UseCompressedOops) __ unimplemented("UseCompressedOops"); jrose@1145: jrose@1145: #ifndef PRODUCT jrose@1145: if (TraceMethodHandles) { jrose@1145: __ push(rax); __ push(rbx); __ push(rcx); __ push(rdx); __ push(rsi); __ push(rdi); jrose@1145: __ lea(rax, Address(rsp, wordSize*6)); // entry_sp jrose@1145: // arguments: jrose@1145: __ push(rsi); // saved_sp jrose@1145: __ push(rax); // entry_sp jrose@1145: __ push(rcx); // mh jrose@1145: __ push(rcx); jrose@1145: __ movptr(Address(rsp, 0), (intptr_t)entry_name(ek)); jrose@1145: __ call_VM_leaf(CAST_FROM_FN_PTR(address, trace_method_handle_stub), 4); jrose@1145: __ pop(rdi); __ pop(rsi); __ pop(rdx); __ pop(rcx); __ pop(rbx); __ pop(rax); jrose@1145: } jrose@1145: #endif //PRODUCT jrose@1145: jrose@1145: switch ((int) ek) { jrose@1145: case _check_mtype: jrose@1145: { jrose@1145: // this stub is special, because it requires a live mtype argument jrose@1145: Register rax_mtype = rax; jrose@1145: jrose@1145: // emit WrongMethodType path first, to enable jccb back-branch jrose@1145: Label wrong_method_type; jrose@1145: __ bind(wrong_method_type); jrose@1145: __ movptr(rdx_temp, ExternalAddress((address) &_entries[_wrong_method_type])); jrose@1145: __ jmp(Address(rdx_temp, MethodHandleEntry::from_interpreted_entry_offset_in_bytes())); jrose@1145: __ hlt(); jrose@1145: jrose@1145: interp_entry = __ pc(); jrose@1145: __ check_method_handle_type(rax_mtype, rcx_recv, rdx_temp, wrong_method_type); jrose@1145: // now rax_mtype is dead; subsequent stubs will use it as a temp jrose@1145: jrose@1145: __ jump_to_method_handle_entry(rcx_recv, rdx_temp); jrose@1145: } jrose@1145: break; jrose@1145: jrose@1145: case _wrong_method_type: jrose@1145: { jrose@1145: // this stub is special, because it requires a live mtype argument jrose@1145: Register rax_mtype = rax; jrose@1145: jrose@1145: interp_entry = __ pc(); jrose@1145: __ push(rax_mtype); // required mtype jrose@1145: __ push(rcx_recv); // random mh (1st stacked argument) jrose@1145: __ jump(ExternalAddress(Interpreter::throw_WrongMethodType_entry())); jrose@1145: } jrose@1145: break; jrose@1145: jrose@1145: case _invokestatic_mh: jrose@1145: case _invokespecial_mh: jrose@1145: { jrose@1145: Register rbx_method = rbx_temp; jrose@1145: __ movptr(rbx_method, rcx_mh_vmtarget); // target is a methodOop jrose@1145: __ verify_oop(rbx_method); jrose@1145: // same as TemplateTable::invokestatic or invokespecial, jrose@1145: // minus the CP setup and profiling: jrose@1145: if (ek == _invokespecial_mh) { jrose@1145: // Must load & check the first argument before entering the target method. jrose@1145: __ load_method_handle_vmslots(rax_argslot, rcx_recv, rdx_temp); jrose@1145: __ movptr(rcx_recv, __ argument_address(rax_argslot, -1)); jrose@1145: __ null_check(rcx_recv); jrose@1145: __ verify_oop(rcx_recv); jrose@1145: } jrose@1145: __ jmp(rbx_method_fie); jrose@1145: } jrose@1145: break; jrose@1145: jrose@1145: case _invokevirtual_mh: jrose@1145: { jrose@1145: // same as TemplateTable::invokevirtual, jrose@1145: // minus the CP setup and profiling: jrose@1145: jrose@1145: // pick out the vtable index and receiver offset from the MH, jrose@1145: // and then we can discard it: jrose@1145: __ load_method_handle_vmslots(rax_argslot, rcx_recv, rdx_temp); jrose@1145: Register rbx_index = rbx_temp; jrose@1145: __ movl(rbx_index, rcx_dmh_vmindex); jrose@1145: // Note: The verifier allows us to ignore rcx_mh_vmtarget. jrose@1145: __ movptr(rcx_recv, __ argument_address(rax_argslot, -1)); jrose@1145: __ null_check(rcx_recv, oopDesc::klass_offset_in_bytes()); jrose@1145: jrose@1145: // get receiver klass jrose@1145: Register rax_klass = rax_argslot; jrose@1145: __ load_klass(rax_klass, rcx_recv); jrose@1145: __ verify_oop(rax_klass); jrose@1145: jrose@1145: // get target methodOop & entry point jrose@1145: const int base = instanceKlass::vtable_start_offset() * wordSize; jrose@1145: assert(vtableEntry::size() * wordSize == wordSize, "adjust the scaling in the code below"); jrose@1145: Address vtable_entry_addr(rax_klass, jrose@1145: rbx_index, Address::times_ptr, jrose@1145: base + vtableEntry::method_offset_in_bytes()); jrose@1145: Register rbx_method = rbx_temp; jrose@1145: __ movl(rbx_method, vtable_entry_addr); jrose@1145: jrose@1145: __ verify_oop(rbx_method); jrose@1145: __ jmp(rbx_method_fie); jrose@1145: } jrose@1145: break; jrose@1145: jrose@1145: case _invokeinterface_mh: jrose@1145: { jrose@1145: // same as TemplateTable::invokeinterface, jrose@1145: // minus the CP setup and profiling: jrose@1145: jrose@1145: // pick out the interface and itable index from the MH. jrose@1145: __ load_method_handle_vmslots(rax_argslot, rcx_recv, rdx_temp); jrose@1145: Register rdx_intf = rdx_temp; jrose@1145: Register rbx_index = rbx_temp; jrose@1145: __ movptr(rdx_intf, rcx_mh_vmtarget); jrose@1145: __ movl(rbx_index, rcx_dmh_vmindex); jrose@1145: __ movptr(rcx_recv, __ argument_address(rax_argslot, -1)); jrose@1145: __ null_check(rcx_recv, oopDesc::klass_offset_in_bytes()); jrose@1145: jrose@1145: // get receiver klass jrose@1145: Register rax_klass = rax_argslot; jrose@1145: __ load_klass(rax_klass, rcx_recv); jrose@1145: __ verify_oop(rax_klass); jrose@1145: jrose@1145: Register rcx_temp = rcx_recv; jrose@1145: Register rbx_method = rbx_index; jrose@1145: jrose@1145: // get interface klass jrose@1145: Label no_such_interface; jrose@1145: __ verify_oop(rdx_intf); jrose@1145: __ lookup_interface_method(rax_klass, rdx_intf, jrose@1145: // note: next two args must be the same: jrose@1145: rbx_index, rbx_method, jrose@1145: rcx_temp, jrose@1145: no_such_interface); jrose@1145: jrose@1145: __ verify_oop(rbx_method); jrose@1145: __ jmp(rbx_method_fie); jrose@1145: __ hlt(); jrose@1145: jrose@1145: __ bind(no_such_interface); jrose@1145: // Throw an exception. jrose@1145: // For historical reasons, it will be IncompatibleClassChangeError. jrose@1145: __ should_not_reach_here(); // %%% FIXME NYI jrose@1145: } jrose@1145: break; jrose@1145: jrose@1145: case _bound_ref_mh: jrose@1145: case _bound_int_mh: jrose@1145: case _bound_long_mh: jrose@1145: case _bound_ref_direct_mh: jrose@1145: case _bound_int_direct_mh: jrose@1145: case _bound_long_direct_mh: jrose@1145: { jrose@1145: bool direct_to_method = (ek >= _bound_ref_direct_mh); jrose@1145: BasicType arg_type = T_ILLEGAL; jrose@1145: if (ek == _bound_long_mh || ek == _bound_long_direct_mh) { jrose@1145: arg_type = T_LONG; jrose@1145: } else if (ek == _bound_int_mh || ek == _bound_int_direct_mh) { jrose@1145: arg_type = T_INT; jrose@1145: } else { jrose@1145: assert(ek == _bound_ref_mh || ek == _bound_ref_direct_mh, "must be ref"); jrose@1145: arg_type = T_OBJECT; jrose@1145: } jrose@1145: int arg_slots = type2size[arg_type]; jrose@1145: int arg_mask = (arg_type == T_OBJECT ? _INSERT_REF_MASK : jrose@1145: arg_slots == 1 ? _INSERT_INT_MASK : _INSERT_LONG_MASK); jrose@1145: jrose@1145: // make room for the new argument: jrose@1145: __ movl(rax_argslot, rcx_bmh_vmargslot); jrose@1145: __ lea(rax_argslot, __ argument_address(rax_argslot)); jrose@1145: insert_arg_slots(_masm, arg_slots * stack_move_unit(), arg_mask, jrose@1145: rax_argslot, rbx_temp, rdx_temp); jrose@1145: jrose@1145: // store bound argument into the new stack slot: jrose@1145: __ movptr(rbx_temp, rcx_bmh_argument); jrose@1145: Address prim_value_addr(rbx_temp, java_lang_boxing_object::value_offset_in_bytes(arg_type)); jrose@1145: if (arg_type == T_OBJECT) { jrose@1145: __ movptr(Address(rax_argslot, 0), rbx_temp); jrose@1145: } else { jrose@1145: __ load_sized_value(rbx_temp, prim_value_addr, jrose@1145: type2aelembytes(arg_type), is_signed_subword_type(arg_type)); jrose@1145: __ movptr(Address(rax_argslot, 0), rbx_temp); jrose@1145: #ifndef _LP64 jrose@1145: if (arg_slots == 2) { jrose@1145: __ movl(rbx_temp, prim_value_addr.plus_disp(wordSize)); jrose@1145: __ movl(Address(rax_argslot, Interpreter::stackElementSize()), rbx_temp); jrose@1145: } jrose@1145: #endif //_LP64 jrose@1145: break; jrose@1145: } jrose@1145: jrose@1145: if (direct_to_method) { jrose@1145: Register rbx_method = rbx_temp; jrose@1145: __ movptr(rbx_method, rcx_mh_vmtarget); jrose@1145: __ verify_oop(rbx_method); jrose@1145: __ jmp(rbx_method_fie); jrose@1145: } else { jrose@1145: __ movptr(rcx_recv, rcx_mh_vmtarget); jrose@1145: __ verify_oop(rcx_recv); jrose@1145: __ jump_to_method_handle_entry(rcx_recv, rdx_temp); jrose@1145: } jrose@1145: } jrose@1145: break; jrose@1145: jrose@1145: case _adapter_retype_only: jrose@1145: // immediately jump to the next MH layer: jrose@1145: __ movptr(rcx_recv, rcx_mh_vmtarget); jrose@1145: __ verify_oop(rcx_recv); jrose@1145: __ jump_to_method_handle_entry(rcx_recv, rdx_temp); jrose@1145: // This is OK when all parameter types widen. jrose@1145: // It is also OK when a return type narrows. jrose@1145: break; jrose@1145: jrose@1145: case _adapter_check_cast: jrose@1145: { jrose@1145: // temps: jrose@1145: Register rbx_klass = rbx_temp; // interesting AMH data jrose@1145: jrose@1145: // check a reference argument before jumping to the next layer of MH: jrose@1145: __ movl(rax_argslot, rcx_amh_vmargslot); jrose@1145: vmarg = __ argument_address(rax_argslot); jrose@1145: jrose@1145: // What class are we casting to? jrose@1145: __ movptr(rbx_klass, rcx_amh_argument); // this is a Class object! jrose@1145: __ movptr(rbx_klass, Address(rbx_klass, java_lang_Class::klass_offset_in_bytes())); jrose@1145: jrose@1145: // get the new MH: jrose@1145: __ movptr(rcx_recv, rcx_mh_vmtarget); jrose@1145: // (now we are done with the old MH) jrose@1145: jrose@1145: Label done; jrose@1145: __ movptr(rdx_temp, vmarg); jrose@1145: __ testl(rdx_temp, rdx_temp); jrose@1145: __ jcc(Assembler::zero, done); // no cast if null jrose@1145: __ load_klass(rdx_temp, rdx_temp); jrose@1145: jrose@1145: // live at this point: jrose@1145: // - rbx_klass: klass required by the target method jrose@1145: // - rdx_temp: argument klass to test jrose@1145: // - rcx_recv: method handle to invoke (after cast succeeds) jrose@1145: __ check_klass_subtype(rdx_temp, rbx_klass, rax_argslot, done); jrose@1145: jrose@1145: // If we get here, the type check failed! jrose@1145: // Call the wrong_method_type stub, passing the failing argument type in rax. jrose@1145: Register rax_mtype = rax_argslot; jrose@1145: __ push(rbx_klass); // missed klass (required type) jrose@1145: __ push(rdx_temp); // bad actual type (1st stacked argument) jrose@1145: __ jump(ExternalAddress(Interpreter::throw_WrongMethodType_entry())); jrose@1145: jrose@1145: __ bind(done); jrose@1145: __ jump_to_method_handle_entry(rcx_recv, rdx_temp); jrose@1145: } jrose@1145: break; jrose@1145: jrose@1145: case _adapter_prim_to_prim: jrose@1145: case _adapter_ref_to_prim: jrose@1145: // handled completely by optimized cases jrose@1145: __ stop("init_AdapterMethodHandle should not issue this"); jrose@1145: break; jrose@1145: jrose@1145: case _adapter_opt_i2i: // optimized subcase of adapt_prim_to_prim jrose@1145: //case _adapter_opt_f2i: // optimized subcase of adapt_prim_to_prim jrose@1145: case _adapter_opt_l2i: // optimized subcase of adapt_prim_to_prim jrose@1145: case _adapter_opt_unboxi: // optimized subcase of adapt_ref_to_prim jrose@1145: { jrose@1145: // perform an in-place conversion to int or an int subword jrose@1145: __ movl(rax_argslot, rcx_amh_vmargslot); jrose@1145: vmarg = __ argument_address(rax_argslot); jrose@1145: jrose@1145: switch (ek) { jrose@1145: case _adapter_opt_i2i: jrose@1145: __ movl(rdx_temp, vmarg); jrose@1145: break; jrose@1145: case _adapter_opt_l2i: jrose@1145: { jrose@1145: // just delete the extra slot; on a little-endian machine we keep the first jrose@1145: __ lea(rax_argslot, __ argument_address(rax_argslot, 1)); jrose@1145: remove_arg_slots(_masm, -stack_move_unit(), jrose@1145: rax_argslot, rbx_temp, rdx_temp); jrose@1145: vmarg = Address(rax_argslot, -Interpreter::stackElementSize()); jrose@1145: __ movl(rdx_temp, vmarg); jrose@1145: } jrose@1145: break; jrose@1145: case _adapter_opt_unboxi: jrose@1145: { jrose@1145: // Load the value up from the heap. jrose@1145: __ movptr(rdx_temp, vmarg); jrose@1145: int value_offset = java_lang_boxing_object::value_offset_in_bytes(T_INT); jrose@1145: #ifdef ASSERT jrose@1145: for (int bt = T_BOOLEAN; bt < T_INT; bt++) { jrose@1145: if (is_subword_type(BasicType(bt))) jrose@1145: assert(value_offset == java_lang_boxing_object::value_offset_in_bytes(BasicType(bt)), ""); jrose@1145: } jrose@1145: #endif jrose@1145: __ null_check(rdx_temp, value_offset); jrose@1145: __ movl(rdx_temp, Address(rdx_temp, value_offset)); jrose@1145: // We load this as a word. Because we are little-endian, jrose@1145: // the low bits will be correct, but the high bits may need cleaning. jrose@1145: // The vminfo will guide us to clean those bits. jrose@1145: } jrose@1145: break; jrose@1145: default: jrose@1145: assert(false, ""); jrose@1145: } jrose@1145: goto finish_int_conversion; jrose@1145: } jrose@1145: jrose@1145: finish_int_conversion: jrose@1145: { jrose@1145: Register rbx_vminfo = rbx_temp; jrose@1145: __ movl(rbx_vminfo, rcx_amh_conversion); jrose@1145: assert(CONV_VMINFO_SHIFT == 0, "preshifted"); jrose@1145: jrose@1145: // get the new MH: jrose@1145: __ movptr(rcx_recv, rcx_mh_vmtarget); jrose@1145: // (now we are done with the old MH) jrose@1145: jrose@1145: // original 32-bit vmdata word must be of this form: jrose@1145: // | MBZ:16 | signBitCount:8 | srcDstTypes:8 | conversionOp:8 | jrose@1145: __ xchgl(rcx, rbx_vminfo); // free rcx for shifts jrose@1145: __ shll(rdx_temp /*, rcx*/); jrose@1145: Label zero_extend, done; jrose@1145: __ testl(rcx, CONV_VMINFO_SIGN_FLAG); jrose@1145: __ jcc(Assembler::zero, zero_extend); jrose@1145: jrose@1145: // this path is taken for int->byte, int->short jrose@1145: __ sarl(rdx_temp /*, rcx*/); jrose@1145: __ jmp(done); jrose@1145: jrose@1145: __ bind(zero_extend); jrose@1145: // this is taken for int->char jrose@1145: __ shrl(rdx_temp /*, rcx*/); jrose@1145: jrose@1145: __ bind(done); jrose@1145: __ movptr(vmarg, rdx_temp); jrose@1145: __ xchgl(rcx, rbx_vminfo); // restore rcx_recv jrose@1145: jrose@1145: __ jump_to_method_handle_entry(rcx_recv, rdx_temp); jrose@1145: } jrose@1145: break; jrose@1145: jrose@1145: case _adapter_opt_i2l: // optimized subcase of adapt_prim_to_prim jrose@1145: case _adapter_opt_unboxl: // optimized subcase of adapt_ref_to_prim jrose@1145: { jrose@1145: // perform an in-place int-to-long or ref-to-long conversion jrose@1145: __ movl(rax_argslot, rcx_amh_vmargslot); jrose@1145: jrose@1145: // on a little-endian machine we keep the first slot and add another after jrose@1145: __ lea(rax_argslot, __ argument_address(rax_argslot, 1)); jrose@1145: insert_arg_slots(_masm, stack_move_unit(), _INSERT_INT_MASK, jrose@1145: rax_argslot, rbx_temp, rdx_temp); jrose@1145: Address vmarg1(rax_argslot, -Interpreter::stackElementSize()); jrose@1145: Address vmarg2 = vmarg1.plus_disp(Interpreter::stackElementSize()); jrose@1145: jrose@1145: switch (ek) { jrose@1145: case _adapter_opt_i2l: jrose@1145: { jrose@1145: __ movl(rdx_temp, vmarg1); jrose@1145: __ sarl(rdx_temp, 31); // __ extend_sign() jrose@1145: __ movl(vmarg2, rdx_temp); // store second word jrose@1145: } jrose@1145: break; jrose@1145: case _adapter_opt_unboxl: jrose@1145: { jrose@1145: // Load the value up from the heap. jrose@1145: __ movptr(rdx_temp, vmarg1); jrose@1145: int value_offset = java_lang_boxing_object::value_offset_in_bytes(T_LONG); jrose@1145: assert(value_offset == java_lang_boxing_object::value_offset_in_bytes(T_DOUBLE), ""); jrose@1145: __ null_check(rdx_temp, value_offset); jrose@1145: __ movl(rbx_temp, Address(rdx_temp, value_offset + 0*BytesPerInt)); jrose@1145: __ movl(rdx_temp, Address(rdx_temp, value_offset + 1*BytesPerInt)); jrose@1145: __ movl(vmarg1, rbx_temp); jrose@1145: __ movl(vmarg2, rdx_temp); jrose@1145: } jrose@1145: break; jrose@1145: default: jrose@1145: assert(false, ""); jrose@1145: } jrose@1145: jrose@1145: __ movptr(rcx_recv, rcx_mh_vmtarget); jrose@1145: __ jump_to_method_handle_entry(rcx_recv, rdx_temp); jrose@1145: } jrose@1145: break; jrose@1145: jrose@1145: case _adapter_opt_f2d: // optimized subcase of adapt_prim_to_prim jrose@1145: case _adapter_opt_d2f: // optimized subcase of adapt_prim_to_prim jrose@1145: { jrose@1145: // perform an in-place floating primitive conversion jrose@1145: __ movl(rax_argslot, rcx_amh_vmargslot); jrose@1145: __ lea(rax_argslot, __ argument_address(rax_argslot, 1)); jrose@1145: if (ek == _adapter_opt_f2d) { jrose@1145: insert_arg_slots(_masm, stack_move_unit(), _INSERT_INT_MASK, jrose@1145: rax_argslot, rbx_temp, rdx_temp); jrose@1145: } jrose@1145: Address vmarg(rax_argslot, -Interpreter::stackElementSize()); jrose@1145: jrose@1145: #ifdef _LP64 jrose@1145: if (ek == _adapter_opt_f2d) { jrose@1145: __ movflt(xmm0, vmarg); jrose@1145: __ cvtss2sd(xmm0, xmm0); jrose@1145: __ movdbl(vmarg, xmm0); jrose@1145: } else { jrose@1145: __ movdbl(xmm0, vmarg); jrose@1145: __ cvtsd2ss(xmm0, xmm0); jrose@1145: __ movflt(vmarg, xmm0); jrose@1145: } jrose@1145: #else //_LP64 jrose@1145: if (ek == _adapter_opt_f2d) { jrose@1145: __ fld_s(vmarg); // load float to ST0 jrose@1145: __ fstp_s(vmarg); // store single jrose@1145: } else if (!TaggedStackInterpreter) { jrose@1145: __ fld_d(vmarg); // load double to ST0 jrose@1145: __ fstp_s(vmarg); // store single jrose@1145: } else { jrose@1145: Address vmarg_tag = vmarg.plus_disp(tag_offset); jrose@1145: Address vmarg2 = vmarg.plus_disp(Interpreter::stackElementSize()); jrose@1145: // vmarg2_tag does not participate in this code jrose@1145: Register rbx_tag = rbx_temp; jrose@1145: __ movl(rbx_tag, vmarg_tag); // preserve tag jrose@1145: __ movl(rdx_temp, vmarg2); // get second word of double jrose@1145: __ movl(vmarg_tag, rdx_temp); // align with first word jrose@1145: __ fld_d(vmarg); // load double to ST0 jrose@1145: __ movl(vmarg_tag, rbx_tag); // restore tag jrose@1145: __ fstp_s(vmarg); // store single jrose@1145: } jrose@1145: #endif //_LP64 jrose@1145: jrose@1145: if (ek == _adapter_opt_d2f) { jrose@1145: remove_arg_slots(_masm, -stack_move_unit(), jrose@1145: rax_argslot, rbx_temp, rdx_temp); jrose@1145: } jrose@1145: jrose@1145: __ movptr(rcx_recv, rcx_mh_vmtarget); jrose@1145: __ jump_to_method_handle_entry(rcx_recv, rdx_temp); jrose@1145: } jrose@1145: break; jrose@1145: jrose@1145: case _adapter_prim_to_ref: jrose@1145: __ unimplemented(entry_name(ek)); // %%% FIXME: NYI jrose@1145: break; jrose@1145: jrose@1145: case _adapter_swap_args: jrose@1145: case _adapter_rot_args: jrose@1145: // handled completely by optimized cases jrose@1145: __ stop("init_AdapterMethodHandle should not issue this"); jrose@1145: break; jrose@1145: jrose@1145: case _adapter_opt_swap_1: jrose@1145: case _adapter_opt_swap_2: jrose@1145: case _adapter_opt_rot_1_up: jrose@1145: case _adapter_opt_rot_1_down: jrose@1145: case _adapter_opt_rot_2_up: jrose@1145: case _adapter_opt_rot_2_down: jrose@1145: { jrose@1145: int rotate = 0, swap_slots = 0; jrose@1145: switch ((int)ek) { jrose@1145: case _adapter_opt_swap_1: swap_slots = 1; break; jrose@1145: case _adapter_opt_swap_2: swap_slots = 2; break; jrose@1145: case _adapter_opt_rot_1_up: swap_slots = 1; rotate++; break; jrose@1145: case _adapter_opt_rot_1_down: swap_slots = 1; rotate--; break; jrose@1145: case _adapter_opt_rot_2_up: swap_slots = 2; rotate++; break; jrose@1145: case _adapter_opt_rot_2_down: swap_slots = 2; rotate--; break; jrose@1145: default: assert(false, ""); jrose@1145: } jrose@1145: jrose@1145: // the real size of the move must be doubled if TaggedStackInterpreter: jrose@1145: int swap_bytes = (int)( swap_slots * Interpreter::stackElementWords() * wordSize ); jrose@1145: jrose@1145: // 'argslot' is the position of the first argument to swap jrose@1145: __ movl(rax_argslot, rcx_amh_vmargslot); jrose@1145: __ lea(rax_argslot, __ argument_address(rax_argslot)); jrose@1145: jrose@1145: // 'vminfo' is the second jrose@1145: Register rbx_destslot = rbx_temp; jrose@1145: __ movl(rbx_destslot, rcx_amh_conversion); jrose@1145: assert(CONV_VMINFO_SHIFT == 0, "preshifted"); jrose@1145: __ andl(rbx_destslot, CONV_VMINFO_MASK); jrose@1145: __ lea(rbx_destslot, __ argument_address(rbx_destslot)); jrose@1145: DEBUG_ONLY(verify_argslot(_masm, rbx_destslot, "swap point must fall within current frame")); jrose@1145: jrose@1145: if (!rotate) { jrose@1145: for (int i = 0; i < swap_bytes; i += wordSize) { jrose@1145: __ movptr(rdx_temp, Address(rax_argslot , i)); jrose@1145: __ push(rdx_temp); jrose@1145: __ movptr(rdx_temp, Address(rbx_destslot, i)); jrose@1145: __ movptr(Address(rax_argslot, i), rdx_temp); jrose@1145: __ pop(rdx_temp); jrose@1145: __ movptr(Address(rbx_destslot, i), rdx_temp); jrose@1145: } jrose@1145: } else { jrose@1145: // push the first chunk, which is going to get overwritten jrose@1145: for (int i = swap_bytes; (i -= wordSize) >= 0; ) { jrose@1145: __ movptr(rdx_temp, Address(rax_argslot, i)); jrose@1145: __ push(rdx_temp); jrose@1145: } jrose@1145: jrose@1145: if (rotate > 0) { jrose@1145: // rotate upward jrose@1145: __ subptr(rax_argslot, swap_bytes); jrose@1145: #ifdef ASSERT jrose@1145: { jrose@1145: // Verify that argslot > destslot, by at least swap_bytes. jrose@1145: Label L_ok; jrose@1145: __ cmpptr(rax_argslot, rbx_destslot); jrose@1145: __ jcc(Assembler::aboveEqual, L_ok); jrose@1145: __ stop("source must be above destination (upward rotation)"); jrose@1145: __ bind(L_ok); jrose@1145: } jrose@1145: #endif jrose@1145: // work argslot down to destslot, copying contiguous data upwards jrose@1145: // pseudo-code: jrose@1145: // rax = src_addr - swap_bytes jrose@1145: // rbx = dest_addr jrose@1145: // while (rax >= rbx) *(rax + swap_bytes) = *(rax + 0), rax--; jrose@1145: Label loop; jrose@1145: __ bind(loop); jrose@1145: __ movptr(rdx_temp, Address(rax_argslot, 0)); jrose@1145: __ movptr(Address(rax_argslot, swap_bytes), rdx_temp); jrose@1145: __ addptr(rax_argslot, -wordSize); jrose@1145: __ cmpptr(rax_argslot, rbx_destslot); jrose@1145: __ jcc(Assembler::aboveEqual, loop); jrose@1145: } else { jrose@1145: __ addptr(rax_argslot, swap_bytes); jrose@1145: #ifdef ASSERT jrose@1145: { jrose@1145: // Verify that argslot < destslot, by at least swap_bytes. jrose@1145: Label L_ok; jrose@1145: __ cmpptr(rax_argslot, rbx_destslot); jrose@1145: __ jcc(Assembler::belowEqual, L_ok); jrose@1145: __ stop("source must be below destination (downward rotation)"); jrose@1145: __ bind(L_ok); jrose@1145: } jrose@1145: #endif jrose@1145: // work argslot up to destslot, copying contiguous data downwards jrose@1145: // pseudo-code: jrose@1145: // rax = src_addr + swap_bytes jrose@1145: // rbx = dest_addr jrose@1145: // while (rax <= rbx) *(rax - swap_bytes) = *(rax + 0), rax++; jrose@1145: Label loop; jrose@1145: __ bind(loop); jrose@1145: __ movptr(rdx_temp, Address(rax_argslot, 0)); jrose@1145: __ movptr(Address(rax_argslot, -swap_bytes), rdx_temp); jrose@1145: __ addptr(rax_argslot, wordSize); jrose@1145: __ cmpptr(rax_argslot, rbx_destslot); jrose@1145: __ jcc(Assembler::belowEqual, loop); jrose@1145: } jrose@1145: jrose@1145: // pop the original first chunk into the destination slot, now free jrose@1145: for (int i = 0; i < swap_bytes; i += wordSize) { jrose@1145: __ pop(rdx_temp); jrose@1145: __ movptr(Address(rbx_destslot, i), rdx_temp); jrose@1145: } jrose@1145: } jrose@1145: jrose@1145: __ movptr(rcx_recv, rcx_mh_vmtarget); jrose@1145: __ jump_to_method_handle_entry(rcx_recv, rdx_temp); jrose@1145: } jrose@1145: break; jrose@1145: jrose@1145: case _adapter_dup_args: jrose@1145: { jrose@1145: // 'argslot' is the position of the first argument to duplicate jrose@1145: __ movl(rax_argslot, rcx_amh_vmargslot); jrose@1145: __ lea(rax_argslot, __ argument_address(rax_argslot)); jrose@1145: jrose@1145: // 'stack_move' is negative number of words to duplicate jrose@1145: Register rdx_stack_move = rdx_temp; jrose@1145: __ movl(rdx_stack_move, rcx_amh_conversion); jrose@1145: __ sarl(rdx_stack_move, CONV_STACK_MOVE_SHIFT); jrose@1145: jrose@1145: int argslot0_num = 0; jrose@1145: Address argslot0 = __ argument_address(RegisterOrConstant(argslot0_num)); jrose@1145: assert(argslot0.base() == rsp, ""); jrose@1145: int pre_arg_size = argslot0.disp(); jrose@1145: assert(pre_arg_size % wordSize == 0, ""); jrose@1145: assert(pre_arg_size > 0, "must include PC"); jrose@1145: jrose@1145: // remember the old rsp+1 (argslot[0]) jrose@1145: Register rbx_oldarg = rbx_temp; jrose@1145: __ lea(rbx_oldarg, argslot0); jrose@1145: jrose@1145: // move rsp down to make room for dups jrose@1145: __ lea(rsp, Address(rsp, rdx_stack_move, Address::times_ptr)); jrose@1145: jrose@1145: // compute the new rsp+1 (argslot[0]) jrose@1145: Register rdx_newarg = rdx_temp; jrose@1145: __ lea(rdx_newarg, argslot0); jrose@1145: jrose@1145: __ push(rdi); // need a temp jrose@1145: // (preceding push must be done after arg addresses are taken!) jrose@1145: jrose@1145: // pull down the pre_arg_size data (PC) jrose@1145: for (int i = -pre_arg_size; i < 0; i += wordSize) { jrose@1145: __ movptr(rdi, Address(rbx_oldarg, i)); jrose@1145: __ movptr(Address(rdx_newarg, i), rdi); jrose@1145: } jrose@1145: jrose@1145: // copy from rax_argslot[0...] down to new_rsp[1...] jrose@1145: // pseudo-code: jrose@1145: // rbx = old_rsp+1 jrose@1145: // rdx = new_rsp+1 jrose@1145: // rax = argslot jrose@1145: // while (rdx < rbx) *rdx++ = *rax++ jrose@1145: Label loop; jrose@1145: __ bind(loop); jrose@1145: __ movptr(rdi, Address(rax_argslot, 0)); jrose@1145: __ movptr(Address(rdx_newarg, 0), rdi); jrose@1145: __ addptr(rax_argslot, wordSize); jrose@1145: __ addptr(rdx_newarg, wordSize); jrose@1145: __ cmpptr(rdx_newarg, rbx_oldarg); jrose@1145: __ jcc(Assembler::less, loop); jrose@1145: jrose@1145: __ pop(rdi); // restore temp jrose@1145: jrose@1145: __ movptr(rcx_recv, rcx_mh_vmtarget); jrose@1145: __ jump_to_method_handle_entry(rcx_recv, rdx_temp); jrose@1145: } jrose@1145: break; jrose@1145: jrose@1145: case _adapter_drop_args: jrose@1145: { jrose@1145: // 'argslot' is the position of the first argument to nuke jrose@1145: __ movl(rax_argslot, rcx_amh_vmargslot); jrose@1145: __ lea(rax_argslot, __ argument_address(rax_argslot)); jrose@1145: jrose@1145: __ push(rdi); // need a temp jrose@1145: // (must do previous push after argslot address is taken) jrose@1145: jrose@1145: // 'stack_move' is number of words to drop jrose@1145: Register rdi_stack_move = rdi; jrose@1145: __ movl(rdi_stack_move, rcx_amh_conversion); jrose@1145: __ sarl(rdi_stack_move, CONV_STACK_MOVE_SHIFT); jrose@1145: remove_arg_slots(_masm, rdi_stack_move, jrose@1145: rax_argslot, rbx_temp, rdx_temp); jrose@1145: jrose@1145: __ pop(rdi); // restore temp jrose@1145: jrose@1145: __ movptr(rcx_recv, rcx_mh_vmtarget); jrose@1145: __ jump_to_method_handle_entry(rcx_recv, rdx_temp); jrose@1145: } jrose@1145: break; jrose@1145: jrose@1145: case _adapter_collect_args: jrose@1145: __ unimplemented(entry_name(ek)); // %%% FIXME: NYI jrose@1145: break; jrose@1145: jrose@1145: case _adapter_spread_args: jrose@1145: // handled completely by optimized cases jrose@1145: __ stop("init_AdapterMethodHandle should not issue this"); jrose@1145: break; jrose@1145: jrose@1145: case _adapter_opt_spread_0: jrose@1145: case _adapter_opt_spread_1: jrose@1145: case _adapter_opt_spread_more: jrose@1145: { jrose@1145: // spread an array out into a group of arguments jrose@1145: int length_constant = -1; jrose@1145: switch (ek) { jrose@1145: case _adapter_opt_spread_0: length_constant = 0; break; jrose@1145: case _adapter_opt_spread_1: length_constant = 1; break; jrose@1145: } jrose@1145: jrose@1145: // find the address of the array argument jrose@1145: __ movl(rax_argslot, rcx_amh_vmargslot); jrose@1145: __ lea(rax_argslot, __ argument_address(rax_argslot)); jrose@1145: jrose@1145: // grab some temps jrose@1145: { __ push(rsi); __ push(rdi); } jrose@1145: // (preceding pushes must be done after argslot address is taken!) jrose@1145: #define UNPUSH_RSI_RDI \ jrose@1145: { __ pop(rdi); __ pop(rsi); } jrose@1145: jrose@1145: // arx_argslot points both to the array and to the first output arg jrose@1145: vmarg = Address(rax_argslot, 0); jrose@1145: jrose@1145: // Get the array value. jrose@1145: Register rsi_array = rsi; jrose@1145: Register rdx_array_klass = rdx_temp; jrose@1145: BasicType elem_type = T_OBJECT; jrose@1145: int length_offset = arrayOopDesc::length_offset_in_bytes(); jrose@1145: int elem0_offset = arrayOopDesc::base_offset_in_bytes(elem_type); jrose@1145: __ movptr(rsi_array, vmarg); jrose@1145: Label skip_array_check; jrose@1145: if (length_constant == 0) { jrose@1145: __ testptr(rsi_array, rsi_array); jrose@1145: __ jcc(Assembler::zero, skip_array_check); jrose@1145: } jrose@1145: __ null_check(rsi_array, oopDesc::klass_offset_in_bytes()); jrose@1145: __ load_klass(rdx_array_klass, rsi_array); jrose@1145: jrose@1145: // Check the array type. jrose@1145: Register rbx_klass = rbx_temp; jrose@1145: __ movptr(rbx_klass, rcx_amh_argument); // this is a Class object! jrose@1145: __ movptr(rbx_klass, Address(rbx_klass, java_lang_Class::klass_offset_in_bytes())); jrose@1145: jrose@1145: Label ok_array_klass, bad_array_klass, bad_array_length; jrose@1145: __ check_klass_subtype(rdx_array_klass, rbx_klass, rdi, ok_array_klass); jrose@1145: // If we get here, the type check failed! jrose@1145: __ jmp(bad_array_klass); jrose@1145: __ bind(ok_array_klass); jrose@1145: jrose@1145: // Check length. jrose@1145: if (length_constant >= 0) { jrose@1145: __ cmpl(Address(rsi_array, length_offset), length_constant); jrose@1145: } else { jrose@1145: Register rbx_vminfo = rbx_temp; jrose@1145: __ movl(rbx_vminfo, rcx_amh_conversion); jrose@1145: assert(CONV_VMINFO_SHIFT == 0, "preshifted"); jrose@1145: __ andl(rbx_vminfo, CONV_VMINFO_MASK); jrose@1145: __ cmpl(rbx_vminfo, Address(rsi_array, length_offset)); jrose@1145: } jrose@1145: __ jcc(Assembler::notEqual, bad_array_length); jrose@1145: jrose@1145: Register rdx_argslot_limit = rdx_temp; jrose@1145: jrose@1145: // Array length checks out. Now insert any required stack slots. jrose@1145: if (length_constant == -1) { jrose@1145: // Form a pointer to the end of the affected region. jrose@1145: __ lea(rdx_argslot_limit, Address(rax_argslot, Interpreter::stackElementSize())); jrose@1145: // 'stack_move' is negative number of words to insert jrose@1145: Register rdi_stack_move = rdi; jrose@1145: __ movl(rdi_stack_move, rcx_amh_conversion); jrose@1145: __ sarl(rdi_stack_move, CONV_STACK_MOVE_SHIFT); jrose@1145: Register rsi_temp = rsi_array; // spill this jrose@1145: insert_arg_slots(_masm, rdi_stack_move, -1, jrose@1145: rax_argslot, rbx_temp, rsi_temp); jrose@1145: // reload the array (since rsi was killed) jrose@1145: __ movptr(rsi_array, vmarg); jrose@1145: } else if (length_constant > 1) { jrose@1145: int arg_mask = 0; jrose@1145: int new_slots = (length_constant - 1); jrose@1145: for (int i = 0; i < new_slots; i++) { jrose@1145: arg_mask <<= 1; jrose@1145: arg_mask |= _INSERT_REF_MASK; jrose@1145: } jrose@1145: insert_arg_slots(_masm, new_slots * stack_move_unit(), arg_mask, jrose@1145: rax_argslot, rbx_temp, rdx_temp); jrose@1145: } else if (length_constant == 1) { jrose@1145: // no stack resizing required jrose@1145: } else if (length_constant == 0) { jrose@1145: remove_arg_slots(_masm, -stack_move_unit(), jrose@1145: rax_argslot, rbx_temp, rdx_temp); jrose@1145: } jrose@1145: jrose@1145: // Copy from the array to the new slots. jrose@1145: // Note: Stack change code preserves integrity of rax_argslot pointer. jrose@1145: // So even after slot insertions, rax_argslot still points to first argument. jrose@1145: if (length_constant == -1) { jrose@1145: // [rax_argslot, rdx_argslot_limit) is the area we are inserting into. jrose@1145: Register rsi_source = rsi_array; jrose@1145: __ lea(rsi_source, Address(rsi_array, elem0_offset)); jrose@1145: Label loop; jrose@1145: __ bind(loop); jrose@1145: __ movptr(rbx_temp, Address(rsi_source, 0)); jrose@1145: __ movptr(Address(rax_argslot, 0), rbx_temp); jrose@1145: __ addptr(rsi_source, type2aelembytes(elem_type)); jrose@1145: if (TaggedStackInterpreter) { jrose@1145: __ movptr(Address(rax_argslot, tag_offset), jrose@1145: frame::tag_for_basic_type(elem_type)); jrose@1145: } jrose@1145: __ addptr(rax_argslot, Interpreter::stackElementSize()); jrose@1145: __ cmpptr(rax_argslot, rdx_argslot_limit); jrose@1145: __ jcc(Assembler::less, loop); jrose@1145: } else if (length_constant == 0) { jrose@1145: __ bind(skip_array_check); jrose@1145: // nothing to copy jrose@1145: } else { jrose@1145: int elem_offset = elem0_offset; jrose@1145: int slot_offset = 0; jrose@1145: for (int index = 0; index < length_constant; index++) { jrose@1145: __ movptr(rbx_temp, Address(rsi_array, elem_offset)); jrose@1145: __ movptr(Address(rax_argslot, slot_offset), rbx_temp); jrose@1145: elem_offset += type2aelembytes(elem_type); jrose@1145: if (TaggedStackInterpreter) { jrose@1145: __ movptr(Address(rax_argslot, slot_offset + tag_offset), jrose@1145: frame::tag_for_basic_type(elem_type)); jrose@1145: } jrose@1145: slot_offset += Interpreter::stackElementSize(); jrose@1145: } jrose@1145: } jrose@1145: jrose@1145: // Arguments are spread. Move to next method handle. jrose@1145: UNPUSH_RSI_RDI; jrose@1145: __ movptr(rcx_recv, rcx_mh_vmtarget); jrose@1145: __ jump_to_method_handle_entry(rcx_recv, rdx_temp); jrose@1145: jrose@1145: __ bind(bad_array_klass); jrose@1145: UNPUSH_RSI_RDI; jrose@1145: __ stop("bad array klass NYI"); jrose@1145: jrose@1145: __ bind(bad_array_length); jrose@1145: UNPUSH_RSI_RDI; jrose@1145: __ stop("bad array length NYI"); jrose@1145: jrose@1145: #undef UNPUSH_RSI_RDI jrose@1145: } jrose@1145: break; jrose@1145: jrose@1145: case _adapter_flyby: jrose@1145: case _adapter_ricochet: jrose@1145: __ unimplemented(entry_name(ek)); // %%% FIXME: NYI jrose@1145: break; jrose@1145: jrose@1145: default: ShouldNotReachHere(); jrose@1145: } jrose@1145: __ hlt(); jrose@1145: jrose@1145: address me_cookie = MethodHandleEntry::start_compiled_entry(_masm, interp_entry); jrose@1145: __ unimplemented(entry_name(ek)); // %%% FIXME: NYI jrose@1145: jrose@1145: init_entry(ek, MethodHandleEntry::finish_compiled_entry(_masm, me_cookie)); jrose@1145: }