src/share/vm/ci/ciMethodData.cpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/ci/ciMethodData.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,715 @@
     1.4 +/*
     1.5 + * Copyright (c) 2001, 2014, 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 "ci/ciMetadata.hpp"
    1.30 +#include "ci/ciMethodData.hpp"
    1.31 +#include "ci/ciReplay.hpp"
    1.32 +#include "ci/ciUtilities.hpp"
    1.33 +#include "memory/allocation.inline.hpp"
    1.34 +#include "memory/resourceArea.hpp"
    1.35 +#include "runtime/deoptimization.hpp"
    1.36 +#include "utilities/copy.hpp"
    1.37 +
    1.38 +// ciMethodData
    1.39 +
    1.40 +// ------------------------------------------------------------------
    1.41 +// ciMethodData::ciMethodData
    1.42 +//
    1.43 +ciMethodData::ciMethodData(MethodData* md) : ciMetadata(md) {
    1.44 +  assert(md != NULL, "no null method data");
    1.45 +  Copy::zero_to_words((HeapWord*) &_orig, sizeof(_orig) / sizeof(HeapWord));
    1.46 +  _data = NULL;
    1.47 +  _data_size = 0;
    1.48 +  _extra_data_size = 0;
    1.49 +  _current_mileage = 0;
    1.50 +  _invocation_counter = 0;
    1.51 +  _backedge_counter = 0;
    1.52 +  _state = empty_state;
    1.53 +  _saw_free_extra_data = false;
    1.54 +  // Set an initial hint. Don't use set_hint_di() because
    1.55 +  // first_di() may be out of bounds if data_size is 0.
    1.56 +  _hint_di = first_di();
    1.57 +  // Initialize the escape information (to "don't know.");
    1.58 +  _eflags = _arg_local = _arg_stack = _arg_returned = 0;
    1.59 +  _parameters = NULL;
    1.60 +}
    1.61 +
    1.62 +// ------------------------------------------------------------------
    1.63 +// ciMethodData::ciMethodData
    1.64 +//
    1.65 +// No MethodData*.
    1.66 +ciMethodData::ciMethodData() : ciMetadata(NULL) {
    1.67 +  Copy::zero_to_words((HeapWord*) &_orig, sizeof(_orig) / sizeof(HeapWord));
    1.68 +  _data = NULL;
    1.69 +  _data_size = 0;
    1.70 +  _extra_data_size = 0;
    1.71 +  _current_mileage = 0;
    1.72 +  _invocation_counter = 0;
    1.73 +  _backedge_counter = 0;
    1.74 +  _state = empty_state;
    1.75 +  _saw_free_extra_data = false;
    1.76 +  // Set an initial hint. Don't use set_hint_di() because
    1.77 +  // first_di() may be out of bounds if data_size is 0.
    1.78 +  _hint_di = first_di();
    1.79 +  // Initialize the escape information (to "don't know.");
    1.80 +  _eflags = _arg_local = _arg_stack = _arg_returned = 0;
    1.81 +  _parameters = NULL;
    1.82 +}
    1.83 +
    1.84 +void ciMethodData::load_extra_data() {
    1.85 +  MethodData* mdo = get_MethodData();
    1.86 +
    1.87 +  // speculative trap entries also hold a pointer to a Method so need to be translated
    1.88 +  DataLayout* dp_src  = mdo->extra_data_base();
    1.89 +  DataLayout* end_src = mdo->extra_data_limit();
    1.90 +  DataLayout* dp_dst  = extra_data_base();
    1.91 +  for (;; dp_src = MethodData::next_extra(dp_src), dp_dst = MethodData::next_extra(dp_dst)) {
    1.92 +    assert(dp_src < end_src, "moved past end of extra data");
    1.93 +    // New traps in the MDO can be added as we translate the copy so
    1.94 +    // look at the entries in the copy.
    1.95 +    switch(dp_dst->tag()) {
    1.96 +    case DataLayout::speculative_trap_data_tag: {
    1.97 +      ciSpeculativeTrapData* data_dst = new ciSpeculativeTrapData(dp_dst);
    1.98 +      SpeculativeTrapData* data_src = new SpeculativeTrapData(dp_src);
    1.99 +      data_dst->translate_from(data_src);
   1.100 +      break;
   1.101 +    }
   1.102 +    case DataLayout::bit_data_tag:
   1.103 +      break;
   1.104 +    case DataLayout::no_tag:
   1.105 +    case DataLayout::arg_info_data_tag:
   1.106 +      // An empty slot or ArgInfoData entry marks the end of the trap data
   1.107 +      return;
   1.108 +    default:
   1.109 +      fatal(err_msg("bad tag = %d", dp_dst->tag()));
   1.110 +    }
   1.111 +  }
   1.112 +}
   1.113 +
   1.114 +void ciMethodData::load_data() {
   1.115 +  MethodData* mdo = get_MethodData();
   1.116 +  if (mdo == NULL) {
   1.117 +    return;
   1.118 +  }
   1.119 +
   1.120 +  // To do: don't copy the data if it is not "ripe" -- require a minimum #
   1.121 +  // of invocations.
   1.122 +
   1.123 +  // Snapshot the data -- actually, take an approximate snapshot of
   1.124 +  // the data.  Any concurrently executing threads may be changing the
   1.125 +  // data as we copy it.
   1.126 +  Copy::disjoint_words((HeapWord*) mdo,
   1.127 +                       (HeapWord*) &_orig,
   1.128 +                       sizeof(_orig) / HeapWordSize);
   1.129 +  Arena* arena = CURRENT_ENV->arena();
   1.130 +  _data_size = mdo->data_size();
   1.131 +  _extra_data_size = mdo->extra_data_size();
   1.132 +  int total_size = _data_size + _extra_data_size;
   1.133 +  _data = (intptr_t *) arena->Amalloc(total_size);
   1.134 +  Copy::disjoint_words((HeapWord*) mdo->data_base(), (HeapWord*) _data, total_size / HeapWordSize);
   1.135 +
   1.136 +  // Traverse the profile data, translating any oops into their
   1.137 +  // ci equivalents.
   1.138 +  ResourceMark rm;
   1.139 +  ciProfileData* ci_data = first_data();
   1.140 +  ProfileData* data = mdo->first_data();
   1.141 +  while (is_valid(ci_data)) {
   1.142 +    ci_data->translate_from(data);
   1.143 +    ci_data = next_data(ci_data);
   1.144 +    data = mdo->next_data(data);
   1.145 +  }
   1.146 +  if (mdo->parameters_type_data() != NULL) {
   1.147 +    _parameters = data_layout_at(mdo->parameters_type_data_di());
   1.148 +    ciParametersTypeData* parameters = new ciParametersTypeData(_parameters);
   1.149 +    parameters->translate_from(mdo->parameters_type_data());
   1.150 +  }
   1.151 +
   1.152 +  load_extra_data();
   1.153 +
   1.154 +  // Note:  Extra data are all BitData, and do not need translation.
   1.155 +  _current_mileage = MethodData::mileage_of(mdo->method());
   1.156 +  _invocation_counter = mdo->invocation_count();
   1.157 +  _backedge_counter = mdo->backedge_count();
   1.158 +  _state = mdo->is_mature()? mature_state: immature_state;
   1.159 +
   1.160 +  _eflags = mdo->eflags();
   1.161 +  _arg_local = mdo->arg_local();
   1.162 +  _arg_stack = mdo->arg_stack();
   1.163 +  _arg_returned  = mdo->arg_returned();
   1.164 +#ifndef PRODUCT
   1.165 +  if (ReplayCompiles) {
   1.166 +    ciReplay::initialize(this);
   1.167 +  }
   1.168 +#endif
   1.169 +}
   1.170 +
   1.171 +void ciReceiverTypeData::translate_receiver_data_from(const ProfileData* data) {
   1.172 +  for (uint row = 0; row < row_limit(); row++) {
   1.173 +    Klass* k = data->as_ReceiverTypeData()->receiver(row);
   1.174 +    if (k != NULL) {
   1.175 +      ciKlass* klass = CURRENT_ENV->get_klass(k);
   1.176 +      set_receiver(row, klass);
   1.177 +    }
   1.178 +  }
   1.179 +}
   1.180 +
   1.181 +
   1.182 +void ciTypeStackSlotEntries::translate_type_data_from(const TypeStackSlotEntries* entries) {
   1.183 +  for (int i = 0; i < _number_of_entries; i++) {
   1.184 +    intptr_t k = entries->type(i);
   1.185 +    TypeStackSlotEntries::set_type(i, translate_klass(k));
   1.186 +  }
   1.187 +}
   1.188 +
   1.189 +void ciReturnTypeEntry::translate_type_data_from(const ReturnTypeEntry* ret) {
   1.190 +  intptr_t k = ret->type();
   1.191 +  set_type(translate_klass(k));
   1.192 +}
   1.193 +
   1.194 +void ciSpeculativeTrapData::translate_from(const ProfileData* data) {
   1.195 +  Method* m = data->as_SpeculativeTrapData()->method();
   1.196 +  ciMethod* ci_m = CURRENT_ENV->get_method(m);
   1.197 +  set_method(ci_m);
   1.198 +}
   1.199 +
   1.200 +// Get the data at an arbitrary (sort of) data index.
   1.201 +ciProfileData* ciMethodData::data_at(int data_index) {
   1.202 +  if (out_of_bounds(data_index)) {
   1.203 +    return NULL;
   1.204 +  }
   1.205 +  DataLayout* data_layout = data_layout_at(data_index);
   1.206 +
   1.207 +  switch (data_layout->tag()) {
   1.208 +  case DataLayout::no_tag:
   1.209 +  default:
   1.210 +    ShouldNotReachHere();
   1.211 +    return NULL;
   1.212 +  case DataLayout::bit_data_tag:
   1.213 +    return new ciBitData(data_layout);
   1.214 +  case DataLayout::counter_data_tag:
   1.215 +    return new ciCounterData(data_layout);
   1.216 +  case DataLayout::jump_data_tag:
   1.217 +    return new ciJumpData(data_layout);
   1.218 +  case DataLayout::receiver_type_data_tag:
   1.219 +    return new ciReceiverTypeData(data_layout);
   1.220 +  case DataLayout::virtual_call_data_tag:
   1.221 +    return new ciVirtualCallData(data_layout);
   1.222 +  case DataLayout::ret_data_tag:
   1.223 +    return new ciRetData(data_layout);
   1.224 +  case DataLayout::branch_data_tag:
   1.225 +    return new ciBranchData(data_layout);
   1.226 +  case DataLayout::multi_branch_data_tag:
   1.227 +    return new ciMultiBranchData(data_layout);
   1.228 +  case DataLayout::arg_info_data_tag:
   1.229 +    return new ciArgInfoData(data_layout);
   1.230 +  case DataLayout::call_type_data_tag:
   1.231 +    return new ciCallTypeData(data_layout);
   1.232 +  case DataLayout::virtual_call_type_data_tag:
   1.233 +    return new ciVirtualCallTypeData(data_layout);
   1.234 +  case DataLayout::parameters_type_data_tag:
   1.235 +    return new ciParametersTypeData(data_layout);
   1.236 +  };
   1.237 +}
   1.238 +
   1.239 +// Iteration over data.
   1.240 +ciProfileData* ciMethodData::next_data(ciProfileData* current) {
   1.241 +  int current_index = dp_to_di(current->dp());
   1.242 +  int next_index = current_index + current->size_in_bytes();
   1.243 +  ciProfileData* next = data_at(next_index);
   1.244 +  return next;
   1.245 +}
   1.246 +
   1.247 +ciProfileData* ciMethodData::bci_to_extra_data(int bci, ciMethod* m, bool& two_free_slots) {
   1.248 +  // bci_to_extra_data(bci) ...
   1.249 +  DataLayout* dp  = data_layout_at(data_size());
   1.250 +  DataLayout* end = data_layout_at(data_size() + extra_data_size());
   1.251 +  two_free_slots = false;
   1.252 +  for (;dp < end; dp = MethodData::next_extra(dp)) {
   1.253 +    switch(dp->tag()) {
   1.254 +    case DataLayout::no_tag:
   1.255 +      _saw_free_extra_data = true;  // observed an empty slot (common case)
   1.256 +      two_free_slots = (MethodData::next_extra(dp)->tag() == DataLayout::no_tag);
   1.257 +      return NULL;
   1.258 +    case DataLayout::arg_info_data_tag:
   1.259 +      return NULL; // ArgInfoData is at the end of extra data section.
   1.260 +    case DataLayout::bit_data_tag:
   1.261 +      if (m == NULL && dp->bci() == bci) {
   1.262 +        return new ciBitData(dp);
   1.263 +      }
   1.264 +      break;
   1.265 +    case DataLayout::speculative_trap_data_tag: {
   1.266 +      ciSpeculativeTrapData* data = new ciSpeculativeTrapData(dp);
   1.267 +      // data->method() might be null if the MDO is snapshotted
   1.268 +      // concurrently with a trap
   1.269 +      if (m != NULL && data->method() == m && dp->bci() == bci) {
   1.270 +        return data;
   1.271 +      }
   1.272 +      break;
   1.273 +    }
   1.274 +    default:
   1.275 +      fatal(err_msg("bad tag = %d", dp->tag()));
   1.276 +    }
   1.277 +  }
   1.278 +  return NULL;
   1.279 +}
   1.280 +
   1.281 +// Translate a bci to its corresponding data, or NULL.
   1.282 +ciProfileData* ciMethodData::bci_to_data(int bci, ciMethod* m) {
   1.283 +  // If m is not NULL we look for a SpeculativeTrapData entry
   1.284 +  if (m == NULL) {
   1.285 +    ciProfileData* data = data_before(bci);
   1.286 +    for ( ; is_valid(data); data = next_data(data)) {
   1.287 +      if (data->bci() == bci) {
   1.288 +        set_hint_di(dp_to_di(data->dp()));
   1.289 +        return data;
   1.290 +      } else if (data->bci() > bci) {
   1.291 +        break;
   1.292 +      }
   1.293 +    }
   1.294 +  }
   1.295 +  bool two_free_slots = false;
   1.296 +  ciProfileData* result = bci_to_extra_data(bci, m, two_free_slots);
   1.297 +  if (result != NULL) {
   1.298 +    return result;
   1.299 +  }
   1.300 +  if (m != NULL && !two_free_slots) {
   1.301 +    // We were looking for a SpeculativeTrapData entry we didn't
   1.302 +    // find. Room is not available for more SpeculativeTrapData
   1.303 +    // entries, look in the non SpeculativeTrapData entries.
   1.304 +    return bci_to_data(bci, NULL);
   1.305 +  }
   1.306 +  return NULL;
   1.307 +}
   1.308 +
   1.309 +// Conservatively decode the trap_state of a ciProfileData.
   1.310 +int ciMethodData::has_trap_at(ciProfileData* data, int reason) {
   1.311 +  typedef Deoptimization::DeoptReason DR_t;
   1.312 +  int per_bc_reason
   1.313 +    = Deoptimization::reason_recorded_per_bytecode_if_any((DR_t) reason);
   1.314 +  if (trap_count(reason) == 0) {
   1.315 +    // Impossible for this trap to have occurred, regardless of trap_state.
   1.316 +    // Note:  This happens if the MDO is empty.
   1.317 +    return 0;
   1.318 +  } else if (per_bc_reason == Deoptimization::Reason_none) {
   1.319 +    // We cannot conclude anything; a trap happened somewhere, maybe here.
   1.320 +    return -1;
   1.321 +  } else if (data == NULL) {
   1.322 +    // No profile here, not even an extra_data record allocated on the fly.
   1.323 +    // If there are empty extra_data records, and there had been a trap,
   1.324 +    // there would have been a non-null data pointer.  If there are no
   1.325 +    // free extra_data records, we must return a conservative -1.
   1.326 +    if (_saw_free_extra_data)
   1.327 +      return 0;                 // Q.E.D.
   1.328 +    else
   1.329 +      return -1;                // bail with a conservative answer
   1.330 +  } else {
   1.331 +    return Deoptimization::trap_state_has_reason(data->trap_state(), per_bc_reason);
   1.332 +  }
   1.333 +}
   1.334 +
   1.335 +int ciMethodData::trap_recompiled_at(ciProfileData* data) {
   1.336 +  if (data == NULL) {
   1.337 +    return (_saw_free_extra_data? 0: -1);  // (see previous method)
   1.338 +  } else {
   1.339 +    return Deoptimization::trap_state_is_recompiled(data->trap_state())? 1: 0;
   1.340 +  }
   1.341 +}
   1.342 +
   1.343 +void ciMethodData::clear_escape_info() {
   1.344 +  VM_ENTRY_MARK;
   1.345 +  MethodData* mdo = get_MethodData();
   1.346 +  if (mdo != NULL) {
   1.347 +    mdo->clear_escape_info();
   1.348 +    ArgInfoData *aid = arg_info();
   1.349 +    int arg_count = (aid == NULL) ? 0 : aid->number_of_args();
   1.350 +    for (int i = 0; i < arg_count; i++) {
   1.351 +      set_arg_modified(i, 0);
   1.352 +    }
   1.353 +  }
   1.354 +  _eflags = _arg_local = _arg_stack = _arg_returned = 0;
   1.355 +}
   1.356 +
   1.357 +// copy our escape info to the MethodData* if it exists
   1.358 +void ciMethodData::update_escape_info() {
   1.359 +  VM_ENTRY_MARK;
   1.360 +  MethodData* mdo = get_MethodData();
   1.361 +  if ( mdo != NULL) {
   1.362 +    mdo->set_eflags(_eflags);
   1.363 +    mdo->set_arg_local(_arg_local);
   1.364 +    mdo->set_arg_stack(_arg_stack);
   1.365 +    mdo->set_arg_returned(_arg_returned);
   1.366 +    int arg_count = mdo->method()->size_of_parameters();
   1.367 +    for (int i = 0; i < arg_count; i++) {
   1.368 +      mdo->set_arg_modified(i, arg_modified(i));
   1.369 +    }
   1.370 +  }
   1.371 +}
   1.372 +
   1.373 +void ciMethodData::set_compilation_stats(short loops, short blocks) {
   1.374 +  VM_ENTRY_MARK;
   1.375 +  MethodData* mdo = get_MethodData();
   1.376 +  if (mdo != NULL) {
   1.377 +    mdo->set_num_loops(loops);
   1.378 +    mdo->set_num_blocks(blocks);
   1.379 +  }
   1.380 +}
   1.381 +
   1.382 +void ciMethodData::set_would_profile(bool p) {
   1.383 +  VM_ENTRY_MARK;
   1.384 +  MethodData* mdo = get_MethodData();
   1.385 +  if (mdo != NULL) {
   1.386 +    mdo->set_would_profile(p);
   1.387 +  }
   1.388 +}
   1.389 +
   1.390 +void ciMethodData::set_argument_type(int bci, int i, ciKlass* k) {
   1.391 +  VM_ENTRY_MARK;
   1.392 +  MethodData* mdo = get_MethodData();
   1.393 +  if (mdo != NULL) {
   1.394 +    ProfileData* data = mdo->bci_to_data(bci);
   1.395 +    if (data->is_CallTypeData()) {
   1.396 +      data->as_CallTypeData()->set_argument_type(i, k->get_Klass());
   1.397 +    } else {
   1.398 +      assert(data->is_VirtualCallTypeData(), "no arguments!");
   1.399 +      data->as_VirtualCallTypeData()->set_argument_type(i, k->get_Klass());
   1.400 +    }
   1.401 +  }
   1.402 +}
   1.403 +
   1.404 +void ciMethodData::set_parameter_type(int i, ciKlass* k) {
   1.405 +  VM_ENTRY_MARK;
   1.406 +  MethodData* mdo = get_MethodData();
   1.407 +  if (mdo != NULL) {
   1.408 +    mdo->parameters_type_data()->set_type(i, k->get_Klass());
   1.409 +  }
   1.410 +}
   1.411 +
   1.412 +void ciMethodData::set_return_type(int bci, ciKlass* k) {
   1.413 +  VM_ENTRY_MARK;
   1.414 +  MethodData* mdo = get_MethodData();
   1.415 +  if (mdo != NULL) {
   1.416 +    ProfileData* data = mdo->bci_to_data(bci);
   1.417 +    if (data->is_CallTypeData()) {
   1.418 +      data->as_CallTypeData()->set_return_type(k->get_Klass());
   1.419 +    } else {
   1.420 +      assert(data->is_VirtualCallTypeData(), "no arguments!");
   1.421 +      data->as_VirtualCallTypeData()->set_return_type(k->get_Klass());
   1.422 +    }
   1.423 +  }
   1.424 +}
   1.425 +
   1.426 +bool ciMethodData::has_escape_info() {
   1.427 +  return eflag_set(MethodData::estimated);
   1.428 +}
   1.429 +
   1.430 +void ciMethodData::set_eflag(MethodData::EscapeFlag f) {
   1.431 +  set_bits(_eflags, f);
   1.432 +}
   1.433 +
   1.434 +void ciMethodData::clear_eflag(MethodData::EscapeFlag f) {
   1.435 +  clear_bits(_eflags, f);
   1.436 +}
   1.437 +
   1.438 +bool ciMethodData::eflag_set(MethodData::EscapeFlag f) const {
   1.439 +  return mask_bits(_eflags, f) != 0;
   1.440 +}
   1.441 +
   1.442 +void ciMethodData::set_arg_local(int i) {
   1.443 +  set_nth_bit(_arg_local, i);
   1.444 +}
   1.445 +
   1.446 +void ciMethodData::set_arg_stack(int i) {
   1.447 +  set_nth_bit(_arg_stack, i);
   1.448 +}
   1.449 +
   1.450 +void ciMethodData::set_arg_returned(int i) {
   1.451 +  set_nth_bit(_arg_returned, i);
   1.452 +}
   1.453 +
   1.454 +void ciMethodData::set_arg_modified(int arg, uint val) {
   1.455 +  ArgInfoData *aid = arg_info();
   1.456 +  if (aid == NULL)
   1.457 +    return;
   1.458 +  assert(arg >= 0 && arg < aid->number_of_args(), "valid argument number");
   1.459 +  aid->set_arg_modified(arg, val);
   1.460 +}
   1.461 +
   1.462 +bool ciMethodData::is_arg_local(int i) const {
   1.463 +  return is_set_nth_bit(_arg_local, i);
   1.464 +}
   1.465 +
   1.466 +bool ciMethodData::is_arg_stack(int i) const {
   1.467 +  return is_set_nth_bit(_arg_stack, i);
   1.468 +}
   1.469 +
   1.470 +bool ciMethodData::is_arg_returned(int i) const {
   1.471 +  return is_set_nth_bit(_arg_returned, i);
   1.472 +}
   1.473 +
   1.474 +uint ciMethodData::arg_modified(int arg) const {
   1.475 +  ArgInfoData *aid = arg_info();
   1.476 +  if (aid == NULL)
   1.477 +    return 0;
   1.478 +  assert(arg >= 0 && arg < aid->number_of_args(), "valid argument number");
   1.479 +  return aid->arg_modified(arg);
   1.480 +}
   1.481 +
   1.482 +ByteSize ciMethodData::offset_of_slot(ciProfileData* data, ByteSize slot_offset_in_data) {
   1.483 +  // Get offset within MethodData* of the data array
   1.484 +  ByteSize data_offset = MethodData::data_offset();
   1.485 +
   1.486 +  // Get cell offset of the ProfileData within data array
   1.487 +  int cell_offset = dp_to_di(data->dp());
   1.488 +
   1.489 +  // Add in counter_offset, the # of bytes into the ProfileData of counter or flag
   1.490 +  int offset = in_bytes(data_offset) + cell_offset + in_bytes(slot_offset_in_data);
   1.491 +
   1.492 +  return in_ByteSize(offset);
   1.493 +}
   1.494 +
   1.495 +ciArgInfoData *ciMethodData::arg_info() const {
   1.496 +  // Should be last, have to skip all traps.
   1.497 +  DataLayout* dp  = data_layout_at(data_size());
   1.498 +  DataLayout* end = data_layout_at(data_size() + extra_data_size());
   1.499 +  for (; dp < end; dp = MethodData::next_extra(dp)) {
   1.500 +    if (dp->tag() == DataLayout::arg_info_data_tag)
   1.501 +      return new ciArgInfoData(dp);
   1.502 +  }
   1.503 +  return NULL;
   1.504 +}
   1.505 +
   1.506 +
   1.507 +// Implementation of the print method.
   1.508 +void ciMethodData::print_impl(outputStream* st) {
   1.509 +  ciMetadata::print_impl(st);
   1.510 +}
   1.511 +
   1.512 +void ciMethodData::dump_replay_data(outputStream* out) {
   1.513 +  ResourceMark rm;
   1.514 +  MethodData* mdo = get_MethodData();
   1.515 +  Method* method = mdo->method();
   1.516 +  Klass* holder = method->method_holder();
   1.517 +  out->print("ciMethodData %s %s %s %d %d",
   1.518 +             holder->name()->as_quoted_ascii(),
   1.519 +             method->name()->as_quoted_ascii(),
   1.520 +             method->signature()->as_quoted_ascii(),
   1.521 +             _state,
   1.522 +             current_mileage());
   1.523 +
   1.524 +  // dump the contents of the MDO header as raw data
   1.525 +  unsigned char* orig = (unsigned char*)&_orig;
   1.526 +  int length = sizeof(_orig);
   1.527 +  out->print(" orig %d", length);
   1.528 +  for (int i = 0; i < length; i++) {
   1.529 +    out->print(" %d", orig[i]);
   1.530 +  }
   1.531 +
   1.532 +  // dump the MDO data as raw data
   1.533 +  int elements = data_size() / sizeof(intptr_t);
   1.534 +  out->print(" data %d", elements);
   1.535 +  for (int i = 0; i < elements; i++) {
   1.536 +    // We could use INTPTR_FORMAT here but that's a zero justified
   1.537 +    // which makes comparing it with the SA version of this output
   1.538 +    // harder.
   1.539 +#ifdef _LP64
   1.540 +    out->print(" 0x%" FORMAT64_MODIFIER "x", data()[i]);
   1.541 +#else
   1.542 +    out->print(" 0x%x", data()[i]);
   1.543 +#endif
   1.544 +  }
   1.545 +
   1.546 +  // The MDO contained oop references as ciObjects, so scan for those
   1.547 +  // and emit pairs of offset and klass name so that they can be
   1.548 +  // reconstructed at runtime.  The first round counts the number of
   1.549 +  // oop references and the second actually emits them.
   1.550 +  int count = 0;
   1.551 +  for (int round = 0; round < 2; round++) {
   1.552 +    if (round == 1) out->print(" oops %d", count);
   1.553 +    ProfileData* pdata = first_data();
   1.554 +    for ( ; is_valid(pdata); pdata = next_data(pdata)) {
   1.555 +      if (pdata->is_ReceiverTypeData()) {
   1.556 +        ciReceiverTypeData* vdata = (ciReceiverTypeData*)pdata;
   1.557 +        for (uint i = 0; i < vdata->row_limit(); i++) {
   1.558 +          ciKlass* k = vdata->receiver(i);
   1.559 +          if (k != NULL) {
   1.560 +            if (round == 0) {
   1.561 +              count++;
   1.562 +            } else {
   1.563 +              out->print(" %d %s", (int)(dp_to_di(vdata->dp() + in_bytes(vdata->receiver_offset(i))) / sizeof(intptr_t)), k->name()->as_quoted_ascii());
   1.564 +            }
   1.565 +          }
   1.566 +        }
   1.567 +      } else if (pdata->is_VirtualCallData()) {
   1.568 +        ciVirtualCallData* vdata = (ciVirtualCallData*)pdata;
   1.569 +        for (uint i = 0; i < vdata->row_limit(); i++) {
   1.570 +          ciKlass* k = vdata->receiver(i);
   1.571 +          if (k != NULL) {
   1.572 +            if (round == 0) {
   1.573 +              count++;
   1.574 +            } else {
   1.575 +              out->print(" %d %s", (int)(dp_to_di(vdata->dp() + in_bytes(vdata->receiver_offset(i))) / sizeof(intptr_t)), k->name()->as_quoted_ascii());
   1.576 +            }
   1.577 +          }
   1.578 +        }
   1.579 +      }
   1.580 +    }
   1.581 +  }
   1.582 +  out->cr();
   1.583 +}
   1.584 +
   1.585 +#ifndef PRODUCT
   1.586 +void ciMethodData::print() {
   1.587 +  print_data_on(tty);
   1.588 +}
   1.589 +
   1.590 +void ciMethodData::print_data_on(outputStream* st) {
   1.591 +  ResourceMark rm;
   1.592 +  ciProfileData* data;
   1.593 +  for (data = first_data(); is_valid(data); data = next_data(data)) {
   1.594 +    st->print("%d", dp_to_di(data->dp()));
   1.595 +    st->fill_to(6);
   1.596 +    data->print_data_on(st);
   1.597 +  }
   1.598 +  st->print_cr("--- Extra data:");
   1.599 +  DataLayout* dp  = data_layout_at(data_size());
   1.600 +  DataLayout* end = data_layout_at(data_size() + extra_data_size());
   1.601 +  for (;; dp = MethodData::next_extra(dp)) {
   1.602 +    assert(dp < end, "moved past end of extra data");
   1.603 +    switch (dp->tag()) {
   1.604 +    case DataLayout::no_tag:
   1.605 +      continue;
   1.606 +    case DataLayout::bit_data_tag:
   1.607 +      data = new BitData(dp);
   1.608 +      break;
   1.609 +    case DataLayout::arg_info_data_tag:
   1.610 +      data = new ciArgInfoData(dp);
   1.611 +      dp = end; // ArgInfoData is at the end of extra data section.
   1.612 +      break;
   1.613 +    default:
   1.614 +      fatal(err_msg("unexpected tag %d", dp->tag()));
   1.615 +    }
   1.616 +    st->print("%d", dp_to_di(data->dp()));
   1.617 +    st->fill_to(6);
   1.618 +    data->print_data_on(st);
   1.619 +    if (dp >= end) return;
   1.620 +  }
   1.621 +}
   1.622 +
   1.623 +void ciTypeEntries::print_ciklass(outputStream* st, intptr_t k) {
   1.624 +  if (TypeEntries::is_type_none(k)) {
   1.625 +    st->print("none");
   1.626 +  } else if (TypeEntries::is_type_unknown(k)) {
   1.627 +    st->print("unknown");
   1.628 +  } else {
   1.629 +    valid_ciklass(k)->print_name_on(st);
   1.630 +  }
   1.631 +  if (TypeEntries::was_null_seen(k)) {
   1.632 +    st->print(" (null seen)");
   1.633 +  }
   1.634 +}
   1.635 +
   1.636 +void ciTypeStackSlotEntries::print_data_on(outputStream* st) const {
   1.637 +  for (int i = 0; i < _number_of_entries; i++) {
   1.638 +    _pd->tab(st);
   1.639 +    st->print("%d: stack (%u) ", i, stack_slot(i));
   1.640 +    print_ciklass(st, type(i));
   1.641 +    st->cr();
   1.642 +  }
   1.643 +}
   1.644 +
   1.645 +void ciReturnTypeEntry::print_data_on(outputStream* st) const {
   1.646 +  _pd->tab(st);
   1.647 +  st->print("ret ");
   1.648 +  print_ciklass(st, type());
   1.649 +  st->cr();
   1.650 +}
   1.651 +
   1.652 +void ciCallTypeData::print_data_on(outputStream* st, const char* extra) const {
   1.653 +  print_shared(st, "ciCallTypeData", extra);
   1.654 +  if (has_arguments()) {
   1.655 +    tab(st, true);
   1.656 +    st->print("argument types");
   1.657 +    args()->print_data_on(st);
   1.658 +  }
   1.659 +  if (has_return()) {
   1.660 +    tab(st, true);
   1.661 +    st->print("return type");
   1.662 +    ret()->print_data_on(st);
   1.663 +  }
   1.664 +}
   1.665 +
   1.666 +void ciReceiverTypeData::print_receiver_data_on(outputStream* st) const {
   1.667 +  uint row;
   1.668 +  int entries = 0;
   1.669 +  for (row = 0; row < row_limit(); row++) {
   1.670 +    if (receiver(row) != NULL)  entries++;
   1.671 +  }
   1.672 +  st->print_cr("count(%u) entries(%u)", count(), entries);
   1.673 +  for (row = 0; row < row_limit(); row++) {
   1.674 +    if (receiver(row) != NULL) {
   1.675 +      tab(st);
   1.676 +      receiver(row)->print_name_on(st);
   1.677 +      st->print_cr("(%u)", receiver_count(row));
   1.678 +    }
   1.679 +  }
   1.680 +}
   1.681 +
   1.682 +void ciReceiverTypeData::print_data_on(outputStream* st, const char* extra) const {
   1.683 +  print_shared(st, "ciReceiverTypeData", extra);
   1.684 +  print_receiver_data_on(st);
   1.685 +}
   1.686 +
   1.687 +void ciVirtualCallData::print_data_on(outputStream* st, const char* extra) const {
   1.688 +  print_shared(st, "ciVirtualCallData", extra);
   1.689 +  rtd_super()->print_receiver_data_on(st);
   1.690 +}
   1.691 +
   1.692 +void ciVirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const {
   1.693 +  print_shared(st, "ciVirtualCallTypeData", extra);
   1.694 +  rtd_super()->print_receiver_data_on(st);
   1.695 +  if (has_arguments()) {
   1.696 +    tab(st, true);
   1.697 +    st->print("argument types");
   1.698 +    args()->print_data_on(st);
   1.699 +  }
   1.700 +  if (has_return()) {
   1.701 +    tab(st, true);
   1.702 +    st->print("return type");
   1.703 +    ret()->print_data_on(st);
   1.704 +  }
   1.705 +}
   1.706 +
   1.707 +void ciParametersTypeData::print_data_on(outputStream* st, const char* extra) const {
   1.708 +  st->print_cr("ciParametersTypeData");
   1.709 +  parameters()->print_data_on(st);
   1.710 +}
   1.711 +
   1.712 +void ciSpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const {
   1.713 +  st->print_cr("ciSpeculativeTrapData");
   1.714 +  tab(st);
   1.715 +  method()->print_short_name(st);
   1.716 +  st->cr();
   1.717 +}
   1.718 +#endif

mercurial