Wed, 03 Jul 2019 20:42:37 +0800
Merge
1 /*
2 * Copyright (c) 2000, 2013, 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 /*
26 * This file has been modified by Loongson Technology in 2015. These
27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
28 * available on the same license terms set forth above.
29 */
31 #ifndef SHARE_VM_C1_C1_FRAMEMAP_HPP
32 #define SHARE_VM_C1_C1_FRAMEMAP_HPP
34 #include "asm/assembler.hpp"
35 #include "c1/c1_Defs.hpp"
36 #include "c1/c1_LIR.hpp"
37 #include "code/vmreg.hpp"
38 #include "memory/allocation.hpp"
39 #include "runtime/frame.hpp"
40 #include "runtime/synchronizer.hpp"
41 #include "utilities/globalDefinitions.hpp"
43 class ciMethod;
44 class CallingConvention;
45 class BasicTypeArray;
46 class BasicTypeList;
48 //--------------------------------------------------------
49 // FrameMap
50 //--------------------------------------------------------
52 // This class is responsible of mapping items (locals, monitors, spill
53 // slots and registers to their frame location
54 //
55 // The monitors are specified by a consecutive index, although each monitor entry
56 // occupies two words. The monitor_index is 0.._num_monitors
57 // The spill index is similar to local index; it is in range 0..(open)
58 //
59 // The CPU registers are mapped using a fixed table; register with number 0
60 // is the most used one.
63 // stack grow direction --> SP
64 // +----------+---+----------+-------+------------------------+-----+
65 // |arguments | x | monitors | spill | reserved argument area | ABI |
66 // +----------+---+----------+-------+------------------------+-----+
67 //
68 // x = ABI area (SPARC) or return adress and link (i486)
69 // ABI = ABI area (SPARC) or nothing (i486)
72 class LIR_OprDesc;
73 typedef LIR_OprDesc* LIR_Opr;
76 class FrameMap : public CompilationResourceObj {
77 public:
78 enum {
79 nof_cpu_regs = pd_nof_cpu_regs_frame_map,
80 nof_fpu_regs = pd_nof_fpu_regs_frame_map,
82 nof_cpu_regs_reg_alloc = pd_nof_cpu_regs_reg_alloc,
83 nof_fpu_regs_reg_alloc = pd_nof_fpu_regs_reg_alloc,
85 max_nof_caller_save_cpu_regs = pd_nof_caller_save_cpu_regs_frame_map,
86 nof_caller_save_fpu_regs = pd_nof_caller_save_fpu_regs_frame_map,
88 spill_slot_size_in_bytes = 4
89 };
91 #ifdef TARGET_ARCH_x86
92 # include "c1_FrameMap_x86.hpp"
93 #endif
94 #ifdef TARGET_ARCH_mips
95 # include "c1_FrameMap_mips.hpp"
96 #endif
97 #ifdef TARGET_ARCH_sparc
98 # include "c1_FrameMap_sparc.hpp"
99 #endif
100 #ifdef TARGET_ARCH_arm
101 # include "c1_FrameMap_arm.hpp"
102 #endif
103 #ifdef TARGET_ARCH_ppc
104 # include "c1_FrameMap_ppc.hpp"
105 #endif
108 friend class LIR_OprDesc;
110 private:
111 static bool _init_done;
112 static Register _cpu_rnr2reg [nof_cpu_regs];
113 static int _cpu_reg2rnr [nof_cpu_regs];
115 static LIR_Opr _caller_save_cpu_regs [max_nof_caller_save_cpu_regs];
116 static LIR_Opr _caller_save_fpu_regs [nof_caller_save_fpu_regs];
118 int _framesize;
119 int _argcount;
120 int _num_monitors;
121 int _num_spills;
122 int _reserved_argument_area_size;
123 int _oop_map_arg_count;
125 CallingConvention* _incoming_arguments;
126 intArray* _argument_locations;
128 void check_spill_index (int spill_index) const { assert(spill_index >= 0, "bad index"); }
129 void check_monitor_index (int monitor_index) const { assert(monitor_index >= 0 &&
130 monitor_index < _num_monitors, "bad index"); }
132 static Register cpu_rnr2reg (int rnr) {
133 assert(_init_done, "tables not initialized");
134 debug_only(cpu_range_check(rnr);)
135 return _cpu_rnr2reg[rnr];
136 }
138 static int cpu_reg2rnr (Register reg) {
139 assert(_init_done, "tables not initialized");
140 debug_only(cpu_range_check(reg->encoding());)
141 return _cpu_reg2rnr[reg->encoding()];
142 }
144 static void map_register(int rnr, Register reg) {
145 debug_only(cpu_range_check(rnr);)
146 debug_only(cpu_range_check(reg->encoding());)
147 _cpu_rnr2reg[rnr] = reg;
148 _cpu_reg2rnr[reg->encoding()] = rnr;
149 }
151 void update_reserved_argument_area_size (int size) {
152 assert(size >= 0, "check");
153 _reserved_argument_area_size = MAX2(_reserved_argument_area_size, size);
154 }
156 protected:
157 #ifndef PRODUCT
158 static void cpu_range_check (int rnr) { assert(0 <= rnr && rnr < nof_cpu_regs, "cpu register number is too big"); }
159 static void fpu_range_check (int rnr) { assert(0 <= rnr && rnr < nof_fpu_regs, "fpu register number is too big"); }
160 #endif
163 ByteSize sp_offset_for_monitor_base(const int idx) const;
165 Address make_new_address(ByteSize sp_offset) const;
167 ByteSize sp_offset_for_slot(const int idx) const;
168 ByteSize sp_offset_for_double_slot(const int idx) const;
169 ByteSize sp_offset_for_spill(const int idx) const;
170 ByteSize sp_offset_for_monitor_lock(int monitor_index) const;
171 ByteSize sp_offset_for_monitor_object(int monitor_index) const;
173 VMReg sp_offset2vmreg(ByteSize offset) const;
175 // platform dependent hook used to check that frame is properly
176 // addressable on the platform. Used by sparc to verify that all
177 // stack addresses are expressable in a simm13.
178 bool validate_frame();
180 static LIR_Opr map_to_opr(BasicType type, VMRegPair* reg, bool incoming);
182 public:
183 // Opr representing the stack_pointer on this platform
184 static LIR_Opr stack_pointer();
186 // JSR 292
187 static LIR_Opr method_handle_invoke_SP_save_opr();
189 static BasicTypeArray* signature_type_array_for(const ciMethod* method);
191 // for outgoing calls, these also update the reserved area to
192 // include space for arguments and any ABI area.
193 CallingConvention* c_calling_convention(const BasicTypeArray* signature);
194 CallingConvention* java_calling_convention(const BasicTypeArray* signature, bool outgoing);
196 // deopt support
197 ByteSize sp_offset_for_orig_pc() { return sp_offset_for_monitor_base(_num_monitors); }
199 static LIR_Opr as_opr(Register r) {
200 return LIR_OprFact::single_cpu(cpu_reg2rnr(r));
201 }
202 static LIR_Opr as_oop_opr(Register r) {
203 return LIR_OprFact::single_cpu_oop(cpu_reg2rnr(r));
204 }
206 static LIR_Opr as_metadata_opr(Register r) {
207 return LIR_OprFact::single_cpu_metadata(cpu_reg2rnr(r));
208 }
210 FrameMap(ciMethod* method, int monitors, int reserved_argument_area_size);
211 bool finalize_frame(int nof_slots);
213 int reserved_argument_area_size () const { return _reserved_argument_area_size; }
214 int framesize () const { assert(_framesize != -1, "hasn't been calculated"); return _framesize; }
215 ByteSize framesize_in_bytes () const { return in_ByteSize(framesize() * 4); }
216 int num_monitors () const { return _num_monitors; }
217 int num_spills () const { assert(_num_spills >= 0, "not set"); return _num_spills; }
218 int argcount () const { assert(_argcount >= 0, "not set"); return _argcount; }
220 int oop_map_arg_count() const { return _oop_map_arg_count; }
222 CallingConvention* incoming_arguments() const { return _incoming_arguments; }
224 // convenience routines
225 Address address_for_slot(int index, int sp_adjust = 0) const {
226 return make_new_address(sp_offset_for_slot(index) + in_ByteSize(sp_adjust));
227 }
228 Address address_for_double_slot(int index, int sp_adjust = 0) const {
229 return make_new_address(sp_offset_for_double_slot(index) + in_ByteSize(sp_adjust));
230 }
231 Address address_for_monitor_lock(int monitor_index) const {
232 return make_new_address(sp_offset_for_monitor_lock(monitor_index));
233 }
234 Address address_for_monitor_object(int monitor_index) const {
235 return make_new_address(sp_offset_for_monitor_object(monitor_index));
236 }
238 // Creates Location describing desired slot and returns it via pointer
239 // to Location object. Returns true if the stack frame offset was legal
240 // (as defined by Location::legal_offset_in_bytes()), false otherwise.
241 // Do not use the returned location if this returns false.
242 bool location_for_sp_offset(ByteSize byte_offset_from_sp,
243 Location::Type loc_type, Location* loc) const;
245 bool location_for_monitor_lock (int monitor_index, Location* loc) const {
246 return location_for_sp_offset(sp_offset_for_monitor_lock(monitor_index), Location::normal, loc);
247 }
248 bool location_for_monitor_object(int monitor_index, Location* loc) const {
249 return location_for_sp_offset(sp_offset_for_monitor_object(monitor_index), Location::oop, loc);
250 }
251 bool locations_for_slot (int index, Location::Type loc_type,
252 Location* loc, Location* second = NULL) const;
254 VMReg slot_regname(int index) const {
255 return sp_offset2vmreg(sp_offset_for_slot(index));
256 }
257 VMReg monitor_object_regname(int monitor_index) const {
258 return sp_offset2vmreg(sp_offset_for_monitor_object(monitor_index));
259 }
260 VMReg regname(LIR_Opr opr) const;
262 static LIR_Opr caller_save_cpu_reg_at(int i) {
263 assert(i >= 0 && i < max_nof_caller_save_cpu_regs, "out of bounds");
264 return _caller_save_cpu_regs[i];
265 }
267 static LIR_Opr caller_save_fpu_reg_at(int i) {
268 assert(i >= 0 && i < nof_caller_save_fpu_regs, "out of bounds");
269 return _caller_save_fpu_regs[i];
270 }
272 static void initialize();
273 };
275 // CallingConvention
276 //--------------------------------------------------------
278 class CallingConvention: public ResourceObj {
279 private:
280 LIR_OprList* _args;
281 int _reserved_stack_slots;
283 public:
284 CallingConvention (LIR_OprList* args, int reserved_stack_slots)
285 : _args(args)
286 , _reserved_stack_slots(reserved_stack_slots) {}
288 LIR_OprList* args() { return _args; }
290 LIR_Opr at(int i) const { return _args->at(i); }
291 int length() const { return _args->length(); }
293 // Indicates number of real frame slots used by arguments passed on stack.
294 int reserved_stack_slots() const { return _reserved_stack_slots; }
296 #ifndef PRODUCT
297 void print () const {
298 for (int i = 0; i < length(); i++) {
299 at(i)->print();
300 }
301 }
302 #endif // PRODUCT
303 };
305 #endif // SHARE_VM_C1_C1_FRAMEMAP_HPP