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