aoqi@0: /* aoqi@0: * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@1: /* aoqi@1: * This file has been modified by Loongson Technology in 2015. These aoqi@1: * modifications are Copyright (c) 2015 Loongson Technology, and are made aoqi@1: * available on the same license terms set forth above. aoqi@1: */ aoqi@1: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "c1/c1_FrameMap.hpp" aoqi@0: #include "c1/c1_LIR.hpp" aoqi@0: #include "runtime/sharedRuntime.hpp" aoqi@0: #ifdef TARGET_ARCH_x86 aoqi@0: # include "vmreg_x86.inline.hpp" aoqi@0: #endif aoqi@1: #ifdef TARGET_ARCH_mips aoqi@1: # include "vmreg_mips.inline.hpp" aoqi@1: #endif aoqi@0: #ifdef TARGET_ARCH_sparc aoqi@0: # include "vmreg_sparc.inline.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_zero aoqi@0: # include "vmreg_zero.inline.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_arm aoqi@0: # include "vmreg_arm.inline.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_ppc aoqi@0: # include "vmreg_ppc.inline.hpp" aoqi@0: #endif aoqi@0: aoqi@0: aoqi@0: aoqi@0: //----------------------------------------------------- aoqi@0: aoqi@0: // Convert method signature into an array of BasicTypes for the arguments aoqi@0: BasicTypeArray* FrameMap::signature_type_array_for(const ciMethod* method) { aoqi@0: ciSignature* sig = method->signature(); aoqi@0: BasicTypeList* sta = new BasicTypeList(method->arg_size()); aoqi@0: // add receiver, if any aoqi@0: if (!method->is_static()) sta->append(T_OBJECT); aoqi@0: // add remaining arguments aoqi@0: for (int i = 0; i < sig->count(); i++) { aoqi@0: ciType* type = sig->type_at(i); aoqi@0: BasicType t = type->basic_type(); aoqi@0: if (t == T_ARRAY) { aoqi@0: t = T_OBJECT; aoqi@0: } aoqi@0: sta->append(t); aoqi@0: } aoqi@0: // done aoqi@0: return sta; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: CallingConvention* FrameMap::java_calling_convention(const BasicTypeArray* signature, bool outgoing) { aoqi@0: // compute the size of the arguments first. The signature array aoqi@0: // that java_calling_convention takes includes a T_VOID after double aoqi@0: // work items but our signatures do not. aoqi@0: int i; aoqi@0: int sizeargs = 0; aoqi@0: for (i = 0; i < signature->length(); i++) { aoqi@0: sizeargs += type2size[signature->at(i)]; aoqi@0: } aoqi@0: aoqi@0: BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs); aoqi@0: VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs); aoqi@0: int sig_index = 0; aoqi@0: for (i = 0; i < sizeargs; i++, sig_index++) { aoqi@0: sig_bt[i] = signature->at(sig_index); aoqi@0: if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) { aoqi@0: sig_bt[i + 1] = T_VOID; aoqi@0: i++; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: intptr_t out_preserve = SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs, outgoing); aoqi@0: LIR_OprList* args = new LIR_OprList(signature->length()); aoqi@0: for (i = 0; i < sizeargs;) { aoqi@0: BasicType t = sig_bt[i]; aoqi@0: assert(t != T_VOID, "should be skipping these"); aoqi@0: LIR_Opr opr = map_to_opr(t, regs + i, outgoing); aoqi@0: args->append(opr); aoqi@0: if (opr->is_address()) { aoqi@0: LIR_Address* addr = opr->as_address_ptr(); aoqi@0: assert(addr->disp() == (int)addr->disp(), "out of range value"); aoqi@0: out_preserve = MAX2(out_preserve, (intptr_t)(addr->disp() - STACK_BIAS) / 4); aoqi@0: } aoqi@0: i += type2size[t]; aoqi@0: } aoqi@0: assert(args->length() == signature->length(), "size mismatch"); aoqi@0: out_preserve += SharedRuntime::out_preserve_stack_slots(); aoqi@0: aoqi@0: if (outgoing) { aoqi@0: // update the space reserved for arguments. aoqi@0: update_reserved_argument_area_size(out_preserve * BytesPerWord); aoqi@0: } aoqi@0: return new CallingConvention(args, out_preserve); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: CallingConvention* FrameMap::c_calling_convention(const BasicTypeArray* signature) { aoqi@0: // compute the size of the arguments first. The signature array aoqi@0: // that java_calling_convention takes includes a T_VOID after double aoqi@0: // work items but our signatures do not. aoqi@0: int i; aoqi@0: int sizeargs = 0; aoqi@0: for (i = 0; i < signature->length(); i++) { aoqi@0: sizeargs += type2size[signature->at(i)]; aoqi@0: } aoqi@0: aoqi@0: BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs); aoqi@0: VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs); aoqi@0: int sig_index = 0; aoqi@0: for (i = 0; i < sizeargs; i++, sig_index++) { aoqi@0: sig_bt[i] = signature->at(sig_index); aoqi@0: if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) { aoqi@0: sig_bt[i + 1] = T_VOID; aoqi@0: i++; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: intptr_t out_preserve = SharedRuntime::c_calling_convention(sig_bt, regs, NULL, sizeargs); aoqi@0: LIR_OprList* args = new LIR_OprList(signature->length()); aoqi@0: for (i = 0; i < sizeargs;) { aoqi@0: BasicType t = sig_bt[i]; aoqi@0: assert(t != T_VOID, "should be skipping these"); aoqi@0: aoqi@0: // C calls are always outgoing aoqi@0: bool outgoing = true; aoqi@0: LIR_Opr opr = map_to_opr(t, regs + i, outgoing); aoqi@0: // they might be of different types if for instance floating point aoqi@0: // values are passed in cpu registers, but the sizes must match. aoqi@0: assert(type2size[opr->type()] == type2size[t], "type mismatch"); aoqi@0: args->append(opr); aoqi@0: if (opr->is_address()) { aoqi@0: LIR_Address* addr = opr->as_address_ptr(); aoqi@0: out_preserve = MAX2(out_preserve, (intptr_t)(addr->disp() - STACK_BIAS) / 4); aoqi@0: } aoqi@0: i += type2size[t]; aoqi@0: } aoqi@0: assert(args->length() == signature->length(), "size mismatch"); aoqi@0: out_preserve += SharedRuntime::out_preserve_stack_slots(); aoqi@0: update_reserved_argument_area_size(out_preserve * BytesPerWord); aoqi@0: return new CallingConvention(args, out_preserve); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: //-------------------------------------------------------- aoqi@0: // FrameMap aoqi@0: //-------------------------------------------------------- aoqi@0: aoqi@0: bool FrameMap::_init_done = false; aoqi@0: Register FrameMap::_cpu_rnr2reg [FrameMap::nof_cpu_regs]; aoqi@0: int FrameMap::_cpu_reg2rnr [FrameMap::nof_cpu_regs]; aoqi@0: aoqi@0: aoqi@0: FrameMap::FrameMap(ciMethod* method, int monitors, int reserved_argument_area_size) { aoqi@0: assert(_init_done, "should already be completed"); aoqi@0: aoqi@0: _framesize = -1; aoqi@0: _num_spills = -1; aoqi@0: aoqi@0: assert(monitors >= 0, "not set"); aoqi@0: _num_monitors = monitors; aoqi@0: assert(reserved_argument_area_size >= 0, "not set"); aoqi@0: _reserved_argument_area_size = MAX2(4, reserved_argument_area_size) * BytesPerWord; aoqi@0: aoqi@0: _argcount = method->arg_size(); aoqi@0: _argument_locations = new intArray(_argcount, -1); aoqi@0: _incoming_arguments = java_calling_convention(signature_type_array_for(method), false); aoqi@0: _oop_map_arg_count = _incoming_arguments->reserved_stack_slots(); aoqi@0: aoqi@0: int java_index = 0; aoqi@0: for (int i = 0; i < _incoming_arguments->length(); i++) { aoqi@0: LIR_Opr opr = _incoming_arguments->at(i); aoqi@0: if (opr->is_address()) { aoqi@0: LIR_Address* address = opr->as_address_ptr(); aoqi@0: _argument_locations->at_put(java_index, address->disp() - STACK_BIAS); aoqi@0: _incoming_arguments->args()->at_put(i, LIR_OprFact::stack(java_index, as_BasicType(as_ValueType(address->type())))); aoqi@0: } aoqi@0: java_index += type2size[opr->type()]; aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool FrameMap::finalize_frame(int nof_slots) { aoqi@0: assert(nof_slots >= 0, "must be positive"); aoqi@0: assert(_num_spills == -1, "can only be set once"); aoqi@0: _num_spills = nof_slots; aoqi@0: assert(_framesize == -1, "should only be calculated once"); aoqi@0: _framesize = round_to(in_bytes(sp_offset_for_monitor_base(0)) + aoqi@0: _num_monitors * sizeof(BasicObjectLock) + aoqi@0: sizeof(intptr_t) + // offset of deopt orig pc aoqi@0: frame_pad_in_bytes, aoqi@0: StackAlignmentInBytes) / 4; aoqi@0: int java_index = 0; aoqi@0: for (int i = 0; i < _incoming_arguments->length(); i++) { aoqi@0: LIR_Opr opr = _incoming_arguments->at(i); aoqi@0: if (opr->is_stack()) { aoqi@0: _argument_locations->at_put(java_index, in_bytes(framesize_in_bytes()) + aoqi@0: _argument_locations->at(java_index)); aoqi@0: } aoqi@0: java_index += type2size[opr->type()]; aoqi@0: } aoqi@0: // make sure it's expressible on the platform aoqi@0: return validate_frame(); aoqi@0: } aoqi@0: aoqi@0: VMReg FrameMap::sp_offset2vmreg(ByteSize offset) const { aoqi@0: int offset_in_bytes = in_bytes(offset); aoqi@0: assert(offset_in_bytes % 4 == 0, "must be multiple of 4 bytes"); aoqi@0: assert(offset_in_bytes / 4 < framesize() + oop_map_arg_count(), "out of range"); aoqi@0: return VMRegImpl::stack2reg(offset_in_bytes / 4); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool FrameMap::location_for_sp_offset(ByteSize byte_offset_from_sp, aoqi@0: Location::Type loc_type, aoqi@0: Location* loc) const { aoqi@0: int offset = in_bytes(byte_offset_from_sp); aoqi@0: assert(offset >= 0, "incorrect offset"); aoqi@0: if (!Location::legal_offset_in_bytes(offset)) { aoqi@0: return false; aoqi@0: } aoqi@0: Location tmp_loc = Location::new_stk_loc(loc_type, offset); aoqi@0: *loc = tmp_loc; aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool FrameMap::locations_for_slot (int index, Location::Type loc_type, aoqi@0: Location* loc, Location* second) const { aoqi@0: ByteSize offset_from_sp = sp_offset_for_slot(index); aoqi@0: if (!location_for_sp_offset(offset_from_sp, loc_type, loc)) { aoqi@0: return false; aoqi@0: } aoqi@0: if (second != NULL) { aoqi@0: // two word item aoqi@0: offset_from_sp = offset_from_sp + in_ByteSize(4); aoqi@0: return location_for_sp_offset(offset_from_sp, loc_type, second); aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: ////////////////////// aoqi@0: // Public accessors // aoqi@0: ////////////////////// aoqi@0: aoqi@0: aoqi@0: ByteSize FrameMap::sp_offset_for_slot(const int index) const { aoqi@0: if (index < argcount()) { aoqi@0: int offset = _argument_locations->at(index); aoqi@0: assert(offset != -1, "not a memory argument"); aoqi@0: assert(offset >= framesize() * 4, "argument inside of frame"); aoqi@0: return in_ByteSize(offset); aoqi@0: } aoqi@0: ByteSize offset = sp_offset_for_spill(index - argcount()); aoqi@0: assert(in_bytes(offset) < framesize() * 4, "spill outside of frame"); aoqi@0: return offset; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: ByteSize FrameMap::sp_offset_for_double_slot(const int index) const { aoqi@0: ByteSize offset = sp_offset_for_slot(index); aoqi@0: if (index >= argcount()) { aoqi@0: assert(in_bytes(offset) + 4 < framesize() * 4, "spill outside of frame"); aoqi@0: } aoqi@0: return offset; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: ByteSize FrameMap::sp_offset_for_spill(const int index) const { aoqi@0: assert(index >= 0 && index < _num_spills, "out of range"); aoqi@0: int offset = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) + aoqi@0: index * spill_slot_size_in_bytes; aoqi@0: return in_ByteSize(offset); aoqi@0: } aoqi@0: aoqi@0: ByteSize FrameMap::sp_offset_for_monitor_base(const int index) const { aoqi@0: int end_of_spills = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) + aoqi@0: _num_spills * spill_slot_size_in_bytes; aoqi@0: int offset = (int) round_to(end_of_spills, HeapWordSize) + index * sizeof(BasicObjectLock); aoqi@0: return in_ByteSize(offset); aoqi@0: } aoqi@0: aoqi@0: ByteSize FrameMap::sp_offset_for_monitor_lock(int index) const { aoqi@0: check_monitor_index(index); aoqi@0: return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::lock_offset_in_bytes());; aoqi@0: } aoqi@0: aoqi@0: ByteSize FrameMap::sp_offset_for_monitor_object(int index) const { aoqi@0: check_monitor_index(index); aoqi@0: return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::obj_offset_in_bytes()); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // For OopMaps, map a local variable or spill index to an VMReg. aoqi@0: // This is the offset from sp() in the frame of the slot for the index, aoqi@0: // skewed by SharedInfo::stack0 to indicate a stack location (vs.a register.) aoqi@0: // aoqi@0: // C ABI size + aoqi@0: // framesize + framesize + aoqi@0: // stack0 stack0 stack0 0 <- VMReg->value() aoqi@0: // | | | | aoqi@0: // ..........|..............|..............|.............| aoqi@0: // 0 1 2 3 | | 4 5 6 ...... | <- local indices aoqi@0: // ^ ^ sp() aoqi@0: // | | aoqi@0: // arguments non-argument locals aoqi@0: aoqi@0: aoqi@0: VMReg FrameMap::regname(LIR_Opr opr) const { aoqi@0: if (opr->is_single_cpu()) { aoqi@0: assert(!opr->is_virtual(), "should not see virtual registers here"); aoqi@0: return opr->as_register()->as_VMReg(); aoqi@0: } else if (opr->is_single_stack()) { aoqi@0: return sp_offset2vmreg(sp_offset_for_slot(opr->single_stack_ix())); aoqi@0: } else if (opr->is_address()) { aoqi@0: LIR_Address* addr = opr->as_address_ptr(); aoqi@0: assert(addr->base() == stack_pointer(), "sp based addressing only"); aoqi@0: return sp_offset2vmreg(in_ByteSize(addr->index()->as_jint())); aoqi@0: } aoqi@0: ShouldNotReachHere(); aoqi@0: return VMRegImpl::Bad(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: aoqi@0: aoqi@0: // ------------ extra spill slots ---------------