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:
779 switch (code) {
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
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 #if INCLUDE_JVMCI
497 print_method_data_on(st);
498 #endif
499 }
500
501 // ==================================================================
502 // RetData
503 //
504 // A RetData is used to access profiling information for a ret bytecode.
505 // It is composed of a count of the number of times that the ret has
506 // been executed, followed by a series of triples of the form
507 // (bci, count, di) which count the number of times that some bci was the
508 // target of the ret and cache a corresponding displacement.
509
510 void RetData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
511 for (uint row = 0; row < row_limit(); row++) {
512 set_bci_displacement(row, -1);
513 set_bci(row, no_bci);
514 }
515 // release so other threads see a consistent state. bci is used as
516 // a valid flag for bci_displacement.
517 OrderAccess::release();
518 }
703 print_shared(st, "SpeculativeTrapData", extra);
704 tab(st);
705 method()->print_short_name(st);
706 st->cr();
707 }
708
709 // ==================================================================
710 // MethodData*
711 //
712 // A MethodData* holds information which has been collected about
713 // a method.
714
715 MethodData* MethodData::allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS) {
716 int size = MethodData::compute_allocation_size_in_words(method);
717
718 return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD)
719 MethodData(method(), size, THREAD);
720 }
721
722 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
723 #if defined(COMPILER1) && !(defined(COMPILER2) || INCLUDE_JVMCI)
724 return no_profile_data;
725 #else
726 switch (code) {
727 case Bytecodes::_checkcast:
728 case Bytecodes::_instanceof:
729 case Bytecodes::_aastore:
730 if (TypeProfileCasts) {
731 return ReceiverTypeData::static_cell_count();
732 } else {
733 return BitData::static_cell_count();
734 }
735 case Bytecodes::_invokespecial:
736 case Bytecodes::_invokestatic:
737 if (MethodData::profile_arguments() || MethodData::profile_return()) {
738 return variable_cell_count;
739 } else {
740 return CounterData::static_cell_count();
741 }
742 case Bytecodes::_goto:
743 case Bytecodes::_goto_w:
834 switch (code) {
835 case Bytecodes::_checkcast:
836 case Bytecodes::_instanceof:
837 case Bytecodes::_aastore:
838 case Bytecodes::_invokevirtual:
839 case Bytecodes::_invokeinterface:
840 case Bytecodes::_if_acmpeq:
841 case Bytecodes::_if_acmpne:
842 case Bytecodes::_ifnull:
843 case Bytecodes::_ifnonnull:
844 case Bytecodes::_invokestatic:
845 #ifdef COMPILER2
846 return UseTypeSpeculation;
847 #endif
848 default:
849 return false;
850 }
851 return false;
852 }
853
854 #if INCLUDE_JVMCI
855 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) {
856 if (!ProfileTraps) return 0;
857
858 // Assume that up to 30% of the possibly trapping BCIs with no MDP will need to allocate one.
859 int extra_data_count = MIN2(empty_bc_count, MAX2(4, (empty_bc_count * 30) / 100));
860
861 // Make sure we have a minimum number of extra data slots to
862 // allocate SpeculativeTrapData entries. We would want to have one
863 // entry per compilation that inlines this method and for which
864 // some type speculation assumption fails. So the room we need for
865 // the SpeculativeTrapData entries doesn't directly depend on the
866 // size of the method. Because it's hard to estimate, we reserve
867 // space for an arbitrary number of entries.
868 int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) *
869 (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells());
870
871 return MAX2(extra_data_count, spec_data_count);
872 }
873 #else
874 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) {
875 if (ProfileTraps) {
876 // Assume that up to 3% of BCIs with no MDP will need to allocate one.
877 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;
878 // If the method is large, let the extra BCIs grow numerous (to ~1%).
879 int one_percent_of_data
880 = (uint)data_size / (DataLayout::header_size_in_bytes()*128);
881 if (extra_data_count < one_percent_of_data)
882 extra_data_count = one_percent_of_data;
883 if (extra_data_count > empty_bc_count)
884 extra_data_count = empty_bc_count; // no need for more
885
886 // Make sure we have a minimum number of extra data slots to
887 // allocate SpeculativeTrapData entries. We would want to have one
888 // entry per compilation that inlines this method and for which
889 // some type speculation assumption fails. So the room we need for
890 // the SpeculativeTrapData entries doesn't directly depend on the
891 // size of the method. Because it's hard to estimate, we reserve
892 // space for an arbitrary number of entries.
893 int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) *
894 (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells());
895
896 return MAX2(extra_data_count, spec_data_count);
897 } else {
898 return 0;
899 }
900 }
901 #endif
902
903 // Compute the size of the MethodData* necessary to store
904 // profiling information about a given method. Size is in bytes.
905 int MethodData::compute_allocation_size_in_bytes(methodHandle method) {
906 int data_size = 0;
907 BytecodeStream stream(method);
908 Bytecodes::Code c;
909 int empty_bc_count = 0; // number of bytecodes lacking data
910 bool needs_speculative_traps = false;
911 while ((c = stream.next()) >= 0) {
912 int size_in_bytes = compute_data_size(&stream);
913 data_size += size_in_bytes;
914 if (size_in_bytes == 0 JVMCI_ONLY(&& Bytecodes::can_trap(c))) empty_bc_count += 1;
915 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
916 }
917 int object_size = in_bytes(data_offset()) + data_size;
918
919 // Add some extra DataLayout cells (at least one) to track stray traps.
920 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps);
921 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);
922
923 // Add a cell to record information about modified arguments.
924 int arg_size = method->size_of_parameters();
925 object_size += DataLayout::compute_size_in_bytes(arg_size+1);
926
927 // Reserve room for an area of the MDO dedicated to profiling of
928 // parameters
929 int args_cell = ParametersTypeData::compute_cell_count(method());
930 if (args_cell > 0) {
931 object_size += DataLayout::compute_size_in_bytes(args_cell);
932 }
933 return object_size;
934 }
935
936 // Compute the size of the MethodData* necessary to store
937 // profiling information about a given method. Size is in words
938 int MethodData::compute_allocation_size_in_words(methodHandle method) {
939 int byte_size = compute_allocation_size_in_bytes(method);
940 int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord;
941 return align_object_size(word_size);
942 }
943
944 // Initialize an individual data segment. Returns the size of
945 // the segment in bytes.
946 int MethodData::initialize_data(BytecodeStream* stream,
947 int data_index) {
948 #if defined(COMPILER1) && !(defined(COMPILER2) || INCLUDE_JVMCI)
949 return 0;
950 #else
951 int cell_count = -1;
952 int tag = DataLayout::no_tag;
953 DataLayout* data_layout = data_layout_at(data_index);
954 Bytecodes::Code c = stream->code();
955 switch (c) {
956 case Bytecodes::_checkcast:
957 case Bytecodes::_instanceof:
958 case Bytecodes::_aastore:
959 if (TypeProfileCasts) {
960 cell_count = ReceiverTypeData::static_cell_count();
961 tag = DataLayout::receiver_type_data_tag;
962 } else {
963 cell_count = BitData::static_cell_count();
964 tag = DataLayout::bit_data_tag;
965 }
966 break;
967 case Bytecodes::_invokespecial:
968 case Bytecodes::_invokestatic: {
1119
1120 // Give each of the data entries a chance to perform specific
1121 // data initialization.
1122 void MethodData::post_initialize(BytecodeStream* stream) {
1123 ResourceMark rm;
1124 ProfileData* data;
1125 for (data = first_data(); is_valid(data); data = next_data(data)) {
1126 stream->set_start(data->bci());
1127 stream->next();
1128 data->post_initialize(stream, this);
1129 }
1130 if (_parameters_type_data_di != no_parameters) {
1131 parameters_type_data()->post_initialize(NULL, this);
1132 }
1133 }
1134
1135 // Initialize the MethodData* corresponding to a given method.
1136 MethodData::MethodData(methodHandle method, int size, TRAPS)
1137 : _extra_data_lock(Monitor::leaf, "MDO extra data lock"),
1138 _parameters_type_data_di(parameters_uninitialized) {
1139 // Set the method back-pointer.
1140 _method = method();
1141 initialize();
1142 }
1143
1144 void MethodData::initialize() {
1145 No_Safepoint_Verifier no_safepoint; // init function atomic wrt GC
1146 ResourceMark rm;
1147
1148 init();
1149 set_creation_mileage(mileage_of(method()));
1150
1151 // Go through the bytecodes and allocate and initialize the
1152 // corresponding data cells.
1153 int data_size = 0;
1154 int empty_bc_count = 0; // number of bytecodes lacking data
1155 _data[0] = 0; // apparently not set below.
1156 BytecodeStream stream(method());
1157 Bytecodes::Code c;
1158 bool needs_speculative_traps = false;
1159 while ((c = stream.next()) >= 0) {
1160 int size_in_bytes = initialize_data(&stream, data_size);
1161 data_size += size_in_bytes;
1162 if (size_in_bytes == 0 JVMCI_ONLY(&& Bytecodes::can_trap(c))) empty_bc_count += 1;
1163 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
1164 }
1165 _data_size = data_size;
1166 int object_size = in_bytes(data_offset()) + data_size;
1167
1168 // Add some extra DataLayout cells (at least one) to track stray traps.
1169 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps);
1170 int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0);
1171
1172 // Let's zero the space for the extra data
1173 Copy::zero_to_bytes(((address)_data) + data_size, extra_size);
1174
1175 // Add a cell to record information about modified arguments.
1176 // Set up _args_modified array after traps cells so that
1177 // the code for traps cells works.
1178 DataLayout *dp = data_layout_at(data_size + extra_size);
1179
1180 int arg_size = method()->size_of_parameters();
1181 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
1182
1183 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1);
1184 object_size += extra_size + arg_data_size;
1185
1186 int parms_cell = ParametersTypeData::compute_cell_count(method());
1187 // If we are profiling parameters, we reserver an area near the end
1188 // of the MDO after the slots for bytecodes (because there's no bci
1189 // for method entry so they don't fit with the framework for the
1190 // profiling of bytecodes). We store the offset within the MDO of
1191 // this area (or -1 if no parameter is profiled)
1192 if (parms_cell > 0) {
1193 object_size += DataLayout::compute_size_in_bytes(parms_cell);
1194 _parameters_type_data_di = data_size + extra_size + arg_data_size;
1195 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size);
1196 dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell);
1197 } else {
1198 _parameters_type_data_di = no_parameters;
1199 }
1200
1201 // Set an initial hint. Don't use set_hint_di() because
1202 // first_di() may be out of bounds if data_size is 0.
1203 // In that situation, _hint_di is never used, but at
1204 // least well-defined.
1205 _hint_di = first_di();
1206
1207 post_initialize(&stream);
1208
1209 assert(object_size == compute_allocation_size_in_bytes(methodHandle(_method)), "MethodData: computed size != initialized size");
1210 set_size(object_size);
1211 }
1212
1213 void MethodData::init() {
1214 _invocation_counter.init();
1215 _backedge_counter.init();
1216 _invocation_counter_start = 0;
1217 _backedge_counter_start = 0;
1218
1219 // Set per-method invoke- and backedge mask.
1220 double scale = 1.0;
1221 CompilerOracle::has_option_value(_method, "CompileThresholdScaling", scale);
1222 _invoke_mask = right_n_bits(Arguments::scaled_freq_log(Tier0InvokeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
1223 _backedge_mask = right_n_bits(Arguments::scaled_freq_log(Tier0BackedgeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
1224
1225 _tenure_traps = 0;
1226 _num_loops = 0;
1227 _num_blocks = 0;
1228 _would_profile = unknown;
1229
1230 #if INCLUDE_JVMCI
1231 _jvmci_ir_size = 0;
1232 #endif
1233
1234 #if INCLUDE_RTM_OPT
1235 _rtm_state = NoRTM; // No RTM lock eliding by default
1236 if (UseRTMLocking &&
1237 !CompilerOracle::has_option_string(_method, "NoRTMLockEliding")) {
1238 if (CompilerOracle::has_option_string(_method, "UseRTMLockEliding") || !UseRTMDeopt) {
1239 // Generate RTM lock eliding code without abort ratio calculation code.
1240 _rtm_state = UseRTM;
1241 } else if (UseRTMDeopt) {
1242 // Generate RTM lock eliding code and include abort ratio calculation
1243 // code if UseRTMDeopt is on.
1244 _rtm_state = ProfileRTM;
1245 }
1246 }
1247 #endif
1248
1249 // Initialize flags and trap history.
1250 _nof_decompiles = 0;
1251 _nof_overflow_recompiles = 0;
1252 _nof_overflow_traps = 0;
1253 clear_escape_info();
|