src/share/vm/oops/methodData.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/oops/methodData.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,2490 @@
     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 +#ifndef SHARE_VM_OOPS_METHODDATAOOP_HPP
    1.29 +#define SHARE_VM_OOPS_METHODDATAOOP_HPP
    1.30 +
    1.31 +#include "interpreter/bytecodes.hpp"
    1.32 +#include "memory/universe.hpp"
    1.33 +#include "oops/method.hpp"
    1.34 +#include "oops/oop.hpp"
    1.35 +#include "runtime/orderAccess.hpp"
    1.36 +
    1.37 +class BytecodeStream;
    1.38 +class KlassSizeStats;
    1.39 +
    1.40 +// The MethodData object collects counts and other profile information
    1.41 +// during zeroth-tier (interpretive) and first-tier execution.
    1.42 +// The profile is used later by compilation heuristics.  Some heuristics
    1.43 +// enable use of aggressive (or "heroic") optimizations.  An aggressive
    1.44 +// optimization often has a down-side, a corner case that it handles
    1.45 +// poorly, but which is thought to be rare.  The profile provides
    1.46 +// evidence of this rarity for a given method or even BCI.  It allows
    1.47 +// the compiler to back out of the optimization at places where it
    1.48 +// has historically been a poor choice.  Other heuristics try to use
    1.49 +// specific information gathered about types observed at a given site.
    1.50 +//
    1.51 +// All data in the profile is approximate.  It is expected to be accurate
    1.52 +// on the whole, but the system expects occasional inaccuraces, due to
    1.53 +// counter overflow, multiprocessor races during data collection, space
    1.54 +// limitations, missing MDO blocks, etc.  Bad or missing data will degrade
    1.55 +// optimization quality but will not affect correctness.  Also, each MDO
    1.56 +// is marked with its birth-date ("creation_mileage") which can be used
    1.57 +// to assess the quality ("maturity") of its data.
    1.58 +//
    1.59 +// Short (<32-bit) counters are designed to overflow to a known "saturated"
    1.60 +// state.  Also, certain recorded per-BCI events are given one-bit counters
    1.61 +// which overflow to a saturated state which applied to all counters at
    1.62 +// that BCI.  In other words, there is a small lattice which approximates
    1.63 +// the ideal of an infinite-precision counter for each event at each BCI,
    1.64 +// and the lattice quickly "bottoms out" in a state where all counters
    1.65 +// are taken to be indefinitely large.
    1.66 +//
    1.67 +// The reader will find many data races in profile gathering code, starting
    1.68 +// with invocation counter incrementation.  None of these races harm correct
    1.69 +// execution of the compiled code.
    1.70 +
    1.71 +// forward decl
    1.72 +class ProfileData;
    1.73 +
    1.74 +// DataLayout
    1.75 +//
    1.76 +// Overlay for generic profiling data.
    1.77 +class DataLayout VALUE_OBJ_CLASS_SPEC {
    1.78 +  friend class VMStructs;
    1.79 +
    1.80 +private:
    1.81 +  // Every data layout begins with a header.  This header
    1.82 +  // contains a tag, which is used to indicate the size/layout
    1.83 +  // of the data, 4 bits of flags, which can be used in any way,
    1.84 +  // 4 bits of trap history (none/one reason/many reasons),
    1.85 +  // and a bci, which is used to tie this piece of data to a
    1.86 +  // specific bci in the bytecodes.
    1.87 +  union {
    1.88 +    intptr_t _bits;
    1.89 +    struct {
    1.90 +      u1 _tag;
    1.91 +      u1 _flags;
    1.92 +      u2 _bci;
    1.93 +    } _struct;
    1.94 +  } _header;
    1.95 +
    1.96 +  // The data layout has an arbitrary number of cells, each sized
    1.97 +  // to accomodate a pointer or an integer.
    1.98 +  intptr_t _cells[1];
    1.99 +
   1.100 +  // Some types of data layouts need a length field.
   1.101 +  static bool needs_array_len(u1 tag);
   1.102 +
   1.103 +public:
   1.104 +  enum {
   1.105 +    counter_increment = 1
   1.106 +  };
   1.107 +
   1.108 +  enum {
   1.109 +    cell_size = sizeof(intptr_t)
   1.110 +  };
   1.111 +
   1.112 +  // Tag values
   1.113 +  enum {
   1.114 +    no_tag,
   1.115 +    bit_data_tag,
   1.116 +    counter_data_tag,
   1.117 +    jump_data_tag,
   1.118 +    receiver_type_data_tag,
   1.119 +    virtual_call_data_tag,
   1.120 +    ret_data_tag,
   1.121 +    branch_data_tag,
   1.122 +    multi_branch_data_tag,
   1.123 +    arg_info_data_tag,
   1.124 +    call_type_data_tag,
   1.125 +    virtual_call_type_data_tag,
   1.126 +    parameters_type_data_tag,
   1.127 +    speculative_trap_data_tag
   1.128 +  };
   1.129 +
   1.130 +  enum {
   1.131 +    // The _struct._flags word is formatted as [trap_state:4 | flags:4].
   1.132 +    // The trap state breaks down further as [recompile:1 | reason:3].
   1.133 +    // This further breakdown is defined in deoptimization.cpp.
   1.134 +    // See Deoptimization::trap_state_reason for an assert that
   1.135 +    // trap_bits is big enough to hold reasons < Reason_RECORDED_LIMIT.
   1.136 +    //
   1.137 +    // The trap_state is collected only if ProfileTraps is true.
   1.138 +    trap_bits = 1+3,  // 3: enough to distinguish [0..Reason_RECORDED_LIMIT].
   1.139 +    trap_shift = BitsPerByte - trap_bits,
   1.140 +    trap_mask = right_n_bits(trap_bits),
   1.141 +    trap_mask_in_place = (trap_mask << trap_shift),
   1.142 +    flag_limit = trap_shift,
   1.143 +    flag_mask = right_n_bits(flag_limit),
   1.144 +    first_flag = 0
   1.145 +  };
   1.146 +
   1.147 +  // Size computation
   1.148 +  static int header_size_in_bytes() {
   1.149 +    return cell_size;
   1.150 +  }
   1.151 +  static int header_size_in_cells() {
   1.152 +    return 1;
   1.153 +  }
   1.154 +
   1.155 +  static int compute_size_in_bytes(int cell_count) {
   1.156 +    return header_size_in_bytes() + cell_count * cell_size;
   1.157 +  }
   1.158 +
   1.159 +  // Initialization
   1.160 +  void initialize(u1 tag, u2 bci, int cell_count);
   1.161 +
   1.162 +  // Accessors
   1.163 +  u1 tag() {
   1.164 +    return _header._struct._tag;
   1.165 +  }
   1.166 +
   1.167 +  // Return a few bits of trap state.  Range is [0..trap_mask].
   1.168 +  // The state tells if traps with zero, one, or many reasons have occurred.
   1.169 +  // It also tells whether zero or many recompilations have occurred.
   1.170 +  // The associated trap histogram in the MDO itself tells whether
   1.171 +  // traps are common or not.  If a BCI shows that a trap X has
   1.172 +  // occurred, and the MDO shows N occurrences of X, we make the
   1.173 +  // simplifying assumption that all N occurrences can be blamed
   1.174 +  // on that BCI.
   1.175 +  int trap_state() const {
   1.176 +    return ((_header._struct._flags >> trap_shift) & trap_mask);
   1.177 +  }
   1.178 +
   1.179 +  void set_trap_state(int new_state) {
   1.180 +    assert(ProfileTraps, "used only under +ProfileTraps");
   1.181 +    uint old_flags = (_header._struct._flags & flag_mask);
   1.182 +    _header._struct._flags = (new_state << trap_shift) | old_flags;
   1.183 +  }
   1.184 +
   1.185 +  u1 flags() const {
   1.186 +    return _header._struct._flags;
   1.187 +  }
   1.188 +
   1.189 +  u2 bci() const {
   1.190 +    return _header._struct._bci;
   1.191 +  }
   1.192 +
   1.193 +  void set_header(intptr_t value) {
   1.194 +    _header._bits = value;
   1.195 +  }
   1.196 +  intptr_t header() {
   1.197 +    return _header._bits;
   1.198 +  }
   1.199 +  void set_cell_at(int index, intptr_t value) {
   1.200 +    _cells[index] = value;
   1.201 +  }
   1.202 +  void release_set_cell_at(int index, intptr_t value) {
   1.203 +    OrderAccess::release_store_ptr(&_cells[index], value);
   1.204 +  }
   1.205 +  intptr_t cell_at(int index) const {
   1.206 +    return _cells[index];
   1.207 +  }
   1.208 +
   1.209 +  void set_flag_at(int flag_number) {
   1.210 +    assert(flag_number < flag_limit, "oob");
   1.211 +    _header._struct._flags |= (0x1 << flag_number);
   1.212 +  }
   1.213 +  bool flag_at(int flag_number) const {
   1.214 +    assert(flag_number < flag_limit, "oob");
   1.215 +    return (_header._struct._flags & (0x1 << flag_number)) != 0;
   1.216 +  }
   1.217 +
   1.218 +  // Low-level support for code generation.
   1.219 +  static ByteSize header_offset() {
   1.220 +    return byte_offset_of(DataLayout, _header);
   1.221 +  }
   1.222 +  static ByteSize tag_offset() {
   1.223 +    return byte_offset_of(DataLayout, _header._struct._tag);
   1.224 +  }
   1.225 +  static ByteSize flags_offset() {
   1.226 +    return byte_offset_of(DataLayout, _header._struct._flags);
   1.227 +  }
   1.228 +  static ByteSize bci_offset() {
   1.229 +    return byte_offset_of(DataLayout, _header._struct._bci);
   1.230 +  }
   1.231 +  static ByteSize cell_offset(int index) {
   1.232 +    return byte_offset_of(DataLayout, _cells) + in_ByteSize(index * cell_size);
   1.233 +  }
   1.234 +#ifdef CC_INTERP
   1.235 +  static int cell_offset_in_bytes(int index) {
   1.236 +    return (int)offset_of(DataLayout, _cells[index]);
   1.237 +  }
   1.238 +#endif // CC_INTERP
   1.239 +  // Return a value which, when or-ed as a byte into _flags, sets the flag.
   1.240 +  static int flag_number_to_byte_constant(int flag_number) {
   1.241 +    assert(0 <= flag_number && flag_number < flag_limit, "oob");
   1.242 +    DataLayout temp; temp.set_header(0);
   1.243 +    temp.set_flag_at(flag_number);
   1.244 +    return temp._header._struct._flags;
   1.245 +  }
   1.246 +  // Return a value which, when or-ed as a word into _header, sets the flag.
   1.247 +  static intptr_t flag_mask_to_header_mask(int byte_constant) {
   1.248 +    DataLayout temp; temp.set_header(0);
   1.249 +    temp._header._struct._flags = byte_constant;
   1.250 +    return temp._header._bits;
   1.251 +  }
   1.252 +
   1.253 +  ProfileData* data_in();
   1.254 +
   1.255 +  // GC support
   1.256 +  void clean_weak_klass_links(BoolObjectClosure* cl);
   1.257 +};
   1.258 +
   1.259 +
   1.260 +// ProfileData class hierarchy
   1.261 +class ProfileData;
   1.262 +class   BitData;
   1.263 +class     CounterData;
   1.264 +class       ReceiverTypeData;
   1.265 +class         VirtualCallData;
   1.266 +class           VirtualCallTypeData;
   1.267 +class       RetData;
   1.268 +class       CallTypeData;
   1.269 +class   JumpData;
   1.270 +class     BranchData;
   1.271 +class   ArrayData;
   1.272 +class     MultiBranchData;
   1.273 +class     ArgInfoData;
   1.274 +class     ParametersTypeData;
   1.275 +class   SpeculativeTrapData;
   1.276 +
   1.277 +// ProfileData
   1.278 +//
   1.279 +// A ProfileData object is created to refer to a section of profiling
   1.280 +// data in a structured way.
   1.281 +class ProfileData : public ResourceObj {
   1.282 +  friend class TypeEntries;
   1.283 +  friend class ReturnTypeEntry;
   1.284 +  friend class TypeStackSlotEntries;
   1.285 +private:
   1.286 +#ifndef PRODUCT
   1.287 +  enum {
   1.288 +    tab_width_one = 16,
   1.289 +    tab_width_two = 36
   1.290 +  };
   1.291 +#endif // !PRODUCT
   1.292 +
   1.293 +  // This is a pointer to a section of profiling data.
   1.294 +  DataLayout* _data;
   1.295 +
   1.296 +  char* print_data_on_helper(const MethodData* md) const;
   1.297 +
   1.298 +protected:
   1.299 +  DataLayout* data() { return _data; }
   1.300 +  const DataLayout* data() const { return _data; }
   1.301 +
   1.302 +  enum {
   1.303 +    cell_size = DataLayout::cell_size
   1.304 +  };
   1.305 +
   1.306 +public:
   1.307 +  // How many cells are in this?
   1.308 +  virtual int cell_count() const {
   1.309 +    ShouldNotReachHere();
   1.310 +    return -1;
   1.311 +  }
   1.312 +
   1.313 +  // Return the size of this data.
   1.314 +  int size_in_bytes() {
   1.315 +    return DataLayout::compute_size_in_bytes(cell_count());
   1.316 +  }
   1.317 +
   1.318 +protected:
   1.319 +  // Low-level accessors for underlying data
   1.320 +  void set_intptr_at(int index, intptr_t value) {
   1.321 +    assert(0 <= index && index < cell_count(), "oob");
   1.322 +    data()->set_cell_at(index, value);
   1.323 +  }
   1.324 +  void release_set_intptr_at(int index, intptr_t value) {
   1.325 +    assert(0 <= index && index < cell_count(), "oob");
   1.326 +    data()->release_set_cell_at(index, value);
   1.327 +  }
   1.328 +  intptr_t intptr_at(int index) const {
   1.329 +    assert(0 <= index && index < cell_count(), "oob");
   1.330 +    return data()->cell_at(index);
   1.331 +  }
   1.332 +  void set_uint_at(int index, uint value) {
   1.333 +    set_intptr_at(index, (intptr_t) value);
   1.334 +  }
   1.335 +  void release_set_uint_at(int index, uint value) {
   1.336 +    release_set_intptr_at(index, (intptr_t) value);
   1.337 +  }
   1.338 +  uint uint_at(int index) const {
   1.339 +    return (uint)intptr_at(index);
   1.340 +  }
   1.341 +  void set_int_at(int index, int value) {
   1.342 +    set_intptr_at(index, (intptr_t) value);
   1.343 +  }
   1.344 +  void release_set_int_at(int index, int value) {
   1.345 +    release_set_intptr_at(index, (intptr_t) value);
   1.346 +  }
   1.347 +  int int_at(int index) const {
   1.348 +    return (int)intptr_at(index);
   1.349 +  }
   1.350 +  int int_at_unchecked(int index) const {
   1.351 +    return (int)data()->cell_at(index);
   1.352 +  }
   1.353 +  void set_oop_at(int index, oop value) {
   1.354 +    set_intptr_at(index, cast_from_oop<intptr_t>(value));
   1.355 +  }
   1.356 +  oop oop_at(int index) const {
   1.357 +    return cast_to_oop(intptr_at(index));
   1.358 +  }
   1.359 +
   1.360 +  void set_flag_at(int flag_number) {
   1.361 +    data()->set_flag_at(flag_number);
   1.362 +  }
   1.363 +  bool flag_at(int flag_number) const {
   1.364 +    return data()->flag_at(flag_number);
   1.365 +  }
   1.366 +
   1.367 +  // two convenient imports for use by subclasses:
   1.368 +  static ByteSize cell_offset(int index) {
   1.369 +    return DataLayout::cell_offset(index);
   1.370 +  }
   1.371 +  static int flag_number_to_byte_constant(int flag_number) {
   1.372 +    return DataLayout::flag_number_to_byte_constant(flag_number);
   1.373 +  }
   1.374 +
   1.375 +  ProfileData(DataLayout* data) {
   1.376 +    _data = data;
   1.377 +  }
   1.378 +
   1.379 +#ifdef CC_INTERP
   1.380 +  // Static low level accessors for DataLayout with ProfileData's semantics.
   1.381 +
   1.382 +  static int cell_offset_in_bytes(int index) {
   1.383 +    return DataLayout::cell_offset_in_bytes(index);
   1.384 +  }
   1.385 +
   1.386 +  static void increment_uint_at_no_overflow(DataLayout* layout, int index,
   1.387 +                                            int inc = DataLayout::counter_increment) {
   1.388 +    uint count = ((uint)layout->cell_at(index)) + inc;
   1.389 +    if (count == 0) return;
   1.390 +    layout->set_cell_at(index, (intptr_t) count);
   1.391 +  }
   1.392 +
   1.393 +  static int int_at(DataLayout* layout, int index) {
   1.394 +    return (int)layout->cell_at(index);
   1.395 +  }
   1.396 +
   1.397 +  static int uint_at(DataLayout* layout, int index) {
   1.398 +    return (uint)layout->cell_at(index);
   1.399 +  }
   1.400 +
   1.401 +  static oop oop_at(DataLayout* layout, int index) {
   1.402 +    return cast_to_oop(layout->cell_at(index));
   1.403 +  }
   1.404 +
   1.405 +  static void set_intptr_at(DataLayout* layout, int index, intptr_t value) {
   1.406 +    layout->set_cell_at(index, (intptr_t) value);
   1.407 +  }
   1.408 +
   1.409 +  static void set_flag_at(DataLayout* layout, int flag_number) {
   1.410 +    layout->set_flag_at(flag_number);
   1.411 +  }
   1.412 +#endif // CC_INTERP
   1.413 +
   1.414 +public:
   1.415 +  // Constructor for invalid ProfileData.
   1.416 +  ProfileData();
   1.417 +
   1.418 +  u2 bci() const {
   1.419 +    return data()->bci();
   1.420 +  }
   1.421 +
   1.422 +  address dp() {
   1.423 +    return (address)_data;
   1.424 +  }
   1.425 +
   1.426 +  int trap_state() const {
   1.427 +    return data()->trap_state();
   1.428 +  }
   1.429 +  void set_trap_state(int new_state) {
   1.430 +    data()->set_trap_state(new_state);
   1.431 +  }
   1.432 +
   1.433 +  // Type checking
   1.434 +  virtual bool is_BitData()         const { return false; }
   1.435 +  virtual bool is_CounterData()     const { return false; }
   1.436 +  virtual bool is_JumpData()        const { return false; }
   1.437 +  virtual bool is_ReceiverTypeData()const { return false; }
   1.438 +  virtual bool is_VirtualCallData() const { return false; }
   1.439 +  virtual bool is_RetData()         const { return false; }
   1.440 +  virtual bool is_BranchData()      const { return false; }
   1.441 +  virtual bool is_ArrayData()       const { return false; }
   1.442 +  virtual bool is_MultiBranchData() const { return false; }
   1.443 +  virtual bool is_ArgInfoData()     const { return false; }
   1.444 +  virtual bool is_CallTypeData()    const { return false; }
   1.445 +  virtual bool is_VirtualCallTypeData()const { return false; }
   1.446 +  virtual bool is_ParametersTypeData() const { return false; }
   1.447 +  virtual bool is_SpeculativeTrapData()const { return false; }
   1.448 +
   1.449 +
   1.450 +  BitData* as_BitData() const {
   1.451 +    assert(is_BitData(), "wrong type");
   1.452 +    return is_BitData()         ? (BitData*)        this : NULL;
   1.453 +  }
   1.454 +  CounterData* as_CounterData() const {
   1.455 +    assert(is_CounterData(), "wrong type");
   1.456 +    return is_CounterData()     ? (CounterData*)    this : NULL;
   1.457 +  }
   1.458 +  JumpData* as_JumpData() const {
   1.459 +    assert(is_JumpData(), "wrong type");
   1.460 +    return is_JumpData()        ? (JumpData*)       this : NULL;
   1.461 +  }
   1.462 +  ReceiverTypeData* as_ReceiverTypeData() const {
   1.463 +    assert(is_ReceiverTypeData(), "wrong type");
   1.464 +    return is_ReceiverTypeData() ? (ReceiverTypeData*)this : NULL;
   1.465 +  }
   1.466 +  VirtualCallData* as_VirtualCallData() const {
   1.467 +    assert(is_VirtualCallData(), "wrong type");
   1.468 +    return is_VirtualCallData() ? (VirtualCallData*)this : NULL;
   1.469 +  }
   1.470 +  RetData* as_RetData() const {
   1.471 +    assert(is_RetData(), "wrong type");
   1.472 +    return is_RetData()         ? (RetData*)        this : NULL;
   1.473 +  }
   1.474 +  BranchData* as_BranchData() const {
   1.475 +    assert(is_BranchData(), "wrong type");
   1.476 +    return is_BranchData()      ? (BranchData*)     this : NULL;
   1.477 +  }
   1.478 +  ArrayData* as_ArrayData() const {
   1.479 +    assert(is_ArrayData(), "wrong type");
   1.480 +    return is_ArrayData()       ? (ArrayData*)      this : NULL;
   1.481 +  }
   1.482 +  MultiBranchData* as_MultiBranchData() const {
   1.483 +    assert(is_MultiBranchData(), "wrong type");
   1.484 +    return is_MultiBranchData() ? (MultiBranchData*)this : NULL;
   1.485 +  }
   1.486 +  ArgInfoData* as_ArgInfoData() const {
   1.487 +    assert(is_ArgInfoData(), "wrong type");
   1.488 +    return is_ArgInfoData() ? (ArgInfoData*)this : NULL;
   1.489 +  }
   1.490 +  CallTypeData* as_CallTypeData() const {
   1.491 +    assert(is_CallTypeData(), "wrong type");
   1.492 +    return is_CallTypeData() ? (CallTypeData*)this : NULL;
   1.493 +  }
   1.494 +  VirtualCallTypeData* as_VirtualCallTypeData() const {
   1.495 +    assert(is_VirtualCallTypeData(), "wrong type");
   1.496 +    return is_VirtualCallTypeData() ? (VirtualCallTypeData*)this : NULL;
   1.497 +  }
   1.498 +  ParametersTypeData* as_ParametersTypeData() const {
   1.499 +    assert(is_ParametersTypeData(), "wrong type");
   1.500 +    return is_ParametersTypeData() ? (ParametersTypeData*)this : NULL;
   1.501 +  }
   1.502 +  SpeculativeTrapData* as_SpeculativeTrapData() const {
   1.503 +    assert(is_SpeculativeTrapData(), "wrong type");
   1.504 +    return is_SpeculativeTrapData() ? (SpeculativeTrapData*)this : NULL;
   1.505 +  }
   1.506 +
   1.507 +
   1.508 +  // Subclass specific initialization
   1.509 +  virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {}
   1.510 +
   1.511 +  // GC support
   1.512 +  virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {}
   1.513 +
   1.514 +  // CI translation: ProfileData can represent both MethodDataOop data
   1.515 +  // as well as CIMethodData data. This function is provided for translating
   1.516 +  // an oop in a ProfileData to the ci equivalent. Generally speaking,
   1.517 +  // most ProfileData don't require any translation, so we provide the null
   1.518 +  // translation here, and the required translators are in the ci subclasses.
   1.519 +  virtual void translate_from(const ProfileData* data) {}
   1.520 +
   1.521 +  virtual void print_data_on(outputStream* st, const char* extra = NULL) const {
   1.522 +    ShouldNotReachHere();
   1.523 +  }
   1.524 +
   1.525 +  void print_data_on(outputStream* st, const MethodData* md) const;
   1.526 +
   1.527 +#ifndef PRODUCT
   1.528 +  void print_shared(outputStream* st, const char* name, const char* extra) const;
   1.529 +  void tab(outputStream* st, bool first = false) const;
   1.530 +#endif
   1.531 +};
   1.532 +
   1.533 +// BitData
   1.534 +//
   1.535 +// A BitData holds a flag or two in its header.
   1.536 +class BitData : public ProfileData {
   1.537 +protected:
   1.538 +  enum {
   1.539 +    // null_seen:
   1.540 +    //  saw a null operand (cast/aastore/instanceof)
   1.541 +    null_seen_flag              = DataLayout::first_flag + 0
   1.542 +  };
   1.543 +  enum { bit_cell_count = 0 };  // no additional data fields needed.
   1.544 +public:
   1.545 +  BitData(DataLayout* layout) : ProfileData(layout) {
   1.546 +  }
   1.547 +
   1.548 +  virtual bool is_BitData() const { return true; }
   1.549 +
   1.550 +  static int static_cell_count() {
   1.551 +    return bit_cell_count;
   1.552 +  }
   1.553 +
   1.554 +  virtual int cell_count() const {
   1.555 +    return static_cell_count();
   1.556 +  }
   1.557 +
   1.558 +  // Accessor
   1.559 +
   1.560 +  // The null_seen flag bit is specially known to the interpreter.
   1.561 +  // Consulting it allows the compiler to avoid setting up null_check traps.
   1.562 +  bool null_seen()     { return flag_at(null_seen_flag); }
   1.563 +  void set_null_seen()    { set_flag_at(null_seen_flag); }
   1.564 +
   1.565 +
   1.566 +  // Code generation support
   1.567 +  static int null_seen_byte_constant() {
   1.568 +    return flag_number_to_byte_constant(null_seen_flag);
   1.569 +  }
   1.570 +
   1.571 +  static ByteSize bit_data_size() {
   1.572 +    return cell_offset(bit_cell_count);
   1.573 +  }
   1.574 +
   1.575 +#ifdef CC_INTERP
   1.576 +  static int bit_data_size_in_bytes() {
   1.577 +    return cell_offset_in_bytes(bit_cell_count);
   1.578 +  }
   1.579 +
   1.580 +  static void set_null_seen(DataLayout* layout) {
   1.581 +    set_flag_at(layout, null_seen_flag);
   1.582 +  }
   1.583 +
   1.584 +  static DataLayout* advance(DataLayout* layout) {
   1.585 +    return (DataLayout*) (((address)layout) + (ssize_t)BitData::bit_data_size_in_bytes());
   1.586 +  }
   1.587 +#endif // CC_INTERP
   1.588 +
   1.589 +#ifndef PRODUCT
   1.590 +  void print_data_on(outputStream* st, const char* extra = NULL) const;
   1.591 +#endif
   1.592 +};
   1.593 +
   1.594 +// CounterData
   1.595 +//
   1.596 +// A CounterData corresponds to a simple counter.
   1.597 +class CounterData : public BitData {
   1.598 +protected:
   1.599 +  enum {
   1.600 +    count_off,
   1.601 +    counter_cell_count
   1.602 +  };
   1.603 +public:
   1.604 +  CounterData(DataLayout* layout) : BitData(layout) {}
   1.605 +
   1.606 +  virtual bool is_CounterData() const { return true; }
   1.607 +
   1.608 +  static int static_cell_count() {
   1.609 +    return counter_cell_count;
   1.610 +  }
   1.611 +
   1.612 +  virtual int cell_count() const {
   1.613 +    return static_cell_count();
   1.614 +  }
   1.615 +
   1.616 +  // Direct accessor
   1.617 +  uint count() const {
   1.618 +    return uint_at(count_off);
   1.619 +  }
   1.620 +
   1.621 +  // Code generation support
   1.622 +  static ByteSize count_offset() {
   1.623 +    return cell_offset(count_off);
   1.624 +  }
   1.625 +  static ByteSize counter_data_size() {
   1.626 +    return cell_offset(counter_cell_count);
   1.627 +  }
   1.628 +
   1.629 +  void set_count(uint count) {
   1.630 +    set_uint_at(count_off, count);
   1.631 +  }
   1.632 +
   1.633 +#ifdef CC_INTERP
   1.634 +  static int counter_data_size_in_bytes() {
   1.635 +    return cell_offset_in_bytes(counter_cell_count);
   1.636 +  }
   1.637 +
   1.638 +  static void increment_count_no_overflow(DataLayout* layout) {
   1.639 +    increment_uint_at_no_overflow(layout, count_off);
   1.640 +  }
   1.641 +
   1.642 +  // Support counter decrementation at checkcast / subtype check failed.
   1.643 +  static void decrement_count(DataLayout* layout) {
   1.644 +    increment_uint_at_no_overflow(layout, count_off, -1);
   1.645 +  }
   1.646 +
   1.647 +  static DataLayout* advance(DataLayout* layout) {
   1.648 +    return (DataLayout*) (((address)layout) + (ssize_t)CounterData::counter_data_size_in_bytes());
   1.649 +  }
   1.650 +#endif // CC_INTERP
   1.651 +
   1.652 +#ifndef PRODUCT
   1.653 +  void print_data_on(outputStream* st, const char* extra = NULL) const;
   1.654 +#endif
   1.655 +};
   1.656 +
   1.657 +// JumpData
   1.658 +//
   1.659 +// A JumpData is used to access profiling information for a direct
   1.660 +// branch.  It is a counter, used for counting the number of branches,
   1.661 +// plus a data displacement, used for realigning the data pointer to
   1.662 +// the corresponding target bci.
   1.663 +class JumpData : public ProfileData {
   1.664 +protected:
   1.665 +  enum {
   1.666 +    taken_off_set,
   1.667 +    displacement_off_set,
   1.668 +    jump_cell_count
   1.669 +  };
   1.670 +
   1.671 +  void set_displacement(int displacement) {
   1.672 +    set_int_at(displacement_off_set, displacement);
   1.673 +  }
   1.674 +
   1.675 +public:
   1.676 +  JumpData(DataLayout* layout) : ProfileData(layout) {
   1.677 +    assert(layout->tag() == DataLayout::jump_data_tag ||
   1.678 +      layout->tag() == DataLayout::branch_data_tag, "wrong type");
   1.679 +  }
   1.680 +
   1.681 +  virtual bool is_JumpData() const { return true; }
   1.682 +
   1.683 +  static int static_cell_count() {
   1.684 +    return jump_cell_count;
   1.685 +  }
   1.686 +
   1.687 +  virtual int cell_count() const {
   1.688 +    return static_cell_count();
   1.689 +  }
   1.690 +
   1.691 +  // Direct accessor
   1.692 +  uint taken() const {
   1.693 +    return uint_at(taken_off_set);
   1.694 +  }
   1.695 +
   1.696 +  void set_taken(uint cnt) {
   1.697 +    set_uint_at(taken_off_set, cnt);
   1.698 +  }
   1.699 +
   1.700 +  // Saturating counter
   1.701 +  uint inc_taken() {
   1.702 +    uint cnt = taken() + 1;
   1.703 +    // Did we wrap? Will compiler screw us??
   1.704 +    if (cnt == 0) cnt--;
   1.705 +    set_uint_at(taken_off_set, cnt);
   1.706 +    return cnt;
   1.707 +  }
   1.708 +
   1.709 +  int displacement() const {
   1.710 +    return int_at(displacement_off_set);
   1.711 +  }
   1.712 +
   1.713 +  // Code generation support
   1.714 +  static ByteSize taken_offset() {
   1.715 +    return cell_offset(taken_off_set);
   1.716 +  }
   1.717 +
   1.718 +  static ByteSize displacement_offset() {
   1.719 +    return cell_offset(displacement_off_set);
   1.720 +  }
   1.721 +
   1.722 +#ifdef CC_INTERP
   1.723 +  static void increment_taken_count_no_overflow(DataLayout* layout) {
   1.724 +    increment_uint_at_no_overflow(layout, taken_off_set);
   1.725 +  }
   1.726 +
   1.727 +  static DataLayout* advance_taken(DataLayout* layout) {
   1.728 +    return (DataLayout*) (((address)layout) + (ssize_t)int_at(layout, displacement_off_set));
   1.729 +  }
   1.730 +
   1.731 +  static uint taken_count(DataLayout* layout) {
   1.732 +    return (uint) uint_at(layout, taken_off_set);
   1.733 +  }
   1.734 +#endif // CC_INTERP
   1.735 +
   1.736 +  // Specific initialization.
   1.737 +  void post_initialize(BytecodeStream* stream, MethodData* mdo);
   1.738 +
   1.739 +#ifndef PRODUCT
   1.740 +  void print_data_on(outputStream* st, const char* extra = NULL) const;
   1.741 +#endif
   1.742 +};
   1.743 +
   1.744 +// Entries in a ProfileData object to record types: it can either be
   1.745 +// none (no profile), unknown (conflicting profile data) or a klass if
   1.746 +// a single one is seen. Whether a null reference was seen is also
   1.747 +// recorded. No counter is associated with the type and a single type
   1.748 +// is tracked (unlike VirtualCallData).
   1.749 +class TypeEntries {
   1.750 +
   1.751 +public:
   1.752 +
   1.753 +  // A single cell is used to record information for a type:
   1.754 +  // - the cell is initialized to 0
   1.755 +  // - when a type is discovered it is stored in the cell
   1.756 +  // - bit zero of the cell is used to record whether a null reference
   1.757 +  // was encountered or not
   1.758 +  // - bit 1 is set to record a conflict in the type information
   1.759 +
   1.760 +  enum {
   1.761 +    null_seen = 1,
   1.762 +    type_mask = ~null_seen,
   1.763 +    type_unknown = 2,
   1.764 +    status_bits = null_seen | type_unknown,
   1.765 +    type_klass_mask = ~status_bits
   1.766 +  };
   1.767 +
   1.768 +  // what to initialize a cell to
   1.769 +  static intptr_t type_none() {
   1.770 +    return 0;
   1.771 +  }
   1.772 +
   1.773 +  // null seen = bit 0 set?
   1.774 +  static bool was_null_seen(intptr_t v) {
   1.775 +    return (v & null_seen) != 0;
   1.776 +  }
   1.777 +
   1.778 +  // conflicting type information = bit 1 set?
   1.779 +  static bool is_type_unknown(intptr_t v) {
   1.780 +    return (v & type_unknown) != 0;
   1.781 +  }
   1.782 +
   1.783 +  // not type information yet = all bits cleared, ignoring bit 0?
   1.784 +  static bool is_type_none(intptr_t v) {
   1.785 +    return (v & type_mask) == 0;
   1.786 +  }
   1.787 +
   1.788 +  // recorded type: cell without bit 0 and 1
   1.789 +  static intptr_t klass_part(intptr_t v) {
   1.790 +    intptr_t r = v & type_klass_mask;
   1.791 +    return r;
   1.792 +  }
   1.793 +
   1.794 +  // type recorded
   1.795 +  static Klass* valid_klass(intptr_t k) {
   1.796 +    if (!is_type_none(k) &&
   1.797 +        !is_type_unknown(k)) {
   1.798 +      Klass* res = (Klass*)klass_part(k);
   1.799 +      assert(res != NULL, "invalid");
   1.800 +      return res;
   1.801 +    } else {
   1.802 +      return NULL;
   1.803 +    }
   1.804 +  }
   1.805 +
   1.806 +  static intptr_t with_status(intptr_t k, intptr_t in) {
   1.807 +    return k | (in & status_bits);
   1.808 +  }
   1.809 +
   1.810 +  static intptr_t with_status(Klass* k, intptr_t in) {
   1.811 +    return with_status((intptr_t)k, in);
   1.812 +  }
   1.813 +
   1.814 +#ifndef PRODUCT
   1.815 +  static void print_klass(outputStream* st, intptr_t k);
   1.816 +#endif
   1.817 +
   1.818 +  // GC support
   1.819 +  static bool is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p);
   1.820 +
   1.821 +protected:
   1.822 +  // ProfileData object these entries are part of
   1.823 +  ProfileData* _pd;
   1.824 +  // offset within the ProfileData object where the entries start
   1.825 +  const int _base_off;
   1.826 +
   1.827 +  TypeEntries(int base_off)
   1.828 +    : _base_off(base_off), _pd(NULL) {}
   1.829 +
   1.830 +  void set_intptr_at(int index, intptr_t value) {
   1.831 +    _pd->set_intptr_at(index, value);
   1.832 +  }
   1.833 +
   1.834 +  intptr_t intptr_at(int index) const {
   1.835 +    return _pd->intptr_at(index);
   1.836 +  }
   1.837 +
   1.838 +public:
   1.839 +  void set_profile_data(ProfileData* pd) {
   1.840 +    _pd = pd;
   1.841 +  }
   1.842 +};
   1.843 +
   1.844 +// Type entries used for arguments passed at a call and parameters on
   1.845 +// method entry. 2 cells per entry: one for the type encoded as in
   1.846 +// TypeEntries and one initialized with the stack slot where the
   1.847 +// profiled object is to be found so that the interpreter can locate
   1.848 +// it quickly.
   1.849 +class TypeStackSlotEntries : public TypeEntries {
   1.850 +
   1.851 +private:
   1.852 +  enum {
   1.853 +    stack_slot_entry,
   1.854 +    type_entry,
   1.855 +    per_arg_cell_count
   1.856 +  };
   1.857 +
   1.858 +  // offset of cell for stack slot for entry i within ProfileData object
   1.859 +  int stack_slot_offset(int i) const {
   1.860 +    return _base_off + stack_slot_local_offset(i);
   1.861 +  }
   1.862 +
   1.863 +protected:
   1.864 +  const int _number_of_entries;
   1.865 +
   1.866 +  // offset of cell for type for entry i within ProfileData object
   1.867 +  int type_offset(int i) const {
   1.868 +    return _base_off + type_local_offset(i);
   1.869 +  }
   1.870 +
   1.871 +public:
   1.872 +
   1.873 +  TypeStackSlotEntries(int base_off, int nb_entries)
   1.874 +    : TypeEntries(base_off), _number_of_entries(nb_entries) {}
   1.875 +
   1.876 +  static int compute_cell_count(Symbol* signature, bool include_receiver, int max);
   1.877 +
   1.878 +  void post_initialize(Symbol* signature, bool has_receiver, bool include_receiver);
   1.879 +
   1.880 +  // offset of cell for stack slot for entry i within this block of cells for a TypeStackSlotEntries
   1.881 +  static int stack_slot_local_offset(int i) {
   1.882 +    return i * per_arg_cell_count + stack_slot_entry;
   1.883 +  }
   1.884 +
   1.885 +  // offset of cell for type for entry i within this block of cells for a TypeStackSlotEntries
   1.886 +  static int type_local_offset(int i) {
   1.887 +    return i * per_arg_cell_count + type_entry;
   1.888 +  }
   1.889 +
   1.890 +  // stack slot for entry i
   1.891 +  uint stack_slot(int i) const {
   1.892 +    assert(i >= 0 && i < _number_of_entries, "oob");
   1.893 +    return _pd->uint_at(stack_slot_offset(i));
   1.894 +  }
   1.895 +
   1.896 +  // set stack slot for entry i
   1.897 +  void set_stack_slot(int i, uint num) {
   1.898 +    assert(i >= 0 && i < _number_of_entries, "oob");
   1.899 +    _pd->set_uint_at(stack_slot_offset(i), num);
   1.900 +  }
   1.901 +
   1.902 +  // type for entry i
   1.903 +  intptr_t type(int i) const {
   1.904 +    assert(i >= 0 && i < _number_of_entries, "oob");
   1.905 +    return _pd->intptr_at(type_offset(i));
   1.906 +  }
   1.907 +
   1.908 +  // set type for entry i
   1.909 +  void set_type(int i, intptr_t k) {
   1.910 +    assert(i >= 0 && i < _number_of_entries, "oob");
   1.911 +    _pd->set_intptr_at(type_offset(i), k);
   1.912 +  }
   1.913 +
   1.914 +  static ByteSize per_arg_size() {
   1.915 +    return in_ByteSize(per_arg_cell_count * DataLayout::cell_size);
   1.916 +  }
   1.917 +
   1.918 +  static int per_arg_count() {
   1.919 +    return per_arg_cell_count ;
   1.920 +  }
   1.921 +
   1.922 +  // GC support
   1.923 +  void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
   1.924 +
   1.925 +#ifndef PRODUCT
   1.926 +  void print_data_on(outputStream* st) const;
   1.927 +#endif
   1.928 +};
   1.929 +
   1.930 +// Type entry used for return from a call. A single cell to record the
   1.931 +// type.
   1.932 +class ReturnTypeEntry : public TypeEntries {
   1.933 +
   1.934 +private:
   1.935 +  enum {
   1.936 +    cell_count = 1
   1.937 +  };
   1.938 +
   1.939 +public:
   1.940 +  ReturnTypeEntry(int base_off)
   1.941 +    : TypeEntries(base_off) {}
   1.942 +
   1.943 +  void post_initialize() {
   1.944 +    set_type(type_none());
   1.945 +  }
   1.946 +
   1.947 +  intptr_t type() const {
   1.948 +    return _pd->intptr_at(_base_off);
   1.949 +  }
   1.950 +
   1.951 +  void set_type(intptr_t k) {
   1.952 +    _pd->set_intptr_at(_base_off, k);
   1.953 +  }
   1.954 +
   1.955 +  static int static_cell_count() {
   1.956 +    return cell_count;
   1.957 +  }
   1.958 +
   1.959 +  static ByteSize size() {
   1.960 +    return in_ByteSize(cell_count * DataLayout::cell_size);
   1.961 +  }
   1.962 +
   1.963 +  ByteSize type_offset() {
   1.964 +    return DataLayout::cell_offset(_base_off);
   1.965 +  }
   1.966 +
   1.967 +  // GC support
   1.968 +  void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
   1.969 +
   1.970 +#ifndef PRODUCT
   1.971 +  void print_data_on(outputStream* st) const;
   1.972 +#endif
   1.973 +};
   1.974 +
   1.975 +// Entries to collect type information at a call: contains arguments
   1.976 +// (TypeStackSlotEntries), a return type (ReturnTypeEntry) and a
   1.977 +// number of cells. Because the number of cells for the return type is
   1.978 +// smaller than the number of cells for the type of an arguments, the
   1.979 +// number of cells is used to tell how many arguments are profiled and
   1.980 +// whether a return value is profiled. See has_arguments() and
   1.981 +// has_return().
   1.982 +class TypeEntriesAtCall {
   1.983 +private:
   1.984 +  static int stack_slot_local_offset(int i) {
   1.985 +    return header_cell_count() + TypeStackSlotEntries::stack_slot_local_offset(i);
   1.986 +  }
   1.987 +
   1.988 +  static int argument_type_local_offset(int i) {
   1.989 +    return header_cell_count() + TypeStackSlotEntries::type_local_offset(i);;
   1.990 +  }
   1.991 +
   1.992 +public:
   1.993 +
   1.994 +  static int header_cell_count() {
   1.995 +    return 1;
   1.996 +  }
   1.997 +
   1.998 +  static int cell_count_local_offset() {
   1.999 +    return 0;
  1.1000 +  }
  1.1001 +
  1.1002 +  static int compute_cell_count(BytecodeStream* stream);
  1.1003 +
  1.1004 +  static void initialize(DataLayout* dl, int base, int cell_count) {
  1.1005 +    int off = base + cell_count_local_offset();
  1.1006 +    dl->set_cell_at(off, cell_count - base - header_cell_count());
  1.1007 +  }
  1.1008 +
  1.1009 +  static bool arguments_profiling_enabled();
  1.1010 +  static bool return_profiling_enabled();
  1.1011 +
  1.1012 +  // Code generation support
  1.1013 +  static ByteSize cell_count_offset() {
  1.1014 +    return in_ByteSize(cell_count_local_offset() * DataLayout::cell_size);
  1.1015 +  }
  1.1016 +
  1.1017 +  static ByteSize args_data_offset() {
  1.1018 +    return in_ByteSize(header_cell_count() * DataLayout::cell_size);
  1.1019 +  }
  1.1020 +
  1.1021 +  static ByteSize stack_slot_offset(int i) {
  1.1022 +    return in_ByteSize(stack_slot_local_offset(i) * DataLayout::cell_size);
  1.1023 +  }
  1.1024 +
  1.1025 +  static ByteSize argument_type_offset(int i) {
  1.1026 +    return in_ByteSize(argument_type_local_offset(i) * DataLayout::cell_size);
  1.1027 +  }
  1.1028 +
  1.1029 +  static ByteSize return_only_size() {
  1.1030 +    return ReturnTypeEntry::size() + in_ByteSize(header_cell_count() * DataLayout::cell_size);
  1.1031 +  }
  1.1032 +
  1.1033 +};
  1.1034 +
  1.1035 +// CallTypeData
  1.1036 +//
  1.1037 +// A CallTypeData is used to access profiling information about a non
  1.1038 +// virtual call for which we collect type information about arguments
  1.1039 +// and return value.
  1.1040 +class CallTypeData : public CounterData {
  1.1041 +private:
  1.1042 +  // entries for arguments if any
  1.1043 +  TypeStackSlotEntries _args;
  1.1044 +  // entry for return type if any
  1.1045 +  ReturnTypeEntry _ret;
  1.1046 +
  1.1047 +  int cell_count_global_offset() const {
  1.1048 +    return CounterData::static_cell_count() + TypeEntriesAtCall::cell_count_local_offset();
  1.1049 +  }
  1.1050 +
  1.1051 +  // number of cells not counting the header
  1.1052 +  int cell_count_no_header() const {
  1.1053 +    return uint_at(cell_count_global_offset());
  1.1054 +  }
  1.1055 +
  1.1056 +  void check_number_of_arguments(int total) {
  1.1057 +    assert(number_of_arguments() == total, "should be set in DataLayout::initialize");
  1.1058 +  }
  1.1059 +
  1.1060 +public:
  1.1061 +  CallTypeData(DataLayout* layout) :
  1.1062 +    CounterData(layout),
  1.1063 +    _args(CounterData::static_cell_count()+TypeEntriesAtCall::header_cell_count(), number_of_arguments()),
  1.1064 +    _ret(cell_count() - ReturnTypeEntry::static_cell_count())
  1.1065 +  {
  1.1066 +    assert(layout->tag() == DataLayout::call_type_data_tag, "wrong type");
  1.1067 +    // Some compilers (VC++) don't want this passed in member initialization list
  1.1068 +    _args.set_profile_data(this);
  1.1069 +    _ret.set_profile_data(this);
  1.1070 +  }
  1.1071 +
  1.1072 +  const TypeStackSlotEntries* args() const {
  1.1073 +    assert(has_arguments(), "no profiling of arguments");
  1.1074 +    return &_args;
  1.1075 +  }
  1.1076 +
  1.1077 +  const ReturnTypeEntry* ret() const {
  1.1078 +    assert(has_return(), "no profiling of return value");
  1.1079 +    return &_ret;
  1.1080 +  }
  1.1081 +
  1.1082 +  virtual bool is_CallTypeData() const { return true; }
  1.1083 +
  1.1084 +  static int static_cell_count() {
  1.1085 +    return -1;
  1.1086 +  }
  1.1087 +
  1.1088 +  static int compute_cell_count(BytecodeStream* stream) {
  1.1089 +    return CounterData::static_cell_count() + TypeEntriesAtCall::compute_cell_count(stream);
  1.1090 +  }
  1.1091 +
  1.1092 +  static void initialize(DataLayout* dl, int cell_count) {
  1.1093 +    TypeEntriesAtCall::initialize(dl, CounterData::static_cell_count(), cell_count);
  1.1094 +  }
  1.1095 +
  1.1096 +  virtual void post_initialize(BytecodeStream* stream, MethodData* mdo);
  1.1097 +
  1.1098 +  virtual int cell_count() const {
  1.1099 +    return CounterData::static_cell_count() +
  1.1100 +      TypeEntriesAtCall::header_cell_count() +
  1.1101 +      int_at_unchecked(cell_count_global_offset());
  1.1102 +  }
  1.1103 +
  1.1104 +  int number_of_arguments() const {
  1.1105 +    return cell_count_no_header() / TypeStackSlotEntries::per_arg_count();
  1.1106 +  }
  1.1107 +
  1.1108 +  void set_argument_type(int i, Klass* k) {
  1.1109 +    assert(has_arguments(), "no arguments!");
  1.1110 +    intptr_t current = _args.type(i);
  1.1111 +    _args.set_type(i, TypeEntries::with_status(k, current));
  1.1112 +  }
  1.1113 +
  1.1114 +  void set_return_type(Klass* k) {
  1.1115 +    assert(has_return(), "no return!");
  1.1116 +    intptr_t current = _ret.type();
  1.1117 +    _ret.set_type(TypeEntries::with_status(k, current));
  1.1118 +  }
  1.1119 +
  1.1120 +  // An entry for a return value takes less space than an entry for an
  1.1121 +  // argument so if the number of cells exceeds the number of cells
  1.1122 +  // needed for an argument, this object contains type information for
  1.1123 +  // at least one argument.
  1.1124 +  bool has_arguments() const {
  1.1125 +    bool res = cell_count_no_header() >= TypeStackSlotEntries::per_arg_count();
  1.1126 +    assert (!res || TypeEntriesAtCall::arguments_profiling_enabled(), "no profiling of arguments");
  1.1127 +    return res;
  1.1128 +  }
  1.1129 +
  1.1130 +  // An entry for a return value takes less space than an entry for an
  1.1131 +  // argument, so if the remainder of the number of cells divided by
  1.1132 +  // the number of cells for an argument is not null, a return value
  1.1133 +  // is profiled in this object.
  1.1134 +  bool has_return() const {
  1.1135 +    bool res = (cell_count_no_header() % TypeStackSlotEntries::per_arg_count()) != 0;
  1.1136 +    assert (!res || TypeEntriesAtCall::return_profiling_enabled(), "no profiling of return values");
  1.1137 +    return res;
  1.1138 +  }
  1.1139 +
  1.1140 +  // Code generation support
  1.1141 +  static ByteSize args_data_offset() {
  1.1142 +    return cell_offset(CounterData::static_cell_count()) + TypeEntriesAtCall::args_data_offset();
  1.1143 +  }
  1.1144 +
  1.1145 +  // GC support
  1.1146 +  virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
  1.1147 +    if (has_arguments()) {
  1.1148 +      _args.clean_weak_klass_links(is_alive_closure);
  1.1149 +    }
  1.1150 +    if (has_return()) {
  1.1151 +      _ret.clean_weak_klass_links(is_alive_closure);
  1.1152 +    }
  1.1153 +  }
  1.1154 +
  1.1155 +#ifndef PRODUCT
  1.1156 +  virtual void print_data_on(outputStream* st, const char* extra = NULL) const;
  1.1157 +#endif
  1.1158 +};
  1.1159 +
  1.1160 +// ReceiverTypeData
  1.1161 +//
  1.1162 +// A ReceiverTypeData is used to access profiling information about a
  1.1163 +// dynamic type check.  It consists of a counter which counts the total times
  1.1164 +// that the check is reached, and a series of (Klass*, count) pairs
  1.1165 +// which are used to store a type profile for the receiver of the check.
  1.1166 +class ReceiverTypeData : public CounterData {
  1.1167 +protected:
  1.1168 +  enum {
  1.1169 +    receiver0_offset = counter_cell_count,
  1.1170 +    count0_offset,
  1.1171 +    receiver_type_row_cell_count = (count0_offset + 1) - receiver0_offset
  1.1172 +  };
  1.1173 +
  1.1174 +public:
  1.1175 +  ReceiverTypeData(DataLayout* layout) : CounterData(layout) {
  1.1176 +    assert(layout->tag() == DataLayout::receiver_type_data_tag ||
  1.1177 +           layout->tag() == DataLayout::virtual_call_data_tag ||
  1.1178 +           layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
  1.1179 +  }
  1.1180 +
  1.1181 +  virtual bool is_ReceiverTypeData() const { return true; }
  1.1182 +
  1.1183 +  static int static_cell_count() {
  1.1184 +    return counter_cell_count + (uint) TypeProfileWidth * receiver_type_row_cell_count;
  1.1185 +  }
  1.1186 +
  1.1187 +  virtual int cell_count() const {
  1.1188 +    return static_cell_count();
  1.1189 +  }
  1.1190 +
  1.1191 +  // Direct accessors
  1.1192 +  static uint row_limit() {
  1.1193 +    return TypeProfileWidth;
  1.1194 +  }
  1.1195 +  static int receiver_cell_index(uint row) {
  1.1196 +    return receiver0_offset + row * receiver_type_row_cell_count;
  1.1197 +  }
  1.1198 +  static int receiver_count_cell_index(uint row) {
  1.1199 +    return count0_offset + row * receiver_type_row_cell_count;
  1.1200 +  }
  1.1201 +
  1.1202 +  Klass* receiver(uint row) const {
  1.1203 +    assert(row < row_limit(), "oob");
  1.1204 +
  1.1205 +    Klass* recv = (Klass*)intptr_at(receiver_cell_index(row));
  1.1206 +    assert(recv == NULL || recv->is_klass(), "wrong type");
  1.1207 +    return recv;
  1.1208 +  }
  1.1209 +
  1.1210 +  void set_receiver(uint row, Klass* k) {
  1.1211 +    assert((uint)row < row_limit(), "oob");
  1.1212 +    set_intptr_at(receiver_cell_index(row), (uintptr_t)k);
  1.1213 +  }
  1.1214 +
  1.1215 +  uint receiver_count(uint row) const {
  1.1216 +    assert(row < row_limit(), "oob");
  1.1217 +    return uint_at(receiver_count_cell_index(row));
  1.1218 +  }
  1.1219 +
  1.1220 +  void set_receiver_count(uint row, uint count) {
  1.1221 +    assert(row < row_limit(), "oob");
  1.1222 +    set_uint_at(receiver_count_cell_index(row), count);
  1.1223 +  }
  1.1224 +
  1.1225 +  void clear_row(uint row) {
  1.1226 +    assert(row < row_limit(), "oob");
  1.1227 +    // Clear total count - indicator of polymorphic call site.
  1.1228 +    // The site may look like as monomorphic after that but
  1.1229 +    // it allow to have more accurate profiling information because
  1.1230 +    // there was execution phase change since klasses were unloaded.
  1.1231 +    // If the site is still polymorphic then MDO will be updated
  1.1232 +    // to reflect it. But it could be the case that the site becomes
  1.1233 +    // only bimorphic. Then keeping total count not 0 will be wrong.
  1.1234 +    // Even if we use monomorphic (when it is not) for compilation
  1.1235 +    // we will only have trap, deoptimization and recompile again
  1.1236 +    // with updated MDO after executing method in Interpreter.
  1.1237 +    // An additional receiver will be recorded in the cleaned row
  1.1238 +    // during next call execution.
  1.1239 +    //
  1.1240 +    // Note: our profiling logic works with empty rows in any slot.
  1.1241 +    // We do sorting a profiling info (ciCallProfile) for compilation.
  1.1242 +    //
  1.1243 +    set_count(0);
  1.1244 +    set_receiver(row, NULL);
  1.1245 +    set_receiver_count(row, 0);
  1.1246 +  }
  1.1247 +
  1.1248 +  // Code generation support
  1.1249 +  static ByteSize receiver_offset(uint row) {
  1.1250 +    return cell_offset(receiver_cell_index(row));
  1.1251 +  }
  1.1252 +  static ByteSize receiver_count_offset(uint row) {
  1.1253 +    return cell_offset(receiver_count_cell_index(row));
  1.1254 +  }
  1.1255 +  static ByteSize receiver_type_data_size() {
  1.1256 +    return cell_offset(static_cell_count());
  1.1257 +  }
  1.1258 +
  1.1259 +  // GC support
  1.1260 +  virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
  1.1261 +
  1.1262 +#ifdef CC_INTERP
  1.1263 +  static int receiver_type_data_size_in_bytes() {
  1.1264 +    return cell_offset_in_bytes(static_cell_count());
  1.1265 +  }
  1.1266 +
  1.1267 +  static Klass *receiver_unchecked(DataLayout* layout, uint row) {
  1.1268 +    Klass* recv = (Klass*)layout->cell_at(receiver_cell_index(row));
  1.1269 +    return recv;
  1.1270 +  }
  1.1271 +
  1.1272 +  static void increment_receiver_count_no_overflow(DataLayout* layout, Klass *rcvr) {
  1.1273 +    const int num_rows = row_limit();
  1.1274 +    // Receiver already exists?
  1.1275 +    for (int row = 0; row < num_rows; row++) {
  1.1276 +      if (receiver_unchecked(layout, row) == rcvr) {
  1.1277 +        increment_uint_at_no_overflow(layout, receiver_count_cell_index(row));
  1.1278 +        return;
  1.1279 +      }
  1.1280 +    }
  1.1281 +    // New receiver, find a free slot.
  1.1282 +    for (int row = 0; row < num_rows; row++) {
  1.1283 +      if (receiver_unchecked(layout, row) == NULL) {
  1.1284 +        set_intptr_at(layout, receiver_cell_index(row), (intptr_t)rcvr);
  1.1285 +        increment_uint_at_no_overflow(layout, receiver_count_cell_index(row));
  1.1286 +        return;
  1.1287 +      }
  1.1288 +    }
  1.1289 +    // Receiver did not match any saved receiver and there is no empty row for it.
  1.1290 +    // Increment total counter to indicate polymorphic case.
  1.1291 +    increment_count_no_overflow(layout);
  1.1292 +  }
  1.1293 +
  1.1294 +  static DataLayout* advance(DataLayout* layout) {
  1.1295 +    return (DataLayout*) (((address)layout) + (ssize_t)ReceiverTypeData::receiver_type_data_size_in_bytes());
  1.1296 +  }
  1.1297 +#endif // CC_INTERP
  1.1298 +
  1.1299 +#ifndef PRODUCT
  1.1300 +  void print_receiver_data_on(outputStream* st) const;
  1.1301 +  void print_data_on(outputStream* st, const char* extra = NULL) const;
  1.1302 +#endif
  1.1303 +};
  1.1304 +
  1.1305 +// VirtualCallData
  1.1306 +//
  1.1307 +// A VirtualCallData is used to access profiling information about a
  1.1308 +// virtual call.  For now, it has nothing more than a ReceiverTypeData.
  1.1309 +class VirtualCallData : public ReceiverTypeData {
  1.1310 +public:
  1.1311 +  VirtualCallData(DataLayout* layout) : ReceiverTypeData(layout) {
  1.1312 +    assert(layout->tag() == DataLayout::virtual_call_data_tag ||
  1.1313 +           layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
  1.1314 +  }
  1.1315 +
  1.1316 +  virtual bool is_VirtualCallData() const { return true; }
  1.1317 +
  1.1318 +  static int static_cell_count() {
  1.1319 +    // At this point we could add more profile state, e.g., for arguments.
  1.1320 +    // But for now it's the same size as the base record type.
  1.1321 +    return ReceiverTypeData::static_cell_count();
  1.1322 +  }
  1.1323 +
  1.1324 +  virtual int cell_count() const {
  1.1325 +    return static_cell_count();
  1.1326 +  }
  1.1327 +
  1.1328 +  // Direct accessors
  1.1329 +  static ByteSize virtual_call_data_size() {
  1.1330 +    return cell_offset(static_cell_count());
  1.1331 +  }
  1.1332 +
  1.1333 +#ifdef CC_INTERP
  1.1334 +  static int virtual_call_data_size_in_bytes() {
  1.1335 +    return cell_offset_in_bytes(static_cell_count());
  1.1336 +  }
  1.1337 +
  1.1338 +  static DataLayout* advance(DataLayout* layout) {
  1.1339 +    return (DataLayout*) (((address)layout) + (ssize_t)VirtualCallData::virtual_call_data_size_in_bytes());
  1.1340 +  }
  1.1341 +#endif // CC_INTERP
  1.1342 +
  1.1343 +#ifndef PRODUCT
  1.1344 +  void print_data_on(outputStream* st, const char* extra = NULL) const;
  1.1345 +#endif
  1.1346 +};
  1.1347 +
  1.1348 +// VirtualCallTypeData
  1.1349 +//
  1.1350 +// A VirtualCallTypeData is used to access profiling information about
  1.1351 +// a virtual call for which we collect type information about
  1.1352 +// arguments and return value.
  1.1353 +class VirtualCallTypeData : public VirtualCallData {
  1.1354 +private:
  1.1355 +  // entries for arguments if any
  1.1356 +  TypeStackSlotEntries _args;
  1.1357 +  // entry for return type if any
  1.1358 +  ReturnTypeEntry _ret;
  1.1359 +
  1.1360 +  int cell_count_global_offset() const {
  1.1361 +    return VirtualCallData::static_cell_count() + TypeEntriesAtCall::cell_count_local_offset();
  1.1362 +  }
  1.1363 +
  1.1364 +  // number of cells not counting the header
  1.1365 +  int cell_count_no_header() const {
  1.1366 +    return uint_at(cell_count_global_offset());
  1.1367 +  }
  1.1368 +
  1.1369 +  void check_number_of_arguments(int total) {
  1.1370 +    assert(number_of_arguments() == total, "should be set in DataLayout::initialize");
  1.1371 +  }
  1.1372 +
  1.1373 +public:
  1.1374 +  VirtualCallTypeData(DataLayout* layout) :
  1.1375 +    VirtualCallData(layout),
  1.1376 +    _args(VirtualCallData::static_cell_count()+TypeEntriesAtCall::header_cell_count(), number_of_arguments()),
  1.1377 +    _ret(cell_count() - ReturnTypeEntry::static_cell_count())
  1.1378 +  {
  1.1379 +    assert(layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
  1.1380 +    // Some compilers (VC++) don't want this passed in member initialization list
  1.1381 +    _args.set_profile_data(this);
  1.1382 +    _ret.set_profile_data(this);
  1.1383 +  }
  1.1384 +
  1.1385 +  const TypeStackSlotEntries* args() const {
  1.1386 +    assert(has_arguments(), "no profiling of arguments");
  1.1387 +    return &_args;
  1.1388 +  }
  1.1389 +
  1.1390 +  const ReturnTypeEntry* ret() const {
  1.1391 +    assert(has_return(), "no profiling of return value");
  1.1392 +    return &_ret;
  1.1393 +  }
  1.1394 +
  1.1395 +  virtual bool is_VirtualCallTypeData() const { return true; }
  1.1396 +
  1.1397 +  static int static_cell_count() {
  1.1398 +    return -1;
  1.1399 +  }
  1.1400 +
  1.1401 +  static int compute_cell_count(BytecodeStream* stream) {
  1.1402 +    return VirtualCallData::static_cell_count() + TypeEntriesAtCall::compute_cell_count(stream);
  1.1403 +  }
  1.1404 +
  1.1405 +  static void initialize(DataLayout* dl, int cell_count) {
  1.1406 +    TypeEntriesAtCall::initialize(dl, VirtualCallData::static_cell_count(), cell_count);
  1.1407 +  }
  1.1408 +
  1.1409 +  virtual void post_initialize(BytecodeStream* stream, MethodData* mdo);
  1.1410 +
  1.1411 +  virtual int cell_count() const {
  1.1412 +    return VirtualCallData::static_cell_count() +
  1.1413 +      TypeEntriesAtCall::header_cell_count() +
  1.1414 +      int_at_unchecked(cell_count_global_offset());
  1.1415 +  }
  1.1416 +
  1.1417 +  int number_of_arguments() const {
  1.1418 +    return cell_count_no_header() / TypeStackSlotEntries::per_arg_count();
  1.1419 +  }
  1.1420 +
  1.1421 +  void set_argument_type(int i, Klass* k) {
  1.1422 +    assert(has_arguments(), "no arguments!");
  1.1423 +    intptr_t current = _args.type(i);
  1.1424 +    _args.set_type(i, TypeEntries::with_status(k, current));
  1.1425 +  }
  1.1426 +
  1.1427 +  void set_return_type(Klass* k) {
  1.1428 +    assert(has_return(), "no return!");
  1.1429 +    intptr_t current = _ret.type();
  1.1430 +    _ret.set_type(TypeEntries::with_status(k, current));
  1.1431 +  }
  1.1432 +
  1.1433 +  // An entry for a return value takes less space than an entry for an
  1.1434 +  // argument, so if the remainder of the number of cells divided by
  1.1435 +  // the number of cells for an argument is not null, a return value
  1.1436 +  // is profiled in this object.
  1.1437 +  bool has_return() const {
  1.1438 +    bool res = (cell_count_no_header() % TypeStackSlotEntries::per_arg_count()) != 0;
  1.1439 +    assert (!res || TypeEntriesAtCall::return_profiling_enabled(), "no profiling of return values");
  1.1440 +    return res;
  1.1441 +  }
  1.1442 +
  1.1443 +  // An entry for a return value takes less space than an entry for an
  1.1444 +  // argument so if the number of cells exceeds the number of cells
  1.1445 +  // needed for an argument, this object contains type information for
  1.1446 +  // at least one argument.
  1.1447 +  bool has_arguments() const {
  1.1448 +    bool res = cell_count_no_header() >= TypeStackSlotEntries::per_arg_count();
  1.1449 +    assert (!res || TypeEntriesAtCall::arguments_profiling_enabled(), "no profiling of arguments");
  1.1450 +    return res;
  1.1451 +  }
  1.1452 +
  1.1453 +  // Code generation support
  1.1454 +  static ByteSize args_data_offset() {
  1.1455 +    return cell_offset(VirtualCallData::static_cell_count()) + TypeEntriesAtCall::args_data_offset();
  1.1456 +  }
  1.1457 +
  1.1458 +  // GC support
  1.1459 +  virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
  1.1460 +    ReceiverTypeData::clean_weak_klass_links(is_alive_closure);
  1.1461 +    if (has_arguments()) {
  1.1462 +      _args.clean_weak_klass_links(is_alive_closure);
  1.1463 +    }
  1.1464 +    if (has_return()) {
  1.1465 +      _ret.clean_weak_klass_links(is_alive_closure);
  1.1466 +    }
  1.1467 +  }
  1.1468 +
  1.1469 +#ifndef PRODUCT
  1.1470 +  virtual void print_data_on(outputStream* st, const char* extra = NULL) const;
  1.1471 +#endif
  1.1472 +};
  1.1473 +
  1.1474 +// RetData
  1.1475 +//
  1.1476 +// A RetData is used to access profiling information for a ret bytecode.
  1.1477 +// It is composed of a count of the number of times that the ret has
  1.1478 +// been executed, followed by a series of triples of the form
  1.1479 +// (bci, count, di) which count the number of times that some bci was the
  1.1480 +// target of the ret and cache a corresponding data displacement.
  1.1481 +class RetData : public CounterData {
  1.1482 +protected:
  1.1483 +  enum {
  1.1484 +    bci0_offset = counter_cell_count,
  1.1485 +    count0_offset,
  1.1486 +    displacement0_offset,
  1.1487 +    ret_row_cell_count = (displacement0_offset + 1) - bci0_offset
  1.1488 +  };
  1.1489 +
  1.1490 +  void set_bci(uint row, int bci) {
  1.1491 +    assert((uint)row < row_limit(), "oob");
  1.1492 +    set_int_at(bci0_offset + row * ret_row_cell_count, bci);
  1.1493 +  }
  1.1494 +  void release_set_bci(uint row, int bci) {
  1.1495 +    assert((uint)row < row_limit(), "oob");
  1.1496 +    // 'release' when setting the bci acts as a valid flag for other
  1.1497 +    // threads wrt bci_count and bci_displacement.
  1.1498 +    release_set_int_at(bci0_offset + row * ret_row_cell_count, bci);
  1.1499 +  }
  1.1500 +  void set_bci_count(uint row, uint count) {
  1.1501 +    assert((uint)row < row_limit(), "oob");
  1.1502 +    set_uint_at(count0_offset + row * ret_row_cell_count, count);
  1.1503 +  }
  1.1504 +  void set_bci_displacement(uint row, int disp) {
  1.1505 +    set_int_at(displacement0_offset + row * ret_row_cell_count, disp);
  1.1506 +  }
  1.1507 +
  1.1508 +public:
  1.1509 +  RetData(DataLayout* layout) : CounterData(layout) {
  1.1510 +    assert(layout->tag() == DataLayout::ret_data_tag, "wrong type");
  1.1511 +  }
  1.1512 +
  1.1513 +  virtual bool is_RetData() const { return true; }
  1.1514 +
  1.1515 +  enum {
  1.1516 +    no_bci = -1 // value of bci when bci1/2 are not in use.
  1.1517 +  };
  1.1518 +
  1.1519 +  static int static_cell_count() {
  1.1520 +    return counter_cell_count + (uint) BciProfileWidth * ret_row_cell_count;
  1.1521 +  }
  1.1522 +
  1.1523 +  virtual int cell_count() const {
  1.1524 +    return static_cell_count();
  1.1525 +  }
  1.1526 +
  1.1527 +  static uint row_limit() {
  1.1528 +    return BciProfileWidth;
  1.1529 +  }
  1.1530 +  static int bci_cell_index(uint row) {
  1.1531 +    return bci0_offset + row * ret_row_cell_count;
  1.1532 +  }
  1.1533 +  static int bci_count_cell_index(uint row) {
  1.1534 +    return count0_offset + row * ret_row_cell_count;
  1.1535 +  }
  1.1536 +  static int bci_displacement_cell_index(uint row) {
  1.1537 +    return displacement0_offset + row * ret_row_cell_count;
  1.1538 +  }
  1.1539 +
  1.1540 +  // Direct accessors
  1.1541 +  int bci(uint row) const {
  1.1542 +    return int_at(bci_cell_index(row));
  1.1543 +  }
  1.1544 +  uint bci_count(uint row) const {
  1.1545 +    return uint_at(bci_count_cell_index(row));
  1.1546 +  }
  1.1547 +  int bci_displacement(uint row) const {
  1.1548 +    return int_at(bci_displacement_cell_index(row));
  1.1549 +  }
  1.1550 +
  1.1551 +  // Interpreter Runtime support
  1.1552 +  address fixup_ret(int return_bci, MethodData* mdo);
  1.1553 +
  1.1554 +  // Code generation support
  1.1555 +  static ByteSize bci_offset(uint row) {
  1.1556 +    return cell_offset(bci_cell_index(row));
  1.1557 +  }
  1.1558 +  static ByteSize bci_count_offset(uint row) {
  1.1559 +    return cell_offset(bci_count_cell_index(row));
  1.1560 +  }
  1.1561 +  static ByteSize bci_displacement_offset(uint row) {
  1.1562 +    return cell_offset(bci_displacement_cell_index(row));
  1.1563 +  }
  1.1564 +
  1.1565 +#ifdef CC_INTERP
  1.1566 +  static DataLayout* advance(MethodData *md, int bci);
  1.1567 +#endif // CC_INTERP
  1.1568 +
  1.1569 +  // Specific initialization.
  1.1570 +  void post_initialize(BytecodeStream* stream, MethodData* mdo);
  1.1571 +
  1.1572 +#ifndef PRODUCT
  1.1573 +  void print_data_on(outputStream* st, const char* extra = NULL) const;
  1.1574 +#endif
  1.1575 +};
  1.1576 +
  1.1577 +// BranchData
  1.1578 +//
  1.1579 +// A BranchData is used to access profiling data for a two-way branch.
  1.1580 +// It consists of taken and not_taken counts as well as a data displacement
  1.1581 +// for the taken case.
  1.1582 +class BranchData : public JumpData {
  1.1583 +protected:
  1.1584 +  enum {
  1.1585 +    not_taken_off_set = jump_cell_count,
  1.1586 +    branch_cell_count
  1.1587 +  };
  1.1588 +
  1.1589 +  void set_displacement(int displacement) {
  1.1590 +    set_int_at(displacement_off_set, displacement);
  1.1591 +  }
  1.1592 +
  1.1593 +public:
  1.1594 +  BranchData(DataLayout* layout) : JumpData(layout) {
  1.1595 +    assert(layout->tag() == DataLayout::branch_data_tag, "wrong type");
  1.1596 +  }
  1.1597 +
  1.1598 +  virtual bool is_BranchData() const { return true; }
  1.1599 +
  1.1600 +  static int static_cell_count() {
  1.1601 +    return branch_cell_count;
  1.1602 +  }
  1.1603 +
  1.1604 +  virtual int cell_count() const {
  1.1605 +    return static_cell_count();
  1.1606 +  }
  1.1607 +
  1.1608 +  // Direct accessor
  1.1609 +  uint not_taken() const {
  1.1610 +    return uint_at(not_taken_off_set);
  1.1611 +  }
  1.1612 +
  1.1613 +  void set_not_taken(uint cnt) {
  1.1614 +    set_uint_at(not_taken_off_set, cnt);
  1.1615 +  }
  1.1616 +
  1.1617 +  uint inc_not_taken() {
  1.1618 +    uint cnt = not_taken() + 1;
  1.1619 +    // Did we wrap? Will compiler screw us??
  1.1620 +    if (cnt == 0) cnt--;
  1.1621 +    set_uint_at(not_taken_off_set, cnt);
  1.1622 +    return cnt;
  1.1623 +  }
  1.1624 +
  1.1625 +  // Code generation support
  1.1626 +  static ByteSize not_taken_offset() {
  1.1627 +    return cell_offset(not_taken_off_set);
  1.1628 +  }
  1.1629 +  static ByteSize branch_data_size() {
  1.1630 +    return cell_offset(branch_cell_count);
  1.1631 +  }
  1.1632 +
  1.1633 +#ifdef CC_INTERP
  1.1634 +  static int branch_data_size_in_bytes() {
  1.1635 +    return cell_offset_in_bytes(branch_cell_count);
  1.1636 +  }
  1.1637 +
  1.1638 +  static void increment_not_taken_count_no_overflow(DataLayout* layout) {
  1.1639 +    increment_uint_at_no_overflow(layout, not_taken_off_set);
  1.1640 +  }
  1.1641 +
  1.1642 +  static DataLayout* advance_not_taken(DataLayout* layout) {
  1.1643 +    return (DataLayout*) (((address)layout) + (ssize_t)BranchData::branch_data_size_in_bytes());
  1.1644 +  }
  1.1645 +#endif // CC_INTERP
  1.1646 +
  1.1647 +  // Specific initialization.
  1.1648 +  void post_initialize(BytecodeStream* stream, MethodData* mdo);
  1.1649 +
  1.1650 +#ifndef PRODUCT
  1.1651 +  void print_data_on(outputStream* st, const char* extra = NULL) const;
  1.1652 +#endif
  1.1653 +};
  1.1654 +
  1.1655 +// ArrayData
  1.1656 +//
  1.1657 +// A ArrayData is a base class for accessing profiling data which does
  1.1658 +// not have a statically known size.  It consists of an array length
  1.1659 +// and an array start.
  1.1660 +class ArrayData : public ProfileData {
  1.1661 +protected:
  1.1662 +  friend class DataLayout;
  1.1663 +
  1.1664 +  enum {
  1.1665 +    array_len_off_set,
  1.1666 +    array_start_off_set
  1.1667 +  };
  1.1668 +
  1.1669 +  uint array_uint_at(int index) const {
  1.1670 +    int aindex = index + array_start_off_set;
  1.1671 +    return uint_at(aindex);
  1.1672 +  }
  1.1673 +  int array_int_at(int index) const {
  1.1674 +    int aindex = index + array_start_off_set;
  1.1675 +    return int_at(aindex);
  1.1676 +  }
  1.1677 +  oop array_oop_at(int index) const {
  1.1678 +    int aindex = index + array_start_off_set;
  1.1679 +    return oop_at(aindex);
  1.1680 +  }
  1.1681 +  void array_set_int_at(int index, int value) {
  1.1682 +    int aindex = index + array_start_off_set;
  1.1683 +    set_int_at(aindex, value);
  1.1684 +  }
  1.1685 +
  1.1686 +#ifdef CC_INTERP
  1.1687 +  // Static low level accessors for DataLayout with ArrayData's semantics.
  1.1688 +
  1.1689 +  static void increment_array_uint_at_no_overflow(DataLayout* layout, int index) {
  1.1690 +    int aindex = index + array_start_off_set;
  1.1691 +    increment_uint_at_no_overflow(layout, aindex);
  1.1692 +  }
  1.1693 +
  1.1694 +  static int array_int_at(DataLayout* layout, int index) {
  1.1695 +    int aindex = index + array_start_off_set;
  1.1696 +    return int_at(layout, aindex);
  1.1697 +  }
  1.1698 +#endif // CC_INTERP
  1.1699 +
  1.1700 +  // Code generation support for subclasses.
  1.1701 +  static ByteSize array_element_offset(int index) {
  1.1702 +    return cell_offset(array_start_off_set + index);
  1.1703 +  }
  1.1704 +
  1.1705 +public:
  1.1706 +  ArrayData(DataLayout* layout) : ProfileData(layout) {}
  1.1707 +
  1.1708 +  virtual bool is_ArrayData() const { return true; }
  1.1709 +
  1.1710 +  static int static_cell_count() {
  1.1711 +    return -1;
  1.1712 +  }
  1.1713 +
  1.1714 +  int array_len() const {
  1.1715 +    return int_at_unchecked(array_len_off_set);
  1.1716 +  }
  1.1717 +
  1.1718 +  virtual int cell_count() const {
  1.1719 +    return array_len() + 1;
  1.1720 +  }
  1.1721 +
  1.1722 +  // Code generation support
  1.1723 +  static ByteSize array_len_offset() {
  1.1724 +    return cell_offset(array_len_off_set);
  1.1725 +  }
  1.1726 +  static ByteSize array_start_offset() {
  1.1727 +    return cell_offset(array_start_off_set);
  1.1728 +  }
  1.1729 +};
  1.1730 +
  1.1731 +// MultiBranchData
  1.1732 +//
  1.1733 +// A MultiBranchData is used to access profiling information for
  1.1734 +// a multi-way branch (*switch bytecodes).  It consists of a series
  1.1735 +// of (count, displacement) pairs, which count the number of times each
  1.1736 +// case was taken and specify the data displacment for each branch target.
  1.1737 +class MultiBranchData : public ArrayData {
  1.1738 +protected:
  1.1739 +  enum {
  1.1740 +    default_count_off_set,
  1.1741 +    default_disaplacement_off_set,
  1.1742 +    case_array_start
  1.1743 +  };
  1.1744 +  enum {
  1.1745 +    relative_count_off_set,
  1.1746 +    relative_displacement_off_set,
  1.1747 +    per_case_cell_count
  1.1748 +  };
  1.1749 +
  1.1750 +  void set_default_displacement(int displacement) {
  1.1751 +    array_set_int_at(default_disaplacement_off_set, displacement);
  1.1752 +  }
  1.1753 +  void set_displacement_at(int index, int displacement) {
  1.1754 +    array_set_int_at(case_array_start +
  1.1755 +                     index * per_case_cell_count +
  1.1756 +                     relative_displacement_off_set,
  1.1757 +                     displacement);
  1.1758 +  }
  1.1759 +
  1.1760 +public:
  1.1761 +  MultiBranchData(DataLayout* layout) : ArrayData(layout) {
  1.1762 +    assert(layout->tag() == DataLayout::multi_branch_data_tag, "wrong type");
  1.1763 +  }
  1.1764 +
  1.1765 +  virtual bool is_MultiBranchData() const { return true; }
  1.1766 +
  1.1767 +  static int compute_cell_count(BytecodeStream* stream);
  1.1768 +
  1.1769 +  int number_of_cases() const {
  1.1770 +    int alen = array_len() - 2; // get rid of default case here.
  1.1771 +    assert(alen % per_case_cell_count == 0, "must be even");
  1.1772 +    return (alen / per_case_cell_count);
  1.1773 +  }
  1.1774 +
  1.1775 +  uint default_count() const {
  1.1776 +    return array_uint_at(default_count_off_set);
  1.1777 +  }
  1.1778 +  int default_displacement() const {
  1.1779 +    return array_int_at(default_disaplacement_off_set);
  1.1780 +  }
  1.1781 +
  1.1782 +  uint count_at(int index) const {
  1.1783 +    return array_uint_at(case_array_start +
  1.1784 +                         index * per_case_cell_count +
  1.1785 +                         relative_count_off_set);
  1.1786 +  }
  1.1787 +  int displacement_at(int index) const {
  1.1788 +    return array_int_at(case_array_start +
  1.1789 +                        index * per_case_cell_count +
  1.1790 +                        relative_displacement_off_set);
  1.1791 +  }
  1.1792 +
  1.1793 +  // Code generation support
  1.1794 +  static ByteSize default_count_offset() {
  1.1795 +    return array_element_offset(default_count_off_set);
  1.1796 +  }
  1.1797 +  static ByteSize default_displacement_offset() {
  1.1798 +    return array_element_offset(default_disaplacement_off_set);
  1.1799 +  }
  1.1800 +  static ByteSize case_count_offset(int index) {
  1.1801 +    return case_array_offset() +
  1.1802 +           (per_case_size() * index) +
  1.1803 +           relative_count_offset();
  1.1804 +  }
  1.1805 +  static ByteSize case_array_offset() {
  1.1806 +    return array_element_offset(case_array_start);
  1.1807 +  }
  1.1808 +  static ByteSize per_case_size() {
  1.1809 +    return in_ByteSize(per_case_cell_count) * cell_size;
  1.1810 +  }
  1.1811 +  static ByteSize relative_count_offset() {
  1.1812 +    return in_ByteSize(relative_count_off_set) * cell_size;
  1.1813 +  }
  1.1814 +  static ByteSize relative_displacement_offset() {
  1.1815 +    return in_ByteSize(relative_displacement_off_set) * cell_size;
  1.1816 +  }
  1.1817 +
  1.1818 +#ifdef CC_INTERP
  1.1819 +  static void increment_count_no_overflow(DataLayout* layout, int index) {
  1.1820 +    if (index == -1) {
  1.1821 +      increment_array_uint_at_no_overflow(layout, default_count_off_set);
  1.1822 +    } else {
  1.1823 +      increment_array_uint_at_no_overflow(layout, case_array_start +
  1.1824 +                                                  index * per_case_cell_count +
  1.1825 +                                                  relative_count_off_set);
  1.1826 +    }
  1.1827 +  }
  1.1828 +
  1.1829 +  static DataLayout* advance(DataLayout* layout, int index) {
  1.1830 +    if (index == -1) {
  1.1831 +      return (DataLayout*) (((address)layout) + (ssize_t)array_int_at(layout, default_disaplacement_off_set));
  1.1832 +    } else {
  1.1833 +      return (DataLayout*) (((address)layout) + (ssize_t)array_int_at(layout, case_array_start +
  1.1834 +                                                                              index * per_case_cell_count +
  1.1835 +                                                                              relative_displacement_off_set));
  1.1836 +    }
  1.1837 +  }
  1.1838 +#endif // CC_INTERP
  1.1839 +
  1.1840 +  // Specific initialization.
  1.1841 +  void post_initialize(BytecodeStream* stream, MethodData* mdo);
  1.1842 +
  1.1843 +#ifndef PRODUCT
  1.1844 +  void print_data_on(outputStream* st, const char* extra = NULL) const;
  1.1845 +#endif
  1.1846 +};
  1.1847 +
  1.1848 +class ArgInfoData : public ArrayData {
  1.1849 +
  1.1850 +public:
  1.1851 +  ArgInfoData(DataLayout* layout) : ArrayData(layout) {
  1.1852 +    assert(layout->tag() == DataLayout::arg_info_data_tag, "wrong type");
  1.1853 +  }
  1.1854 +
  1.1855 +  virtual bool is_ArgInfoData() const { return true; }
  1.1856 +
  1.1857 +
  1.1858 +  int number_of_args() const {
  1.1859 +    return array_len();
  1.1860 +  }
  1.1861 +
  1.1862 +  uint arg_modified(int arg) const {
  1.1863 +    return array_uint_at(arg);
  1.1864 +  }
  1.1865 +
  1.1866 +  void set_arg_modified(int arg, uint val) {
  1.1867 +    array_set_int_at(arg, val);
  1.1868 +  }
  1.1869 +
  1.1870 +#ifndef PRODUCT
  1.1871 +  void print_data_on(outputStream* st, const char* extra = NULL) const;
  1.1872 +#endif
  1.1873 +};
  1.1874 +
  1.1875 +// ParametersTypeData
  1.1876 +//
  1.1877 +// A ParametersTypeData is used to access profiling information about
  1.1878 +// types of parameters to a method
  1.1879 +class ParametersTypeData : public ArrayData {
  1.1880 +
  1.1881 +private:
  1.1882 +  TypeStackSlotEntries _parameters;
  1.1883 +
  1.1884 +  static int stack_slot_local_offset(int i) {
  1.1885 +    assert_profiling_enabled();
  1.1886 +    return array_start_off_set + TypeStackSlotEntries::stack_slot_local_offset(i);
  1.1887 +  }
  1.1888 +
  1.1889 +  static int type_local_offset(int i) {
  1.1890 +    assert_profiling_enabled();
  1.1891 +    return array_start_off_set + TypeStackSlotEntries::type_local_offset(i);
  1.1892 +  }
  1.1893 +
  1.1894 +  static bool profiling_enabled();
  1.1895 +  static void assert_profiling_enabled() {
  1.1896 +    assert(profiling_enabled(), "method parameters profiling should be on");
  1.1897 +  }
  1.1898 +
  1.1899 +public:
  1.1900 +  ParametersTypeData(DataLayout* layout) : ArrayData(layout), _parameters(1, number_of_parameters()) {
  1.1901 +    assert(layout->tag() == DataLayout::parameters_type_data_tag, "wrong type");
  1.1902 +    // Some compilers (VC++) don't want this passed in member initialization list
  1.1903 +    _parameters.set_profile_data(this);
  1.1904 +  }
  1.1905 +
  1.1906 +  static int compute_cell_count(Method* m);
  1.1907 +
  1.1908 +  virtual bool is_ParametersTypeData() const { return true; }
  1.1909 +
  1.1910 +  virtual void post_initialize(BytecodeStream* stream, MethodData* mdo);
  1.1911 +
  1.1912 +  int number_of_parameters() const {
  1.1913 +    return array_len() / TypeStackSlotEntries::per_arg_count();
  1.1914 +  }
  1.1915 +
  1.1916 +  const TypeStackSlotEntries* parameters() const { return &_parameters; }
  1.1917 +
  1.1918 +  uint stack_slot(int i) const {
  1.1919 +    return _parameters.stack_slot(i);
  1.1920 +  }
  1.1921 +
  1.1922 +  void set_type(int i, Klass* k) {
  1.1923 +    intptr_t current = _parameters.type(i);
  1.1924 +    _parameters.set_type(i, TypeEntries::with_status((intptr_t)k, current));
  1.1925 +  }
  1.1926 +
  1.1927 +  virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
  1.1928 +    _parameters.clean_weak_klass_links(is_alive_closure);
  1.1929 +  }
  1.1930 +
  1.1931 +#ifndef PRODUCT
  1.1932 +  virtual void print_data_on(outputStream* st, const char* extra = NULL) const;
  1.1933 +#endif
  1.1934 +
  1.1935 +  static ByteSize stack_slot_offset(int i) {
  1.1936 +    return cell_offset(stack_slot_local_offset(i));
  1.1937 +  }
  1.1938 +
  1.1939 +  static ByteSize type_offset(int i) {
  1.1940 +    return cell_offset(type_local_offset(i));
  1.1941 +  }
  1.1942 +};
  1.1943 +
  1.1944 +// SpeculativeTrapData
  1.1945 +//
  1.1946 +// A SpeculativeTrapData is used to record traps due to type
  1.1947 +// speculation. It records the root of the compilation: that type
  1.1948 +// speculation is wrong in the context of one compilation (for
  1.1949 +// method1) doesn't mean it's wrong in the context of another one (for
  1.1950 +// method2). Type speculation could have more/different data in the
  1.1951 +// context of the compilation of method2 and it's worthwhile to try an
  1.1952 +// optimization that failed for compilation of method1 in the context
  1.1953 +// of compilation of method2.
  1.1954 +// Space for SpeculativeTrapData entries is allocated from the extra
  1.1955 +// data space in the MDO. If we run out of space, the trap data for
  1.1956 +// the ProfileData at that bci is updated.
  1.1957 +class SpeculativeTrapData : public ProfileData {
  1.1958 +protected:
  1.1959 +  enum {
  1.1960 +    method_offset,
  1.1961 +    speculative_trap_cell_count
  1.1962 +  };
  1.1963 +public:
  1.1964 +  SpeculativeTrapData(DataLayout* layout) : ProfileData(layout) {
  1.1965 +    assert(layout->tag() == DataLayout::speculative_trap_data_tag, "wrong type");
  1.1966 +  }
  1.1967 +
  1.1968 +  virtual bool is_SpeculativeTrapData() const { return true; }
  1.1969 +
  1.1970 +  static int static_cell_count() {
  1.1971 +    return speculative_trap_cell_count;
  1.1972 +  }
  1.1973 +
  1.1974 +  virtual int cell_count() const {
  1.1975 +    return static_cell_count();
  1.1976 +  }
  1.1977 +
  1.1978 +  // Direct accessor
  1.1979 +  Method* method() const {
  1.1980 +    return (Method*)intptr_at(method_offset);
  1.1981 +  }
  1.1982 +
  1.1983 +  void set_method(Method* m) {
  1.1984 +    set_intptr_at(method_offset, (intptr_t)m);
  1.1985 +  }
  1.1986 +
  1.1987 +#ifndef PRODUCT
  1.1988 +  virtual void print_data_on(outputStream* st, const char* extra = NULL) const;
  1.1989 +#endif
  1.1990 +};
  1.1991 +
  1.1992 +// MethodData*
  1.1993 +//
  1.1994 +// A MethodData* holds information which has been collected about
  1.1995 +// a method.  Its layout looks like this:
  1.1996 +//
  1.1997 +// -----------------------------
  1.1998 +// | header                    |
  1.1999 +// | klass                     |
  1.2000 +// -----------------------------
  1.2001 +// | method                    |
  1.2002 +// | size of the MethodData* |
  1.2003 +// -----------------------------
  1.2004 +// | Data entries...           |
  1.2005 +// |   (variable size)         |
  1.2006 +// |                           |
  1.2007 +// .                           .
  1.2008 +// .                           .
  1.2009 +// .                           .
  1.2010 +// |                           |
  1.2011 +// -----------------------------
  1.2012 +//
  1.2013 +// The data entry area is a heterogeneous array of DataLayouts. Each
  1.2014 +// DataLayout in the array corresponds to a specific bytecode in the
  1.2015 +// method.  The entries in the array are sorted by the corresponding
  1.2016 +// bytecode.  Access to the data is via resource-allocated ProfileData,
  1.2017 +// which point to the underlying blocks of DataLayout structures.
  1.2018 +//
  1.2019 +// During interpretation, if profiling in enabled, the interpreter
  1.2020 +// maintains a method data pointer (mdp), which points at the entry
  1.2021 +// in the array corresponding to the current bci.  In the course of
  1.2022 +// intepretation, when a bytecode is encountered that has profile data
  1.2023 +// associated with it, the entry pointed to by mdp is updated, then the
  1.2024 +// mdp is adjusted to point to the next appropriate DataLayout.  If mdp
  1.2025 +// is NULL to begin with, the interpreter assumes that the current method
  1.2026 +// is not (yet) being profiled.
  1.2027 +//
  1.2028 +// In MethodData* parlance, "dp" is a "data pointer", the actual address
  1.2029 +// of a DataLayout element.  A "di" is a "data index", the offset in bytes
  1.2030 +// from the base of the data entry array.  A "displacement" is the byte offset
  1.2031 +// in certain ProfileData objects that indicate the amount the mdp must be
  1.2032 +// adjusted in the event of a change in control flow.
  1.2033 +//
  1.2034 +
  1.2035 +CC_INTERP_ONLY(class BytecodeInterpreter;)
  1.2036 +
  1.2037 +class MethodData : public Metadata {
  1.2038 +  friend class VMStructs;
  1.2039 +  CC_INTERP_ONLY(friend class BytecodeInterpreter;)
  1.2040 +private:
  1.2041 +  friend class ProfileData;
  1.2042 +
  1.2043 +  // Back pointer to the Method*
  1.2044 +  Method* _method;
  1.2045 +
  1.2046 +  // Size of this oop in bytes
  1.2047 +  int _size;
  1.2048 +
  1.2049 +  // Cached hint for bci_to_dp and bci_to_data
  1.2050 +  int _hint_di;
  1.2051 +
  1.2052 +  Mutex _extra_data_lock;
  1.2053 +
  1.2054 +  MethodData(methodHandle method, int size, TRAPS);
  1.2055 +public:
  1.2056 +  static MethodData* allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS);
  1.2057 +  MethodData() : _extra_data_lock(Monitor::leaf, "MDO extra data lock") {}; // For ciMethodData
  1.2058 +
  1.2059 +  bool is_methodData() const volatile { return true; }
  1.2060 +
  1.2061 +  // Whole-method sticky bits and flags
  1.2062 +  enum {
  1.2063 +    _trap_hist_limit    = 19,   // decoupled from Deoptimization::Reason_LIMIT
  1.2064 +    _trap_hist_mask     = max_jubyte,
  1.2065 +    _extra_data_count   = 4     // extra DataLayout headers, for trap history
  1.2066 +  }; // Public flag values
  1.2067 +private:
  1.2068 +  uint _nof_decompiles;             // count of all nmethod removals
  1.2069 +  uint _nof_overflow_recompiles;    // recompile count, excluding recomp. bits
  1.2070 +  uint _nof_overflow_traps;         // trap count, excluding _trap_hist
  1.2071 +  union {
  1.2072 +    intptr_t _align;
  1.2073 +    u1 _array[_trap_hist_limit];
  1.2074 +  } _trap_hist;
  1.2075 +
  1.2076 +  // Support for interprocedural escape analysis, from Thomas Kotzmann.
  1.2077 +  intx              _eflags;          // flags on escape information
  1.2078 +  intx              _arg_local;       // bit set of non-escaping arguments
  1.2079 +  intx              _arg_stack;       // bit set of stack-allocatable arguments
  1.2080 +  intx              _arg_returned;    // bit set of returned arguments
  1.2081 +
  1.2082 +  int _creation_mileage;              // method mileage at MDO creation
  1.2083 +
  1.2084 +  // How many invocations has this MDO seen?
  1.2085 +  // These counters are used to determine the exact age of MDO.
  1.2086 +  // We need those because in tiered a method can be concurrently
  1.2087 +  // executed at different levels.
  1.2088 +  InvocationCounter _invocation_counter;
  1.2089 +  // Same for backedges.
  1.2090 +  InvocationCounter _backedge_counter;
  1.2091 +  // Counter values at the time profiling started.
  1.2092 +  int               _invocation_counter_start;
  1.2093 +  int               _backedge_counter_start;
  1.2094 +
  1.2095 +#if INCLUDE_RTM_OPT
  1.2096 +  // State of RTM code generation during compilation of the method
  1.2097 +  int               _rtm_state;
  1.2098 +#endif
  1.2099 +
  1.2100 +  // Number of loops and blocks is computed when compiling the first
  1.2101 +  // time with C1. It is used to determine if method is trivial.
  1.2102 +  short             _num_loops;
  1.2103 +  short             _num_blocks;
  1.2104 +  // Highest compile level this method has ever seen.
  1.2105 +  u1                _highest_comp_level;
  1.2106 +  // Same for OSR level
  1.2107 +  u1                _highest_osr_comp_level;
  1.2108 +  // Does this method contain anything worth profiling?
  1.2109 +  bool              _would_profile;
  1.2110 +
  1.2111 +  // Size of _data array in bytes.  (Excludes header and extra_data fields.)
  1.2112 +  int _data_size;
  1.2113 +
  1.2114 +  // data index for the area dedicated to parameters. -1 if no
  1.2115 +  // parameter profiling.
  1.2116 +  int _parameters_type_data_di;
  1.2117 +
  1.2118 +  // Beginning of the data entries
  1.2119 +  intptr_t _data[1];
  1.2120 +
  1.2121 +  // Helper for size computation
  1.2122 +  static int compute_data_size(BytecodeStream* stream);
  1.2123 +  static int bytecode_cell_count(Bytecodes::Code code);
  1.2124 +  static bool is_speculative_trap_bytecode(Bytecodes::Code code);
  1.2125 +  enum { no_profile_data = -1, variable_cell_count = -2 };
  1.2126 +
  1.2127 +  // Helper for initialization
  1.2128 +  DataLayout* data_layout_at(int data_index) const {
  1.2129 +    assert(data_index % sizeof(intptr_t) == 0, "unaligned");
  1.2130 +    return (DataLayout*) (((address)_data) + data_index);
  1.2131 +  }
  1.2132 +
  1.2133 +  // Initialize an individual data segment.  Returns the size of
  1.2134 +  // the segment in bytes.
  1.2135 +  int initialize_data(BytecodeStream* stream, int data_index);
  1.2136 +
  1.2137 +  // Helper for data_at
  1.2138 +  DataLayout* limit_data_position() const {
  1.2139 +    return (DataLayout*)((address)data_base() + _data_size);
  1.2140 +  }
  1.2141 +  bool out_of_bounds(int data_index) const {
  1.2142 +    return data_index >= data_size();
  1.2143 +  }
  1.2144 +
  1.2145 +  // Give each of the data entries a chance to perform specific
  1.2146 +  // data initialization.
  1.2147 +  void post_initialize(BytecodeStream* stream);
  1.2148 +
  1.2149 +  // hint accessors
  1.2150 +  int      hint_di() const  { return _hint_di; }
  1.2151 +  void set_hint_di(int di)  {
  1.2152 +    assert(!out_of_bounds(di), "hint_di out of bounds");
  1.2153 +    _hint_di = di;
  1.2154 +  }
  1.2155 +  ProfileData* data_before(int bci) {
  1.2156 +    // avoid SEGV on this edge case
  1.2157 +    if (data_size() == 0)
  1.2158 +      return NULL;
  1.2159 +    int hint = hint_di();
  1.2160 +    if (data_layout_at(hint)->bci() <= bci)
  1.2161 +      return data_at(hint);
  1.2162 +    return first_data();
  1.2163 +  }
  1.2164 +
  1.2165 +  // What is the index of the first data entry?
  1.2166 +  int first_di() const { return 0; }
  1.2167 +
  1.2168 +  ProfileData* bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp, bool concurrent);
  1.2169 +  // Find or create an extra ProfileData:
  1.2170 +  ProfileData* bci_to_extra_data(int bci, Method* m, bool create_if_missing);
  1.2171 +
  1.2172 +  // return the argument info cell
  1.2173 +  ArgInfoData *arg_info();
  1.2174 +
  1.2175 +  enum {
  1.2176 +    no_type_profile = 0,
  1.2177 +    type_profile_jsr292 = 1,
  1.2178 +    type_profile_all = 2
  1.2179 +  };
  1.2180 +
  1.2181 +  static bool profile_jsr292(methodHandle m, int bci);
  1.2182 +  static int profile_arguments_flag();
  1.2183 +  static bool profile_all_arguments();
  1.2184 +  static bool profile_arguments_for_invoke(methodHandle m, int bci);
  1.2185 +  static int profile_return_flag();
  1.2186 +  static bool profile_all_return();
  1.2187 +  static bool profile_return_for_invoke(methodHandle m, int bci);
  1.2188 +  static int profile_parameters_flag();
  1.2189 +  static bool profile_parameters_jsr292_only();
  1.2190 +  static bool profile_all_parameters();
  1.2191 +
  1.2192 +  void clean_extra_data(BoolObjectClosure* is_alive);
  1.2193 +  void clean_extra_data_helper(DataLayout* dp, int shift, bool reset = false);
  1.2194 +  void verify_extra_data_clean(BoolObjectClosure* is_alive);
  1.2195 +
  1.2196 +public:
  1.2197 +  static int header_size() {
  1.2198 +    return sizeof(MethodData)/wordSize;
  1.2199 +  }
  1.2200 +
  1.2201 +  // Compute the size of a MethodData* before it is created.
  1.2202 +  static int compute_allocation_size_in_bytes(methodHandle method);
  1.2203 +  static int compute_allocation_size_in_words(methodHandle method);
  1.2204 +  static int compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps);
  1.2205 +
  1.2206 +  // Determine if a given bytecode can have profile information.
  1.2207 +  static bool bytecode_has_profile(Bytecodes::Code code) {
  1.2208 +    return bytecode_cell_count(code) != no_profile_data;
  1.2209 +  }
  1.2210 +
  1.2211 +  // reset into original state
  1.2212 +  void init();
  1.2213 +
  1.2214 +  // My size
  1.2215 +  int size_in_bytes() const { return _size; }
  1.2216 +  int size() const    { return align_object_size(align_size_up(_size, BytesPerWord)/BytesPerWord); }
  1.2217 +#if INCLUDE_SERVICES
  1.2218 +  void collect_statistics(KlassSizeStats *sz) const;
  1.2219 +#endif
  1.2220 +
  1.2221 +  int      creation_mileage() const  { return _creation_mileage; }
  1.2222 +  void set_creation_mileage(int x)   { _creation_mileage = x; }
  1.2223 +
  1.2224 +  int invocation_count() {
  1.2225 +    if (invocation_counter()->carry()) {
  1.2226 +      return InvocationCounter::count_limit;
  1.2227 +    }
  1.2228 +    return invocation_counter()->count();
  1.2229 +  }
  1.2230 +  int backedge_count() {
  1.2231 +    if (backedge_counter()->carry()) {
  1.2232 +      return InvocationCounter::count_limit;
  1.2233 +    }
  1.2234 +    return backedge_counter()->count();
  1.2235 +  }
  1.2236 +
  1.2237 +  int invocation_count_start() {
  1.2238 +    if (invocation_counter()->carry()) {
  1.2239 +      return 0;
  1.2240 +    }
  1.2241 +    return _invocation_counter_start;
  1.2242 +  }
  1.2243 +
  1.2244 +  int backedge_count_start() {
  1.2245 +    if (backedge_counter()->carry()) {
  1.2246 +      return 0;
  1.2247 +    }
  1.2248 +    return _backedge_counter_start;
  1.2249 +  }
  1.2250 +
  1.2251 +  int invocation_count_delta() { return invocation_count() - invocation_count_start(); }
  1.2252 +  int backedge_count_delta()   { return backedge_count()   - backedge_count_start();   }
  1.2253 +
  1.2254 +  void reset_start_counters() {
  1.2255 +    _invocation_counter_start = invocation_count();
  1.2256 +    _backedge_counter_start = backedge_count();
  1.2257 +  }
  1.2258 +
  1.2259 +  InvocationCounter* invocation_counter()     { return &_invocation_counter; }
  1.2260 +  InvocationCounter* backedge_counter()       { return &_backedge_counter;   }
  1.2261 +
  1.2262 +#if INCLUDE_RTM_OPT
  1.2263 +  int rtm_state() const {
  1.2264 +    return _rtm_state;
  1.2265 +  }
  1.2266 +  void set_rtm_state(RTMState rstate) {
  1.2267 +    _rtm_state = (int)rstate;
  1.2268 +  }
  1.2269 +  void atomic_set_rtm_state(RTMState rstate) {
  1.2270 +    Atomic::store((int)rstate, &_rtm_state);
  1.2271 +  }
  1.2272 +
  1.2273 +  static int rtm_state_offset_in_bytes() {
  1.2274 +    return offset_of(MethodData, _rtm_state);
  1.2275 +  }
  1.2276 +#endif
  1.2277 +
  1.2278 +  void set_would_profile(bool p)              { _would_profile = p;    }
  1.2279 +  bool would_profile() const                  { return _would_profile; }
  1.2280 +
  1.2281 +  int highest_comp_level() const              { return _highest_comp_level;      }
  1.2282 +  void set_highest_comp_level(int level)      { _highest_comp_level = level;     }
  1.2283 +  int highest_osr_comp_level() const          { return _highest_osr_comp_level;  }
  1.2284 +  void set_highest_osr_comp_level(int level)  { _highest_osr_comp_level = level; }
  1.2285 +
  1.2286 +  int num_loops() const                       { return _num_loops;  }
  1.2287 +  void set_num_loops(int n)                   { _num_loops = n;     }
  1.2288 +  int num_blocks() const                      { return _num_blocks; }
  1.2289 +  void set_num_blocks(int n)                  { _num_blocks = n;    }
  1.2290 +
  1.2291 +  bool is_mature() const;  // consult mileage and ProfileMaturityPercentage
  1.2292 +  static int mileage_of(Method* m);
  1.2293 +
  1.2294 +  // Support for interprocedural escape analysis, from Thomas Kotzmann.
  1.2295 +  enum EscapeFlag {
  1.2296 +    estimated    = 1 << 0,
  1.2297 +    return_local = 1 << 1,
  1.2298 +    return_allocated = 1 << 2,
  1.2299 +    allocated_escapes = 1 << 3,
  1.2300 +    unknown_modified = 1 << 4
  1.2301 +  };
  1.2302 +
  1.2303 +  intx eflags()                                  { return _eflags; }
  1.2304 +  intx arg_local()                               { return _arg_local; }
  1.2305 +  intx arg_stack()                               { return _arg_stack; }
  1.2306 +  intx arg_returned()                            { return _arg_returned; }
  1.2307 +  uint arg_modified(int a)                       { ArgInfoData *aid = arg_info();
  1.2308 +                                                   assert(aid != NULL, "arg_info must be not null");
  1.2309 +                                                   assert(a >= 0 && a < aid->number_of_args(), "valid argument number");
  1.2310 +                                                   return aid->arg_modified(a); }
  1.2311 +
  1.2312 +  void set_eflags(intx v)                        { _eflags = v; }
  1.2313 +  void set_arg_local(intx v)                     { _arg_local = v; }
  1.2314 +  void set_arg_stack(intx v)                     { _arg_stack = v; }
  1.2315 +  void set_arg_returned(intx v)                  { _arg_returned = v; }
  1.2316 +  void set_arg_modified(int a, uint v)           { ArgInfoData *aid = arg_info();
  1.2317 +                                                   assert(aid != NULL, "arg_info must be not null");
  1.2318 +                                                   assert(a >= 0 && a < aid->number_of_args(), "valid argument number");
  1.2319 +                                                   aid->set_arg_modified(a, v); }
  1.2320 +
  1.2321 +  void clear_escape_info()                       { _eflags = _arg_local = _arg_stack = _arg_returned = 0; }
  1.2322 +
  1.2323 +  // Location and size of data area
  1.2324 +  address data_base() const {
  1.2325 +    return (address) _data;
  1.2326 +  }
  1.2327 +  int data_size() const {
  1.2328 +    return _data_size;
  1.2329 +  }
  1.2330 +
  1.2331 +  // Accessors
  1.2332 +  Method* method() const { return _method; }
  1.2333 +
  1.2334 +  // Get the data at an arbitrary (sort of) data index.
  1.2335 +  ProfileData* data_at(int data_index) const;
  1.2336 +
  1.2337 +  // Walk through the data in order.
  1.2338 +  ProfileData* first_data() const { return data_at(first_di()); }
  1.2339 +  ProfileData* next_data(ProfileData* current) const;
  1.2340 +  bool is_valid(ProfileData* current) const { return current != NULL; }
  1.2341 +
  1.2342 +  // Convert a dp (data pointer) to a di (data index).
  1.2343 +  int dp_to_di(address dp) const {
  1.2344 +    return dp - ((address)_data);
  1.2345 +  }
  1.2346 +
  1.2347 +  address di_to_dp(int di) {
  1.2348 +    return (address)data_layout_at(di);
  1.2349 +  }
  1.2350 +
  1.2351 +  // bci to di/dp conversion.
  1.2352 +  address bci_to_dp(int bci);
  1.2353 +  int bci_to_di(int bci) {
  1.2354 +    return dp_to_di(bci_to_dp(bci));
  1.2355 +  }
  1.2356 +
  1.2357 +  // Get the data at an arbitrary bci, or NULL if there is none.
  1.2358 +  ProfileData* bci_to_data(int bci);
  1.2359 +
  1.2360 +  // Same, but try to create an extra_data record if one is needed:
  1.2361 +  ProfileData* allocate_bci_to_data(int bci, Method* m) {
  1.2362 +    ProfileData* data = NULL;
  1.2363 +    // If m not NULL, try to allocate a SpeculativeTrapData entry
  1.2364 +    if (m == NULL) {
  1.2365 +      data = bci_to_data(bci);
  1.2366 +    }
  1.2367 +    if (data != NULL) {
  1.2368 +      return data;
  1.2369 +    }
  1.2370 +    data = bci_to_extra_data(bci, m, true);
  1.2371 +    if (data != NULL) {
  1.2372 +      return data;
  1.2373 +    }
  1.2374 +    // If SpeculativeTrapData allocation fails try to allocate a
  1.2375 +    // regular entry
  1.2376 +    data = bci_to_data(bci);
  1.2377 +    if (data != NULL) {
  1.2378 +      return data;
  1.2379 +    }
  1.2380 +    return bci_to_extra_data(bci, NULL, true);
  1.2381 +  }
  1.2382 +
  1.2383 +  // Add a handful of extra data records, for trap tracking.
  1.2384 +  DataLayout* extra_data_base() const { return limit_data_position(); }
  1.2385 +  DataLayout* extra_data_limit() const { return (DataLayout*)((address)this + size_in_bytes()); }
  1.2386 +  int extra_data_size() const { return (address)extra_data_limit()
  1.2387 +                               - (address)extra_data_base(); }
  1.2388 +  static DataLayout* next_extra(DataLayout* dp);
  1.2389 +
  1.2390 +  // Return (uint)-1 for overflow.
  1.2391 +  uint trap_count(int reason) const {
  1.2392 +    assert((uint)reason < _trap_hist_limit, "oob");
  1.2393 +    return (int)((_trap_hist._array[reason]+1) & _trap_hist_mask) - 1;
  1.2394 +  }
  1.2395 +  // For loops:
  1.2396 +  static uint trap_reason_limit() { return _trap_hist_limit; }
  1.2397 +  static uint trap_count_limit()  { return _trap_hist_mask; }
  1.2398 +  uint inc_trap_count(int reason) {
  1.2399 +    // Count another trap, anywhere in this method.
  1.2400 +    assert(reason >= 0, "must be single trap");
  1.2401 +    if ((uint)reason < _trap_hist_limit) {
  1.2402 +      uint cnt1 = 1 + _trap_hist._array[reason];
  1.2403 +      if ((cnt1 & _trap_hist_mask) != 0) {  // if no counter overflow...
  1.2404 +        _trap_hist._array[reason] = cnt1;
  1.2405 +        return cnt1;
  1.2406 +      } else {
  1.2407 +        return _trap_hist_mask + (++_nof_overflow_traps);
  1.2408 +      }
  1.2409 +    } else {
  1.2410 +      // Could not represent the count in the histogram.
  1.2411 +      return (++_nof_overflow_traps);
  1.2412 +    }
  1.2413 +  }
  1.2414 +
  1.2415 +  uint overflow_trap_count() const {
  1.2416 +    return _nof_overflow_traps;
  1.2417 +  }
  1.2418 +  uint overflow_recompile_count() const {
  1.2419 +    return _nof_overflow_recompiles;
  1.2420 +  }
  1.2421 +  void inc_overflow_recompile_count() {
  1.2422 +    _nof_overflow_recompiles += 1;
  1.2423 +  }
  1.2424 +  uint decompile_count() const {
  1.2425 +    return _nof_decompiles;
  1.2426 +  }
  1.2427 +  void inc_decompile_count() {
  1.2428 +    _nof_decompiles += 1;
  1.2429 +    if (decompile_count() > (uint)PerMethodRecompilationCutoff) {
  1.2430 +      method()->set_not_compilable(CompLevel_full_optimization, true, "decompile_count > PerMethodRecompilationCutoff");
  1.2431 +    }
  1.2432 +  }
  1.2433 +
  1.2434 +  // Return pointer to area dedicated to parameters in MDO
  1.2435 +  ParametersTypeData* parameters_type_data() const {
  1.2436 +    return _parameters_type_data_di != -1 ? data_layout_at(_parameters_type_data_di)->data_in()->as_ParametersTypeData() : NULL;
  1.2437 +  }
  1.2438 +
  1.2439 +  int parameters_type_data_di() const {
  1.2440 +    assert(_parameters_type_data_di != -1, "no args type data");
  1.2441 +    return _parameters_type_data_di;
  1.2442 +  }
  1.2443 +
  1.2444 +  // Support for code generation
  1.2445 +  static ByteSize data_offset() {
  1.2446 +    return byte_offset_of(MethodData, _data[0]);
  1.2447 +  }
  1.2448 +
  1.2449 +  static ByteSize invocation_counter_offset() {
  1.2450 +    return byte_offset_of(MethodData, _invocation_counter);
  1.2451 +  }
  1.2452 +  static ByteSize backedge_counter_offset() {
  1.2453 +    return byte_offset_of(MethodData, _backedge_counter);
  1.2454 +  }
  1.2455 +
  1.2456 +  static ByteSize parameters_type_data_di_offset() {
  1.2457 +    return byte_offset_of(MethodData, _parameters_type_data_di);
  1.2458 +  }
  1.2459 +
  1.2460 +  // Deallocation support - no pointer fields to deallocate
  1.2461 +  void deallocate_contents(ClassLoaderData* loader_data) {}
  1.2462 +
  1.2463 +  // GC support
  1.2464 +  void set_size(int object_size_in_bytes) { _size = object_size_in_bytes; }
  1.2465 +
  1.2466 +  // Printing
  1.2467 +#ifndef PRODUCT
  1.2468 +  void print_on      (outputStream* st) const;
  1.2469 +#endif
  1.2470 +  void print_value_on(outputStream* st) const;
  1.2471 +
  1.2472 +#ifndef PRODUCT
  1.2473 +  // printing support for method data
  1.2474 +  void print_data_on(outputStream* st) const;
  1.2475 +#endif
  1.2476 +
  1.2477 +  const char* internal_name() const { return "{method data}"; }
  1.2478 +
  1.2479 +  // verification
  1.2480 +  void verify_on(outputStream* st);
  1.2481 +  void verify_data_on(outputStream* st);
  1.2482 +
  1.2483 +  static bool profile_parameters_for_method(methodHandle m);
  1.2484 +  static bool profile_arguments();
  1.2485 +  static bool profile_arguments_jsr292_only();
  1.2486 +  static bool profile_return();
  1.2487 +  static bool profile_parameters();
  1.2488 +  static bool profile_return_jsr292_only();
  1.2489 +
  1.2490 +  void clean_method_data(BoolObjectClosure* is_alive);
  1.2491 +};
  1.2492 +
  1.2493 +#endif // SHARE_VM_OOPS_METHODDATAOOP_HPP

mercurial