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