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