src/share/vm/c1/c1_FrameMap.cpp

Wed, 31 Aug 2011 16:46:11 -0700

author
never
date
Wed, 31 Aug 2011 16:46:11 -0700
changeset 3099
c124e2e7463e
parent 2708
1d1603768966
child 3969
1d7922586cf6
permissions
-rw-r--r--

7083786: dead various dead chunks of code
Reviewed-by: iveresov, kvn

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

mercurial