src/share/vm/c1/c1_FrameMap.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 1
2d8a650513c2
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial