duke@435: /* trims@2708: * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_C1_C1_FRAMEMAP_HPP stefank@2314: #define SHARE_VM_C1_C1_FRAMEMAP_HPP stefank@2314: stefank@2314: #include "asm/assembler.hpp" stefank@2314: #include "c1/c1_Defs.hpp" stefank@2314: #include "c1/c1_LIR.hpp" stefank@2314: #include "code/vmreg.hpp" stefank@2314: #include "memory/allocation.hpp" stefank@2314: #include "runtime/frame.hpp" stefank@2314: #include "runtime/synchronizer.hpp" stefank@2314: #include "utilities/globalDefinitions.hpp" stefank@2314: duke@435: class ciMethod; duke@435: class CallingConvention; duke@435: class BasicTypeArray; duke@435: class BasicTypeList; duke@435: duke@435: //-------------------------------------------------------- duke@435: // FrameMap duke@435: //-------------------------------------------------------- duke@435: duke@435: // This class is responsible of mapping items (locals, monitors, spill duke@435: // slots and registers to their frame location duke@435: // duke@435: // The monitors are specified by a consecutive index, although each monitor entry duke@435: // occupies two words. The monitor_index is 0.._num_monitors duke@435: // The spill index is similar to local index; it is in range 0..(open) duke@435: // duke@435: // The CPU registers are mapped using a fixed table; register with number 0 duke@435: // is the most used one. duke@435: duke@435: duke@435: // stack grow direction --> SP duke@435: // +----------+---+----------+-------+------------------------+-----+ duke@435: // |arguments | x | monitors | spill | reserved argument area | ABI | duke@435: // +----------+---+----------+-------+------------------------+-----+ duke@435: // duke@435: // x = ABI area (SPARC) or return adress and link (i486) duke@435: // ABI = ABI area (SPARC) or nothing (i486) duke@435: duke@435: duke@435: class LIR_OprDesc; duke@435: typedef LIR_OprDesc* LIR_Opr; duke@435: duke@435: duke@435: class FrameMap : public CompilationResourceObj { duke@435: public: duke@435: enum { duke@435: nof_cpu_regs = pd_nof_cpu_regs_frame_map, duke@435: nof_fpu_regs = pd_nof_fpu_regs_frame_map, duke@435: duke@435: nof_cpu_regs_reg_alloc = pd_nof_cpu_regs_reg_alloc, duke@435: nof_fpu_regs_reg_alloc = pd_nof_fpu_regs_reg_alloc, duke@435: iveresov@2344: max_nof_caller_save_cpu_regs = pd_nof_caller_save_cpu_regs_frame_map, iveresov@2344: nof_caller_save_fpu_regs = pd_nof_caller_save_fpu_regs_frame_map, duke@435: duke@435: spill_slot_size_in_bytes = 4 duke@435: }; duke@435: stefank@2314: #ifdef TARGET_ARCH_x86 stefank@2314: # include "c1_FrameMap_x86.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_ARCH_sparc stefank@2314: # include "c1_FrameMap_sparc.hpp" stefank@2314: #endif bobv@2508: #ifdef TARGET_ARCH_arm bobv@2508: # include "c1_FrameMap_arm.hpp" bobv@2508: #endif bobv@2508: #ifdef TARGET_ARCH_ppc bobv@2508: # include "c1_FrameMap_ppc.hpp" bobv@2508: #endif stefank@2314: duke@435: duke@435: friend class LIR_OprDesc; duke@435: duke@435: private: duke@435: static bool _init_done; duke@435: static Register _cpu_rnr2reg [nof_cpu_regs]; duke@435: static int _cpu_reg2rnr [nof_cpu_regs]; duke@435: iveresov@2344: static LIR_Opr _caller_save_cpu_regs [max_nof_caller_save_cpu_regs]; duke@435: static LIR_Opr _caller_save_fpu_regs [nof_caller_save_fpu_regs]; duke@435: duke@435: int _framesize; duke@435: int _argcount; duke@435: int _num_monitors; duke@435: int _num_spills; duke@435: int _reserved_argument_area_size; duke@435: int _oop_map_arg_count; duke@435: duke@435: CallingConvention* _incoming_arguments; duke@435: intArray* _argument_locations; duke@435: duke@435: void check_spill_index (int spill_index) const { assert(spill_index >= 0, "bad index"); } duke@435: void check_monitor_index (int monitor_index) const { assert(monitor_index >= 0 && duke@435: monitor_index < _num_monitors, "bad index"); } duke@435: duke@435: static Register cpu_rnr2reg (int rnr) { duke@435: assert(_init_done, "tables not initialized"); duke@435: debug_only(cpu_range_check(rnr);) duke@435: return _cpu_rnr2reg[rnr]; duke@435: } duke@435: duke@435: static int cpu_reg2rnr (Register reg) { duke@435: assert(_init_done, "tables not initialized"); duke@435: debug_only(cpu_range_check(reg->encoding());) duke@435: return _cpu_reg2rnr[reg->encoding()]; duke@435: } duke@435: duke@435: static void map_register(int rnr, Register reg) { duke@435: debug_only(cpu_range_check(rnr);) duke@435: debug_only(cpu_range_check(reg->encoding());) duke@435: _cpu_rnr2reg[rnr] = reg; duke@435: _cpu_reg2rnr[reg->encoding()] = rnr; duke@435: } duke@435: duke@435: void update_reserved_argument_area_size (int size) { duke@435: assert(size >= 0, "check"); duke@435: _reserved_argument_area_size = MAX2(_reserved_argument_area_size, size); duke@435: } duke@435: duke@435: protected: duke@435: #ifndef PRODUCT duke@435: static void cpu_range_check (int rnr) { assert(0 <= rnr && rnr < nof_cpu_regs, "cpu register number is too big"); } duke@435: static void fpu_range_check (int rnr) { assert(0 <= rnr && rnr < nof_fpu_regs, "fpu register number is too big"); } duke@435: #endif duke@435: duke@435: duke@435: ByteSize sp_offset_for_monitor_base(const int idx) const; duke@435: duke@435: Address make_new_address(ByteSize sp_offset) const; duke@435: duke@435: ByteSize sp_offset_for_slot(const int idx) const; duke@435: ByteSize sp_offset_for_double_slot(const int idx) const; duke@435: ByteSize sp_offset_for_spill(const int idx) const; duke@435: ByteSize sp_offset_for_monitor_lock(int monitor_index) const; duke@435: ByteSize sp_offset_for_monitor_object(int monitor_index) const; duke@435: duke@435: VMReg sp_offset2vmreg(ByteSize offset) const; duke@435: duke@435: // platform dependent hook used to check that frame is properly duke@435: // addressable on the platform. Used by sparc to verify that all duke@435: // stack addresses are expressable in a simm13. duke@435: bool validate_frame(); duke@435: duke@435: static LIR_Opr map_to_opr(BasicType type, VMRegPair* reg, bool incoming); duke@435: duke@435: public: duke@435: // Opr representing the stack_pointer on this platform duke@435: static LIR_Opr stack_pointer(); duke@435: twisti@1919: // JSR 292 twisti@1919: static LIR_Opr method_handle_invoke_SP_save_opr(); twisti@1919: duke@435: static BasicTypeArray* signature_type_array_for(const ciMethod* method); duke@435: duke@435: // for outgoing calls, these also update the reserved area to duke@435: // include space for arguments and any ABI area. twisti@3969: CallingConvention* c_calling_convention(const BasicTypeArray* signature); twisti@3969: CallingConvention* java_calling_convention(const BasicTypeArray* signature, bool outgoing); duke@435: duke@435: // deopt support duke@435: ByteSize sp_offset_for_orig_pc() { return sp_offset_for_monitor_base(_num_monitors); } duke@435: duke@435: static LIR_Opr as_opr(Register r) { duke@435: return LIR_OprFact::single_cpu(cpu_reg2rnr(r)); duke@435: } duke@435: static LIR_Opr as_oop_opr(Register r) { duke@435: return LIR_OprFact::single_cpu_oop(cpu_reg2rnr(r)); duke@435: } duke@435: roland@4051: static LIR_Opr as_metadata_opr(Register r) { roland@4051: return LIR_OprFact::single_cpu_metadata(cpu_reg2rnr(r)); roland@4051: } roland@4051: duke@435: FrameMap(ciMethod* method, int monitors, int reserved_argument_area_size); duke@435: bool finalize_frame(int nof_slots); duke@435: duke@435: int reserved_argument_area_size () const { return _reserved_argument_area_size; } duke@435: int framesize () const { assert(_framesize != -1, "hasn't been calculated"); return _framesize; } duke@435: ByteSize framesize_in_bytes () const { return in_ByteSize(framesize() * 4); } duke@435: int num_monitors () const { return _num_monitors; } duke@435: int num_spills () const { assert(_num_spills >= 0, "not set"); return _num_spills; } duke@435: int argcount () const { assert(_argcount >= 0, "not set"); return _argcount; } duke@435: duke@435: int oop_map_arg_count() const { return _oop_map_arg_count; } duke@435: duke@435: CallingConvention* incoming_arguments() const { return _incoming_arguments; } duke@435: duke@435: // convenience routines duke@435: Address address_for_slot(int index, int sp_adjust = 0) const { duke@435: return make_new_address(sp_offset_for_slot(index) + in_ByteSize(sp_adjust)); duke@435: } duke@435: Address address_for_double_slot(int index, int sp_adjust = 0) const { duke@435: return make_new_address(sp_offset_for_double_slot(index) + in_ByteSize(sp_adjust)); duke@435: } duke@435: Address address_for_monitor_lock(int monitor_index) const { duke@435: return make_new_address(sp_offset_for_monitor_lock(monitor_index)); duke@435: } duke@435: Address address_for_monitor_object(int monitor_index) const { duke@435: return make_new_address(sp_offset_for_monitor_object(monitor_index)); duke@435: } duke@435: duke@435: void print_frame_layout() const; duke@435: duke@435: // Creates Location describing desired slot and returns it via pointer duke@435: // to Location object. Returns true if the stack frame offset was legal duke@435: // (as defined by Location::legal_offset_in_bytes()), false otherwise. duke@435: // Do not use the returned location if this returns false. duke@435: bool location_for_sp_offset(ByteSize byte_offset_from_sp, duke@435: Location::Type loc_type, Location* loc) const; duke@435: duke@435: bool location_for_monitor_lock (int monitor_index, Location* loc) const { duke@435: return location_for_sp_offset(sp_offset_for_monitor_lock(monitor_index), Location::normal, loc); duke@435: } duke@435: bool location_for_monitor_object(int monitor_index, Location* loc) const { duke@435: return location_for_sp_offset(sp_offset_for_monitor_object(monitor_index), Location::oop, loc); duke@435: } duke@435: bool locations_for_slot (int index, Location::Type loc_type, duke@435: Location* loc, Location* second = NULL) const; duke@435: duke@435: VMReg slot_regname(int index) const { duke@435: return sp_offset2vmreg(sp_offset_for_slot(index)); duke@435: } duke@435: VMReg monitor_object_regname(int monitor_index) const { duke@435: return sp_offset2vmreg(sp_offset_for_monitor_object(monitor_index)); duke@435: } duke@435: VMReg regname(LIR_Opr opr) const; duke@435: duke@435: static LIR_Opr caller_save_cpu_reg_at(int i) { iveresov@2344: assert(i >= 0 && i < max_nof_caller_save_cpu_regs, "out of bounds"); duke@435: return _caller_save_cpu_regs[i]; duke@435: } duke@435: duke@435: static LIR_Opr caller_save_fpu_reg_at(int i) { duke@435: assert(i >= 0 && i < nof_caller_save_fpu_regs, "out of bounds"); duke@435: return _caller_save_fpu_regs[i]; duke@435: } duke@435: iveresov@1939: static void initialize(); duke@435: }; duke@435: duke@435: // CallingConvention duke@435: //-------------------------------------------------------- duke@435: duke@435: class CallingConvention: public ResourceObj { duke@435: private: duke@435: LIR_OprList* _args; duke@435: int _reserved_stack_slots; duke@435: duke@435: public: duke@435: CallingConvention (LIR_OprList* args, int reserved_stack_slots) duke@435: : _args(args) duke@435: , _reserved_stack_slots(reserved_stack_slots) {} duke@435: duke@435: LIR_OprList* args() { return _args; } duke@435: duke@435: LIR_Opr at(int i) const { return _args->at(i); } duke@435: int length() const { return _args->length(); } duke@435: duke@435: // Indicates number of real frame slots used by arguments passed on stack. duke@435: int reserved_stack_slots() const { return _reserved_stack_slots; } duke@435: duke@435: #ifndef PRODUCT duke@435: void print () const { duke@435: for (int i = 0; i < length(); i++) { duke@435: at(i)->print(); duke@435: } duke@435: } duke@435: #endif // PRODUCT duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_C1_C1_FRAMEMAP_HPP