Mercurial > hg > truffle
comparison src/share/vm/oops/methodData.cpp @ 18041:52b4284cb496
Merge with jdk8u20-b26
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Wed, 15 Oct 2014 16:02:50 +0200 |
parents | 4ca6dc0799b6 78bbf4d43a14 |
children | 94faadc823ea |
comparison
equal
deleted
inserted
replaced
17606:45d7b2c7029d | 18041:52b4284cb496 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
22 * | 22 * |
23 */ | 23 */ |
24 | 24 |
25 #include "precompiled.hpp" | 25 #include "precompiled.hpp" |
26 #include "classfile/systemDictionary.hpp" | 26 #include "classfile/systemDictionary.hpp" |
27 #include "compiler/compilerOracle.hpp" | |
27 #include "interpreter/bytecode.hpp" | 28 #include "interpreter/bytecode.hpp" |
28 #include "interpreter/bytecodeStream.hpp" | 29 #include "interpreter/bytecodeStream.hpp" |
29 #include "interpreter/linkResolver.hpp" | 30 #include "interpreter/linkResolver.hpp" |
30 #include "memory/heapInspection.hpp" | 31 #include "memory/heapInspection.hpp" |
31 #include "oops/methodData.hpp" | 32 #include "oops/methodData.hpp" |
32 #include "prims/jvmtiRedefineClasses.hpp" | 33 #include "prims/jvmtiRedefineClasses.hpp" |
33 #include "runtime/compilationPolicy.hpp" | 34 #include "runtime/compilationPolicy.hpp" |
34 #include "runtime/deoptimization.hpp" | 35 #include "runtime/deoptimization.hpp" |
35 #include "runtime/handles.inline.hpp" | 36 #include "runtime/handles.inline.hpp" |
36 | 37 |
38 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC | |
39 | |
37 // ================================================================== | 40 // ================================================================== |
38 // DataLayout | 41 // DataLayout |
39 // | 42 // |
40 // Overlay for generic profiling data. | 43 // Overlay for generic profiling data. |
41 | 44 |
78 // Constructor for invalid ProfileData. | 81 // Constructor for invalid ProfileData. |
79 ProfileData::ProfileData() { | 82 ProfileData::ProfileData() { |
80 _data = NULL; | 83 _data = NULL; |
81 } | 84 } |
82 | 85 |
86 char* ProfileData::print_data_on_helper(const MethodData* md) const { | |
87 DataLayout* dp = md->extra_data_base(); | |
88 DataLayout* end = md->extra_data_limit(); | |
89 stringStream ss; | |
90 for (;; dp = MethodData::next_extra(dp)) { | |
91 assert(dp < end, "moved past end of extra data"); | |
92 switch(dp->tag()) { | |
93 case DataLayout::speculative_trap_data_tag: | |
94 if (dp->bci() == bci()) { | |
95 SpeculativeTrapData* data = new SpeculativeTrapData(dp); | |
96 int trap = data->trap_state(); | |
97 char buf[100]; | |
98 ss.print("trap/"); | |
99 data->method()->print_short_name(&ss); | |
100 ss.print("(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap)); | |
101 } | |
102 break; | |
103 case DataLayout::bit_data_tag: | |
104 break; | |
105 case DataLayout::no_tag: | |
106 case DataLayout::arg_info_data_tag: | |
107 return ss.as_string(); | |
108 break; | |
109 default: | |
110 fatal(err_msg("unexpected tag %d", dp->tag())); | |
111 } | |
112 } | |
113 return NULL; | |
114 } | |
115 | |
116 void ProfileData::print_data_on(outputStream* st, const MethodData* md) const { | |
117 print_data_on(st, print_data_on_helper(md)); | |
118 } | |
119 | |
83 #ifndef PRODUCT | 120 #ifndef PRODUCT |
84 void ProfileData::print_shared(outputStream* st, const char* name) const { | 121 void ProfileData::print_shared(outputStream* st, const char* name, const char* extra) const { |
85 st->print("bci: %d", bci()); | 122 st->print("bci: %d", bci()); |
86 st->fill_to(tab_width_one); | 123 st->fill_to(tab_width_one); |
87 st->print("%s", name); | 124 st->print("%s", name); |
88 tab(st); | 125 tab(st); |
89 int trap = trap_state(); | 126 int trap = trap_state(); |
90 if (trap != 0) { | 127 if (trap != 0) { |
91 char buf[100]; | 128 char buf[100]; |
92 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap)); | 129 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap)); |
93 } | 130 } |
131 if (extra != NULL) { | |
132 st->print("%s", extra); | |
133 } | |
94 int flags = data()->flags(); | 134 int flags = data()->flags(); |
95 if (flags != 0) | 135 if (flags != 0) { |
96 st->print("flags(%d) ", flags); | 136 st->print("flags(%d) ", flags); |
137 } | |
97 } | 138 } |
98 | 139 |
99 void ProfileData::tab(outputStream* st, bool first) const { | 140 void ProfileData::tab(outputStream* st, bool first) const { |
100 st->fill_to(first ? tab_width_one : tab_width_two); | 141 st->fill_to(first ? tab_width_one : tab_width_two); |
101 } | 142 } |
107 // A BitData corresponds to a one-bit flag. This is used to indicate | 148 // A BitData corresponds to a one-bit flag. This is used to indicate |
108 // whether a checkcast bytecode has seen a null value. | 149 // whether a checkcast bytecode has seen a null value. |
109 | 150 |
110 | 151 |
111 #ifndef PRODUCT | 152 #ifndef PRODUCT |
112 void BitData::print_data_on(outputStream* st) const { | 153 void BitData::print_data_on(outputStream* st, const char* extra) const { |
113 print_shared(st, "BitData"); | 154 print_shared(st, "BitData", extra); |
114 } | 155 } |
115 #endif // !PRODUCT | 156 #endif // !PRODUCT |
116 | 157 |
117 // ================================================================== | 158 // ================================================================== |
118 // CounterData | 159 // CounterData |
119 // | 160 // |
120 // A CounterData corresponds to a simple counter. | 161 // A CounterData corresponds to a simple counter. |
121 | 162 |
122 #ifndef PRODUCT | 163 #ifndef PRODUCT |
123 void CounterData::print_data_on(outputStream* st) const { | 164 void CounterData::print_data_on(outputStream* st, const char* extra) const { |
124 print_shared(st, "CounterData"); | 165 print_shared(st, "CounterData", extra); |
125 st->print_cr("count(%u)", count()); | 166 st->print_cr("count(%u)", count()); |
126 } | 167 } |
127 #endif // !PRODUCT | 168 #endif // !PRODUCT |
128 | 169 |
129 // ================================================================== | 170 // ================================================================== |
148 int offset = target_di - my_di; | 189 int offset = target_di - my_di; |
149 set_displacement(offset); | 190 set_displacement(offset); |
150 } | 191 } |
151 | 192 |
152 #ifndef PRODUCT | 193 #ifndef PRODUCT |
153 void JumpData::print_data_on(outputStream* st) const { | 194 void JumpData::print_data_on(outputStream* st, const char* extra) const { |
154 print_shared(st, "JumpData"); | 195 print_shared(st, "JumpData", extra); |
155 st->print_cr("taken(%u) displacement(%d)", taken(), displacement()); | 196 st->print_cr("taken(%u) displacement(%d)", taken(), displacement()); |
156 } | 197 } |
157 #endif // !PRODUCT | 198 #endif // !PRODUCT |
158 | 199 |
159 int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) { | 200 int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) { |
330 _pd->tab(st); | 371 _pd->tab(st); |
331 print_klass(st, type()); | 372 print_klass(st, type()); |
332 st->cr(); | 373 st->cr(); |
333 } | 374 } |
334 | 375 |
335 void CallTypeData::print_data_on(outputStream* st) const { | 376 void CallTypeData::print_data_on(outputStream* st, const char* extra) const { |
336 CounterData::print_data_on(st); | 377 CounterData::print_data_on(st, extra); |
337 if (has_arguments()) { | 378 if (has_arguments()) { |
338 tab(st, true); | 379 tab(st, true); |
339 st->print("argument types"); | 380 st->print("argument types"); |
340 _args.print_data_on(st); | 381 _args.print_data_on(st); |
341 } | 382 } |
344 st->print("return type"); | 385 st->print("return type"); |
345 _ret.print_data_on(st); | 386 _ret.print_data_on(st); |
346 } | 387 } |
347 } | 388 } |
348 | 389 |
349 void VirtualCallTypeData::print_data_on(outputStream* st) const { | 390 void VirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const { |
350 VirtualCallData::print_data_on(st); | 391 VirtualCallData::print_data_on(st, extra); |
351 if (has_arguments()) { | 392 if (has_arguments()) { |
352 tab(st, true); | 393 tab(st, true); |
353 st->print("argument types"); | 394 st->print("argument types"); |
354 _args.print_data_on(st); | 395 _args.print_data_on(st); |
355 } | 396 } |
424 receiver(row)->print_value_on(st); | 465 receiver(row)->print_value_on(st); |
425 st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total); | 466 st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total); |
426 } | 467 } |
427 } | 468 } |
428 } | 469 } |
429 void ReceiverTypeData::print_data_on(outputStream* st) const { | 470 void ReceiverTypeData::print_data_on(outputStream* st, const char* extra) const { |
430 print_shared(st, "ReceiverTypeData"); | 471 print_shared(st, "ReceiverTypeData", extra); |
431 print_receiver_data_on(st); | 472 print_receiver_data_on(st); |
432 } | 473 } |
433 | 474 |
434 #ifdef GRAAL | 475 #ifdef GRAAL |
435 void VirtualCallData::print_method_data_on(outputStream* st) const { | 476 void VirtualCallData::print_method_data_on(outputStream* st) const { |
454 } | 495 } |
455 } | 496 } |
456 } | 497 } |
457 #endif | 498 #endif |
458 | 499 |
459 void VirtualCallData::print_data_on(outputStream* st) const { | 500 void VirtualCallData::print_data_on(outputStream* st, const char* extra) const { |
460 print_shared(st, "VirtualCallData"); | 501 print_shared(st, "VirtualCallData", extra); |
461 print_receiver_data_on(st); | 502 print_receiver_data_on(st); |
462 #ifdef GRAAL | 503 #ifdef GRAAL |
463 print_method_data_on(st); | 504 print_method_data_on(st); |
464 #endif | 505 #endif |
465 } | 506 } |
507 } | 548 } |
508 } | 549 } |
509 return mdp; | 550 return mdp; |
510 } | 551 } |
511 | 552 |
553 #ifdef CC_INTERP | |
554 DataLayout* RetData::advance(MethodData *md, int bci) { | |
555 return (DataLayout*) md->bci_to_dp(bci); | |
556 } | |
557 #endif // CC_INTERP | |
512 | 558 |
513 #ifndef PRODUCT | 559 #ifndef PRODUCT |
514 void RetData::print_data_on(outputStream* st) const { | 560 void RetData::print_data_on(outputStream* st, const char* extra) const { |
515 print_shared(st, "RetData"); | 561 print_shared(st, "RetData", extra); |
516 uint row; | 562 uint row; |
517 int entries = 0; | 563 int entries = 0; |
518 for (row = 0; row < row_limit(); row++) { | 564 for (row = 0; row < row_limit(); row++) { |
519 if (bci(row) != no_bci) entries++; | 565 if (bci(row) != no_bci) entries++; |
520 } | 566 } |
544 int offset = target_di - my_di; | 590 int offset = target_di - my_di; |
545 set_displacement(offset); | 591 set_displacement(offset); |
546 } | 592 } |
547 | 593 |
548 #ifndef PRODUCT | 594 #ifndef PRODUCT |
549 void BranchData::print_data_on(outputStream* st) const { | 595 void BranchData::print_data_on(outputStream* st, const char* extra) const { |
550 print_shared(st, "BranchData"); | 596 print_shared(st, "BranchData", extra); |
551 st->print_cr("taken(%u) displacement(%d)", | 597 st->print_cr("taken(%u) displacement(%d)", |
552 taken(), displacement()); | 598 taken(), displacement()); |
553 tab(st); | 599 tab(st); |
554 st->print_cr("not taken(%u)", not_taken()); | 600 st->print_cr("not taken(%u)", not_taken()); |
555 } | 601 } |
618 set_default_displacement(offset); | 664 set_default_displacement(offset); |
619 } | 665 } |
620 } | 666 } |
621 | 667 |
622 #ifndef PRODUCT | 668 #ifndef PRODUCT |
623 void MultiBranchData::print_data_on(outputStream* st) const { | 669 void MultiBranchData::print_data_on(outputStream* st, const char* extra) const { |
624 print_shared(st, "MultiBranchData"); | 670 print_shared(st, "MultiBranchData", extra); |
625 st->print_cr("default_count(%u) displacement(%d)", | 671 st->print_cr("default_count(%u) displacement(%d)", |
626 default_count(), default_displacement()); | 672 default_count(), default_displacement()); |
627 int cases = number_of_cases(); | 673 int cases = number_of_cases(); |
628 for (int i = 0; i < cases; i++) { | 674 for (int i = 0; i < cases; i++) { |
629 tab(st); | 675 tab(st); |
632 } | 678 } |
633 } | 679 } |
634 #endif | 680 #endif |
635 | 681 |
636 #ifndef PRODUCT | 682 #ifndef PRODUCT |
637 void ArgInfoData::print_data_on(outputStream* st) const { | 683 void ArgInfoData::print_data_on(outputStream* st, const char* extra) const { |
638 print_shared(st, "ArgInfoData"); | 684 print_shared(st, "ArgInfoData", extra); |
639 int nargs = number_of_args(); | 685 int nargs = number_of_args(); |
640 for (int i = 0; i < nargs; i++) { | 686 for (int i = 0; i < nargs; i++) { |
641 st->print(" 0x%x", arg_modified(i)); | 687 st->print(" 0x%x", arg_modified(i)); |
642 } | 688 } |
643 st->cr(); | 689 st->cr(); |
664 bool ParametersTypeData::profiling_enabled() { | 710 bool ParametersTypeData::profiling_enabled() { |
665 return MethodData::profile_parameters(); | 711 return MethodData::profile_parameters(); |
666 } | 712 } |
667 | 713 |
668 #ifndef PRODUCT | 714 #ifndef PRODUCT |
669 void ParametersTypeData::print_data_on(outputStream* st) const { | 715 void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const { |
670 st->print("parameter types"); | 716 st->print("parameter types"); // FIXME extra ignored? |
671 _parameters.print_data_on(st); | 717 _parameters.print_data_on(st); |
718 } | |
719 | |
720 void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const { | |
721 print_shared(st, "SpeculativeTrapData", extra); | |
722 tab(st); | |
723 method()->print_short_name(st); | |
724 st->cr(); | |
672 } | 725 } |
673 #endif | 726 #endif |
674 | 727 |
675 // ================================================================== | 728 // ================================================================== |
676 // MethodData* | 729 // MethodData* |
793 // a DataLayout header, with no extra cells. | 846 // a DataLayout header, with no extra cells. |
794 assert(cell_count >= 0, "sanity"); | 847 assert(cell_count >= 0, "sanity"); |
795 return DataLayout::compute_size_in_bytes(cell_count); | 848 return DataLayout::compute_size_in_bytes(cell_count); |
796 } | 849 } |
797 | 850 |
851 bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) { | |
852 // Bytecodes for which we may use speculation | |
853 switch (code) { | |
854 case Bytecodes::_checkcast: | |
855 case Bytecodes::_instanceof: | |
856 case Bytecodes::_aastore: | |
857 case Bytecodes::_invokevirtual: | |
858 case Bytecodes::_invokeinterface: | |
859 case Bytecodes::_if_acmpeq: | |
860 case Bytecodes::_if_acmpne: | |
861 case Bytecodes::_invokestatic: | |
862 #ifdef COMPILER2 | |
863 return UseTypeSpeculation; | |
864 #endif | |
865 default: | |
866 return false; | |
867 } | |
868 return false; | |
869 } | |
870 | |
798 #ifdef GRAAL | 871 #ifdef GRAAL |
799 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) { | 872 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) { |
800 if (!ProfileTraps) return 0; | 873 if (!ProfileTraps) return 0; |
801 | 874 |
802 // Assume that up to 30% of the possibly trapping BCIs with no MDP will need to allocate one. | 875 // Assume that up to 30% of the possibly trapping BCIs with no MDP will need to allocate one. |
803 return MIN2(empty_bc_count, MAX2(4, (empty_bc_count * 30) / 100)); | 876 int extra_data_count = MIN2(empty_bc_count, MAX2(4, (empty_bc_count * 30) / 100)); |
877 | |
878 // Make sure we have a minimum number of extra data slots to | |
879 // allocate SpeculativeTrapData entries. We would want to have one | |
880 // entry per compilation that inlines this method and for which | |
881 // some type speculation assumption fails. So the room we need for | |
882 // the SpeculativeTrapData entries doesn't directly depend on the | |
883 // size of the method. Because it's hard to estimate, we reserve | |
884 // space for an arbitrary number of entries. | |
885 int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) * | |
886 (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells()); | |
887 | |
888 return MAX2(extra_data_count, spec_data_count); | |
804 } | 889 } |
805 #else | 890 #else |
806 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) { | 891 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) { |
807 if (ProfileTraps) { | 892 if (ProfileTraps) { |
808 // Assume that up to 3% of BCIs with no MDP will need to allocate one. | 893 // Assume that up to 3% of BCIs with no MDP will need to allocate one. |
809 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1; | 894 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1; |
810 // If the method is large, let the extra BCIs grow numerous (to ~1%). | 895 // If the method is large, let the extra BCIs grow numerous (to ~1%). |
811 int one_percent_of_data | 896 int one_percent_of_data |
812 = (uint)data_size / (DataLayout::header_size_in_bytes()*128); | 897 = (uint)data_size / (DataLayout::header_size_in_bytes()*128); |
813 if (extra_data_count < one_percent_of_data) | 898 if (extra_data_count < one_percent_of_data) |
814 extra_data_count = one_percent_of_data; | 899 extra_data_count = one_percent_of_data; |
815 if (extra_data_count > empty_bc_count) | 900 if (extra_data_count > empty_bc_count) |
816 extra_data_count = empty_bc_count; // no need for more | 901 extra_data_count = empty_bc_count; // no need for more |
817 return extra_data_count; | 902 |
903 // Make sure we have a minimum number of extra data slots to | |
904 // allocate SpeculativeTrapData entries. We would want to have one | |
905 // entry per compilation that inlines this method and for which | |
906 // some type speculation assumption fails. So the room we need for | |
907 // the SpeculativeTrapData entries doesn't directly depend on the | |
908 // size of the method. Because it's hard to estimate, we reserve | |
909 // space for an arbitrary number of entries. | |
910 int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) * | |
911 (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells()); | |
912 | |
913 return MAX2(extra_data_count, spec_data_count); | |
818 } else { | 914 } else { |
819 return 0; | 915 return 0; |
820 } | 916 } |
821 } | 917 } |
822 #endif | 918 #endif |
826 int MethodData::compute_allocation_size_in_bytes(methodHandle method) { | 922 int MethodData::compute_allocation_size_in_bytes(methodHandle method) { |
827 int data_size = 0; | 923 int data_size = 0; |
828 BytecodeStream stream(method); | 924 BytecodeStream stream(method); |
829 Bytecodes::Code c; | 925 Bytecodes::Code c; |
830 int empty_bc_count = 0; // number of bytecodes lacking data | 926 int empty_bc_count = 0; // number of bytecodes lacking data |
927 bool needs_speculative_traps = false; | |
831 while ((c = stream.next()) >= 0) { | 928 while ((c = stream.next()) >= 0) { |
832 int size_in_bytes = compute_data_size(&stream); | 929 int size_in_bytes = compute_data_size(&stream); |
833 data_size += size_in_bytes; | 930 data_size += size_in_bytes; |
834 if (size_in_bytes == 0 GRAAL_ONLY(&& Bytecodes::can_trap(c))) empty_bc_count += 1; | 931 if (size_in_bytes == 0 GRAAL_ONLY(&& Bytecodes::can_trap(c))) empty_bc_count += 1; |
932 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); | |
835 } | 933 } |
836 int object_size = in_bytes(data_offset()) + data_size; | 934 int object_size = in_bytes(data_offset()) + data_size; |
837 | 935 |
838 // Add some extra DataLayout cells (at least one) to track stray traps. | 936 // Add some extra DataLayout cells (at least one) to track stray traps. |
839 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count); | 937 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps); |
840 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0); | 938 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0); |
841 | 939 |
842 // Add a cell to record information about modified arguments. | 940 // Add a cell to record information about modified arguments. |
843 int arg_size = method->size_of_parameters(); | 941 int arg_size = method->size_of_parameters(); |
844 object_size += DataLayout::compute_size_in_bytes(arg_size+1); | 942 object_size += DataLayout::compute_size_in_bytes(arg_size+1); |
1050 parameters_type_data()->post_initialize(NULL, this); | 1148 parameters_type_data()->post_initialize(NULL, this); |
1051 } | 1149 } |
1052 } | 1150 } |
1053 | 1151 |
1054 // Initialize the MethodData* corresponding to a given method. | 1152 // Initialize the MethodData* corresponding to a given method. |
1055 MethodData::MethodData(methodHandle method, int size, TRAPS) { | 1153 MethodData::MethodData(methodHandle method, int size, TRAPS) |
1154 : _extra_data_lock(Monitor::leaf, "MDO extra data lock") { | |
1056 // Set the method back-pointer. | 1155 // Set the method back-pointer. |
1057 _method = method(); | 1156 _method = method(); |
1058 initialize(); | 1157 initialize(); |
1059 } | 1158 } |
1060 | 1159 |
1160 //TODO remove useless for_reprofile argument | |
1061 void MethodData::initialize(bool for_reprofile) { | 1161 void MethodData::initialize(bool for_reprofile) { |
1062 No_Safepoint_Verifier no_safepoint; // init function atomic wrt GC | 1162 No_Safepoint_Verifier no_safepoint; // init function atomic wrt GC |
1063 ResourceMark rm; | 1163 ResourceMark rm; |
1064 | 1164 |
1065 init(); | 1165 init(); |
1070 int data_size = 0; | 1170 int data_size = 0; |
1071 int empty_bc_count = 0; // number of bytecodes lacking data | 1171 int empty_bc_count = 0; // number of bytecodes lacking data |
1072 _data[0] = 0; // apparently not set below. | 1172 _data[0] = 0; // apparently not set below. |
1073 BytecodeStream stream(method()); | 1173 BytecodeStream stream(method()); |
1074 Bytecodes::Code c; | 1174 Bytecodes::Code c; |
1175 bool needs_speculative_traps = false; | |
1075 while ((c = stream.next()) >= 0) { | 1176 while ((c = stream.next()) >= 0) { |
1076 int size_in_bytes = initialize_data(&stream, data_size); | 1177 int size_in_bytes = initialize_data(&stream, data_size); |
1077 data_size += size_in_bytes; | 1178 data_size += size_in_bytes; |
1078 if (size_in_bytes == 0 GRAAL_ONLY(&& Bytecodes::can_trap(c))) empty_bc_count += 1; | 1179 if (size_in_bytes == 0 GRAAL_ONLY(&& Bytecodes::can_trap(c))) empty_bc_count += 1; |
1180 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); | |
1079 } | 1181 } |
1080 _data_size = data_size; | 1182 _data_size = data_size; |
1081 int object_size = in_bytes(data_offset()) + data_size; | 1183 int object_size = in_bytes(data_offset()) + data_size; |
1082 | 1184 |
1083 // Add some extra DataLayout cells (at least one) to track stray traps. | 1185 // Add some extra DataLayout cells (at least one) to track stray traps. |
1084 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count); | 1186 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps); |
1085 int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0); | 1187 int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0); |
1086 | 1188 |
1087 #ifdef GRAAL | 1189 // Let's zero the space for the extra data |
1088 if (for_reprofile) { | 1190 Copy::zero_to_bytes(((address)_data) + data_size, extra_size); |
1089 // Clear out extra data | |
1090 Copy::zero_to_bytes((HeapWord*) extra_data_base(), extra_size); | |
1091 } | |
1092 #endif | |
1093 | 1191 |
1094 // Add a cell to record information about modified arguments. | 1192 // Add a cell to record information about modified arguments. |
1095 // Set up _args_modified array after traps cells so that | 1193 // Set up _args_modified array after traps cells so that |
1096 // the code for traps cells works. | 1194 // the code for traps cells works. |
1097 DataLayout *dp = data_layout_at(data_size + extra_size); | 1195 DataLayout *dp = data_layout_at(data_size + extra_size); |
1100 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); | 1198 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); |
1101 | 1199 |
1102 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1); | 1200 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1); |
1103 object_size += extra_size + arg_data_size; | 1201 object_size += extra_size + arg_data_size; |
1104 | 1202 |
1105 int args_cell = ParametersTypeData::compute_cell_count(method()); | 1203 int parms_cell = ParametersTypeData::compute_cell_count(method()); |
1106 // If we are profiling parameters, we reserver an area near the end | 1204 // If we are profiling parameters, we reserver an area near the end |
1107 // of the MDO after the slots for bytecodes (because there's no bci | 1205 // of the MDO after the slots for bytecodes (because there's no bci |
1108 // for method entry so they don't fit with the framework for the | 1206 // for method entry so they don't fit with the framework for the |
1109 // profiling of bytecodes). We store the offset within the MDO of | 1207 // profiling of bytecodes). We store the offset within the MDO of |
1110 // this area (or -1 if no parameter is profiled) | 1208 // this area (or -1 if no parameter is profiled) |
1111 if (args_cell > 0) { | 1209 if (parms_cell > 0) { |
1112 object_size += DataLayout::compute_size_in_bytes(args_cell); | 1210 object_size += DataLayout::compute_size_in_bytes(parms_cell); |
1113 _parameters_type_data_di = data_size + extra_size + arg_data_size; | 1211 _parameters_type_data_di = data_size + extra_size + arg_data_size; |
1114 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size); | 1212 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size); |
1115 dp->initialize(DataLayout::parameters_type_data_tag, 0, args_cell); | 1213 dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell); |
1116 } else { | 1214 } else { |
1117 _parameters_type_data_di = -1; | 1215 _parameters_type_data_di = -1; |
1118 } | 1216 } |
1119 | 1217 |
1120 // Set an initial hint. Don't use set_hint_di() because | 1218 // Set an initial hint. Don't use set_hint_di() because |
1139 _highest_comp_level = 0; | 1237 _highest_comp_level = 0; |
1140 _highest_osr_comp_level = 0; | 1238 _highest_osr_comp_level = 0; |
1141 _would_profile = true; | 1239 _would_profile = true; |
1142 #ifdef GRAAL | 1240 #ifdef GRAAL |
1143 _graal_node_count = 0; | 1241 _graal_node_count = 0; |
1242 #endif | |
1243 | |
1244 #if INCLUDE_RTM_OPT | |
1245 _rtm_state = NoRTM; // No RTM lock eliding by default | |
1246 if (UseRTMLocking && | |
1247 !CompilerOracle::has_option_string(_method, "NoRTMLockEliding")) { | |
1248 if (CompilerOracle::has_option_string(_method, "UseRTMLockEliding") || !UseRTMDeopt) { | |
1249 // Generate RTM lock eliding code without abort ratio calculation code. | |
1250 _rtm_state = UseRTM; | |
1251 } else if (UseRTMDeopt) { | |
1252 // Generate RTM lock eliding code and include abort ratio calculation | |
1253 // code if UseRTMDeopt is on. | |
1254 _rtm_state = ProfileRTM; | |
1255 } | |
1256 } | |
1144 #endif | 1257 #endif |
1145 | 1258 |
1146 // Initialize flags and trap history. | 1259 // Initialize flags and trap history. |
1147 _nof_decompiles = 0; | 1260 _nof_decompiles = 0; |
1148 _nof_overflow_recompiles = 0; | 1261 _nof_overflow_recompiles = 0; |
1205 return data; | 1318 return data; |
1206 } else if (data->bci() > bci) { | 1319 } else if (data->bci() > bci) { |
1207 break; | 1320 break; |
1208 } | 1321 } |
1209 } | 1322 } |
1210 return bci_to_extra_data(bci, false); | 1323 return bci_to_extra_data(bci, NULL, false); |
1211 } | 1324 } |
1212 | 1325 |
1213 // Translate a bci to its corresponding extra data, or NULL. | 1326 DataLayout* MethodData::next_extra(DataLayout* dp) { |
1214 ProfileData* MethodData::bci_to_extra_data(int bci, bool create_if_missing) { | 1327 int nb_cells = 0; |
1215 DataLayout* dp = extra_data_base(); | 1328 switch(dp->tag()) { |
1216 DataLayout* end = extra_data_limit(); | 1329 case DataLayout::bit_data_tag: |
1217 DataLayout* avail = NULL; | 1330 case DataLayout::no_tag: |
1218 for (; dp < end; dp = next_extra(dp)) { | 1331 nb_cells = BitData::static_cell_count(); |
1332 break; | |
1333 case DataLayout::speculative_trap_data_tag: | |
1334 nb_cells = SpeculativeTrapData::static_cell_count(); | |
1335 break; | |
1336 default: | |
1337 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1338 } | |
1339 return (DataLayout*)((address)dp + DataLayout::compute_size_in_bytes(nb_cells)); | |
1340 } | |
1341 | |
1342 ProfileData* MethodData::bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp, bool concurrent) { | |
1343 DataLayout* end = extra_data_limit(); | |
1344 | |
1345 for (;; dp = next_extra(dp)) { | |
1346 assert(dp < end, "moved past end of extra data"); | |
1219 // No need for "OrderAccess::load_acquire" ops, | 1347 // No need for "OrderAccess::load_acquire" ops, |
1220 // since the data structure is monotonic. | 1348 // since the data structure is monotonic. |
1221 if (dp->tag() == DataLayout::no_tag) break; | 1349 switch(dp->tag()) { |
1222 if (dp->tag() == DataLayout::arg_info_data_tag) { | 1350 case DataLayout::no_tag: |
1223 dp = end; // ArgInfoData is at the end of extra data section. | 1351 return NULL; |
1352 case DataLayout::arg_info_data_tag: | |
1353 dp = end; | |
1354 return NULL; // ArgInfoData is at the end of extra data section. | |
1355 case DataLayout::bit_data_tag: | |
1356 if (m == NULL && dp->bci() == bci) { | |
1357 return new BitData(dp); | |
1358 } | |
1224 break; | 1359 break; |
1225 } | 1360 case DataLayout::speculative_trap_data_tag: |
1226 if (dp->bci() == bci) { | 1361 if (m != NULL) { |
1227 assert(dp->tag() == DataLayout::bit_data_tag, "sane"); | 1362 SpeculativeTrapData* data = new SpeculativeTrapData(dp); |
1363 // data->method() may be null in case of a concurrent | |
1364 // allocation. Maybe it's for the same method. Try to use that | |
1365 // entry in that case. | |
1366 if (dp->bci() == bci) { | |
1367 if (data->method() == NULL) { | |
1368 assert(concurrent, "impossible because no concurrent allocation"); | |
1369 return NULL; | |
1370 } else if (data->method() == m) { | |
1371 return data; | |
1372 } | |
1373 } | |
1374 } | |
1375 break; | |
1376 default: | |
1377 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1378 } | |
1379 } | |
1380 return NULL; | |
1381 } | |
1382 | |
1383 | |
1384 // Translate a bci to its corresponding extra data, or NULL. | |
1385 ProfileData* MethodData::bci_to_extra_data(int bci, Method* m, bool create_if_missing) { | |
1386 // This code assumes an entry for a SpeculativeTrapData is 2 cells | |
1387 assert(2*DataLayout::compute_size_in_bytes(BitData::static_cell_count()) == | |
1388 DataLayout::compute_size_in_bytes(SpeculativeTrapData::static_cell_count()), | |
1389 "code needs to be adjusted"); | |
1390 | |
1391 DataLayout* dp = extra_data_base(); | |
1392 DataLayout* end = extra_data_limit(); | |
1393 | |
1394 // Allocation in the extra data space has to be atomic because not | |
1395 // all entries have the same size and non atomic concurrent | |
1396 // allocation would result in a corrupted extra data space. | |
1397 ProfileData* result = bci_to_extra_data_helper(bci, m, dp, true); | |
1398 if (result != NULL) { | |
1399 return result; | |
1400 } | |
1401 | |
1402 if (create_if_missing && dp < end) { | |
1403 MutexLocker ml(&_extra_data_lock); | |
1404 // Check again now that we have the lock. Another thread may | |
1405 // have added extra data entries. | |
1406 ProfileData* result = bci_to_extra_data_helper(bci, m, dp, false); | |
1407 if (result != NULL || dp >= end) { | |
1408 return result; | |
1409 } | |
1410 | |
1411 assert(dp->tag() == DataLayout::no_tag || (dp->tag() == DataLayout::speculative_trap_data_tag && m != NULL), "should be free"); | |
1412 assert(next_extra(dp)->tag() == DataLayout::no_tag || next_extra(dp)->tag() == DataLayout::arg_info_data_tag, "should be free or arg info"); | |
1413 u1 tag = m == NULL ? DataLayout::bit_data_tag : DataLayout::speculative_trap_data_tag; | |
1414 // SpeculativeTrapData is 2 slots. Make sure we have room. | |
1415 if (m != NULL && next_extra(dp)->tag() != DataLayout::no_tag) { | |
1416 return NULL; | |
1417 } | |
1418 DataLayout temp; | |
1419 temp.initialize(tag, bci, 0); | |
1420 | |
1421 dp->set_header(temp.header()); | |
1422 assert(dp->tag() == tag, "sane"); | |
1423 assert(dp->bci() == bci, "no concurrent allocation"); | |
1424 if (tag == DataLayout::bit_data_tag) { | |
1228 return new BitData(dp); | 1425 return new BitData(dp); |
1229 } | 1426 } else { |
1230 } | 1427 SpeculativeTrapData* data = new SpeculativeTrapData(dp); |
1231 if (create_if_missing && dp < end) { | 1428 data->set_method(m); |
1232 // Allocate this one. There is no mutual exclusion, | 1429 return data; |
1233 // so two threads could allocate different BCIs to the | 1430 } |
1234 // same data layout. This means these extra data | |
1235 // records, like most other MDO contents, must not be | |
1236 // trusted too much. | |
1237 DataLayout temp; | |
1238 temp.initialize(DataLayout::bit_data_tag, bci, 0); | |
1239 dp->release_set_header(temp.header()); | |
1240 assert(dp->tag() == DataLayout::bit_data_tag, "sane"); | |
1241 //NO: assert(dp->bci() == bci, "no concurrent allocation"); | |
1242 return new BitData(dp); | |
1243 } | 1431 } |
1244 return NULL; | 1432 return NULL; |
1245 } | 1433 } |
1246 | 1434 |
1247 ArgInfoData *MethodData::arg_info() { | 1435 ArgInfoData *MethodData::arg_info() { |
1282 parameters_type_data()->print_data_on(st); | 1470 parameters_type_data()->print_data_on(st); |
1283 } | 1471 } |
1284 for ( ; is_valid(data); data = next_data(data)) { | 1472 for ( ; is_valid(data); data = next_data(data)) { |
1285 st->print("%d", dp_to_di(data->dp())); | 1473 st->print("%d", dp_to_di(data->dp())); |
1286 st->fill_to(6); | 1474 st->fill_to(6); |
1287 data->print_data_on(st); | 1475 data->print_data_on(st, this); |
1288 } | 1476 } |
1289 st->print_cr("--- Extra data:"); | 1477 st->print_cr("--- Extra data:"); |
1290 DataLayout* dp = extra_data_base(); | 1478 DataLayout* dp = extra_data_base(); |
1291 DataLayout* end = extra_data_limit(); | 1479 DataLayout* end = extra_data_limit(); |
1292 for (; dp < end; dp = next_extra(dp)) { | 1480 for (;; dp = next_extra(dp)) { |
1481 assert(dp < end, "moved past end of extra data"); | |
1293 // No need for "OrderAccess::load_acquire" ops, | 1482 // No need for "OrderAccess::load_acquire" ops, |
1294 // since the data structure is monotonic. | 1483 // since the data structure is monotonic. |
1295 if (dp->tag() == DataLayout::no_tag) continue; | 1484 switch(dp->tag()) { |
1296 if (dp->tag() == DataLayout::bit_data_tag) { | 1485 case DataLayout::no_tag: |
1486 continue; | |
1487 case DataLayout::bit_data_tag: | |
1297 data = new BitData(dp); | 1488 data = new BitData(dp); |
1298 } else { | 1489 break; |
1299 assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo"); | 1490 case DataLayout::speculative_trap_data_tag: |
1491 data = new SpeculativeTrapData(dp); | |
1492 break; | |
1493 case DataLayout::arg_info_data_tag: | |
1300 data = new ArgInfoData(dp); | 1494 data = new ArgInfoData(dp); |
1301 dp = end; // ArgInfoData is at the end of extra data section. | 1495 dp = end; // ArgInfoData is at the end of extra data section. |
1496 break; | |
1497 default: | |
1498 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1302 } | 1499 } |
1303 st->print("%d", dp_to_di(data->dp())); | 1500 st->print("%d", dp_to_di(data->dp())); |
1304 st->fill_to(6); | 1501 st->fill_to(6); |
1305 data->print_data_on(st); | 1502 data->print_data_on(st); |
1503 if (dp >= end) return; | |
1306 } | 1504 } |
1307 } | 1505 } |
1308 #endif | 1506 #endif |
1309 | 1507 |
1310 #if INCLUDE_SERVICES | 1508 #if INCLUDE_SERVICES |
1424 | 1622 |
1425 assert(profile_parameters_jsr292_only(), "inconsistent"); | 1623 assert(profile_parameters_jsr292_only(), "inconsistent"); |
1426 return m->is_compiled_lambda_form(); | 1624 return m->is_compiled_lambda_form(); |
1427 } | 1625 } |
1428 | 1626 |
1627 void MethodData::clean_extra_data_helper(DataLayout* dp, int shift, bool reset) { | |
1628 if (shift == 0) { | |
1629 return; | |
1630 } | |
1631 if (!reset) { | |
1632 // Move all cells of trap entry at dp left by "shift" cells | |
1633 intptr_t* start = (intptr_t*)dp; | |
1634 intptr_t* end = (intptr_t*)next_extra(dp); | |
1635 for (intptr_t* ptr = start; ptr < end; ptr++) { | |
1636 *(ptr-shift) = *ptr; | |
1637 } | |
1638 } else { | |
1639 // Reset "shift" cells stopping at dp | |
1640 intptr_t* start = ((intptr_t*)dp) - shift; | |
1641 intptr_t* end = (intptr_t*)dp; | |
1642 for (intptr_t* ptr = start; ptr < end; ptr++) { | |
1643 *ptr = 0; | |
1644 } | |
1645 } | |
1646 } | |
1647 | |
1648 // Remove SpeculativeTrapData entries that reference an unloaded | |
1649 // method | |
1650 void MethodData::clean_extra_data(BoolObjectClosure* is_alive) { | |
1651 DataLayout* dp = extra_data_base(); | |
1652 DataLayout* end = extra_data_limit(); | |
1653 | |
1654 int shift = 0; | |
1655 for (; dp < end; dp = next_extra(dp)) { | |
1656 switch(dp->tag()) { | |
1657 case DataLayout::speculative_trap_data_tag: { | |
1658 SpeculativeTrapData* data = new SpeculativeTrapData(dp); | |
1659 Method* m = data->method(); | |
1660 assert(m != NULL, "should have a method"); | |
1661 if (!m->method_holder()->is_loader_alive(is_alive)) { | |
1662 // "shift" accumulates the number of cells for dead | |
1663 // SpeculativeTrapData entries that have been seen so | |
1664 // far. Following entries must be shifted left by that many | |
1665 // cells to remove the dead SpeculativeTrapData entries. | |
1666 shift += (int)((intptr_t*)next_extra(dp) - (intptr_t*)dp); | |
1667 } else { | |
1668 // Shift this entry left if it follows dead | |
1669 // SpeculativeTrapData entries | |
1670 clean_extra_data_helper(dp, shift); | |
1671 } | |
1672 break; | |
1673 } | |
1674 case DataLayout::bit_data_tag: | |
1675 // Shift this entry left if it follows dead SpeculativeTrapData | |
1676 // entries | |
1677 clean_extra_data_helper(dp, shift); | |
1678 continue; | |
1679 case DataLayout::no_tag: | |
1680 case DataLayout::arg_info_data_tag: | |
1681 // We are at end of the live trap entries. The previous "shift" | |
1682 // cells contain entries that are either dead or were shifted | |
1683 // left. They need to be reset to no_tag | |
1684 clean_extra_data_helper(dp, shift, true); | |
1685 return; | |
1686 default: | |
1687 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1688 } | |
1689 } | |
1690 } | |
1691 | |
1692 // Verify there's no unloaded method referenced by a | |
1693 // SpeculativeTrapData entry | |
1694 void MethodData::verify_extra_data_clean(BoolObjectClosure* is_alive) { | |
1695 #ifdef ASSERT | |
1696 DataLayout* dp = extra_data_base(); | |
1697 DataLayout* end = extra_data_limit(); | |
1698 | |
1699 for (; dp < end; dp = next_extra(dp)) { | |
1700 switch(dp->tag()) { | |
1701 case DataLayout::speculative_trap_data_tag: { | |
1702 SpeculativeTrapData* data = new SpeculativeTrapData(dp); | |
1703 Method* m = data->method(); | |
1704 assert(m != NULL && m->method_holder()->is_loader_alive(is_alive), "Method should exist"); | |
1705 break; | |
1706 } | |
1707 case DataLayout::bit_data_tag: | |
1708 continue; | |
1709 case DataLayout::no_tag: | |
1710 case DataLayout::arg_info_data_tag: | |
1711 return; | |
1712 default: | |
1713 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1714 } | |
1715 } | |
1716 #endif | |
1717 } | |
1718 | |
1719 void MethodData::clean_method_data(BoolObjectClosure* is_alive) { | |
1720 for (ProfileData* data = first_data(); | |
1721 is_valid(data); | |
1722 data = next_data(data)) { | |
1723 data->clean_weak_klass_links(is_alive); | |
1724 } | |
1725 ParametersTypeData* parameters = parameters_type_data(); | |
1726 if (parameters != NULL) { | |
1727 parameters->clean_weak_klass_links(is_alive); | |
1728 } | |
1729 | |
1730 clean_extra_data(is_alive); | |
1731 verify_extra_data_clean(is_alive); | |
1732 } | |
1733 | |
1429 void MethodData::clean_weak_method_links() { | 1734 void MethodData::clean_weak_method_links() { |
1430 for (ProfileData* data = first_data(); | 1735 for (ProfileData* data = first_data(); |
1431 is_valid(data); | 1736 is_valid(data); |
1432 data = next_data(data)) { | 1737 data = next_data(data)) { |
1433 data->clean_weak_method_links(); | 1738 data->clean_weak_method_links(); |