src/share/vm/c1/c1_FrameMap.cpp

changeset 435
a61af66fc99e
child 739
dc7f315e41f7
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/c1/c1_FrameMap.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,350 @@
     1.4 +/*
     1.5 + * Copyright 2000-2006 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +# include "incls/_precompiled.incl"
    1.29 +# include "incls/_c1_FrameMap.cpp.incl"
    1.30 +
    1.31 +
    1.32 +
    1.33 +//-----------------------------------------------------
    1.34 +
    1.35 +// Convert method signature into an array of BasicTypes for the arguments
    1.36 +BasicTypeArray* FrameMap::signature_type_array_for(const ciMethod* method) {
    1.37 +  ciSignature* sig = method->signature();
    1.38 +  BasicTypeList* sta = new BasicTypeList(method->arg_size());
    1.39 +  // add receiver, if any
    1.40 +  if (!method->is_static()) sta->append(T_OBJECT);
    1.41 +  // add remaining arguments
    1.42 +  for (int i = 0; i < sig->count(); i++) {
    1.43 +    ciType* type = sig->type_at(i);
    1.44 +    BasicType t = type->basic_type();
    1.45 +    if (t == T_ARRAY) {
    1.46 +      t = T_OBJECT;
    1.47 +    }
    1.48 +    sta->append(t);
    1.49 +  }
    1.50 +  // done
    1.51 +  return sta;
    1.52 +}
    1.53 +
    1.54 +
    1.55 +CallingConvention* FrameMap::java_calling_convention(const BasicTypeArray* signature, bool outgoing) {
    1.56 +  // compute the size of the arguments first.  The signature array
    1.57 +  // that java_calling_convention takes includes a T_VOID after double
    1.58 +  // work items but our signatures do not.
    1.59 +  int i;
    1.60 +  int sizeargs = 0;
    1.61 +  for (i = 0; i < signature->length(); i++) {
    1.62 +    sizeargs += type2size[signature->at(i)];
    1.63 +  }
    1.64 +
    1.65 +  BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
    1.66 +  VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
    1.67 +  int sig_index = 0;
    1.68 +  for (i = 0; i < sizeargs; i++, sig_index++) {
    1.69 +    sig_bt[i] = signature->at(sig_index);
    1.70 +    if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
    1.71 +      sig_bt[i + 1] = T_VOID;
    1.72 +      i++;
    1.73 +    }
    1.74 +  }
    1.75 +
    1.76 +  intptr_t out_preserve = SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs, outgoing);
    1.77 +  LIR_OprList* args = new LIR_OprList(signature->length());
    1.78 +  for (i = 0; i < sizeargs;) {
    1.79 +    BasicType t = sig_bt[i];
    1.80 +    assert(t != T_VOID, "should be skipping these");
    1.81 +
    1.82 +    LIR_Opr opr = map_to_opr(t, regs + i, outgoing);
    1.83 +    args->append(opr);
    1.84 +    if (opr->is_address()) {
    1.85 +      LIR_Address* addr = opr->as_address_ptr();
    1.86 +      assert(addr->disp() == (int)addr->disp(), "out of range value");
    1.87 +      out_preserve = MAX2(out_preserve, (intptr_t)addr->disp() / 4);
    1.88 +    }
    1.89 +    i += type2size[t];
    1.90 +  }
    1.91 +  assert(args->length() == signature->length(), "size mismatch");
    1.92 +  out_preserve += SharedRuntime::out_preserve_stack_slots();
    1.93 +
    1.94 +  if (outgoing) {
    1.95 +    // update the space reserved for arguments.
    1.96 +    update_reserved_argument_area_size(out_preserve);
    1.97 +  }
    1.98 +  return new CallingConvention(args, out_preserve);
    1.99 +}
   1.100 +
   1.101 +
   1.102 +CallingConvention* FrameMap::c_calling_convention(const BasicTypeArray* signature) {
   1.103 +  // compute the size of the arguments first.  The signature array
   1.104 +  // that java_calling_convention takes includes a T_VOID after double
   1.105 +  // work items but our signatures do not.
   1.106 +  int i;
   1.107 +  int sizeargs = 0;
   1.108 +  for (i = 0; i < signature->length(); i++) {
   1.109 +    sizeargs += type2size[signature->at(i)];
   1.110 +  }
   1.111 +
   1.112 +  BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
   1.113 +  VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
   1.114 +  int sig_index = 0;
   1.115 +  for (i = 0; i < sizeargs; i++, sig_index++) {
   1.116 +    sig_bt[i] = signature->at(sig_index);
   1.117 +    if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
   1.118 +      sig_bt[i + 1] = T_VOID;
   1.119 +      i++;
   1.120 +    }
   1.121 +  }
   1.122 +
   1.123 +  intptr_t out_preserve = SharedRuntime::c_calling_convention(sig_bt, regs, sizeargs);
   1.124 +  LIR_OprList* args = new LIR_OprList(signature->length());
   1.125 +  for (i = 0; i < sizeargs;) {
   1.126 +    BasicType t = sig_bt[i];
   1.127 +    assert(t != T_VOID, "should be skipping these");
   1.128 +
   1.129 +    // C calls are always outgoing
   1.130 +    bool outgoing = true;
   1.131 +    LIR_Opr opr = map_to_opr(t, regs + i, outgoing);
   1.132 +    // they might be of different types if for instance floating point
   1.133 +    // values are passed in cpu registers, but the sizes must match.
   1.134 +    assert(type2size[opr->type()] == type2size[t], "type mismatch");
   1.135 +    args->append(opr);
   1.136 +    if (opr->is_address()) {
   1.137 +      LIR_Address* addr = opr->as_address_ptr();
   1.138 +      out_preserve = MAX2(out_preserve, (intptr_t)addr->disp() / 4);
   1.139 +    }
   1.140 +    i += type2size[t];
   1.141 +  }
   1.142 +  assert(args->length() == signature->length(), "size mismatch");
   1.143 +  out_preserve += SharedRuntime::out_preserve_stack_slots();
   1.144 +  update_reserved_argument_area_size(out_preserve);
   1.145 +  return new CallingConvention(args, out_preserve);
   1.146 +}
   1.147 +
   1.148 +
   1.149 +//--------------------------------------------------------
   1.150 +//               FrameMap
   1.151 +//--------------------------------------------------------
   1.152 +
   1.153 +bool      FrameMap::_init_done = false;
   1.154 +Register  FrameMap::_cpu_rnr2reg [FrameMap::nof_cpu_regs];
   1.155 +int       FrameMap::_cpu_reg2rnr [FrameMap::nof_cpu_regs];
   1.156 +
   1.157 +
   1.158 +FrameMap::FrameMap(ciMethod* method, int monitors, int reserved_argument_area_size) {
   1.159 +  if (!_init_done) init();
   1.160 +
   1.161 +  _framesize = -1;
   1.162 +  _num_spills = -1;
   1.163 +
   1.164 +  assert(monitors >= 0, "not set");
   1.165 +  _num_monitors = monitors;
   1.166 +  assert(reserved_argument_area_size >= 0, "not set");
   1.167 +  _reserved_argument_area_size = MAX2(4, reserved_argument_area_size) * BytesPerWord;
   1.168 +
   1.169 +  _argcount = method->arg_size();
   1.170 +  _argument_locations = new intArray(_argcount, -1);
   1.171 +  _incoming_arguments = java_calling_convention(signature_type_array_for(method), false);
   1.172 +  _oop_map_arg_count = _incoming_arguments->reserved_stack_slots();
   1.173 +
   1.174 +  int java_index = 0;
   1.175 +  for (int i = 0; i < _incoming_arguments->length(); i++) {
   1.176 +    LIR_Opr opr = _incoming_arguments->at(i);
   1.177 +    if (opr->is_address()) {
   1.178 +      LIR_Address* address = opr->as_address_ptr();
   1.179 +      _argument_locations->at_put(java_index, address->disp() - STACK_BIAS);
   1.180 +      _incoming_arguments->args()->at_put(i, LIR_OprFact::stack(java_index, as_BasicType(as_ValueType(address->type()))));
   1.181 +    }
   1.182 +    java_index += type2size[opr->type()];
   1.183 +  }
   1.184 +
   1.185 +}
   1.186 +
   1.187 +
   1.188 +bool FrameMap::finalize_frame(int nof_slots) {
   1.189 +  assert(nof_slots >= 0, "must be positive");
   1.190 +  assert(_num_spills == -1, "can only be set once");
   1.191 +  _num_spills = nof_slots;
   1.192 +  assert(_framesize == -1, "should only be calculated once");
   1.193 +  _framesize =  round_to(in_bytes(sp_offset_for_monitor_base(0)) +
   1.194 +                         _num_monitors * sizeof(BasicObjectLock) +
   1.195 +                         sizeof(intptr_t) +                        // offset of deopt orig pc
   1.196 +                         frame_pad_in_bytes,
   1.197 +                         StackAlignmentInBytes) / 4;
   1.198 +  int java_index = 0;
   1.199 +  for (int i = 0; i < _incoming_arguments->length(); i++) {
   1.200 +    LIR_Opr opr = _incoming_arguments->at(i);
   1.201 +    if (opr->is_stack()) {
   1.202 +      _argument_locations->at_put(java_index, in_bytes(framesize_in_bytes()) +
   1.203 +                                  _argument_locations->at(java_index));
   1.204 +    }
   1.205 +    java_index += type2size[opr->type()];
   1.206 +  }
   1.207 +  // make sure it's expressible on the platform
   1.208 +  return validate_frame();
   1.209 +}
   1.210 +
   1.211 +VMReg FrameMap::sp_offset2vmreg(ByteSize offset) const {
   1.212 +  int offset_in_bytes = in_bytes(offset);
   1.213 +  assert(offset_in_bytes % 4 == 0, "must be multiple of 4 bytes");
   1.214 +  assert(offset_in_bytes / 4 < framesize() + oop_map_arg_count(), "out of range");
   1.215 +  return VMRegImpl::stack2reg(offset_in_bytes / 4);
   1.216 +}
   1.217 +
   1.218 +
   1.219 +bool FrameMap::location_for_sp_offset(ByteSize byte_offset_from_sp,
   1.220 +                                      Location::Type loc_type,
   1.221 +                                      Location* loc) const {
   1.222 +  int offset = in_bytes(byte_offset_from_sp);
   1.223 +  assert(offset >= 0, "incorrect offset");
   1.224 +  if (!Location::legal_offset_in_bytes(offset)) {
   1.225 +    return false;
   1.226 +  }
   1.227 +  Location tmp_loc = Location::new_stk_loc(loc_type, offset);
   1.228 +  *loc = tmp_loc;
   1.229 +  return true;
   1.230 +}
   1.231 +
   1.232 +
   1.233 +bool FrameMap::locations_for_slot  (int index, Location::Type loc_type,
   1.234 +                                     Location* loc, Location* second) const {
   1.235 +  ByteSize offset_from_sp = sp_offset_for_slot(index);
   1.236 +  if (!location_for_sp_offset(offset_from_sp, loc_type, loc)) {
   1.237 +    return false;
   1.238 +  }
   1.239 +  if (second != NULL) {
   1.240 +    // two word item
   1.241 +    offset_from_sp = offset_from_sp + in_ByteSize(4);
   1.242 +    return location_for_sp_offset(offset_from_sp, loc_type, second);
   1.243 +  }
   1.244 +  return true;
   1.245 +}
   1.246 +
   1.247 +//////////////////////
   1.248 +// Public accessors //
   1.249 +//////////////////////
   1.250 +
   1.251 +
   1.252 +ByteSize FrameMap::sp_offset_for_slot(const int index) const {
   1.253 +  if (index < argcount()) {
   1.254 +    int offset = _argument_locations->at(index);
   1.255 +    assert(offset != -1, "not a memory argument");
   1.256 +    assert(offset >= framesize() * 4, "argument inside of frame");
   1.257 +    return in_ByteSize(offset);
   1.258 +  }
   1.259 +  ByteSize offset = sp_offset_for_spill(index - argcount());
   1.260 +  assert(in_bytes(offset) < framesize() * 4, "spill outside of frame");
   1.261 +  return offset;
   1.262 +}
   1.263 +
   1.264 +
   1.265 +ByteSize FrameMap::sp_offset_for_double_slot(const int index) const {
   1.266 +  ByteSize offset = sp_offset_for_slot(index);
   1.267 +  if (index >= argcount()) {
   1.268 +    assert(in_bytes(offset) + 4 < framesize() * 4, "spill outside of frame");
   1.269 +  }
   1.270 +  return offset;
   1.271 +}
   1.272 +
   1.273 +
   1.274 +ByteSize FrameMap::sp_offset_for_spill(const int index) const {
   1.275 +  assert(index >= 0 && index < _num_spills, "out of range");
   1.276 +  int offset = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) +
   1.277 +    index * spill_slot_size_in_bytes;
   1.278 +  return in_ByteSize(offset);
   1.279 +}
   1.280 +
   1.281 +ByteSize FrameMap::sp_offset_for_monitor_base(const int index) const {
   1.282 +  int end_of_spills = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) +
   1.283 +    _num_spills * spill_slot_size_in_bytes;
   1.284 +  int offset = round_to(end_of_spills, HeapWordSize) + index * sizeof(BasicObjectLock);
   1.285 +  return in_ByteSize(offset);
   1.286 +}
   1.287 +
   1.288 +ByteSize FrameMap::sp_offset_for_monitor_lock(int index) const {
   1.289 +  check_monitor_index(index);
   1.290 +  return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::lock_offset_in_bytes());;
   1.291 +}
   1.292 +
   1.293 +ByteSize FrameMap::sp_offset_for_monitor_object(int index) const {
   1.294 +  check_monitor_index(index);
   1.295 +  return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::obj_offset_in_bytes());
   1.296 +}
   1.297 +
   1.298 +void FrameMap::print_frame_layout() const {
   1.299 +  int svar;
   1.300 +  tty->print_cr("#####################################");
   1.301 +  tty->print_cr("Frame size in words %d", framesize());
   1.302 +
   1.303 +  if( _num_monitors > 0) {
   1.304 +    tty->print_cr("monitor [0]:%d | [%2d]:%d",
   1.305 +                  in_bytes(sp_offset_for_monitor_base(0)),
   1.306 +                  in_bytes(sp_offset_for_monitor_base(_num_monitors)));
   1.307 +  }
   1.308 +  if( _num_spills > 0) {
   1.309 +    svar = _num_spills - 1;
   1.310 +    if(svar == 0)
   1.311 +      tty->print_cr("spill   [0]:%d", in_bytes(sp_offset_for_spill(0)));
   1.312 +    else
   1.313 +      tty->print_cr("spill   [0]:%d | [%2d]:%d", in_bytes(sp_offset_for_spill(0)),
   1.314 +                    svar,
   1.315 +                    in_bytes(sp_offset_for_spill(svar)));
   1.316 +  }
   1.317 +}
   1.318 +
   1.319 +
   1.320 +// For OopMaps, map a local variable or spill index to an VMReg.
   1.321 +// This is the offset from sp() in the frame of the slot for the index,
   1.322 +// skewed by SharedInfo::stack0 to indicate a stack location (vs.a register.)
   1.323 +//
   1.324 +//         C ABI size +
   1.325 +//         framesize +     framesize +
   1.326 +//         stack0          stack0         stack0          0 <- VMReg->value()
   1.327 +//            |              |              | <registers> |
   1.328 +//  ..........|..............|..............|.............|
   1.329 +//    0 1 2 3 | <C ABI area> | 4 5 6 ...... |               <- local indices
   1.330 +//    ^                        ^          sp()
   1.331 +//    |                        |
   1.332 +//  arguments            non-argument locals
   1.333 +
   1.334 +
   1.335 +VMReg FrameMap::regname(LIR_Opr opr) const {
   1.336 +  if (opr->is_single_cpu()) {
   1.337 +    assert(!opr->is_virtual(), "should not see virtual registers here");
   1.338 +    return opr->as_register()->as_VMReg();
   1.339 +  } else if (opr->is_single_stack()) {
   1.340 +    return sp_offset2vmreg(sp_offset_for_slot(opr->single_stack_ix()));
   1.341 +  } else if (opr->is_address()) {
   1.342 +    LIR_Address* addr = opr->as_address_ptr();
   1.343 +    assert(addr->base() == stack_pointer(), "sp based addressing only");
   1.344 +    return sp_offset2vmreg(in_ByteSize(addr->index()->as_jint()));
   1.345 +  }
   1.346 +  ShouldNotReachHere();
   1.347 +  return VMRegImpl::Bad();
   1.348 +}
   1.349 +
   1.350 +
   1.351 +
   1.352 +
   1.353 +// ------------ extra spill slots ---------------

mercurial