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: #ifndef SHARE_VM_C1_C1_FRAMEMAP_HPP aoqi@0: #define SHARE_VM_C1_C1_FRAMEMAP_HPP aoqi@0: aoqi@0: #include "asm/assembler.hpp" aoqi@0: #include "c1/c1_Defs.hpp" aoqi@0: #include "c1/c1_LIR.hpp" aoqi@0: #include "code/vmreg.hpp" aoqi@0: #include "memory/allocation.hpp" aoqi@0: #include "runtime/frame.hpp" aoqi@0: #include "runtime/synchronizer.hpp" aoqi@0: #include "utilities/globalDefinitions.hpp" aoqi@0: aoqi@0: class ciMethod; aoqi@0: class CallingConvention; aoqi@0: class BasicTypeArray; aoqi@0: class BasicTypeList; aoqi@0: aoqi@0: //-------------------------------------------------------- aoqi@0: // FrameMap aoqi@0: //-------------------------------------------------------- aoqi@0: aoqi@0: // This class is responsible of mapping items (locals, monitors, spill aoqi@0: // slots and registers to their frame location aoqi@0: // aoqi@0: // The monitors are specified by a consecutive index, although each monitor entry aoqi@0: // occupies two words. The monitor_index is 0.._num_monitors aoqi@0: // The spill index is similar to local index; it is in range 0..(open) aoqi@0: // aoqi@0: // The CPU registers are mapped using a fixed table; register with number 0 aoqi@0: // is the most used one. aoqi@0: aoqi@0: aoqi@0: // stack grow direction --> SP aoqi@0: // +----------+---+----------+-------+------------------------+-----+ aoqi@0: // |arguments | x | monitors | spill | reserved argument area | ABI | aoqi@0: // +----------+---+----------+-------+------------------------+-----+ aoqi@0: // aoqi@0: // x = ABI area (SPARC) or return adress and link (i486) aoqi@0: // ABI = ABI area (SPARC) or nothing (i486) aoqi@0: aoqi@0: aoqi@0: class LIR_OprDesc; aoqi@0: typedef LIR_OprDesc* LIR_Opr; aoqi@0: aoqi@0: aoqi@0: class FrameMap : public CompilationResourceObj { aoqi@0: public: aoqi@0: enum { aoqi@0: nof_cpu_regs = pd_nof_cpu_regs_frame_map, aoqi@0: nof_fpu_regs = pd_nof_fpu_regs_frame_map, aoqi@0: aoqi@0: nof_cpu_regs_reg_alloc = pd_nof_cpu_regs_reg_alloc, aoqi@0: nof_fpu_regs_reg_alloc = pd_nof_fpu_regs_reg_alloc, aoqi@0: aoqi@0: max_nof_caller_save_cpu_regs = pd_nof_caller_save_cpu_regs_frame_map, aoqi@0: nof_caller_save_fpu_regs = pd_nof_caller_save_fpu_regs_frame_map, aoqi@0: aoqi@0: spill_slot_size_in_bytes = 4 aoqi@0: }; aoqi@0: aoqi@0: #ifdef TARGET_ARCH_x86 aoqi@0: # include "c1_FrameMap_x86.hpp" aoqi@0: #endif aoqi@1: #ifdef TARGET_ARCH_mips aoqi@1: # include "c1_FrameMap_mips.hpp" aoqi@1: #endif aoqi@0: #ifdef TARGET_ARCH_sparc aoqi@0: # include "c1_FrameMap_sparc.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_arm aoqi@0: # include "c1_FrameMap_arm.hpp" aoqi@0: #endif aoqi@0: #ifdef TARGET_ARCH_ppc aoqi@0: # include "c1_FrameMap_ppc.hpp" aoqi@0: #endif aoqi@0: aoqi@0: aoqi@0: friend class LIR_OprDesc; aoqi@0: aoqi@0: private: aoqi@0: static bool _init_done; aoqi@0: static Register _cpu_rnr2reg [nof_cpu_regs]; aoqi@0: static int _cpu_reg2rnr [nof_cpu_regs]; aoqi@0: aoqi@0: static LIR_Opr _caller_save_cpu_regs [max_nof_caller_save_cpu_regs]; aoqi@0: static LIR_Opr _caller_save_fpu_regs [nof_caller_save_fpu_regs]; aoqi@0: aoqi@0: int _framesize; aoqi@0: int _argcount; aoqi@0: int _num_monitors; aoqi@0: int _num_spills; aoqi@0: int _reserved_argument_area_size; aoqi@0: int _oop_map_arg_count; aoqi@0: aoqi@0: CallingConvention* _incoming_arguments; aoqi@0: intArray* _argument_locations; aoqi@0: aoqi@0: void check_spill_index (int spill_index) const { assert(spill_index >= 0, "bad index"); } aoqi@0: void check_monitor_index (int monitor_index) const { assert(monitor_index >= 0 && aoqi@0: monitor_index < _num_monitors, "bad index"); } aoqi@0: aoqi@0: static Register cpu_rnr2reg (int rnr) { aoqi@0: assert(_init_done, "tables not initialized"); aoqi@0: debug_only(cpu_range_check(rnr);) aoqi@0: return _cpu_rnr2reg[rnr]; aoqi@0: } aoqi@0: aoqi@0: static int cpu_reg2rnr (Register reg) { aoqi@0: assert(_init_done, "tables not initialized"); aoqi@0: debug_only(cpu_range_check(reg->encoding());) aoqi@0: return _cpu_reg2rnr[reg->encoding()]; aoqi@0: } aoqi@0: aoqi@0: static void map_register(int rnr, Register reg) { aoqi@0: debug_only(cpu_range_check(rnr);) aoqi@0: debug_only(cpu_range_check(reg->encoding());) aoqi@0: _cpu_rnr2reg[rnr] = reg; aoqi@0: _cpu_reg2rnr[reg->encoding()] = rnr; aoqi@0: } aoqi@0: aoqi@0: void update_reserved_argument_area_size (int size) { aoqi@0: assert(size >= 0, "check"); aoqi@0: _reserved_argument_area_size = MAX2(_reserved_argument_area_size, size); aoqi@0: } aoqi@0: aoqi@0: protected: aoqi@0: #ifndef PRODUCT aoqi@0: static void cpu_range_check (int rnr) { assert(0 <= rnr && rnr < nof_cpu_regs, "cpu register number is too big"); } aoqi@0: static void fpu_range_check (int rnr) { assert(0 <= rnr && rnr < nof_fpu_regs, "fpu register number is too big"); } aoqi@0: #endif aoqi@0: aoqi@0: aoqi@0: ByteSize sp_offset_for_monitor_base(const int idx) const; aoqi@0: aoqi@0: Address make_new_address(ByteSize sp_offset) const; aoqi@0: aoqi@0: ByteSize sp_offset_for_slot(const int idx) const; aoqi@0: ByteSize sp_offset_for_double_slot(const int idx) const; aoqi@0: ByteSize sp_offset_for_spill(const int idx) const; aoqi@0: ByteSize sp_offset_for_monitor_lock(int monitor_index) const; aoqi@0: ByteSize sp_offset_for_monitor_object(int monitor_index) const; aoqi@0: aoqi@0: VMReg sp_offset2vmreg(ByteSize offset) const; aoqi@0: aoqi@0: // platform dependent hook used to check that frame is properly aoqi@0: // addressable on the platform. Used by sparc to verify that all aoqi@0: // stack addresses are expressable in a simm13. aoqi@0: bool validate_frame(); aoqi@0: aoqi@0: static LIR_Opr map_to_opr(BasicType type, VMRegPair* reg, bool incoming); aoqi@0: aoqi@0: public: aoqi@0: // Opr representing the stack_pointer on this platform aoqi@0: static LIR_Opr stack_pointer(); aoqi@0: aoqi@0: // JSR 292 aoqi@0: static LIR_Opr method_handle_invoke_SP_save_opr(); aoqi@0: aoqi@0: static BasicTypeArray* signature_type_array_for(const ciMethod* method); aoqi@0: aoqi@0: // for outgoing calls, these also update the reserved area to aoqi@0: // include space for arguments and any ABI area. aoqi@0: CallingConvention* c_calling_convention(const BasicTypeArray* signature); aoqi@0: CallingConvention* java_calling_convention(const BasicTypeArray* signature, bool outgoing); aoqi@0: aoqi@0: // deopt support aoqi@0: ByteSize sp_offset_for_orig_pc() { return sp_offset_for_monitor_base(_num_monitors); } aoqi@0: aoqi@0: static LIR_Opr as_opr(Register r) { aoqi@0: return LIR_OprFact::single_cpu(cpu_reg2rnr(r)); aoqi@0: } aoqi@0: static LIR_Opr as_oop_opr(Register r) { aoqi@0: return LIR_OprFact::single_cpu_oop(cpu_reg2rnr(r)); aoqi@0: } aoqi@0: aoqi@0: static LIR_Opr as_metadata_opr(Register r) { aoqi@0: return LIR_OprFact::single_cpu_metadata(cpu_reg2rnr(r)); aoqi@0: } aoqi@0: aoqi@0: FrameMap(ciMethod* method, int monitors, int reserved_argument_area_size); aoqi@0: bool finalize_frame(int nof_slots); aoqi@0: aoqi@0: int reserved_argument_area_size () const { return _reserved_argument_area_size; } aoqi@0: int framesize () const { assert(_framesize != -1, "hasn't been calculated"); return _framesize; } aoqi@0: ByteSize framesize_in_bytes () const { return in_ByteSize(framesize() * 4); } aoqi@0: int num_monitors () const { return _num_monitors; } aoqi@0: int num_spills () const { assert(_num_spills >= 0, "not set"); return _num_spills; } aoqi@0: int argcount () const { assert(_argcount >= 0, "not set"); return _argcount; } aoqi@0: aoqi@0: int oop_map_arg_count() const { return _oop_map_arg_count; } aoqi@0: aoqi@0: CallingConvention* incoming_arguments() const { return _incoming_arguments; } aoqi@0: aoqi@0: // convenience routines aoqi@0: Address address_for_slot(int index, int sp_adjust = 0) const { aoqi@0: return make_new_address(sp_offset_for_slot(index) + in_ByteSize(sp_adjust)); aoqi@0: } aoqi@0: Address address_for_double_slot(int index, int sp_adjust = 0) const { aoqi@0: return make_new_address(sp_offset_for_double_slot(index) + in_ByteSize(sp_adjust)); aoqi@0: } aoqi@0: Address address_for_monitor_lock(int monitor_index) const { aoqi@0: return make_new_address(sp_offset_for_monitor_lock(monitor_index)); aoqi@0: } aoqi@0: Address address_for_monitor_object(int monitor_index) const { aoqi@0: return make_new_address(sp_offset_for_monitor_object(monitor_index)); aoqi@0: } aoqi@0: aoqi@0: // Creates Location describing desired slot and returns it via pointer aoqi@0: // to Location object. Returns true if the stack frame offset was legal aoqi@0: // (as defined by Location::legal_offset_in_bytes()), false otherwise. aoqi@0: // Do not use the returned location if this returns false. aoqi@0: bool location_for_sp_offset(ByteSize byte_offset_from_sp, aoqi@0: Location::Type loc_type, Location* loc) const; aoqi@0: aoqi@0: bool location_for_monitor_lock (int monitor_index, Location* loc) const { aoqi@0: return location_for_sp_offset(sp_offset_for_monitor_lock(monitor_index), Location::normal, loc); aoqi@0: } aoqi@0: bool location_for_monitor_object(int monitor_index, Location* loc) const { aoqi@0: return location_for_sp_offset(sp_offset_for_monitor_object(monitor_index), Location::oop, loc); aoqi@0: } aoqi@0: bool locations_for_slot (int index, Location::Type loc_type, aoqi@0: Location* loc, Location* second = NULL) const; aoqi@0: aoqi@0: VMReg slot_regname(int index) const { aoqi@0: return sp_offset2vmreg(sp_offset_for_slot(index)); aoqi@0: } aoqi@0: VMReg monitor_object_regname(int monitor_index) const { aoqi@0: return sp_offset2vmreg(sp_offset_for_monitor_object(monitor_index)); aoqi@0: } aoqi@0: VMReg regname(LIR_Opr opr) const; aoqi@0: aoqi@0: static LIR_Opr caller_save_cpu_reg_at(int i) { aoqi@0: assert(i >= 0 && i < max_nof_caller_save_cpu_regs, "out of bounds"); aoqi@0: return _caller_save_cpu_regs[i]; aoqi@0: } aoqi@0: aoqi@0: static LIR_Opr caller_save_fpu_reg_at(int i) { aoqi@0: assert(i >= 0 && i < nof_caller_save_fpu_regs, "out of bounds"); aoqi@0: return _caller_save_fpu_regs[i]; aoqi@0: } aoqi@0: aoqi@0: static void initialize(); aoqi@0: }; aoqi@0: aoqi@0: // CallingConvention aoqi@0: //-------------------------------------------------------- aoqi@0: aoqi@0: class CallingConvention: public ResourceObj { aoqi@0: private: aoqi@0: LIR_OprList* _args; aoqi@0: int _reserved_stack_slots; aoqi@0: aoqi@0: public: aoqi@0: CallingConvention (LIR_OprList* args, int reserved_stack_slots) aoqi@0: : _args(args) aoqi@0: , _reserved_stack_slots(reserved_stack_slots) {} aoqi@0: aoqi@0: LIR_OprList* args() { return _args; } aoqi@0: aoqi@0: LIR_Opr at(int i) const { return _args->at(i); } aoqi@0: int length() const { return _args->length(); } aoqi@0: aoqi@0: // Indicates number of real frame slots used by arguments passed on stack. aoqi@0: int reserved_stack_slots() const { return _reserved_stack_slots; } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: void print () const { aoqi@0: for (int i = 0; i < length(); i++) { aoqi@0: at(i)->print(); aoqi@0: } aoqi@0: } aoqi@0: #endif // PRODUCT aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_C1_C1_FRAMEMAP_HPP