src/share/vm/c1/c1_FrameMap.cpp

changeset 0
f90c822e73f8
child 1
2d8a650513c2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/c1/c1_FrameMap.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,345 @@
     1.4 +/*
     1.5 + * Copyright (c) 2000, 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "c1/c1_FrameMap.hpp"
    1.30 +#include "c1/c1_LIR.hpp"
    1.31 +#include "runtime/sharedRuntime.hpp"
    1.32 +#ifdef TARGET_ARCH_x86
    1.33 +# include "vmreg_x86.inline.hpp"
    1.34 +#endif
    1.35 +#ifdef TARGET_ARCH_sparc
    1.36 +# include "vmreg_sparc.inline.hpp"
    1.37 +#endif
    1.38 +#ifdef TARGET_ARCH_zero
    1.39 +# include "vmreg_zero.inline.hpp"
    1.40 +#endif
    1.41 +#ifdef TARGET_ARCH_arm
    1.42 +# include "vmreg_arm.inline.hpp"
    1.43 +#endif
    1.44 +#ifdef TARGET_ARCH_ppc
    1.45 +# include "vmreg_ppc.inline.hpp"
    1.46 +#endif
    1.47 +
    1.48 +
    1.49 +
    1.50 +//-----------------------------------------------------
    1.51 +
    1.52 +// Convert method signature into an array of BasicTypes for the arguments
    1.53 +BasicTypeArray* FrameMap::signature_type_array_for(const ciMethod* method) {
    1.54 +  ciSignature* sig = method->signature();
    1.55 +  BasicTypeList* sta = new BasicTypeList(method->arg_size());
    1.56 +  // add receiver, if any
    1.57 +  if (!method->is_static()) sta->append(T_OBJECT);
    1.58 +  // add remaining arguments
    1.59 +  for (int i = 0; i < sig->count(); i++) {
    1.60 +    ciType* type = sig->type_at(i);
    1.61 +    BasicType t = type->basic_type();
    1.62 +    if (t == T_ARRAY) {
    1.63 +      t = T_OBJECT;
    1.64 +    }
    1.65 +    sta->append(t);
    1.66 +  }
    1.67 +  // done
    1.68 +  return sta;
    1.69 +}
    1.70 +
    1.71 +
    1.72 +CallingConvention* FrameMap::java_calling_convention(const BasicTypeArray* signature, bool outgoing) {
    1.73 +  // compute the size of the arguments first.  The signature array
    1.74 +  // that java_calling_convention takes includes a T_VOID after double
    1.75 +  // work items but our signatures do not.
    1.76 +  int i;
    1.77 +  int sizeargs = 0;
    1.78 +  for (i = 0; i < signature->length(); i++) {
    1.79 +    sizeargs += type2size[signature->at(i)];
    1.80 +  }
    1.81 +
    1.82 +  BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
    1.83 +  VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
    1.84 +  int sig_index = 0;
    1.85 +  for (i = 0; i < sizeargs; i++, sig_index++) {
    1.86 +    sig_bt[i] = signature->at(sig_index);
    1.87 +    if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
    1.88 +      sig_bt[i + 1] = T_VOID;
    1.89 +      i++;
    1.90 +    }
    1.91 +  }
    1.92 +
    1.93 +  intptr_t out_preserve = SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs, outgoing);
    1.94 +  LIR_OprList* args = new LIR_OprList(signature->length());
    1.95 +  for (i = 0; i < sizeargs;) {
    1.96 +    BasicType t = sig_bt[i];
    1.97 +    assert(t != T_VOID, "should be skipping these");
    1.98 +    LIR_Opr opr = map_to_opr(t, regs + i, outgoing);
    1.99 +    args->append(opr);
   1.100 +    if (opr->is_address()) {
   1.101 +      LIR_Address* addr = opr->as_address_ptr();
   1.102 +      assert(addr->disp() == (int)addr->disp(), "out of range value");
   1.103 +      out_preserve = MAX2(out_preserve, (intptr_t)(addr->disp() - STACK_BIAS) / 4);
   1.104 +    }
   1.105 +    i += type2size[t];
   1.106 +  }
   1.107 +  assert(args->length() == signature->length(), "size mismatch");
   1.108 +  out_preserve += SharedRuntime::out_preserve_stack_slots();
   1.109 +
   1.110 +  if (outgoing) {
   1.111 +    // update the space reserved for arguments.
   1.112 +    update_reserved_argument_area_size(out_preserve * BytesPerWord);
   1.113 +  }
   1.114 +  return new CallingConvention(args, out_preserve);
   1.115 +}
   1.116 +
   1.117 +
   1.118 +CallingConvention* FrameMap::c_calling_convention(const BasicTypeArray* signature) {
   1.119 +  // compute the size of the arguments first.  The signature array
   1.120 +  // that java_calling_convention takes includes a T_VOID after double
   1.121 +  // work items but our signatures do not.
   1.122 +  int i;
   1.123 +  int sizeargs = 0;
   1.124 +  for (i = 0; i < signature->length(); i++) {
   1.125 +    sizeargs += type2size[signature->at(i)];
   1.126 +  }
   1.127 +
   1.128 +  BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
   1.129 +  VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
   1.130 +  int sig_index = 0;
   1.131 +  for (i = 0; i < sizeargs; i++, sig_index++) {
   1.132 +    sig_bt[i] = signature->at(sig_index);
   1.133 +    if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
   1.134 +      sig_bt[i + 1] = T_VOID;
   1.135 +      i++;
   1.136 +    }
   1.137 +  }
   1.138 +
   1.139 +  intptr_t out_preserve = SharedRuntime::c_calling_convention(sig_bt, regs, NULL, sizeargs);
   1.140 +  LIR_OprList* args = new LIR_OprList(signature->length());
   1.141 +  for (i = 0; i < sizeargs;) {
   1.142 +    BasicType t = sig_bt[i];
   1.143 +    assert(t != T_VOID, "should be skipping these");
   1.144 +
   1.145 +    // C calls are always outgoing
   1.146 +    bool outgoing = true;
   1.147 +    LIR_Opr opr = map_to_opr(t, regs + i, outgoing);
   1.148 +    // they might be of different types if for instance floating point
   1.149 +    // values are passed in cpu registers, but the sizes must match.
   1.150 +    assert(type2size[opr->type()] == type2size[t], "type mismatch");
   1.151 +    args->append(opr);
   1.152 +    if (opr->is_address()) {
   1.153 +      LIR_Address* addr = opr->as_address_ptr();
   1.154 +      out_preserve = MAX2(out_preserve, (intptr_t)(addr->disp() - STACK_BIAS) / 4);
   1.155 +    }
   1.156 +    i += type2size[t];
   1.157 +  }
   1.158 +  assert(args->length() == signature->length(), "size mismatch");
   1.159 +  out_preserve += SharedRuntime::out_preserve_stack_slots();
   1.160 +  update_reserved_argument_area_size(out_preserve * BytesPerWord);
   1.161 +  return new CallingConvention(args, out_preserve);
   1.162 +}
   1.163 +
   1.164 +
   1.165 +//--------------------------------------------------------
   1.166 +//               FrameMap
   1.167 +//--------------------------------------------------------
   1.168 +
   1.169 +bool      FrameMap::_init_done = false;
   1.170 +Register  FrameMap::_cpu_rnr2reg [FrameMap::nof_cpu_regs];
   1.171 +int       FrameMap::_cpu_reg2rnr [FrameMap::nof_cpu_regs];
   1.172 +
   1.173 +
   1.174 +FrameMap::FrameMap(ciMethod* method, int monitors, int reserved_argument_area_size) {
   1.175 +  assert(_init_done, "should already be completed");
   1.176 +
   1.177 +  _framesize = -1;
   1.178 +  _num_spills = -1;
   1.179 +
   1.180 +  assert(monitors >= 0, "not set");
   1.181 +  _num_monitors = monitors;
   1.182 +  assert(reserved_argument_area_size >= 0, "not set");
   1.183 +  _reserved_argument_area_size = MAX2(4, reserved_argument_area_size) * BytesPerWord;
   1.184 +
   1.185 +  _argcount = method->arg_size();
   1.186 +  _argument_locations = new intArray(_argcount, -1);
   1.187 +  _incoming_arguments = java_calling_convention(signature_type_array_for(method), false);
   1.188 +  _oop_map_arg_count = _incoming_arguments->reserved_stack_slots();
   1.189 +
   1.190 +  int java_index = 0;
   1.191 +  for (int i = 0; i < _incoming_arguments->length(); i++) {
   1.192 +    LIR_Opr opr = _incoming_arguments->at(i);
   1.193 +    if (opr->is_address()) {
   1.194 +      LIR_Address* address = opr->as_address_ptr();
   1.195 +      _argument_locations->at_put(java_index, address->disp() - STACK_BIAS);
   1.196 +      _incoming_arguments->args()->at_put(i, LIR_OprFact::stack(java_index, as_BasicType(as_ValueType(address->type()))));
   1.197 +    }
   1.198 +    java_index += type2size[opr->type()];
   1.199 +  }
   1.200 +
   1.201 +}
   1.202 +
   1.203 +
   1.204 +bool FrameMap::finalize_frame(int nof_slots) {
   1.205 +  assert(nof_slots >= 0, "must be positive");
   1.206 +  assert(_num_spills == -1, "can only be set once");
   1.207 +  _num_spills = nof_slots;
   1.208 +  assert(_framesize == -1, "should only be calculated once");
   1.209 +  _framesize =  round_to(in_bytes(sp_offset_for_monitor_base(0)) +
   1.210 +                         _num_monitors * sizeof(BasicObjectLock) +
   1.211 +                         sizeof(intptr_t) +                        // offset of deopt orig pc
   1.212 +                         frame_pad_in_bytes,
   1.213 +                         StackAlignmentInBytes) / 4;
   1.214 +  int java_index = 0;
   1.215 +  for (int i = 0; i < _incoming_arguments->length(); i++) {
   1.216 +    LIR_Opr opr = _incoming_arguments->at(i);
   1.217 +    if (opr->is_stack()) {
   1.218 +      _argument_locations->at_put(java_index, in_bytes(framesize_in_bytes()) +
   1.219 +                                  _argument_locations->at(java_index));
   1.220 +    }
   1.221 +    java_index += type2size[opr->type()];
   1.222 +  }
   1.223 +  // make sure it's expressible on the platform
   1.224 +  return validate_frame();
   1.225 +}
   1.226 +
   1.227 +VMReg FrameMap::sp_offset2vmreg(ByteSize offset) const {
   1.228 +  int offset_in_bytes = in_bytes(offset);
   1.229 +  assert(offset_in_bytes % 4 == 0, "must be multiple of 4 bytes");
   1.230 +  assert(offset_in_bytes / 4 < framesize() + oop_map_arg_count(), "out of range");
   1.231 +  return VMRegImpl::stack2reg(offset_in_bytes / 4);
   1.232 +}
   1.233 +
   1.234 +
   1.235 +bool FrameMap::location_for_sp_offset(ByteSize byte_offset_from_sp,
   1.236 +                                      Location::Type loc_type,
   1.237 +                                      Location* loc) const {
   1.238 +  int offset = in_bytes(byte_offset_from_sp);
   1.239 +  assert(offset >= 0, "incorrect offset");
   1.240 +  if (!Location::legal_offset_in_bytes(offset)) {
   1.241 +    return false;
   1.242 +  }
   1.243 +  Location tmp_loc = Location::new_stk_loc(loc_type, offset);
   1.244 +  *loc = tmp_loc;
   1.245 +  return true;
   1.246 +}
   1.247 +
   1.248 +
   1.249 +bool FrameMap::locations_for_slot  (int index, Location::Type loc_type,
   1.250 +                                     Location* loc, Location* second) const {
   1.251 +  ByteSize offset_from_sp = sp_offset_for_slot(index);
   1.252 +  if (!location_for_sp_offset(offset_from_sp, loc_type, loc)) {
   1.253 +    return false;
   1.254 +  }
   1.255 +  if (second != NULL) {
   1.256 +    // two word item
   1.257 +    offset_from_sp = offset_from_sp + in_ByteSize(4);
   1.258 +    return location_for_sp_offset(offset_from_sp, loc_type, second);
   1.259 +  }
   1.260 +  return true;
   1.261 +}
   1.262 +
   1.263 +//////////////////////
   1.264 +// Public accessors //
   1.265 +//////////////////////
   1.266 +
   1.267 +
   1.268 +ByteSize FrameMap::sp_offset_for_slot(const int index) const {
   1.269 +  if (index < argcount()) {
   1.270 +    int offset = _argument_locations->at(index);
   1.271 +    assert(offset != -1, "not a memory argument");
   1.272 +    assert(offset >= framesize() * 4, "argument inside of frame");
   1.273 +    return in_ByteSize(offset);
   1.274 +  }
   1.275 +  ByteSize offset = sp_offset_for_spill(index - argcount());
   1.276 +  assert(in_bytes(offset) < framesize() * 4, "spill outside of frame");
   1.277 +  return offset;
   1.278 +}
   1.279 +
   1.280 +
   1.281 +ByteSize FrameMap::sp_offset_for_double_slot(const int index) const {
   1.282 +  ByteSize offset = sp_offset_for_slot(index);
   1.283 +  if (index >= argcount()) {
   1.284 +    assert(in_bytes(offset) + 4 < framesize() * 4, "spill outside of frame");
   1.285 +  }
   1.286 +  return offset;
   1.287 +}
   1.288 +
   1.289 +
   1.290 +ByteSize FrameMap::sp_offset_for_spill(const int index) const {
   1.291 +  assert(index >= 0 && index < _num_spills, "out of range");
   1.292 +  int offset = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) +
   1.293 +    index * spill_slot_size_in_bytes;
   1.294 +  return in_ByteSize(offset);
   1.295 +}
   1.296 +
   1.297 +ByteSize FrameMap::sp_offset_for_monitor_base(const int index) const {
   1.298 +  int end_of_spills = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) +
   1.299 +    _num_spills * spill_slot_size_in_bytes;
   1.300 +  int offset = (int) round_to(end_of_spills, HeapWordSize) + index * sizeof(BasicObjectLock);
   1.301 +  return in_ByteSize(offset);
   1.302 +}
   1.303 +
   1.304 +ByteSize FrameMap::sp_offset_for_monitor_lock(int index) const {
   1.305 +  check_monitor_index(index);
   1.306 +  return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::lock_offset_in_bytes());;
   1.307 +}
   1.308 +
   1.309 +ByteSize FrameMap::sp_offset_for_monitor_object(int index) const {
   1.310 +  check_monitor_index(index);
   1.311 +  return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::obj_offset_in_bytes());
   1.312 +}
   1.313 +
   1.314 +
   1.315 +// For OopMaps, map a local variable or spill index to an VMReg.
   1.316 +// This is the offset from sp() in the frame of the slot for the index,
   1.317 +// skewed by SharedInfo::stack0 to indicate a stack location (vs.a register.)
   1.318 +//
   1.319 +//         C ABI size +
   1.320 +//         framesize +     framesize +
   1.321 +//         stack0          stack0         stack0          0 <- VMReg->value()
   1.322 +//            |              |              | <registers> |
   1.323 +//  ..........|..............|..............|.............|
   1.324 +//    0 1 2 3 | <C ABI area> | 4 5 6 ...... |               <- local indices
   1.325 +//    ^                        ^          sp()
   1.326 +//    |                        |
   1.327 +//  arguments            non-argument locals
   1.328 +
   1.329 +
   1.330 +VMReg FrameMap::regname(LIR_Opr opr) const {
   1.331 +  if (opr->is_single_cpu()) {
   1.332 +    assert(!opr->is_virtual(), "should not see virtual registers here");
   1.333 +    return opr->as_register()->as_VMReg();
   1.334 +  } else if (opr->is_single_stack()) {
   1.335 +    return sp_offset2vmreg(sp_offset_for_slot(opr->single_stack_ix()));
   1.336 +  } else if (opr->is_address()) {
   1.337 +    LIR_Address* addr = opr->as_address_ptr();
   1.338 +    assert(addr->base() == stack_pointer(), "sp based addressing only");
   1.339 +    return sp_offset2vmreg(in_ByteSize(addr->index()->as_jint()));
   1.340 +  }
   1.341 +  ShouldNotReachHere();
   1.342 +  return VMRegImpl::Bad();
   1.343 +}
   1.344 +
   1.345 +
   1.346 +
   1.347 +
   1.348 +// ------------ extra spill slots ---------------

mercurial