139 int target;
140 Bytecodes::Code c = stream->code();
141 if (c == Bytecodes::_goto_w || c == Bytecodes::_jsr_w) {
142 target = stream->dest_w();
143 } else {
144 target = stream->dest();
145 }
146 int my_di = mdo->dp_to_di(dp());
147 int target_di = mdo->bci_to_di(target);
148 int offset = target_di - my_di;
149 set_displacement(offset);
150 }
151
152 #ifndef PRODUCT
153 void JumpData::print_data_on(outputStream* st) const {
154 print_shared(st, "JumpData");
155 st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
156 }
157 #endif // !PRODUCT
158
159 int TypeStackSlotEntries::compute_cell_count(BytecodeStream* stream) {
160 int max = TypeProfileArgsLimit;
161 assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
162 Bytecode_invoke inv(stream->method(), stream->bci());
163
164 ResourceMark rm;
165 SignatureStream ss(inv.signature());
166 int args_count = MIN2(ss.reference_parameter_count(), max);
167
168 return args_count * per_arg_cell_count + (args_count > 0 ? header_cell_count() : 0);
169 }
170
171 class ArgumentOffsetComputer : public SignatureInfo {
172 private:
173 int _max;
174 GrowableArray<int> _offsets;
175
176 void set(int size, BasicType type) { _size += size; }
177 void do_object(int begin, int end) {
178 if (_offsets.length() < _max) {
179 _offsets.push(_size);
180 }
181 SignatureInfo::do_object(begin, end);
182 }
183 void do_array (int begin, int end) {
184 if (_offsets.length() < _max) {
185 _offsets.push(_size);
186 }
187 SignatureInfo::do_array(begin, end);
188 }
189
190 public:
191 ArgumentOffsetComputer(Symbol* signature, int max)
192 : SignatureInfo(signature), _max(max), _offsets(Thread::current(), max) {
193 }
194
195 int total() { lazy_iterate_parameters(); return _size; }
196
197 int off_at(int i) const { return _offsets.at(i); }
198 };
199
200 void TypeStackSlotEntries::post_initialize(BytecodeStream* stream) {
201 ResourceMark rm;
202
203 assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
204 Bytecode_invoke inv(stream->method(), stream->bci());
205
206 #ifdef ASSERT
207 SignatureStream ss(inv.signature());
208 int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit);
209 assert(count > 0, "room for args type but none found?");
210 check_number_of_arguments(count);
211 #endif
212
213 int start = 0;
214 ArgumentOffsetComputer aos(inv.signature(), number_of_arguments()-start);
215 aos.total();
216 bool has_receiver = inv.has_receiver();
217 for (int i = start; i < number_of_arguments(); i++) {
218 set_stack_slot(i, aos.off_at(i-start) + (has_receiver ? 1 : 0));
219 set_type(i, type_none());
220 }
221 }
222
223 bool TypeEntries::is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p) {
224 return !is_type_none(p) &&
225 !((Klass*)klass_part(p))->is_loader_alive(is_alive_cl);
226 }
227
228 void TypeStackSlotEntries::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
229 for (int i = 0; i < number_of_arguments(); i++) {
230 intptr_t p = type(i);
231 if (is_loader_alive(is_alive_cl, p)) {
232 set_type(i, type_none());
233 }
234 }
235 }
236
237 bool TypeStackSlotEntries::arguments_profiling_enabled() {
238 return MethodData::profile_arguments();
239 }
240
241 #ifndef PRODUCT
242 void TypeEntries::print_klass(outputStream* st, intptr_t k) {
243 if (is_type_none(k)) {
244 st->print("none");
245 } else if (is_type_unknown(k)) {
246 st->print("unknown");
247 } else {
248 valid_klass(k)->print_value_on(st);
249 }
250 if (was_null_seen(k)) {
251 st->print(" (null seen)");
252 }
253 }
254
255 void TypeStackSlotEntries::print_data_on(outputStream* st) const {
256 _pd->tab(st, true);
257 st->print("argument types");
258 for (int i = 0; i < number_of_arguments(); i++) {
259 _pd->tab(st);
260 st->print("%d: stack(%u) ", i, stack_slot(i));
261 print_klass(st, type(i));
262 st->cr();
263 }
264 }
265
266 void CallTypeData::print_data_on(outputStream* st) const {
267 CounterData::print_data_on(st);
268 _args.print_data_on(st);
269 }
270
271 void VirtualCallTypeData::print_data_on(outputStream* st) const {
272 VirtualCallData::print_data_on(st);
273 _args.print_data_on(st);
274 }
275 #endif
276
277 // ==================================================================
278 // ReceiverTypeData
279 //
280 // A ReceiverTypeData is used to access profiling information about a
281 // dynamic type check. It consists of a counter which counts the total times
282 // that the check is reached, and a series of (Klass*, count) pairs
283 // which are used to store a type profile for the receiver of the check.
284
285 void ReceiverTypeData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
286 for (uint row = 0; row < row_limit(); row++) {
287 Klass* p = receiver(row);
288 if (p != NULL && !p->is_loader_alive(is_alive_cl)) {
289 clear_row(row);
290 }
291 }
292 }
293
513
514 return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD)
515 MethodData(method(), size, CHECK_NULL);
516 }
517
518 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
519 #if defined(COMPILER1) && !defined(COMPILER2)
520 return no_profile_data;
521 #else
522 switch (code) {
523 case Bytecodes::_checkcast:
524 case Bytecodes::_instanceof:
525 case Bytecodes::_aastore:
526 if (TypeProfileCasts) {
527 return ReceiverTypeData::static_cell_count();
528 } else {
529 return BitData::static_cell_count();
530 }
531 case Bytecodes::_invokespecial:
532 case Bytecodes::_invokestatic:
533 if (MethodData::profile_arguments()) {
534 return variable_cell_count;
535 } else {
536 return CounterData::static_cell_count();
537 }
538 case Bytecodes::_goto:
539 case Bytecodes::_goto_w:
540 case Bytecodes::_jsr:
541 case Bytecodes::_jsr_w:
542 return JumpData::static_cell_count();
543 case Bytecodes::_invokevirtual:
544 case Bytecodes::_invokeinterface:
545 if (MethodData::profile_arguments()) {
546 return variable_cell_count;
547 } else {
548 return VirtualCallData::static_cell_count();
549 }
550 case Bytecodes::_invokedynamic:
551 if (MethodData::profile_arguments()) {
552 return variable_cell_count;
553 } else {
554 return CounterData::static_cell_count();
555 }
556 case Bytecodes::_ret:
557 return RetData::static_cell_count();
558 case Bytecodes::_ifeq:
559 case Bytecodes::_ifne:
560 case Bytecodes::_iflt:
561 case Bytecodes::_ifge:
562 case Bytecodes::_ifgt:
563 case Bytecodes::_ifle:
564 case Bytecodes::_if_icmpeq:
565 case Bytecodes::_if_icmpne:
566 case Bytecodes::_if_icmplt:
567 case Bytecodes::_if_icmpge:
568 case Bytecodes::_if_icmpgt:
569 case Bytecodes::_if_icmple:
570 case Bytecodes::_if_acmpeq:
571 case Bytecodes::_if_acmpne:
579 return no_profile_data;
580 #endif
581 }
582
583 // Compute the size of the profiling information corresponding to
584 // the current bytecode.
585 int MethodData::compute_data_size(BytecodeStream* stream) {
586 int cell_count = bytecode_cell_count(stream->code());
587 if (cell_count == no_profile_data) {
588 return 0;
589 }
590 if (cell_count == variable_cell_count) {
591 switch (stream->code()) {
592 case Bytecodes::_lookupswitch:
593 case Bytecodes::_tableswitch:
594 cell_count = MultiBranchData::compute_cell_count(stream);
595 break;
596 case Bytecodes::_invokespecial:
597 case Bytecodes::_invokestatic:
598 case Bytecodes::_invokedynamic:
599 assert(MethodData::profile_arguments(), "should be collecting args profile");
600 if (profile_arguments_for_invoke(stream->method(), stream->bci())) {
601 cell_count = CallTypeData::compute_cell_count(stream);
602 } else {
603 cell_count = CounterData::static_cell_count();
604 }
605 break;
606 case Bytecodes::_invokevirtual:
607 case Bytecodes::_invokeinterface: {
608 assert(MethodData::profile_arguments(), "should be collecting args profile");
609 if (profile_arguments_for_invoke(stream->method(), stream->bci())) {
610 cell_count = VirtualCallTypeData::compute_cell_count(stream);
611 } else {
612 cell_count = VirtualCallData::static_cell_count();
613 }
614 break;
615 }
616 default:
617 fatal("unexpected bytecode for var length profile data");
618 }
619 }
620 // Note: cell_count might be zero, meaning that there is just
621 // a DataLayout header, with no extra cells.
622 assert(cell_count >= 0, "sanity");
623 return DataLayout::compute_size_in_bytes(cell_count);
624 }
625
626 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) {
627 if (ProfileTraps) {
628 // Assume that up to 3% of BCIs with no MDP will need to allocate one.
629 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;
682 #else
683 int cell_count = -1;
684 int tag = DataLayout::no_tag;
685 DataLayout* data_layout = data_layout_at(data_index);
686 Bytecodes::Code c = stream->code();
687 switch (c) {
688 case Bytecodes::_checkcast:
689 case Bytecodes::_instanceof:
690 case Bytecodes::_aastore:
691 if (TypeProfileCasts) {
692 cell_count = ReceiverTypeData::static_cell_count();
693 tag = DataLayout::receiver_type_data_tag;
694 } else {
695 cell_count = BitData::static_cell_count();
696 tag = DataLayout::bit_data_tag;
697 }
698 break;
699 case Bytecodes::_invokespecial:
700 case Bytecodes::_invokestatic: {
701 int counter_data_cell_count = CounterData::static_cell_count();
702 if (profile_arguments_for_invoke(stream->method(), stream->bci())) {
703 cell_count = CallTypeData::compute_cell_count(stream);
704 } else {
705 cell_count = counter_data_cell_count;
706 }
707 if (cell_count > counter_data_cell_count) {
708 tag = DataLayout::call_type_data_tag;
709 } else {
710 tag = DataLayout::counter_data_tag;
711 }
712 break;
713 }
714 case Bytecodes::_goto:
715 case Bytecodes::_goto_w:
716 case Bytecodes::_jsr:
717 case Bytecodes::_jsr_w:
718 cell_count = JumpData::static_cell_count();
719 tag = DataLayout::jump_data_tag;
720 break;
721 case Bytecodes::_invokevirtual:
722 case Bytecodes::_invokeinterface: {
723 int virtual_call_data_cell_count = VirtualCallData::static_cell_count();
724 if (profile_arguments_for_invoke(stream->method(), stream->bci())) {
725 cell_count = VirtualCallTypeData::compute_cell_count(stream);
726 } else {
727 cell_count = virtual_call_data_cell_count;
728 }
729 if (cell_count > virtual_call_data_cell_count) {
730 tag = DataLayout::virtual_call_type_data_tag;
731 } else {
732 tag = DataLayout::virtual_call_data_tag;
733 }
734 break;
735 }
736 case Bytecodes::_invokedynamic: {
737 // %%% should make a type profile for any invokedynamic that takes a ref argument
738 int counter_data_cell_count = CounterData::static_cell_count();
739 if (profile_arguments_for_invoke(stream->method(), stream->bci())) {
740 cell_count = CallTypeData::compute_cell_count(stream);
741 } else {
742 cell_count = counter_data_cell_count;
743 }
744 if (cell_count > counter_data_cell_count) {
745 tag = DataLayout::call_type_data_tag;
746 } else {
747 tag = DataLayout::counter_data_tag;
748 }
749 break;
750 }
751 case Bytecodes::_ret:
752 cell_count = RetData::static_cell_count();
753 tag = DataLayout::ret_data_tag;
754 break;
755 case Bytecodes::_ifeq:
756 case Bytecodes::_ifne:
757 case Bytecodes::_iflt:
758 case Bytecodes::_ifge:
759 case Bytecodes::_ifgt:
761 case Bytecodes::_if_icmpeq:
762 case Bytecodes::_if_icmpne:
763 case Bytecodes::_if_icmplt:
764 case Bytecodes::_if_icmpge:
765 case Bytecodes::_if_icmpgt:
766 case Bytecodes::_if_icmple:
767 case Bytecodes::_if_acmpeq:
768 case Bytecodes::_if_acmpne:
769 case Bytecodes::_ifnull:
770 case Bytecodes::_ifnonnull:
771 cell_count = BranchData::static_cell_count();
772 tag = DataLayout::branch_data_tag;
773 break;
774 case Bytecodes::_lookupswitch:
775 case Bytecodes::_tableswitch:
776 cell_count = MultiBranchData::compute_cell_count(stream);
777 tag = DataLayout::multi_branch_data_tag;
778 break;
779 }
780 assert(tag == DataLayout::multi_branch_data_tag ||
781 (MethodData::profile_arguments() &&
782 (tag == DataLayout::call_type_data_tag ||
783 tag == DataLayout::counter_data_tag ||
784 tag == DataLayout::virtual_call_type_data_tag ||
785 tag == DataLayout::virtual_call_data_tag)) ||
786 cell_count == bytecode_cell_count(c), "cell counts must agree");
787 if (cell_count >= 0) {
788 assert(tag != DataLayout::no_tag, "bad tag");
789 assert(bytecode_has_profile(c), "agree w/ BHP");
790 data_layout->initialize(tag, stream->bci(), cell_count);
791 return DataLayout::compute_size_in_bytes(cell_count);
792 } else {
793 assert(!bytecode_has_profile(c), "agree w/ !BHP");
794 return 0;
795 }
796 #endif
797 }
798
799 // Get the data at an arbitrary (sort of) data index.
800 ProfileData* MethodData::data_at(int data_index) const {
801 if (out_of_bounds(data_index)) {
1094 guarantee(is_methodData(), "object must be method data");
1095 // guarantee(m->is_perm(), "should be in permspace");
1096 this->verify_data_on(st);
1097 }
1098
1099 void MethodData::verify_data_on(outputStream* st) {
1100 NEEDS_CLEANUP;
1101 // not yet implemented.
1102 }
1103
1104 bool MethodData::profile_jsr292(methodHandle m, int bci) {
1105 if (m->is_compiled_lambda_form()) {
1106 return true;
1107 }
1108
1109 Bytecode_invoke inv(m , bci);
1110 return inv.is_invokedynamic() || inv.is_invokehandle();
1111 }
1112
1113 int MethodData::profile_arguments_flag() {
1114 return TypeProfileLevel;
1115 }
1116
1117 bool MethodData::profile_arguments() {
1118 return profile_arguments_flag() > no_type_profile && profile_arguments_flag() <= type_profile_all;
1119 }
1120
1121 bool MethodData::profile_arguments_jsr292_only() {
1122 return profile_arguments_flag() == type_profile_jsr292;
1123 }
1124
1125 bool MethodData::profile_all_arguments() {
1126 return profile_arguments_flag() == type_profile_all;
1127 }
1128
1129 bool MethodData::profile_arguments_for_invoke(methodHandle m, int bci) {
1130 if (!profile_arguments()) {
1131 return false;
1132 }
1133
1134 if (profile_all_arguments()) {
1135 return true;
1136 }
1137
1138 assert(profile_arguments_jsr292_only(), "inconsistent");
1139 return profile_jsr292(m, bci);
1140 }
1141
|
139 int target;
140 Bytecodes::Code c = stream->code();
141 if (c == Bytecodes::_goto_w || c == Bytecodes::_jsr_w) {
142 target = stream->dest_w();
143 } else {
144 target = stream->dest();
145 }
146 int my_di = mdo->dp_to_di(dp());
147 int target_di = mdo->bci_to_di(target);
148 int offset = target_di - my_di;
149 set_displacement(offset);
150 }
151
152 #ifndef PRODUCT
153 void JumpData::print_data_on(outputStream* st) const {
154 print_shared(st, "JumpData");
155 st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
156 }
157 #endif // !PRODUCT
158
159 int TypeStackSlotEntries::compute_cell_count(Symbol* signature, int max) {
160 ResourceMark rm;
161 SignatureStream ss(signature);
162 int args_count = MIN2(ss.reference_parameter_count(), max);
163 return args_count * per_arg_cell_count;
164 }
165
166 int TypeEntriesAtCall::compute_cell_count(BytecodeStream* stream) {
167 assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
168 assert(TypeStackSlotEntries::per_arg_count() > ReturnTypeEntry::static_cell_count(), "code to test for arguments/results broken");
169 Bytecode_invoke inv(stream->method(), stream->bci());
170 int args_cell = 0;
171 if (arguments_profiling_enabled()) {
172 args_cell = TypeStackSlotEntries::compute_cell_count(inv.signature(), TypeProfileArgsLimit);
173 }
174 int ret_cell = 0;
175 if (return_profiling_enabled() && (inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY)) {
176 ret_cell = ReturnTypeEntry::static_cell_count();
177 }
178 int header_cell = 0;
179 if (args_cell + ret_cell > 0) {
180 header_cell = header_cell_count();
181 }
182
183 return header_cell + args_cell + ret_cell;
184 }
185
186 class ArgumentOffsetComputer : public SignatureInfo {
187 private:
188 int _max;
189 GrowableArray<int> _offsets;
190
191 void set(int size, BasicType type) { _size += size; }
192 void do_object(int begin, int end) {
193 if (_offsets.length() < _max) {
194 _offsets.push(_size);
195 }
196 SignatureInfo::do_object(begin, end);
197 }
198 void do_array (int begin, int end) {
199 if (_offsets.length() < _max) {
200 _offsets.push(_size);
201 }
202 SignatureInfo::do_array(begin, end);
203 }
204
205 public:
206 ArgumentOffsetComputer(Symbol* signature, int max)
207 : SignatureInfo(signature), _max(max), _offsets(Thread::current(), max) {
208 }
209
210 int total() { lazy_iterate_parameters(); return _size; }
211
212 int off_at(int i) const { return _offsets.at(i); }
213 };
214
215 void TypeStackSlotEntries::post_initialize(Symbol* signature, bool has_receiver) {
216 ResourceMark rm;
217 ArgumentOffsetComputer aos(signature, _number_of_entries);
218 aos.total();
219 for (int i = 0; i < _number_of_entries; i++) {
220 set_stack_slot(i, aos.off_at(i) + (has_receiver ? 1 : 0));
221 set_type(i, type_none());
222 }
223 }
224
225 void CallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
226 assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
227 Bytecode_invoke inv(stream->method(), stream->bci());
228
229 SignatureStream ss(inv.signature());
230 if (has_arguments()) {
231 #ifdef ASSERT
232 ResourceMark rm;
233 int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit);
234 assert(count > 0, "room for args type but none found?");
235 check_number_of_arguments(count);
236 #endif
237 _args.post_initialize(inv.signature(), inv.has_receiver());
238 }
239
240 if (has_return()) {
241 assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?");
242 _ret.post_initialize();
243 }
244 }
245
246 void VirtualCallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
247 assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
248 Bytecode_invoke inv(stream->method(), stream->bci());
249
250 if (has_arguments()) {
251 #ifdef ASSERT
252 ResourceMark rm;
253 SignatureStream ss(inv.signature());
254 int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit);
255 assert(count > 0, "room for args type but none found?");
256 check_number_of_arguments(count);
257 #endif
258 _args.post_initialize(inv.signature(), inv.has_receiver());
259 }
260
261 if (has_return()) {
262 assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?");
263 _ret.post_initialize();
264 }
265 }
266
267 bool TypeEntries::is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p) {
268 return !is_type_none(p) &&
269 !((Klass*)klass_part(p))->is_loader_alive(is_alive_cl);
270 }
271
272 void TypeStackSlotEntries::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
273 for (int i = 0; i < _number_of_entries; i++) {
274 intptr_t p = type(i);
275 if (is_loader_alive(is_alive_cl, p)) {
276 set_type(i, type_none());
277 }
278 }
279 }
280
281 void ReturnTypeEntry::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
282 intptr_t p = type();
283 if (is_loader_alive(is_alive_cl, p)) {
284 set_type(type_none());
285 }
286 }
287
288 bool TypeEntriesAtCall::return_profiling_enabled() {
289 return MethodData::profile_return();
290 }
291
292 bool TypeEntriesAtCall::arguments_profiling_enabled() {
293 return MethodData::profile_arguments();
294 }
295
296 #ifndef PRODUCT
297 void TypeEntries::print_klass(outputStream* st, intptr_t k) {
298 if (is_type_none(k)) {
299 st->print("none");
300 } else if (is_type_unknown(k)) {
301 st->print("unknown");
302 } else {
303 valid_klass(k)->print_value_on(st);
304 }
305 if (was_null_seen(k)) {
306 st->print(" (null seen)");
307 }
308 }
309
310 void TypeStackSlotEntries::print_data_on(outputStream* st) const {
311 for (int i = 0; i < _number_of_entries; i++) {
312 _pd->tab(st);
313 st->print("%d: stack(%u) ", i, stack_slot(i));
314 print_klass(st, type(i));
315 st->cr();
316 }
317 }
318
319 void ReturnTypeEntry::print_data_on(outputStream* st) const {
320 _pd->tab(st);
321 print_klass(st, type());
322 st->cr();
323 }
324
325 void CallTypeData::print_data_on(outputStream* st) const {
326 CounterData::print_data_on(st);
327 if (has_arguments()) {
328 tab(st, true);
329 st->print("argument types");
330 _args.print_data_on(st);
331 }
332 if (has_return()) {
333 tab(st, true);
334 st->print("return type");
335 _ret.print_data_on(st);
336 }
337 }
338
339 void VirtualCallTypeData::print_data_on(outputStream* st) const {
340 VirtualCallData::print_data_on(st);
341 if (has_arguments()) {
342 tab(st, true);
343 st->print("argument types");
344 _args.print_data_on(st);
345 }
346 if (has_return()) {
347 tab(st, true);
348 st->print("return type");
349 _ret.print_data_on(st);
350 }
351 }
352 #endif
353
354 // ==================================================================
355 // ReceiverTypeData
356 //
357 // A ReceiverTypeData is used to access profiling information about a
358 // dynamic type check. It consists of a counter which counts the total times
359 // that the check is reached, and a series of (Klass*, count) pairs
360 // which are used to store a type profile for the receiver of the check.
361
362 void ReceiverTypeData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
363 for (uint row = 0; row < row_limit(); row++) {
364 Klass* p = receiver(row);
365 if (p != NULL && !p->is_loader_alive(is_alive_cl)) {
366 clear_row(row);
367 }
368 }
369 }
370
590
591 return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD)
592 MethodData(method(), size, CHECK_NULL);
593 }
594
595 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
596 #if defined(COMPILER1) && !defined(COMPILER2)
597 return no_profile_data;
598 #else
599 switch (code) {
600 case Bytecodes::_checkcast:
601 case Bytecodes::_instanceof:
602 case Bytecodes::_aastore:
603 if (TypeProfileCasts) {
604 return ReceiverTypeData::static_cell_count();
605 } else {
606 return BitData::static_cell_count();
607 }
608 case Bytecodes::_invokespecial:
609 case Bytecodes::_invokestatic:
610 if (MethodData::profile_arguments() || MethodData::profile_return()) {
611 return variable_cell_count;
612 } else {
613 return CounterData::static_cell_count();
614 }
615 case Bytecodes::_goto:
616 case Bytecodes::_goto_w:
617 case Bytecodes::_jsr:
618 case Bytecodes::_jsr_w:
619 return JumpData::static_cell_count();
620 case Bytecodes::_invokevirtual:
621 case Bytecodes::_invokeinterface:
622 if (MethodData::profile_arguments() || MethodData::profile_return()) {
623 return variable_cell_count;
624 } else {
625 return VirtualCallData::static_cell_count();
626 }
627 case Bytecodes::_invokedynamic:
628 if (MethodData::profile_arguments() || MethodData::profile_return()) {
629 return variable_cell_count;
630 } else {
631 return CounterData::static_cell_count();
632 }
633 case Bytecodes::_ret:
634 return RetData::static_cell_count();
635 case Bytecodes::_ifeq:
636 case Bytecodes::_ifne:
637 case Bytecodes::_iflt:
638 case Bytecodes::_ifge:
639 case Bytecodes::_ifgt:
640 case Bytecodes::_ifle:
641 case Bytecodes::_if_icmpeq:
642 case Bytecodes::_if_icmpne:
643 case Bytecodes::_if_icmplt:
644 case Bytecodes::_if_icmpge:
645 case Bytecodes::_if_icmpgt:
646 case Bytecodes::_if_icmple:
647 case Bytecodes::_if_acmpeq:
648 case Bytecodes::_if_acmpne:
656 return no_profile_data;
657 #endif
658 }
659
660 // Compute the size of the profiling information corresponding to
661 // the current bytecode.
662 int MethodData::compute_data_size(BytecodeStream* stream) {
663 int cell_count = bytecode_cell_count(stream->code());
664 if (cell_count == no_profile_data) {
665 return 0;
666 }
667 if (cell_count == variable_cell_count) {
668 switch (stream->code()) {
669 case Bytecodes::_lookupswitch:
670 case Bytecodes::_tableswitch:
671 cell_count = MultiBranchData::compute_cell_count(stream);
672 break;
673 case Bytecodes::_invokespecial:
674 case Bytecodes::_invokestatic:
675 case Bytecodes::_invokedynamic:
676 assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile");
677 if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
678 profile_return_for_invoke(stream->method(), stream->bci())) {
679 cell_count = CallTypeData::compute_cell_count(stream);
680 } else {
681 cell_count = CounterData::static_cell_count();
682 }
683 break;
684 case Bytecodes::_invokevirtual:
685 case Bytecodes::_invokeinterface: {
686 assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile");
687 if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
688 profile_return_for_invoke(stream->method(), stream->bci())) {
689 cell_count = VirtualCallTypeData::compute_cell_count(stream);
690 } else {
691 cell_count = VirtualCallData::static_cell_count();
692 }
693 break;
694 }
695 default:
696 fatal("unexpected bytecode for var length profile data");
697 }
698 }
699 // Note: cell_count might be zero, meaning that there is just
700 // a DataLayout header, with no extra cells.
701 assert(cell_count >= 0, "sanity");
702 return DataLayout::compute_size_in_bytes(cell_count);
703 }
704
705 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) {
706 if (ProfileTraps) {
707 // Assume that up to 3% of BCIs with no MDP will need to allocate one.
708 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;
761 #else
762 int cell_count = -1;
763 int tag = DataLayout::no_tag;
764 DataLayout* data_layout = data_layout_at(data_index);
765 Bytecodes::Code c = stream->code();
766 switch (c) {
767 case Bytecodes::_checkcast:
768 case Bytecodes::_instanceof:
769 case Bytecodes::_aastore:
770 if (TypeProfileCasts) {
771 cell_count = ReceiverTypeData::static_cell_count();
772 tag = DataLayout::receiver_type_data_tag;
773 } else {
774 cell_count = BitData::static_cell_count();
775 tag = DataLayout::bit_data_tag;
776 }
777 break;
778 case Bytecodes::_invokespecial:
779 case Bytecodes::_invokestatic: {
780 int counter_data_cell_count = CounterData::static_cell_count();
781 if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
782 profile_return_for_invoke(stream->method(), stream->bci())) {
783 cell_count = CallTypeData::compute_cell_count(stream);
784 } else {
785 cell_count = counter_data_cell_count;
786 }
787 if (cell_count > counter_data_cell_count) {
788 tag = DataLayout::call_type_data_tag;
789 } else {
790 tag = DataLayout::counter_data_tag;
791 }
792 break;
793 }
794 case Bytecodes::_goto:
795 case Bytecodes::_goto_w:
796 case Bytecodes::_jsr:
797 case Bytecodes::_jsr_w:
798 cell_count = JumpData::static_cell_count();
799 tag = DataLayout::jump_data_tag;
800 break;
801 case Bytecodes::_invokevirtual:
802 case Bytecodes::_invokeinterface: {
803 int virtual_call_data_cell_count = VirtualCallData::static_cell_count();
804 if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
805 profile_return_for_invoke(stream->method(), stream->bci())) {
806 cell_count = VirtualCallTypeData::compute_cell_count(stream);
807 } else {
808 cell_count = virtual_call_data_cell_count;
809 }
810 if (cell_count > virtual_call_data_cell_count) {
811 tag = DataLayout::virtual_call_type_data_tag;
812 } else {
813 tag = DataLayout::virtual_call_data_tag;
814 }
815 break;
816 }
817 case Bytecodes::_invokedynamic: {
818 // %%% should make a type profile for any invokedynamic that takes a ref argument
819 int counter_data_cell_count = CounterData::static_cell_count();
820 if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
821 profile_return_for_invoke(stream->method(), stream->bci())) {
822 cell_count = CallTypeData::compute_cell_count(stream);
823 } else {
824 cell_count = counter_data_cell_count;
825 }
826 if (cell_count > counter_data_cell_count) {
827 tag = DataLayout::call_type_data_tag;
828 } else {
829 tag = DataLayout::counter_data_tag;
830 }
831 break;
832 }
833 case Bytecodes::_ret:
834 cell_count = RetData::static_cell_count();
835 tag = DataLayout::ret_data_tag;
836 break;
837 case Bytecodes::_ifeq:
838 case Bytecodes::_ifne:
839 case Bytecodes::_iflt:
840 case Bytecodes::_ifge:
841 case Bytecodes::_ifgt:
843 case Bytecodes::_if_icmpeq:
844 case Bytecodes::_if_icmpne:
845 case Bytecodes::_if_icmplt:
846 case Bytecodes::_if_icmpge:
847 case Bytecodes::_if_icmpgt:
848 case Bytecodes::_if_icmple:
849 case Bytecodes::_if_acmpeq:
850 case Bytecodes::_if_acmpne:
851 case Bytecodes::_ifnull:
852 case Bytecodes::_ifnonnull:
853 cell_count = BranchData::static_cell_count();
854 tag = DataLayout::branch_data_tag;
855 break;
856 case Bytecodes::_lookupswitch:
857 case Bytecodes::_tableswitch:
858 cell_count = MultiBranchData::compute_cell_count(stream);
859 tag = DataLayout::multi_branch_data_tag;
860 break;
861 }
862 assert(tag == DataLayout::multi_branch_data_tag ||
863 ((MethodData::profile_arguments() || MethodData::profile_return()) &&
864 (tag == DataLayout::call_type_data_tag ||
865 tag == DataLayout::counter_data_tag ||
866 tag == DataLayout::virtual_call_type_data_tag ||
867 tag == DataLayout::virtual_call_data_tag)) ||
868 cell_count == bytecode_cell_count(c), "cell counts must agree");
869 if (cell_count >= 0) {
870 assert(tag != DataLayout::no_tag, "bad tag");
871 assert(bytecode_has_profile(c), "agree w/ BHP");
872 data_layout->initialize(tag, stream->bci(), cell_count);
873 return DataLayout::compute_size_in_bytes(cell_count);
874 } else {
875 assert(!bytecode_has_profile(c), "agree w/ !BHP");
876 return 0;
877 }
878 #endif
879 }
880
881 // Get the data at an arbitrary (sort of) data index.
882 ProfileData* MethodData::data_at(int data_index) const {
883 if (out_of_bounds(data_index)) {
1176 guarantee(is_methodData(), "object must be method data");
1177 // guarantee(m->is_perm(), "should be in permspace");
1178 this->verify_data_on(st);
1179 }
1180
1181 void MethodData::verify_data_on(outputStream* st) {
1182 NEEDS_CLEANUP;
1183 // not yet implemented.
1184 }
1185
1186 bool MethodData::profile_jsr292(methodHandle m, int bci) {
1187 if (m->is_compiled_lambda_form()) {
1188 return true;
1189 }
1190
1191 Bytecode_invoke inv(m , bci);
1192 return inv.is_invokedynamic() || inv.is_invokehandle();
1193 }
1194
1195 int MethodData::profile_arguments_flag() {
1196 return TypeProfileLevel % 10;
1197 }
1198
1199 bool MethodData::profile_arguments() {
1200 return profile_arguments_flag() > no_type_profile && profile_arguments_flag() <= type_profile_all;
1201 }
1202
1203 bool MethodData::profile_arguments_jsr292_only() {
1204 return profile_arguments_flag() == type_profile_jsr292;
1205 }
1206
1207 bool MethodData::profile_all_arguments() {
1208 return profile_arguments_flag() == type_profile_all;
1209 }
1210
1211 bool MethodData::profile_arguments_for_invoke(methodHandle m, int bci) {
1212 if (!profile_arguments()) {
1213 return false;
1214 }
1215
1216 if (profile_all_arguments()) {
1217 return true;
1218 }
1219
1220 assert(profile_arguments_jsr292_only(), "inconsistent");
1221 return profile_jsr292(m, bci);
1222 }
1223
1224 int MethodData::profile_return_flag() {
1225 return TypeProfileLevel / 10;
1226 }
1227
1228 bool MethodData::profile_return() {
1229 return profile_return_flag() > no_type_profile && profile_return_flag() <= type_profile_all;
1230 }
1231
1232 bool MethodData::profile_return_jsr292_only() {
1233 return profile_return_flag() == type_profile_jsr292;
1234 }
1235
1236 bool MethodData::profile_all_return() {
1237 return profile_return_flag() == type_profile_all;
1238 }
1239
1240 bool MethodData::profile_return_for_invoke(methodHandle m, int bci) {
1241 if (!profile_return()) {
1242 return false;
1243 }
1244
1245 if (profile_all_return()) {
1246 return true;
1247 }
1248
1249 assert(profile_return_jsr292_only(), "inconsistent");
1250 return profile_jsr292(m, bci);
1251 }
|