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

src/share/vm/oops/methodData.cpp

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


  39 //
  40 // Overlay for generic profiling data.
  41 
  42 // Some types of data layouts need a length field.
  43 bool DataLayout::needs_array_len(u1 tag) {
  44   return (tag == multi_branch_data_tag) || (tag == arg_info_data_tag);
  45 }
  46 
  47 // Perform generic initialization of the data.  More specific
  48 // initialization occurs in overrides of ProfileData::post_initialize.
  49 void DataLayout::initialize(u1 tag, u2 bci, int cell_count) {
  50   _header._bits = (intptr_t)0;
  51   _header._struct._tag = tag;
  52   _header._struct._bci = bci;
  53   for (int i = 0; i < cell_count; i++) {
  54     set_cell_at(i, (intptr_t)0);
  55   }
  56   if (needs_array_len(tag)) {
  57     set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header.
  58   }





  59 }
  60 
  61 void DataLayout::clean_weak_klass_links(BoolObjectClosure* cl) {
  62   ResourceMark m;
  63   data_in()->clean_weak_klass_links(cl);
  64 }
  65 
  66 
  67 // ==================================================================
  68 // ProfileData
  69 //
  70 // A ProfileData object is created to refer to a section of profiling
  71 // data in a structured way.
  72 
  73 // Constructor for invalid ProfileData.
  74 ProfileData::ProfileData() {
  75   _data = NULL;
  76 }
  77 
  78 #ifndef PRODUCT
  79 void ProfileData::print_shared(outputStream* st, const char* name) {
  80   st->print("bci: %d", bci());
  81   st->fill_to(tab_width_one);
  82   st->print("%s", name);
  83   tab(st);
  84   int trap = trap_state();
  85   if (trap != 0) {
  86     char buf[100];
  87     st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
  88   }
  89   int flags = data()->flags();
  90   if (flags != 0)
  91     st->print("flags(%d) ", flags);
  92 }
  93 
  94 void ProfileData::tab(outputStream* st) {
  95   st->fill_to(tab_width_two);
  96 }
  97 #endif // !PRODUCT
  98 
  99 // ==================================================================
 100 // BitData
 101 //
 102 // A BitData corresponds to a one-bit flag.  This is used to indicate
 103 // whether a checkcast bytecode has seen a null value.
 104 
 105 
 106 #ifndef PRODUCT
 107 void BitData::print_data_on(outputStream* st) {
 108   print_shared(st, "BitData");
 109 }
 110 #endif // !PRODUCT
 111 
 112 // ==================================================================
 113 // CounterData
 114 //
 115 // A CounterData corresponds to a simple counter.
 116 
 117 #ifndef PRODUCT
 118 void CounterData::print_data_on(outputStream* st) {
 119   print_shared(st, "CounterData");
 120   st->print_cr("count(%u)", count());
 121 }
 122 #endif // !PRODUCT
 123 
 124 // ==================================================================
 125 // JumpData
 126 //
 127 // A JumpData is used to access profiling information for a direct
 128 // branch.  It is a counter, used for counting the number of branches,
 129 // plus a data displacement, used for realigning the data pointer to
 130 // the corresponding target bci.
 131 
 132 void JumpData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 133   assert(stream->bci() == bci(), "wrong pos");
 134   int target;
 135   Bytecodes::Code c = stream->code();
 136   if (c == Bytecodes::_goto_w || c == Bytecodes::_jsr_w) {
 137     target = stream->dest_w();
 138   } else {
 139     target = stream->dest();
 140   }
 141   int my_di = mdo->dp_to_di(dp());
 142   int target_di = mdo->bci_to_di(target);
 143   int offset = target_di - my_di;
 144   set_displacement(offset);
 145 }
 146 
 147 #ifndef PRODUCT
 148 void JumpData::print_data_on(outputStream* st) {
 149   print_shared(st, "JumpData");
 150   st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
 151 }
 152 #endif // !PRODUCT
 153 




































































































































 154 // ==================================================================
 155 // ReceiverTypeData
 156 //
 157 // A ReceiverTypeData is used to access profiling information about a
 158 // dynamic type check.  It consists of a counter which counts the total times
 159 // that the check is reached, and a series of (Klass*, count) pairs
 160 // which are used to store a type profile for the receiver of the check.
 161 
 162 void ReceiverTypeData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
 163     for (uint row = 0; row < row_limit(); row++) {
 164     Klass* p = receiver(row);
 165     if (p != NULL && !p->is_loader_alive(is_alive_cl)) {
 166       clear_row(row);
 167     }
 168   }
 169 }
 170 
 171 #ifndef PRODUCT
 172 void ReceiverTypeData::print_receiver_data_on(outputStream* st) {
 173   uint row;
 174   int entries = 0;
 175   for (row = 0; row < row_limit(); row++) {
 176     if (receiver(row) != NULL)  entries++;
 177   }
 178   st->print_cr("count(%u) entries(%u)", count(), entries);
 179   int total = count();
 180   for (row = 0; row < row_limit(); row++) {
 181     if (receiver(row) != NULL) {
 182       total += receiver_count(row);
 183     }
 184   }
 185   for (row = 0; row < row_limit(); row++) {
 186     if (receiver(row) != NULL) {
 187       tab(st);
 188       receiver(row)->print_value_on(st);
 189       st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total);
 190     }
 191   }
 192 }
 193 void ReceiverTypeData::print_data_on(outputStream* st) {
 194   print_shared(st, "ReceiverTypeData");
 195   print_receiver_data_on(st);
 196 }
 197 void VirtualCallData::print_data_on(outputStream* st) {
 198   print_shared(st, "VirtualCallData");
 199   print_receiver_data_on(st);
 200 }
 201 #endif // !PRODUCT
 202 
 203 // ==================================================================
 204 // RetData
 205 //
 206 // A RetData is used to access profiling information for a ret bytecode.
 207 // It is composed of a count of the number of times that the ret has
 208 // been executed, followed by a series of triples of the form
 209 // (bci, count, di) which count the number of times that some bci was the
 210 // target of the ret and cache a corresponding displacement.
 211 
 212 void RetData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 213   for (uint row = 0; row < row_limit(); row++) {
 214     set_bci_displacement(row, -1);
 215     set_bci(row, no_bci);
 216   }
 217   // release so other threads see a consistent state.  bci is used as


 229 address RetData::fixup_ret(int return_bci, MethodData* h_mdo) {
 230   // First find the mdp which corresponds to the return bci.
 231   address mdp = h_mdo->bci_to_dp(return_bci);
 232 
 233   // Now check to see if any of the cache slots are open.
 234   for (uint row = 0; row < row_limit(); row++) {
 235     if (bci(row) == no_bci) {
 236       set_bci_displacement(row, mdp - dp());
 237       set_bci_count(row, DataLayout::counter_increment);
 238       // Barrier to ensure displacement is written before the bci; allows
 239       // the interpreter to read displacement without fear of race condition.
 240       release_set_bci(row, return_bci);
 241       break;
 242     }
 243   }
 244   return mdp;
 245 }
 246 
 247 
 248 #ifndef PRODUCT
 249 void RetData::print_data_on(outputStream* st) {
 250   print_shared(st, "RetData");
 251   uint row;
 252   int entries = 0;
 253   for (row = 0; row < row_limit(); row++) {
 254     if (bci(row) != no_bci)  entries++;
 255   }
 256   st->print_cr("count(%u) entries(%u)", count(), entries);
 257   for (row = 0; row < row_limit(); row++) {
 258     if (bci(row) != no_bci) {
 259       tab(st);
 260       st->print_cr("bci(%d: count(%u) displacement(%d))",
 261                    bci(row), bci_count(row), bci_displacement(row));
 262     }
 263   }
 264 }
 265 #endif // !PRODUCT
 266 
 267 // ==================================================================
 268 // BranchData
 269 //
 270 // A BranchData is used to access profiling data for a two-way branch.
 271 // It consists of taken and not_taken counts as well as a data displacement
 272 // for the taken case.
 273 
 274 void BranchData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 275   assert(stream->bci() == bci(), "wrong pos");
 276   int target = stream->dest();
 277   int my_di = mdo->dp_to_di(dp());
 278   int target_di = mdo->bci_to_di(target);
 279   int offset = target_di - my_di;
 280   set_displacement(offset);
 281 }
 282 
 283 #ifndef PRODUCT
 284 void BranchData::print_data_on(outputStream* st) {
 285   print_shared(st, "BranchData");
 286   st->print_cr("taken(%u) displacement(%d)",
 287                taken(), displacement());
 288   tab(st);
 289   st->print_cr("not taken(%u)", not_taken());
 290 }
 291 #endif
 292 
 293 // ==================================================================
 294 // MultiBranchData
 295 //
 296 // A MultiBranchData is used to access profiling information for
 297 // a multi-way branch (*switch bytecodes).  It consists of a series
 298 // of (count, displacement) pairs, which count the number of times each
 299 // case was taken and specify the data displacment for each branch target.
 300 
 301 int MultiBranchData::compute_cell_count(BytecodeStream* stream) {
 302   int cell_count = 0;
 303   if (stream->code() == Bytecodes::_tableswitch) {
 304     Bytecode_tableswitch sw(stream->method()(), stream->bcp());


 338     Bytecode_lookupswitch sw(stream->method()(), stream->bcp());
 339     int npairs = sw.number_of_pairs();
 340     assert(array_len() == per_case_cell_count * (npairs + 1), "wrong len");
 341     for (int count = 0; count < npairs; count++) {
 342       LookupswitchPair pair = sw.pair_at(count);
 343       target = pair.offset() + bci();
 344       my_di = mdo->dp_to_di(dp());
 345       target_di = mdo->bci_to_di(target);
 346       offset = target_di - my_di;
 347       set_displacement_at(count, offset);
 348     }
 349     target = sw.default_offset() + bci();
 350     my_di = mdo->dp_to_di(dp());
 351     target_di = mdo->bci_to_di(target);
 352     offset = target_di - my_di;
 353     set_default_displacement(offset);
 354   }
 355 }
 356 
 357 #ifndef PRODUCT
 358 void MultiBranchData::print_data_on(outputStream* st) {
 359   print_shared(st, "MultiBranchData");
 360   st->print_cr("default_count(%u) displacement(%d)",
 361                default_count(), default_displacement());
 362   int cases = number_of_cases();
 363   for (int i = 0; i < cases; i++) {
 364     tab(st);
 365     st->print_cr("count(%u) displacement(%d)",
 366                  count_at(i), displacement_at(i));
 367   }
 368 }
 369 #endif
 370 
 371 #ifndef PRODUCT
 372 void ArgInfoData::print_data_on(outputStream* st) {
 373   print_shared(st, "ArgInfoData");
 374   int nargs = number_of_args();
 375   for (int i = 0; i < nargs; i++) {
 376     st->print("  0x%x", arg_modified(i));
 377   }
 378   st->cr();
 379 }
 380 
 381 #endif
 382 // ==================================================================
 383 // MethodData*
 384 //
 385 // A MethodData* holds information which has been collected about
 386 // a method.
 387 
 388 MethodData* MethodData::allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS) {
 389   int size = MethodData::compute_allocation_size_in_words(method);
 390 
 391   return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD)
 392     MethodData(method(), size, CHECK_NULL);
 393 }
 394 
 395 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
 396 #if defined(COMPILER1) && !defined(COMPILER2)
 397   return no_profile_data;
 398 #else
 399   switch (code) {
 400   case Bytecodes::_checkcast:
 401   case Bytecodes::_instanceof:
 402   case Bytecodes::_aastore:
 403     if (TypeProfileCasts) {
 404       return ReceiverTypeData::static_cell_count();
 405     } else {
 406       return BitData::static_cell_count();
 407     }
 408   case Bytecodes::_invokespecial:
 409   case Bytecodes::_invokestatic:



 410     return CounterData::static_cell_count();

 411   case Bytecodes::_goto:
 412   case Bytecodes::_goto_w:
 413   case Bytecodes::_jsr:
 414   case Bytecodes::_jsr_w:
 415     return JumpData::static_cell_count();
 416   case Bytecodes::_invokevirtual:
 417   case Bytecodes::_invokeinterface:



 418     return VirtualCallData::static_cell_count();

 419   case Bytecodes::_invokedynamic:



 420     return CounterData::static_cell_count();

 421   case Bytecodes::_ret:
 422     return RetData::static_cell_count();
 423   case Bytecodes::_ifeq:
 424   case Bytecodes::_ifne:
 425   case Bytecodes::_iflt:
 426   case Bytecodes::_ifge:
 427   case Bytecodes::_ifgt:
 428   case Bytecodes::_ifle:
 429   case Bytecodes::_if_icmpeq:
 430   case Bytecodes::_if_icmpne:
 431   case Bytecodes::_if_icmplt:
 432   case Bytecodes::_if_icmpge:
 433   case Bytecodes::_if_icmpgt:
 434   case Bytecodes::_if_icmple:
 435   case Bytecodes::_if_acmpeq:
 436   case Bytecodes::_if_acmpne:
 437   case Bytecodes::_ifnull:
 438   case Bytecodes::_ifnonnull:
 439     return BranchData::static_cell_count();
 440   case Bytecodes::_lookupswitch:
 441   case Bytecodes::_tableswitch:
 442     return variable_cell_count;
 443   }
 444   return no_profile_data;
 445 #endif
 446 }
 447 
 448 // Compute the size of the profiling information corresponding to
 449 // the current bytecode.
 450 int MethodData::compute_data_size(BytecodeStream* stream) {
 451   int cell_count = bytecode_cell_count(stream->code());
 452   if (cell_count == no_profile_data) {
 453     return 0;
 454   }
 455   if (cell_count == variable_cell_count) {



 456     cell_count = MultiBranchData::compute_cell_count(stream);
























 457   }
 458   // Note:  cell_count might be zero, meaning that there is just
 459   //        a DataLayout header, with no extra cells.
 460   assert(cell_count >= 0, "sanity");
 461   return DataLayout::compute_size_in_bytes(cell_count);
 462 }
 463 
 464 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) {
 465   if (ProfileTraps) {
 466     // Assume that up to 3% of BCIs with no MDP will need to allocate one.
 467     int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;
 468     // If the method is large, let the extra BCIs grow numerous (to ~1%).
 469     int one_percent_of_data
 470       = (uint)data_size / (DataLayout::header_size_in_bytes()*128);
 471     if (extra_data_count < one_percent_of_data)
 472       extra_data_count = one_percent_of_data;
 473     if (extra_data_count > empty_bc_count)
 474       extra_data_count = empty_bc_count;  // no need for more
 475     return extra_data_count;
 476   } else {


 482 // profiling information about a given method.  Size is in bytes.
 483 int MethodData::compute_allocation_size_in_bytes(methodHandle method) {
 484   int data_size = 0;
 485   BytecodeStream stream(method);
 486   Bytecodes::Code c;
 487   int empty_bc_count = 0;  // number of bytecodes lacking data
 488   while ((c = stream.next()) >= 0) {
 489     int size_in_bytes = compute_data_size(&stream);
 490     data_size += size_in_bytes;
 491     if (size_in_bytes == 0)  empty_bc_count += 1;
 492   }
 493   int object_size = in_bytes(data_offset()) + data_size;
 494 
 495   // Add some extra DataLayout cells (at least one) to track stray traps.
 496   int extra_data_count = compute_extra_data_count(data_size, empty_bc_count);
 497   object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);
 498 
 499   // Add a cell to record information about modified arguments.
 500   int arg_size = method->size_of_parameters();
 501   object_size += DataLayout::compute_size_in_bytes(arg_size+1);

 502   return object_size;
 503 }
 504 
 505 // Compute the size of the MethodData* necessary to store
 506 // profiling information about a given method.  Size is in words
 507 int MethodData::compute_allocation_size_in_words(methodHandle method) {
 508   int byte_size = compute_allocation_size_in_bytes(method);
 509   int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord;
 510   return align_object_size(word_size);
 511 }
 512 
 513 // Initialize an individual data segment.  Returns the size of
 514 // the segment in bytes.
 515 int MethodData::initialize_data(BytecodeStream* stream,
 516                                        int data_index) {
 517 #if defined(COMPILER1) && !defined(COMPILER2)
 518   return 0;
 519 #else
 520   int cell_count = -1;
 521   int tag = DataLayout::no_tag;
 522   DataLayout* data_layout = data_layout_at(data_index);
 523   Bytecodes::Code c = stream->code();
 524   switch (c) {
 525   case Bytecodes::_checkcast:
 526   case Bytecodes::_instanceof:
 527   case Bytecodes::_aastore:
 528     if (TypeProfileCasts) {
 529       cell_count = ReceiverTypeData::static_cell_count();
 530       tag = DataLayout::receiver_type_data_tag;
 531     } else {
 532       cell_count = BitData::static_cell_count();
 533       tag = DataLayout::bit_data_tag;
 534     }
 535     break;
 536   case Bytecodes::_invokespecial:
 537   case Bytecodes::_invokestatic:
 538     cell_count = CounterData::static_cell_count();








 539     tag = DataLayout::counter_data_tag;

 540     break;

 541   case Bytecodes::_goto:
 542   case Bytecodes::_goto_w:
 543   case Bytecodes::_jsr:
 544   case Bytecodes::_jsr_w:
 545     cell_count = JumpData::static_cell_count();
 546     tag = DataLayout::jump_data_tag;
 547     break;
 548   case Bytecodes::_invokevirtual:
 549   case Bytecodes::_invokeinterface:
 550     cell_count = VirtualCallData::static_cell_count();








 551     tag = DataLayout::virtual_call_data_tag;

 552     break;
 553   case Bytecodes::_invokedynamic:

 554     // %%% should make a type profile for any invokedynamic that takes a ref argument
 555     cell_count = CounterData::static_cell_count();








 556     tag = DataLayout::counter_data_tag;

 557     break;

 558   case Bytecodes::_ret:
 559     cell_count = RetData::static_cell_count();
 560     tag = DataLayout::ret_data_tag;
 561     break;
 562   case Bytecodes::_ifeq:
 563   case Bytecodes::_ifne:
 564   case Bytecodes::_iflt:
 565   case Bytecodes::_ifge:
 566   case Bytecodes::_ifgt:
 567   case Bytecodes::_ifle:
 568   case Bytecodes::_if_icmpeq:
 569   case Bytecodes::_if_icmpne:
 570   case Bytecodes::_if_icmplt:
 571   case Bytecodes::_if_icmpge:
 572   case Bytecodes::_if_icmpgt:
 573   case Bytecodes::_if_icmple:
 574   case Bytecodes::_if_acmpeq:
 575   case Bytecodes::_if_acmpne:
 576   case Bytecodes::_ifnull:
 577   case Bytecodes::_ifnonnull:
 578     cell_count = BranchData::static_cell_count();
 579     tag = DataLayout::branch_data_tag;
 580     break;
 581   case Bytecodes::_lookupswitch:
 582   case Bytecodes::_tableswitch:
 583     cell_count = MultiBranchData::compute_cell_count(stream);
 584     tag = DataLayout::multi_branch_data_tag;
 585     break;
 586   }
 587   assert(tag == DataLayout::multi_branch_data_tag ||





 588          cell_count == bytecode_cell_count(c), "cell counts must agree");
 589   if (cell_count >= 0) {
 590     assert(tag != DataLayout::no_tag, "bad tag");
 591     assert(bytecode_has_profile(c), "agree w/ BHP");
 592     data_layout->initialize(tag, stream->bci(), cell_count);
 593     return DataLayout::compute_size_in_bytes(cell_count);
 594   } else {
 595     assert(!bytecode_has_profile(c), "agree w/ !BHP");
 596     return 0;
 597   }
 598 #endif
 599 }
 600 
 601 // Get the data at an arbitrary (sort of) data index.
 602 ProfileData* MethodData::data_at(int data_index) const {
 603   if (out_of_bounds(data_index)) {
 604     return NULL;
 605   }
 606   DataLayout* data_layout = data_layout_at(data_index);
 607   return data_layout->data_in();


 614     ShouldNotReachHere();
 615     return NULL;
 616   case DataLayout::bit_data_tag:
 617     return new BitData(this);
 618   case DataLayout::counter_data_tag:
 619     return new CounterData(this);
 620   case DataLayout::jump_data_tag:
 621     return new JumpData(this);
 622   case DataLayout::receiver_type_data_tag:
 623     return new ReceiverTypeData(this);
 624   case DataLayout::virtual_call_data_tag:
 625     return new VirtualCallData(this);
 626   case DataLayout::ret_data_tag:
 627     return new RetData(this);
 628   case DataLayout::branch_data_tag:
 629     return new BranchData(this);
 630   case DataLayout::multi_branch_data_tag:
 631     return new MultiBranchData(this);
 632   case DataLayout::arg_info_data_tag:
 633     return new ArgInfoData(this);




 634   };
 635 }
 636 
 637 // Iteration over data.
 638 ProfileData* MethodData::next_data(ProfileData* current) const {
 639   int current_index = dp_to_di(current->dp());
 640   int next_index = current_index + current->size_in_bytes();
 641   ProfileData* next = data_at(next_index);
 642   return next;
 643 }
 644 
 645 // Give each of the data entries a chance to perform specific
 646 // data initialization.
 647 void MethodData::post_initialize(BytecodeStream* stream) {
 648   ResourceMark rm;
 649   ProfileData* data;
 650   for (data = first_data(); is_valid(data); data = next_data(data)) {
 651     stream->set_start(data->bci());
 652     stream->next();
 653     data->post_initialize(stream, this);


 881 void MethodData::collect_statistics(KlassSizeStats *sz) const {
 882   int n = sz->count(this);
 883   sz->_method_data_bytes += n;
 884   sz->_method_all_bytes += n;
 885   sz->_rw_bytes += n;
 886 }
 887 #endif // INCLUDE_SERVICES
 888 
 889 // Verification
 890 
 891 void MethodData::verify_on(outputStream* st) {
 892   guarantee(is_methodData(), "object must be method data");
 893   // guarantee(m->is_perm(), "should be in permspace");
 894   this->verify_data_on(st);
 895 }
 896 
 897 void MethodData::verify_data_on(outputStream* st) {
 898   NEEDS_CLEANUP;
 899   // not yet implemented.
 900 }











































  39 //
  40 // Overlay for generic profiling data.
  41 
  42 // Some types of data layouts need a length field.
  43 bool DataLayout::needs_array_len(u1 tag) {
  44   return (tag == multi_branch_data_tag) || (tag == arg_info_data_tag);
  45 }
  46 
  47 // Perform generic initialization of the data.  More specific
  48 // initialization occurs in overrides of ProfileData::post_initialize.
  49 void DataLayout::initialize(u1 tag, u2 bci, int cell_count) {
  50   _header._bits = (intptr_t)0;
  51   _header._struct._tag = tag;
  52   _header._struct._bci = bci;
  53   for (int i = 0; i < cell_count; i++) {
  54     set_cell_at(i, (intptr_t)0);
  55   }
  56   if (needs_array_len(tag)) {
  57     set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header.
  58   }
  59   if (tag == call_type_data_tag) {
  60     CallTypeData::initialize(this, cell_count);
  61   } else if (tag == virtual_call_type_data_tag) {
  62     VirtualCallTypeData::initialize(this, cell_count);
  63   }
  64 }
  65 
  66 void DataLayout::clean_weak_klass_links(BoolObjectClosure* cl) {
  67   ResourceMark m;
  68   data_in()->clean_weak_klass_links(cl);
  69 }
  70 
  71 
  72 // ==================================================================
  73 // ProfileData
  74 //
  75 // A ProfileData object is created to refer to a section of profiling
  76 // data in a structured way.
  77 
  78 // Constructor for invalid ProfileData.
  79 ProfileData::ProfileData() {
  80   _data = NULL;
  81 }
  82 
  83 #ifndef PRODUCT
  84 void ProfileData::print_shared(outputStream* st, const char* name) const {
  85   st->print("bci: %d", bci());
  86   st->fill_to(tab_width_one);
  87   st->print("%s", name);
  88   tab(st);
  89   int trap = trap_state();
  90   if (trap != 0) {
  91     char buf[100];
  92     st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
  93   }
  94   int flags = data()->flags();
  95   if (flags != 0)
  96     st->print("flags(%d) ", flags);
  97 }
  98 
  99 void ProfileData::tab(outputStream* st, bool first) const {
 100   st->fill_to(first ? tab_width_one : tab_width_two);
 101 }
 102 #endif // !PRODUCT
 103 
 104 // ==================================================================
 105 // BitData
 106 //
 107 // A BitData corresponds to a one-bit flag.  This is used to indicate
 108 // whether a checkcast bytecode has seen a null value.
 109 
 110 
 111 #ifndef PRODUCT
 112 void BitData::print_data_on(outputStream* st) const {
 113   print_shared(st, "BitData");
 114 }
 115 #endif // !PRODUCT
 116 
 117 // ==================================================================
 118 // CounterData
 119 //
 120 // A CounterData corresponds to a simple counter.
 121 
 122 #ifndef PRODUCT
 123 void CounterData::print_data_on(outputStream* st) const {
 124   print_shared(st, "CounterData");
 125   st->print_cr("count(%u)", count());
 126 }
 127 #endif // !PRODUCT
 128 
 129 // ==================================================================
 130 // JumpData
 131 //
 132 // A JumpData is used to access profiling information for a direct
 133 // branch.  It is a counter, used for counting the number of branches,
 134 // plus a data displacement, used for realigning the data pointer to
 135 // the corresponding target bci.
 136 
 137 void JumpData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 138   assert(stream->bci() == bci(), "wrong pos");
 139   int target;
 140   Bytecodes::Code c = stream->code();
 141   if (c == Bytecodes::_goto_w || c == Bytecodes::_jsr_w) {
 142     target = stream->dest_w();
 143   } else {
 144     target = stream->dest();
 145   }
 146   int my_di = mdo->dp_to_di(dp());
 147   int target_di = mdo->bci_to_di(target);
 148   int offset = target_di - my_di;
 149   set_displacement(offset);
 150 }
 151 
 152 #ifndef PRODUCT
 153 void JumpData::print_data_on(outputStream* st) const {
 154   print_shared(st, "JumpData");
 155   st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
 156 }
 157 #endif // !PRODUCT
 158 
 159 int TypeStackSlotEntries::compute_cell_count(BytecodeStream* stream) {
 160   int max = TypeProfileArgsLimit;
 161   assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
 162   Bytecode_invoke inv(stream->method(), stream->bci());
 163   
 164   ResourceMark rm;
 165   SignatureStream ss(inv.signature());
 166   int args_count = 0;
 167   for ( ; !ss.at_return_type(); ss.next()) {
 168     if (ss.is_object() || ss.is_array()) {
 169       args_count++;
 170       if (args_count >= max) {
 171         break;
 172       }
 173     }
 174   }
 175   return args_count * per_arg_cell_count + (args_count > 0 ? header_cell_count() : 0);
 176 }
 177 
 178 class ArgumentOffsetComputer : public SignatureInfo {
 179 private:
 180   int _max;
 181   GrowableArray<int> _offsets;
 182 
 183   void set(int size, BasicType type) { _size += size; }
 184   void do_object(int begin, int end) {
 185     if (_offsets.length() < _max) {
 186       _offsets.push(_size);
 187     }
 188     SignatureInfo::do_object(begin, end);
 189   }
 190   void do_array (int begin, int end) {
 191     if (_offsets.length() < _max) {
 192       _offsets.push(_size);
 193     }
 194     SignatureInfo::do_array(begin, end);
 195   }
 196 
 197 public:
 198   ArgumentOffsetComputer(Symbol* signature, int max)
 199     : SignatureInfo(signature), _max(max), _offsets(Thread::current(), max) {
 200   }
 201 
 202   int total() { lazy_iterate_parameters(); return _size; }
 203 
 204   int off_at(int i) const { return _offsets.at(i); }
 205 };
 206 
 207 void TypeStackSlotEntries::post_initialize(BytecodeStream* stream) {
 208   ResourceMark rm;
 209 
 210   assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
 211   Bytecode_invoke inv(stream->method(), stream->bci());
 212 
 213 #ifdef ASSERT
 214   int count = 0;
 215   for (SignatureStream ss(inv.signature()); !ss.at_return_type(); ss.next()) {
 216     if (ss.is_object() || ss.is_array()) {
 217       count++;
 218       if (count >= TypeProfileArgsLimit) {
 219         break;
 220       }
 221     }
 222   }
 223   assert(count > 0, "room for args type but none found?");
 224   check_number_of_arguments(count);
 225 #endif
 226   
 227   int start = 0;
 228   ArgumentOffsetComputer aos(inv.signature(), number_of_arguments()-start);
 229   aos.total();
 230   bool has_receiver = inv.has_receiver();
 231   for (int i = start; i < number_of_arguments(); i++) {
 232     set_stack_slot(i, aos.off_at(i-start) + (has_receiver ? 1 : 0));
 233     set_type(i, type_none());
 234   }
 235 }
 236 
 237 bool TypeEntries::is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p) {
 238   return !is_type_none(p) &&
 239     !((Klass*)klass_part(p))->is_loader_alive(is_alive_cl);
 240 }
 241 
 242 void TypeStackSlotEntries::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
 243   for (int i = 0; i < number_of_arguments(); i++) {
 244     intptr_t p = type(i);
 245     if (is_loader_alive(is_alive_cl, p)) {
 246       set_type(i, type_none());
 247     }
 248   }
 249 }
 250 
 251 bool TypeStackSlotEntries::arguments_profiling_enabled() {
 252   return MethodData::profile_arguments();
 253 }
 254 
 255 #ifndef PRODUCT
 256 void TypeEntries::print_klass(outputStream* st, intptr_t k) {
 257   if (is_type_none(k)) {
 258     st->print("none");
 259   } else if (is_type_unknown(k)) {
 260     st->print("unknown");
 261   } else {
 262     valid_klass(k)->print_value_on(st);
 263   }
 264   if (was_null_seen(k)) {
 265     st->print(" (null seen)");
 266   }
 267 }
 268 
 269 void TypeStackSlotEntries::print_data_on(outputStream* st) const {
 270   _pd->tab(st, true);
 271   st->print("argument types");
 272   for (int i = 0; i < number_of_arguments(); i++) {
 273     _pd->tab(st);
 274     st->print("%d: stack(%u) ", i, stack_slot(i));
 275     print_klass(st, type(i));
 276     st->cr();
 277   }
 278 }
 279 
 280 void CallTypeData::print_data_on(outputStream* st) const {
 281   CounterData::print_data_on(st);
 282   _args.print_data_on(st);
 283 }
 284 
 285 void VirtualCallTypeData::print_data_on(outputStream* st) const {
 286   VirtualCallData::print_data_on(st);
 287   _args.print_data_on(st);
 288 }
 289 #endif
 290 
 291 // ==================================================================
 292 // ReceiverTypeData
 293 //
 294 // A ReceiverTypeData is used to access profiling information about a
 295 // dynamic type check.  It consists of a counter which counts the total times
 296 // that the check is reached, and a series of (Klass*, count) pairs
 297 // which are used to store a type profile for the receiver of the check.
 298 
 299 void ReceiverTypeData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
 300     for (uint row = 0; row < row_limit(); row++) {
 301     Klass* p = receiver(row);
 302     if (p != NULL && !p->is_loader_alive(is_alive_cl)) {
 303       clear_row(row);
 304     }
 305   }
 306 }
 307 
 308 #ifndef PRODUCT
 309 void ReceiverTypeData::print_receiver_data_on(outputStream* st) const {
 310   uint row;
 311   int entries = 0;
 312   for (row = 0; row < row_limit(); row++) {
 313     if (receiver(row) != NULL)  entries++;
 314   }
 315   st->print_cr("count(%u) entries(%u)", count(), entries);
 316   int total = count();
 317   for (row = 0; row < row_limit(); row++) {
 318     if (receiver(row) != NULL) {
 319       total += receiver_count(row);
 320     }
 321   }
 322   for (row = 0; row < row_limit(); row++) {
 323     if (receiver(row) != NULL) {
 324       tab(st);
 325       receiver(row)->print_value_on(st);
 326       st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total);
 327     }
 328   }
 329 }
 330 void ReceiverTypeData::print_data_on(outputStream* st) const {
 331   print_shared(st, "ReceiverTypeData");
 332   print_receiver_data_on(st);
 333 }
 334 void VirtualCallData::print_data_on(outputStream* st) const {
 335   print_shared(st, "VirtualCallData");
 336   print_receiver_data_on(st);
 337 }
 338 #endif // !PRODUCT
 339 
 340 // ==================================================================
 341 // RetData
 342 //
 343 // A RetData is used to access profiling information for a ret bytecode.
 344 // It is composed of a count of the number of times that the ret has
 345 // been executed, followed by a series of triples of the form
 346 // (bci, count, di) which count the number of times that some bci was the
 347 // target of the ret and cache a corresponding displacement.
 348 
 349 void RetData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 350   for (uint row = 0; row < row_limit(); row++) {
 351     set_bci_displacement(row, -1);
 352     set_bci(row, no_bci);
 353   }
 354   // release so other threads see a consistent state.  bci is used as


 366 address RetData::fixup_ret(int return_bci, MethodData* h_mdo) {
 367   // First find the mdp which corresponds to the return bci.
 368   address mdp = h_mdo->bci_to_dp(return_bci);
 369 
 370   // Now check to see if any of the cache slots are open.
 371   for (uint row = 0; row < row_limit(); row++) {
 372     if (bci(row) == no_bci) {
 373       set_bci_displacement(row, mdp - dp());
 374       set_bci_count(row, DataLayout::counter_increment);
 375       // Barrier to ensure displacement is written before the bci; allows
 376       // the interpreter to read displacement without fear of race condition.
 377       release_set_bci(row, return_bci);
 378       break;
 379     }
 380   }
 381   return mdp;
 382 }
 383 
 384 
 385 #ifndef PRODUCT
 386 void RetData::print_data_on(outputStream* st) const {
 387   print_shared(st, "RetData");
 388   uint row;
 389   int entries = 0;
 390   for (row = 0; row < row_limit(); row++) {
 391     if (bci(row) != no_bci)  entries++;
 392   }
 393   st->print_cr("count(%u) entries(%u)", count(), entries);
 394   for (row = 0; row < row_limit(); row++) {
 395     if (bci(row) != no_bci) {
 396       tab(st);
 397       st->print_cr("bci(%d: count(%u) displacement(%d))",
 398                    bci(row), bci_count(row), bci_displacement(row));
 399     }
 400   }
 401 }
 402 #endif // !PRODUCT
 403 
 404 // ==================================================================
 405 // BranchData
 406 //
 407 // A BranchData is used to access profiling data for a two-way branch.
 408 // It consists of taken and not_taken counts as well as a data displacement
 409 // for the taken case.
 410 
 411 void BranchData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 412   assert(stream->bci() == bci(), "wrong pos");
 413   int target = stream->dest();
 414   int my_di = mdo->dp_to_di(dp());
 415   int target_di = mdo->bci_to_di(target);
 416   int offset = target_di - my_di;
 417   set_displacement(offset);
 418 }
 419 
 420 #ifndef PRODUCT
 421 void BranchData::print_data_on(outputStream* st) const {
 422   print_shared(st, "BranchData");
 423   st->print_cr("taken(%u) displacement(%d)",
 424                taken(), displacement());
 425   tab(st);
 426   st->print_cr("not taken(%u)", not_taken());
 427 }
 428 #endif
 429 
 430 // ==================================================================
 431 // MultiBranchData
 432 //
 433 // A MultiBranchData is used to access profiling information for
 434 // a multi-way branch (*switch bytecodes).  It consists of a series
 435 // of (count, displacement) pairs, which count the number of times each
 436 // case was taken and specify the data displacment for each branch target.
 437 
 438 int MultiBranchData::compute_cell_count(BytecodeStream* stream) {
 439   int cell_count = 0;
 440   if (stream->code() == Bytecodes::_tableswitch) {
 441     Bytecode_tableswitch sw(stream->method()(), stream->bcp());


 475     Bytecode_lookupswitch sw(stream->method()(), stream->bcp());
 476     int npairs = sw.number_of_pairs();
 477     assert(array_len() == per_case_cell_count * (npairs + 1), "wrong len");
 478     for (int count = 0; count < npairs; count++) {
 479       LookupswitchPair pair = sw.pair_at(count);
 480       target = pair.offset() + bci();
 481       my_di = mdo->dp_to_di(dp());
 482       target_di = mdo->bci_to_di(target);
 483       offset = target_di - my_di;
 484       set_displacement_at(count, offset);
 485     }
 486     target = sw.default_offset() + bci();
 487     my_di = mdo->dp_to_di(dp());
 488     target_di = mdo->bci_to_di(target);
 489     offset = target_di - my_di;
 490     set_default_displacement(offset);
 491   }
 492 }
 493 
 494 #ifndef PRODUCT
 495 void MultiBranchData::print_data_on(outputStream* st) const {
 496   print_shared(st, "MultiBranchData");
 497   st->print_cr("default_count(%u) displacement(%d)",
 498                default_count(), default_displacement());
 499   int cases = number_of_cases();
 500   for (int i = 0; i < cases; i++) {
 501     tab(st);
 502     st->print_cr("count(%u) displacement(%d)",
 503                  count_at(i), displacement_at(i));
 504   }
 505 }
 506 #endif
 507 
 508 #ifndef PRODUCT
 509 void ArgInfoData::print_data_on(outputStream* st) const {
 510   print_shared(st, "ArgInfoData");
 511   int nargs = number_of_args();
 512   for (int i = 0; i < nargs; i++) {
 513     st->print("  0x%x", arg_modified(i));
 514   }
 515   st->cr();
 516 }
 517 
 518 #endif
 519 // ==================================================================
 520 // MethodData*
 521 //
 522 // A MethodData* holds information which has been collected about
 523 // a method.
 524 
 525 MethodData* MethodData::allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS) {
 526   int size = MethodData::compute_allocation_size_in_words(method);
 527 
 528   return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD)
 529     MethodData(method(), size, CHECK_NULL);
 530 }
 531 
 532 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
 533 #if defined(COMPILER1) && !defined(COMPILER2)
 534   return no_profile_data;
 535 #else
 536   switch (code) {
 537   case Bytecodes::_checkcast:
 538   case Bytecodes::_instanceof:
 539   case Bytecodes::_aastore:
 540     if (TypeProfileCasts) {
 541       return ReceiverTypeData::static_cell_count();
 542     } else {
 543       return BitData::static_cell_count();
 544     }
 545   case Bytecodes::_invokespecial:
 546   case Bytecodes::_invokestatic:
 547     if (MethodData::profile_arguments()) {
 548       return variable_cell_count;
 549     } else {
 550       return CounterData::static_cell_count();
 551     }
 552   case Bytecodes::_goto:
 553   case Bytecodes::_goto_w:
 554   case Bytecodes::_jsr:
 555   case Bytecodes::_jsr_w:
 556     return JumpData::static_cell_count();
 557   case Bytecodes::_invokevirtual:
 558   case Bytecodes::_invokeinterface:
 559     if (MethodData::profile_arguments()) {
 560       return variable_cell_count;
 561     } else {
 562       return VirtualCallData::static_cell_count();
 563     }
 564   case Bytecodes::_invokedynamic:
 565     if (MethodData::profile_arguments()) {
 566       return variable_cell_count;
 567     } else {
 568       return CounterData::static_cell_count();
 569     }
 570   case Bytecodes::_ret:
 571     return RetData::static_cell_count();
 572   case Bytecodes::_ifeq:
 573   case Bytecodes::_ifne:
 574   case Bytecodes::_iflt:
 575   case Bytecodes::_ifge:
 576   case Bytecodes::_ifgt:
 577   case Bytecodes::_ifle:
 578   case Bytecodes::_if_icmpeq:
 579   case Bytecodes::_if_icmpne:
 580   case Bytecodes::_if_icmplt:
 581   case Bytecodes::_if_icmpge:
 582   case Bytecodes::_if_icmpgt:
 583   case Bytecodes::_if_icmple:
 584   case Bytecodes::_if_acmpeq:
 585   case Bytecodes::_if_acmpne:
 586   case Bytecodes::_ifnull:
 587   case Bytecodes::_ifnonnull:
 588     return BranchData::static_cell_count();
 589   case Bytecodes::_lookupswitch:
 590   case Bytecodes::_tableswitch:
 591     return variable_cell_count;
 592   }
 593   return no_profile_data;
 594 #endif
 595 }
 596 
 597 // Compute the size of the profiling information corresponding to
 598 // the current bytecode.
 599 int MethodData::compute_data_size(BytecodeStream* stream) {
 600   int cell_count = bytecode_cell_count(stream->code());
 601   if (cell_count == no_profile_data) {
 602     return 0;
 603   }
 604   if (cell_count == variable_cell_count) {
 605     switch (stream->code()) {
 606     case Bytecodes::_lookupswitch:
 607     case Bytecodes::_tableswitch:
 608       cell_count = MultiBranchData::compute_cell_count(stream);
 609       break;
 610     case Bytecodes::_invokespecial:
 611     case Bytecodes::_invokestatic:
 612     case Bytecodes::_invokedynamic:
 613       assert(MethodData::profile_arguments(), "should be collecting args profile");
 614       if (profile_arguments_for_invoke(stream->method(), stream->bci())) {
 615         cell_count = CallTypeData::compute_cell_count(stream);
 616       } else {
 617         cell_count = CounterData::static_cell_count();
 618       }
 619       break;
 620     case Bytecodes::_invokevirtual:
 621     case Bytecodes::_invokeinterface: {
 622       assert(MethodData::profile_arguments(), "should be collecting args profile");
 623       if (profile_arguments_for_invoke(stream->method(), stream->bci())) {
 624         cell_count = VirtualCallTypeData::compute_cell_count(stream);
 625       } else {
 626         cell_count = VirtualCallData::static_cell_count();
 627       }
 628       break;
 629     }
 630     default:
 631       fatal("unexpected bytecode for var length profile data");
 632     }
 633   }
 634   // Note:  cell_count might be zero, meaning that there is just
 635   //        a DataLayout header, with no extra cells.
 636   assert(cell_count >= 0, "sanity");
 637   return DataLayout::compute_size_in_bytes(cell_count);
 638 }
 639 
 640 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) {
 641   if (ProfileTraps) {
 642     // Assume that up to 3% of BCIs with no MDP will need to allocate one.
 643     int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;
 644     // If the method is large, let the extra BCIs grow numerous (to ~1%).
 645     int one_percent_of_data
 646       = (uint)data_size / (DataLayout::header_size_in_bytes()*128);
 647     if (extra_data_count < one_percent_of_data)
 648       extra_data_count = one_percent_of_data;
 649     if (extra_data_count > empty_bc_count)
 650       extra_data_count = empty_bc_count;  // no need for more
 651     return extra_data_count;
 652   } else {


 658 // profiling information about a given method.  Size is in bytes.
 659 int MethodData::compute_allocation_size_in_bytes(methodHandle method) {
 660   int data_size = 0;
 661   BytecodeStream stream(method);
 662   Bytecodes::Code c;
 663   int empty_bc_count = 0;  // number of bytecodes lacking data
 664   while ((c = stream.next()) >= 0) {
 665     int size_in_bytes = compute_data_size(&stream);
 666     data_size += size_in_bytes;
 667     if (size_in_bytes == 0)  empty_bc_count += 1;
 668   }
 669   int object_size = in_bytes(data_offset()) + data_size;
 670 
 671   // Add some extra DataLayout cells (at least one) to track stray traps.
 672   int extra_data_count = compute_extra_data_count(data_size, empty_bc_count);
 673   object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);
 674 
 675   // Add a cell to record information about modified arguments.
 676   int arg_size = method->size_of_parameters();
 677   object_size += DataLayout::compute_size_in_bytes(arg_size+1);
 678 
 679   return object_size;
 680 }
 681 
 682 // Compute the size of the MethodData* necessary to store
 683 // profiling information about a given method.  Size is in words
 684 int MethodData::compute_allocation_size_in_words(methodHandle method) {
 685   int byte_size = compute_allocation_size_in_bytes(method);
 686   int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord;
 687   return align_object_size(word_size);
 688 }
 689 
 690 // Initialize an individual data segment.  Returns the size of
 691 // the segment in bytes.
 692 int MethodData::initialize_data(BytecodeStream* stream,
 693                                        int data_index) {
 694 #if defined(COMPILER1) && !defined(COMPILER2)
 695   return 0;
 696 #else
 697   int cell_count = -1;
 698   int tag = DataLayout::no_tag;
 699   DataLayout* data_layout = data_layout_at(data_index);
 700   Bytecodes::Code c = stream->code();
 701   switch (c) {
 702   case Bytecodes::_checkcast:
 703   case Bytecodes::_instanceof:
 704   case Bytecodes::_aastore:
 705     if (TypeProfileCasts) {
 706       cell_count = ReceiverTypeData::static_cell_count();
 707       tag = DataLayout::receiver_type_data_tag;
 708     } else {
 709       cell_count = BitData::static_cell_count();
 710       tag = DataLayout::bit_data_tag;
 711     }
 712     break;
 713   case Bytecodes::_invokespecial:
 714   case Bytecodes::_invokestatic: {
 715     int counter_data_cell_count = CounterData::static_cell_count();
 716     if (profile_arguments_for_invoke(stream->method(), stream->bci())) {
 717       cell_count = CallTypeData::compute_cell_count(stream);
 718     } else {
 719       cell_count = counter_data_cell_count;
 720     }
 721     if (cell_count > counter_data_cell_count) {
 722       tag = DataLayout::call_type_data_tag;
 723     } else {
 724       tag = DataLayout::counter_data_tag;
 725     }
 726     break;
 727   }
 728   case Bytecodes::_goto:
 729   case Bytecodes::_goto_w:
 730   case Bytecodes::_jsr:
 731   case Bytecodes::_jsr_w:
 732     cell_count = JumpData::static_cell_count();
 733     tag = DataLayout::jump_data_tag;
 734     break;
 735   case Bytecodes::_invokevirtual:
 736   case Bytecodes::_invokeinterface: {
 737     int virtual_call_data_cell_count = VirtualCallData::static_cell_count();
 738     if (profile_arguments_for_invoke(stream->method(), stream->bci())) {
 739       cell_count = VirtualCallTypeData::compute_cell_count(stream);
 740     } else {
 741       cell_count = virtual_call_data_cell_count;
 742     }
 743     if (cell_count > virtual_call_data_cell_count) {
 744       tag = DataLayout::virtual_call_type_data_tag;
 745     } else {
 746       tag = DataLayout::virtual_call_data_tag;
 747     }
 748     break;
 749   }
 750   case Bytecodes::_invokedynamic: {
 751     // %%% should make a type profile for any invokedynamic that takes a ref argument
 752     int counter_data_cell_count = CounterData::static_cell_count();
 753     if (profile_arguments_for_invoke(stream->method(), stream->bci())) {
 754       cell_count = CallTypeData::compute_cell_count(stream);
 755     } else {
 756       cell_count = counter_data_cell_count;
 757     }
 758     if (cell_count > counter_data_cell_count) {
 759       tag = DataLayout::call_type_data_tag;
 760     } else {
 761       tag = DataLayout::counter_data_tag;
 762     }
 763     break;
 764   }
 765   case Bytecodes::_ret:
 766     cell_count = RetData::static_cell_count();
 767     tag = DataLayout::ret_data_tag;
 768     break;
 769   case Bytecodes::_ifeq:
 770   case Bytecodes::_ifne:
 771   case Bytecodes::_iflt:
 772   case Bytecodes::_ifge:
 773   case Bytecodes::_ifgt:
 774   case Bytecodes::_ifle:
 775   case Bytecodes::_if_icmpeq:
 776   case Bytecodes::_if_icmpne:
 777   case Bytecodes::_if_icmplt:
 778   case Bytecodes::_if_icmpge:
 779   case Bytecodes::_if_icmpgt:
 780   case Bytecodes::_if_icmple:
 781   case Bytecodes::_if_acmpeq:
 782   case Bytecodes::_if_acmpne:
 783   case Bytecodes::_ifnull:
 784   case Bytecodes::_ifnonnull:
 785     cell_count = BranchData::static_cell_count();
 786     tag = DataLayout::branch_data_tag;
 787     break;
 788   case Bytecodes::_lookupswitch:
 789   case Bytecodes::_tableswitch:
 790     cell_count = MultiBranchData::compute_cell_count(stream);
 791     tag = DataLayout::multi_branch_data_tag;
 792     break;
 793   }
 794   assert(tag == DataLayout::multi_branch_data_tag ||
 795          (MethodData::profile_arguments() &&
 796           (tag == DataLayout::call_type_data_tag ||
 797            tag == DataLayout::counter_data_tag ||
 798            tag == DataLayout::virtual_call_type_data_tag ||
 799            tag == DataLayout::virtual_call_data_tag)) ||
 800          cell_count == bytecode_cell_count(c), "cell counts must agree");
 801   if (cell_count >= 0) {
 802     assert(tag != DataLayout::no_tag, "bad tag");
 803     assert(bytecode_has_profile(c), "agree w/ BHP");
 804     data_layout->initialize(tag, stream->bci(), cell_count);
 805     return DataLayout::compute_size_in_bytes(cell_count);
 806   } else {
 807     assert(!bytecode_has_profile(c), "agree w/ !BHP");
 808     return 0;
 809   }
 810 #endif
 811 }
 812 
 813 // Get the data at an arbitrary (sort of) data index.
 814 ProfileData* MethodData::data_at(int data_index) const {
 815   if (out_of_bounds(data_index)) {
 816     return NULL;
 817   }
 818   DataLayout* data_layout = data_layout_at(data_index);
 819   return data_layout->data_in();


 826     ShouldNotReachHere();
 827     return NULL;
 828   case DataLayout::bit_data_tag:
 829     return new BitData(this);
 830   case DataLayout::counter_data_tag:
 831     return new CounterData(this);
 832   case DataLayout::jump_data_tag:
 833     return new JumpData(this);
 834   case DataLayout::receiver_type_data_tag:
 835     return new ReceiverTypeData(this);
 836   case DataLayout::virtual_call_data_tag:
 837     return new VirtualCallData(this);
 838   case DataLayout::ret_data_tag:
 839     return new RetData(this);
 840   case DataLayout::branch_data_tag:
 841     return new BranchData(this);
 842   case DataLayout::multi_branch_data_tag:
 843     return new MultiBranchData(this);
 844   case DataLayout::arg_info_data_tag:
 845     return new ArgInfoData(this);
 846   case DataLayout::call_type_data_tag:
 847     return new CallTypeData(this);
 848   case DataLayout::virtual_call_type_data_tag:
 849     return new VirtualCallTypeData(this);
 850   };
 851 }
 852 
 853 // Iteration over data.
 854 ProfileData* MethodData::next_data(ProfileData* current) const {
 855   int current_index = dp_to_di(current->dp());
 856   int next_index = current_index + current->size_in_bytes();
 857   ProfileData* next = data_at(next_index);
 858   return next;
 859 }
 860 
 861 // Give each of the data entries a chance to perform specific
 862 // data initialization.
 863 void MethodData::post_initialize(BytecodeStream* stream) {
 864   ResourceMark rm;
 865   ProfileData* data;
 866   for (data = first_data(); is_valid(data); data = next_data(data)) {
 867     stream->set_start(data->bci());
 868     stream->next();
 869     data->post_initialize(stream, this);


1097 void MethodData::collect_statistics(KlassSizeStats *sz) const {
1098   int n = sz->count(this);
1099   sz->_method_data_bytes += n;
1100   sz->_method_all_bytes += n;
1101   sz->_rw_bytes += n;
1102 }
1103 #endif // INCLUDE_SERVICES
1104 
1105 // Verification
1106 
1107 void MethodData::verify_on(outputStream* st) {
1108   guarantee(is_methodData(), "object must be method data");
1109   // guarantee(m->is_perm(), "should be in permspace");
1110   this->verify_data_on(st);
1111 }
1112 
1113 void MethodData::verify_data_on(outputStream* st) {
1114   NEEDS_CLEANUP;
1115   // not yet implemented.
1116 }
1117 
1118 bool MethodData::profile_jsr292(methodHandle m, int bci) {
1119   if (m->is_compiled_lambda_form()) {
1120     return true;
1121   }
1122 
1123   Bytecodes::Code bc = m->code_at(bci);
1124   assert(Bytecodes::is_invoke(m->java_code_at(bci)), "arguments only make sense at call");
1125 
1126   return bc == Bytecodes::_invokedynamic || bc == Bytecodes::_invokehandle;
1127 }
1128 
1129 int MethodData::profile_arguments_flag() {
1130   return TypeProfile % 10;
1131 }
1132 
1133 bool MethodData::profile_arguments() {
1134   return profile_arguments_flag() > 0 && profile_arguments_flag() <= 2;
1135 }
1136 
1137 bool MethodData::profile_arguments_jsr292_only() {
1138   return profile_arguments_flag() == 1;
1139 }
1140 
1141 bool MethodData::profile_all_arguments() {
1142   return profile_arguments_flag() == 2;
1143 }
1144 
1145 bool MethodData::profile_arguments_for_invoke(methodHandle m, int bci) {
1146   if (!profile_arguments()) {
1147     return false;
1148   }
1149   
1150   if (profile_all_arguments()) {
1151     return true;
1152   }
1153   
1154   assert(profile_arguments_jsr292_only(), "inconsistent");
1155   return profile_jsr292(m, bci);
1156 }
1157 
src/share/vm/oops/methodData.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File