c1_FrameMap.hpp revision 1879:f95d63e2154a
1184610Salfred/* 2184610Salfred * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 3184610Salfred * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4184610Salfred * 5184610Salfred * This code is free software; you can redistribute it and/or modify it 6184610Salfred * under the terms of the GNU General Public License version 2 only, as 7184610Salfred * published by the Free Software Foundation. 8184610Salfred * 9184610Salfred * This code is distributed in the hope that it will be useful, but WITHOUT 10184610Salfred * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11184610Salfred * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12184610Salfred * version 2 for more details (a copy is included in the LICENSE file that 13184610Salfred * accompanied this code). 14184610Salfred * 15184610Salfred * You should have received a copy of the GNU General Public License version 16184610Salfred * 2 along with this work; if not, write to the Free Software Foundation, 17184610Salfred * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18184610Salfred * 19184610Salfred * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20184610Salfred * or visit www.oracle.com if you need additional information or have any 21184610Salfred * questions. 22184610Salfred * 23184610Salfred */ 24184610Salfred 25184610Salfred#ifndef SHARE_VM_C1_C1_FRAMEMAP_HPP 26184610Salfred#define SHARE_VM_C1_C1_FRAMEMAP_HPP 27184610Salfred 28184610Salfred#include "asm/assembler.hpp" 29184610Salfred#include "c1/c1_Defs.hpp" 30184610Salfred#include "c1/c1_LIR.hpp" 31184610Salfred#include "code/vmreg.hpp" 32184610Salfred#include "memory/allocation.hpp" 33184610Salfred#include "runtime/frame.hpp" 34184610Salfred#include "runtime/synchronizer.hpp" 35184610Salfred#include "utilities/globalDefinitions.hpp" 36184610Salfred 37184610Salfredclass ciMethod; 38184610Salfredclass CallingConvention; 39184610Salfredclass BasicTypeArray; 40184610Salfredclass BasicTypeList; 41184610Salfred 42184610Salfred//-------------------------------------------------------- 43184610Salfred// FrameMap 44184610Salfred//-------------------------------------------------------- 45184610Salfred 46184610Salfred// This class is responsible of mapping items (locals, monitors, spill 47184610Salfred// slots and registers to their frame location 48184610Salfred// 49184610Salfred// The monitors are specified by a consecutive index, although each monitor entry 50184610Salfred// occupies two words. The monitor_index is 0.._num_monitors 51184610Salfred// The spill index is similar to local index; it is in range 0..(open) 52184610Salfred// 53184610Salfred// The CPU registers are mapped using a fixed table; register with number 0 54184610Salfred// is the most used one. 55184610Salfred 56184610Salfred 57184610Salfred// stack grow direction --> SP 58184610Salfred// +----------+---+----------+-------+------------------------+-----+ 59184610Salfred// |arguments | x | monitors | spill | reserved argument area | ABI | 60184610Salfred// +----------+---+----------+-------+------------------------+-----+ 61184610Salfred// 62184610Salfred// x = ABI area (SPARC) or return adress and link (i486) 63184610Salfred// ABI = ABI area (SPARC) or nothing (i486) 64184610Salfred 65184610Salfred 66184610Salfredclass LIR_OprDesc; 67184610Salfredtypedef LIR_OprDesc* LIR_Opr; 68184610Salfred 69184610Salfred 70184610Salfredclass FrameMap : public CompilationResourceObj { 71184610Salfred public: 72184610Salfred enum { 73184610Salfred nof_cpu_regs = pd_nof_cpu_regs_frame_map, 74184610Salfred nof_fpu_regs = pd_nof_fpu_regs_frame_map, 75184610Salfred 76184610Salfred nof_cpu_regs_reg_alloc = pd_nof_cpu_regs_reg_alloc, 77184610Salfred nof_fpu_regs_reg_alloc = pd_nof_fpu_regs_reg_alloc, 78184610Salfred 79184610Salfred nof_caller_save_cpu_regs = pd_nof_caller_save_cpu_regs_frame_map, 80184610Salfred nof_caller_save_fpu_regs = pd_nof_caller_save_fpu_regs_frame_map, 81184610Salfred 82184610Salfred spill_slot_size_in_bytes = 4 83184610Salfred }; 84184610Salfred 85184610Salfred#ifdef TARGET_ARCH_x86 86184610Salfred# include "c1_FrameMap_x86.hpp" 87184610Salfred#endif 88184610Salfred#ifdef TARGET_ARCH_sparc 89184610Salfred# include "c1_FrameMap_sparc.hpp" 90184610Salfred#endif 91184610Salfred 92184610Salfred 93184610Salfred friend class LIR_OprDesc; 94184610Salfred 95215969Syongari private: 96215969Syongari static bool _init_done; 97215969Syongari static Register _cpu_rnr2reg [nof_cpu_regs]; 98215969Syongari static int _cpu_reg2rnr [nof_cpu_regs]; 99224020Syongari 100226743Syongari static LIR_Opr _caller_save_cpu_regs [nof_caller_save_cpu_regs]; 101226743Syongari static LIR_Opr _caller_save_fpu_regs [nof_caller_save_fpu_regs]; 102226743Syongari 103226743Syongari int _framesize; 104224020Syongari int _argcount; 105184610Salfred int _num_monitors; 106184610Salfred int _num_spills; 107184610Salfred int _reserved_argument_area_size; 108184610Salfred int _oop_map_arg_count; 109184610Salfred 110184610Salfred CallingConvention* _incoming_arguments; 111184610Salfred intArray* _argument_locations; 112184610Salfred 113184610Salfred void check_spill_index (int spill_index) const { assert(spill_index >= 0, "bad index"); } 114184610Salfred void check_monitor_index (int monitor_index) const { assert(monitor_index >= 0 && 115184610Salfred monitor_index < _num_monitors, "bad index"); } 116184610Salfred 117184610Salfred static Register cpu_rnr2reg (int rnr) { 118184610Salfred assert(_init_done, "tables not initialized"); 119184610Salfred debug_only(cpu_range_check(rnr);) 120184610Salfred return _cpu_rnr2reg[rnr]; 121184610Salfred } 122184610Salfred 123184610Salfred static int cpu_reg2rnr (Register reg) { 124184610Salfred assert(_init_done, "tables not initialized"); 125184610Salfred debug_only(cpu_range_check(reg->encoding());) 126184610Salfred return _cpu_reg2rnr[reg->encoding()]; 127184610Salfred } 128184610Salfred 129184610Salfred static void map_register(int rnr, Register reg) { 130184610Salfred debug_only(cpu_range_check(rnr);) 131184610Salfred debug_only(cpu_range_check(reg->encoding());) 132184610Salfred _cpu_rnr2reg[rnr] = reg; 133184610Salfred _cpu_reg2rnr[reg->encoding()] = rnr; 134184610Salfred } 135184610Salfred 136184610Salfred void update_reserved_argument_area_size (int size) { 137184610Salfred assert(size >= 0, "check"); 138184610Salfred _reserved_argument_area_size = MAX2(_reserved_argument_area_size, size); 139184610Salfred } 140184610Salfred 141224020Syongari protected: 142184610Salfred#ifndef PRODUCT 143184610Salfred static void cpu_range_check (int rnr) { assert(0 <= rnr && rnr < nof_cpu_regs, "cpu register number is too big"); } 144184610Salfred static void fpu_range_check (int rnr) { assert(0 <= rnr && rnr < nof_fpu_regs, "fpu register number is too big"); } 145184610Salfred#endif 146184610Salfred 147184610Salfred 148224020Syongari ByteSize sp_offset_for_monitor_base(const int idx) const; 149224020Syongari 150224020Syongari Address make_new_address(ByteSize sp_offset) const; 151224020Syongari 152224020Syongari ByteSize sp_offset_for_slot(const int idx) const; 153184610Salfred ByteSize sp_offset_for_double_slot(const int idx) const; 154186730Salfred ByteSize sp_offset_for_spill(const int idx) const; 155186730Salfred ByteSize sp_offset_for_monitor_lock(int monitor_index) const; 156186730Salfred ByteSize sp_offset_for_monitor_object(int monitor_index) const; 157186730Salfred 158186730Salfred VMReg sp_offset2vmreg(ByteSize offset) const; 159186730Salfred 160184610Salfred // platform dependent hook used to check that frame is properly 161186730Salfred // addressable on the platform. Used by sparc to verify that all 162186730Salfred // stack addresses are expressable in a simm13. 163186730Salfred bool validate_frame(); 164186730Salfred 165186730Salfred static LIR_Opr map_to_opr(BasicType type, VMRegPair* reg, bool incoming); 166186730Salfred 167186730Salfred public: 168186730Salfred // Opr representing the stack_pointer on this platform 169186730Salfred static LIR_Opr stack_pointer(); 170186730Salfred 171186730Salfred // JSR 292 172212130Sthompsa static LIR_Opr method_handle_invoke_SP_save_opr(); 173212130Sthompsa 174212130Sthompsa static BasicTypeArray* signature_type_array_for(const ciMethod* method); 175212130Sthompsa 176212130Sthompsa // for outgoing calls, these also update the reserved area to 177212130Sthompsa // include space for arguments and any ABI area. 178212130Sthompsa CallingConvention* c_calling_convention (const BasicTypeArray* signature); 179212130Sthompsa CallingConvention* java_calling_convention (const BasicTypeArray* signature, bool outgoing); 180212130Sthompsa 181212130Sthompsa // deopt support 182212130Sthompsa ByteSize sp_offset_for_orig_pc() { return sp_offset_for_monitor_base(_num_monitors); } 183212130Sthompsa 184212130Sthompsa static LIR_Opr as_opr(Register r) { 185212130Sthompsa return LIR_OprFact::single_cpu(cpu_reg2rnr(r)); 186212130Sthompsa } 187212130Sthompsa static LIR_Opr as_oop_opr(Register r) { 188212130Sthompsa return LIR_OprFact::single_cpu_oop(cpu_reg2rnr(r)); 189212130Sthompsa } 190212130Sthompsa 191224020Syongari FrameMap(ciMethod* method, int monitors, int reserved_argument_area_size); 192215969Syongari bool finalize_frame(int nof_slots); 193215969Syongari 194215969Syongari int reserved_argument_area_size () const { return _reserved_argument_area_size; } 195215969Syongari int framesize () const { assert(_framesize != -1, "hasn't been calculated"); return _framesize; } 196215969Syongari ByteSize framesize_in_bytes () const { return in_ByteSize(framesize() * 4); } 197215969Syongari int num_monitors () const { return _num_monitors; } 198215969Syongari int num_spills () const { assert(_num_spills >= 0, "not set"); return _num_spills; } 199215969Syongari int argcount () const { assert(_argcount >= 0, "not set"); return _argcount; } 200215969Syongari 201215969Syongari int oop_map_arg_count() const { return _oop_map_arg_count; } 202215969Syongari 203215969Syongari CallingConvention* incoming_arguments() const { return _incoming_arguments; } 204215969Syongari 205215969Syongari // convenience routines 206226743Syongari Address address_for_slot(int index, int sp_adjust = 0) const { 207226743Syongari return make_new_address(sp_offset_for_slot(index) + in_ByteSize(sp_adjust)); 208226743Syongari } 209226743Syongari Address address_for_double_slot(int index, int sp_adjust = 0) const { 210226743Syongari return make_new_address(sp_offset_for_double_slot(index) + in_ByteSize(sp_adjust)); 211226743Syongari } 212226743Syongari Address address_for_monitor_lock(int monitor_index) const { 213226743Syongari return make_new_address(sp_offset_for_monitor_lock(monitor_index)); 214226743Syongari } 215226743Syongari Address address_for_monitor_object(int monitor_index) const { 216226743Syongari return make_new_address(sp_offset_for_monitor_object(monitor_index)); 217226743Syongari } 218226743Syongari 219226743Syongari void print_frame_layout() const; 220226743Syongari 221226743Syongari // Creates Location describing desired slot and returns it via pointer 222226743Syongari // to Location object. Returns true if the stack frame offset was legal 223226743Syongari // (as defined by Location::legal_offset_in_bytes()), false otherwise. 224226743Syongari // Do not use the returned location if this returns false. 225226743Syongari bool location_for_sp_offset(ByteSize byte_offset_from_sp, 226226743Syongari Location::Type loc_type, Location* loc) const; 227226743Syongari 228226743Syongari bool location_for_monitor_lock (int monitor_index, Location* loc) const { 229226743Syongari return location_for_sp_offset(sp_offset_for_monitor_lock(monitor_index), Location::normal, loc); 230226743Syongari } 231226743Syongari bool location_for_monitor_object(int monitor_index, Location* loc) const { 232226743Syongari return location_for_sp_offset(sp_offset_for_monitor_object(monitor_index), Location::oop, loc); 233226743Syongari } 234226743Syongari bool locations_for_slot (int index, Location::Type loc_type, 235226743Syongari Location* loc, Location* second = NULL) const; 236226743Syongari 237226743Syongari VMReg slot_regname(int index) const { 238226743Syongari return sp_offset2vmreg(sp_offset_for_slot(index)); 239226743Syongari } 240184610Salfred VMReg monitor_object_regname(int monitor_index) const { 241184610Salfred return sp_offset2vmreg(sp_offset_for_monitor_object(monitor_index)); 242184610Salfred } 243184610Salfred VMReg regname(LIR_Opr opr) const; 244184610Salfred 245184610Salfred static LIR_Opr caller_save_cpu_reg_at(int i) { 246184610Salfred assert(i >= 0 && i < nof_caller_save_cpu_regs, "out of bounds"); 247184610Salfred return _caller_save_cpu_regs[i]; 248224020Syongari } 249224020Syongari 250224020Syongari static LIR_Opr caller_save_fpu_reg_at(int i) { 251224020Syongari assert(i >= 0 && i < nof_caller_save_fpu_regs, "out of bounds"); 252224020Syongari return _caller_save_fpu_regs[i]; 253224020Syongari } 254224020Syongari 255224020Syongari static void initialize(); 256224020Syongari}; 257224020Syongari 258224020Syongari// CallingConvention 259224020Syongari//-------------------------------------------------------- 260224020Syongari 261224020Syongariclass CallingConvention: public ResourceObj { 262224020Syongari private: 263224020Syongari LIR_OprList* _args; 264224020Syongari int _reserved_stack_slots; 265224020Syongari 266184610Salfred public: 267184610Salfred CallingConvention (LIR_OprList* args, int reserved_stack_slots) 268226743Syongari : _args(args) 269184610Salfred , _reserved_stack_slots(reserved_stack_slots) {} 270184610Salfred 271184610Salfred LIR_OprList* args() { return _args; } 272226743Syongari 273226743Syongari LIR_Opr at(int i) const { return _args->at(i); } 274226743Syongari int length() const { return _args->length(); } 275226743Syongari 276226743Syongari // Indicates number of real frame slots used by arguments passed on stack. 277226743Syongari int reserved_stack_slots() const { return _reserved_stack_slots; } 278226743Syongari 279226743Syongari#ifndef PRODUCT 280226743Syongari void print () const { 281226743Syongari for (int i = 0; i < length(); i++) { 282226743Syongari at(i)->print(); 283226743Syongari } 284226743Syongari } 285226743Syongari#endif // PRODUCT 286226743Syongari}; 287226743Syongari 288226743Syongari#endif // SHARE_VM_C1_C1_FRAMEMAP_HPP 289226743Syongari