409 clear_row(row); |
409 clear_row(row); |
410 } |
410 } |
411 } |
411 } |
412 } |
412 } |
413 |
413 |
|
414 #if INCLUDE_JVMCI |
|
415 void VirtualCallData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) { |
|
416 ReceiverTypeData::clean_weak_klass_links(is_alive_cl); |
|
417 for (uint row = 0; row < method_row_limit(); row++) { |
|
418 Method* p = method(row); |
|
419 if (p != NULL && !p->method_holder()->is_loader_alive(is_alive_cl)) { |
|
420 clear_method_row(row); |
|
421 } |
|
422 } |
|
423 } |
|
424 |
|
425 void VirtualCallData::clean_weak_method_links() { |
|
426 ReceiverTypeData::clean_weak_method_links(); |
|
427 for (uint row = 0; row < method_row_limit(); row++) { |
|
428 Method* p = method(row); |
|
429 if (p != NULL && !p->on_stack()) { |
|
430 clear_method_row(row); |
|
431 } |
|
432 } |
|
433 } |
|
434 #endif // INCLUDE_JVMCI |
|
435 |
414 void ReceiverTypeData::print_receiver_data_on(outputStream* st) const { |
436 void ReceiverTypeData::print_receiver_data_on(outputStream* st) const { |
415 uint row; |
437 uint row; |
416 int entries = 0; |
438 int entries = 0; |
417 for (row = 0; row < row_limit(); row++) { |
439 for (row = 0; row < row_limit(); row++) { |
418 if (receiver(row) != NULL) entries++; |
440 if (receiver(row) != NULL) entries++; |
419 } |
441 } |
|
442 #if INCLUDE_JVMCI |
|
443 st->print_cr("count(%u) nonprofiled_count(%u) entries(%u)", count(), nonprofiled_count(), entries); |
|
444 #else |
420 st->print_cr("count(%u) entries(%u)", count(), entries); |
445 st->print_cr("count(%u) entries(%u)", count(), entries); |
|
446 #endif |
421 int total = count(); |
447 int total = count(); |
422 for (row = 0; row < row_limit(); row++) { |
448 for (row = 0; row < row_limit(); row++) { |
423 if (receiver(row) != NULL) { |
449 if (receiver(row) != NULL) { |
424 total += receiver_count(row); |
450 total += receiver_count(row); |
425 } |
451 } |
434 } |
460 } |
435 void ReceiverTypeData::print_data_on(outputStream* st, const char* extra) const { |
461 void ReceiverTypeData::print_data_on(outputStream* st, const char* extra) const { |
436 print_shared(st, "ReceiverTypeData", extra); |
462 print_shared(st, "ReceiverTypeData", extra); |
437 print_receiver_data_on(st); |
463 print_receiver_data_on(st); |
438 } |
464 } |
|
465 |
|
466 #if INCLUDE_JVMCI |
|
467 void VirtualCallData::print_method_data_on(outputStream* st) const { |
|
468 uint row; |
|
469 int entries = 0; |
|
470 for (row = 0; row < method_row_limit(); row++) { |
|
471 if (method(row) != NULL) entries++; |
|
472 } |
|
473 tab(st); |
|
474 st->print_cr("method_entries(%u)", entries); |
|
475 int total = count(); |
|
476 for (row = 0; row < method_row_limit(); row++) { |
|
477 if (method(row) != NULL) { |
|
478 total += method_count(row); |
|
479 } |
|
480 } |
|
481 for (row = 0; row < method_row_limit(); row++) { |
|
482 if (method(row) != NULL) { |
|
483 tab(st); |
|
484 method(row)->print_value_on(st); |
|
485 st->print_cr("(%u %4.2f)", method_count(row), (float) method_count(row) / (float) total); |
|
486 } |
|
487 } |
|
488 } |
|
489 #endif // INCLUDE_JVMCI |
|
490 |
439 void VirtualCallData::print_data_on(outputStream* st, const char* extra) const { |
491 void VirtualCallData::print_data_on(outputStream* st, const char* extra) const { |
440 print_shared(st, "VirtualCallData", extra); |
492 print_shared(st, "VirtualCallData", extra); |
441 print_receiver_data_on(st); |
493 print_receiver_data_on(st); |
|
494 print_method_data_on(st); |
442 } |
495 } |
443 |
496 |
444 // ================================================================== |
497 // ================================================================== |
445 // RetData |
498 // RetData |
446 // |
499 // |
661 return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD) |
714 return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD) |
662 MethodData(method(), size, THREAD); |
715 MethodData(method(), size, THREAD); |
663 } |
716 } |
664 |
717 |
665 int MethodData::bytecode_cell_count(Bytecodes::Code code) { |
718 int MethodData::bytecode_cell_count(Bytecodes::Code code) { |
666 #if defined(COMPILER1) && !defined(COMPILER2) |
719 #if defined(COMPILER1) && !(defined(COMPILER2) || INCLUDE_JVMCI) |
667 return no_profile_data; |
720 return no_profile_data; |
668 #else |
721 #else |
669 switch (code) { |
722 switch (code) { |
670 case Bytecodes::_checkcast: |
723 case Bytecodes::_checkcast: |
671 case Bytecodes::_instanceof: |
724 case Bytecodes::_instanceof: |
793 } |
846 } |
794 return false; |
847 return false; |
795 } |
848 } |
796 |
849 |
797 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) { |
850 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) { |
|
851 #if INCLUDE_JVMCI |
|
852 if (ProfileTraps) { |
|
853 // Assume that up to 30% of the possibly trapping BCIs with no MDP will need to allocate one. |
|
854 int extra_data_count = MIN2(empty_bc_count, MAX2(4, (empty_bc_count * 30) / 100)); |
|
855 |
|
856 // Make sure we have a minimum number of extra data slots to |
|
857 // allocate SpeculativeTrapData entries. We would want to have one |
|
858 // entry per compilation that inlines this method and for which |
|
859 // some type speculation assumption fails. So the room we need for |
|
860 // the SpeculativeTrapData entries doesn't directly depend on the |
|
861 // size of the method. Because it's hard to estimate, we reserve |
|
862 // space for an arbitrary number of entries. |
|
863 int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) * |
|
864 (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells()); |
|
865 |
|
866 return MAX2(extra_data_count, spec_data_count); |
|
867 } else { |
|
868 return 0; |
|
869 } |
|
870 #else // INCLUDE_JVMCI |
798 if (ProfileTraps) { |
871 if (ProfileTraps) { |
799 // Assume that up to 3% of BCIs with no MDP will need to allocate one. |
872 // Assume that up to 3% of BCIs with no MDP will need to allocate one. |
800 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1; |
873 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1; |
801 // If the method is large, let the extra BCIs grow numerous (to ~1%). |
874 // If the method is large, let the extra BCIs grow numerous (to ~1%). |
802 int one_percent_of_data |
875 int one_percent_of_data |
818 |
891 |
819 return MAX2(extra_data_count, spec_data_count); |
892 return MAX2(extra_data_count, spec_data_count); |
820 } else { |
893 } else { |
821 return 0; |
894 return 0; |
822 } |
895 } |
|
896 #endif // INCLUDE_JVMCI |
823 } |
897 } |
824 |
898 |
825 // Compute the size of the MethodData* necessary to store |
899 // Compute the size of the MethodData* necessary to store |
826 // profiling information about a given method. Size is in bytes. |
900 // profiling information about a given method. Size is in bytes. |
827 int MethodData::compute_allocation_size_in_bytes(methodHandle method) { |
901 int MethodData::compute_allocation_size_in_bytes(methodHandle method) { |
831 int empty_bc_count = 0; // number of bytecodes lacking data |
905 int empty_bc_count = 0; // number of bytecodes lacking data |
832 bool needs_speculative_traps = false; |
906 bool needs_speculative_traps = false; |
833 while ((c = stream.next()) >= 0) { |
907 while ((c = stream.next()) >= 0) { |
834 int size_in_bytes = compute_data_size(&stream); |
908 int size_in_bytes = compute_data_size(&stream); |
835 data_size += size_in_bytes; |
909 data_size += size_in_bytes; |
836 if (size_in_bytes == 0) empty_bc_count += 1; |
910 if (size_in_bytes == 0 JVMCI_ONLY(&& Bytecodes::can_trap(c))) empty_bc_count += 1; |
837 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); |
911 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); |
838 } |
912 } |
839 int object_size = in_bytes(data_offset()) + data_size; |
913 int object_size = in_bytes(data_offset()) + data_size; |
840 |
914 |
841 // Add some extra DataLayout cells (at least one) to track stray traps. |
915 // Add some extra DataLayout cells (at least one) to track stray traps. |
865 |
939 |
866 // Initialize an individual data segment. Returns the size of |
940 // Initialize an individual data segment. Returns the size of |
867 // the segment in bytes. |
941 // the segment in bytes. |
868 int MethodData::initialize_data(BytecodeStream* stream, |
942 int MethodData::initialize_data(BytecodeStream* stream, |
869 int data_index) { |
943 int data_index) { |
870 #if defined(COMPILER1) && !defined(COMPILER2) |
944 #if defined(COMPILER1) && !(defined(COMPILER2) || INCLUDE_JVMCI) |
871 return 0; |
945 return 0; |
872 #else |
946 #else |
873 int cell_count = -1; |
947 int cell_count = -1; |
874 int tag = DataLayout::no_tag; |
948 int tag = DataLayout::no_tag; |
875 DataLayout* data_layout = data_layout_at(data_index); |
949 DataLayout* data_layout = data_layout_at(data_index); |
1056 |
1130 |
1057 // Initialize the MethodData* corresponding to a given method. |
1131 // Initialize the MethodData* corresponding to a given method. |
1058 MethodData::MethodData(methodHandle method, int size, TRAPS) |
1132 MethodData::MethodData(methodHandle method, int size, TRAPS) |
1059 : _extra_data_lock(Monitor::leaf, "MDO extra data lock"), |
1133 : _extra_data_lock(Monitor::leaf, "MDO extra data lock"), |
1060 _parameters_type_data_di(parameters_uninitialized) { |
1134 _parameters_type_data_di(parameters_uninitialized) { |
|
1135 // Set the method back-pointer. |
|
1136 _method = method(); |
|
1137 initialize(); |
|
1138 } |
|
1139 |
|
1140 void MethodData::initialize() { |
1061 No_Safepoint_Verifier no_safepoint; // init function atomic wrt GC |
1141 No_Safepoint_Verifier no_safepoint; // init function atomic wrt GC |
1062 ResourceMark rm; |
1142 ResourceMark rm; |
1063 // Set the method back-pointer. |
|
1064 _method = method(); |
|
1065 |
1143 |
1066 init(); |
1144 init(); |
1067 set_creation_mileage(mileage_of(method())); |
1145 set_creation_mileage(mileage_of(method())); |
1068 |
1146 |
1069 // Go through the bytecodes and allocate and initialize the |
1147 // Go through the bytecodes and allocate and initialize the |
1070 // corresponding data cells. |
1148 // corresponding data cells. |
1071 int data_size = 0; |
1149 int data_size = 0; |
1072 int empty_bc_count = 0; // number of bytecodes lacking data |
1150 int empty_bc_count = 0; // number of bytecodes lacking data |
1073 _data[0] = 0; // apparently not set below. |
1151 _data[0] = 0; // apparently not set below. |
1074 BytecodeStream stream(method); |
1152 BytecodeStream stream(method()); |
1075 Bytecodes::Code c; |
1153 Bytecodes::Code c; |
1076 bool needs_speculative_traps = false; |
1154 bool needs_speculative_traps = false; |
1077 while ((c = stream.next()) >= 0) { |
1155 while ((c = stream.next()) >= 0) { |
1078 int size_in_bytes = initialize_data(&stream, data_size); |
1156 int size_in_bytes = initialize_data(&stream, data_size); |
1079 data_size += size_in_bytes; |
1157 data_size += size_in_bytes; |
1080 if (size_in_bytes == 0) empty_bc_count += 1; |
1158 if (size_in_bytes == 0 JVMCI_ONLY(&& Bytecodes::can_trap(c))) empty_bc_count += 1; |
1081 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); |
1159 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); |
1082 } |
1160 } |
1083 _data_size = data_size; |
1161 _data_size = data_size; |
1084 int object_size = in_bytes(data_offset()) + data_size; |
1162 int object_size = in_bytes(data_offset()) + data_size; |
1085 |
1163 |
1093 // Add a cell to record information about modified arguments. |
1171 // Add a cell to record information about modified arguments. |
1094 // Set up _args_modified array after traps cells so that |
1172 // Set up _args_modified array after traps cells so that |
1095 // the code for traps cells works. |
1173 // the code for traps cells works. |
1096 DataLayout *dp = data_layout_at(data_size + extra_size); |
1174 DataLayout *dp = data_layout_at(data_size + extra_size); |
1097 |
1175 |
1098 int arg_size = method->size_of_parameters(); |
1176 int arg_size = method()->size_of_parameters(); |
1099 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); |
1177 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); |
1100 |
1178 |
1101 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1); |
1179 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1); |
1102 object_size += extra_size + arg_data_size; |
1180 object_size += extra_size + arg_data_size; |
1103 |
1181 |
1122 // least well-defined. |
1200 // least well-defined. |
1123 _hint_di = first_di(); |
1201 _hint_di = first_di(); |
1124 |
1202 |
1125 post_initialize(&stream); |
1203 post_initialize(&stream); |
1126 |
1204 |
|
1205 assert(object_size == compute_allocation_size_in_bytes(methodHandle(_method)), "MethodData: computed size != initialized size"); |
1127 set_size(object_size); |
1206 set_size(object_size); |
1128 } |
1207 } |
1129 |
1208 |
1130 void MethodData::init() { |
1209 void MethodData::init() { |
1131 _invocation_counter.init(); |
1210 _invocation_counter.init(); |