Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/c1/c1_FrameMap.cpp
32285 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "c1/c1_FrameMap.hpp"26#include "c1/c1_LIR.hpp"27#include "runtime/sharedRuntime.hpp"28#ifdef TARGET_ARCH_x8629# include "vmreg_x86.inline.hpp"30#endif31#ifdef TARGET_ARCH_aarch6432# include "vmreg_aarch64.inline.hpp"33#endif34#ifdef TARGET_ARCH_sparc35# include "vmreg_sparc.inline.hpp"36#endif37#ifdef TARGET_ARCH_zero38# include "vmreg_zero.inline.hpp"39#endif40#ifdef TARGET_ARCH_arm41# include "vmreg_arm.inline.hpp"42#endif43#ifdef TARGET_ARCH_ppc44# include "vmreg_ppc.inline.hpp"45#endif46474849//-----------------------------------------------------5051// Convert method signature into an array of BasicTypes for the arguments52BasicTypeArray* FrameMap::signature_type_array_for(const ciMethod* method) {53ciSignature* sig = method->signature();54BasicTypeList* sta = new BasicTypeList(method->arg_size());55// add receiver, if any56if (!method->is_static()) sta->append(T_OBJECT);57// add remaining arguments58for (int i = 0; i < sig->count(); i++) {59ciType* type = sig->type_at(i);60BasicType t = type->basic_type();61if (t == T_ARRAY) {62t = T_OBJECT;63}64sta->append(t);65}66// done67return sta;68}697071CallingConvention* FrameMap::java_calling_convention(const BasicTypeArray* signature, bool outgoing) {72// compute the size of the arguments first. The signature array73// that java_calling_convention takes includes a T_VOID after double74// work items but our signatures do not.75int i;76int sizeargs = 0;77for (i = 0; i < signature->length(); i++) {78sizeargs += type2size[signature->at(i)];79}8081BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);82VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);83int sig_index = 0;84for (i = 0; i < sizeargs; i++, sig_index++) {85sig_bt[i] = signature->at(sig_index);86if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {87sig_bt[i + 1] = T_VOID;88i++;89}90}9192intptr_t out_preserve = SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs, outgoing);93LIR_OprList* args = new LIR_OprList(signature->length());94for (i = 0; i < sizeargs;) {95BasicType t = sig_bt[i];96assert(t != T_VOID, "should be skipping these");97LIR_Opr opr = map_to_opr(t, regs + i, outgoing);98args->append(opr);99if (opr->is_address()) {100LIR_Address* addr = opr->as_address_ptr();101assert(addr->disp() == (int)addr->disp(), "out of range value");102out_preserve = MAX2(out_preserve, (intptr_t)(addr->disp() - STACK_BIAS) / 4);103}104i += type2size[t];105}106assert(args->length() == signature->length(), "size mismatch");107out_preserve += SharedRuntime::out_preserve_stack_slots();108109if (outgoing) {110// update the space reserved for arguments.111update_reserved_argument_area_size(out_preserve * BytesPerWord);112}113return new CallingConvention(args, out_preserve);114}115116117CallingConvention* FrameMap::c_calling_convention(const BasicTypeArray* signature) {118// compute the size of the arguments first. The signature array119// that java_calling_convention takes includes a T_VOID after double120// work items but our signatures do not.121int i;122int sizeargs = 0;123for (i = 0; i < signature->length(); i++) {124sizeargs += type2size[signature->at(i)];125}126127BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);128VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);129int sig_index = 0;130for (i = 0; i < sizeargs; i++, sig_index++) {131sig_bt[i] = signature->at(sig_index);132if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {133sig_bt[i + 1] = T_VOID;134i++;135}136}137138intptr_t out_preserve = SharedRuntime::c_calling_convention(sig_bt, regs, NULL, sizeargs);139LIR_OprList* args = new LIR_OprList(signature->length());140for (i = 0; i < sizeargs;) {141BasicType t = sig_bt[i];142assert(t != T_VOID, "should be skipping these");143144// C calls are always outgoing145bool outgoing = true;146LIR_Opr opr = map_to_opr(t, regs + i, outgoing);147// they might be of different types if for instance floating point148// values are passed in cpu registers, but the sizes must match.149assert(type2size[opr->type()] == type2size[t], "type mismatch");150args->append(opr);151if (opr->is_address()) {152LIR_Address* addr = opr->as_address_ptr();153out_preserve = MAX2(out_preserve, (intptr_t)(addr->disp() - STACK_BIAS) / 4);154}155i += type2size[t];156}157assert(args->length() == signature->length(), "size mismatch");158out_preserve += SharedRuntime::out_preserve_stack_slots();159update_reserved_argument_area_size(out_preserve * BytesPerWord);160return new CallingConvention(args, out_preserve);161}162163164//--------------------------------------------------------165// FrameMap166//--------------------------------------------------------167168bool FrameMap::_init_done = false;169Register FrameMap::_cpu_rnr2reg [FrameMap::nof_cpu_regs];170int FrameMap::_cpu_reg2rnr [FrameMap::nof_cpu_regs];171172173FrameMap::FrameMap(ciMethod* method, int monitors, int reserved_argument_area_size) {174assert(_init_done, "should already be completed");175176_framesize = -1;177_num_spills = -1;178179assert(monitors >= 0, "not set");180_num_monitors = monitors;181assert(reserved_argument_area_size >= 0, "not set");182_reserved_argument_area_size = MAX2(4, reserved_argument_area_size) * BytesPerWord;183184_argcount = method->arg_size();185_argument_locations = new intArray(_argcount, -1);186_incoming_arguments = java_calling_convention(signature_type_array_for(method), false);187_oop_map_arg_count = _incoming_arguments->reserved_stack_slots();188189int java_index = 0;190for (int i = 0; i < _incoming_arguments->length(); i++) {191LIR_Opr opr = _incoming_arguments->at(i);192if (opr->is_address()) {193LIR_Address* address = opr->as_address_ptr();194_argument_locations->at_put(java_index, address->disp() - STACK_BIAS);195_incoming_arguments->args()->at_put(i, LIR_OprFact::stack(java_index, as_BasicType(as_ValueType(address->type()))));196}197java_index += type2size[opr->type()];198}199200}201202203bool FrameMap::finalize_frame(int nof_slots) {204assert(nof_slots >= 0, "must be positive");205assert(_num_spills == -1, "can only be set once");206_num_spills = nof_slots;207assert(_framesize == -1, "should only be calculated once");208_framesize = round_to(in_bytes(sp_offset_for_monitor_base(0)) +209_num_monitors * sizeof(BasicObjectLock) +210sizeof(intptr_t) + // offset of deopt orig pc211frame_pad_in_bytes,212StackAlignmentInBytes) / 4;213int java_index = 0;214for (int i = 0; i < _incoming_arguments->length(); i++) {215LIR_Opr opr = _incoming_arguments->at(i);216if (opr->is_stack()) {217_argument_locations->at_put(java_index, in_bytes(framesize_in_bytes()) +218_argument_locations->at(java_index));219}220java_index += type2size[opr->type()];221}222// make sure it's expressible on the platform223return validate_frame();224}225226VMReg FrameMap::sp_offset2vmreg(ByteSize offset) const {227int offset_in_bytes = in_bytes(offset);228assert(offset_in_bytes % 4 == 0, "must be multiple of 4 bytes");229assert(offset_in_bytes / 4 < framesize() + oop_map_arg_count(), "out of range");230return VMRegImpl::stack2reg(offset_in_bytes / 4);231}232233234bool FrameMap::location_for_sp_offset(ByteSize byte_offset_from_sp,235Location::Type loc_type,236Location* loc) const {237int offset = in_bytes(byte_offset_from_sp);238assert(offset >= 0, "incorrect offset");239if (!Location::legal_offset_in_bytes(offset)) {240return false;241}242Location tmp_loc = Location::new_stk_loc(loc_type, offset);243*loc = tmp_loc;244return true;245}246247248bool FrameMap::locations_for_slot (int index, Location::Type loc_type,249Location* loc, Location* second) const {250ByteSize offset_from_sp = sp_offset_for_slot(index);251if (!location_for_sp_offset(offset_from_sp, loc_type, loc)) {252return false;253}254if (second != NULL) {255// two word item256offset_from_sp = offset_from_sp + in_ByteSize(4);257return location_for_sp_offset(offset_from_sp, loc_type, second);258}259return true;260}261262//////////////////////263// Public accessors //264//////////////////////265266267ByteSize FrameMap::sp_offset_for_slot(const int index) const {268if (index < argcount()) {269int offset = _argument_locations->at(index);270assert(offset != -1, "not a memory argument");271assert(offset >= framesize() * 4, "argument inside of frame");272return in_ByteSize(offset);273}274ByteSize offset = sp_offset_for_spill(index - argcount());275assert(in_bytes(offset) < framesize() * 4, "spill outside of frame");276return offset;277}278279280ByteSize FrameMap::sp_offset_for_double_slot(const int index) const {281ByteSize offset = sp_offset_for_slot(index);282if (index >= argcount()) {283assert(in_bytes(offset) + 4 < framesize() * 4, "spill outside of frame");284}285return offset;286}287288289ByteSize FrameMap::sp_offset_for_spill(const int index) const {290assert(index >= 0 && index < _num_spills, "out of range");291int offset = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) +292index * spill_slot_size_in_bytes;293return in_ByteSize(offset);294}295296ByteSize FrameMap::sp_offset_for_monitor_base(const int index) const {297int end_of_spills = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) +298_num_spills * spill_slot_size_in_bytes;299int offset = (int) round_to(end_of_spills, HeapWordSize) + index * sizeof(BasicObjectLock);300return in_ByteSize(offset);301}302303ByteSize FrameMap::sp_offset_for_monitor_lock(int index) const {304check_monitor_index(index);305return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::lock_offset_in_bytes());;306}307308ByteSize FrameMap::sp_offset_for_monitor_object(int index) const {309check_monitor_index(index);310return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::obj_offset_in_bytes());311}312313314// For OopMaps, map a local variable or spill index to an VMReg.315// This is the offset from sp() in the frame of the slot for the index,316// skewed by SharedInfo::stack0 to indicate a stack location (vs.a register.)317//318// C ABI size +319// framesize + framesize +320// stack0 stack0 stack0 0 <- VMReg->value()321// | | | <registers> |322// ..........|..............|..............|.............|323// 0 1 2 3 | <C ABI area> | 4 5 6 ...... | <- local indices324// ^ ^ sp()325// | |326// arguments non-argument locals327328329VMReg FrameMap::regname(LIR_Opr opr) const {330if (opr->is_single_cpu()) {331assert(!opr->is_virtual(), "should not see virtual registers here");332return opr->as_register()->as_VMReg();333} else if (opr->is_single_stack()) {334return sp_offset2vmreg(sp_offset_for_slot(opr->single_stack_ix()));335} else if (opr->is_address()) {336LIR_Address* addr = opr->as_address_ptr();337assert(addr->base() == stack_pointer(), "sp based addressing only");338return sp_offset2vmreg(in_ByteSize(addr->index()->as_jint()));339}340ShouldNotReachHere();341return VMRegImpl::Bad();342}343344345346347// ------------ extra spill slots ---------------348349350