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