src/share/vm/oops/methodData.hpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/oops

src/share/vm/oops/methodData.hpp

Print this page
rev 5349 : 8023657: New type profiling points: arguments to call
Summary: x86 interpreter and c1 type profiling for arguments at calls
Reviewed-by:


 100 public:
 101   enum {
 102     counter_increment = 1
 103   };
 104 
 105   enum {
 106     cell_size = sizeof(intptr_t)
 107   };
 108 
 109   // Tag values
 110   enum {
 111     no_tag,
 112     bit_data_tag,
 113     counter_data_tag,
 114     jump_data_tag,
 115     receiver_type_data_tag,
 116     virtual_call_data_tag,
 117     ret_data_tag,
 118     branch_data_tag,
 119     multi_branch_data_tag,
 120     arg_info_data_tag


 121   };
 122 
 123   enum {
 124     // The _struct._flags word is formatted as [trap_state:4 | flags:4].
 125     // The trap state breaks down further as [recompile:1 | reason:3].
 126     // This further breakdown is defined in deoptimization.cpp.
 127     // See Deoptimization::trap_state_reason for an assert that
 128     // trap_bits is big enough to hold reasons < Reason_RECORDED_LIMIT.
 129     //
 130     // The trap_state is collected only if ProfileTraps is true.
 131     trap_bits = 1+3,  // 3: enough to distinguish [0..Reason_RECORDED_LIMIT].
 132     trap_shift = BitsPerByte - trap_bits,
 133     trap_mask = right_n_bits(trap_bits),
 134     trap_mask_in_place = (trap_mask << trap_shift),
 135     flag_limit = trap_shift,
 136     flag_mask = right_n_bits(flag_limit),
 137     first_flag = 0
 138   };
 139 
 140   // Size computation


 148   static int compute_size_in_bytes(int cell_count) {
 149     return header_size_in_bytes() + cell_count * cell_size;
 150   }
 151 
 152   // Initialization
 153   void initialize(u1 tag, u2 bci, int cell_count);
 154 
 155   // Accessors
 156   u1 tag() {
 157     return _header._struct._tag;
 158   }
 159 
 160   // Return a few bits of trap state.  Range is [0..trap_mask].
 161   // The state tells if traps with zero, one, or many reasons have occurred.
 162   // It also tells whether zero or many recompilations have occurred.
 163   // The associated trap histogram in the MDO itself tells whether
 164   // traps are common or not.  If a BCI shows that a trap X has
 165   // occurred, and the MDO shows N occurrences of X, we make the
 166   // simplifying assumption that all N occurrences can be blamed
 167   // on that BCI.
 168   int trap_state() {
 169     return ((_header._struct._flags >> trap_shift) & trap_mask);
 170   }
 171 
 172   void set_trap_state(int new_state) {
 173     assert(ProfileTraps, "used only under +ProfileTraps");
 174     uint old_flags = (_header._struct._flags & flag_mask);
 175     _header._struct._flags = (new_state << trap_shift) | old_flags;
 176   }
 177 
 178   u1 flags() {
 179     return _header._struct._flags;
 180   }
 181 
 182   u2 bci() {
 183     return _header._struct._bci;
 184   }
 185 
 186   void set_header(intptr_t value) {
 187     _header._bits = value;
 188   }
 189   void release_set_header(intptr_t value) {
 190     OrderAccess::release_store_ptr(&_header._bits, value);
 191   }
 192   intptr_t header() {
 193     return _header._bits;
 194   }
 195   void set_cell_at(int index, intptr_t value) {
 196     _cells[index] = value;
 197   }
 198   void release_set_cell_at(int index, intptr_t value) {
 199     OrderAccess::release_store_ptr(&_cells[index], value);
 200   }
 201   intptr_t cell_at(int index) {
 202     return _cells[index];
 203   }
 204 
 205   void set_flag_at(int flag_number) {
 206     assert(flag_number < flag_limit, "oob");
 207     _header._struct._flags |= (0x1 << flag_number);
 208   }
 209   bool flag_at(int flag_number) {
 210     assert(flag_number < flag_limit, "oob");
 211     return (_header._struct._flags & (0x1 << flag_number)) != 0;
 212   }
 213 
 214   // Low-level support for code generation.
 215   static ByteSize header_offset() {
 216     return byte_offset_of(DataLayout, _header);
 217   }
 218   static ByteSize tag_offset() {
 219     return byte_offset_of(DataLayout, _header._struct._tag);
 220   }
 221   static ByteSize flags_offset() {
 222     return byte_offset_of(DataLayout, _header._struct._flags);
 223   }
 224   static ByteSize bci_offset() {
 225     return byte_offset_of(DataLayout, _header._struct._bci);
 226   }
 227   static ByteSize cell_offset(int index) {
 228     return byte_offset_of(DataLayout, _cells) + in_ByteSize(index * cell_size);
 229   }


 237   // Return a value which, when or-ed as a word into _header, sets the flag.
 238   static intptr_t flag_mask_to_header_mask(int byte_constant) {
 239     DataLayout temp; temp.set_header(0);
 240     temp._header._struct._flags = byte_constant;
 241     return temp._header._bits;
 242   }
 243 
 244   ProfileData* data_in();
 245 
 246   // GC support
 247   void clean_weak_klass_links(BoolObjectClosure* cl);
 248 };
 249 
 250 
 251 // ProfileData class hierarchy
 252 class ProfileData;
 253 class   BitData;
 254 class     CounterData;
 255 class       ReceiverTypeData;
 256 class         VirtualCallData;

 257 class       RetData;

 258 class   JumpData;
 259 class     BranchData;
 260 class   ArrayData;
 261 class     MultiBranchData;
 262 class     ArgInfoData;
 263 
 264 
 265 // ProfileData
 266 //
 267 // A ProfileData object is created to refer to a section of profiling
 268 // data in a structured way.
 269 class ProfileData : public ResourceObj {


 270 private:
 271 #ifndef PRODUCT
 272   enum {
 273     tab_width_one = 16,
 274     tab_width_two = 36
 275   };
 276 #endif // !PRODUCT
 277 
 278   // This is a pointer to a section of profiling data.
 279   DataLayout* _data;
 280 
 281 protected:
 282   DataLayout* data() { return _data; }

 283 
 284   enum {
 285     cell_size = DataLayout::cell_size
 286   };
 287 
 288 public:
 289   // How many cells are in this?
 290   virtual int cell_count() {
 291     ShouldNotReachHere();
 292     return -1;
 293   }
 294 
 295   // Return the size of this data.
 296   int size_in_bytes() {
 297     return DataLayout::compute_size_in_bytes(cell_count());
 298   }
 299 
 300 protected:
 301   // Low-level accessors for underlying data
 302   void set_intptr_at(int index, intptr_t value) {
 303     assert(0 <= index && index < cell_count(), "oob");
 304     data()->set_cell_at(index, value);
 305   }
 306   void release_set_intptr_at(int index, intptr_t value) {
 307     assert(0 <= index && index < cell_count(), "oob");
 308     data()->release_set_cell_at(index, value);
 309   }
 310   intptr_t intptr_at(int index) {
 311     assert(0 <= index && index < cell_count(), "oob");
 312     return data()->cell_at(index);
 313   }
 314   void set_uint_at(int index, uint value) {
 315     set_intptr_at(index, (intptr_t) value);
 316   }
 317   void release_set_uint_at(int index, uint value) {
 318     release_set_intptr_at(index, (intptr_t) value);
 319   }
 320   uint uint_at(int index) {
 321     return (uint)intptr_at(index);
 322   }
 323   void set_int_at(int index, int value) {
 324     set_intptr_at(index, (intptr_t) value);
 325   }
 326   void release_set_int_at(int index, int value) {
 327     release_set_intptr_at(index, (intptr_t) value);
 328   }
 329   int int_at(int index) {
 330     return (int)intptr_at(index);
 331   }
 332   int int_at_unchecked(int index) {
 333     return (int)data()->cell_at(index);
 334   }
 335   void set_oop_at(int index, oop value) {
 336     set_intptr_at(index, (intptr_t) value);
 337   }
 338   oop oop_at(int index) {
 339     return (oop)intptr_at(index);
 340   }
 341 
 342   void set_flag_at(int flag_number) {
 343     data()->set_flag_at(flag_number);
 344   }
 345   bool flag_at(int flag_number) {
 346     return data()->flag_at(flag_number);
 347   }
 348 
 349   // two convenient imports for use by subclasses:
 350   static ByteSize cell_offset(int index) {
 351     return DataLayout::cell_offset(index);
 352   }
 353   static int flag_number_to_byte_constant(int flag_number) {
 354     return DataLayout::flag_number_to_byte_constant(flag_number);
 355   }
 356 
 357   ProfileData(DataLayout* data) {
 358     _data = data;
 359   }
 360 
 361 public:
 362   // Constructor for invalid ProfileData.
 363   ProfileData();
 364 
 365   u2 bci() {
 366     return data()->bci();
 367   }
 368 
 369   address dp() {
 370     return (address)_data;
 371   }
 372 
 373   int trap_state() {
 374     return data()->trap_state();
 375   }
 376   void set_trap_state(int new_state) {
 377     data()->set_trap_state(new_state);
 378   }
 379 
 380   // Type checking
 381   virtual bool is_BitData()         { return false; }
 382   virtual bool is_CounterData()     { return false; }
 383   virtual bool is_JumpData()        { return false; }
 384   virtual bool is_ReceiverTypeData(){ return false; }
 385   virtual bool is_VirtualCallData() { return false; }
 386   virtual bool is_RetData()         { return false; }
 387   virtual bool is_BranchData()      { return false; }
 388   virtual bool is_ArrayData()       { return false; }
 389   virtual bool is_MultiBranchData() { return false; }
 390   virtual bool is_ArgInfoData()     { return false; }


 391 
 392 
 393   BitData* as_BitData() {
 394     assert(is_BitData(), "wrong type");
 395     return is_BitData()         ? (BitData*)        this : NULL;
 396   }
 397   CounterData* as_CounterData() {
 398     assert(is_CounterData(), "wrong type");
 399     return is_CounterData()     ? (CounterData*)    this : NULL;
 400   }
 401   JumpData* as_JumpData() {
 402     assert(is_JumpData(), "wrong type");
 403     return is_JumpData()        ? (JumpData*)       this : NULL;
 404   }
 405   ReceiverTypeData* as_ReceiverTypeData() {
 406     assert(is_ReceiverTypeData(), "wrong type");
 407     return is_ReceiverTypeData() ? (ReceiverTypeData*)this : NULL;
 408   }
 409   VirtualCallData* as_VirtualCallData() {
 410     assert(is_VirtualCallData(), "wrong type");
 411     return is_VirtualCallData() ? (VirtualCallData*)this : NULL;
 412   }
 413   RetData* as_RetData() {
 414     assert(is_RetData(), "wrong type");
 415     return is_RetData()         ? (RetData*)        this : NULL;
 416   }
 417   BranchData* as_BranchData() {
 418     assert(is_BranchData(), "wrong type");
 419     return is_BranchData()      ? (BranchData*)     this : NULL;
 420   }
 421   ArrayData* as_ArrayData() {
 422     assert(is_ArrayData(), "wrong type");
 423     return is_ArrayData()       ? (ArrayData*)      this : NULL;
 424   }
 425   MultiBranchData* as_MultiBranchData() {
 426     assert(is_MultiBranchData(), "wrong type");
 427     return is_MultiBranchData() ? (MultiBranchData*)this : NULL;
 428   }
 429   ArgInfoData* as_ArgInfoData() {
 430     assert(is_ArgInfoData(), "wrong type");
 431     return is_ArgInfoData() ? (ArgInfoData*)this : NULL;
 432   }








 433 
 434 
 435   // Subclass specific initialization
 436   virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {}
 437 
 438   // GC support
 439   virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {}
 440 
 441   // CI translation: ProfileData can represent both MethodDataOop data
 442   // as well as CIMethodData data. This function is provided for translating
 443   // an oop in a ProfileData to the ci equivalent. Generally speaking,
 444   // most ProfileData don't require any translation, so we provide the null
 445   // translation here, and the required translators are in the ci subclasses.
 446   virtual void translate_from(ProfileData* data) {}
 447 
 448   virtual void print_data_on(outputStream* st) {
 449     ShouldNotReachHere();
 450   }
 451 
 452 #ifndef PRODUCT
 453   void print_shared(outputStream* st, const char* name);
 454   void tab(outputStream* st);
 455 #endif
 456 };
 457 
 458 // BitData
 459 //
 460 // A BitData holds a flag or two in its header.
 461 class BitData : public ProfileData {
 462 protected:
 463   enum {
 464     // null_seen:
 465     //  saw a null operand (cast/aastore/instanceof)
 466     null_seen_flag              = DataLayout::first_flag + 0
 467   };
 468   enum { bit_cell_count = 0 };  // no additional data fields needed.
 469 public:
 470   BitData(DataLayout* layout) : ProfileData(layout) {
 471   }
 472 
 473   virtual bool is_BitData() { return true; }
 474 
 475   static int static_cell_count() {
 476     return bit_cell_count;
 477   }
 478 
 479   virtual int cell_count() {
 480     return static_cell_count();
 481   }
 482 
 483   // Accessor
 484 
 485   // The null_seen flag bit is specially known to the interpreter.
 486   // Consulting it allows the compiler to avoid setting up null_check traps.
 487   bool null_seen()     { return flag_at(null_seen_flag); }
 488   void set_null_seen()    { set_flag_at(null_seen_flag); }
 489 
 490 
 491   // Code generation support
 492   static int null_seen_byte_constant() {
 493     return flag_number_to_byte_constant(null_seen_flag);
 494   }
 495 
 496   static ByteSize bit_data_size() {
 497     return cell_offset(bit_cell_count);
 498   }
 499 
 500 #ifndef PRODUCT
 501   void print_data_on(outputStream* st);
 502 #endif
 503 };
 504 
 505 // CounterData
 506 //
 507 // A CounterData corresponds to a simple counter.
 508 class CounterData : public BitData {
 509 protected:
 510   enum {
 511     count_off,
 512     counter_cell_count
 513   };
 514 public:
 515   CounterData(DataLayout* layout) : BitData(layout) {}
 516 
 517   virtual bool is_CounterData() { return true; }
 518 
 519   static int static_cell_count() {
 520     return counter_cell_count;
 521   }
 522 
 523   virtual int cell_count() {
 524     return static_cell_count();
 525   }
 526 
 527   // Direct accessor
 528   uint count() {
 529     return uint_at(count_off);
 530   }
 531 
 532   // Code generation support
 533   static ByteSize count_offset() {
 534     return cell_offset(count_off);
 535   }
 536   static ByteSize counter_data_size() {
 537     return cell_offset(counter_cell_count);
 538   }
 539 
 540   void set_count(uint count) {
 541     set_uint_at(count_off, count);
 542   }
 543 
 544 #ifndef PRODUCT
 545   void print_data_on(outputStream* st);
 546 #endif
 547 };
 548 
 549 // JumpData
 550 //
 551 // A JumpData is used to access profiling information for a direct
 552 // branch.  It is a counter, used for counting the number of branches,
 553 // plus a data displacement, used for realigning the data pointer to
 554 // the corresponding target bci.
 555 class JumpData : public ProfileData {
 556 protected:
 557   enum {
 558     taken_off_set,
 559     displacement_off_set,
 560     jump_cell_count
 561   };
 562 
 563   void set_displacement(int displacement) {
 564     set_int_at(displacement_off_set, displacement);
 565   }
 566 
 567 public:
 568   JumpData(DataLayout* layout) : ProfileData(layout) {
 569     assert(layout->tag() == DataLayout::jump_data_tag ||
 570       layout->tag() == DataLayout::branch_data_tag, "wrong type");
 571   }
 572 
 573   virtual bool is_JumpData() { return true; }
 574 
 575   static int static_cell_count() {
 576     return jump_cell_count;
 577   }
 578 
 579   virtual int cell_count() {
 580     return static_cell_count();
 581   }
 582 
 583   // Direct accessor
 584   uint taken() {
 585     return uint_at(taken_off_set);
 586   }
 587 
 588   void set_taken(uint cnt) {
 589     set_uint_at(taken_off_set, cnt);
 590   }
 591 
 592   // Saturating counter
 593   uint inc_taken() {
 594     uint cnt = taken() + 1;
 595     // Did we wrap? Will compiler screw us??
 596     if (cnt == 0) cnt--;
 597     set_uint_at(taken_off_set, cnt);
 598     return cnt;
 599   }
 600 
 601   int displacement() {
 602     return int_at(displacement_off_set);
 603   }
 604 
 605   // Code generation support
 606   static ByteSize taken_offset() {
 607     return cell_offset(taken_off_set);
 608   }
 609 
 610   static ByteSize displacement_offset() {
 611     return cell_offset(displacement_off_set);
 612   }
 613 
 614   // Specific initialization.
 615   void post_initialize(BytecodeStream* stream, MethodData* mdo);
 616 
 617 #ifndef PRODUCT
 618   void print_data_on(outputStream* st);






























































































































































































































































































































 619 #endif
 620 };
 621 
 622 // ReceiverTypeData
 623 //
 624 // A ReceiverTypeData is used to access profiling information about a
 625 // dynamic type check.  It consists of a counter which counts the total times
 626 // that the check is reached, and a series of (Klass*, count) pairs
 627 // which are used to store a type profile for the receiver of the check.
 628 class ReceiverTypeData : public CounterData {
 629 protected:
 630   enum {
 631     receiver0_offset = counter_cell_count,
 632     count0_offset,
 633     receiver_type_row_cell_count = (count0_offset + 1) - receiver0_offset
 634   };
 635 
 636 public:
 637   ReceiverTypeData(DataLayout* layout) : CounterData(layout) {
 638     assert(layout->tag() == DataLayout::receiver_type_data_tag ||
 639            layout->tag() == DataLayout::virtual_call_data_tag, "wrong type");

 640   }
 641 
 642   virtual bool is_ReceiverTypeData() { return true; }
 643 
 644   static int static_cell_count() {
 645     return counter_cell_count + (uint) TypeProfileWidth * receiver_type_row_cell_count;
 646   }
 647 
 648   virtual int cell_count() {
 649     return static_cell_count();
 650   }
 651 
 652   // Direct accessors
 653   static uint row_limit() {
 654     return TypeProfileWidth;
 655   }
 656   static int receiver_cell_index(uint row) {
 657     return receiver0_offset + row * receiver_type_row_cell_count;
 658   }
 659   static int receiver_count_cell_index(uint row) {
 660     return count0_offset + row * receiver_type_row_cell_count;
 661   }
 662 
 663   Klass* receiver(uint row) {
 664     assert(row < row_limit(), "oob");
 665 
 666     Klass* recv = (Klass*)intptr_at(receiver_cell_index(row));
 667     assert(recv == NULL || recv->is_klass(), "wrong type");
 668     return recv;
 669   }
 670 
 671   void set_receiver(uint row, Klass* k) {
 672     assert((uint)row < row_limit(), "oob");
 673     set_intptr_at(receiver_cell_index(row), (uintptr_t)k);
 674   }
 675 
 676   uint receiver_count(uint row) {
 677     assert(row < row_limit(), "oob");
 678     return uint_at(receiver_count_cell_index(row));
 679   }
 680 
 681   void set_receiver_count(uint row, uint count) {
 682     assert(row < row_limit(), "oob");
 683     set_uint_at(receiver_count_cell_index(row), count);
 684   }
 685 
 686   void clear_row(uint row) {
 687     assert(row < row_limit(), "oob");
 688     // Clear total count - indicator of polymorphic call site.
 689     // The site may look like as monomorphic after that but
 690     // it allow to have more accurate profiling information because
 691     // there was execution phase change since klasses were unloaded.
 692     // If the site is still polymorphic then MDO will be updated
 693     // to reflect it. But it could be the case that the site becomes
 694     // only bimorphic. Then keeping total count not 0 will be wrong.
 695     // Even if we use monomorphic (when it is not) for compilation
 696     // we will only have trap, deoptimization and recompile again


 704     set_count(0);
 705     set_receiver(row, NULL);
 706     set_receiver_count(row, 0);
 707   }
 708 
 709   // Code generation support
 710   static ByteSize receiver_offset(uint row) {
 711     return cell_offset(receiver_cell_index(row));
 712   }
 713   static ByteSize receiver_count_offset(uint row) {
 714     return cell_offset(receiver_count_cell_index(row));
 715   }
 716   static ByteSize receiver_type_data_size() {
 717     return cell_offset(static_cell_count());
 718   }
 719 
 720   // GC support
 721   virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
 722 
 723 #ifndef PRODUCT
 724   void print_receiver_data_on(outputStream* st);
 725   void print_data_on(outputStream* st);
 726 #endif
 727 };
 728 
 729 // VirtualCallData
 730 //
 731 // A VirtualCallData is used to access profiling information about a
 732 // virtual call.  For now, it has nothing more than a ReceiverTypeData.
 733 class VirtualCallData : public ReceiverTypeData {
 734 public:
 735   VirtualCallData(DataLayout* layout) : ReceiverTypeData(layout) {
 736     assert(layout->tag() == DataLayout::virtual_call_data_tag, "wrong type");

 737   }
 738 
 739   virtual bool is_VirtualCallData() { return true; }
 740 
 741   static int static_cell_count() {
 742     // At this point we could add more profile state, e.g., for arguments.
 743     // But for now it's the same size as the base record type.
 744     return ReceiverTypeData::static_cell_count();
 745   }
 746 
 747   virtual int cell_count() {
 748     return static_cell_count();
 749   }
 750 
 751   // Direct accessors
 752   static ByteSize virtual_call_data_size() {
 753     return cell_offset(static_cell_count());
 754   }
 755 
 756 #ifndef PRODUCT
 757   void print_data_on(outputStream* st);
































































 758 #endif
 759 };
 760 
 761 // RetData
 762 //
 763 // A RetData is used to access profiling information for a ret bytecode.
 764 // It is composed of a count of the number of times that the ret has
 765 // been executed, followed by a series of triples of the form
 766 // (bci, count, di) which count the number of times that some bci was the
 767 // target of the ret and cache a corresponding data displacement.
 768 class RetData : public CounterData {
 769 protected:
 770   enum {
 771     bci0_offset = counter_cell_count,
 772     count0_offset,
 773     displacement0_offset,
 774     ret_row_cell_count = (displacement0_offset + 1) - bci0_offset
 775   };
 776 
 777   void set_bci(uint row, int bci) {


 780   }
 781   void release_set_bci(uint row, int bci) {
 782     assert((uint)row < row_limit(), "oob");
 783     // 'release' when setting the bci acts as a valid flag for other
 784     // threads wrt bci_count and bci_displacement.
 785     release_set_int_at(bci0_offset + row * ret_row_cell_count, bci);
 786   }
 787   void set_bci_count(uint row, uint count) {
 788     assert((uint)row < row_limit(), "oob");
 789     set_uint_at(count0_offset + row * ret_row_cell_count, count);
 790   }
 791   void set_bci_displacement(uint row, int disp) {
 792     set_int_at(displacement0_offset + row * ret_row_cell_count, disp);
 793   }
 794 
 795 public:
 796   RetData(DataLayout* layout) : CounterData(layout) {
 797     assert(layout->tag() == DataLayout::ret_data_tag, "wrong type");
 798   }
 799 
 800   virtual bool is_RetData() { return true; }
 801 
 802   enum {
 803     no_bci = -1 // value of bci when bci1/2 are not in use.
 804   };
 805 
 806   static int static_cell_count() {
 807     return counter_cell_count + (uint) BciProfileWidth * ret_row_cell_count;
 808   }
 809 
 810   virtual int cell_count() {
 811     return static_cell_count();
 812   }
 813 
 814   static uint row_limit() {
 815     return BciProfileWidth;
 816   }
 817   static int bci_cell_index(uint row) {
 818     return bci0_offset + row * ret_row_cell_count;
 819   }
 820   static int bci_count_cell_index(uint row) {
 821     return count0_offset + row * ret_row_cell_count;
 822   }
 823   static int bci_displacement_cell_index(uint row) {
 824     return displacement0_offset + row * ret_row_cell_count;
 825   }
 826 
 827   // Direct accessors
 828   int bci(uint row) {
 829     return int_at(bci_cell_index(row));
 830   }
 831   uint bci_count(uint row) {
 832     return uint_at(bci_count_cell_index(row));
 833   }
 834   int bci_displacement(uint row) {
 835     return int_at(bci_displacement_cell_index(row));
 836   }
 837 
 838   // Interpreter Runtime support
 839   address fixup_ret(int return_bci, MethodData* mdo);
 840 
 841   // Code generation support
 842   static ByteSize bci_offset(uint row) {
 843     return cell_offset(bci_cell_index(row));
 844   }
 845   static ByteSize bci_count_offset(uint row) {
 846     return cell_offset(bci_count_cell_index(row));
 847   }
 848   static ByteSize bci_displacement_offset(uint row) {
 849     return cell_offset(bci_displacement_cell_index(row));
 850   }
 851 
 852   // Specific initialization.
 853   void post_initialize(BytecodeStream* stream, MethodData* mdo);
 854 
 855 #ifndef PRODUCT
 856   void print_data_on(outputStream* st);
 857 #endif
 858 };
 859 
 860 // BranchData
 861 //
 862 // A BranchData is used to access profiling data for a two-way branch.
 863 // It consists of taken and not_taken counts as well as a data displacement
 864 // for the taken case.
 865 class BranchData : public JumpData {
 866 protected:
 867   enum {
 868     not_taken_off_set = jump_cell_count,
 869     branch_cell_count
 870   };
 871 
 872   void set_displacement(int displacement) {
 873     set_int_at(displacement_off_set, displacement);
 874   }
 875 
 876 public:
 877   BranchData(DataLayout* layout) : JumpData(layout) {
 878     assert(layout->tag() == DataLayout::branch_data_tag, "wrong type");
 879   }
 880 
 881   virtual bool is_BranchData() { return true; }
 882 
 883   static int static_cell_count() {
 884     return branch_cell_count;
 885   }
 886 
 887   virtual int cell_count() {
 888     return static_cell_count();
 889   }
 890 
 891   // Direct accessor
 892   uint not_taken() {
 893     return uint_at(not_taken_off_set);
 894   }
 895 
 896   void set_not_taken(uint cnt) {
 897     set_uint_at(not_taken_off_set, cnt);
 898   }
 899 
 900   uint inc_not_taken() {
 901     uint cnt = not_taken() + 1;
 902     // Did we wrap? Will compiler screw us??
 903     if (cnt == 0) cnt--;
 904     set_uint_at(not_taken_off_set, cnt);
 905     return cnt;
 906   }
 907 
 908   // Code generation support
 909   static ByteSize not_taken_offset() {
 910     return cell_offset(not_taken_off_set);
 911   }
 912   static ByteSize branch_data_size() {
 913     return cell_offset(branch_cell_count);
 914   }
 915 
 916   // Specific initialization.
 917   void post_initialize(BytecodeStream* stream, MethodData* mdo);
 918 
 919 #ifndef PRODUCT
 920   void print_data_on(outputStream* st);
 921 #endif
 922 };
 923 
 924 // ArrayData
 925 //
 926 // A ArrayData is a base class for accessing profiling data which does
 927 // not have a statically known size.  It consists of an array length
 928 // and an array start.
 929 class ArrayData : public ProfileData {
 930 protected:
 931   friend class DataLayout;
 932 
 933   enum {
 934     array_len_off_set,
 935     array_start_off_set
 936   };
 937 
 938   uint array_uint_at(int index) {
 939     int aindex = index + array_start_off_set;
 940     return uint_at(aindex);
 941   }
 942   int array_int_at(int index) {
 943     int aindex = index + array_start_off_set;
 944     return int_at(aindex);
 945   }
 946   oop array_oop_at(int index) {
 947     int aindex = index + array_start_off_set;
 948     return oop_at(aindex);
 949   }
 950   void array_set_int_at(int index, int value) {
 951     int aindex = index + array_start_off_set;
 952     set_int_at(aindex, value);
 953   }
 954 
 955   // Code generation support for subclasses.
 956   static ByteSize array_element_offset(int index) {
 957     return cell_offset(array_start_off_set + index);
 958   }
 959 
 960 public:
 961   ArrayData(DataLayout* layout) : ProfileData(layout) {}
 962 
 963   virtual bool is_ArrayData() { return true; }
 964 
 965   static int static_cell_count() {
 966     return -1;
 967   }
 968 
 969   int array_len() {
 970     return int_at_unchecked(array_len_off_set);
 971   }
 972 
 973   virtual int cell_count() {
 974     return array_len() + 1;
 975   }
 976 
 977   // Code generation support
 978   static ByteSize array_len_offset() {
 979     return cell_offset(array_len_off_set);
 980   }
 981   static ByteSize array_start_offset() {
 982     return cell_offset(array_start_off_set);
 983   }
 984 };
 985 
 986 // MultiBranchData
 987 //
 988 // A MultiBranchData is used to access profiling information for
 989 // a multi-way branch (*switch bytecodes).  It consists of a series
 990 // of (count, displacement) pairs, which count the number of times each
 991 // case was taken and specify the data displacment for each branch target.
 992 class MultiBranchData : public ArrayData {
 993 protected:


1000     relative_count_off_set,
1001     relative_displacement_off_set,
1002     per_case_cell_count
1003   };
1004 
1005   void set_default_displacement(int displacement) {
1006     array_set_int_at(default_disaplacement_off_set, displacement);
1007   }
1008   void set_displacement_at(int index, int displacement) {
1009     array_set_int_at(case_array_start +
1010                      index * per_case_cell_count +
1011                      relative_displacement_off_set,
1012                      displacement);
1013   }
1014 
1015 public:
1016   MultiBranchData(DataLayout* layout) : ArrayData(layout) {
1017     assert(layout->tag() == DataLayout::multi_branch_data_tag, "wrong type");
1018   }
1019 
1020   virtual bool is_MultiBranchData() { return true; }
1021 
1022   static int compute_cell_count(BytecodeStream* stream);
1023 
1024   int number_of_cases() {
1025     int alen = array_len() - 2; // get rid of default case here.
1026     assert(alen % per_case_cell_count == 0, "must be even");
1027     return (alen / per_case_cell_count);
1028   }
1029 
1030   uint default_count() {
1031     return array_uint_at(default_count_off_set);
1032   }
1033   int default_displacement() {
1034     return array_int_at(default_disaplacement_off_set);
1035   }
1036 
1037   uint count_at(int index) {
1038     return array_uint_at(case_array_start +
1039                          index * per_case_cell_count +
1040                          relative_count_off_set);
1041   }
1042   int displacement_at(int index) {
1043     return array_int_at(case_array_start +
1044                         index * per_case_cell_count +
1045                         relative_displacement_off_set);
1046   }
1047 
1048   // Code generation support
1049   static ByteSize default_count_offset() {
1050     return array_element_offset(default_count_off_set);
1051   }
1052   static ByteSize default_displacement_offset() {
1053     return array_element_offset(default_disaplacement_off_set);
1054   }
1055   static ByteSize case_count_offset(int index) {
1056     return case_array_offset() +
1057            (per_case_size() * index) +
1058            relative_count_offset();
1059   }
1060   static ByteSize case_array_offset() {
1061     return array_element_offset(case_array_start);
1062   }
1063   static ByteSize per_case_size() {
1064     return in_ByteSize(per_case_cell_count) * cell_size;
1065   }
1066   static ByteSize relative_count_offset() {
1067     return in_ByteSize(relative_count_off_set) * cell_size;
1068   }
1069   static ByteSize relative_displacement_offset() {
1070     return in_ByteSize(relative_displacement_off_set) * cell_size;
1071   }
1072 
1073   // Specific initialization.
1074   void post_initialize(BytecodeStream* stream, MethodData* mdo);
1075 
1076 #ifndef PRODUCT
1077   void print_data_on(outputStream* st);
1078 #endif
1079 };
1080 
1081 class ArgInfoData : public ArrayData {
1082 
1083 public:
1084   ArgInfoData(DataLayout* layout) : ArrayData(layout) {
1085     assert(layout->tag() == DataLayout::arg_info_data_tag, "wrong type");
1086   }
1087 
1088   virtual bool is_ArgInfoData() { return true; }
1089 
1090 
1091   int number_of_args() {
1092     return array_len();
1093   }
1094 
1095   uint arg_modified(int arg) {
1096     return array_uint_at(arg);
1097   }
1098 
1099   void set_arg_modified(int arg, uint val) {
1100     array_set_int_at(arg, val);
1101   }
1102 
1103 #ifndef PRODUCT
1104   void print_data_on(outputStream* st);
1105 #endif
1106 };
1107 
1108 // MethodData*
1109 //
1110 // A MethodData* holds information which has been collected about
1111 // a method.  Its layout looks like this:
1112 //
1113 // -----------------------------
1114 // | header                    |
1115 // | klass                     |
1116 // -----------------------------
1117 // | method                    |
1118 // | size of the MethodData* |
1119 // -----------------------------
1120 // | Data entries...           |
1121 // |   (variable size)         |
1122 // |                           |
1123 // .                           .
1124 // .                           .


1254   }
1255   ProfileData* data_before(int bci) {
1256     // avoid SEGV on this edge case
1257     if (data_size() == 0)
1258       return NULL;
1259     int hint = hint_di();
1260     if (data_layout_at(hint)->bci() <= bci)
1261       return data_at(hint);
1262     return first_data();
1263   }
1264 
1265   // What is the index of the first data entry?
1266   int first_di() const { return 0; }
1267 
1268   // Find or create an extra ProfileData:
1269   ProfileData* bci_to_extra_data(int bci, bool create_if_missing);
1270 
1271   // return the argument info cell
1272   ArgInfoData *arg_info();
1273 












1274 public:
1275   static int header_size() {
1276     return sizeof(MethodData)/wordSize;
1277   }
1278 
1279   // Compute the size of a MethodData* before it is created.
1280   static int compute_allocation_size_in_bytes(methodHandle method);
1281   static int compute_allocation_size_in_words(methodHandle method);
1282   static int compute_extra_data_count(int data_size, int empty_bc_count);
1283 
1284   // Determine if a given bytecode can have profile information.
1285   static bool bytecode_has_profile(Bytecodes::Code code) {
1286     return bytecode_cell_count(code) != no_profile_data;
1287   }
1288 
1289   // reset into original state
1290   void init();
1291 
1292   // My size
1293   int size_in_bytes() const { return _size; }


1493 
1494   // GC support
1495   void set_size(int object_size_in_bytes) { _size = object_size_in_bytes; }
1496 
1497   // Printing
1498 #ifndef PRODUCT
1499   void print_on      (outputStream* st) const;
1500 #endif
1501   void print_value_on(outputStream* st) const;
1502 
1503 #ifndef PRODUCT
1504   // printing support for method data
1505   void print_data_on(outputStream* st) const;
1506 #endif
1507 
1508   const char* internal_name() const { return "{method data}"; }
1509 
1510   // verification
1511   void verify_on(outputStream* st);
1512   void verify_data_on(outputStream* st);


1513 };
1514 
1515 #endif // SHARE_VM_OOPS_METHODDATAOOP_HPP


 100 public:
 101   enum {
 102     counter_increment = 1
 103   };
 104 
 105   enum {
 106     cell_size = sizeof(intptr_t)
 107   };
 108 
 109   // Tag values
 110   enum {
 111     no_tag,
 112     bit_data_tag,
 113     counter_data_tag,
 114     jump_data_tag,
 115     receiver_type_data_tag,
 116     virtual_call_data_tag,
 117     ret_data_tag,
 118     branch_data_tag,
 119     multi_branch_data_tag,
 120     arg_info_data_tag,
 121     call_type_data_tag,
 122     virtual_call_type_data_tag
 123   };
 124 
 125   enum {
 126     // The _struct._flags word is formatted as [trap_state:4 | flags:4].
 127     // The trap state breaks down further as [recompile:1 | reason:3].
 128     // This further breakdown is defined in deoptimization.cpp.
 129     // See Deoptimization::trap_state_reason for an assert that
 130     // trap_bits is big enough to hold reasons < Reason_RECORDED_LIMIT.
 131     //
 132     // The trap_state is collected only if ProfileTraps is true.
 133     trap_bits = 1+3,  // 3: enough to distinguish [0..Reason_RECORDED_LIMIT].
 134     trap_shift = BitsPerByte - trap_bits,
 135     trap_mask = right_n_bits(trap_bits),
 136     trap_mask_in_place = (trap_mask << trap_shift),
 137     flag_limit = trap_shift,
 138     flag_mask = right_n_bits(flag_limit),
 139     first_flag = 0
 140   };
 141 
 142   // Size computation


 150   static int compute_size_in_bytes(int cell_count) {
 151     return header_size_in_bytes() + cell_count * cell_size;
 152   }
 153 
 154   // Initialization
 155   void initialize(u1 tag, u2 bci, int cell_count);
 156 
 157   // Accessors
 158   u1 tag() {
 159     return _header._struct._tag;
 160   }
 161 
 162   // Return a few bits of trap state.  Range is [0..trap_mask].
 163   // The state tells if traps with zero, one, or many reasons have occurred.
 164   // It also tells whether zero or many recompilations have occurred.
 165   // The associated trap histogram in the MDO itself tells whether
 166   // traps are common or not.  If a BCI shows that a trap X has
 167   // occurred, and the MDO shows N occurrences of X, we make the
 168   // simplifying assumption that all N occurrences can be blamed
 169   // on that BCI.
 170   int trap_state() const {
 171     return ((_header._struct._flags >> trap_shift) & trap_mask);
 172   }
 173 
 174   void set_trap_state(int new_state) {
 175     assert(ProfileTraps, "used only under +ProfileTraps");
 176     uint old_flags = (_header._struct._flags & flag_mask);
 177     _header._struct._flags = (new_state << trap_shift) | old_flags;
 178   }
 179 
 180   u1 flags() const {
 181     return _header._struct._flags;
 182   }
 183 
 184   u2 bci() const {
 185     return _header._struct._bci;
 186   }
 187 
 188   void set_header(intptr_t value) {
 189     _header._bits = value;
 190   }
 191   void release_set_header(intptr_t value) {
 192     OrderAccess::release_store_ptr(&_header._bits, value);
 193   }
 194   intptr_t header() {
 195     return _header._bits;
 196   }
 197   void set_cell_at(int index, intptr_t value) {
 198     _cells[index] = value;
 199   }
 200   void release_set_cell_at(int index, intptr_t value) {
 201     OrderAccess::release_store_ptr(&_cells[index], value);
 202   }
 203   intptr_t cell_at(int index) const {
 204     return _cells[index];
 205   }
 206 
 207   void set_flag_at(int flag_number) {
 208     assert(flag_number < flag_limit, "oob");
 209     _header._struct._flags |= (0x1 << flag_number);
 210   }
 211   bool flag_at(int flag_number) const {
 212     assert(flag_number < flag_limit, "oob");
 213     return (_header._struct._flags & (0x1 << flag_number)) != 0;
 214   }
 215 
 216   // Low-level support for code generation.
 217   static ByteSize header_offset() {
 218     return byte_offset_of(DataLayout, _header);
 219   }
 220   static ByteSize tag_offset() {
 221     return byte_offset_of(DataLayout, _header._struct._tag);
 222   }
 223   static ByteSize flags_offset() {
 224     return byte_offset_of(DataLayout, _header._struct._flags);
 225   }
 226   static ByteSize bci_offset() {
 227     return byte_offset_of(DataLayout, _header._struct._bci);
 228   }
 229   static ByteSize cell_offset(int index) {
 230     return byte_offset_of(DataLayout, _cells) + in_ByteSize(index * cell_size);
 231   }


 239   // Return a value which, when or-ed as a word into _header, sets the flag.
 240   static intptr_t flag_mask_to_header_mask(int byte_constant) {
 241     DataLayout temp; temp.set_header(0);
 242     temp._header._struct._flags = byte_constant;
 243     return temp._header._bits;
 244   }
 245 
 246   ProfileData* data_in();
 247 
 248   // GC support
 249   void clean_weak_klass_links(BoolObjectClosure* cl);
 250 };
 251 
 252 
 253 // ProfileData class hierarchy
 254 class ProfileData;
 255 class   BitData;
 256 class     CounterData;
 257 class       ReceiverTypeData;
 258 class         VirtualCallData;
 259 class           VirtualCallTypeData;
 260 class       RetData;
 261 class       CallTypeData;
 262 class   JumpData;
 263 class     BranchData;
 264 class   ArrayData;
 265 class     MultiBranchData;
 266 class     ArgInfoData;
 267 

 268 // ProfileData
 269 //
 270 // A ProfileData object is created to refer to a section of profiling
 271 // data in a structured way.
 272 class ProfileData : public ResourceObj {
 273   friend class TypeEntries;
 274   friend class TypeStackSlotEntries;
 275 private:
 276 #ifndef PRODUCT
 277   enum {
 278     tab_width_one = 16,
 279     tab_width_two = 36
 280   };
 281 #endif // !PRODUCT
 282 
 283   // This is a pointer to a section of profiling data.
 284   DataLayout* _data;
 285 
 286 protected:
 287   DataLayout* data() { return _data; }
 288   const DataLayout* data() const { return _data; }
 289 
 290   enum {
 291     cell_size = DataLayout::cell_size
 292   };
 293 
 294 public:
 295   // How many cells are in this?
 296   virtual int cell_count() const {
 297     ShouldNotReachHere();
 298     return -1;
 299   }
 300 
 301   // Return the size of this data.
 302   int size_in_bytes() {
 303     return DataLayout::compute_size_in_bytes(cell_count());
 304   }
 305 
 306 protected:
 307   // Low-level accessors for underlying data
 308   void set_intptr_at(int index, intptr_t value) {
 309     assert(0 <= index && index < cell_count(), "oob");
 310     data()->set_cell_at(index, value);
 311   }
 312   void release_set_intptr_at(int index, intptr_t value) {
 313     assert(0 <= index && index < cell_count(), "oob");
 314     data()->release_set_cell_at(index, value);
 315   }
 316   intptr_t intptr_at(int index) const {
 317     assert(0 <= index && index < cell_count(), "oob");
 318     return data()->cell_at(index);
 319   }
 320   void set_uint_at(int index, uint value) {
 321     set_intptr_at(index, (intptr_t) value);
 322   }
 323   void release_set_uint_at(int index, uint value) {
 324     release_set_intptr_at(index, (intptr_t) value);
 325   }
 326   uint uint_at(int index) const {
 327     return (uint)intptr_at(index);
 328   }
 329   void set_int_at(int index, int value) {
 330     set_intptr_at(index, (intptr_t) value);
 331   }
 332   void release_set_int_at(int index, int value) {
 333     release_set_intptr_at(index, (intptr_t) value);
 334   }
 335   int int_at(int index) const {
 336     return (int)intptr_at(index);
 337   }
 338   int int_at_unchecked(int index) const {
 339     return (int)data()->cell_at(index);
 340   }
 341   void set_oop_at(int index, oop value) {
 342     set_intptr_at(index, (intptr_t) value);
 343   }
 344   oop oop_at(int index) const {
 345     return (oop)intptr_at(index);
 346   }
 347 
 348   void set_flag_at(int flag_number) {
 349     data()->set_flag_at(flag_number);
 350   }
 351   bool flag_at(int flag_number) const {
 352     return data()->flag_at(flag_number);
 353   }
 354 
 355   // two convenient imports for use by subclasses:
 356   static ByteSize cell_offset(int index) {
 357     return DataLayout::cell_offset(index);
 358   }
 359   static int flag_number_to_byte_constant(int flag_number) {
 360     return DataLayout::flag_number_to_byte_constant(flag_number);
 361   }
 362 
 363   ProfileData(DataLayout* data) {
 364     _data = data;
 365   }
 366 
 367 public:
 368   // Constructor for invalid ProfileData.
 369   ProfileData();
 370 
 371   u2 bci() const {
 372     return data()->bci();
 373   }
 374 
 375   address dp() {
 376     return (address)_data;
 377   }
 378 
 379   int trap_state() const {
 380     return data()->trap_state();
 381   }
 382   void set_trap_state(int new_state) {
 383     data()->set_trap_state(new_state);
 384   }
 385 
 386   // Type checking
 387   virtual bool is_BitData()         const { return false; }
 388   virtual bool is_CounterData()     const { return false; }
 389   virtual bool is_JumpData()        const { return false; }
 390   virtual bool is_ReceiverTypeData()const { return false; }
 391   virtual bool is_VirtualCallData() const { return false; }
 392   virtual bool is_RetData()         const { return false; }
 393   virtual bool is_BranchData()      const { return false; }
 394   virtual bool is_ArrayData()       const { return false; }
 395   virtual bool is_MultiBranchData() const { return false; }
 396   virtual bool is_ArgInfoData()     const { return false; }
 397   virtual bool is_CallTypeData()    const { return false; }
 398   virtual bool is_VirtualCallTypeData()const { return false; }
 399 
 400 
 401   BitData* as_BitData() const {
 402     assert(is_BitData(), "wrong type");
 403     return is_BitData()         ? (BitData*)        this : NULL;
 404   }
 405   CounterData* as_CounterData() const {
 406     assert(is_CounterData(), "wrong type");
 407     return is_CounterData()     ? (CounterData*)    this : NULL;
 408   }
 409   JumpData* as_JumpData() const {
 410     assert(is_JumpData(), "wrong type");
 411     return is_JumpData()        ? (JumpData*)       this : NULL;
 412   }
 413   ReceiverTypeData* as_ReceiverTypeData() const {
 414     assert(is_ReceiverTypeData(), "wrong type");
 415     return is_ReceiverTypeData() ? (ReceiverTypeData*)this : NULL;
 416   }
 417   VirtualCallData* as_VirtualCallData() const {
 418     assert(is_VirtualCallData(), "wrong type");
 419     return is_VirtualCallData() ? (VirtualCallData*)this : NULL;
 420   }
 421   RetData* as_RetData() const {
 422     assert(is_RetData(), "wrong type");
 423     return is_RetData()         ? (RetData*)        this : NULL;
 424   }
 425   BranchData* as_BranchData() const {
 426     assert(is_BranchData(), "wrong type");
 427     return is_BranchData()      ? (BranchData*)     this : NULL;
 428   }
 429   ArrayData* as_ArrayData() const {
 430     assert(is_ArrayData(), "wrong type");
 431     return is_ArrayData()       ? (ArrayData*)      this : NULL;
 432   }
 433   MultiBranchData* as_MultiBranchData() const {
 434     assert(is_MultiBranchData(), "wrong type");
 435     return is_MultiBranchData() ? (MultiBranchData*)this : NULL;
 436   }
 437   ArgInfoData* as_ArgInfoData() const {
 438     assert(is_ArgInfoData(), "wrong type");
 439     return is_ArgInfoData() ? (ArgInfoData*)this : NULL;
 440   }
 441   CallTypeData* as_CallTypeData() const {
 442     assert(is_CallTypeData(), "wrong type");
 443     return is_CallTypeData() ? (CallTypeData*)this : NULL;
 444   }
 445   VirtualCallTypeData* as_VirtualCallTypeData() const {
 446     assert(is_VirtualCallTypeData(), "wrong type");
 447     return is_VirtualCallTypeData() ? (VirtualCallTypeData*)this : NULL;
 448   }
 449 
 450 
 451   // Subclass specific initialization
 452   virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {}
 453 
 454   // GC support
 455   virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {}
 456 
 457   // CI translation: ProfileData can represent both MethodDataOop data
 458   // as well as CIMethodData data. This function is provided for translating
 459   // an oop in a ProfileData to the ci equivalent. Generally speaking,
 460   // most ProfileData don't require any translation, so we provide the null
 461   // translation here, and the required translators are in the ci subclasses.
 462   virtual void translate_from(const ProfileData* data) {}
 463 
 464   virtual void print_data_on(outputStream* st) const {
 465     ShouldNotReachHere();
 466   }
 467 
 468 #ifndef PRODUCT
 469   void print_shared(outputStream* st, const char* name) const;
 470   void tab(outputStream* st, bool first = false) const;
 471 #endif
 472 };
 473 
 474 // BitData
 475 //
 476 // A BitData holds a flag or two in its header.
 477 class BitData : public ProfileData {
 478 protected:
 479   enum {
 480     // null_seen:
 481     //  saw a null operand (cast/aastore/instanceof)
 482     null_seen_flag              = DataLayout::first_flag + 0
 483   };
 484   enum { bit_cell_count = 0 };  // no additional data fields needed.
 485 public:
 486   BitData(DataLayout* layout) : ProfileData(layout) {
 487   }
 488 
 489   virtual bool is_BitData() const { return true; }
 490 
 491   static int static_cell_count() {
 492     return bit_cell_count;
 493   }
 494 
 495   virtual int cell_count() const {
 496     return static_cell_count();
 497   }
 498 
 499   // Accessor
 500 
 501   // The null_seen flag bit is specially known to the interpreter.
 502   // Consulting it allows the compiler to avoid setting up null_check traps.
 503   bool null_seen()     { return flag_at(null_seen_flag); }
 504   void set_null_seen()    { set_flag_at(null_seen_flag); }
 505 
 506 
 507   // Code generation support
 508   static int null_seen_byte_constant() {
 509     return flag_number_to_byte_constant(null_seen_flag);
 510   }
 511 
 512   static ByteSize bit_data_size() {
 513     return cell_offset(bit_cell_count);
 514   }
 515 
 516 #ifndef PRODUCT
 517   void print_data_on(outputStream* st) const;
 518 #endif
 519 };
 520 
 521 // CounterData
 522 //
 523 // A CounterData corresponds to a simple counter.
 524 class CounterData : public BitData {
 525 protected:
 526   enum {
 527     count_off,
 528     counter_cell_count
 529   };
 530 public:
 531   CounterData(DataLayout* layout) : BitData(layout) {}
 532 
 533   virtual bool is_CounterData() const { return true; }
 534 
 535   static int static_cell_count() {
 536     return counter_cell_count;
 537   }
 538 
 539   virtual int cell_count() const {
 540     return static_cell_count();
 541   }
 542 
 543   // Direct accessor
 544   uint count() const {
 545     return uint_at(count_off);
 546   }
 547 
 548   // Code generation support
 549   static ByteSize count_offset() {
 550     return cell_offset(count_off);
 551   }
 552   static ByteSize counter_data_size() {
 553     return cell_offset(counter_cell_count);
 554   }
 555 
 556   void set_count(uint count) {
 557     set_uint_at(count_off, count);
 558   }
 559 
 560 #ifndef PRODUCT
 561   void print_data_on(outputStream* st) const;
 562 #endif
 563 };
 564 
 565 // JumpData
 566 //
 567 // A JumpData is used to access profiling information for a direct
 568 // branch.  It is a counter, used for counting the number of branches,
 569 // plus a data displacement, used for realigning the data pointer to
 570 // the corresponding target bci.
 571 class JumpData : public ProfileData {
 572 protected:
 573   enum {
 574     taken_off_set,
 575     displacement_off_set,
 576     jump_cell_count
 577   };
 578 
 579   void set_displacement(int displacement) {
 580     set_int_at(displacement_off_set, displacement);
 581   }
 582 
 583 public:
 584   JumpData(DataLayout* layout) : ProfileData(layout) {
 585     assert(layout->tag() == DataLayout::jump_data_tag ||
 586       layout->tag() == DataLayout::branch_data_tag, "wrong type");
 587   }
 588 
 589   virtual bool is_JumpData() const { return true; }
 590 
 591   static int static_cell_count() {
 592     return jump_cell_count;
 593   }
 594 
 595   virtual int cell_count() const {
 596     return static_cell_count();
 597   }
 598 
 599   // Direct accessor
 600   uint taken() const {
 601     return uint_at(taken_off_set);
 602   }
 603 
 604   void set_taken(uint cnt) {
 605     set_uint_at(taken_off_set, cnt);
 606   }
 607 
 608   // Saturating counter
 609   uint inc_taken() {
 610     uint cnt = taken() + 1;
 611     // Did we wrap? Will compiler screw us??
 612     if (cnt == 0) cnt--;
 613     set_uint_at(taken_off_set, cnt);
 614     return cnt;
 615   }
 616 
 617   int displacement() const {
 618     return int_at(displacement_off_set);
 619   }
 620 
 621   // Code generation support
 622   static ByteSize taken_offset() {
 623     return cell_offset(taken_off_set);
 624   }
 625 
 626   static ByteSize displacement_offset() {
 627     return cell_offset(displacement_off_set);
 628   }
 629 
 630   // Specific initialization.
 631   void post_initialize(BytecodeStream* stream, MethodData* mdo);
 632 
 633 #ifndef PRODUCT
 634   void print_data_on(outputStream* st) const;
 635 #endif
 636 };
 637 
 638 // Entries in a ProfileData object to record types: it can either be
 639 // none (no profile), unknown (conflicting profile data) or a klass if
 640 // a single one is seen. Whether a null reference was seen is also
 641 // recorded. No counter is associated with the type and a single type
 642 // is tracked (unlike VirtualCallData).
 643 class TypeEntries {
 644 
 645 public:
 646 
 647   // A single cell is used to record information for a type:
 648   // - the cell is initialized to 0
 649   // - when a type is discovered it is stored in the cell
 650   // - bit zero of the cell is used to record whether a null reference
 651   // was encountered or not
 652   // - bit 1 is set to record a conflict in the type information
 653 
 654   enum {
 655     null_seen = 1,
 656     type_mask = ~null_seen,
 657     type_unknown = 2,
 658     status_bits = null_seen | type_unknown,
 659     type_klass_mask = ~status_bits
 660   };
 661 
 662   // what to initialize a cell to
 663   static intptr_t type_none() {
 664     return NULL;
 665   }
 666 
 667   // null seen = bit 0 set?
 668   static bool was_null_seen(intptr_t v) {
 669     return v & null_seen;
 670   }
 671 
 672   // conflicting type information = bit 1 set?
 673   static bool is_type_unknown(intptr_t v) {
 674     return v & type_unknown;
 675   }
 676 
 677   // not type information yet = all bits cleared, ignoring bit 0?
 678   static bool is_type_none(intptr_t v) {
 679     return (v & type_mask) == 0;
 680   }
 681 
 682   // recorded type: cell without bit 0 and 1
 683   static intptr_t klass_part(intptr_t v) {
 684     intptr_t r = v & type_klass_mask;
 685     assert (r != NULL, "invalid");
 686     return r;
 687   }
 688 
 689   // type recorded
 690   static Klass* valid_klass(intptr_t k) {
 691     if (!is_type_none(k) &&
 692         !is_type_unknown(k)) {
 693       return (Klass*)klass_part(k);
 694     } else {
 695       return NULL;
 696     }
 697   }
 698 
 699   static intptr_t with_status(intptr_t k, intptr_t in) {
 700     return k | (in & status_bits);
 701   }
 702 
 703   static intptr_t with_status(Klass* k, intptr_t in) {
 704     return with_status((intptr_t)k, in);
 705   }
 706 
 707 #ifndef PRODUCT
 708   static void print_klass(outputStream* st, intptr_t k);
 709 #endif
 710 
 711   // GC support
 712   static bool is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p);
 713 
 714 protected:
 715   // ProfileData object these entries are part of
 716   ProfileData* _pd;
 717   // offset within the ProfileData object where the entries start
 718   const int _base_off;
 719 
 720   TypeEntries(int base_off, ProfileData* pd)
 721     : _base_off(base_off), _pd(pd) {}
 722 
 723   void set_intptr_at(int index, intptr_t value) {
 724     _pd->set_intptr_at(index, value);
 725   }
 726 
 727   intptr_t intptr_at(int index) const {
 728     return _pd->intptr_at(index);
 729   }
 730 };
 731 
 732 // Type entries used for arguments passed at a call and parameters on
 733 // method entry. 2 cells per entry: one for the type encoded as in
 734 // TypeEntries and one initialized with the stack slot where the
 735 // profiled object is to be found so that the interpreter can locate
 736 // it quickly.
 737 class TypeStackSlotEntries : public TypeEntries {
 738 
 739 private:
 740   enum {
 741     stack_slot_entry,
 742     type_entry,
 743     per_arg_cell_count
 744   };
 745 
 746   // Start with a header if needed. It stores the number of cells used
 747   // for this call type information. Unless we collect only profiling
 748   // for a single argument the number of cells is unknown statically.
 749   static int header_cell_count() {
 750     return (TypeProfileArgsLimit > 1) ? 1 : 0;
 751   }
 752 
 753   static int cell_count_local_offset() {
 754      assert(arguments_profiling_enabled() && TypeProfileArgsLimit > 1, "no cell count");
 755      return 0;
 756    }
 757 
 758   int cell_count_global_offset() const {
 759     return _base_off + cell_count_local_offset();
 760   }
 761   
 762   // offset of cell for stack slot for entry i within ProfileData object
 763   int stack_slot_global_offset(int i) const {
 764     return _base_off + stack_slot_local_offset(i);
 765   }
 766 
 767   void check_number_of_arguments(uint total) {
 768     assert(number_of_arguments() == total, "should be set in DataLayout::initialize");
 769   }
 770 
 771   // number of cells not counting the header
 772   int cell_count_no_header() const {
 773     return _pd->uint_at(cell_count_global_offset());
 774   }
 775 
 776   static bool arguments_profiling_enabled();
 777   static void assert_arguments_profiling_enabled() {
 778     assert(arguments_profiling_enabled(), "args profiling should be on");
 779   }
 780 
 781 protected:
 782 
 783   // offset of cell for type for entry i within ProfileData object
 784   int type_global_offset(int i) const {
 785     return _base_off + type_local_offset(i);
 786   }
 787 
 788 public:
 789 
 790   TypeStackSlotEntries(int base_off, ProfileData* pd)
 791     : TypeEntries(base_off, pd) {}
 792 
 793   static int compute_cell_count(BytecodeStream* stream);
 794 
 795   static void initialize(DataLayout* dl, int base, int cell_count) {
 796     if (TypeProfileArgsLimit > 1) {
 797       int off = base + cell_count_local_offset();
 798       dl->set_cell_at(off, cell_count - base - header_cell_count());
 799     }
 800   }
 801 
 802   void post_initialize(BytecodeStream* stream);
 803 
 804   uint number_of_arguments() const {
 805     assert_arguments_profiling_enabled();
 806     if (TypeProfileArgsLimit > 1) {
 807       int cell_count = cell_count_no_header();
 808       int nb = cell_count / TypeStackSlotEntries::per_arg_count();
 809       assert(nb > 0 && nb <= TypeProfileArgsLimit , "only when we profile args");
 810       return nb;
 811     } else {
 812       assert(TypeProfileArgsLimit == 1, "at least one arg");
 813       return 1;
 814     }
 815   }
 816   
 817   int cell_count() const {
 818     assert_arguments_profiling_enabled();
 819     if (TypeProfileArgsLimit > 1) {
 820       return _base_off + header_cell_count() + _pd->int_at_unchecked(cell_count_global_offset());
 821     } else {
 822       return _base_off + TypeStackSlotEntries::per_arg_count();
 823     }
 824   }
 825 
 826   // offset of cell for stack slot for entry i within this block of cells for a TypeStackSlotEntries
 827   static int stack_slot_local_offset(int i) {
 828     assert_arguments_profiling_enabled();
 829     return header_cell_count() + i * per_arg_cell_count + stack_slot_entry;
 830   }
 831 
 832   // offset of cell for type for entry i within this block of cells for a TypeStackSlotEntries
 833   static int type_local_offset(int i) {
 834     return header_cell_count() + i * per_arg_cell_count + type_entry;
 835   }
 836 
 837   // stack slot for entry i
 838   uint stack_slot(int i) const {
 839     assert(i >= 0 && i < number_of_arguments(), "oob");
 840     return _pd->uint_at(stack_slot_global_offset(i));
 841   }
 842 
 843   // set stack slot for entry i
 844   void set_stack_slot(int i, uint num) {
 845     assert(i >= 0 && i < number_of_arguments(), "oob");
 846     _pd->set_uint_at(stack_slot_global_offset(i), num);
 847   }
 848   
 849   // type for entry i
 850   intptr_t type(int i) const {
 851     assert(i >= 0 && i < number_of_arguments(), "oob");
 852     return _pd->intptr_at(type_global_offset(i));
 853   }
 854 
 855   // set type for entry i
 856   void set_type(int i, intptr_t k) {
 857     assert(i >= 0 && i < number_of_arguments(), "oob");
 858     _pd->set_intptr_at(type_global_offset(i), k);
 859   }
 860 
 861   static ByteSize per_arg_size() {
 862     return in_ByteSize(per_arg_cell_count * DataLayout::cell_size);
 863   }
 864 
 865   static int per_arg_count() {
 866     return per_arg_cell_count ;
 867   }
 868 
 869   // Code generation support
 870    static ByteSize cell_count_offset() {
 871      return in_ByteSize(cell_count_local_offset() * DataLayout::cell_size);
 872    }
 873  
 874    static ByteSize args_data_offset() {
 875      return in_ByteSize(header_cell_count() * DataLayout::cell_size);
 876    }
 877  
 878    static ByteSize stack_slot_offset(int i) {
 879      return in_ByteSize(stack_slot_local_offset(i) * DataLayout::cell_size);
 880    }
 881  
 882    static ByteSize type_offset(int i) {
 883      return in_ByteSize(type_local_offset(i) * DataLayout::cell_size);
 884    }
 885 
 886   // GC support
 887   void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
 888 
 889 #ifndef PRODUCT
 890   void print_data_on(outputStream* st) const;
 891 #endif
 892 };
 893 
 894 // CallTypeData
 895 //
 896 // A CallTypeData is used to access profiling information about a non
 897 // virtual call for which we collect type information about arguments.
 898 class CallTypeData : public CounterData {
 899 private:
 900   TypeStackSlotEntries _args;
 901 
 902 public:
 903   CallTypeData(DataLayout* layout) :
 904     CounterData(layout), _args(CounterData::static_cell_count(), this)  {
 905     assert(layout->tag() == DataLayout::call_type_data_tag, "wrong type");
 906   }
 907 
 908   const TypeStackSlotEntries* args() const { return &_args; }
 909 
 910   virtual bool is_CallTypeData() const { return true; }
 911 
 912   static int static_cell_count() {
 913     return -1;
 914   }
 915 
 916   static int compute_cell_count(BytecodeStream* stream) {
 917     return CounterData::static_cell_count() + TypeStackSlotEntries::compute_cell_count(stream);
 918   }
 919   
 920   static void initialize(DataLayout* dl, int cell_count) {
 921     TypeStackSlotEntries::initialize(dl, CounterData::static_cell_count(), cell_count);
 922   }
 923 
 924   virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {
 925     _args.post_initialize(stream);
 926   }
 927 
 928   virtual int cell_count() const {
 929     return _args.cell_count();
 930   }
 931 
 932   uint number_of_arguments() const {
 933     return args()->number_of_arguments();
 934   }
 935 
 936   void set_argument_type(int i, Klass* k) {
 937     intptr_t current = _args.type(i);
 938     _args.set_type(i, TypeEntries::with_status(k, current));
 939   }
 940 
 941   // Code generation support
 942   static ByteSize args_data_offset() {
 943     return cell_offset(CounterData::static_cell_count()) + TypeStackSlotEntries::args_data_offset();
 944   }
 945 
 946   // GC support
 947   virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
 948     _args.clean_weak_klass_links(is_alive_closure);
 949   }
 950 
 951 #ifndef PRODUCT
 952   virtual void print_data_on(outputStream* st) const;
 953 #endif
 954 };
 955 
 956 // ReceiverTypeData
 957 //
 958 // A ReceiverTypeData is used to access profiling information about a
 959 // dynamic type check.  It consists of a counter which counts the total times
 960 // that the check is reached, and a series of (Klass*, count) pairs
 961 // which are used to store a type profile for the receiver of the check.
 962 class ReceiverTypeData : public CounterData {
 963 protected:
 964   enum {
 965     receiver0_offset = counter_cell_count,
 966     count0_offset,
 967     receiver_type_row_cell_count = (count0_offset + 1) - receiver0_offset
 968   };
 969 
 970 public:
 971   ReceiverTypeData(DataLayout* layout) : CounterData(layout) {
 972     assert(layout->tag() == DataLayout::receiver_type_data_tag ||
 973            layout->tag() == DataLayout::virtual_call_data_tag ||
 974            layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
 975   }
 976 
 977   virtual bool is_ReceiverTypeData() const { return true; }
 978 
 979   static int static_cell_count() {
 980     return counter_cell_count + (uint) TypeProfileWidth * receiver_type_row_cell_count;
 981   }
 982 
 983   virtual int cell_count() const {
 984     return static_cell_count();
 985   }
 986 
 987   // Direct accessors
 988   static uint row_limit() {
 989     return TypeProfileWidth;
 990   }
 991   static int receiver_cell_index(uint row) {
 992     return receiver0_offset + row * receiver_type_row_cell_count;
 993   }
 994   static int receiver_count_cell_index(uint row) {
 995     return count0_offset + row * receiver_type_row_cell_count;
 996   }
 997 
 998   Klass* receiver(uint row) const {
 999     assert(row < row_limit(), "oob");
1000 
1001     Klass* recv = (Klass*)intptr_at(receiver_cell_index(row));
1002     assert(recv == NULL || recv->is_klass(), "wrong type");
1003     return recv;
1004   }
1005 
1006   void set_receiver(uint row, Klass* k) {
1007     assert((uint)row < row_limit(), "oob");
1008     set_intptr_at(receiver_cell_index(row), (uintptr_t)k);
1009   }
1010 
1011   uint receiver_count(uint row) const {
1012     assert(row < row_limit(), "oob");
1013     return uint_at(receiver_count_cell_index(row));
1014   }
1015 
1016   void set_receiver_count(uint row, uint count) {
1017     assert(row < row_limit(), "oob");
1018     set_uint_at(receiver_count_cell_index(row), count);
1019   }
1020 
1021   void clear_row(uint row) {
1022     assert(row < row_limit(), "oob");
1023     // Clear total count - indicator of polymorphic call site.
1024     // The site may look like as monomorphic after that but
1025     // it allow to have more accurate profiling information because
1026     // there was execution phase change since klasses were unloaded.
1027     // If the site is still polymorphic then MDO will be updated
1028     // to reflect it. But it could be the case that the site becomes
1029     // only bimorphic. Then keeping total count not 0 will be wrong.
1030     // Even if we use monomorphic (when it is not) for compilation
1031     // we will only have trap, deoptimization and recompile again


1039     set_count(0);
1040     set_receiver(row, NULL);
1041     set_receiver_count(row, 0);
1042   }
1043 
1044   // Code generation support
1045   static ByteSize receiver_offset(uint row) {
1046     return cell_offset(receiver_cell_index(row));
1047   }
1048   static ByteSize receiver_count_offset(uint row) {
1049     return cell_offset(receiver_count_cell_index(row));
1050   }
1051   static ByteSize receiver_type_data_size() {
1052     return cell_offset(static_cell_count());
1053   }
1054 
1055   // GC support
1056   virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
1057 
1058 #ifndef PRODUCT
1059   void print_receiver_data_on(outputStream* st) const;
1060   void print_data_on(outputStream* st) const;
1061 #endif
1062 };
1063 
1064 // VirtualCallData
1065 //
1066 // A VirtualCallData is used to access profiling information about a
1067 // virtual call.  For now, it has nothing more than a ReceiverTypeData.
1068 class VirtualCallData : public ReceiverTypeData {
1069 public:
1070   VirtualCallData(DataLayout* layout) : ReceiverTypeData(layout) {
1071     assert(layout->tag() == DataLayout::virtual_call_data_tag ||
1072            layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
1073   }
1074 
1075   virtual bool is_VirtualCallData() const { return true; }
1076 
1077   static int static_cell_count() {
1078     // At this point we could add more profile state, e.g., for arguments.
1079     // But for now it's the same size as the base record type.
1080     return ReceiverTypeData::static_cell_count();
1081   }
1082 
1083   virtual int cell_count() const {
1084     return static_cell_count();
1085   }
1086 
1087   // Direct accessors
1088   static ByteSize virtual_call_data_size() {
1089     return cell_offset(static_cell_count());
1090   }
1091 
1092 #ifndef PRODUCT
1093   void print_data_on(outputStream* st) const;
1094 #endif
1095 };
1096 
1097 // VirtualCallTypeData
1098 //
1099 // A VirtualCallTypeData is used to access profiling information about
1100 // a virtual call for which we collect type information about
1101 // arguments.
1102 class VirtualCallTypeData : public VirtualCallData {
1103 private:
1104   TypeStackSlotEntries _args;
1105 
1106 public:
1107   VirtualCallTypeData(DataLayout* layout) :
1108     VirtualCallData(layout), _args(VirtualCallData::static_cell_count(), this)  {
1109     assert(layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
1110   }
1111 
1112   const TypeStackSlotEntries* args() const { return &_args; }
1113 
1114   virtual bool is_VirtualCallTypeData() const { return true; }
1115 
1116   static int static_cell_count() {
1117     return -1;
1118   }
1119 
1120   static int compute_cell_count(BytecodeStream* stream) {
1121     return VirtualCallData::static_cell_count() + TypeStackSlotEntries::compute_cell_count(stream);
1122   }
1123   
1124   static void initialize(DataLayout* dl, int cell_count) {
1125     TypeStackSlotEntries::initialize(dl, VirtualCallData::static_cell_count(), cell_count);
1126   }
1127 
1128   virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {
1129     _args.post_initialize(stream);
1130   }
1131 
1132   virtual int cell_count() const {
1133     return _args.cell_count();
1134   }
1135 
1136   uint number_of_arguments() const {
1137     return args()->number_of_arguments();
1138   }
1139 
1140   void set_argument_type(int i, Klass* k) {
1141     intptr_t current = _args.type(i);
1142     _args.set_type(i, TypeEntries::with_status(k, current));
1143   }
1144 
1145   // Code generation support
1146   static ByteSize args_data_offset() {
1147     return cell_offset(VirtualCallData::static_cell_count()) + TypeStackSlotEntries::args_data_offset();
1148   }
1149 
1150   // GC support
1151   virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
1152     ReceiverTypeData::clean_weak_klass_links(is_alive_closure);
1153     _args.clean_weak_klass_links(is_alive_closure);
1154   }
1155 
1156 #ifndef PRODUCT
1157   virtual void print_data_on(outputStream* st) const;
1158 #endif
1159 };
1160 
1161 // RetData
1162 //
1163 // A RetData is used to access profiling information for a ret bytecode.
1164 // It is composed of a count of the number of times that the ret has
1165 // been executed, followed by a series of triples of the form
1166 // (bci, count, di) which count the number of times that some bci was the
1167 // target of the ret and cache a corresponding data displacement.
1168 class RetData : public CounterData {
1169 protected:
1170   enum {
1171     bci0_offset = counter_cell_count,
1172     count0_offset,
1173     displacement0_offset,
1174     ret_row_cell_count = (displacement0_offset + 1) - bci0_offset
1175   };
1176 
1177   void set_bci(uint row, int bci) {


1180   }
1181   void release_set_bci(uint row, int bci) {
1182     assert((uint)row < row_limit(), "oob");
1183     // 'release' when setting the bci acts as a valid flag for other
1184     // threads wrt bci_count and bci_displacement.
1185     release_set_int_at(bci0_offset + row * ret_row_cell_count, bci);
1186   }
1187   void set_bci_count(uint row, uint count) {
1188     assert((uint)row < row_limit(), "oob");
1189     set_uint_at(count0_offset + row * ret_row_cell_count, count);
1190   }
1191   void set_bci_displacement(uint row, int disp) {
1192     set_int_at(displacement0_offset + row * ret_row_cell_count, disp);
1193   }
1194 
1195 public:
1196   RetData(DataLayout* layout) : CounterData(layout) {
1197     assert(layout->tag() == DataLayout::ret_data_tag, "wrong type");
1198   }
1199 
1200   virtual bool is_RetData() const { return true; }
1201 
1202   enum {
1203     no_bci = -1 // value of bci when bci1/2 are not in use.
1204   };
1205 
1206   static int static_cell_count() {
1207     return counter_cell_count + (uint) BciProfileWidth * ret_row_cell_count;
1208   }
1209 
1210   virtual int cell_count() const {
1211     return static_cell_count();
1212   }
1213 
1214   static uint row_limit() {
1215     return BciProfileWidth;
1216   }
1217   static int bci_cell_index(uint row) {
1218     return bci0_offset + row * ret_row_cell_count;
1219   }
1220   static int bci_count_cell_index(uint row) {
1221     return count0_offset + row * ret_row_cell_count;
1222   }
1223   static int bci_displacement_cell_index(uint row) {
1224     return displacement0_offset + row * ret_row_cell_count;
1225   }
1226 
1227   // Direct accessors
1228   int bci(uint row) const {
1229     return int_at(bci_cell_index(row));
1230   }
1231   uint bci_count(uint row) const {
1232     return uint_at(bci_count_cell_index(row));
1233   }
1234   int bci_displacement(uint row) const {
1235     return int_at(bci_displacement_cell_index(row));
1236   }
1237 
1238   // Interpreter Runtime support
1239   address fixup_ret(int return_bci, MethodData* mdo);
1240 
1241   // Code generation support
1242   static ByteSize bci_offset(uint row) {
1243     return cell_offset(bci_cell_index(row));
1244   }
1245   static ByteSize bci_count_offset(uint row) {
1246     return cell_offset(bci_count_cell_index(row));
1247   }
1248   static ByteSize bci_displacement_offset(uint row) {
1249     return cell_offset(bci_displacement_cell_index(row));
1250   }
1251 
1252   // Specific initialization.
1253   void post_initialize(BytecodeStream* stream, MethodData* mdo);
1254 
1255 #ifndef PRODUCT
1256   void print_data_on(outputStream* st) const;
1257 #endif
1258 };
1259 
1260 // BranchData
1261 //
1262 // A BranchData is used to access profiling data for a two-way branch.
1263 // It consists of taken and not_taken counts as well as a data displacement
1264 // for the taken case.
1265 class BranchData : public JumpData {
1266 protected:
1267   enum {
1268     not_taken_off_set = jump_cell_count,
1269     branch_cell_count
1270   };
1271 
1272   void set_displacement(int displacement) {
1273     set_int_at(displacement_off_set, displacement);
1274   }
1275 
1276 public:
1277   BranchData(DataLayout* layout) : JumpData(layout) {
1278     assert(layout->tag() == DataLayout::branch_data_tag, "wrong type");
1279   }
1280 
1281   virtual bool is_BranchData() const { return true; }
1282 
1283   static int static_cell_count() {
1284     return branch_cell_count;
1285   }
1286 
1287   virtual int cell_count() const {
1288     return static_cell_count();
1289   }
1290 
1291   // Direct accessor
1292   uint not_taken() const {
1293     return uint_at(not_taken_off_set);
1294   }
1295 
1296   void set_not_taken(uint cnt) {
1297     set_uint_at(not_taken_off_set, cnt);
1298   }
1299 
1300   uint inc_not_taken() {
1301     uint cnt = not_taken() + 1;
1302     // Did we wrap? Will compiler screw us??
1303     if (cnt == 0) cnt--;
1304     set_uint_at(not_taken_off_set, cnt);
1305     return cnt;
1306   }
1307 
1308   // Code generation support
1309   static ByteSize not_taken_offset() {
1310     return cell_offset(not_taken_off_set);
1311   }
1312   static ByteSize branch_data_size() {
1313     return cell_offset(branch_cell_count);
1314   }
1315 
1316   // Specific initialization.
1317   void post_initialize(BytecodeStream* stream, MethodData* mdo);
1318 
1319 #ifndef PRODUCT
1320   void print_data_on(outputStream* st) const;
1321 #endif
1322 };
1323 
1324 // ArrayData
1325 //
1326 // A ArrayData is a base class for accessing profiling data which does
1327 // not have a statically known size.  It consists of an array length
1328 // and an array start.
1329 class ArrayData : public ProfileData {
1330 protected:
1331   friend class DataLayout;
1332 
1333   enum {
1334     array_len_off_set,
1335     array_start_off_set
1336   };
1337 
1338   uint array_uint_at(int index) const {
1339     int aindex = index + array_start_off_set;
1340     return uint_at(aindex);
1341   }
1342   int array_int_at(int index) const {
1343     int aindex = index + array_start_off_set;
1344     return int_at(aindex);
1345   }
1346   oop array_oop_at(int index) const {
1347     int aindex = index + array_start_off_set;
1348     return oop_at(aindex);
1349   }
1350   void array_set_int_at(int index, int value) {
1351     int aindex = index + array_start_off_set;
1352     set_int_at(aindex, value);
1353   }
1354 
1355   // Code generation support for subclasses.
1356   static ByteSize array_element_offset(int index) {
1357     return cell_offset(array_start_off_set + index);
1358   }
1359 
1360 public:
1361   ArrayData(DataLayout* layout) : ProfileData(layout) {}
1362 
1363   virtual bool is_ArrayData() const { return true; }
1364 
1365   static int static_cell_count() {
1366     return -1;
1367   }
1368 
1369   int array_len() const {
1370     return int_at_unchecked(array_len_off_set);
1371   }
1372 
1373   virtual int cell_count() const {
1374     return array_len() + 1;
1375   }
1376 
1377   // Code generation support
1378   static ByteSize array_len_offset() {
1379     return cell_offset(array_len_off_set);
1380   }
1381   static ByteSize array_start_offset() {
1382     return cell_offset(array_start_off_set);
1383   }
1384 };
1385 
1386 // MultiBranchData
1387 //
1388 // A MultiBranchData is used to access profiling information for
1389 // a multi-way branch (*switch bytecodes).  It consists of a series
1390 // of (count, displacement) pairs, which count the number of times each
1391 // case was taken and specify the data displacment for each branch target.
1392 class MultiBranchData : public ArrayData {
1393 protected:


1400     relative_count_off_set,
1401     relative_displacement_off_set,
1402     per_case_cell_count
1403   };
1404 
1405   void set_default_displacement(int displacement) {
1406     array_set_int_at(default_disaplacement_off_set, displacement);
1407   }
1408   void set_displacement_at(int index, int displacement) {
1409     array_set_int_at(case_array_start +
1410                      index * per_case_cell_count +
1411                      relative_displacement_off_set,
1412                      displacement);
1413   }
1414 
1415 public:
1416   MultiBranchData(DataLayout* layout) : ArrayData(layout) {
1417     assert(layout->tag() == DataLayout::multi_branch_data_tag, "wrong type");
1418   }
1419 
1420   virtual bool is_MultiBranchData() const { return true; }
1421 
1422   static int compute_cell_count(BytecodeStream* stream);
1423 
1424   int number_of_cases() const {
1425     int alen = array_len() - 2; // get rid of default case here.
1426     assert(alen % per_case_cell_count == 0, "must be even");
1427     return (alen / per_case_cell_count);
1428   }
1429 
1430   uint default_count() const {
1431     return array_uint_at(default_count_off_set);
1432   }
1433   int default_displacement() const {
1434     return array_int_at(default_disaplacement_off_set);
1435   }
1436 
1437   uint count_at(int index) const {
1438     return array_uint_at(case_array_start +
1439                          index * per_case_cell_count +
1440                          relative_count_off_set);
1441   }
1442   int displacement_at(int index) const {
1443     return array_int_at(case_array_start +
1444                         index * per_case_cell_count +
1445                         relative_displacement_off_set);
1446   }
1447 
1448   // Code generation support
1449   static ByteSize default_count_offset() {
1450     return array_element_offset(default_count_off_set);
1451   }
1452   static ByteSize default_displacement_offset() {
1453     return array_element_offset(default_disaplacement_off_set);
1454   }
1455   static ByteSize case_count_offset(int index) {
1456     return case_array_offset() +
1457            (per_case_size() * index) +
1458            relative_count_offset();
1459   }
1460   static ByteSize case_array_offset() {
1461     return array_element_offset(case_array_start);
1462   }
1463   static ByteSize per_case_size() {
1464     return in_ByteSize(per_case_cell_count) * cell_size;
1465   }
1466   static ByteSize relative_count_offset() {
1467     return in_ByteSize(relative_count_off_set) * cell_size;
1468   }
1469   static ByteSize relative_displacement_offset() {
1470     return in_ByteSize(relative_displacement_off_set) * cell_size;
1471   }
1472 
1473   // Specific initialization.
1474   void post_initialize(BytecodeStream* stream, MethodData* mdo);
1475 
1476 #ifndef PRODUCT
1477   void print_data_on(outputStream* st) const;
1478 #endif
1479 };
1480 
1481 class ArgInfoData : public ArrayData {
1482 
1483 public:
1484   ArgInfoData(DataLayout* layout) : ArrayData(layout) {
1485     assert(layout->tag() == DataLayout::arg_info_data_tag, "wrong type");
1486   }
1487 
1488   virtual bool is_ArgInfoData() const { return true; }
1489 
1490 
1491   int number_of_args() const {
1492     return array_len();
1493   }
1494 
1495   uint arg_modified(int arg) const {
1496     return array_uint_at(arg);
1497   }
1498 
1499   void set_arg_modified(int arg, uint val) {
1500     array_set_int_at(arg, val);
1501   }
1502 
1503 #ifndef PRODUCT
1504   void print_data_on(outputStream* st) const;
1505 #endif
1506 };
1507 
1508 // MethodData*
1509 //
1510 // A MethodData* holds information which has been collected about
1511 // a method.  Its layout looks like this:
1512 //
1513 // -----------------------------
1514 // | header                    |
1515 // | klass                     |
1516 // -----------------------------
1517 // | method                    |
1518 // | size of the MethodData* |
1519 // -----------------------------
1520 // | Data entries...           |
1521 // |   (variable size)         |
1522 // |                           |
1523 // .                           .
1524 // .                           .


1654   }
1655   ProfileData* data_before(int bci) {
1656     // avoid SEGV on this edge case
1657     if (data_size() == 0)
1658       return NULL;
1659     int hint = hint_di();
1660     if (data_layout_at(hint)->bci() <= bci)
1661       return data_at(hint);
1662     return first_data();
1663   }
1664 
1665   // What is the index of the first data entry?
1666   int first_di() const { return 0; }
1667 
1668   // Find or create an extra ProfileData:
1669   ProfileData* bci_to_extra_data(int bci, bool create_if_missing);
1670 
1671   // return the argument info cell
1672   ArgInfoData *arg_info();
1673 
1674   enum {
1675     no_type_profile = 0,
1676     type_profile_jsr292 = 1,
1677     type_profile_all = 2
1678   };
1679 
1680   static bool profile_jsr292(methodHandle m, int bci);
1681   static int profile_arguments_flag();
1682   static bool profile_arguments_jsr292_only();
1683   static bool profile_all_arguments();
1684   static bool profile_arguments_for_invoke(methodHandle m, int bci);
1685 
1686 public:
1687   static int header_size() {
1688     return sizeof(MethodData)/wordSize;
1689   }
1690 
1691   // Compute the size of a MethodData* before it is created.
1692   static int compute_allocation_size_in_bytes(methodHandle method);
1693   static int compute_allocation_size_in_words(methodHandle method);
1694   static int compute_extra_data_count(int data_size, int empty_bc_count);
1695 
1696   // Determine if a given bytecode can have profile information.
1697   static bool bytecode_has_profile(Bytecodes::Code code) {
1698     return bytecode_cell_count(code) != no_profile_data;
1699   }
1700 
1701   // reset into original state
1702   void init();
1703 
1704   // My size
1705   int size_in_bytes() const { return _size; }


1905 
1906   // GC support
1907   void set_size(int object_size_in_bytes) { _size = object_size_in_bytes; }
1908 
1909   // Printing
1910 #ifndef PRODUCT
1911   void print_on      (outputStream* st) const;
1912 #endif
1913   void print_value_on(outputStream* st) const;
1914 
1915 #ifndef PRODUCT
1916   // printing support for method data
1917   void print_data_on(outputStream* st) const;
1918 #endif
1919 
1920   const char* internal_name() const { return "{method data}"; }
1921 
1922   // verification
1923   void verify_on(outputStream* st);
1924   void verify_data_on(outputStream* st);
1925 
1926   static bool profile_arguments();
1927 };
1928 
1929 #endif // SHARE_VM_OOPS_METHODDATAOOP_HPP
src/share/vm/oops/methodData.hpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File