1 /*
   2  * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_OOPS_METHODDATA_HPP
  26 #define SHARE_OOPS_METHODDATA_HPP
  27 
  28 #include "interpreter/bytecodes.hpp"
  29 #include "interpreter/invocationCounter.hpp"
  30 #include "oops/metadata.hpp"
  31 #include "oops/method.hpp"
  32 #include "oops/oop.hpp"
  33 #include "runtime/atomic.hpp"
  34 #include "runtime/deoptimization.hpp"
  35 #include "runtime/mutex.hpp"
  36 #include "utilities/align.hpp"
  37 #include "utilities/copy.hpp"
  38 
  39 class BytecodeStream;
  40 
  41 // The MethodData object collects counts and other profile information
  42 // during zeroth-tier (interpreter) and third-tier (C1 with full profiling)
  43 // execution.
  44 //
  45 // The profile is used later by compilation heuristics.  Some heuristics
  46 // enable use of aggressive (or "heroic") optimizations.  An aggressive
  47 // optimization often has a down-side, a corner case that it handles
  48 // poorly, but which is thought to be rare.  The profile provides
  49 // evidence of this rarity for a given method or even BCI.  It allows
  50 // the compiler to back out of the optimization at places where it
  51 // has historically been a poor choice.  Other heuristics try to use
  52 // specific information gathered about types observed at a given site.
  53 //
  54 // All data in the profile is approximate.  It is expected to be accurate
  55 // on the whole, but the system expects occasional inaccuraces, due to
  56 // counter overflow, multiprocessor races during data collection, space
  57 // limitations, missing MDO blocks, etc.  Bad or missing data will degrade
  58 // optimization quality but will not affect correctness.  Also, each MDO
  59 // is marked with its birth-date ("creation_mileage") which can be used
  60 // to assess the quality ("maturity") of its data.
  61 //
  62 // Short (<32-bit) counters are designed to overflow to a known "saturated"
  63 // state.  Also, certain recorded per-BCI events are given one-bit counters
  64 // which overflow to a saturated state which applied to all counters at
  65 // that BCI.  In other words, there is a small lattice which approximates
  66 // the ideal of an infinite-precision counter for each event at each BCI,
  67 // and the lattice quickly "bottoms out" in a state where all counters
  68 // are taken to be indefinitely large.
  69 //
  70 // The reader will find many data races in profile gathering code, starting
  71 // with invocation counter incrementation.  None of these races harm correct
  72 // execution of the compiled code.
  73 
  74 // forward decl
  75 class ProfileData;
  76 
  77 // DataLayout
  78 //
  79 // Overlay for generic profiling data.
  80 class DataLayout {
  81   friend class VMStructs;
  82   friend class JVMCIVMStructs;
  83 
  84 private:
  85   // Every data layout begins with a header.  This header
  86   // contains a tag, which is used to indicate the size/layout
  87   // of the data, 8 bits of flags, which can be used in any way,
  88   // 32 bits of trap history (none/one reason/many reasons),
  89   // and a bci, which is used to tie this piece of data to a
  90   // specific bci in the bytecodes.
  91   union {
  92     u8 _bits;
  93     struct {
  94       u1 _tag;
  95       u1 _flags;
  96       u2 _bci;
  97       u4 _traps;
  98     } _struct;
  99   } _header;
 100 
 101   // The data layout has an arbitrary number of cells, each sized
 102   // to accommodate a pointer or an integer.
 103   intptr_t _cells[1];
 104 
 105   // Some types of data layouts need a length field.
 106   static bool needs_array_len(u1 tag);
 107 
 108 public:
 109   enum {
 110     counter_increment = 1
 111   };
 112 
 113   enum {
 114     cell_size = sizeof(intptr_t)
 115   };
 116 
 117   // Tag values
 118   enum : u1 {
 119     no_tag,
 120     bit_data_tag,
 121     counter_data_tag,
 122     jump_data_tag,
 123     receiver_type_data_tag,
 124     virtual_call_data_tag,
 125     ret_data_tag,
 126     branch_data_tag,
 127     multi_branch_data_tag,
 128     arg_info_data_tag,
 129     call_type_data_tag,
 130     virtual_call_type_data_tag,
 131     parameters_type_data_tag,
 132     speculative_trap_data_tag,
 133     array_store_data_tag,
 134     array_load_data_tag,
 135     acmp_data_tag
 136   };
 137 
 138   enum {
 139     // The trap state breaks down as [recompile:1 | reason:31].
 140     // This further breakdown is defined in deoptimization.cpp.
 141     // See Deoptimization::trap_state_reason for an assert that
 142     // trap_bits is big enough to hold reasons < Reason_RECORDED_LIMIT.
 143     //
 144     // The trap_state is collected only if ProfileTraps is true.
 145     trap_bits = 1+31,  // 31: enough to distinguish [0..Reason_RECORDED_LIMIT].
 146     trap_mask = -1,
 147     first_flag = 0
 148   };
 149 
 150   // Size computation
 151   static int header_size_in_bytes() {
 152     return header_size_in_cells() * cell_size;
 153   }
 154   static int header_size_in_cells() {
 155     return LP64_ONLY(1) NOT_LP64(2);
 156   }
 157 
 158   static int compute_size_in_bytes(int cell_count) {
 159     return header_size_in_bytes() + cell_count * cell_size;
 160   }
 161 
 162   // Initialization
 163   void initialize(u1 tag, u2 bci, int cell_count);
 164 
 165   // Accessors
 166   u1 tag() {
 167     return _header._struct._tag;
 168   }
 169 
 170   // Return 32 bits of trap state.
 171   // The state tells if traps with zero, one, or many reasons have occurred.
 172   // It also tells whether zero or many recompilations have occurred.
 173   // The associated trap histogram in the MDO itself tells whether
 174   // traps are common or not.  If a BCI shows that a trap X has
 175   // occurred, and the MDO shows N occurrences of X, we make the
 176   // simplifying assumption that all N occurrences can be blamed
 177   // on that BCI.
 178   uint trap_state() const {
 179     return _header._struct._traps;
 180   }
 181 
 182   void set_trap_state(uint new_state) {
 183     assert(ProfileTraps, "used only under +ProfileTraps");
 184     uint old_flags = _header._struct._traps;
 185     _header._struct._traps = new_state | old_flags;
 186   }
 187 
 188   u1 flags() const {
 189     return Atomic::load_acquire(&_header._struct._flags);
 190   }
 191 
 192   u2 bci() const {
 193     return _header._struct._bci;
 194   }
 195 
 196   void set_header(u8 value) {
 197     _header._bits = value;
 198   }
 199   u8 header() {
 200     return _header._bits;
 201   }
 202   void set_cell_at(int index, intptr_t value) {
 203     _cells[index] = value;
 204   }
 205   void release_set_cell_at(int index, intptr_t value);
 206   intptr_t cell_at(int index) const {
 207     return _cells[index];
 208   }
 209 
 210   bool set_flag_at(u1 flag_number) {
 211     const u1 bit = 1 << flag_number;
 212     u1 compare_value;
 213     do {
 214       compare_value = _header._struct._flags;
 215       if ((compare_value & bit) == bit) {
 216         // already set.
 217         return false;
 218       }
 219     } while (compare_value != Atomic::cmpxchg(&_header._struct._flags, compare_value, static_cast<u1>(compare_value | bit)));
 220     return true;
 221   }
 222 
 223   bool clear_flag_at(u1 flag_number) {
 224     const u1 bit = 1 << flag_number;
 225     u1 compare_value;
 226     u1 exchange_value;
 227     do {
 228       compare_value = _header._struct._flags;
 229       if ((compare_value & bit) == 0) {
 230         // already cleaed.
 231         return false;
 232       }
 233       exchange_value = compare_value & ~bit;
 234     } while (compare_value != Atomic::cmpxchg(&_header._struct._flags, compare_value, exchange_value));
 235     return true;
 236   }
 237 
 238   bool flag_at(u1 flag_number) const {
 239     return (flags() & (1 << flag_number)) != 0;
 240   }
 241 
 242   // Low-level support for code generation.
 243   static ByteSize header_offset() {
 244     return byte_offset_of(DataLayout, _header);
 245   }
 246   static ByteSize tag_offset() {
 247     return byte_offset_of(DataLayout, _header._struct._tag);
 248   }
 249   static ByteSize flags_offset() {
 250     return byte_offset_of(DataLayout, _header._struct._flags);
 251   }
 252   static ByteSize bci_offset() {
 253     return byte_offset_of(DataLayout, _header._struct._bci);
 254   }
 255   static ByteSize cell_offset(int index) {
 256     return byte_offset_of(DataLayout, _cells) + in_ByteSize(index * cell_size);
 257   }
 258   // Return a value which, when or-ed as a byte into _flags, sets the flag.
 259   static u1 flag_number_to_constant(u1 flag_number) {
 260     DataLayout temp; temp.set_header(0);
 261     temp.set_flag_at(flag_number);
 262     return temp._header._struct._flags;
 263   }
 264   // Return a value which, when or-ed as a word into _header, sets the flag.
 265   static u8 flag_mask_to_header_mask(u1 byte_constant) {
 266     DataLayout temp; temp.set_header(0);
 267     temp._header._struct._flags = byte_constant;
 268     return temp._header._bits;
 269   }
 270 
 271   ProfileData* data_in();
 272 
 273   int size_in_bytes() {
 274     int cells = cell_count();
 275     assert(cells >= 0, "invalid number of cells");
 276     return DataLayout::compute_size_in_bytes(cells);
 277   }
 278   int cell_count();
 279 
 280   // GC support
 281   void clean_weak_klass_links(bool always_clean);
 282 };
 283 
 284 
 285 // ProfileData class hierarchy
 286 class ProfileData;
 287 class   BitData;
 288 class     CounterData;
 289 class       ReceiverTypeData;
 290 class         VirtualCallData;
 291 class           VirtualCallTypeData;
 292 class         ArrayStoreData;
 293 class       RetData;
 294 class       CallTypeData;
 295 class   JumpData;
 296 class     BranchData;
 297 class       ACmpData;
 298 class   ArrayData;
 299 class     MultiBranchData;
 300 class     ArgInfoData;
 301 class     ParametersTypeData;
 302 class   SpeculativeTrapData;
 303 class   ArrayLoadData;
 304 
 305 // ProfileData
 306 //
 307 // A ProfileData object is created to refer to a section of profiling
 308 // data in a structured way.
 309 class ProfileData : public ResourceObj {
 310   friend class TypeEntries;
 311   friend class SingleTypeEntry;
 312   friend class TypeStackSlotEntries;
 313 private:
 314   enum {
 315     tab_width_one = 16,
 316     tab_width_two = 36
 317   };
 318 
 319   // This is a pointer to a section of profiling data.
 320   DataLayout* _data;
 321 
 322   char* print_data_on_helper(const MethodData* md) const;
 323 
 324 protected:
 325   DataLayout* data() { return _data; }
 326   const DataLayout* data() const { return _data; }
 327 
 328   enum {
 329     cell_size = DataLayout::cell_size
 330   };
 331 
 332 public:
 333   // How many cells are in this?
 334   virtual int cell_count() const {
 335     ShouldNotReachHere();
 336     return -1;
 337   }
 338 
 339   // Return the size of this data.
 340   int size_in_bytes() {
 341     return DataLayout::compute_size_in_bytes(cell_count());
 342   }
 343 
 344 protected:
 345   // Low-level accessors for underlying data
 346   void set_intptr_at(int index, intptr_t value) {
 347     assert(0 <= index && index < cell_count(), "oob");
 348     data()->set_cell_at(index, value);
 349   }
 350   void release_set_intptr_at(int index, intptr_t value);
 351   intptr_t intptr_at(int index) const {
 352     assert(0 <= index && index < cell_count(), "oob");
 353     return data()->cell_at(index);
 354   }
 355   void set_uint_at(int index, uint value) {
 356     set_intptr_at(index, (intptr_t) value);
 357   }
 358   void release_set_uint_at(int index, uint value);
 359   uint uint_at(int index) const {
 360     return (uint)intptr_at(index);
 361   }
 362   void set_int_at(int index, int value) {
 363     set_intptr_at(index, (intptr_t) value);
 364   }
 365   void release_set_int_at(int index, int value);
 366   int int_at(int index) const {
 367     return (int)intptr_at(index);
 368   }
 369   int int_at_unchecked(int index) const {
 370     return (int)data()->cell_at(index);
 371   }
 372   void set_oop_at(int index, oop value) {
 373     set_intptr_at(index, cast_from_oop<intptr_t>(value));
 374   }
 375   oop oop_at(int index) const {
 376     return cast_to_oop(intptr_at(index));
 377   }
 378 
 379   void set_flag_at(u1 flag_number) {
 380     data()->set_flag_at(flag_number);
 381   }
 382   bool flag_at(u1 flag_number) const {
 383     return data()->flag_at(flag_number);
 384   }
 385 
 386   // two convenient imports for use by subclasses:
 387   static ByteSize cell_offset(int index) {
 388     return DataLayout::cell_offset(index);
 389   }
 390   static u1 flag_number_to_constant(u1 flag_number) {
 391     return DataLayout::flag_number_to_constant(flag_number);
 392   }
 393 
 394   ProfileData(DataLayout* data) {
 395     _data = data;
 396   }
 397 
 398 public:
 399   // Constructor for invalid ProfileData.
 400   ProfileData();
 401 
 402   u2 bci() const {
 403     return data()->bci();
 404   }
 405 
 406   address dp() {
 407     return (address)_data;
 408   }
 409 
 410   int trap_state() const {
 411     return data()->trap_state();
 412   }
 413   void set_trap_state(int new_state) {
 414     data()->set_trap_state(new_state);
 415   }
 416 
 417   // Type checking
 418   virtual bool is_BitData()         const { return false; }
 419   virtual bool is_CounterData()     const { return false; }
 420   virtual bool is_JumpData()        const { return false; }
 421   virtual bool is_ReceiverTypeData()const { return false; }
 422   virtual bool is_VirtualCallData() const { return false; }
 423   virtual bool is_RetData()         const { return false; }
 424   virtual bool is_BranchData()      const { return false; }
 425   virtual bool is_ArrayData()       const { return false; }
 426   virtual bool is_MultiBranchData() const { return false; }
 427   virtual bool is_ArgInfoData()     const { return false; }
 428   virtual bool is_CallTypeData()    const { return false; }
 429   virtual bool is_VirtualCallTypeData()const { return false; }
 430   virtual bool is_ParametersTypeData() const { return false; }
 431   virtual bool is_SpeculativeTrapData()const { return false; }
 432   virtual bool is_ArrayStoreData() const { return false; }
 433   virtual bool is_ArrayLoadData() const { return false; }
 434   virtual bool is_ACmpData()           const { return false; }
 435 
 436 
 437   BitData* as_BitData() const {
 438     assert(is_BitData(), "wrong type");
 439     return is_BitData()         ? (BitData*)        this : nullptr;
 440   }
 441   CounterData* as_CounterData() const {
 442     assert(is_CounterData(), "wrong type");
 443     return is_CounterData()     ? (CounterData*)    this : nullptr;
 444   }
 445   JumpData* as_JumpData() const {
 446     assert(is_JumpData(), "wrong type");
 447     return is_JumpData()        ? (JumpData*)       this : nullptr;
 448   }
 449   ReceiverTypeData* as_ReceiverTypeData() const {
 450     assert(is_ReceiverTypeData(), "wrong type");
 451     return is_ReceiverTypeData() ? (ReceiverTypeData*)this : nullptr;
 452   }
 453   VirtualCallData* as_VirtualCallData() const {
 454     assert(is_VirtualCallData(), "wrong type");
 455     return is_VirtualCallData() ? (VirtualCallData*)this : nullptr;
 456   }
 457   RetData* as_RetData() const {
 458     assert(is_RetData(), "wrong type");
 459     return is_RetData()         ? (RetData*)        this : nullptr;
 460   }
 461   BranchData* as_BranchData() const {
 462     assert(is_BranchData(), "wrong type");
 463     return is_BranchData()      ? (BranchData*)     this : nullptr;
 464   }
 465   ArrayData* as_ArrayData() const {
 466     assert(is_ArrayData(), "wrong type");
 467     return is_ArrayData()       ? (ArrayData*)      this : nullptr;
 468   }
 469   MultiBranchData* as_MultiBranchData() const {
 470     assert(is_MultiBranchData(), "wrong type");
 471     return is_MultiBranchData() ? (MultiBranchData*)this : nullptr;
 472   }
 473   ArgInfoData* as_ArgInfoData() const {
 474     assert(is_ArgInfoData(), "wrong type");
 475     return is_ArgInfoData() ? (ArgInfoData*)this : nullptr;
 476   }
 477   CallTypeData* as_CallTypeData() const {
 478     assert(is_CallTypeData(), "wrong type");
 479     return is_CallTypeData() ? (CallTypeData*)this : nullptr;
 480   }
 481   VirtualCallTypeData* as_VirtualCallTypeData() const {
 482     assert(is_VirtualCallTypeData(), "wrong type");
 483     return is_VirtualCallTypeData() ? (VirtualCallTypeData*)this : nullptr;
 484   }
 485   ParametersTypeData* as_ParametersTypeData() const {
 486     assert(is_ParametersTypeData(), "wrong type");
 487     return is_ParametersTypeData() ? (ParametersTypeData*)this : nullptr;
 488   }
 489   SpeculativeTrapData* as_SpeculativeTrapData() const {
 490     assert(is_SpeculativeTrapData(), "wrong type");
 491     return is_SpeculativeTrapData() ? (SpeculativeTrapData*)this : nullptr;
 492   }
 493   ArrayStoreData* as_ArrayStoreData() const {
 494     assert(is_ArrayStoreData(), "wrong type");
 495     return is_ArrayStoreData() ? (ArrayStoreData*)this : nullptr;
 496   }
 497   ArrayLoadData* as_ArrayLoadData() const {
 498     assert(is_ArrayLoadData(), "wrong type");
 499     return is_ArrayLoadData() ? (ArrayLoadData*)this : nullptr;
 500   }
 501   ACmpData* as_ACmpData() const {
 502     assert(is_ACmpData(), "wrong type");
 503     return is_ACmpData() ? (ACmpData*)this : nullptr;
 504   }
 505 
 506 
 507   // Subclass specific initialization
 508   virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {}
 509 
 510   // GC support
 511   virtual void clean_weak_klass_links(bool always_clean) {}
 512 
 513   // CI translation: ProfileData can represent both MethodDataOop data
 514   // as well as CIMethodData data. This function is provided for translating
 515   // an oop in a ProfileData to the ci equivalent. Generally speaking,
 516   // most ProfileData don't require any translation, so we provide the null
 517   // translation here, and the required translators are in the ci subclasses.
 518   virtual void translate_from(const ProfileData* data) {}
 519 
 520   virtual void print_data_on(outputStream* st, const char* extra = nullptr) const {
 521     ShouldNotReachHere();
 522   }
 523 
 524   void print_data_on(outputStream* st, const MethodData* md) const;
 525 
 526   void print_shared(outputStream* st, const char* name, const char* extra) const;
 527   void tab(outputStream* st, bool first = false) const;
 528 };
 529 
 530 // BitData
 531 //
 532 // A BitData holds a flag or two in its header.
 533 class BitData : public ProfileData {
 534   friend class VMStructs;
 535   friend class JVMCIVMStructs;
 536 protected:
 537   enum : u1 {
 538     // null_seen:
 539     //  saw a null operand (cast/aastore/instanceof)
 540       null_seen_flag                  = DataLayout::first_flag + 0,
 541       exception_handler_entered_flag  = null_seen_flag + 1,
 542       deprecated_method_callsite_flag = exception_handler_entered_flag + 1
 543 #if INCLUDE_JVMCI
 544     // bytecode threw any exception
 545     , exception_seen_flag             = deprecated_method_callsite_flag + 1
 546 #endif
 547     , last_bit_data_flag
 548   };
 549   enum { bit_cell_count = 0 };  // no additional data fields needed.
 550 public:
 551   BitData(DataLayout* layout) : ProfileData(layout) {
 552   }
 553 
 554   virtual bool is_BitData() const { return true; }
 555 
 556   static int static_cell_count() {
 557     return bit_cell_count;
 558   }
 559 
 560   virtual int cell_count() const {
 561     return static_cell_count();
 562   }
 563 
 564   // Accessor
 565 
 566   // The null_seen flag bit is specially known to the interpreter.
 567   // Consulting it allows the compiler to avoid setting up null_check traps.
 568   bool null_seen() const  { return flag_at(null_seen_flag); }
 569   void set_null_seen()    { set_flag_at(null_seen_flag); }
 570   bool deprecated_method_call_site() const { return flag_at(deprecated_method_callsite_flag); }
 571   bool set_deprecated_method_call_site() { return data()->set_flag_at(deprecated_method_callsite_flag); }
 572   bool clear_deprecated_method_call_site() { return data()->clear_flag_at(deprecated_method_callsite_flag); }
 573 
 574 #if INCLUDE_JVMCI
 575   // true if an exception was thrown at the specific BCI
 576   bool exception_seen() { return flag_at(exception_seen_flag); }
 577   void set_exception_seen() { set_flag_at(exception_seen_flag); }
 578 #endif
 579 
 580   // true if a ex handler block at this bci was entered
 581   bool exception_handler_entered() { return flag_at(exception_handler_entered_flag); }
 582   void set_exception_handler_entered() { set_flag_at(exception_handler_entered_flag); }
 583 
 584   // Code generation support
 585   static u1 null_seen_byte_constant() {
 586     return flag_number_to_constant(null_seen_flag);
 587   }
 588 
 589   static ByteSize bit_data_size() {
 590     return cell_offset(bit_cell_count);
 591   }
 592 
 593   void print_data_on(outputStream* st, const char* extra = nullptr) const;
 594 };
 595 
 596 // CounterData
 597 //
 598 // A CounterData corresponds to a simple counter.
 599 class CounterData : public BitData {
 600   friend class VMStructs;
 601   friend class JVMCIVMStructs;
 602 protected:
 603   enum {
 604     count_off,
 605     counter_cell_count
 606   };
 607 public:
 608   CounterData(DataLayout* layout) : BitData(layout) {}
 609 
 610   virtual bool is_CounterData() const { return true; }
 611 
 612   static int static_cell_count() {
 613     return counter_cell_count;
 614   }
 615 
 616   virtual int cell_count() const {
 617     return static_cell_count();
 618   }
 619 
 620   // Direct accessor
 621   int count() const {
 622     intptr_t raw_data = intptr_at(count_off);
 623     if (raw_data > max_jint) {
 624       raw_data = max_jint;
 625     } else if (raw_data < min_jint) {
 626       raw_data = min_jint;
 627     }
 628     return int(raw_data);
 629   }
 630 
 631   // Code generation support
 632   static ByteSize count_offset() {
 633     return cell_offset(count_off);
 634   }
 635   static ByteSize counter_data_size() {
 636     return cell_offset(counter_cell_count);
 637   }
 638 
 639   void set_count(int count) {
 640     set_int_at(count_off, count);
 641   }
 642 
 643   void print_data_on(outputStream* st, const char* extra = nullptr) const;
 644 };
 645 
 646 // JumpData
 647 //
 648 // A JumpData is used to access profiling information for a direct
 649 // branch.  It is a counter, used for counting the number of branches,
 650 // plus a data displacement, used for realigning the data pointer to
 651 // the corresponding target bci.
 652 class JumpData : public ProfileData {
 653   friend class VMStructs;
 654   friend class JVMCIVMStructs;
 655 protected:
 656   enum {
 657     taken_off_set,
 658     displacement_off_set,
 659     jump_cell_count
 660   };
 661 
 662   void set_displacement(int displacement) {
 663     set_int_at(displacement_off_set, displacement);
 664   }
 665 
 666 public:
 667   JumpData(DataLayout* layout) : ProfileData(layout) {
 668     assert(layout->tag() == DataLayout::jump_data_tag ||
 669       layout->tag() == DataLayout::branch_data_tag ||
 670       layout->tag() == DataLayout::acmp_data_tag, "wrong type");
 671   }
 672 
 673   virtual bool is_JumpData() const { return true; }
 674 
 675   static int static_cell_count() {
 676     return jump_cell_count;
 677   }
 678 
 679   virtual int cell_count() const {
 680     return static_cell_count();
 681   }
 682 
 683   // Direct accessor
 684   uint taken() const {
 685     return uint_at(taken_off_set);
 686   }
 687 
 688   void set_taken(uint cnt) {
 689     set_uint_at(taken_off_set, cnt);
 690   }
 691 
 692   // Saturating counter
 693   uint inc_taken() {
 694     uint cnt = taken() + 1;
 695     // Did we wrap? Will compiler screw us??
 696     if (cnt == 0) cnt--;
 697     set_uint_at(taken_off_set, cnt);
 698     return cnt;
 699   }
 700 
 701   int displacement() const {
 702     return int_at(displacement_off_set);
 703   }
 704 
 705   // Code generation support
 706   static ByteSize taken_offset() {
 707     return cell_offset(taken_off_set);
 708   }
 709 
 710   static ByteSize displacement_offset() {
 711     return cell_offset(displacement_off_set);
 712   }
 713 
 714   // Specific initialization.
 715   void post_initialize(BytecodeStream* stream, MethodData* mdo);
 716 
 717   void print_data_on(outputStream* st, const char* extra = nullptr) const;
 718 };
 719 
 720 // Entries in a ProfileData object to record types: it can either be
 721 // none (no profile), unknown (conflicting profile data) or a klass if
 722 // a single one is seen. Whether a null reference was seen is also
 723 // recorded. No counter is associated with the type and a single type
 724 // is tracked (unlike VirtualCallData).
 725 class TypeEntries {
 726 
 727 public:
 728 
 729   // A single cell is used to record information for a type:
 730   // - the cell is initialized to 0
 731   // - when a type is discovered it is stored in the cell
 732   // - bit zero of the cell is used to record whether a null reference
 733   // was encountered or not
 734   // - bit 1 is set to record a conflict in the type information
 735 
 736   enum {
 737     null_seen = 1,
 738     type_mask = ~null_seen,
 739     type_unknown = 2,
 740     status_bits = null_seen | type_unknown,
 741     type_klass_mask = ~status_bits
 742   };
 743 
 744   // what to initialize a cell to
 745   static intptr_t type_none() {
 746     return 0;
 747   }
 748 
 749   // null seen = bit 0 set?
 750   static bool was_null_seen(intptr_t v) {
 751     return (v & null_seen) != 0;
 752   }
 753 
 754   // conflicting type information = bit 1 set?
 755   static bool is_type_unknown(intptr_t v) {
 756     return (v & type_unknown) != 0;
 757   }
 758 
 759   // not type information yet = all bits cleared, ignoring bit 0?
 760   static bool is_type_none(intptr_t v) {
 761     return (v & type_mask) == 0;
 762   }
 763 
 764   // recorded type: cell without bit 0 and 1
 765   static intptr_t klass_part(intptr_t v) {
 766     intptr_t r = v & type_klass_mask;
 767     return r;
 768   }
 769 
 770   // type recorded
 771   static Klass* valid_klass(intptr_t k) {
 772     if (!is_type_none(k) &&
 773         !is_type_unknown(k)) {
 774       Klass* res = (Klass*)klass_part(k);
 775       assert(res != nullptr, "invalid");
 776       return res;
 777     } else {
 778       return nullptr;
 779     }
 780   }
 781 
 782   static intptr_t with_status(intptr_t k, intptr_t in) {
 783     return k | (in & status_bits);
 784   }
 785 
 786   static intptr_t with_status(Klass* k, intptr_t in) {
 787     return with_status((intptr_t)k, in);
 788   }
 789 
 790   static void print_klass(outputStream* st, intptr_t k);
 791 
 792 protected:
 793   // ProfileData object these entries are part of
 794   ProfileData* _pd;
 795   // offset within the ProfileData object where the entries start
 796   const int _base_off;
 797 
 798   TypeEntries(int base_off)
 799     : _pd(nullptr), _base_off(base_off) {}
 800 
 801   void set_intptr_at(int index, intptr_t value) {
 802     _pd->set_intptr_at(index, value);
 803   }
 804 
 805   intptr_t intptr_at(int index) const {
 806     return _pd->intptr_at(index);
 807   }
 808 
 809 public:
 810   void set_profile_data(ProfileData* pd) {
 811     _pd = pd;
 812   }
 813 };
 814 
 815 // Type entries used for arguments passed at a call and parameters on
 816 // method entry. 2 cells per entry: one for the type encoded as in
 817 // TypeEntries and one initialized with the stack slot where the
 818 // profiled object is to be found so that the interpreter can locate
 819 // it quickly.
 820 class TypeStackSlotEntries : public TypeEntries {
 821 
 822 private:
 823   enum {
 824     stack_slot_entry,
 825     type_entry,
 826     per_arg_cell_count
 827   };
 828 
 829   // offset of cell for stack slot for entry i within ProfileData object
 830   int stack_slot_offset(int i) const {
 831     return _base_off + stack_slot_local_offset(i);
 832   }
 833 
 834   const int _number_of_entries;
 835 
 836   // offset of cell for type for entry i within ProfileData object
 837   int type_offset_in_cells(int i) const {
 838     return _base_off + type_local_offset(i);
 839   }
 840 
 841 public:
 842 
 843   TypeStackSlotEntries(int base_off, int nb_entries)
 844     : TypeEntries(base_off), _number_of_entries(nb_entries) {}
 845 
 846   static int compute_cell_count(Symbol* signature, bool include_receiver, int max);
 847 
 848   void post_initialize(Symbol* signature, bool has_receiver, bool include_receiver);
 849 
 850   int number_of_entries() const { return _number_of_entries; }
 851 
 852   // offset of cell for stack slot for entry i within this block of cells for a TypeStackSlotEntries
 853   static int stack_slot_local_offset(int i) {
 854     return i * per_arg_cell_count + stack_slot_entry;
 855   }
 856 
 857   // offset of cell for type for entry i within this block of cells for a TypeStackSlotEntries
 858   static int type_local_offset(int i) {
 859     return i * per_arg_cell_count + type_entry;
 860   }
 861 
 862   // stack slot for entry i
 863   uint stack_slot(int i) const {
 864     assert(i >= 0 && i < _number_of_entries, "oob");
 865     return _pd->uint_at(stack_slot_offset(i));
 866   }
 867 
 868   // set stack slot for entry i
 869   void set_stack_slot(int i, uint num) {
 870     assert(i >= 0 && i < _number_of_entries, "oob");
 871     _pd->set_uint_at(stack_slot_offset(i), num);
 872   }
 873 
 874   // type for entry i
 875   intptr_t type(int i) const {
 876     assert(i >= 0 && i < _number_of_entries, "oob");
 877     return _pd->intptr_at(type_offset_in_cells(i));
 878   }
 879 
 880   // set type for entry i
 881   void set_type(int i, intptr_t k) {
 882     assert(i >= 0 && i < _number_of_entries, "oob");
 883     _pd->set_intptr_at(type_offset_in_cells(i), k);
 884   }
 885 
 886   static ByteSize per_arg_size() {
 887     return in_ByteSize(per_arg_cell_count * DataLayout::cell_size);
 888   }
 889 
 890   static int per_arg_count() {
 891     return per_arg_cell_count;
 892   }
 893 
 894   ByteSize type_offset(int i) const {
 895     return DataLayout::cell_offset(type_offset_in_cells(i));
 896   }
 897 
 898   // GC support
 899   void clean_weak_klass_links(bool always_clean);
 900 
 901   void print_data_on(outputStream* st) const;
 902 };
 903 
 904 // Type entry used for return from a call. A single cell to record the
 905 // type.
 906 class SingleTypeEntry : public TypeEntries {
 907 
 908 private:
 909   enum {
 910     cell_count = 1
 911   };
 912 
 913 public:
 914   SingleTypeEntry(int base_off)
 915     : TypeEntries(base_off) {}
 916 
 917   void post_initialize() {
 918     set_type(type_none());
 919   }
 920 
 921   intptr_t type() const {
 922     return _pd->intptr_at(_base_off);
 923   }
 924 
 925   void set_type(intptr_t k) {
 926     _pd->set_intptr_at(_base_off, k);
 927   }
 928 
 929   static int static_cell_count() {
 930     return cell_count;
 931   }
 932 
 933   static ByteSize size() {
 934     return in_ByteSize(cell_count * DataLayout::cell_size);
 935   }
 936 
 937   ByteSize type_offset() {
 938     return DataLayout::cell_offset(_base_off);
 939   }
 940 
 941   // GC support
 942   void clean_weak_klass_links(bool always_clean);
 943 
 944   void print_data_on(outputStream* st) const;
 945 };
 946 
 947 // Entries to collect type information at a call: contains arguments
 948 // (TypeStackSlotEntries), a return type (SingleTypeEntry) and a
 949 // number of cells. Because the number of cells for the return type is
 950 // smaller than the number of cells for the type of an arguments, the
 951 // number of cells is used to tell how many arguments are profiled and
 952 // whether a return value is profiled. See has_arguments() and
 953 // has_return().
 954 class TypeEntriesAtCall {
 955 private:
 956   static int stack_slot_local_offset(int i) {
 957     return header_cell_count() + TypeStackSlotEntries::stack_slot_local_offset(i);
 958   }
 959 
 960   static int argument_type_local_offset(int i) {
 961     return header_cell_count() + TypeStackSlotEntries::type_local_offset(i);
 962   }
 963 
 964 public:
 965 
 966   static int header_cell_count() {
 967     return 1;
 968   }
 969 
 970   static int cell_count_local_offset() {
 971     return 0;
 972   }
 973 
 974   static int compute_cell_count(BytecodeStream* stream);
 975 
 976   static void initialize(DataLayout* dl, int base, int cell_count) {
 977     int off = base + cell_count_local_offset();
 978     dl->set_cell_at(off, cell_count - base - header_cell_count());
 979   }
 980 
 981   static bool arguments_profiling_enabled();
 982   static bool return_profiling_enabled();
 983 
 984   // Code generation support
 985   static ByteSize cell_count_offset() {
 986     return in_ByteSize(cell_count_local_offset() * DataLayout::cell_size);
 987   }
 988 
 989   static ByteSize args_data_offset() {
 990     return in_ByteSize(header_cell_count() * DataLayout::cell_size);
 991   }
 992 
 993   static ByteSize stack_slot_offset(int i) {
 994     return in_ByteSize(stack_slot_local_offset(i) * DataLayout::cell_size);
 995   }
 996 
 997   static ByteSize argument_type_offset(int i) {
 998     return in_ByteSize(argument_type_local_offset(i) * DataLayout::cell_size);
 999   }
1000 
1001   static ByteSize return_only_size() {
1002     return SingleTypeEntry::size() + in_ByteSize(header_cell_count() * DataLayout::cell_size);
1003   }
1004 
1005 };
1006 
1007 // CallTypeData
1008 //
1009 // A CallTypeData is used to access profiling information about a non
1010 // virtual call for which we collect type information about arguments
1011 // and return value.
1012 class CallTypeData : public CounterData {
1013 private:
1014   // entries for arguments if any
1015   TypeStackSlotEntries _args;
1016   // entry for return type if any
1017   SingleTypeEntry _ret;
1018 
1019   int cell_count_global_offset() const {
1020     return CounterData::static_cell_count() + TypeEntriesAtCall::cell_count_local_offset();
1021   }
1022 
1023   // number of cells not counting the header
1024   int cell_count_no_header() const {
1025     return uint_at(cell_count_global_offset());
1026   }
1027 
1028   void check_number_of_arguments(int total) {
1029     assert(number_of_arguments() == total, "should be set in DataLayout::initialize");
1030   }
1031 
1032 public:
1033   CallTypeData(DataLayout* layout) :
1034     CounterData(layout),
1035     _args(CounterData::static_cell_count()+TypeEntriesAtCall::header_cell_count(), number_of_arguments()),
1036     _ret(cell_count() - SingleTypeEntry::static_cell_count())
1037   {
1038     assert(layout->tag() == DataLayout::call_type_data_tag, "wrong type");
1039     // Some compilers (VC++) don't want this passed in member initialization list
1040     _args.set_profile_data(this);
1041     _ret.set_profile_data(this);
1042   }
1043 
1044   const TypeStackSlotEntries* args() const {
1045     assert(has_arguments(), "no profiling of arguments");
1046     return &_args;
1047   }
1048 
1049   const SingleTypeEntry* ret() const {
1050     assert(has_return(), "no profiling of return value");
1051     return &_ret;
1052   }
1053 
1054   virtual bool is_CallTypeData() const { return true; }
1055 
1056   static int static_cell_count() {
1057     return -1;
1058   }
1059 
1060   static int compute_cell_count(BytecodeStream* stream) {
1061     return CounterData::static_cell_count() + TypeEntriesAtCall::compute_cell_count(stream);
1062   }
1063 
1064   static void initialize(DataLayout* dl, int cell_count) {
1065     TypeEntriesAtCall::initialize(dl, CounterData::static_cell_count(), cell_count);
1066   }
1067 
1068   virtual void post_initialize(BytecodeStream* stream, MethodData* mdo);
1069 
1070   virtual int cell_count() const {
1071     return CounterData::static_cell_count() +
1072       TypeEntriesAtCall::header_cell_count() +
1073       int_at_unchecked(cell_count_global_offset());
1074   }
1075 
1076   int number_of_arguments() const {
1077     return cell_count_no_header() / TypeStackSlotEntries::per_arg_count();
1078   }
1079 
1080   void set_argument_type(int i, Klass* k) {
1081     assert(has_arguments(), "no arguments!");
1082     intptr_t current = _args.type(i);
1083     _args.set_type(i, TypeEntries::with_status(k, current));
1084   }
1085 
1086   void set_return_type(Klass* k) {
1087     assert(has_return(), "no return!");
1088     intptr_t current = _ret.type();
1089     _ret.set_type(TypeEntries::with_status(k, current));
1090   }
1091 
1092   // An entry for a return value takes less space than an entry for an
1093   // argument so if the number of cells exceeds the number of cells
1094   // needed for an argument, this object contains type information for
1095   // at least one argument.
1096   bool has_arguments() const {
1097     bool res = cell_count_no_header() >= TypeStackSlotEntries::per_arg_count();
1098     assert (!res || TypeEntriesAtCall::arguments_profiling_enabled(), "no profiling of arguments");
1099     return res;
1100   }
1101 
1102   // An entry for a return value takes less space than an entry for an
1103   // argument, so if the remainder of the number of cells divided by
1104   // the number of cells for an argument is not null, a return value
1105   // is profiled in this object.
1106   bool has_return() const {
1107     bool res = (cell_count_no_header() % TypeStackSlotEntries::per_arg_count()) != 0;
1108     assert (!res || TypeEntriesAtCall::return_profiling_enabled(), "no profiling of return values");
1109     return res;
1110   }
1111 
1112   // Code generation support
1113   static ByteSize args_data_offset() {
1114     return cell_offset(CounterData::static_cell_count()) + TypeEntriesAtCall::args_data_offset();
1115   }
1116 
1117   ByteSize argument_type_offset(int i) {
1118     return _args.type_offset(i);
1119   }
1120 
1121   ByteSize return_type_offset() {
1122     return _ret.type_offset();
1123   }
1124 
1125   // GC support
1126   virtual void clean_weak_klass_links(bool always_clean) {
1127     if (has_arguments()) {
1128       _args.clean_weak_klass_links(always_clean);
1129     }
1130     if (has_return()) {
1131       _ret.clean_weak_klass_links(always_clean);
1132     }
1133   }
1134 
1135   virtual void print_data_on(outputStream* st, const char* extra = nullptr) const;
1136 };
1137 
1138 // ReceiverTypeData
1139 //
1140 // A ReceiverTypeData is used to access profiling information about a
1141 // dynamic type check.  It consists of a series of (Klass*, count)
1142 // pairs which are used to store a type profile for the receiver of
1143 // the check, the associated count is incremented every time the type
1144 // is seen. A per ReceiverTypeData counter is incremented on type
1145 // overflow (when there's no more room for a not yet profiled Klass*).
1146 //
1147 class ReceiverTypeData : public CounterData {
1148   friend class VMStructs;
1149   friend class JVMCIVMStructs;
1150 protected:
1151   enum {
1152     receiver0_offset = counter_cell_count,
1153     count0_offset,
1154     receiver_type_row_cell_count = (count0_offset + 1) - receiver0_offset
1155   };
1156 
1157 public:
1158   ReceiverTypeData(DataLayout* layout) : CounterData(layout) {
1159     assert(layout->tag() == DataLayout::receiver_type_data_tag ||
1160            layout->tag() == DataLayout::virtual_call_data_tag ||
1161            layout->tag() == DataLayout::virtual_call_type_data_tag ||
1162            layout->tag() == DataLayout::array_store_data_tag, "wrong type");
1163   }
1164 
1165   virtual bool is_ReceiverTypeData() const { return true; }
1166 
1167   static int static_cell_count() {
1168     return counter_cell_count + (uint) TypeProfileWidth * receiver_type_row_cell_count;
1169   }
1170 
1171   virtual int cell_count() const {
1172     return static_cell_count();
1173   }
1174 
1175   // Direct accessors
1176   static uint row_limit() {
1177     return (uint) TypeProfileWidth;
1178   }
1179   static int receiver_cell_index(uint row) {
1180     return receiver0_offset + row * receiver_type_row_cell_count;
1181   }
1182   static int receiver_count_cell_index(uint row) {
1183     return count0_offset + row * receiver_type_row_cell_count;
1184   }
1185 
1186   Klass* receiver(uint row) const {
1187     assert(row < row_limit(), "oob");
1188 
1189     Klass* recv = (Klass*)intptr_at(receiver_cell_index(row));
1190     assert(recv == nullptr || recv->is_klass(), "wrong type");
1191     return recv;
1192   }
1193 
1194   void set_receiver(uint row, Klass* k) {
1195     assert((uint)row < row_limit(), "oob");
1196     set_intptr_at(receiver_cell_index(row), (uintptr_t)k);
1197   }
1198 
1199   uint receiver_count(uint row) const {
1200     assert(row < row_limit(), "oob");
1201     return uint_at(receiver_count_cell_index(row));
1202   }
1203 
1204   void set_receiver_count(uint row, uint count) {
1205     assert(row < row_limit(), "oob");
1206     set_uint_at(receiver_count_cell_index(row), count);
1207   }
1208 
1209   void clear_row(uint row) {
1210     assert(row < row_limit(), "oob");
1211     // Clear total count - indicator of polymorphic call site.
1212     // The site may look like as monomorphic after that but
1213     // it allow to have more accurate profiling information because
1214     // there was execution phase change since klasses were unloaded.
1215     // If the site is still polymorphic then MDO will be updated
1216     // to reflect it. But it could be the case that the site becomes
1217     // only bimorphic. Then keeping total count not 0 will be wrong.
1218     // Even if we use monomorphic (when it is not) for compilation
1219     // we will only have trap, deoptimization and recompile again
1220     // with updated MDO after executing method in Interpreter.
1221     // An additional receiver will be recorded in the cleaned row
1222     // during next call execution.
1223     //
1224     // Note: our profiling logic works with empty rows in any slot.
1225     // We do sorting a profiling info (ciCallProfile) for compilation.
1226     //
1227     set_count(0);
1228     set_receiver(row, nullptr);
1229     set_receiver_count(row, 0);
1230   }
1231 
1232   // Code generation support
1233   static ByteSize receiver_offset(uint row) {
1234     return cell_offset(receiver_cell_index(row));
1235   }
1236   static ByteSize receiver_count_offset(uint row) {
1237     return cell_offset(receiver_count_cell_index(row));
1238   }
1239   static ByteSize receiver_type_data_size() {
1240     return cell_offset(static_cell_count());
1241   }
1242 
1243   // GC support
1244   virtual void clean_weak_klass_links(bool always_clean);
1245 
1246   void print_receiver_data_on(outputStream* st) const;
1247   void print_data_on(outputStream* st, const char* extra = nullptr) const;
1248 };
1249 
1250 // VirtualCallData
1251 //
1252 // A VirtualCallData is used to access profiling information about a
1253 // virtual call.  For now, it has nothing more than a ReceiverTypeData.
1254 class VirtualCallData : public ReceiverTypeData {
1255 public:
1256   VirtualCallData(DataLayout* layout) : ReceiverTypeData(layout) {
1257     assert(layout->tag() == DataLayout::virtual_call_data_tag ||
1258            layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
1259   }
1260 
1261   virtual bool is_VirtualCallData() const { return true; }
1262 
1263   static int static_cell_count() {
1264     // At this point we could add more profile state, e.g., for arguments.
1265     // But for now it's the same size as the base record type.
1266     return ReceiverTypeData::static_cell_count();
1267   }
1268 
1269   virtual int cell_count() const {
1270     return static_cell_count();
1271   }
1272 
1273   // Direct accessors
1274   static ByteSize virtual_call_data_size() {
1275     return cell_offset(static_cell_count());
1276   }
1277 
1278   void print_method_data_on(outputStream* st) const NOT_JVMCI_RETURN;
1279   void print_data_on(outputStream* st, const char* extra = nullptr) const;
1280 };
1281 
1282 // VirtualCallTypeData
1283 //
1284 // A VirtualCallTypeData is used to access profiling information about
1285 // a virtual call for which we collect type information about
1286 // arguments and return value.
1287 class VirtualCallTypeData : public VirtualCallData {
1288 private:
1289   // entries for arguments if any
1290   TypeStackSlotEntries _args;
1291   // entry for return type if any
1292   SingleTypeEntry _ret;
1293 
1294   int cell_count_global_offset() const {
1295     return VirtualCallData::static_cell_count() + TypeEntriesAtCall::cell_count_local_offset();
1296   }
1297 
1298   // number of cells not counting the header
1299   int cell_count_no_header() const {
1300     return uint_at(cell_count_global_offset());
1301   }
1302 
1303   void check_number_of_arguments(int total) {
1304     assert(number_of_arguments() == total, "should be set in DataLayout::initialize");
1305   }
1306 
1307 public:
1308   VirtualCallTypeData(DataLayout* layout) :
1309     VirtualCallData(layout),
1310     _args(VirtualCallData::static_cell_count()+TypeEntriesAtCall::header_cell_count(), number_of_arguments()),
1311     _ret(cell_count() - SingleTypeEntry::static_cell_count())
1312   {
1313     assert(layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
1314     // Some compilers (VC++) don't want this passed in member initialization list
1315     _args.set_profile_data(this);
1316     _ret.set_profile_data(this);
1317   }
1318 
1319   const TypeStackSlotEntries* args() const {
1320     assert(has_arguments(), "no profiling of arguments");
1321     return &_args;
1322   }
1323 
1324   const SingleTypeEntry* ret() const {
1325     assert(has_return(), "no profiling of return value");
1326     return &_ret;
1327   }
1328 
1329   virtual bool is_VirtualCallTypeData() const { return true; }
1330 
1331   static int static_cell_count() {
1332     return -1;
1333   }
1334 
1335   static int compute_cell_count(BytecodeStream* stream) {
1336     return VirtualCallData::static_cell_count() + TypeEntriesAtCall::compute_cell_count(stream);
1337   }
1338 
1339   static void initialize(DataLayout* dl, int cell_count) {
1340     TypeEntriesAtCall::initialize(dl, VirtualCallData::static_cell_count(), cell_count);
1341   }
1342 
1343   virtual void post_initialize(BytecodeStream* stream, MethodData* mdo);
1344 
1345   virtual int cell_count() const {
1346     return VirtualCallData::static_cell_count() +
1347       TypeEntriesAtCall::header_cell_count() +
1348       int_at_unchecked(cell_count_global_offset());
1349   }
1350 
1351   int number_of_arguments() const {
1352     return cell_count_no_header() / TypeStackSlotEntries::per_arg_count();
1353   }
1354 
1355   void set_argument_type(int i, Klass* k) {
1356     assert(has_arguments(), "no arguments!");
1357     intptr_t current = _args.type(i);
1358     _args.set_type(i, TypeEntries::with_status(k, current));
1359   }
1360 
1361   void set_return_type(Klass* k) {
1362     assert(has_return(), "no return!");
1363     intptr_t current = _ret.type();
1364     _ret.set_type(TypeEntries::with_status(k, current));
1365   }
1366 
1367   // An entry for a return value takes less space than an entry for an
1368   // argument, so if the remainder of the number of cells divided by
1369   // the number of cells for an argument is not null, a return value
1370   // is profiled in this object.
1371   bool has_return() const {
1372     bool res = (cell_count_no_header() % TypeStackSlotEntries::per_arg_count()) != 0;
1373     assert (!res || TypeEntriesAtCall::return_profiling_enabled(), "no profiling of return values");
1374     return res;
1375   }
1376 
1377   // An entry for a return value takes less space than an entry for an
1378   // argument so if the number of cells exceeds the number of cells
1379   // needed for an argument, this object contains type information for
1380   // at least one argument.
1381   bool has_arguments() const {
1382     bool res = cell_count_no_header() >= TypeStackSlotEntries::per_arg_count();
1383     assert (!res || TypeEntriesAtCall::arguments_profiling_enabled(), "no profiling of arguments");
1384     return res;
1385   }
1386 
1387   // Code generation support
1388   static ByteSize args_data_offset() {
1389     return cell_offset(VirtualCallData::static_cell_count()) + TypeEntriesAtCall::args_data_offset();
1390   }
1391 
1392   ByteSize argument_type_offset(int i) {
1393     return _args.type_offset(i);
1394   }
1395 
1396   ByteSize return_type_offset() {
1397     return _ret.type_offset();
1398   }
1399 
1400   // GC support
1401   virtual void clean_weak_klass_links(bool always_clean) {
1402     ReceiverTypeData::clean_weak_klass_links(always_clean);
1403     if (has_arguments()) {
1404       _args.clean_weak_klass_links(always_clean);
1405     }
1406     if (has_return()) {
1407       _ret.clean_weak_klass_links(always_clean);
1408     }
1409   }
1410 
1411   virtual void print_data_on(outputStream* st, const char* extra = nullptr) const;
1412 };
1413 
1414 // RetData
1415 //
1416 // A RetData is used to access profiling information for a ret bytecode.
1417 // It is composed of a count of the number of times that the ret has
1418 // been executed, followed by a series of triples of the form
1419 // (bci, count, di) which count the number of times that some bci was the
1420 // target of the ret and cache a corresponding data displacement.
1421 class RetData : public CounterData {
1422 protected:
1423   enum {
1424     bci0_offset = counter_cell_count,
1425     count0_offset,
1426     displacement0_offset,
1427     ret_row_cell_count = (displacement0_offset + 1) - bci0_offset
1428   };
1429 
1430   void set_bci(uint row, int bci) {
1431     assert((uint)row < row_limit(), "oob");
1432     set_int_at(bci0_offset + row * ret_row_cell_count, bci);
1433   }
1434   void release_set_bci(uint row, int bci);
1435   void set_bci_count(uint row, uint count) {
1436     assert((uint)row < row_limit(), "oob");
1437     set_uint_at(count0_offset + row * ret_row_cell_count, count);
1438   }
1439   void set_bci_displacement(uint row, int disp) {
1440     set_int_at(displacement0_offset + row * ret_row_cell_count, disp);
1441   }
1442 
1443 public:
1444   RetData(DataLayout* layout) : CounterData(layout) {
1445     assert(layout->tag() == DataLayout::ret_data_tag, "wrong type");
1446   }
1447 
1448   virtual bool is_RetData() const { return true; }
1449 
1450   enum {
1451     no_bci = -1 // value of bci when bci1/2 are not in use.
1452   };
1453 
1454   static int static_cell_count() {
1455     return counter_cell_count + (uint) BciProfileWidth * ret_row_cell_count;
1456   }
1457 
1458   virtual int cell_count() const {
1459     return static_cell_count();
1460   }
1461 
1462   static uint row_limit() {
1463     return (uint) BciProfileWidth;
1464   }
1465   static int bci_cell_index(uint row) {
1466     return bci0_offset + row * ret_row_cell_count;
1467   }
1468   static int bci_count_cell_index(uint row) {
1469     return count0_offset + row * ret_row_cell_count;
1470   }
1471   static int bci_displacement_cell_index(uint row) {
1472     return displacement0_offset + row * ret_row_cell_count;
1473   }
1474 
1475   // Direct accessors
1476   int bci(uint row) const {
1477     return int_at(bci_cell_index(row));
1478   }
1479   uint bci_count(uint row) const {
1480     return uint_at(bci_count_cell_index(row));
1481   }
1482   int bci_displacement(uint row) const {
1483     return int_at(bci_displacement_cell_index(row));
1484   }
1485 
1486   // Interpreter Runtime support
1487   address fixup_ret(int return_bci, MethodData* mdo);
1488 
1489   // Code generation support
1490   static ByteSize bci_offset(uint row) {
1491     return cell_offset(bci_cell_index(row));
1492   }
1493   static ByteSize bci_count_offset(uint row) {
1494     return cell_offset(bci_count_cell_index(row));
1495   }
1496   static ByteSize bci_displacement_offset(uint row) {
1497     return cell_offset(bci_displacement_cell_index(row));
1498   }
1499 
1500   // Specific initialization.
1501   void post_initialize(BytecodeStream* stream, MethodData* mdo);
1502 
1503   void print_data_on(outputStream* st, const char* extra = nullptr) const;
1504 };
1505 
1506 // BranchData
1507 //
1508 // A BranchData is used to access profiling data for a two-way branch.
1509 // It consists of taken and not_taken counts as well as a data displacement
1510 // for the taken case.
1511 class BranchData : public JumpData {
1512   friend class VMStructs;
1513   friend class JVMCIVMStructs;
1514 protected:
1515   enum {
1516     not_taken_off_set = jump_cell_count,
1517     branch_cell_count
1518   };
1519 
1520   void set_displacement(int displacement) {
1521     set_int_at(displacement_off_set, displacement);
1522   }
1523 
1524 public:
1525   BranchData(DataLayout* layout) : JumpData(layout) {
1526     assert(layout->tag() == DataLayout::branch_data_tag || layout->tag() == DataLayout::acmp_data_tag, "wrong type");
1527   }
1528 
1529   virtual bool is_BranchData() const { return true; }
1530 
1531   static int static_cell_count() {
1532     return branch_cell_count;
1533   }
1534 
1535   virtual int cell_count() const {
1536     return static_cell_count();
1537   }
1538 
1539   // Direct accessor
1540   uint not_taken() const {
1541     return uint_at(not_taken_off_set);
1542   }
1543 
1544   void set_not_taken(uint cnt) {
1545     set_uint_at(not_taken_off_set, cnt);
1546   }
1547 
1548   uint inc_not_taken() {
1549     uint cnt = not_taken() + 1;
1550     // Did we wrap? Will compiler screw us??
1551     if (cnt == 0) cnt--;
1552     set_uint_at(not_taken_off_set, cnt);
1553     return cnt;
1554   }
1555 
1556   // Code generation support
1557   static ByteSize not_taken_offset() {
1558     return cell_offset(not_taken_off_set);
1559   }
1560   static ByteSize branch_data_size() {
1561     return cell_offset(branch_cell_count);
1562   }
1563 
1564   // Specific initialization.
1565   void post_initialize(BytecodeStream* stream, MethodData* mdo);
1566 
1567   void print_data_on(outputStream* st, const char* extra = nullptr) const;
1568 };
1569 
1570 // ArrayData
1571 //
1572 // A ArrayData is a base class for accessing profiling data which does
1573 // not have a statically known size.  It consists of an array length
1574 // and an array start.
1575 class ArrayData : public ProfileData {
1576   friend class VMStructs;
1577   friend class JVMCIVMStructs;
1578 protected:
1579   friend class DataLayout;
1580 
1581   enum {
1582     array_len_off_set,
1583     array_start_off_set
1584   };
1585 
1586   uint array_uint_at(int index) const {
1587     int aindex = index + array_start_off_set;
1588     return uint_at(aindex);
1589   }
1590   int array_int_at(int index) const {
1591     int aindex = index + array_start_off_set;
1592     return int_at(aindex);
1593   }
1594   oop array_oop_at(int index) const {
1595     int aindex = index + array_start_off_set;
1596     return oop_at(aindex);
1597   }
1598   void array_set_int_at(int index, int value) {
1599     int aindex = index + array_start_off_set;
1600     set_int_at(aindex, value);
1601   }
1602 
1603   // Code generation support for subclasses.
1604   static ByteSize array_element_offset(int index) {
1605     return cell_offset(array_start_off_set + index);
1606   }
1607 
1608 public:
1609   ArrayData(DataLayout* layout) : ProfileData(layout) {}
1610 
1611   virtual bool is_ArrayData() const { return true; }
1612 
1613   static int static_cell_count() {
1614     return -1;
1615   }
1616 
1617   int array_len() const {
1618     return int_at_unchecked(array_len_off_set);
1619   }
1620 
1621   virtual int cell_count() const {
1622     return array_len() + 1;
1623   }
1624 
1625   // Code generation support
1626   static ByteSize array_len_offset() {
1627     return cell_offset(array_len_off_set);
1628   }
1629   static ByteSize array_start_offset() {
1630     return cell_offset(array_start_off_set);
1631   }
1632 };
1633 
1634 // MultiBranchData
1635 //
1636 // A MultiBranchData is used to access profiling information for
1637 // a multi-way branch (*switch bytecodes).  It consists of a series
1638 // of (count, displacement) pairs, which count the number of times each
1639 // case was taken and specify the data displacement for each branch target.
1640 class MultiBranchData : public ArrayData {
1641   friend class VMStructs;
1642   friend class JVMCIVMStructs;
1643 protected:
1644   enum {
1645     default_count_off_set,
1646     default_disaplacement_off_set,
1647     case_array_start
1648   };
1649   enum {
1650     relative_count_off_set,
1651     relative_displacement_off_set,
1652     per_case_cell_count
1653   };
1654 
1655   void set_default_displacement(int displacement) {
1656     array_set_int_at(default_disaplacement_off_set, displacement);
1657   }
1658   void set_displacement_at(int index, int displacement) {
1659     array_set_int_at(case_array_start +
1660                      index * per_case_cell_count +
1661                      relative_displacement_off_set,
1662                      displacement);
1663   }
1664 
1665 public:
1666   MultiBranchData(DataLayout* layout) : ArrayData(layout) {
1667     assert(layout->tag() == DataLayout::multi_branch_data_tag, "wrong type");
1668   }
1669 
1670   virtual bool is_MultiBranchData() const { return true; }
1671 
1672   static int compute_cell_count(BytecodeStream* stream);
1673 
1674   int number_of_cases() const {
1675     int alen = array_len() - 2; // get rid of default case here.
1676     assert(alen % per_case_cell_count == 0, "must be even");
1677     return (alen / per_case_cell_count);
1678   }
1679 
1680   uint default_count() const {
1681     return array_uint_at(default_count_off_set);
1682   }
1683   int default_displacement() const {
1684     return array_int_at(default_disaplacement_off_set);
1685   }
1686 
1687   uint count_at(int index) const {
1688     return array_uint_at(case_array_start +
1689                          index * per_case_cell_count +
1690                          relative_count_off_set);
1691   }
1692   int displacement_at(int index) const {
1693     return array_int_at(case_array_start +
1694                         index * per_case_cell_count +
1695                         relative_displacement_off_set);
1696   }
1697 
1698   // Code generation support
1699   static ByteSize default_count_offset() {
1700     return array_element_offset(default_count_off_set);
1701   }
1702   static ByteSize default_displacement_offset() {
1703     return array_element_offset(default_disaplacement_off_set);
1704   }
1705   static ByteSize case_count_offset(int index) {
1706     return case_array_offset() +
1707            (per_case_size() * index) +
1708            relative_count_offset();
1709   }
1710   static ByteSize case_array_offset() {
1711     return array_element_offset(case_array_start);
1712   }
1713   static ByteSize per_case_size() {
1714     return in_ByteSize(per_case_cell_count) * cell_size;
1715   }
1716   static ByteSize relative_count_offset() {
1717     return in_ByteSize(relative_count_off_set) * cell_size;
1718   }
1719   static ByteSize relative_displacement_offset() {
1720     return in_ByteSize(relative_displacement_off_set) * cell_size;
1721   }
1722 
1723   // Specific initialization.
1724   void post_initialize(BytecodeStream* stream, MethodData* mdo);
1725 
1726   void print_data_on(outputStream* st, const char* extra = nullptr) const;
1727 };
1728 
1729 class ArgInfoData : public ArrayData {
1730 
1731 public:
1732   ArgInfoData(DataLayout* layout) : ArrayData(layout) {
1733     assert(layout->tag() == DataLayout::arg_info_data_tag, "wrong type");
1734   }
1735 
1736   virtual bool is_ArgInfoData() const { return true; }
1737 
1738 
1739   int number_of_args() const {
1740     return array_len();
1741   }
1742 
1743   uint arg_modified(int arg) const {
1744     return array_uint_at(arg);
1745   }
1746 
1747   void set_arg_modified(int arg, uint val) {
1748     array_set_int_at(arg, val);
1749   }
1750 
1751   void print_data_on(outputStream* st, const char* extra = nullptr) const;
1752 };
1753 
1754 // ParametersTypeData
1755 //
1756 // A ParametersTypeData is used to access profiling information about
1757 // types of parameters to a method
1758 class ParametersTypeData : public ArrayData {
1759 
1760 private:
1761   TypeStackSlotEntries _parameters;
1762 
1763   static int stack_slot_local_offset(int i) {
1764     assert_profiling_enabled();
1765     return array_start_off_set + TypeStackSlotEntries::stack_slot_local_offset(i);
1766   }
1767 
1768   static int type_local_offset(int i) {
1769     assert_profiling_enabled();
1770     return array_start_off_set + TypeStackSlotEntries::type_local_offset(i);
1771   }
1772 
1773   static bool profiling_enabled();
1774   static void assert_profiling_enabled() {
1775     assert(profiling_enabled(), "method parameters profiling should be on");
1776   }
1777 
1778 public:
1779   ParametersTypeData(DataLayout* layout) : ArrayData(layout), _parameters(1, number_of_parameters()) {
1780     assert(layout->tag() == DataLayout::parameters_type_data_tag, "wrong type");
1781     // Some compilers (VC++) don't want this passed in member initialization list
1782     _parameters.set_profile_data(this);
1783   }
1784 
1785   static int compute_cell_count(Method* m);
1786 
1787   virtual bool is_ParametersTypeData() const { return true; }
1788 
1789   virtual void post_initialize(BytecodeStream* stream, MethodData* mdo);
1790 
1791   int number_of_parameters() const {
1792     return array_len() / TypeStackSlotEntries::per_arg_count();
1793   }
1794 
1795   const TypeStackSlotEntries* parameters() const { return &_parameters; }
1796 
1797   uint stack_slot(int i) const {
1798     return _parameters.stack_slot(i);
1799   }
1800 
1801   void set_type(int i, Klass* k) {
1802     intptr_t current = _parameters.type(i);
1803     _parameters.set_type(i, TypeEntries::with_status((intptr_t)k, current));
1804   }
1805 
1806   virtual void clean_weak_klass_links(bool always_clean) {
1807     _parameters.clean_weak_klass_links(always_clean);
1808   }
1809 
1810   virtual void print_data_on(outputStream* st, const char* extra = nullptr) const;
1811 
1812   static ByteSize stack_slot_offset(int i) {
1813     return cell_offset(stack_slot_local_offset(i));
1814   }
1815 
1816   static ByteSize type_offset(int i) {
1817     return cell_offset(type_local_offset(i));
1818   }
1819 };
1820 
1821 // SpeculativeTrapData
1822 //
1823 // A SpeculativeTrapData is used to record traps due to type
1824 // speculation. It records the root of the compilation: that type
1825 // speculation is wrong in the context of one compilation (for
1826 // method1) doesn't mean it's wrong in the context of another one (for
1827 // method2). Type speculation could have more/different data in the
1828 // context of the compilation of method2 and it's worthwhile to try an
1829 // optimization that failed for compilation of method1 in the context
1830 // of compilation of method2.
1831 // Space for SpeculativeTrapData entries is allocated from the extra
1832 // data space in the MDO. If we run out of space, the trap data for
1833 // the ProfileData at that bci is updated.
1834 class SpeculativeTrapData : public ProfileData {
1835 protected:
1836   enum {
1837     speculative_trap_method,
1838 #ifndef _LP64
1839     // The size of the area for traps is a multiple of the header
1840     // size, 2 cells on 32 bits. Packed at the end of this area are
1841     // argument info entries (with tag
1842     // DataLayout::arg_info_data_tag). The logic in
1843     // MethodData::bci_to_extra_data() that guarantees traps don't
1844     // overflow over argument info entries assumes the size of a
1845     // SpeculativeTrapData is twice the header size. On 32 bits, a
1846     // SpeculativeTrapData must be 4 cells.
1847     padding,
1848 #endif
1849     speculative_trap_cell_count
1850   };
1851 public:
1852   SpeculativeTrapData(DataLayout* layout) : ProfileData(layout) {
1853     assert(layout->tag() == DataLayout::speculative_trap_data_tag, "wrong type");
1854   }
1855 
1856   virtual bool is_SpeculativeTrapData() const { return true; }
1857 
1858   static int static_cell_count() {
1859     return speculative_trap_cell_count;
1860   }
1861 
1862   virtual int cell_count() const {
1863     return static_cell_count();
1864   }
1865 
1866   // Direct accessor
1867   Method* method() const {
1868     return (Method*)intptr_at(speculative_trap_method);
1869   }
1870 
1871   void set_method(Method* m) {
1872     assert(!m->is_old(), "cannot add old methods");
1873     set_intptr_at(speculative_trap_method, (intptr_t)m);
1874   }
1875 
1876   static ByteSize method_offset() {
1877     return cell_offset(speculative_trap_method);
1878   }
1879 
1880   virtual void print_data_on(outputStream* st, const char* extra = nullptr) const;
1881 };
1882 
1883 class ArrayStoreData : public ReceiverTypeData {
1884 private:
1885   enum {
1886     flat_array_flag = BitData::last_bit_data_flag,
1887     null_free_array_flag = flat_array_flag + 1,
1888   };
1889 
1890   SingleTypeEntry _array;
1891 
1892 public:
1893   ArrayStoreData(DataLayout* layout) :
1894     ReceiverTypeData(layout),
1895     _array(ReceiverTypeData::static_cell_count()) {
1896     assert(layout->tag() == DataLayout::array_store_data_tag, "wrong type");
1897     _array.set_profile_data(this);
1898   }
1899 
1900   const SingleTypeEntry* array() const {
1901     return &_array;
1902   }
1903 
1904   virtual bool is_ArrayStoreData() const { return true; }
1905 
1906   static int static_cell_count() {
1907     return ReceiverTypeData::static_cell_count() + SingleTypeEntry::static_cell_count();
1908   }
1909 
1910   virtual int cell_count() const {
1911     return static_cell_count();
1912   }
1913 
1914   void set_flat_array() { set_flag_at(flat_array_flag); }
1915   bool flat_array() const { return flag_at(flat_array_flag); }
1916 
1917   void set_null_free_array() { set_flag_at(null_free_array_flag); }
1918   bool null_free_array() const { return flag_at(null_free_array_flag); }
1919 
1920   // Code generation support
1921   static int flat_array_byte_constant() {
1922     return flag_number_to_constant(flat_array_flag);
1923   }
1924 
1925   static int null_free_array_byte_constant() {
1926     return flag_number_to_constant(null_free_array_flag);
1927   }
1928 
1929   static ByteSize array_offset() {
1930     return cell_offset(ReceiverTypeData::static_cell_count());
1931   }
1932 
1933   virtual void clean_weak_klass_links(bool always_clean) {
1934     ReceiverTypeData::clean_weak_klass_links(always_clean);
1935     _array.clean_weak_klass_links(always_clean);
1936   }
1937 
1938   static ByteSize array_store_data_size() {
1939     return cell_offset(static_cell_count());
1940   }
1941 
1942   virtual void print_data_on(outputStream* st, const char* extra = nullptr) const;
1943 };
1944 
1945 class ArrayLoadData : public ProfileData {
1946 private:
1947   enum {
1948     flat_array_flag = DataLayout::first_flag,
1949     null_free_array_flag = flat_array_flag + 1,
1950   };
1951 
1952   SingleTypeEntry _array;
1953   SingleTypeEntry _element;
1954 
1955 public:
1956   ArrayLoadData(DataLayout* layout) :
1957     ProfileData(layout),
1958     _array(0),
1959     _element(SingleTypeEntry::static_cell_count()) {
1960     assert(layout->tag() == DataLayout::array_load_data_tag, "wrong type");
1961     _array.set_profile_data(this);
1962     _element.set_profile_data(this);
1963   }
1964 
1965   const SingleTypeEntry* array() const {
1966     return &_array;
1967   }
1968 
1969   const SingleTypeEntry* element() const {
1970     return &_element;
1971   }
1972 
1973   virtual bool is_ArrayLoadData() const { return true; }
1974 
1975   static int static_cell_count() {
1976     return SingleTypeEntry::static_cell_count() * 2;
1977   }
1978 
1979   virtual int cell_count() const {
1980     return static_cell_count();
1981   }
1982 
1983   void set_flat_array() { set_flag_at(flat_array_flag); }
1984   bool flat_array() const { return flag_at(flat_array_flag); }
1985 
1986   void set_null_free_array() { set_flag_at(null_free_array_flag); }
1987   bool null_free_array() const { return flag_at(null_free_array_flag); }
1988 
1989   // Code generation support
1990   static int flat_array_byte_constant() {
1991     return flag_number_to_constant(flat_array_flag);
1992   }
1993 
1994   static int null_free_array_byte_constant() {
1995     return flag_number_to_constant(null_free_array_flag);
1996   }
1997 
1998   static ByteSize array_offset() {
1999     return cell_offset(0);
2000   }
2001 
2002   static ByteSize element_offset() {
2003     return cell_offset(SingleTypeEntry::static_cell_count());
2004   }
2005 
2006   virtual void clean_weak_klass_links(bool always_clean) {
2007     _array.clean_weak_klass_links(always_clean);
2008     _element.clean_weak_klass_links(always_clean);
2009   }
2010 
2011   static ByteSize array_load_data_size() {
2012     return cell_offset(static_cell_count());
2013   }
2014 
2015   virtual void print_data_on(outputStream* st, const char* extra = nullptr) const;
2016 };
2017 
2018 class ACmpData : public BranchData {
2019 private:
2020   enum {
2021     left_inline_type_flag = DataLayout::first_flag,
2022     right_inline_type_flag
2023   };
2024 
2025   SingleTypeEntry _left;
2026   SingleTypeEntry _right;
2027 
2028 public:
2029   ACmpData(DataLayout* layout) :
2030     BranchData(layout),
2031     _left(BranchData::static_cell_count()),
2032     _right(BranchData::static_cell_count() + SingleTypeEntry::static_cell_count()) {
2033     assert(layout->tag() == DataLayout::acmp_data_tag, "wrong type");
2034     _left.set_profile_data(this);
2035     _right.set_profile_data(this);
2036   }
2037 
2038   const SingleTypeEntry* left() const {
2039     return &_left;
2040   }
2041 
2042   const SingleTypeEntry* right() const {
2043     return &_right;
2044   }
2045 
2046   virtual bool is_ACmpData() const { return true; }
2047 
2048   static int static_cell_count() {
2049     return BranchData::static_cell_count() + SingleTypeEntry::static_cell_count() * 2;
2050   }
2051 
2052   virtual int cell_count() const {
2053     return static_cell_count();
2054   }
2055 
2056   void set_left_inline_type() { set_flag_at(left_inline_type_flag); }
2057   bool left_inline_type() const { return flag_at(left_inline_type_flag); }
2058 
2059   void set_right_inline_type() { set_flag_at(right_inline_type_flag); }
2060   bool right_inline_type() const { return flag_at(right_inline_type_flag); }
2061 
2062   // Code generation support
2063   static int left_inline_type_byte_constant() {
2064     return flag_number_to_constant(left_inline_type_flag);
2065   }
2066 
2067   static int right_inline_type_byte_constant() {
2068     return flag_number_to_constant(right_inline_type_flag);
2069   }
2070 
2071   static ByteSize left_offset() {
2072     return cell_offset(BranchData::static_cell_count());
2073   }
2074 
2075   static ByteSize right_offset() {
2076     return cell_offset(BranchData::static_cell_count() + SingleTypeEntry::static_cell_count());
2077   }
2078 
2079   virtual void clean_weak_klass_links(bool always_clean) {
2080     _left.clean_weak_klass_links(always_clean);
2081     _right.clean_weak_klass_links(always_clean);
2082   }
2083 
2084   static ByteSize acmp_data_size() {
2085     return cell_offset(static_cell_count());
2086   }
2087 
2088   virtual void print_data_on(outputStream* st, const char* extra = nullptr) const;
2089 };
2090 
2091 // MethodData*
2092 //
2093 // A MethodData* holds information which has been collected about
2094 // a method.  Its layout looks like this:
2095 //
2096 // -----------------------------
2097 // | header                    |
2098 // | klass                     |
2099 // -----------------------------
2100 // | method                    |
2101 // | size of the MethodData* |
2102 // -----------------------------
2103 // | Data entries...           |
2104 // |   (variable size)         |
2105 // |                           |
2106 // .                           .
2107 // .                           .
2108 // .                           .
2109 // |                           |
2110 // -----------------------------
2111 //
2112 // The data entry area is a heterogeneous array of DataLayouts. Each
2113 // DataLayout in the array corresponds to a specific bytecode in the
2114 // method.  The entries in the array are sorted by the corresponding
2115 // bytecode.  Access to the data is via resource-allocated ProfileData,
2116 // which point to the underlying blocks of DataLayout structures.
2117 //
2118 // During interpretation, if profiling in enabled, the interpreter
2119 // maintains a method data pointer (mdp), which points at the entry
2120 // in the array corresponding to the current bci.  In the course of
2121 // interpretation, when a bytecode is encountered that has profile data
2122 // associated with it, the entry pointed to by mdp is updated, then the
2123 // mdp is adjusted to point to the next appropriate DataLayout.  If mdp
2124 // is null to begin with, the interpreter assumes that the current method
2125 // is not (yet) being profiled.
2126 //
2127 // In MethodData* parlance, "dp" is a "data pointer", the actual address
2128 // of a DataLayout element.  A "di" is a "data index", the offset in bytes
2129 // from the base of the data entry array.  A "displacement" is the byte offset
2130 // in certain ProfileData objects that indicate the amount the mdp must be
2131 // adjusted in the event of a change in control flow.
2132 //
2133 
2134 class CleanExtraDataClosure : public StackObj {
2135 public:
2136   virtual bool is_live(Method* m) = 0;
2137 };
2138 
2139 
2140 #if INCLUDE_JVMCI
2141 // Encapsulates an encoded speculation reason. These are linked together in
2142 // a list that is atomically appended to during deoptimization. Entries are
2143 // never removed from the list.
2144 // @see jdk.vm.ci.hotspot.HotSpotSpeculationLog.HotSpotSpeculationEncoding
2145 class FailedSpeculation: public CHeapObj<mtCompiler> {
2146  private:
2147   // The length of HotSpotSpeculationEncoding.toByteArray(). The data itself
2148   // is an array embedded at the end of this object.
2149   int   _data_len;
2150 
2151   // Next entry in a linked list.
2152   FailedSpeculation* _next;
2153 
2154   FailedSpeculation(address data, int data_len);
2155 
2156   FailedSpeculation** next_adr() { return &_next; }
2157 
2158   // Placement new operator for inlining the speculation data into
2159   // the FailedSpeculation object.
2160   void* operator new(size_t size, size_t fs_size) throw();
2161 
2162  public:
2163   char* data()         { return (char*)(((address) this) + sizeof(FailedSpeculation)); }
2164   int data_len() const { return _data_len; }
2165   FailedSpeculation* next() const { return _next; }
2166 
2167   // Atomically appends a speculation from nm to the list whose head is at (*failed_speculations_address).
2168   // Returns false if the FailedSpeculation object could not be allocated.
2169   static bool add_failed_speculation(nmethod* nm, FailedSpeculation** failed_speculations_address, address speculation, int speculation_len);
2170 
2171   // Frees all entries in the linked list whose head is at (*failed_speculations_address).
2172   static void free_failed_speculations(FailedSpeculation** failed_speculations_address);
2173 };
2174 #endif
2175 
2176 class ciMethodData;
2177 
2178 class MethodData : public Metadata {
2179   friend class VMStructs;
2180   friend class JVMCIVMStructs;
2181   friend class ProfileData;
2182   friend class TypeEntriesAtCall;
2183   friend class ciMethodData;
2184 
2185   // If you add a new field that points to any metaspace object, you
2186   // must add this field to MethodData::metaspace_pointers_do().
2187 
2188   // Back pointer to the Method*
2189   Method* _method;
2190 
2191   // Size of this oop in bytes
2192   int _size;
2193 
2194   // Cached hint for bci_to_dp and bci_to_data
2195   int _hint_di;
2196 
2197   Mutex _extra_data_lock;
2198 
2199   MethodData(const methodHandle& method);
2200 public:
2201   static MethodData* allocate(ClassLoaderData* loader_data, const methodHandle& method, TRAPS);
2202 
2203   virtual bool is_methodData() const { return true; }
2204   void initialize();
2205 
2206   // Whole-method sticky bits and flags
2207   enum {
2208     _trap_hist_limit    = Deoptimization::Reason_TRAP_HISTORY_LENGTH,
2209     _trap_hist_mask     = max_jubyte,
2210     _extra_data_count   = 4     // extra DataLayout headers, for trap history
2211   }; // Public flag values
2212 
2213   // Compiler-related counters.
2214   class CompilerCounters {
2215     friend class VMStructs;
2216     friend class JVMCIVMStructs;
2217 
2218     uint _nof_decompiles;             // count of all nmethod removals
2219     uint _nof_overflow_recompiles;    // recompile count, excluding recomp. bits
2220     uint _nof_overflow_traps;         // trap count, excluding _trap_hist
2221     union {
2222       intptr_t _align;
2223       // JVMCI separates trap history for OSR compilations from normal compilations
2224       u1 _array[JVMCI_ONLY(2 *) MethodData::_trap_hist_limit];
2225     } _trap_hist;
2226 
2227   public:
2228     CompilerCounters() : _nof_decompiles(0), _nof_overflow_recompiles(0), _nof_overflow_traps(0) {
2229 #ifndef ZERO
2230       // Some Zero platforms do not have expected alignment, and do not use
2231       // this code. static_assert would still fire and fail for them.
2232       static_assert(sizeof(_trap_hist) % HeapWordSize == 0, "align");
2233 #endif
2234       uint size_in_words = sizeof(_trap_hist) / HeapWordSize;
2235       Copy::zero_to_words((HeapWord*) &_trap_hist, size_in_words);
2236     }
2237 
2238     // Return (uint)-1 for overflow.
2239     uint trap_count(int reason) const {
2240       assert((uint)reason < ARRAY_SIZE(_trap_hist._array), "oob");
2241       return (int)((_trap_hist._array[reason]+1) & _trap_hist_mask) - 1;
2242     }
2243 
2244     uint inc_trap_count(int reason) {
2245       // Count another trap, anywhere in this method.
2246       assert(reason >= 0, "must be single trap");
2247       assert((uint)reason < ARRAY_SIZE(_trap_hist._array), "oob");
2248       uint cnt1 = 1 + _trap_hist._array[reason];
2249       if ((cnt1 & _trap_hist_mask) != 0) {  // if no counter overflow...
2250         _trap_hist._array[reason] = (u1)cnt1;
2251         return cnt1;
2252       } else {
2253         return _trap_hist_mask + (++_nof_overflow_traps);
2254       }
2255     }
2256 
2257     uint overflow_trap_count() const {
2258       return _nof_overflow_traps;
2259     }
2260     uint overflow_recompile_count() const {
2261       return _nof_overflow_recompiles;
2262     }
2263     uint inc_overflow_recompile_count() {
2264       return ++_nof_overflow_recompiles;
2265     }
2266     uint decompile_count() const {
2267       return _nof_decompiles;
2268     }
2269     uint inc_decompile_count() {
2270       return ++_nof_decompiles;
2271     }
2272 
2273     // Support for code generation
2274     static ByteSize trap_history_offset() {
2275       return byte_offset_of(CompilerCounters, _trap_hist._array);
2276     }
2277   };
2278 
2279 private:
2280   CompilerCounters _compiler_counters;
2281 
2282   // Support for interprocedural escape analysis, from Thomas Kotzmann.
2283   intx              _eflags;          // flags on escape information
2284   intx              _arg_local;       // bit set of non-escaping arguments
2285   intx              _arg_stack;       // bit set of stack-allocatable arguments
2286   intx              _arg_returned;    // bit set of returned arguments
2287 
2288   int               _creation_mileage; // method mileage at MDO creation
2289 
2290   // How many invocations has this MDO seen?
2291   // These counters are used to determine the exact age of MDO.
2292   // We need those because in tiered a method can be concurrently
2293   // executed at different levels.
2294   InvocationCounter _invocation_counter;
2295   // Same for backedges.
2296   InvocationCounter _backedge_counter;
2297   // Counter values at the time profiling started.
2298   int               _invocation_counter_start;
2299   int               _backedge_counter_start;
2300   uint              _tenure_traps;
2301   int               _invoke_mask;      // per-method Tier0InvokeNotifyFreqLog
2302   int               _backedge_mask;    // per-method Tier0BackedgeNotifyFreqLog
2303 
2304   // Number of loops and blocks is computed when compiling the first
2305   // time with C1. It is used to determine if method is trivial.
2306   short             _num_loops;
2307   short             _num_blocks;
2308   // Does this method contain anything worth profiling?
2309   enum WouldProfile {unknown, no_profile, profile};
2310   WouldProfile      _would_profile;
2311 
2312 #if INCLUDE_JVMCI
2313   // Support for HotSpotMethodData.setCompiledIRSize(int)
2314   FailedSpeculation* _failed_speculations;
2315   int                _jvmci_ir_size;
2316 #endif
2317 
2318   // Size of _data array in bytes.  (Excludes header and extra_data fields.)
2319   int _data_size;
2320 
2321   // data index for the area dedicated to parameters. -1 if no
2322   // parameter profiling.
2323   enum { no_parameters = -2, parameters_uninitialized = -1 };
2324   int _parameters_type_data_di;
2325 
2326   // data index of exception handler profiling data
2327   int _exception_handler_data_di;
2328 
2329   // Beginning of the data entries
2330   // See comment in ciMethodData::load_data
2331   intptr_t _data[1];
2332 
2333   // Helper for size computation
2334   static int compute_data_size(BytecodeStream* stream);
2335   static int bytecode_cell_count(Bytecodes::Code code);
2336   static bool is_speculative_trap_bytecode(Bytecodes::Code code);
2337   enum { no_profile_data = -1, variable_cell_count = -2 };
2338 
2339   // Helper for initialization
2340   DataLayout* data_layout_at(int data_index) const {
2341     assert(data_index % sizeof(intptr_t) == 0, "unaligned");
2342     return (DataLayout*) (((address)_data) + data_index);
2343   }
2344 
2345   static int single_exception_handler_data_cell_count() {
2346     return BitData::static_cell_count();
2347   }
2348 
2349   static int single_exception_handler_data_size() {
2350     return DataLayout::compute_size_in_bytes(single_exception_handler_data_cell_count());
2351   }
2352 
2353   DataLayout* exception_handler_data_at(int exception_handler_index) const {
2354     return data_layout_at(_exception_handler_data_di + (exception_handler_index * single_exception_handler_data_size()));
2355   }
2356 
2357   int num_exception_handler_data() const {
2358     return exception_handlers_data_size() / single_exception_handler_data_size();
2359   }
2360 
2361   // Initialize an individual data segment.  Returns the size of
2362   // the segment in bytes.
2363   int initialize_data(BytecodeStream* stream, int data_index);
2364 
2365   // Helper for data_at
2366   DataLayout* limit_data_position() const {
2367     return data_layout_at(_data_size);
2368   }
2369   bool out_of_bounds(int data_index) const {
2370     return data_index >= data_size();
2371   }
2372 
2373   // Give each of the data entries a chance to perform specific
2374   // data initialization.
2375   void post_initialize(BytecodeStream* stream);
2376 
2377   // hint accessors
2378   int      hint_di() const  { return _hint_di; }
2379   void set_hint_di(int di)  {
2380     assert(!out_of_bounds(di), "hint_di out of bounds");
2381     _hint_di = di;
2382   }
2383 
2384   DataLayout* data_layout_before(int bci) {
2385     // avoid SEGV on this edge case
2386     if (data_size() == 0)
2387       return nullptr;
2388     DataLayout* layout = data_layout_at(hint_di());
2389     if (layout->bci() <= bci)
2390       return layout;
2391     return data_layout_at(first_di());
2392   }
2393 
2394   // What is the index of the first data entry?
2395   int first_di() const { return 0; }
2396 
2397   ProfileData* bci_to_extra_data_find(int bci, Method* m, DataLayout*& dp);
2398   // Find or create an extra ProfileData:
2399   ProfileData* bci_to_extra_data(int bci, Method* m, bool create_if_missing);
2400 
2401   // return the argument info cell
2402   ArgInfoData *arg_info();
2403 
2404   enum {
2405     no_type_profile = 0,
2406     type_profile_jsr292 = 1,
2407     type_profile_all = 2
2408   };
2409 
2410   static bool profile_jsr292(const methodHandle& m, int bci);
2411   static bool profile_unsafe(const methodHandle& m, int bci);
2412   static bool profile_memory_access(const methodHandle& m, int bci);
2413   static int profile_arguments_flag();
2414   static bool profile_all_arguments();
2415   static bool profile_arguments_for_invoke(const methodHandle& m, int bci);
2416   static int profile_return_flag();
2417   static bool profile_all_return();
2418   static bool profile_return_for_invoke(const methodHandle& m, int bci);
2419   static int profile_parameters_flag();
2420   static bool profile_parameters_jsr292_only();
2421   static bool profile_all_parameters();
2422 
2423   void clean_extra_data_helper(DataLayout* dp, int shift, bool reset = false);
2424   void verify_extra_data_clean(CleanExtraDataClosure* cl);
2425 
2426   DataLayout* exception_handler_bci_to_data_helper(int bci);
2427 
2428 public:
2429   void clean_extra_data(CleanExtraDataClosure* cl);
2430 
2431   static int header_size() {
2432     return sizeof(MethodData)/wordSize;
2433   }
2434 
2435   // Compute the size of a MethodData* before it is created.
2436   static int compute_allocation_size_in_bytes(const methodHandle& method);
2437   static int compute_allocation_size_in_words(const methodHandle& method);
2438   static int compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps);
2439 
2440   // Determine if a given bytecode can have profile information.
2441   static bool bytecode_has_profile(Bytecodes::Code code) {
2442     return bytecode_cell_count(code) != no_profile_data;
2443   }
2444 
2445   // reset into original state
2446   void init();
2447 
2448   // My size
2449   int size_in_bytes() const { return _size; }
2450   int size() const    { return align_metadata_size(align_up(_size, BytesPerWord)/BytesPerWord); }
2451 
2452   int      creation_mileage() const { return _creation_mileage; }
2453   void set_creation_mileage(int x)  { _creation_mileage = x; }
2454 
2455   int invocation_count() {
2456     if (invocation_counter()->carry()) {
2457       return InvocationCounter::count_limit;
2458     }
2459     return invocation_counter()->count();
2460   }
2461   int backedge_count() {
2462     if (backedge_counter()->carry()) {
2463       return InvocationCounter::count_limit;
2464     }
2465     return backedge_counter()->count();
2466   }
2467 
2468   int invocation_count_start() {
2469     if (invocation_counter()->carry()) {
2470       return 0;
2471     }
2472     return _invocation_counter_start;
2473   }
2474 
2475   int backedge_count_start() {
2476     if (backedge_counter()->carry()) {
2477       return 0;
2478     }
2479     return _backedge_counter_start;
2480   }
2481 
2482   int invocation_count_delta() { return invocation_count() - invocation_count_start(); }
2483   int backedge_count_delta()   { return backedge_count()   - backedge_count_start();   }
2484 
2485   void reset_start_counters() {
2486     _invocation_counter_start = invocation_count();
2487     _backedge_counter_start = backedge_count();
2488   }
2489 
2490   InvocationCounter* invocation_counter()     { return &_invocation_counter; }
2491   InvocationCounter* backedge_counter()       { return &_backedge_counter;   }
2492 
2493 #if INCLUDE_JVMCI
2494   FailedSpeculation** get_failed_speculations_address() {
2495     return &_failed_speculations;
2496   }
2497 #endif
2498 
2499   void set_would_profile(bool p)              { _would_profile = p ? profile : no_profile; }
2500   bool would_profile() const                  { return _would_profile != no_profile; }
2501 
2502   int num_loops() const                       { return _num_loops;  }
2503   void set_num_loops(short n)                 { _num_loops = n;     }
2504   int num_blocks() const                      { return _num_blocks; }
2505   void set_num_blocks(short n)                { _num_blocks = n;    }
2506 
2507   bool is_mature() const;  // consult mileage and ProfileMaturityPercentage
2508   static int mileage_of(Method* m);
2509 
2510   // Support for interprocedural escape analysis, from Thomas Kotzmann.
2511   enum EscapeFlag {
2512     estimated    = 1 << 0,
2513     return_local = 1 << 1,
2514     return_allocated = 1 << 2,
2515     allocated_escapes = 1 << 3,
2516     unknown_modified = 1 << 4
2517   };
2518 
2519   intx eflags()                                  { return _eflags; }
2520   intx arg_local()                               { return _arg_local; }
2521   intx arg_stack()                               { return _arg_stack; }
2522   intx arg_returned()                            { return _arg_returned; }
2523   uint arg_modified(int a);
2524   void set_eflags(intx v)                        { _eflags = v; }
2525   void set_arg_local(intx v)                     { _arg_local = v; }
2526   void set_arg_stack(intx v)                     { _arg_stack = v; }
2527   void set_arg_returned(intx v)                  { _arg_returned = v; }
2528   void set_arg_modified(int a, uint v);
2529   void clear_escape_info()                       { _eflags = _arg_local = _arg_stack = _arg_returned = 0; }
2530 
2531   // Location and size of data area
2532   address data_base() const {
2533     return (address) _data;
2534   }
2535   int data_size() const {
2536     return _data_size;
2537   }
2538 
2539   int parameters_size_in_bytes() const {
2540     return pointer_delta_as_int((address) parameters_data_limit(), (address) parameters_data_base());
2541   }
2542 
2543   int exception_handlers_data_size() const {
2544     return pointer_delta_as_int((address) exception_handler_data_limit(), (address) exception_handler_data_base());
2545   }
2546 
2547   // Accessors
2548   Method* method() const { return _method; }
2549 
2550   // Get the data at an arbitrary (sort of) data index.
2551   ProfileData* data_at(int data_index) const;
2552 
2553   // Walk through the data in order.
2554   ProfileData* first_data() const { return data_at(first_di()); }
2555   ProfileData* next_data(ProfileData* current) const;
2556   DataLayout*  next_data_layout(DataLayout* current) const;
2557   bool is_valid(ProfileData* current) const { return current != nullptr; }
2558   bool is_valid(DataLayout*  current) const { return current != nullptr; }
2559 
2560   // Convert a dp (data pointer) to a di (data index).
2561   int dp_to_di(address dp) const {
2562     return (int)(dp - ((address)_data));
2563   }
2564 
2565   // bci to di/dp conversion.
2566   address bci_to_dp(int bci);
2567   int bci_to_di(int bci) {
2568     return dp_to_di(bci_to_dp(bci));
2569   }
2570 
2571   // Get the data at an arbitrary bci, or null if there is none.
2572   ProfileData* bci_to_data(int bci);
2573 
2574   // Same, but try to create an extra_data record if one is needed:
2575   ProfileData* allocate_bci_to_data(int bci, Method* m) {
2576     check_extra_data_locked();
2577 
2578     ProfileData* data = nullptr;
2579     // If m not null, try to allocate a SpeculativeTrapData entry
2580     if (m == nullptr) {
2581       data = bci_to_data(bci);
2582     }
2583     if (data != nullptr) {
2584       return data;
2585     }
2586     data = bci_to_extra_data(bci, m, true);
2587     if (data != nullptr) {
2588       return data;
2589     }
2590     // If SpeculativeTrapData allocation fails try to allocate a
2591     // regular entry
2592     data = bci_to_data(bci);
2593     if (data != nullptr) {
2594       return data;
2595     }
2596     return bci_to_extra_data(bci, nullptr, true);
2597   }
2598 
2599   BitData* exception_handler_bci_to_data_or_null(int bci);
2600   BitData exception_handler_bci_to_data(int bci);
2601 
2602   // Add a handful of extra data records, for trap tracking.
2603   // Only valid after 'set_size' is called at the end of MethodData::initialize
2604   DataLayout* extra_data_base() const  {
2605     check_extra_data_locked();
2606     return limit_data_position();
2607   }
2608   DataLayout* extra_data_limit() const { return (DataLayout*)((address)this + size_in_bytes()); }
2609   // pointers to sections in extra data
2610   DataLayout* args_data_limit() const  { return parameters_data_base(); }
2611   DataLayout* parameters_data_base() const {
2612     assert(_parameters_type_data_di != parameters_uninitialized, "called too early");
2613     return _parameters_type_data_di != no_parameters ? data_layout_at(_parameters_type_data_di) : parameters_data_limit();
2614   }
2615   DataLayout* parameters_data_limit() const {
2616     assert(_parameters_type_data_di != parameters_uninitialized, "called too early");
2617     return exception_handler_data_base();
2618   }
2619   DataLayout* exception_handler_data_base() const { return data_layout_at(_exception_handler_data_di); }
2620   DataLayout* exception_handler_data_limit() const { return extra_data_limit(); }
2621 
2622   int extra_data_size() const          { return (int)((address)extra_data_limit() - (address)limit_data_position()); }
2623   static DataLayout* next_extra(DataLayout* dp);
2624 
2625   // Return (uint)-1 for overflow.
2626   uint trap_count(int reason) const {
2627     return _compiler_counters.trap_count(reason);
2628   }
2629   // For loops:
2630   static uint trap_reason_limit() { return _trap_hist_limit; }
2631   static uint trap_count_limit()  { return _trap_hist_mask; }
2632   uint inc_trap_count(int reason) {
2633     return _compiler_counters.inc_trap_count(reason);
2634   }
2635 
2636   uint overflow_trap_count() const {
2637     return _compiler_counters.overflow_trap_count();
2638   }
2639   uint overflow_recompile_count() const {
2640     return _compiler_counters.overflow_recompile_count();
2641   }
2642   uint inc_overflow_recompile_count() {
2643     return _compiler_counters.inc_overflow_recompile_count();
2644   }
2645   uint decompile_count() const {
2646     return _compiler_counters.decompile_count();
2647   }
2648   uint inc_decompile_count() {
2649     uint dec_count = _compiler_counters.inc_decompile_count();
2650     if (dec_count > (uint)PerMethodRecompilationCutoff) {
2651       method()->set_not_compilable("decompile_count > PerMethodRecompilationCutoff", CompLevel_full_optimization);
2652     }
2653     return dec_count;
2654   }
2655   uint tenure_traps() const {
2656     return _tenure_traps;
2657   }
2658   void inc_tenure_traps() {
2659     _tenure_traps += 1;
2660   }
2661 
2662   // Return pointer to area dedicated to parameters in MDO
2663   ParametersTypeData* parameters_type_data() const {
2664     assert(_parameters_type_data_di != parameters_uninitialized, "called too early");
2665     return _parameters_type_data_di != no_parameters ? data_layout_at(_parameters_type_data_di)->data_in()->as_ParametersTypeData() : nullptr;
2666   }
2667 
2668   int parameters_type_data_di() const {
2669     assert(_parameters_type_data_di != parameters_uninitialized, "called too early");
2670     return _parameters_type_data_di != no_parameters ? _parameters_type_data_di : exception_handlers_data_di();
2671   }
2672 
2673   int exception_handlers_data_di() const {
2674     return _exception_handler_data_di;
2675   }
2676 
2677   // Support for code generation
2678   static ByteSize data_offset() {
2679     return byte_offset_of(MethodData, _data[0]);
2680   }
2681 
2682   static ByteSize trap_history_offset() {
2683     return byte_offset_of(MethodData, _compiler_counters) + CompilerCounters::trap_history_offset();
2684   }
2685 
2686   static ByteSize invocation_counter_offset() {
2687     return byte_offset_of(MethodData, _invocation_counter);
2688   }
2689 
2690   static ByteSize backedge_counter_offset() {
2691     return byte_offset_of(MethodData, _backedge_counter);
2692   }
2693 
2694   static ByteSize invoke_mask_offset() {
2695     return byte_offset_of(MethodData, _invoke_mask);
2696   }
2697 
2698   static ByteSize backedge_mask_offset() {
2699     return byte_offset_of(MethodData, _backedge_mask);
2700   }
2701 
2702   static ByteSize parameters_type_data_di_offset() {
2703     return byte_offset_of(MethodData, _parameters_type_data_di);
2704   }
2705 
2706   virtual void metaspace_pointers_do(MetaspaceClosure* iter);
2707   virtual MetaspaceObj::Type type() const { return MethodDataType; }
2708 
2709   // Deallocation support
2710   void deallocate_contents(ClassLoaderData* loader_data);
2711   void release_C_heap_structures();
2712 
2713   // GC support
2714   void set_size(int object_size_in_bytes) { _size = object_size_in_bytes; }
2715 
2716   // Printing
2717   void print_on      (outputStream* st) const;
2718   void print_value_on(outputStream* st) const;
2719 
2720   // printing support for method data
2721   void print_data_on(outputStream* st) const;
2722 
2723   const char* internal_name() const { return "{method data}"; }
2724 
2725   // verification
2726   void verify_on(outputStream* st);
2727   void verify_data_on(outputStream* st);
2728 
2729   static bool profile_parameters_for_method(const methodHandle& m);
2730   static bool profile_arguments();
2731   static bool profile_arguments_jsr292_only();
2732   static bool profile_return();
2733   static bool profile_parameters();
2734   static bool profile_return_jsr292_only();
2735 
2736   void clean_method_data(bool always_clean);
2737   void clean_weak_method_links();
2738   Mutex* extra_data_lock() { return &_extra_data_lock; }
2739   void check_extra_data_locked() const NOT_DEBUG_RETURN;
2740 };
2741 
2742 #endif // SHARE_OOPS_METHODDATA_HPP