annotate src/share/vm/c1/c1_FrameMap.hpp @ 0:a61af66fc99e

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 61b2245abf36 c18cbe5936b8
rev   line source
duke@0 1 /*
duke@0 2 * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 class ciMethod;
duke@0 26 class CallingConvention;
duke@0 27 class BasicTypeArray;
duke@0 28 class BasicTypeList;
duke@0 29
duke@0 30 //--------------------------------------------------------
duke@0 31 // FrameMap
duke@0 32 //--------------------------------------------------------
duke@0 33
duke@0 34 // This class is responsible of mapping items (locals, monitors, spill
duke@0 35 // slots and registers to their frame location
duke@0 36 //
duke@0 37 // The monitors are specified by a consecutive index, although each monitor entry
duke@0 38 // occupies two words. The monitor_index is 0.._num_monitors
duke@0 39 // The spill index is similar to local index; it is in range 0..(open)
duke@0 40 //
duke@0 41 // The CPU registers are mapped using a fixed table; register with number 0
duke@0 42 // is the most used one.
duke@0 43
duke@0 44
duke@0 45 // stack grow direction --> SP
duke@0 46 // +----------+---+----------+-------+------------------------+-----+
duke@0 47 // |arguments | x | monitors | spill | reserved argument area | ABI |
duke@0 48 // +----------+---+----------+-------+------------------------+-----+
duke@0 49 //
duke@0 50 // x = ABI area (SPARC) or return adress and link (i486)
duke@0 51 // ABI = ABI area (SPARC) or nothing (i486)
duke@0 52
duke@0 53
duke@0 54 class LIR_OprDesc;
duke@0 55 typedef LIR_OprDesc* LIR_Opr;
duke@0 56
duke@0 57
duke@0 58 class FrameMap : public CompilationResourceObj {
duke@0 59 public:
duke@0 60 enum {
duke@0 61 nof_cpu_regs = pd_nof_cpu_regs_frame_map,
duke@0 62 nof_fpu_regs = pd_nof_fpu_regs_frame_map,
duke@0 63
duke@0 64 nof_cpu_regs_reg_alloc = pd_nof_cpu_regs_reg_alloc,
duke@0 65 nof_fpu_regs_reg_alloc = pd_nof_fpu_regs_reg_alloc,
duke@0 66
duke@0 67 nof_caller_save_cpu_regs = pd_nof_caller_save_cpu_regs_frame_map,
duke@0 68 nof_caller_save_fpu_regs = pd_nof_caller_save_fpu_regs_frame_map,
duke@0 69
duke@0 70 spill_slot_size_in_bytes = 4
duke@0 71 };
duke@0 72
duke@0 73 # include "incls/_c1_FrameMap_pd.hpp.incl" // platform dependent declarations
duke@0 74
duke@0 75 friend class LIR_OprDesc;
duke@0 76
duke@0 77 private:
duke@0 78 static bool _init_done;
duke@0 79 static Register _cpu_rnr2reg [nof_cpu_regs];
duke@0 80 static int _cpu_reg2rnr [nof_cpu_regs];
duke@0 81
duke@0 82 static LIR_Opr _caller_save_cpu_regs [nof_caller_save_cpu_regs];
duke@0 83 static LIR_Opr _caller_save_fpu_regs [nof_caller_save_fpu_regs];
duke@0 84
duke@0 85 int _framesize;
duke@0 86 int _argcount;
duke@0 87 int _num_monitors;
duke@0 88 int _num_spills;
duke@0 89 int _reserved_argument_area_size;
duke@0 90 int _oop_map_arg_count;
duke@0 91
duke@0 92 CallingConvention* _incoming_arguments;
duke@0 93 intArray* _argument_locations;
duke@0 94
duke@0 95 void check_spill_index (int spill_index) const { assert(spill_index >= 0, "bad index"); }
duke@0 96 void check_monitor_index (int monitor_index) const { assert(monitor_index >= 0 &&
duke@0 97 monitor_index < _num_monitors, "bad index"); }
duke@0 98
duke@0 99 static Register cpu_rnr2reg (int rnr) {
duke@0 100 assert(_init_done, "tables not initialized");
duke@0 101 debug_only(cpu_range_check(rnr);)
duke@0 102 return _cpu_rnr2reg[rnr];
duke@0 103 }
duke@0 104
duke@0 105 static int cpu_reg2rnr (Register reg) {
duke@0 106 assert(_init_done, "tables not initialized");
duke@0 107 debug_only(cpu_range_check(reg->encoding());)
duke@0 108 return _cpu_reg2rnr[reg->encoding()];
duke@0 109 }
duke@0 110
duke@0 111 static void map_register(int rnr, Register reg) {
duke@0 112 debug_only(cpu_range_check(rnr);)
duke@0 113 debug_only(cpu_range_check(reg->encoding());)
duke@0 114 _cpu_rnr2reg[rnr] = reg;
duke@0 115 _cpu_reg2rnr[reg->encoding()] = rnr;
duke@0 116 }
duke@0 117
duke@0 118 void update_reserved_argument_area_size (int size) {
duke@0 119 assert(size >= 0, "check");
duke@0 120 _reserved_argument_area_size = MAX2(_reserved_argument_area_size, size);
duke@0 121 }
duke@0 122
duke@0 123 protected:
duke@0 124 #ifndef PRODUCT
duke@0 125 static void cpu_range_check (int rnr) { assert(0 <= rnr && rnr < nof_cpu_regs, "cpu register number is too big"); }
duke@0 126 static void fpu_range_check (int rnr) { assert(0 <= rnr && rnr < nof_fpu_regs, "fpu register number is too big"); }
duke@0 127 #endif
duke@0 128
duke@0 129
duke@0 130 ByteSize sp_offset_for_monitor_base(const int idx) const;
duke@0 131
duke@0 132 Address make_new_address(ByteSize sp_offset) const;
duke@0 133
duke@0 134 ByteSize sp_offset_for_slot(const int idx) const;
duke@0 135 ByteSize sp_offset_for_double_slot(const int idx) const;
duke@0 136 ByteSize sp_offset_for_spill(const int idx) const;
duke@0 137 ByteSize sp_offset_for_monitor_lock(int monitor_index) const;
duke@0 138 ByteSize sp_offset_for_monitor_object(int monitor_index) const;
duke@0 139
duke@0 140 VMReg sp_offset2vmreg(ByteSize offset) const;
duke@0 141
duke@0 142 // platform dependent hook used to check that frame is properly
duke@0 143 // addressable on the platform. Used by sparc to verify that all
duke@0 144 // stack addresses are expressable in a simm13.
duke@0 145 bool validate_frame();
duke@0 146
duke@0 147 static LIR_Opr map_to_opr(BasicType type, VMRegPair* reg, bool incoming);
duke@0 148
duke@0 149 public:
duke@0 150 // Opr representing the stack_pointer on this platform
duke@0 151 static LIR_Opr stack_pointer();
duke@0 152
duke@0 153 static BasicTypeArray* signature_type_array_for(const ciMethod* method);
duke@0 154 static BasicTypeArray* signature_type_array_for(const char * signature);
duke@0 155
duke@0 156 // for outgoing calls, these also update the reserved area to
duke@0 157 // include space for arguments and any ABI area.
duke@0 158 CallingConvention* c_calling_convention (const BasicTypeArray* signature);
duke@0 159 CallingConvention* java_calling_convention (const BasicTypeArray* signature, bool outgoing);
duke@0 160
duke@0 161 // deopt support
duke@0 162 ByteSize sp_offset_for_orig_pc() { return sp_offset_for_monitor_base(_num_monitors); }
duke@0 163
duke@0 164 static LIR_Opr as_opr(Register r) {
duke@0 165 return LIR_OprFact::single_cpu(cpu_reg2rnr(r));
duke@0 166 }
duke@0 167 static LIR_Opr as_oop_opr(Register r) {
duke@0 168 return LIR_OprFact::single_cpu_oop(cpu_reg2rnr(r));
duke@0 169 }
duke@0 170
duke@0 171 FrameMap(ciMethod* method, int monitors, int reserved_argument_area_size);
duke@0 172 bool finalize_frame(int nof_slots);
duke@0 173
duke@0 174 int reserved_argument_area_size () const { return _reserved_argument_area_size; }
duke@0 175 int framesize () const { assert(_framesize != -1, "hasn't been calculated"); return _framesize; }
duke@0 176 ByteSize framesize_in_bytes () const { return in_ByteSize(framesize() * 4); }
duke@0 177 int num_monitors () const { return _num_monitors; }
duke@0 178 int num_spills () const { assert(_num_spills >= 0, "not set"); return _num_spills; }
duke@0 179 int argcount () const { assert(_argcount >= 0, "not set"); return _argcount; }
duke@0 180
duke@0 181 int oop_map_arg_count() const { return _oop_map_arg_count; }
duke@0 182
duke@0 183 CallingConvention* incoming_arguments() const { return _incoming_arguments; }
duke@0 184
duke@0 185 // convenience routines
duke@0 186 Address address_for_slot(int index, int sp_adjust = 0) const {
duke@0 187 return make_new_address(sp_offset_for_slot(index) + in_ByteSize(sp_adjust));
duke@0 188 }
duke@0 189 Address address_for_double_slot(int index, int sp_adjust = 0) const {
duke@0 190 return make_new_address(sp_offset_for_double_slot(index) + in_ByteSize(sp_adjust));
duke@0 191 }
duke@0 192 Address address_for_monitor_lock(int monitor_index) const {
duke@0 193 return make_new_address(sp_offset_for_monitor_lock(monitor_index));
duke@0 194 }
duke@0 195 Address address_for_monitor_object(int monitor_index) const {
duke@0 196 return make_new_address(sp_offset_for_monitor_object(monitor_index));
duke@0 197 }
duke@0 198
duke@0 199 void print_frame_layout() const;
duke@0 200
duke@0 201 // Creates Location describing desired slot and returns it via pointer
duke@0 202 // to Location object. Returns true if the stack frame offset was legal
duke@0 203 // (as defined by Location::legal_offset_in_bytes()), false otherwise.
duke@0 204 // Do not use the returned location if this returns false.
duke@0 205 bool location_for_sp_offset(ByteSize byte_offset_from_sp,
duke@0 206 Location::Type loc_type, Location* loc) const;
duke@0 207
duke@0 208 bool location_for_monitor_lock (int monitor_index, Location* loc) const {
duke@0 209 return location_for_sp_offset(sp_offset_for_monitor_lock(monitor_index), Location::normal, loc);
duke@0 210 }
duke@0 211 bool location_for_monitor_object(int monitor_index, Location* loc) const {
duke@0 212 return location_for_sp_offset(sp_offset_for_monitor_object(monitor_index), Location::oop, loc);
duke@0 213 }
duke@0 214 bool locations_for_slot (int index, Location::Type loc_type,
duke@0 215 Location* loc, Location* second = NULL) const;
duke@0 216
duke@0 217 VMReg slot_regname(int index) const {
duke@0 218 return sp_offset2vmreg(sp_offset_for_slot(index));
duke@0 219 }
duke@0 220 VMReg monitor_object_regname(int monitor_index) const {
duke@0 221 return sp_offset2vmreg(sp_offset_for_monitor_object(monitor_index));
duke@0 222 }
duke@0 223 VMReg regname(LIR_Opr opr) const;
duke@0 224
duke@0 225 static LIR_Opr caller_save_cpu_reg_at(int i) {
duke@0 226 assert(i >= 0 && i < nof_caller_save_cpu_regs, "out of bounds");
duke@0 227 return _caller_save_cpu_regs[i];
duke@0 228 }
duke@0 229
duke@0 230 static LIR_Opr caller_save_fpu_reg_at(int i) {
duke@0 231 assert(i >= 0 && i < nof_caller_save_fpu_regs, "out of bounds");
duke@0 232 return _caller_save_fpu_regs[i];
duke@0 233 }
duke@0 234
duke@0 235 static void init();
duke@0 236 };
duke@0 237
duke@0 238 // CallingConvention
duke@0 239 //--------------------------------------------------------
duke@0 240
duke@0 241 class CallingConvention: public ResourceObj {
duke@0 242 private:
duke@0 243 LIR_OprList* _args;
duke@0 244 int _reserved_stack_slots;
duke@0 245
duke@0 246 public:
duke@0 247 CallingConvention (LIR_OprList* args, int reserved_stack_slots)
duke@0 248 : _args(args)
duke@0 249 , _reserved_stack_slots(reserved_stack_slots) {}
duke@0 250
duke@0 251 LIR_OprList* args() { return _args; }
duke@0 252
duke@0 253 LIR_Opr at(int i) const { return _args->at(i); }
duke@0 254 int length() const { return _args->length(); }
duke@0 255
duke@0 256 // Indicates number of real frame slots used by arguments passed on stack.
duke@0 257 int reserved_stack_slots() const { return _reserved_stack_slots; }
duke@0 258
duke@0 259 #ifndef PRODUCT
duke@0 260 void print () const {
duke@0 261 for (int i = 0; i < length(); i++) {
duke@0 262 at(i)->print();
duke@0 263 }
duke@0 264 }
duke@0 265 #endif // PRODUCT
duke@0 266 };