< prev index next >

src/share/vm/oops/methodData.cpp

Print this page




 396   }
 397 }
 398 
 399 // ==================================================================
 400 // ReceiverTypeData
 401 //
 402 // A ReceiverTypeData is used to access profiling information about a
 403 // dynamic type check.  It consists of a counter which counts the total times
 404 // that the check is reached, and a series of (Klass*, count) pairs
 405 // which are used to store a type profile for the receiver of the check.
 406 
 407 void ReceiverTypeData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
 408     for (uint row = 0; row < row_limit(); row++) {
 409     Klass* p = receiver(row);
 410     if (p != NULL && !p->is_loader_alive(is_alive_cl)) {
 411       clear_row(row);
 412     }
 413   }
 414 }
 415 






















 416 void ReceiverTypeData::print_receiver_data_on(outputStream* st) const {
 417   uint row;
 418   int entries = 0;
 419   for (row = 0; row < row_limit(); row++) {
 420     if (receiver(row) != NULL)  entries++;
 421   }



 422   st->print_cr("count(%u) entries(%u)", count(), entries);

 423   int total = count();
 424   for (row = 0; row < row_limit(); row++) {
 425     if (receiver(row) != NULL) {
 426       total += receiver_count(row);
 427     }
 428   }
 429   for (row = 0; row < row_limit(); row++) {
 430     if (receiver(row) != NULL) {
 431       tab(st);
 432       receiver(row)->print_value_on(st);
 433       st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total);
 434     }
 435   }
 436 }
 437 void ReceiverTypeData::print_data_on(outputStream* st, const char* extra) const {
 438   print_shared(st, "ReceiverTypeData", extra);
 439   print_receiver_data_on(st);
 440 }


























 441 void VirtualCallData::print_data_on(outputStream* st, const char* extra) const {
 442   print_shared(st, "VirtualCallData", extra);
 443   print_receiver_data_on(st);

 444 }
 445 
 446 // ==================================================================
 447 // RetData
 448 //
 449 // A RetData is used to access profiling information for a ret bytecode.
 450 // It is composed of a count of the number of times that the ret has
 451 // been executed, followed by a series of triples of the form
 452 // (bci, count, di) which count the number of times that some bci was the
 453 // target of the ret and cache a corresponding displacement.
 454 
 455 void RetData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 456   for (uint row = 0; row < row_limit(); row++) {
 457     set_bci_displacement(row, -1);
 458     set_bci(row, no_bci);
 459   }
 460   // release so other threads see a consistent state.  bci is used as
 461   // a valid flag for bci_displacement.
 462   OrderAccess::release();
 463 }


 648   print_shared(st, "SpeculativeTrapData", extra);
 649   tab(st);
 650   method()->print_short_name(st);
 651   st->cr();
 652 }
 653 
 654 // ==================================================================
 655 // MethodData*
 656 //
 657 // A MethodData* holds information which has been collected about
 658 // a method.
 659 
 660 MethodData* MethodData::allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS) {
 661   int size = MethodData::compute_allocation_size_in_words(method);
 662 
 663   return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD)
 664     MethodData(method(), size, THREAD);
 665 }
 666 
 667 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
 668 #if defined(COMPILER1) && !defined(COMPILER2)
 669   return no_profile_data;
 670 #else
 671   switch (code) {
 672   case Bytecodes::_checkcast:
 673   case Bytecodes::_instanceof:
 674   case Bytecodes::_aastore:
 675     if (TypeProfileCasts) {
 676       return ReceiverTypeData::static_cell_count();
 677     } else {
 678       return BitData::static_cell_count();
 679     }
 680   case Bytecodes::_invokespecial:
 681   case Bytecodes::_invokestatic:
 682     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 683       return variable_cell_count;
 684     } else {
 685       return CounterData::static_cell_count();
 686     }
 687   case Bytecodes::_goto:
 688   case Bytecodes::_goto_w:


 780   case Bytecodes::_checkcast:
 781   case Bytecodes::_instanceof:
 782   case Bytecodes::_aastore:
 783   case Bytecodes::_invokevirtual:
 784   case Bytecodes::_invokeinterface:
 785   case Bytecodes::_if_acmpeq:
 786   case Bytecodes::_if_acmpne:
 787   case Bytecodes::_ifnull:
 788   case Bytecodes::_ifnonnull:
 789   case Bytecodes::_invokestatic:
 790 #ifdef COMPILER2
 791     return UseTypeSpeculation;
 792 #endif
 793   default:
 794     return false;
 795   }
 796   return false;
 797 }
 798 
 799 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) {




















 800   if (ProfileTraps) {
 801     // Assume that up to 3% of BCIs with no MDP will need to allocate one.
 802     int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;
 803     // If the method is large, let the extra BCIs grow numerous (to ~1%).
 804     int one_percent_of_data
 805       = (uint)data_size / (DataLayout::header_size_in_bytes()*128);
 806     if (extra_data_count < one_percent_of_data)
 807       extra_data_count = one_percent_of_data;
 808     if (extra_data_count > empty_bc_count)
 809       extra_data_count = empty_bc_count;  // no need for more
 810 
 811     // Make sure we have a minimum number of extra data slots to
 812     // allocate SpeculativeTrapData entries. We would want to have one
 813     // entry per compilation that inlines this method and for which
 814     // some type speculation assumption fails. So the room we need for
 815     // the SpeculativeTrapData entries doesn't directly depend on the
 816     // size of the method. Because it's hard to estimate, we reserve
 817     // space for an arbitrary number of entries.
 818     int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) *
 819       (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells());
 820 
 821     return MAX2(extra_data_count, spec_data_count);
 822   } else {
 823     return 0;
 824   }

 825 }
 826 
 827 // Compute the size of the MethodData* necessary to store
 828 // profiling information about a given method.  Size is in bytes.
 829 int MethodData::compute_allocation_size_in_bytes(methodHandle method) {
 830   int data_size = 0;
 831   BytecodeStream stream(method);
 832   Bytecodes::Code c;
 833   int empty_bc_count = 0;  // number of bytecodes lacking data
 834   bool needs_speculative_traps = false;
 835   while ((c = stream.next()) >= 0) {
 836     int size_in_bytes = compute_data_size(&stream);
 837     data_size += size_in_bytes;
 838     if (size_in_bytes == 0)  empty_bc_count += 1;
 839     needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
 840   }
 841   int object_size = in_bytes(data_offset()) + data_size;
 842 
 843   // Add some extra DataLayout cells (at least one) to track stray traps.
 844   int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps);
 845   object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);
 846 
 847   // Add a cell to record information about modified arguments.
 848   int arg_size = method->size_of_parameters();
 849   object_size += DataLayout::compute_size_in_bytes(arg_size+1);
 850 
 851   // Reserve room for an area of the MDO dedicated to profiling of
 852   // parameters
 853   int args_cell = ParametersTypeData::compute_cell_count(method());
 854   if (args_cell > 0) {
 855     object_size += DataLayout::compute_size_in_bytes(args_cell);
 856   }
 857   return object_size;
 858 }
 859 
 860 // Compute the size of the MethodData* necessary to store
 861 // profiling information about a given method.  Size is in words
 862 int MethodData::compute_allocation_size_in_words(methodHandle method) {
 863   int byte_size = compute_allocation_size_in_bytes(method);
 864   int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord;
 865   return align_object_size(word_size);
 866 }
 867 
 868 // Initialize an individual data segment.  Returns the size of
 869 // the segment in bytes.
 870 int MethodData::initialize_data(BytecodeStream* stream,
 871                                        int data_index) {
 872 #if defined(COMPILER1) && !defined(COMPILER2)
 873   return 0;
 874 #else
 875   int cell_count = -1;
 876   int tag = DataLayout::no_tag;
 877   DataLayout* data_layout = data_layout_at(data_index);
 878   Bytecodes::Code c = stream->code();
 879   switch (c) {
 880   case Bytecodes::_checkcast:
 881   case Bytecodes::_instanceof:
 882   case Bytecodes::_aastore:
 883     if (TypeProfileCasts) {
 884       cell_count = ReceiverTypeData::static_cell_count();
 885       tag = DataLayout::receiver_type_data_tag;
 886     } else {
 887       cell_count = BitData::static_cell_count();
 888       tag = DataLayout::bit_data_tag;
 889     }
 890     break;
 891   case Bytecodes::_invokespecial:
 892   case Bytecodes::_invokestatic: {


1043 
1044 // Give each of the data entries a chance to perform specific
1045 // data initialization.
1046 void MethodData::post_initialize(BytecodeStream* stream) {
1047   ResourceMark rm;
1048   ProfileData* data;
1049   for (data = first_data(); is_valid(data); data = next_data(data)) {
1050     stream->set_start(data->bci());
1051     stream->next();
1052     data->post_initialize(stream, this);
1053   }
1054   if (_parameters_type_data_di != no_parameters) {
1055     parameters_type_data()->post_initialize(NULL, this);
1056   }
1057 }
1058 
1059 // Initialize the MethodData* corresponding to a given method.
1060 MethodData::MethodData(methodHandle method, int size, TRAPS)
1061   : _extra_data_lock(Monitor::leaf, "MDO extra data lock"),
1062     _parameters_type_data_di(parameters_uninitialized) {
1063   No_Safepoint_Verifier no_safepoint;  // init function atomic wrt GC
1064   ResourceMark rm;
1065   // Set the method back-pointer.
1066   _method = method();






1067 
1068   init();
1069   set_creation_mileage(mileage_of(method()));
1070 
1071   // Go through the bytecodes and allocate and initialize the
1072   // corresponding data cells.
1073   int data_size = 0;
1074   int empty_bc_count = 0;  // number of bytecodes lacking data
1075   _data[0] = 0;  // apparently not set below.
1076   BytecodeStream stream(method);
1077   Bytecodes::Code c;
1078   bool needs_speculative_traps = false;
1079   while ((c = stream.next()) >= 0) {
1080     int size_in_bytes = initialize_data(&stream, data_size);
1081     data_size += size_in_bytes;
1082     if (size_in_bytes == 0)  empty_bc_count += 1;
1083     needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
1084   }
1085   _data_size = data_size;
1086   int object_size = in_bytes(data_offset()) + data_size;
1087 
1088   // Add some extra DataLayout cells (at least one) to track stray traps.
1089   int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps);
1090   int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0);
1091 
1092   // Let's zero the space for the extra data
1093   Copy::zero_to_bytes(((address)_data) + data_size, extra_size);
1094 
1095   // Add a cell to record information about modified arguments.
1096   // Set up _args_modified array after traps cells so that
1097   // the code for traps cells works.
1098   DataLayout *dp = data_layout_at(data_size + extra_size);
1099 
1100   int arg_size = method->size_of_parameters();
1101   dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
1102 
1103   int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1);
1104   object_size += extra_size + arg_data_size;
1105 
1106   int parms_cell = ParametersTypeData::compute_cell_count(method());
1107   // If we are profiling parameters, we reserver an area near the end
1108   // of the MDO after the slots for bytecodes (because there's no bci
1109   // for method entry so they don't fit with the framework for the
1110   // profiling of bytecodes). We store the offset within the MDO of
1111   // this area (or -1 if no parameter is profiled)
1112   if (parms_cell > 0) {
1113     object_size += DataLayout::compute_size_in_bytes(parms_cell);
1114     _parameters_type_data_di = data_size + extra_size + arg_data_size;
1115     DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size);
1116     dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell);
1117   } else {
1118     _parameters_type_data_di = no_parameters;
1119   }
1120 
1121   // Set an initial hint. Don't use set_hint_di() because
1122   // first_di() may be out of bounds if data_size is 0.
1123   // In that situation, _hint_di is never used, but at
1124   // least well-defined.
1125   _hint_di = first_di();
1126 
1127   post_initialize(&stream);
1128 

1129   set_size(object_size);
1130 }
1131 
1132 void MethodData::init() {
1133   _invocation_counter.init();
1134   _backedge_counter.init();
1135   _invocation_counter_start = 0;
1136   _backedge_counter_start = 0;
1137 
1138   // Set per-method invoke- and backedge mask.
1139   double scale = 1.0;
1140   CompilerOracle::has_option_value(_method, "CompileThresholdScaling", scale);
1141   _invoke_mask = right_n_bits(Arguments::scaled_freq_log(Tier0InvokeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
1142   _backedge_mask = right_n_bits(Arguments::scaled_freq_log(Tier0BackedgeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
1143 
1144   _tenure_traps = 0;
1145   _num_loops = 0;
1146   _num_blocks = 0;
1147   _would_profile = unknown;
1148 




1149 #if INCLUDE_RTM_OPT
1150   _rtm_state = NoRTM; // No RTM lock eliding by default
1151   if (UseRTMLocking &&
1152       !CompilerOracle::has_option_string(_method, "NoRTMLockEliding")) {
1153     if (CompilerOracle::has_option_string(_method, "UseRTMLockEliding") || !UseRTMDeopt) {
1154       // Generate RTM lock eliding code without abort ratio calculation code.
1155       _rtm_state = UseRTM;
1156     } else if (UseRTMDeopt) {
1157       // Generate RTM lock eliding code and include abort ratio calculation
1158       // code if UseRTMDeopt is on.
1159       _rtm_state = ProfileRTM;
1160     }
1161   }
1162 #endif
1163 
1164   // Initialize flags and trap history.
1165   _nof_decompiles = 0;
1166   _nof_overflow_recompiles = 0;
1167   _nof_overflow_traps = 0;
1168   clear_escape_info();




 396   }
 397 }
 398 
 399 // ==================================================================
 400 // ReceiverTypeData
 401 //
 402 // A ReceiverTypeData is used to access profiling information about a
 403 // dynamic type check.  It consists of a counter which counts the total times
 404 // that the check is reached, and a series of (Klass*, count) pairs
 405 // which are used to store a type profile for the receiver of the check.
 406 
 407 void ReceiverTypeData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
 408     for (uint row = 0; row < row_limit(); row++) {
 409     Klass* p = receiver(row);
 410     if (p != NULL && !p->is_loader_alive(is_alive_cl)) {
 411       clear_row(row);
 412     }
 413   }
 414 }
 415 
 416 #if INCLUDE_JVMCI
 417 void VirtualCallData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
 418   ReceiverTypeData::clean_weak_klass_links(is_alive_cl);
 419   for (uint row = 0; row < method_row_limit(); row++) {
 420     Method* p = method(row);
 421     if (p != NULL && !p->method_holder()->is_loader_alive(is_alive_cl)) {
 422       clear_method_row(row);
 423     }
 424   }
 425 }
 426 
 427 void VirtualCallData::clean_weak_method_links() {
 428   ReceiverTypeData::clean_weak_method_links();
 429   for (uint row = 0; row < method_row_limit(); row++) {
 430     Method* p = method(row);
 431     if (p != NULL && !p->on_stack()) {
 432       clear_method_row(row);
 433     }
 434   }
 435 }
 436 #endif // INCLUDE_JVMCI
 437 
 438 void ReceiverTypeData::print_receiver_data_on(outputStream* st) const {
 439   uint row;
 440   int entries = 0;
 441   for (row = 0; row < row_limit(); row++) {
 442     if (receiver(row) != NULL)  entries++;
 443   }
 444 #if INCLUDE_JVMCI
 445   st->print_cr("count(%u) nonprofiled_count(%u) entries(%u)", count(), nonprofiled_count(), entries);
 446 #else
 447   st->print_cr("count(%u) entries(%u)", count(), entries);
 448 #endif
 449   int total = count();
 450   for (row = 0; row < row_limit(); row++) {
 451     if (receiver(row) != NULL) {
 452       total += receiver_count(row);
 453     }
 454   }
 455   for (row = 0; row < row_limit(); row++) {
 456     if (receiver(row) != NULL) {
 457       tab(st);
 458       receiver(row)->print_value_on(st);
 459       st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total);
 460     }
 461   }
 462 }
 463 void ReceiverTypeData::print_data_on(outputStream* st, const char* extra) const {
 464   print_shared(st, "ReceiverTypeData", extra);
 465   print_receiver_data_on(st);
 466 }
 467 
 468 #if INCLUDE_JVMCI
 469 void VirtualCallData::print_method_data_on(outputStream* st) const {
 470   uint row;
 471   int entries = 0;
 472   for (row = 0; row < method_row_limit(); row++) {
 473     if (method(row) != NULL) entries++;
 474   }
 475   tab(st);
 476   st->print_cr("method_entries(%u)", entries);
 477   int total = count();
 478   for (row = 0; row < method_row_limit(); row++) {
 479     if (method(row) != NULL) {
 480       total += method_count(row);
 481     }
 482   }
 483   for (row = 0; row < method_row_limit(); row++) {
 484     if (method(row) != NULL) {
 485       tab(st);
 486       method(row)->print_value_on(st);
 487       st->print_cr("(%u %4.2f)", method_count(row), (float) method_count(row) / (float) total);
 488     }
 489   }
 490 }
 491 #endif // INCLUDE_JVMCI
 492 
 493 void VirtualCallData::print_data_on(outputStream* st, const char* extra) const {
 494   print_shared(st, "VirtualCallData", extra);
 495   print_receiver_data_on(st);
 496   print_method_data_on(st);
 497 }
 498 
 499 // ==================================================================
 500 // RetData
 501 //
 502 // A RetData is used to access profiling information for a ret bytecode.
 503 // It is composed of a count of the number of times that the ret has
 504 // been executed, followed by a series of triples of the form
 505 // (bci, count, di) which count the number of times that some bci was the
 506 // target of the ret and cache a corresponding displacement.
 507 
 508 void RetData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 509   for (uint row = 0; row < row_limit(); row++) {
 510     set_bci_displacement(row, -1);
 511     set_bci(row, no_bci);
 512   }
 513   // release so other threads see a consistent state.  bci is used as
 514   // a valid flag for bci_displacement.
 515   OrderAccess::release();
 516 }


 701   print_shared(st, "SpeculativeTrapData", extra);
 702   tab(st);
 703   method()->print_short_name(st);
 704   st->cr();
 705 }
 706 
 707 // ==================================================================
 708 // MethodData*
 709 //
 710 // A MethodData* holds information which has been collected about
 711 // a method.
 712 
 713 MethodData* MethodData::allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS) {
 714   int size = MethodData::compute_allocation_size_in_words(method);
 715 
 716   return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD)
 717     MethodData(method(), size, THREAD);
 718 }
 719 
 720 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
 721 #if defined(COMPILER1) && !(defined(COMPILER2) || INCLUDE_JVMCI)
 722   return no_profile_data;
 723 #else
 724   switch (code) {
 725   case Bytecodes::_checkcast:
 726   case Bytecodes::_instanceof:
 727   case Bytecodes::_aastore:
 728     if (TypeProfileCasts) {
 729       return ReceiverTypeData::static_cell_count();
 730     } else {
 731       return BitData::static_cell_count();
 732     }
 733   case Bytecodes::_invokespecial:
 734   case Bytecodes::_invokestatic:
 735     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 736       return variable_cell_count;
 737     } else {
 738       return CounterData::static_cell_count();
 739     }
 740   case Bytecodes::_goto:
 741   case Bytecodes::_goto_w:


 833   case Bytecodes::_checkcast:
 834   case Bytecodes::_instanceof:
 835   case Bytecodes::_aastore:
 836   case Bytecodes::_invokevirtual:
 837   case Bytecodes::_invokeinterface:
 838   case Bytecodes::_if_acmpeq:
 839   case Bytecodes::_if_acmpne:
 840   case Bytecodes::_ifnull:
 841   case Bytecodes::_ifnonnull:
 842   case Bytecodes::_invokestatic:
 843 #ifdef COMPILER2
 844     return UseTypeSpeculation;
 845 #endif
 846   default:
 847     return false;
 848   }
 849   return false;
 850 }
 851 
 852 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) {
 853 #if INCLUDE_JVMCI
 854   if (ProfileTraps) {
 855     // Assume that up to 30% of the possibly trapping BCIs with no MDP will need to allocate one.
 856     int extra_data_count = MIN2(empty_bc_count, MAX2(4, (empty_bc_count * 30) / 100));
 857 
 858     // Make sure we have a minimum number of extra data slots to
 859     // allocate SpeculativeTrapData entries. We would want to have one
 860     // entry per compilation that inlines this method and for which
 861     // some type speculation assumption fails. So the room we need for
 862     // the SpeculativeTrapData entries doesn't directly depend on the
 863     // size of the method. Because it's hard to estimate, we reserve
 864     // space for an arbitrary number of entries.
 865     int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) *
 866       (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells());
 867 
 868     return MAX2(extra_data_count, spec_data_count);
 869   } else {
 870     return 0;
 871   }
 872 #else // INCLUDE_JVMCI
 873   if (ProfileTraps) {
 874     // Assume that up to 3% of BCIs with no MDP will need to allocate one.
 875     int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;
 876     // If the method is large, let the extra BCIs grow numerous (to ~1%).
 877     int one_percent_of_data
 878       = (uint)data_size / (DataLayout::header_size_in_bytes()*128);
 879     if (extra_data_count < one_percent_of_data)
 880       extra_data_count = one_percent_of_data;
 881     if (extra_data_count > empty_bc_count)
 882       extra_data_count = empty_bc_count;  // no need for more
 883 
 884     // Make sure we have a minimum number of extra data slots to
 885     // allocate SpeculativeTrapData entries. We would want to have one
 886     // entry per compilation that inlines this method and for which
 887     // some type speculation assumption fails. So the room we need for
 888     // the SpeculativeTrapData entries doesn't directly depend on the
 889     // size of the method. Because it's hard to estimate, we reserve
 890     // space for an arbitrary number of entries.
 891     int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) *
 892       (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells());
 893 
 894     return MAX2(extra_data_count, spec_data_count);
 895   } else {
 896     return 0;
 897   }
 898 #endif // INCLUDE_JVMCI
 899 }
 900 
 901 // Compute the size of the MethodData* necessary to store
 902 // profiling information about a given method.  Size is in bytes.
 903 int MethodData::compute_allocation_size_in_bytes(methodHandle method) {
 904   int data_size = 0;
 905   BytecodeStream stream(method);
 906   Bytecodes::Code c;
 907   int empty_bc_count = 0;  // number of bytecodes lacking data
 908   bool needs_speculative_traps = false;
 909   while ((c = stream.next()) >= 0) {
 910     int size_in_bytes = compute_data_size(&stream);
 911     data_size += size_in_bytes;
 912     if (size_in_bytes == 0 JVMCI_ONLY(&& Bytecodes::can_trap(c)))  empty_bc_count += 1;
 913     needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
 914   }
 915   int object_size = in_bytes(data_offset()) + data_size;
 916 
 917   // Add some extra DataLayout cells (at least one) to track stray traps.
 918   int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps);
 919   object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);
 920 
 921   // Add a cell to record information about modified arguments.
 922   int arg_size = method->size_of_parameters();
 923   object_size += DataLayout::compute_size_in_bytes(arg_size+1);
 924 
 925   // Reserve room for an area of the MDO dedicated to profiling of
 926   // parameters
 927   int args_cell = ParametersTypeData::compute_cell_count(method());
 928   if (args_cell > 0) {
 929     object_size += DataLayout::compute_size_in_bytes(args_cell);
 930   }
 931   return object_size;
 932 }
 933 
 934 // Compute the size of the MethodData* necessary to store
 935 // profiling information about a given method.  Size is in words
 936 int MethodData::compute_allocation_size_in_words(methodHandle method) {
 937   int byte_size = compute_allocation_size_in_bytes(method);
 938   int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord;
 939   return align_object_size(word_size);
 940 }
 941 
 942 // Initialize an individual data segment.  Returns the size of
 943 // the segment in bytes.
 944 int MethodData::initialize_data(BytecodeStream* stream,
 945                                        int data_index) {
 946 #if defined(COMPILER1) && !(defined(COMPILER2) || INCLUDE_JVMCI)
 947   return 0;
 948 #else
 949   int cell_count = -1;
 950   int tag = DataLayout::no_tag;
 951   DataLayout* data_layout = data_layout_at(data_index);
 952   Bytecodes::Code c = stream->code();
 953   switch (c) {
 954   case Bytecodes::_checkcast:
 955   case Bytecodes::_instanceof:
 956   case Bytecodes::_aastore:
 957     if (TypeProfileCasts) {
 958       cell_count = ReceiverTypeData::static_cell_count();
 959       tag = DataLayout::receiver_type_data_tag;
 960     } else {
 961       cell_count = BitData::static_cell_count();
 962       tag = DataLayout::bit_data_tag;
 963     }
 964     break;
 965   case Bytecodes::_invokespecial:
 966   case Bytecodes::_invokestatic: {


1117 
1118 // Give each of the data entries a chance to perform specific
1119 // data initialization.
1120 void MethodData::post_initialize(BytecodeStream* stream) {
1121   ResourceMark rm;
1122   ProfileData* data;
1123   for (data = first_data(); is_valid(data); data = next_data(data)) {
1124     stream->set_start(data->bci());
1125     stream->next();
1126     data->post_initialize(stream, this);
1127   }
1128   if (_parameters_type_data_di != no_parameters) {
1129     parameters_type_data()->post_initialize(NULL, this);
1130   }
1131 }
1132 
1133 // Initialize the MethodData* corresponding to a given method.
1134 MethodData::MethodData(methodHandle method, int size, TRAPS)
1135   : _extra_data_lock(Monitor::leaf, "MDO extra data lock"),
1136     _parameters_type_data_di(parameters_uninitialized) {


1137   // Set the method back-pointer.
1138   _method = method();
1139   initialize();
1140 }
1141 
1142 void MethodData::initialize() {
1143   No_Safepoint_Verifier no_safepoint;  // init function atomic wrt GC
1144   ResourceMark rm;
1145 
1146   init();
1147   set_creation_mileage(mileage_of(method()));
1148 
1149   // Go through the bytecodes and allocate and initialize the
1150   // corresponding data cells.
1151   int data_size = 0;
1152   int empty_bc_count = 0;  // number of bytecodes lacking data
1153   _data[0] = 0;  // apparently not set below.
1154   BytecodeStream stream(method());
1155   Bytecodes::Code c;
1156   bool needs_speculative_traps = false;
1157   while ((c = stream.next()) >= 0) {
1158     int size_in_bytes = initialize_data(&stream, data_size);
1159     data_size += size_in_bytes;
1160     if (size_in_bytes == 0 JVMCI_ONLY(&& Bytecodes::can_trap(c)))  empty_bc_count += 1;
1161     needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
1162   }
1163   _data_size = data_size;
1164   int object_size = in_bytes(data_offset()) + data_size;
1165 
1166   // Add some extra DataLayout cells (at least one) to track stray traps.
1167   int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps);
1168   int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0);
1169 
1170   // Let's zero the space for the extra data
1171   Copy::zero_to_bytes(((address)_data) + data_size, extra_size);
1172 
1173   // Add a cell to record information about modified arguments.
1174   // Set up _args_modified array after traps cells so that
1175   // the code for traps cells works.
1176   DataLayout *dp = data_layout_at(data_size + extra_size);
1177 
1178   int arg_size = method()->size_of_parameters();
1179   dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
1180 
1181   int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1);
1182   object_size += extra_size + arg_data_size;
1183 
1184   int parms_cell = ParametersTypeData::compute_cell_count(method());
1185   // If we are profiling parameters, we reserver an area near the end
1186   // of the MDO after the slots for bytecodes (because there's no bci
1187   // for method entry so they don't fit with the framework for the
1188   // profiling of bytecodes). We store the offset within the MDO of
1189   // this area (or -1 if no parameter is profiled)
1190   if (parms_cell > 0) {
1191     object_size += DataLayout::compute_size_in_bytes(parms_cell);
1192     _parameters_type_data_di = data_size + extra_size + arg_data_size;
1193     DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size);
1194     dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell);
1195   } else {
1196     _parameters_type_data_di = no_parameters;
1197   }
1198 
1199   // Set an initial hint. Don't use set_hint_di() because
1200   // first_di() may be out of bounds if data_size is 0.
1201   // In that situation, _hint_di is never used, but at
1202   // least well-defined.
1203   _hint_di = first_di();
1204 
1205   post_initialize(&stream);
1206 
1207   assert(object_size == compute_allocation_size_in_bytes(methodHandle(_method)), "MethodData: computed size != initialized size");
1208   set_size(object_size);
1209 }
1210 
1211 void MethodData::init() {
1212   _invocation_counter.init();
1213   _backedge_counter.init();
1214   _invocation_counter_start = 0;
1215   _backedge_counter_start = 0;
1216 
1217   // Set per-method invoke- and backedge mask.
1218   double scale = 1.0;
1219   CompilerOracle::has_option_value(_method, "CompileThresholdScaling", scale);
1220   _invoke_mask = right_n_bits(Arguments::scaled_freq_log(Tier0InvokeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
1221   _backedge_mask = right_n_bits(Arguments::scaled_freq_log(Tier0BackedgeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
1222 
1223   _tenure_traps = 0;
1224   _num_loops = 0;
1225   _num_blocks = 0;
1226   _would_profile = unknown;
1227 
1228 #if INCLUDE_JVMCI
1229   _jvmci_ir_size = 0;
1230 #endif
1231 
1232 #if INCLUDE_RTM_OPT
1233   _rtm_state = NoRTM; // No RTM lock eliding by default
1234   if (UseRTMLocking &&
1235       !CompilerOracle::has_option_string(_method, "NoRTMLockEliding")) {
1236     if (CompilerOracle::has_option_string(_method, "UseRTMLockEliding") || !UseRTMDeopt) {
1237       // Generate RTM lock eliding code without abort ratio calculation code.
1238       _rtm_state = UseRTM;
1239     } else if (UseRTMDeopt) {
1240       // Generate RTM lock eliding code and include abort ratio calculation
1241       // code if UseRTMDeopt is on.
1242       _rtm_state = ProfileRTM;
1243     }
1244   }
1245 #endif
1246 
1247   // Initialize flags and trap history.
1248   _nof_decompiles = 0;
1249   _nof_overflow_recompiles = 0;
1250   _nof_overflow_traps = 0;
1251   clear_escape_info();


< prev index next >