src/share/vm/c1/c1_FrameMap.hpp

changeset 435
a61af66fc99e
child 1907
c18cbe5936b8
child 1919
61b2245abf36
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/c1/c1_FrameMap.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,266 @@
     1.4 +/*
     1.5 + * Copyright 2000-2006 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +class ciMethod;
    1.29 +class CallingConvention;
    1.30 +class BasicTypeArray;
    1.31 +class BasicTypeList;
    1.32 +
    1.33 +//--------------------------------------------------------
    1.34 +//               FrameMap
    1.35 +//--------------------------------------------------------
    1.36 +
    1.37 +//  This class is responsible of mapping items (locals, monitors, spill
    1.38 +//  slots and registers to their frame location
    1.39 +//
    1.40 +//  The monitors are specified by a consecutive index, although each monitor entry
    1.41 +//  occupies two words. The monitor_index is 0.._num_monitors
    1.42 +//  The spill index is similar to local index; it is in range 0..(open)
    1.43 +//
    1.44 +//  The CPU registers are mapped using a fixed table; register with number 0
    1.45 +//  is the most used one.
    1.46 +
    1.47 +
    1.48 +//   stack grow direction -->                                        SP
    1.49 +//  +----------+---+----------+-------+------------------------+-----+
    1.50 +//  |arguments | x | monitors | spill | reserved argument area | ABI |
    1.51 +//  +----------+---+----------+-------+------------------------+-----+
    1.52 +//
    1.53 +//  x =  ABI area (SPARC) or  return adress and link (i486)
    1.54 +//  ABI  = ABI area (SPARC) or nothing (i486)
    1.55 +
    1.56 +
    1.57 +class LIR_OprDesc;
    1.58 +typedef LIR_OprDesc* LIR_Opr;
    1.59 +
    1.60 +
    1.61 +class FrameMap : public CompilationResourceObj {
    1.62 + public:
    1.63 +  enum {
    1.64 +    nof_cpu_regs = pd_nof_cpu_regs_frame_map,
    1.65 +    nof_fpu_regs = pd_nof_fpu_regs_frame_map,
    1.66 +
    1.67 +    nof_cpu_regs_reg_alloc = pd_nof_cpu_regs_reg_alloc,
    1.68 +    nof_fpu_regs_reg_alloc = pd_nof_fpu_regs_reg_alloc,
    1.69 +
    1.70 +    nof_caller_save_cpu_regs = pd_nof_caller_save_cpu_regs_frame_map,
    1.71 +    nof_caller_save_fpu_regs = pd_nof_caller_save_fpu_regs_frame_map,
    1.72 +
    1.73 +    spill_slot_size_in_bytes = 4
    1.74 +  };
    1.75 +
    1.76 +# include "incls/_c1_FrameMap_pd.hpp.incl"  // platform dependent declarations
    1.77 +
    1.78 +  friend class LIR_OprDesc;
    1.79 +
    1.80 + private:
    1.81 +  static bool         _init_done;
    1.82 +  static Register     _cpu_rnr2reg [nof_cpu_regs];
    1.83 +  static int          _cpu_reg2rnr [nof_cpu_regs];
    1.84 +
    1.85 +  static LIR_Opr      _caller_save_cpu_regs [nof_caller_save_cpu_regs];
    1.86 +  static LIR_Opr      _caller_save_fpu_regs [nof_caller_save_fpu_regs];
    1.87 +
    1.88 +  int                 _framesize;
    1.89 +  int                 _argcount;
    1.90 +  int                 _num_monitors;
    1.91 +  int                 _num_spills;
    1.92 +  int                 _reserved_argument_area_size;
    1.93 +  int                 _oop_map_arg_count;
    1.94 +
    1.95 +  CallingConvention*  _incoming_arguments;
    1.96 +  intArray*           _argument_locations;
    1.97 +
    1.98 +  void check_spill_index   (int spill_index)   const { assert(spill_index   >= 0, "bad index"); }
    1.99 +  void check_monitor_index (int monitor_index) const { assert(monitor_index >= 0 &&
   1.100 +                                                              monitor_index < _num_monitors, "bad index"); }
   1.101 +
   1.102 +  static Register cpu_rnr2reg (int rnr) {
   1.103 +    assert(_init_done, "tables not initialized");
   1.104 +    debug_only(cpu_range_check(rnr);)
   1.105 +    return _cpu_rnr2reg[rnr];
   1.106 +  }
   1.107 +
   1.108 +  static int cpu_reg2rnr (Register reg) {
   1.109 +    assert(_init_done, "tables not initialized");
   1.110 +    debug_only(cpu_range_check(reg->encoding());)
   1.111 +    return _cpu_reg2rnr[reg->encoding()];
   1.112 +  }
   1.113 +
   1.114 +  static void map_register(int rnr, Register reg) {
   1.115 +    debug_only(cpu_range_check(rnr);)
   1.116 +    debug_only(cpu_range_check(reg->encoding());)
   1.117 +    _cpu_rnr2reg[rnr] = reg;
   1.118 +    _cpu_reg2rnr[reg->encoding()] = rnr;
   1.119 +  }
   1.120 +
   1.121 +  void update_reserved_argument_area_size (int size) {
   1.122 +    assert(size >= 0, "check");
   1.123 +    _reserved_argument_area_size = MAX2(_reserved_argument_area_size, size);
   1.124 +  }
   1.125 +
   1.126 + protected:
   1.127 +#ifndef PRODUCT
   1.128 +  static void cpu_range_check (int rnr)          { assert(0 <= rnr && rnr < nof_cpu_regs, "cpu register number is too big"); }
   1.129 +  static void fpu_range_check (int rnr)          { assert(0 <= rnr && rnr < nof_fpu_regs, "fpu register number is too big"); }
   1.130 +#endif
   1.131 +
   1.132 +
   1.133 +  ByteSize sp_offset_for_monitor_base(const int idx) const;
   1.134 +
   1.135 +  Address make_new_address(ByteSize sp_offset) const;
   1.136 +
   1.137 +  ByteSize sp_offset_for_slot(const int idx) const;
   1.138 +  ByteSize sp_offset_for_double_slot(const int idx) const;
   1.139 +  ByteSize sp_offset_for_spill(const int idx) const;
   1.140 +  ByteSize sp_offset_for_monitor_lock(int monitor_index) const;
   1.141 +  ByteSize sp_offset_for_monitor_object(int monitor_index) const;
   1.142 +
   1.143 +  VMReg sp_offset2vmreg(ByteSize offset) const;
   1.144 +
   1.145 +  // platform dependent hook used to check that frame is properly
   1.146 +  // addressable on the platform.  Used by sparc to verify that all
   1.147 +  // stack addresses are expressable in a simm13.
   1.148 +  bool validate_frame();
   1.149 +
   1.150 +  static LIR_Opr map_to_opr(BasicType type, VMRegPair* reg, bool incoming);
   1.151 +
   1.152 + public:
   1.153 +  // Opr representing the stack_pointer on this platform
   1.154 +  static LIR_Opr stack_pointer();
   1.155 +
   1.156 +  static BasicTypeArray*     signature_type_array_for(const ciMethod* method);
   1.157 +  static BasicTypeArray*     signature_type_array_for(const char * signature);
   1.158 +
   1.159 +  // for outgoing calls, these also update the reserved area to
   1.160 +  // include space for arguments and any ABI area.
   1.161 +  CallingConvention* c_calling_convention (const BasicTypeArray* signature);
   1.162 +  CallingConvention* java_calling_convention (const BasicTypeArray* signature, bool outgoing);
   1.163 +
   1.164 +  // deopt support
   1.165 +  ByteSize sp_offset_for_orig_pc() { return sp_offset_for_monitor_base(_num_monitors); }
   1.166 +
   1.167 +  static LIR_Opr as_opr(Register r) {
   1.168 +    return LIR_OprFact::single_cpu(cpu_reg2rnr(r));
   1.169 +  }
   1.170 +  static LIR_Opr as_oop_opr(Register r) {
   1.171 +    return LIR_OprFact::single_cpu_oop(cpu_reg2rnr(r));
   1.172 +  }
   1.173 +
   1.174 +  FrameMap(ciMethod* method, int monitors, int reserved_argument_area_size);
   1.175 +  bool finalize_frame(int nof_slots);
   1.176 +
   1.177 +  int   reserved_argument_area_size () const     { return _reserved_argument_area_size; }
   1.178 +  int   framesize                   () const     { assert(_framesize != -1, "hasn't been calculated"); return _framesize; }
   1.179 +  ByteSize framesize_in_bytes       () const     { return in_ByteSize(framesize() * 4); }
   1.180 +  int   num_monitors                () const     { return _num_monitors; }
   1.181 +  int   num_spills                  () const     { assert(_num_spills >= 0, "not set"); return _num_spills; }
   1.182 +  int   argcount              () const     { assert(_argcount >= 0, "not set"); return _argcount; }
   1.183 +
   1.184 +  int oop_map_arg_count() const { return _oop_map_arg_count; }
   1.185 +
   1.186 +  CallingConvention* incoming_arguments() const  { return _incoming_arguments; }
   1.187 +
   1.188 +  // convenience routines
   1.189 +  Address address_for_slot(int index, int sp_adjust = 0) const {
   1.190 +    return make_new_address(sp_offset_for_slot(index) + in_ByteSize(sp_adjust));
   1.191 +  }
   1.192 +  Address address_for_double_slot(int index, int sp_adjust = 0) const {
   1.193 +    return make_new_address(sp_offset_for_double_slot(index) + in_ByteSize(sp_adjust));
   1.194 +  }
   1.195 +  Address address_for_monitor_lock(int monitor_index) const {
   1.196 +    return make_new_address(sp_offset_for_monitor_lock(monitor_index));
   1.197 +  }
   1.198 +  Address address_for_monitor_object(int monitor_index) const {
   1.199 +    return make_new_address(sp_offset_for_monitor_object(monitor_index));
   1.200 +  }
   1.201 +
   1.202 +  void print_frame_layout() const;
   1.203 +
   1.204 +  // Creates Location describing desired slot and returns it via pointer
   1.205 +  // to Location object. Returns true if the stack frame offset was legal
   1.206 +  // (as defined by Location::legal_offset_in_bytes()), false otherwise.
   1.207 +  // Do not use the returned location if this returns false.
   1.208 +  bool location_for_sp_offset(ByteSize byte_offset_from_sp,
   1.209 +                              Location::Type loc_type, Location* loc) const;
   1.210 +
   1.211 +  bool location_for_monitor_lock  (int monitor_index, Location* loc) const {
   1.212 +    return location_for_sp_offset(sp_offset_for_monitor_lock(monitor_index), Location::normal, loc);
   1.213 +  }
   1.214 +  bool location_for_monitor_object(int monitor_index, Location* loc) const {
   1.215 +    return location_for_sp_offset(sp_offset_for_monitor_object(monitor_index), Location::oop, loc);
   1.216 +  }
   1.217 +  bool locations_for_slot  (int index, Location::Type loc_type,
   1.218 +                            Location* loc, Location* second = NULL) const;
   1.219 +
   1.220 +  VMReg slot_regname(int index) const {
   1.221 +    return sp_offset2vmreg(sp_offset_for_slot(index));
   1.222 +  }
   1.223 +  VMReg monitor_object_regname(int monitor_index) const {
   1.224 +    return sp_offset2vmreg(sp_offset_for_monitor_object(monitor_index));
   1.225 +  }
   1.226 +  VMReg regname(LIR_Opr opr) const;
   1.227 +
   1.228 +  static LIR_Opr caller_save_cpu_reg_at(int i) {
   1.229 +    assert(i >= 0 && i < nof_caller_save_cpu_regs, "out of bounds");
   1.230 +    return _caller_save_cpu_regs[i];
   1.231 +  }
   1.232 +
   1.233 +  static LIR_Opr caller_save_fpu_reg_at(int i) {
   1.234 +    assert(i >= 0 && i < nof_caller_save_fpu_regs, "out of bounds");
   1.235 +    return _caller_save_fpu_regs[i];
   1.236 +  }
   1.237 +
   1.238 +  static void init();
   1.239 +};
   1.240 +
   1.241 +//               CallingConvention
   1.242 +//--------------------------------------------------------
   1.243 +
   1.244 +class CallingConvention: public ResourceObj {
   1.245 + private:
   1.246 +  LIR_OprList* _args;
   1.247 +  int          _reserved_stack_slots;
   1.248 +
   1.249 + public:
   1.250 +  CallingConvention (LIR_OprList* args, int reserved_stack_slots)
   1.251 +    : _args(args)
   1.252 +    , _reserved_stack_slots(reserved_stack_slots)  {}
   1.253 +
   1.254 +  LIR_OprList* args()       { return _args; }
   1.255 +
   1.256 +  LIR_Opr at(int i) const   { return _args->at(i); }
   1.257 +  int length() const        { return _args->length(); }
   1.258 +
   1.259 +  // Indicates number of real frame slots used by arguments passed on stack.
   1.260 +  int reserved_stack_slots() const            { return _reserved_stack_slots; }
   1.261 +
   1.262 +#ifndef PRODUCT
   1.263 +  void print () const {
   1.264 +    for (int i = 0; i < length(); i++) {
   1.265 +      at(i)->print();
   1.266 +    }
   1.267 +  }
   1.268 +#endif // PRODUCT
   1.269 +};

mercurial