src/share/vm/c1/c1_FrameMap.cpp

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 #include "precompiled.hpp"
aoqi@0 26 #include "c1/c1_FrameMap.hpp"
aoqi@0 27 #include "c1/c1_LIR.hpp"
aoqi@0 28 #include "runtime/sharedRuntime.hpp"
aoqi@0 29 #ifdef TARGET_ARCH_x86
aoqi@0 30 # include "vmreg_x86.inline.hpp"
aoqi@0 31 #endif
aoqi@0 32 #ifdef TARGET_ARCH_sparc
aoqi@0 33 # include "vmreg_sparc.inline.hpp"
aoqi@0 34 #endif
aoqi@0 35 #ifdef TARGET_ARCH_zero
aoqi@0 36 # include "vmreg_zero.inline.hpp"
aoqi@0 37 #endif
aoqi@0 38 #ifdef TARGET_ARCH_arm
aoqi@0 39 # include "vmreg_arm.inline.hpp"
aoqi@0 40 #endif
aoqi@0 41 #ifdef TARGET_ARCH_ppc
aoqi@0 42 # include "vmreg_ppc.inline.hpp"
aoqi@0 43 #endif
aoqi@0 44
aoqi@0 45
aoqi@0 46
aoqi@0 47 //-----------------------------------------------------
aoqi@0 48
aoqi@0 49 // Convert method signature into an array of BasicTypes for the arguments
aoqi@0 50 BasicTypeArray* FrameMap::signature_type_array_for(const ciMethod* method) {
aoqi@0 51 ciSignature* sig = method->signature();
aoqi@0 52 BasicTypeList* sta = new BasicTypeList(method->arg_size());
aoqi@0 53 // add receiver, if any
aoqi@0 54 if (!method->is_static()) sta->append(T_OBJECT);
aoqi@0 55 // add remaining arguments
aoqi@0 56 for (int i = 0; i < sig->count(); i++) {
aoqi@0 57 ciType* type = sig->type_at(i);
aoqi@0 58 BasicType t = type->basic_type();
aoqi@0 59 if (t == T_ARRAY) {
aoqi@0 60 t = T_OBJECT;
aoqi@0 61 }
aoqi@0 62 sta->append(t);
aoqi@0 63 }
aoqi@0 64 // done
aoqi@0 65 return sta;
aoqi@0 66 }
aoqi@0 67
aoqi@0 68
aoqi@0 69 CallingConvention* FrameMap::java_calling_convention(const BasicTypeArray* signature, bool outgoing) {
aoqi@0 70 // compute the size of the arguments first. The signature array
aoqi@0 71 // that java_calling_convention takes includes a T_VOID after double
aoqi@0 72 // work items but our signatures do not.
aoqi@0 73 int i;
aoqi@0 74 int sizeargs = 0;
aoqi@0 75 for (i = 0; i < signature->length(); i++) {
aoqi@0 76 sizeargs += type2size[signature->at(i)];
aoqi@0 77 }
aoqi@0 78
aoqi@0 79 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
aoqi@0 80 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
aoqi@0 81 int sig_index = 0;
aoqi@0 82 for (i = 0; i < sizeargs; i++, sig_index++) {
aoqi@0 83 sig_bt[i] = signature->at(sig_index);
aoqi@0 84 if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
aoqi@0 85 sig_bt[i + 1] = T_VOID;
aoqi@0 86 i++;
aoqi@0 87 }
aoqi@0 88 }
aoqi@0 89
aoqi@0 90 intptr_t out_preserve = SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs, outgoing);
aoqi@0 91 LIR_OprList* args = new LIR_OprList(signature->length());
aoqi@0 92 for (i = 0; i < sizeargs;) {
aoqi@0 93 BasicType t = sig_bt[i];
aoqi@0 94 assert(t != T_VOID, "should be skipping these");
aoqi@0 95 LIR_Opr opr = map_to_opr(t, regs + i, outgoing);
aoqi@0 96 args->append(opr);
aoqi@0 97 if (opr->is_address()) {
aoqi@0 98 LIR_Address* addr = opr->as_address_ptr();
aoqi@0 99 assert(addr->disp() == (int)addr->disp(), "out of range value");
aoqi@0 100 out_preserve = MAX2(out_preserve, (intptr_t)(addr->disp() - STACK_BIAS) / 4);
aoqi@0 101 }
aoqi@0 102 i += type2size[t];
aoqi@0 103 }
aoqi@0 104 assert(args->length() == signature->length(), "size mismatch");
aoqi@0 105 out_preserve += SharedRuntime::out_preserve_stack_slots();
aoqi@0 106
aoqi@0 107 if (outgoing) {
aoqi@0 108 // update the space reserved for arguments.
aoqi@0 109 update_reserved_argument_area_size(out_preserve * BytesPerWord);
aoqi@0 110 }
aoqi@0 111 return new CallingConvention(args, out_preserve);
aoqi@0 112 }
aoqi@0 113
aoqi@0 114
aoqi@0 115 CallingConvention* FrameMap::c_calling_convention(const BasicTypeArray* signature) {
aoqi@0 116 // compute the size of the arguments first. The signature array
aoqi@0 117 // that java_calling_convention takes includes a T_VOID after double
aoqi@0 118 // work items but our signatures do not.
aoqi@0 119 int i;
aoqi@0 120 int sizeargs = 0;
aoqi@0 121 for (i = 0; i < signature->length(); i++) {
aoqi@0 122 sizeargs += type2size[signature->at(i)];
aoqi@0 123 }
aoqi@0 124
aoqi@0 125 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
aoqi@0 126 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
aoqi@0 127 int sig_index = 0;
aoqi@0 128 for (i = 0; i < sizeargs; i++, sig_index++) {
aoqi@0 129 sig_bt[i] = signature->at(sig_index);
aoqi@0 130 if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
aoqi@0 131 sig_bt[i + 1] = T_VOID;
aoqi@0 132 i++;
aoqi@0 133 }
aoqi@0 134 }
aoqi@0 135
aoqi@0 136 intptr_t out_preserve = SharedRuntime::c_calling_convention(sig_bt, regs, NULL, sizeargs);
aoqi@0 137 LIR_OprList* args = new LIR_OprList(signature->length());
aoqi@0 138 for (i = 0; i < sizeargs;) {
aoqi@0 139 BasicType t = sig_bt[i];
aoqi@0 140 assert(t != T_VOID, "should be skipping these");
aoqi@0 141
aoqi@0 142 // C calls are always outgoing
aoqi@0 143 bool outgoing = true;
aoqi@0 144 LIR_Opr opr = map_to_opr(t, regs + i, outgoing);
aoqi@0 145 // they might be of different types if for instance floating point
aoqi@0 146 // values are passed in cpu registers, but the sizes must match.
aoqi@0 147 assert(type2size[opr->type()] == type2size[t], "type mismatch");
aoqi@0 148 args->append(opr);
aoqi@0 149 if (opr->is_address()) {
aoqi@0 150 LIR_Address* addr = opr->as_address_ptr();
aoqi@0 151 out_preserve = MAX2(out_preserve, (intptr_t)(addr->disp() - STACK_BIAS) / 4);
aoqi@0 152 }
aoqi@0 153 i += type2size[t];
aoqi@0 154 }
aoqi@0 155 assert(args->length() == signature->length(), "size mismatch");
aoqi@0 156 out_preserve += SharedRuntime::out_preserve_stack_slots();
aoqi@0 157 update_reserved_argument_area_size(out_preserve * BytesPerWord);
aoqi@0 158 return new CallingConvention(args, out_preserve);
aoqi@0 159 }
aoqi@0 160
aoqi@0 161
aoqi@0 162 //--------------------------------------------------------
aoqi@0 163 // FrameMap
aoqi@0 164 //--------------------------------------------------------
aoqi@0 165
aoqi@0 166 bool FrameMap::_init_done = false;
aoqi@0 167 Register FrameMap::_cpu_rnr2reg [FrameMap::nof_cpu_regs];
aoqi@0 168 int FrameMap::_cpu_reg2rnr [FrameMap::nof_cpu_regs];
aoqi@0 169
aoqi@0 170
aoqi@0 171 FrameMap::FrameMap(ciMethod* method, int monitors, int reserved_argument_area_size) {
aoqi@0 172 assert(_init_done, "should already be completed");
aoqi@0 173
aoqi@0 174 _framesize = -1;
aoqi@0 175 _num_spills = -1;
aoqi@0 176
aoqi@0 177 assert(monitors >= 0, "not set");
aoqi@0 178 _num_monitors = monitors;
aoqi@0 179 assert(reserved_argument_area_size >= 0, "not set");
aoqi@0 180 _reserved_argument_area_size = MAX2(4, reserved_argument_area_size) * BytesPerWord;
aoqi@0 181
aoqi@0 182 _argcount = method->arg_size();
aoqi@0 183 _argument_locations = new intArray(_argcount, -1);
aoqi@0 184 _incoming_arguments = java_calling_convention(signature_type_array_for(method), false);
aoqi@0 185 _oop_map_arg_count = _incoming_arguments->reserved_stack_slots();
aoqi@0 186
aoqi@0 187 int java_index = 0;
aoqi@0 188 for (int i = 0; i < _incoming_arguments->length(); i++) {
aoqi@0 189 LIR_Opr opr = _incoming_arguments->at(i);
aoqi@0 190 if (opr->is_address()) {
aoqi@0 191 LIR_Address* address = opr->as_address_ptr();
aoqi@0 192 _argument_locations->at_put(java_index, address->disp() - STACK_BIAS);
aoqi@0 193 _incoming_arguments->args()->at_put(i, LIR_OprFact::stack(java_index, as_BasicType(as_ValueType(address->type()))));
aoqi@0 194 }
aoqi@0 195 java_index += type2size[opr->type()];
aoqi@0 196 }
aoqi@0 197
aoqi@0 198 }
aoqi@0 199
aoqi@0 200
aoqi@0 201 bool FrameMap::finalize_frame(int nof_slots) {
aoqi@0 202 assert(nof_slots >= 0, "must be positive");
aoqi@0 203 assert(_num_spills == -1, "can only be set once");
aoqi@0 204 _num_spills = nof_slots;
aoqi@0 205 assert(_framesize == -1, "should only be calculated once");
aoqi@0 206 _framesize = round_to(in_bytes(sp_offset_for_monitor_base(0)) +
aoqi@0 207 _num_monitors * sizeof(BasicObjectLock) +
aoqi@0 208 sizeof(intptr_t) + // offset of deopt orig pc
aoqi@0 209 frame_pad_in_bytes,
aoqi@0 210 StackAlignmentInBytes) / 4;
aoqi@0 211 int java_index = 0;
aoqi@0 212 for (int i = 0; i < _incoming_arguments->length(); i++) {
aoqi@0 213 LIR_Opr opr = _incoming_arguments->at(i);
aoqi@0 214 if (opr->is_stack()) {
aoqi@0 215 _argument_locations->at_put(java_index, in_bytes(framesize_in_bytes()) +
aoqi@0 216 _argument_locations->at(java_index));
aoqi@0 217 }
aoqi@0 218 java_index += type2size[opr->type()];
aoqi@0 219 }
aoqi@0 220 // make sure it's expressible on the platform
aoqi@0 221 return validate_frame();
aoqi@0 222 }
aoqi@0 223
aoqi@0 224 VMReg FrameMap::sp_offset2vmreg(ByteSize offset) const {
aoqi@0 225 int offset_in_bytes = in_bytes(offset);
aoqi@0 226 assert(offset_in_bytes % 4 == 0, "must be multiple of 4 bytes");
aoqi@0 227 assert(offset_in_bytes / 4 < framesize() + oop_map_arg_count(), "out of range");
aoqi@0 228 return VMRegImpl::stack2reg(offset_in_bytes / 4);
aoqi@0 229 }
aoqi@0 230
aoqi@0 231
aoqi@0 232 bool FrameMap::location_for_sp_offset(ByteSize byte_offset_from_sp,
aoqi@0 233 Location::Type loc_type,
aoqi@0 234 Location* loc) const {
aoqi@0 235 int offset = in_bytes(byte_offset_from_sp);
aoqi@0 236 assert(offset >= 0, "incorrect offset");
aoqi@0 237 if (!Location::legal_offset_in_bytes(offset)) {
aoqi@0 238 return false;
aoqi@0 239 }
aoqi@0 240 Location tmp_loc = Location::new_stk_loc(loc_type, offset);
aoqi@0 241 *loc = tmp_loc;
aoqi@0 242 return true;
aoqi@0 243 }
aoqi@0 244
aoqi@0 245
aoqi@0 246 bool FrameMap::locations_for_slot (int index, Location::Type loc_type,
aoqi@0 247 Location* loc, Location* second) const {
aoqi@0 248 ByteSize offset_from_sp = sp_offset_for_slot(index);
aoqi@0 249 if (!location_for_sp_offset(offset_from_sp, loc_type, loc)) {
aoqi@0 250 return false;
aoqi@0 251 }
aoqi@0 252 if (second != NULL) {
aoqi@0 253 // two word item
aoqi@0 254 offset_from_sp = offset_from_sp + in_ByteSize(4);
aoqi@0 255 return location_for_sp_offset(offset_from_sp, loc_type, second);
aoqi@0 256 }
aoqi@0 257 return true;
aoqi@0 258 }
aoqi@0 259
aoqi@0 260 //////////////////////
aoqi@0 261 // Public accessors //
aoqi@0 262 //////////////////////
aoqi@0 263
aoqi@0 264
aoqi@0 265 ByteSize FrameMap::sp_offset_for_slot(const int index) const {
aoqi@0 266 if (index < argcount()) {
aoqi@0 267 int offset = _argument_locations->at(index);
aoqi@0 268 assert(offset != -1, "not a memory argument");
aoqi@0 269 assert(offset >= framesize() * 4, "argument inside of frame");
aoqi@0 270 return in_ByteSize(offset);
aoqi@0 271 }
aoqi@0 272 ByteSize offset = sp_offset_for_spill(index - argcount());
aoqi@0 273 assert(in_bytes(offset) < framesize() * 4, "spill outside of frame");
aoqi@0 274 return offset;
aoqi@0 275 }
aoqi@0 276
aoqi@0 277
aoqi@0 278 ByteSize FrameMap::sp_offset_for_double_slot(const int index) const {
aoqi@0 279 ByteSize offset = sp_offset_for_slot(index);
aoqi@0 280 if (index >= argcount()) {
aoqi@0 281 assert(in_bytes(offset) + 4 < framesize() * 4, "spill outside of frame");
aoqi@0 282 }
aoqi@0 283 return offset;
aoqi@0 284 }
aoqi@0 285
aoqi@0 286
aoqi@0 287 ByteSize FrameMap::sp_offset_for_spill(const int index) const {
aoqi@0 288 assert(index >= 0 && index < _num_spills, "out of range");
aoqi@0 289 int offset = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) +
aoqi@0 290 index * spill_slot_size_in_bytes;
aoqi@0 291 return in_ByteSize(offset);
aoqi@0 292 }
aoqi@0 293
aoqi@0 294 ByteSize FrameMap::sp_offset_for_monitor_base(const int index) const {
aoqi@0 295 int end_of_spills = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) +
aoqi@0 296 _num_spills * spill_slot_size_in_bytes;
aoqi@0 297 int offset = (int) round_to(end_of_spills, HeapWordSize) + index * sizeof(BasicObjectLock);
aoqi@0 298 return in_ByteSize(offset);
aoqi@0 299 }
aoqi@0 300
aoqi@0 301 ByteSize FrameMap::sp_offset_for_monitor_lock(int index) const {
aoqi@0 302 check_monitor_index(index);
aoqi@0 303 return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::lock_offset_in_bytes());;
aoqi@0 304 }
aoqi@0 305
aoqi@0 306 ByteSize FrameMap::sp_offset_for_monitor_object(int index) const {
aoqi@0 307 check_monitor_index(index);
aoqi@0 308 return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::obj_offset_in_bytes());
aoqi@0 309 }
aoqi@0 310
aoqi@0 311
aoqi@0 312 // For OopMaps, map a local variable or spill index to an VMReg.
aoqi@0 313 // This is the offset from sp() in the frame of the slot for the index,
aoqi@0 314 // skewed by SharedInfo::stack0 to indicate a stack location (vs.a register.)
aoqi@0 315 //
aoqi@0 316 // C ABI size +
aoqi@0 317 // framesize + framesize +
aoqi@0 318 // stack0 stack0 stack0 0 <- VMReg->value()
aoqi@0 319 // | | | <registers> |
aoqi@0 320 // ..........|..............|..............|.............|
aoqi@0 321 // 0 1 2 3 | <C ABI area> | 4 5 6 ...... | <- local indices
aoqi@0 322 // ^ ^ sp()
aoqi@0 323 // | |
aoqi@0 324 // arguments non-argument locals
aoqi@0 325
aoqi@0 326
aoqi@0 327 VMReg FrameMap::regname(LIR_Opr opr) const {
aoqi@0 328 if (opr->is_single_cpu()) {
aoqi@0 329 assert(!opr->is_virtual(), "should not see virtual registers here");
aoqi@0 330 return opr->as_register()->as_VMReg();
aoqi@0 331 } else if (opr->is_single_stack()) {
aoqi@0 332 return sp_offset2vmreg(sp_offset_for_slot(opr->single_stack_ix()));
aoqi@0 333 } else if (opr->is_address()) {
aoqi@0 334 LIR_Address* addr = opr->as_address_ptr();
aoqi@0 335 assert(addr->base() == stack_pointer(), "sp based addressing only");
aoqi@0 336 return sp_offset2vmreg(in_ByteSize(addr->index()->as_jint()));
aoqi@0 337 }
aoqi@0 338 ShouldNotReachHere();
aoqi@0 339 return VMRegImpl::Bad();
aoqi@0 340 }
aoqi@0 341
aoqi@0 342
aoqi@0 343
aoqi@0 344
aoqi@0 345 // ------------ extra spill slots ---------------

mercurial