src/share/vm/c1/c1_FrameMap.cpp

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 739
dc7f315e41f7
permissions
-rw-r--r--

Initial load

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

mercurial