annotate src/share/vm/c1/c1_FrameMap.cpp @ 1601:126ea7725993

6953477: Increase portability and flexibility of building Hotspot Summary: A collection of portability improvements including shared code support for PPC, ARM platforms, software floating point, cross compilation support and improvements in error crash detail. Reviewed-by: phh, never, coleenp, dholmes
author bobv
date Tue, 03 Aug 2010 08:13:38 -0400
parents b812ff5abc73
children f95d63e2154a
rev   line source
duke@0 1 /*
trims@1472 2 * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 # include "incls/_precompiled.incl"
duke@0 26 # include "incls/_c1_FrameMap.cpp.incl"
duke@0 27
duke@0 28
duke@0 29
duke@0 30 //-----------------------------------------------------
duke@0 31
duke@0 32 // Convert method signature into an array of BasicTypes for the arguments
duke@0 33 BasicTypeArray* FrameMap::signature_type_array_for(const ciMethod* method) {
duke@0 34 ciSignature* sig = method->signature();
duke@0 35 BasicTypeList* sta = new BasicTypeList(method->arg_size());
duke@0 36 // add receiver, if any
duke@0 37 if (!method->is_static()) sta->append(T_OBJECT);
duke@0 38 // add remaining arguments
duke@0 39 for (int i = 0; i < sig->count(); i++) {
duke@0 40 ciType* type = sig->type_at(i);
duke@0 41 BasicType t = type->basic_type();
duke@0 42 if (t == T_ARRAY) {
duke@0 43 t = T_OBJECT;
duke@0 44 }
duke@0 45 sta->append(t);
duke@0 46 }
duke@0 47 // done
duke@0 48 return sta;
duke@0 49 }
duke@0 50
duke@0 51
duke@0 52 CallingConvention* FrameMap::java_calling_convention(const BasicTypeArray* signature, bool outgoing) {
duke@0 53 // compute the size of the arguments first. The signature array
duke@0 54 // that java_calling_convention takes includes a T_VOID after double
duke@0 55 // work items but our signatures do not.
duke@0 56 int i;
duke@0 57 int sizeargs = 0;
duke@0 58 for (i = 0; i < signature->length(); i++) {
duke@0 59 sizeargs += type2size[signature->at(i)];
duke@0 60 }
duke@0 61
duke@0 62 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
duke@0 63 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
duke@0 64 int sig_index = 0;
duke@0 65 for (i = 0; i < sizeargs; i++, sig_index++) {
duke@0 66 sig_bt[i] = signature->at(sig_index);
duke@0 67 if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
duke@0 68 sig_bt[i + 1] = T_VOID;
duke@0 69 i++;
duke@0 70 }
duke@0 71 }
duke@0 72
duke@0 73 intptr_t out_preserve = SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs, outgoing);
duke@0 74 LIR_OprList* args = new LIR_OprList(signature->length());
duke@0 75 for (i = 0; i < sizeargs;) {
duke@0 76 BasicType t = sig_bt[i];
duke@0 77 assert(t != T_VOID, "should be skipping these");
duke@0 78
duke@0 79 LIR_Opr opr = map_to_opr(t, regs + i, outgoing);
duke@0 80 args->append(opr);
duke@0 81 if (opr->is_address()) {
duke@0 82 LIR_Address* addr = opr->as_address_ptr();
duke@0 83 assert(addr->disp() == (int)addr->disp(), "out of range value");
duke@0 84 out_preserve = MAX2(out_preserve, (intptr_t)addr->disp() / 4);
duke@0 85 }
duke@0 86 i += type2size[t];
duke@0 87 }
duke@0 88 assert(args->length() == signature->length(), "size mismatch");
duke@0 89 out_preserve += SharedRuntime::out_preserve_stack_slots();
duke@0 90
duke@0 91 if (outgoing) {
duke@0 92 // update the space reserved for arguments.
bobv@1601 93 update_reserved_argument_area_size(out_preserve * BytesPerWord);
duke@0 94 }
duke@0 95 return new CallingConvention(args, out_preserve);
duke@0 96 }
duke@0 97
duke@0 98
duke@0 99 CallingConvention* FrameMap::c_calling_convention(const BasicTypeArray* signature) {
duke@0 100 // compute the size of the arguments first. The signature array
duke@0 101 // that java_calling_convention takes includes a T_VOID after double
duke@0 102 // work items but our signatures do not.
duke@0 103 int i;
duke@0 104 int sizeargs = 0;
duke@0 105 for (i = 0; i < signature->length(); i++) {
duke@0 106 sizeargs += type2size[signature->at(i)];
duke@0 107 }
duke@0 108
duke@0 109 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
duke@0 110 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
duke@0 111 int sig_index = 0;
duke@0 112 for (i = 0; i < sizeargs; i++, sig_index++) {
duke@0 113 sig_bt[i] = signature->at(sig_index);
duke@0 114 if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
duke@0 115 sig_bt[i + 1] = T_VOID;
duke@0 116 i++;
duke@0 117 }
duke@0 118 }
duke@0 119
duke@0 120 intptr_t out_preserve = SharedRuntime::c_calling_convention(sig_bt, regs, sizeargs);
duke@0 121 LIR_OprList* args = new LIR_OprList(signature->length());
duke@0 122 for (i = 0; i < sizeargs;) {
duke@0 123 BasicType t = sig_bt[i];
duke@0 124 assert(t != T_VOID, "should be skipping these");
duke@0 125
duke@0 126 // C calls are always outgoing
duke@0 127 bool outgoing = true;
duke@0 128 LIR_Opr opr = map_to_opr(t, regs + i, outgoing);
duke@0 129 // they might be of different types if for instance floating point
duke@0 130 // values are passed in cpu registers, but the sizes must match.
duke@0 131 assert(type2size[opr->type()] == type2size[t], "type mismatch");
duke@0 132 args->append(opr);
duke@0 133 if (opr->is_address()) {
duke@0 134 LIR_Address* addr = opr->as_address_ptr();
duke@0 135 out_preserve = MAX2(out_preserve, (intptr_t)addr->disp() / 4);
duke@0 136 }
duke@0 137 i += type2size[t];
duke@0 138 }
duke@0 139 assert(args->length() == signature->length(), "size mismatch");
duke@0 140 out_preserve += SharedRuntime::out_preserve_stack_slots();
bobv@1601 141 update_reserved_argument_area_size(out_preserve * BytesPerWord);
duke@0 142 return new CallingConvention(args, out_preserve);
duke@0 143 }
duke@0 144
duke@0 145
duke@0 146 //--------------------------------------------------------
duke@0 147 // FrameMap
duke@0 148 //--------------------------------------------------------
duke@0 149
duke@0 150 bool FrameMap::_init_done = false;
duke@0 151 Register FrameMap::_cpu_rnr2reg [FrameMap::nof_cpu_regs];
duke@0 152 int FrameMap::_cpu_reg2rnr [FrameMap::nof_cpu_regs];
duke@0 153
duke@0 154
duke@0 155 FrameMap::FrameMap(ciMethod* method, int monitors, int reserved_argument_area_size) {
iveresov@1504 156 assert(_init_done, "should already be completed");
duke@0 157
duke@0 158 _framesize = -1;
duke@0 159 _num_spills = -1;
duke@0 160
duke@0 161 assert(monitors >= 0, "not set");
duke@0 162 _num_monitors = monitors;
duke@0 163 assert(reserved_argument_area_size >= 0, "not set");
duke@0 164 _reserved_argument_area_size = MAX2(4, reserved_argument_area_size) * BytesPerWord;
duke@0 165
duke@0 166 _argcount = method->arg_size();
duke@0 167 _argument_locations = new intArray(_argcount, -1);
duke@0 168 _incoming_arguments = java_calling_convention(signature_type_array_for(method), false);
duke@0 169 _oop_map_arg_count = _incoming_arguments->reserved_stack_slots();
duke@0 170
duke@0 171 int java_index = 0;
duke@0 172 for (int i = 0; i < _incoming_arguments->length(); i++) {
duke@0 173 LIR_Opr opr = _incoming_arguments->at(i);
duke@0 174 if (opr->is_address()) {
duke@0 175 LIR_Address* address = opr->as_address_ptr();
duke@0 176 _argument_locations->at_put(java_index, address->disp() - STACK_BIAS);
duke@0 177 _incoming_arguments->args()->at_put(i, LIR_OprFact::stack(java_index, as_BasicType(as_ValueType(address->type()))));
duke@0 178 }
duke@0 179 java_index += type2size[opr->type()];
duke@0 180 }
duke@0 181
duke@0 182 }
duke@0 183
duke@0 184
duke@0 185 bool FrameMap::finalize_frame(int nof_slots) {
duke@0 186 assert(nof_slots >= 0, "must be positive");
duke@0 187 assert(_num_spills == -1, "can only be set once");
duke@0 188 _num_spills = nof_slots;
duke@0 189 assert(_framesize == -1, "should only be calculated once");
duke@0 190 _framesize = round_to(in_bytes(sp_offset_for_monitor_base(0)) +
duke@0 191 _num_monitors * sizeof(BasicObjectLock) +
duke@0 192 sizeof(intptr_t) + // offset of deopt orig pc
duke@0 193 frame_pad_in_bytes,
duke@0 194 StackAlignmentInBytes) / 4;
duke@0 195 int java_index = 0;
duke@0 196 for (int i = 0; i < _incoming_arguments->length(); i++) {
duke@0 197 LIR_Opr opr = _incoming_arguments->at(i);
duke@0 198 if (opr->is_stack()) {
duke@0 199 _argument_locations->at_put(java_index, in_bytes(framesize_in_bytes()) +
duke@0 200 _argument_locations->at(java_index));
duke@0 201 }
duke@0 202 java_index += type2size[opr->type()];
duke@0 203 }
duke@0 204 // make sure it's expressible on the platform
duke@0 205 return validate_frame();
duke@0 206 }
duke@0 207
duke@0 208 VMReg FrameMap::sp_offset2vmreg(ByteSize offset) const {
duke@0 209 int offset_in_bytes = in_bytes(offset);
duke@0 210 assert(offset_in_bytes % 4 == 0, "must be multiple of 4 bytes");
duke@0 211 assert(offset_in_bytes / 4 < framesize() + oop_map_arg_count(), "out of range");
duke@0 212 return VMRegImpl::stack2reg(offset_in_bytes / 4);
duke@0 213 }
duke@0 214
duke@0 215
duke@0 216 bool FrameMap::location_for_sp_offset(ByteSize byte_offset_from_sp,
duke@0 217 Location::Type loc_type,
duke@0 218 Location* loc) const {
duke@0 219 int offset = in_bytes(byte_offset_from_sp);
duke@0 220 assert(offset >= 0, "incorrect offset");
duke@0 221 if (!Location::legal_offset_in_bytes(offset)) {
duke@0 222 return false;
duke@0 223 }
duke@0 224 Location tmp_loc = Location::new_stk_loc(loc_type, offset);
duke@0 225 *loc = tmp_loc;
duke@0 226 return true;
duke@0 227 }
duke@0 228
duke@0 229
duke@0 230 bool FrameMap::locations_for_slot (int index, Location::Type loc_type,
duke@0 231 Location* loc, Location* second) const {
duke@0 232 ByteSize offset_from_sp = sp_offset_for_slot(index);
duke@0 233 if (!location_for_sp_offset(offset_from_sp, loc_type, loc)) {
duke@0 234 return false;
duke@0 235 }
duke@0 236 if (second != NULL) {
duke@0 237 // two word item
duke@0 238 offset_from_sp = offset_from_sp + in_ByteSize(4);
duke@0 239 return location_for_sp_offset(offset_from_sp, loc_type, second);
duke@0 240 }
duke@0 241 return true;
duke@0 242 }
duke@0 243
duke@0 244 //////////////////////
duke@0 245 // Public accessors //
duke@0 246 //////////////////////
duke@0 247
duke@0 248
duke@0 249 ByteSize FrameMap::sp_offset_for_slot(const int index) const {
duke@0 250 if (index < argcount()) {
duke@0 251 int offset = _argument_locations->at(index);
duke@0 252 assert(offset != -1, "not a memory argument");
duke@0 253 assert(offset >= framesize() * 4, "argument inside of frame");
duke@0 254 return in_ByteSize(offset);
duke@0 255 }
duke@0 256 ByteSize offset = sp_offset_for_spill(index - argcount());
duke@0 257 assert(in_bytes(offset) < framesize() * 4, "spill outside of frame");
duke@0 258 return offset;
duke@0 259 }
duke@0 260
duke@0 261
duke@0 262 ByteSize FrameMap::sp_offset_for_double_slot(const int index) const {
duke@0 263 ByteSize offset = sp_offset_for_slot(index);
duke@0 264 if (index >= argcount()) {
duke@0 265 assert(in_bytes(offset) + 4 < framesize() * 4, "spill outside of frame");
duke@0 266 }
duke@0 267 return offset;
duke@0 268 }
duke@0 269
duke@0 270
duke@0 271 ByteSize FrameMap::sp_offset_for_spill(const int index) const {
duke@0 272 assert(index >= 0 && index < _num_spills, "out of range");
duke@0 273 int offset = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) +
duke@0 274 index * spill_slot_size_in_bytes;
duke@0 275 return in_ByteSize(offset);
duke@0 276 }
duke@0 277
duke@0 278 ByteSize FrameMap::sp_offset_for_monitor_base(const int index) const {
duke@0 279 int end_of_spills = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) +
duke@0 280 _num_spills * spill_slot_size_in_bytes;
never@304 281 int offset = (int) round_to(end_of_spills, HeapWordSize) + index * sizeof(BasicObjectLock);
duke@0 282 return in_ByteSize(offset);
duke@0 283 }
duke@0 284
duke@0 285 ByteSize FrameMap::sp_offset_for_monitor_lock(int index) const {
duke@0 286 check_monitor_index(index);
duke@0 287 return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::lock_offset_in_bytes());;
duke@0 288 }
duke@0 289
duke@0 290 ByteSize FrameMap::sp_offset_for_monitor_object(int index) const {
duke@0 291 check_monitor_index(index);
duke@0 292 return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::obj_offset_in_bytes());
duke@0 293 }
duke@0 294
duke@0 295 void FrameMap::print_frame_layout() const {
duke@0 296 int svar;
duke@0 297 tty->print_cr("#####################################");
duke@0 298 tty->print_cr("Frame size in words %d", framesize());
duke@0 299
duke@0 300 if( _num_monitors > 0) {
duke@0 301 tty->print_cr("monitor [0]:%d | [%2d]:%d",
duke@0 302 in_bytes(sp_offset_for_monitor_base(0)),
duke@0 303 in_bytes(sp_offset_for_monitor_base(_num_monitors)));
duke@0 304 }
duke@0 305 if( _num_spills > 0) {
duke@0 306 svar = _num_spills - 1;
duke@0 307 if(svar == 0)
duke@0 308 tty->print_cr("spill [0]:%d", in_bytes(sp_offset_for_spill(0)));
duke@0 309 else
duke@0 310 tty->print_cr("spill [0]:%d | [%2d]:%d", in_bytes(sp_offset_for_spill(0)),
duke@0 311 svar,
duke@0 312 in_bytes(sp_offset_for_spill(svar)));
duke@0 313 }
duke@0 314 }
duke@0 315
duke@0 316
duke@0 317 // For OopMaps, map a local variable or spill index to an VMReg.
duke@0 318 // This is the offset from sp() in the frame of the slot for the index,
duke@0 319 // skewed by SharedInfo::stack0 to indicate a stack location (vs.a register.)
duke@0 320 //
duke@0 321 // C ABI size +
duke@0 322 // framesize + framesize +
duke@0 323 // stack0 stack0 stack0 0 <- VMReg->value()
duke@0 324 // | | | <registers> |
duke@0 325 // ..........|..............|..............|.............|
duke@0 326 // 0 1 2 3 | <C ABI area> | 4 5 6 ...... | <- local indices
duke@0 327 // ^ ^ sp()
duke@0 328 // | |
duke@0 329 // arguments non-argument locals
duke@0 330
duke@0 331
duke@0 332 VMReg FrameMap::regname(LIR_Opr opr) const {
duke@0 333 if (opr->is_single_cpu()) {
duke@0 334 assert(!opr->is_virtual(), "should not see virtual registers here");
duke@0 335 return opr->as_register()->as_VMReg();
duke@0 336 } else if (opr->is_single_stack()) {
duke@0 337 return sp_offset2vmreg(sp_offset_for_slot(opr->single_stack_ix()));
duke@0 338 } else if (opr->is_address()) {
duke@0 339 LIR_Address* addr = opr->as_address_ptr();
duke@0 340 assert(addr->base() == stack_pointer(), "sp based addressing only");
duke@0 341 return sp_offset2vmreg(in_ByteSize(addr->index()->as_jint()));
duke@0 342 }
duke@0 343 ShouldNotReachHere();
duke@0 344 return VMRegImpl::Bad();
duke@0 345 }
duke@0 346
duke@0 347
duke@0 348
duke@0 349
duke@0 350 // ------------ extra spill slots ---------------