Mercurial > hg > truffle
comparison src/share/vm/oops/methodData.cpp @ 13086:096c224171c4
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 20 Nov 2013 00:10:38 +0100 |
parents | 359f7e70ae7f 6e1826d5c23e |
children | ec3e4f35e466 |
comparison
equal
deleted
inserted
replaced
12782:92b7ec34ddfa | 13086:096c224171c4 |
---|---|
39 // | 39 // |
40 // Overlay for generic profiling data. | 40 // Overlay for generic profiling data. |
41 | 41 |
42 // Some types of data layouts need a length field. | 42 // Some types of data layouts need a length field. |
43 bool DataLayout::needs_array_len(u1 tag) { | 43 bool DataLayout::needs_array_len(u1 tag) { |
44 return (tag == multi_branch_data_tag) || (tag == arg_info_data_tag); | 44 return (tag == multi_branch_data_tag) || (tag == arg_info_data_tag) || (tag == parameters_type_data_tag); |
45 } | 45 } |
46 | 46 |
47 // Perform generic initialization of the data. More specific | 47 // Perform generic initialization of the data. More specific |
48 // initialization occurs in overrides of ProfileData::post_initialize. | 48 // initialization occurs in overrides of ProfileData::post_initialize. |
49 void DataLayout::initialize(u1 tag, u2 bci, int cell_count) { | 49 void DataLayout::initialize(u1 tag, u2 bci, int cell_count) { |
54 set_cell_at(i, (intptr_t)0); | 54 set_cell_at(i, (intptr_t)0); |
55 } | 55 } |
56 if (needs_array_len(tag)) { | 56 if (needs_array_len(tag)) { |
57 set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header. | 57 set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header. |
58 } | 58 } |
59 if (tag == call_type_data_tag) { | |
60 CallTypeData::initialize(this, cell_count); | |
61 } else if (tag == virtual_call_type_data_tag) { | |
62 VirtualCallTypeData::initialize(this, cell_count); | |
63 } | |
59 } | 64 } |
60 | 65 |
61 void DataLayout::clean_weak_klass_links(BoolObjectClosure* cl) { | 66 void DataLayout::clean_weak_klass_links(BoolObjectClosure* cl) { |
62 ResourceMark m; | 67 ResourceMark m; |
63 data_in()->clean_weak_klass_links(cl); | 68 data_in()->clean_weak_klass_links(cl); |
74 ProfileData::ProfileData() { | 79 ProfileData::ProfileData() { |
75 _data = NULL; | 80 _data = NULL; |
76 } | 81 } |
77 | 82 |
78 #ifndef PRODUCT | 83 #ifndef PRODUCT |
79 void ProfileData::print_shared(outputStream* st, const char* name) { | 84 void ProfileData::print_shared(outputStream* st, const char* name) const { |
80 st->print("bci: %d", bci()); | 85 st->print("bci: %d", bci()); |
81 st->fill_to(tab_width_one); | 86 st->fill_to(tab_width_one); |
82 st->print("%s", name); | 87 st->print("%s", name); |
83 tab(st); | 88 tab(st); |
84 int trap = trap_state(); | 89 int trap = trap_state(); |
89 int flags = data()->flags(); | 94 int flags = data()->flags(); |
90 if (flags != 0) | 95 if (flags != 0) |
91 st->print("flags(%d) ", flags); | 96 st->print("flags(%d) ", flags); |
92 } | 97 } |
93 | 98 |
94 void ProfileData::tab(outputStream* st) { | 99 void ProfileData::tab(outputStream* st, bool first) const { |
95 st->fill_to(tab_width_two); | 100 st->fill_to(first ? tab_width_one : tab_width_two); |
96 } | 101 } |
97 #endif // !PRODUCT | 102 #endif // !PRODUCT |
98 | 103 |
99 // ================================================================== | 104 // ================================================================== |
100 // BitData | 105 // BitData |
102 // A BitData corresponds to a one-bit flag. This is used to indicate | 107 // A BitData corresponds to a one-bit flag. This is used to indicate |
103 // whether a checkcast bytecode has seen a null value. | 108 // whether a checkcast bytecode has seen a null value. |
104 | 109 |
105 | 110 |
106 #ifndef PRODUCT | 111 #ifndef PRODUCT |
107 void BitData::print_data_on(outputStream* st) { | 112 void BitData::print_data_on(outputStream* st) const { |
108 print_shared(st, "BitData"); | 113 print_shared(st, "BitData"); |
109 } | 114 } |
110 #endif // !PRODUCT | 115 #endif // !PRODUCT |
111 | 116 |
112 // ================================================================== | 117 // ================================================================== |
113 // CounterData | 118 // CounterData |
114 // | 119 // |
115 // A CounterData corresponds to a simple counter. | 120 // A CounterData corresponds to a simple counter. |
116 | 121 |
117 #ifndef PRODUCT | 122 #ifndef PRODUCT |
118 void CounterData::print_data_on(outputStream* st) { | 123 void CounterData::print_data_on(outputStream* st) const { |
119 print_shared(st, "CounterData"); | 124 print_shared(st, "CounterData"); |
120 st->print_cr("count(%u)", count()); | 125 st->print_cr("count(%u)", count()); |
121 } | 126 } |
122 #endif // !PRODUCT | 127 #endif // !PRODUCT |
123 | 128 |
143 int offset = target_di - my_di; | 148 int offset = target_di - my_di; |
144 set_displacement(offset); | 149 set_displacement(offset); |
145 } | 150 } |
146 | 151 |
147 #ifndef PRODUCT | 152 #ifndef PRODUCT |
148 void JumpData::print_data_on(outputStream* st) { | 153 void JumpData::print_data_on(outputStream* st) const { |
149 print_shared(st, "JumpData"); | 154 print_shared(st, "JumpData"); |
150 st->print_cr("taken(%u) displacement(%d)", taken(), displacement()); | 155 st->print_cr("taken(%u) displacement(%d)", taken(), displacement()); |
151 } | 156 } |
152 #endif // !PRODUCT | 157 #endif // !PRODUCT |
158 | |
159 int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) { | |
160 // Parameter profiling include the receiver | |
161 int args_count = include_receiver ? 1 : 0; | |
162 ResourceMark rm; | |
163 SignatureStream ss(signature); | |
164 args_count += ss.reference_parameter_count(); | |
165 args_count = MIN2(args_count, max); | |
166 return args_count * per_arg_cell_count; | |
167 } | |
168 | |
169 int TypeEntriesAtCall::compute_cell_count(BytecodeStream* stream) { | |
170 assert(Bytecodes::is_invoke(stream->code()), "should be invoke"); | |
171 assert(TypeStackSlotEntries::per_arg_count() > ReturnTypeEntry::static_cell_count(), "code to test for arguments/results broken"); | |
172 Bytecode_invoke inv(stream->method(), stream->bci()); | |
173 int args_cell = 0; | |
174 if (arguments_profiling_enabled()) { | |
175 args_cell = TypeStackSlotEntries::compute_cell_count(inv.signature(), false, TypeProfileArgsLimit); | |
176 } | |
177 int ret_cell = 0; | |
178 if (return_profiling_enabled() && (inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY)) { | |
179 ret_cell = ReturnTypeEntry::static_cell_count(); | |
180 } | |
181 int header_cell = 0; | |
182 if (args_cell + ret_cell > 0) { | |
183 header_cell = header_cell_count(); | |
184 } | |
185 | |
186 return header_cell + args_cell + ret_cell; | |
187 } | |
188 | |
189 class ArgumentOffsetComputer : public SignatureInfo { | |
190 private: | |
191 int _max; | |
192 GrowableArray<int> _offsets; | |
193 | |
194 void set(int size, BasicType type) { _size += size; } | |
195 void do_object(int begin, int end) { | |
196 if (_offsets.length() < _max) { | |
197 _offsets.push(_size); | |
198 } | |
199 SignatureInfo::do_object(begin, end); | |
200 } | |
201 void do_array (int begin, int end) { | |
202 if (_offsets.length() < _max) { | |
203 _offsets.push(_size); | |
204 } | |
205 SignatureInfo::do_array(begin, end); | |
206 } | |
207 | |
208 public: | |
209 ArgumentOffsetComputer(Symbol* signature, int max) | |
210 : SignatureInfo(signature), _max(max), _offsets(Thread::current(), max) { | |
211 } | |
212 | |
213 int total() { lazy_iterate_parameters(); return _size; } | |
214 | |
215 int off_at(int i) const { return _offsets.at(i); } | |
216 }; | |
217 | |
218 void TypeStackSlotEntries::post_initialize(Symbol* signature, bool has_receiver, bool include_receiver) { | |
219 ResourceMark rm; | |
220 int start = 0; | |
221 // Parameter profiling include the receiver | |
222 if (include_receiver && has_receiver) { | |
223 set_stack_slot(0, 0); | |
224 set_type(0, type_none()); | |
225 start += 1; | |
226 } | |
227 ArgumentOffsetComputer aos(signature, _number_of_entries-start); | |
228 aos.total(); | |
229 for (int i = start; i < _number_of_entries; i++) { | |
230 set_stack_slot(i, aos.off_at(i-start) + (has_receiver ? 1 : 0)); | |
231 set_type(i, type_none()); | |
232 } | |
233 } | |
234 | |
235 void CallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) { | |
236 assert(Bytecodes::is_invoke(stream->code()), "should be invoke"); | |
237 Bytecode_invoke inv(stream->method(), stream->bci()); | |
238 | |
239 SignatureStream ss(inv.signature()); | |
240 if (has_arguments()) { | |
241 #ifdef ASSERT | |
242 ResourceMark rm; | |
243 int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit); | |
244 assert(count > 0, "room for args type but none found?"); | |
245 check_number_of_arguments(count); | |
246 #endif | |
247 _args.post_initialize(inv.signature(), inv.has_receiver(), false); | |
248 } | |
249 | |
250 if (has_return()) { | |
251 assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?"); | |
252 _ret.post_initialize(); | |
253 } | |
254 } | |
255 | |
256 void VirtualCallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) { | |
257 assert(Bytecodes::is_invoke(stream->code()), "should be invoke"); | |
258 Bytecode_invoke inv(stream->method(), stream->bci()); | |
259 | |
260 if (has_arguments()) { | |
261 #ifdef ASSERT | |
262 ResourceMark rm; | |
263 SignatureStream ss(inv.signature()); | |
264 int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit); | |
265 assert(count > 0, "room for args type but none found?"); | |
266 check_number_of_arguments(count); | |
267 #endif | |
268 _args.post_initialize(inv.signature(), inv.has_receiver(), false); | |
269 } | |
270 | |
271 if (has_return()) { | |
272 assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?"); | |
273 _ret.post_initialize(); | |
274 } | |
275 } | |
276 | |
277 bool TypeEntries::is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p) { | |
278 Klass* k = (Klass*)klass_part(p); | |
279 return k != NULL && k->is_loader_alive(is_alive_cl); | |
280 } | |
281 | |
282 void TypeStackSlotEntries::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) { | |
283 for (int i = 0; i < _number_of_entries; i++) { | |
284 intptr_t p = type(i); | |
285 if (!is_loader_alive(is_alive_cl, p)) { | |
286 set_type(i, with_status((Klass*)NULL, p)); | |
287 } | |
288 } | |
289 } | |
290 | |
291 void ReturnTypeEntry::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) { | |
292 intptr_t p = type(); | |
293 if (!is_loader_alive(is_alive_cl, p)) { | |
294 set_type(with_status((Klass*)NULL, p)); | |
295 } | |
296 } | |
297 | |
298 bool TypeEntriesAtCall::return_profiling_enabled() { | |
299 return MethodData::profile_return(); | |
300 } | |
301 | |
302 bool TypeEntriesAtCall::arguments_profiling_enabled() { | |
303 return MethodData::profile_arguments(); | |
304 } | |
305 | |
306 #ifndef PRODUCT | |
307 void TypeEntries::print_klass(outputStream* st, intptr_t k) { | |
308 if (is_type_none(k)) { | |
309 st->print("none"); | |
310 } else if (is_type_unknown(k)) { | |
311 st->print("unknown"); | |
312 } else { | |
313 valid_klass(k)->print_value_on(st); | |
314 } | |
315 if (was_null_seen(k)) { | |
316 st->print(" (null seen)"); | |
317 } | |
318 } | |
319 | |
320 void TypeStackSlotEntries::print_data_on(outputStream* st) const { | |
321 for (int i = 0; i < _number_of_entries; i++) { | |
322 _pd->tab(st); | |
323 st->print("%d: stack(%u) ", i, stack_slot(i)); | |
324 print_klass(st, type(i)); | |
325 st->cr(); | |
326 } | |
327 } | |
328 | |
329 void ReturnTypeEntry::print_data_on(outputStream* st) const { | |
330 _pd->tab(st); | |
331 print_klass(st, type()); | |
332 st->cr(); | |
333 } | |
334 | |
335 void CallTypeData::print_data_on(outputStream* st) const { | |
336 CounterData::print_data_on(st); | |
337 if (has_arguments()) { | |
338 tab(st, true); | |
339 st->print("argument types"); | |
340 _args.print_data_on(st); | |
341 } | |
342 if (has_return()) { | |
343 tab(st, true); | |
344 st->print("return type"); | |
345 _ret.print_data_on(st); | |
346 } | |
347 } | |
348 | |
349 void VirtualCallTypeData::print_data_on(outputStream* st) const { | |
350 VirtualCallData::print_data_on(st); | |
351 if (has_arguments()) { | |
352 tab(st, true); | |
353 st->print("argument types"); | |
354 _args.print_data_on(st); | |
355 } | |
356 if (has_return()) { | |
357 tab(st, true); | |
358 st->print("return type"); | |
359 _ret.print_data_on(st); | |
360 } | |
361 } | |
362 #endif | |
153 | 363 |
154 // ================================================================== | 364 // ================================================================== |
155 // ReceiverTypeData | 365 // ReceiverTypeData |
156 // | 366 // |
157 // A ReceiverTypeData is used to access profiling information about a | 367 // A ReceiverTypeData is used to access profiling information about a |
179 } | 389 } |
180 } | 390 } |
181 #endif // GRAAL | 391 #endif // GRAAL |
182 | 392 |
183 #ifndef PRODUCT | 393 #ifndef PRODUCT |
184 void ReceiverTypeData::print_receiver_data_on(outputStream* st) { | 394 void ReceiverTypeData::print_receiver_data_on(outputStream* st) const { |
185 uint row; | 395 uint row; |
186 int entries = 0; | 396 int entries = 0; |
187 for (row = 0; row < row_limit(); row++) { | 397 for (row = 0; row < row_limit(); row++) { |
188 if (receiver(row) != NULL) entries++; | 398 if (receiver(row) != NULL) entries++; |
189 } | 399 } |
200 receiver(row)->print_value_on(st); | 410 receiver(row)->print_value_on(st); |
201 st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total); | 411 st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total); |
202 } | 412 } |
203 } | 413 } |
204 } | 414 } |
205 void ReceiverTypeData::print_data_on(outputStream* st) { | 415 void ReceiverTypeData::print_data_on(outputStream* st) const { |
206 print_shared(st, "ReceiverTypeData"); | 416 print_shared(st, "ReceiverTypeData"); |
207 print_receiver_data_on(st); | 417 print_receiver_data_on(st); |
208 } | 418 } |
209 void VirtualCallData::print_data_on(outputStream* st) { | 419 void VirtualCallData::print_data_on(outputStream* st) const { |
210 print_shared(st, "VirtualCallData"); | 420 print_shared(st, "VirtualCallData"); |
211 print_receiver_data_on(st); | 421 print_receiver_data_on(st); |
212 } | 422 } |
213 #endif // !PRODUCT | 423 #endif // !PRODUCT |
214 | 424 |
256 return mdp; | 466 return mdp; |
257 } | 467 } |
258 | 468 |
259 | 469 |
260 #ifndef PRODUCT | 470 #ifndef PRODUCT |
261 void RetData::print_data_on(outputStream* st) { | 471 void RetData::print_data_on(outputStream* st) const { |
262 print_shared(st, "RetData"); | 472 print_shared(st, "RetData"); |
263 uint row; | 473 uint row; |
264 int entries = 0; | 474 int entries = 0; |
265 for (row = 0; row < row_limit(); row++) { | 475 for (row = 0; row < row_limit(); row++) { |
266 if (bci(row) != no_bci) entries++; | 476 if (bci(row) != no_bci) entries++; |
291 int offset = target_di - my_di; | 501 int offset = target_di - my_di; |
292 set_displacement(offset); | 502 set_displacement(offset); |
293 } | 503 } |
294 | 504 |
295 #ifndef PRODUCT | 505 #ifndef PRODUCT |
296 void BranchData::print_data_on(outputStream* st) { | 506 void BranchData::print_data_on(outputStream* st) const { |
297 print_shared(st, "BranchData"); | 507 print_shared(st, "BranchData"); |
298 st->print_cr("taken(%u) displacement(%d)", | 508 st->print_cr("taken(%u) displacement(%d)", |
299 taken(), displacement()); | 509 taken(), displacement()); |
300 tab(st); | 510 tab(st); |
301 st->print_cr("not taken(%u)", not_taken()); | 511 st->print_cr("not taken(%u)", not_taken()); |
365 set_default_displacement(offset); | 575 set_default_displacement(offset); |
366 } | 576 } |
367 } | 577 } |
368 | 578 |
369 #ifndef PRODUCT | 579 #ifndef PRODUCT |
370 void MultiBranchData::print_data_on(outputStream* st) { | 580 void MultiBranchData::print_data_on(outputStream* st) const { |
371 print_shared(st, "MultiBranchData"); | 581 print_shared(st, "MultiBranchData"); |
372 st->print_cr("default_count(%u) displacement(%d)", | 582 st->print_cr("default_count(%u) displacement(%d)", |
373 default_count(), default_displacement()); | 583 default_count(), default_displacement()); |
374 int cases = number_of_cases(); | 584 int cases = number_of_cases(); |
375 for (int i = 0; i < cases; i++) { | 585 for (int i = 0; i < cases; i++) { |
379 } | 589 } |
380 } | 590 } |
381 #endif | 591 #endif |
382 | 592 |
383 #ifndef PRODUCT | 593 #ifndef PRODUCT |
384 void ArgInfoData::print_data_on(outputStream* st) { | 594 void ArgInfoData::print_data_on(outputStream* st) const { |
385 print_shared(st, "ArgInfoData"); | 595 print_shared(st, "ArgInfoData"); |
386 int nargs = number_of_args(); | 596 int nargs = number_of_args(); |
387 for (int i = 0; i < nargs; i++) { | 597 for (int i = 0; i < nargs; i++) { |
388 st->print(" 0x%x", arg_modified(i)); | 598 st->print(" 0x%x", arg_modified(i)); |
389 } | 599 } |
390 st->cr(); | 600 st->cr(); |
391 } | 601 } |
392 | 602 |
393 #endif | 603 #endif |
604 | |
605 int ParametersTypeData::compute_cell_count(Method* m) { | |
606 if (!MethodData::profile_parameters_for_method(m)) { | |
607 return 0; | |
608 } | |
609 int max = TypeProfileParmsLimit == -1 ? INT_MAX : TypeProfileParmsLimit; | |
610 int obj_args = TypeStackSlotEntries::compute_cell_count(m->signature(), !m->is_static(), max); | |
611 if (obj_args > 0) { | |
612 return obj_args + 1; // 1 cell for array len | |
613 } | |
614 return 0; | |
615 } | |
616 | |
617 void ParametersTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) { | |
618 _parameters.post_initialize(mdo->method()->signature(), !mdo->method()->is_static(), true); | |
619 } | |
620 | |
621 bool ParametersTypeData::profiling_enabled() { | |
622 return MethodData::profile_parameters(); | |
623 } | |
624 | |
625 #ifndef PRODUCT | |
626 void ParametersTypeData::print_data_on(outputStream* st) const { | |
627 st->print("parameter types"); | |
628 _parameters.print_data_on(st); | |
629 } | |
630 #endif | |
631 | |
394 // ================================================================== | 632 // ================================================================== |
395 // MethodData* | 633 // MethodData* |
396 // | 634 // |
397 // A MethodData* holds information which has been collected about | 635 // A MethodData* holds information which has been collected about |
398 // a method. | 636 // a method. |
417 } else { | 655 } else { |
418 return BitData::static_cell_count(); | 656 return BitData::static_cell_count(); |
419 } | 657 } |
420 case Bytecodes::_invokespecial: | 658 case Bytecodes::_invokespecial: |
421 case Bytecodes::_invokestatic: | 659 case Bytecodes::_invokestatic: |
422 return CounterData::static_cell_count(); | 660 if (MethodData::profile_arguments() || MethodData::profile_return()) { |
661 return variable_cell_count; | |
662 } else { | |
663 return CounterData::static_cell_count(); | |
664 } | |
423 case Bytecodes::_goto: | 665 case Bytecodes::_goto: |
424 case Bytecodes::_goto_w: | 666 case Bytecodes::_goto_w: |
425 case Bytecodes::_jsr: | 667 case Bytecodes::_jsr: |
426 case Bytecodes::_jsr_w: | 668 case Bytecodes::_jsr_w: |
427 return JumpData::static_cell_count(); | 669 return JumpData::static_cell_count(); |
428 case Bytecodes::_invokevirtual: | 670 case Bytecodes::_invokevirtual: |
429 case Bytecodes::_invokeinterface: | 671 case Bytecodes::_invokeinterface: |
430 return VirtualCallData::static_cell_count(); | 672 if (MethodData::profile_arguments() || MethodData::profile_return()) { |
673 return variable_cell_count; | |
674 } else { | |
675 return VirtualCallData::static_cell_count(); | |
676 } | |
431 case Bytecodes::_invokedynamic: | 677 case Bytecodes::_invokedynamic: |
432 return CounterData::static_cell_count(); | 678 if (MethodData::profile_arguments() || MethodData::profile_return()) { |
679 return variable_cell_count; | |
680 } else { | |
681 return CounterData::static_cell_count(); | |
682 } | |
433 case Bytecodes::_ret: | 683 case Bytecodes::_ret: |
434 return RetData::static_cell_count(); | 684 return RetData::static_cell_count(); |
435 case Bytecodes::_ifeq: | 685 case Bytecodes::_ifeq: |
436 case Bytecodes::_ifne: | 686 case Bytecodes::_ifne: |
437 case Bytecodes::_iflt: | 687 case Bytecodes::_iflt: |
463 int cell_count = bytecode_cell_count(stream->code()); | 713 int cell_count = bytecode_cell_count(stream->code()); |
464 if (cell_count == no_profile_data) { | 714 if (cell_count == no_profile_data) { |
465 return 0; | 715 return 0; |
466 } | 716 } |
467 if (cell_count == variable_cell_count) { | 717 if (cell_count == variable_cell_count) { |
468 cell_count = MultiBranchData::compute_cell_count(stream); | 718 switch (stream->code()) { |
719 case Bytecodes::_lookupswitch: | |
720 case Bytecodes::_tableswitch: | |
721 cell_count = MultiBranchData::compute_cell_count(stream); | |
722 break; | |
723 case Bytecodes::_invokespecial: | |
724 case Bytecodes::_invokestatic: | |
725 case Bytecodes::_invokedynamic: | |
726 assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile"); | |
727 if (profile_arguments_for_invoke(stream->method(), stream->bci()) || | |
728 profile_return_for_invoke(stream->method(), stream->bci())) { | |
729 cell_count = CallTypeData::compute_cell_count(stream); | |
730 } else { | |
731 cell_count = CounterData::static_cell_count(); | |
732 } | |
733 break; | |
734 case Bytecodes::_invokevirtual: | |
735 case Bytecodes::_invokeinterface: { | |
736 assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile"); | |
737 if (profile_arguments_for_invoke(stream->method(), stream->bci()) || | |
738 profile_return_for_invoke(stream->method(), stream->bci())) { | |
739 cell_count = VirtualCallTypeData::compute_cell_count(stream); | |
740 } else { | |
741 cell_count = VirtualCallData::static_cell_count(); | |
742 } | |
743 break; | |
744 } | |
745 default: | |
746 fatal("unexpected bytecode for var length profile data"); | |
747 } | |
469 } | 748 } |
470 // Note: cell_count might be zero, meaning that there is just | 749 // Note: cell_count might be zero, meaning that there is just |
471 // a DataLayout header, with no extra cells. | 750 // a DataLayout header, with no extra cells. |
472 assert(cell_count >= 0, "sanity"); | 751 assert(cell_count >= 0, "sanity"); |
473 return DataLayout::compute_size_in_bytes(cell_count); | 752 return DataLayout::compute_size_in_bytes(cell_count); |
520 | 799 |
521 #ifndef GRAALVM | 800 #ifndef GRAALVM |
522 // Add a cell to record information about modified arguments. | 801 // Add a cell to record information about modified arguments. |
523 int arg_size = method->size_of_parameters(); | 802 int arg_size = method->size_of_parameters(); |
524 object_size += DataLayout::compute_size_in_bytes(arg_size+1); | 803 object_size += DataLayout::compute_size_in_bytes(arg_size+1); |
804 | |
805 // Reserve room for an area of the MDO dedicated to profiling of | |
806 // parameters | |
807 int args_cell = ParametersTypeData::compute_cell_count(method()); | |
808 if (args_cell > 0) { | |
809 object_size += DataLayout::compute_size_in_bytes(args_cell); | |
810 } | |
525 #endif | 811 #endif |
526 return object_size; | 812 return object_size; |
527 } | 813 } |
528 | 814 |
529 // Compute the size of the MethodData* necessary to store | 815 // Compute the size of the MethodData* necessary to store |
556 cell_count = BitData::static_cell_count(); | 842 cell_count = BitData::static_cell_count(); |
557 tag = DataLayout::bit_data_tag; | 843 tag = DataLayout::bit_data_tag; |
558 } | 844 } |
559 break; | 845 break; |
560 case Bytecodes::_invokespecial: | 846 case Bytecodes::_invokespecial: |
561 case Bytecodes::_invokestatic: | 847 case Bytecodes::_invokestatic: { |
562 cell_count = CounterData::static_cell_count(); | 848 int counter_data_cell_count = CounterData::static_cell_count(); |
563 tag = DataLayout::counter_data_tag; | 849 if (profile_arguments_for_invoke(stream->method(), stream->bci()) || |
850 profile_return_for_invoke(stream->method(), stream->bci())) { | |
851 cell_count = CallTypeData::compute_cell_count(stream); | |
852 } else { | |
853 cell_count = counter_data_cell_count; | |
854 } | |
855 if (cell_count > counter_data_cell_count) { | |
856 tag = DataLayout::call_type_data_tag; | |
857 } else { | |
858 tag = DataLayout::counter_data_tag; | |
859 } | |
564 break; | 860 break; |
861 } | |
565 case Bytecodes::_goto: | 862 case Bytecodes::_goto: |
566 case Bytecodes::_goto_w: | 863 case Bytecodes::_goto_w: |
567 case Bytecodes::_jsr: | 864 case Bytecodes::_jsr: |
568 case Bytecodes::_jsr_w: | 865 case Bytecodes::_jsr_w: |
569 cell_count = JumpData::static_cell_count(); | 866 cell_count = JumpData::static_cell_count(); |
570 tag = DataLayout::jump_data_tag; | 867 tag = DataLayout::jump_data_tag; |
571 break; | 868 break; |
572 case Bytecodes::_invokevirtual: | 869 case Bytecodes::_invokevirtual: |
573 case Bytecodes::_invokeinterface: | 870 case Bytecodes::_invokeinterface: { |
574 cell_count = VirtualCallData::static_cell_count(); | 871 int virtual_call_data_cell_count = VirtualCallData::static_cell_count(); |
575 tag = DataLayout::virtual_call_data_tag; | 872 if (profile_arguments_for_invoke(stream->method(), stream->bci()) || |
873 profile_return_for_invoke(stream->method(), stream->bci())) { | |
874 cell_count = VirtualCallTypeData::compute_cell_count(stream); | |
875 } else { | |
876 cell_count = virtual_call_data_cell_count; | |
877 } | |
878 if (cell_count > virtual_call_data_cell_count) { | |
879 tag = DataLayout::virtual_call_type_data_tag; | |
880 } else { | |
881 tag = DataLayout::virtual_call_data_tag; | |
882 } | |
576 break; | 883 break; |
577 case Bytecodes::_invokedynamic: | 884 } |
885 case Bytecodes::_invokedynamic: { | |
578 // %%% should make a type profile for any invokedynamic that takes a ref argument | 886 // %%% should make a type profile for any invokedynamic that takes a ref argument |
579 cell_count = CounterData::static_cell_count(); | 887 int counter_data_cell_count = CounterData::static_cell_count(); |
580 tag = DataLayout::counter_data_tag; | 888 if (profile_arguments_for_invoke(stream->method(), stream->bci()) || |
889 profile_return_for_invoke(stream->method(), stream->bci())) { | |
890 cell_count = CallTypeData::compute_cell_count(stream); | |
891 } else { | |
892 cell_count = counter_data_cell_count; | |
893 } | |
894 if (cell_count > counter_data_cell_count) { | |
895 tag = DataLayout::call_type_data_tag; | |
896 } else { | |
897 tag = DataLayout::counter_data_tag; | |
898 } | |
581 break; | 899 break; |
900 } | |
582 case Bytecodes::_ret: | 901 case Bytecodes::_ret: |
583 cell_count = RetData::static_cell_count(); | 902 cell_count = RetData::static_cell_count(); |
584 tag = DataLayout::ret_data_tag; | 903 tag = DataLayout::ret_data_tag; |
585 break; | 904 break; |
586 case Bytecodes::_ifeq: | 905 case Bytecodes::_ifeq: |
607 cell_count = MultiBranchData::compute_cell_count(stream); | 926 cell_count = MultiBranchData::compute_cell_count(stream); |
608 tag = DataLayout::multi_branch_data_tag; | 927 tag = DataLayout::multi_branch_data_tag; |
609 break; | 928 break; |
610 } | 929 } |
611 assert(tag == DataLayout::multi_branch_data_tag || | 930 assert(tag == DataLayout::multi_branch_data_tag || |
931 ((MethodData::profile_arguments() || MethodData::profile_return()) && | |
932 (tag == DataLayout::call_type_data_tag || | |
933 tag == DataLayout::counter_data_tag || | |
934 tag == DataLayout::virtual_call_type_data_tag || | |
935 tag == DataLayout::virtual_call_data_tag)) || | |
612 cell_count == bytecode_cell_count(c), "cell counts must agree"); | 936 cell_count == bytecode_cell_count(c), "cell counts must agree"); |
613 if (cell_count >= 0) { | 937 if (cell_count >= 0) { |
614 assert(tag != DataLayout::no_tag, "bad tag"); | 938 assert(tag != DataLayout::no_tag, "bad tag"); |
615 assert(bytecode_has_profile(c), "agree w/ BHP"); | 939 assert(bytecode_has_profile(c), "agree w/ BHP"); |
616 data_layout->initialize(tag, stream->bci(), cell_count); | 940 data_layout->initialize(tag, stream->bci(), cell_count); |
653 return new BranchData(this); | 977 return new BranchData(this); |
654 case DataLayout::multi_branch_data_tag: | 978 case DataLayout::multi_branch_data_tag: |
655 return new MultiBranchData(this); | 979 return new MultiBranchData(this); |
656 case DataLayout::arg_info_data_tag: | 980 case DataLayout::arg_info_data_tag: |
657 return new ArgInfoData(this); | 981 return new ArgInfoData(this); |
982 case DataLayout::call_type_data_tag: | |
983 return new CallTypeData(this); | |
984 case DataLayout::virtual_call_type_data_tag: | |
985 return new VirtualCallTypeData(this); | |
986 case DataLayout::parameters_type_data_tag: | |
987 return new ParametersTypeData(this); | |
658 }; | 988 }; |
659 } | 989 } |
660 | 990 |
661 // Iteration over data. | 991 // Iteration over data. |
662 ProfileData* MethodData::next_data(ProfileData* current) const { | 992 ProfileData* MethodData::next_data(ProfileData* current) const { |
673 ProfileData* data; | 1003 ProfileData* data; |
674 for (data = first_data(); is_valid(data); data = next_data(data)) { | 1004 for (data = first_data(); is_valid(data); data = next_data(data)) { |
675 stream->set_start(data->bci()); | 1005 stream->set_start(data->bci()); |
676 stream->next(); | 1006 stream->next(); |
677 data->post_initialize(stream, this); | 1007 data->post_initialize(stream, this); |
1008 } | |
1009 if (_parameters_type_data_di != -1) { | |
1010 parameters_type_data()->post_initialize(NULL, this); | |
678 } | 1011 } |
679 } | 1012 } |
680 | 1013 |
681 // Initialize the MethodData* corresponding to a given method. | 1014 // Initialize the MethodData* corresponding to a given method. |
682 MethodData::MethodData(methodHandle method, int size, TRAPS) { | 1015 MethodData::MethodData(methodHandle method, int size, TRAPS) { |
722 DataLayout *dp = data_layout_at(data_size + extra_size); | 1055 DataLayout *dp = data_layout_at(data_size + extra_size); |
723 | 1056 |
724 int arg_size = method()->size_of_parameters(); | 1057 int arg_size = method()->size_of_parameters(); |
725 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); | 1058 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); |
726 | 1059 |
727 object_size += DataLayout::compute_size_in_bytes(arg_size+1); | 1060 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1); |
1061 object_size += extra_size + arg_data_size; | |
1062 | |
1063 int args_cell = ParametersTypeData::compute_cell_count(method()); | |
1064 // If we are profiling parameters, we reserver an area near the end | |
1065 // of the MDO after the slots for bytecodes (because there's no bci | |
1066 // for method entry so they don't fit with the framework for the | |
1067 // profiling of bytecodes). We store the offset within the MDO of | |
1068 // this area (or -1 if no parameter is profiled) | |
1069 if (args_cell > 0) { | |
1070 object_size += DataLayout::compute_size_in_bytes(args_cell); | |
1071 _parameters_type_data_di = data_size + extra_size + arg_data_size; | |
1072 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size); | |
1073 dp->initialize(DataLayout::parameters_type_data_tag, 0, args_cell); | |
1074 } else { | |
1075 _parameters_type_data_di = -1; | |
1076 } | |
728 #endif | 1077 #endif |
729 | 1078 |
730 // Set an initial hint. Don't use set_hint_di() because | 1079 // Set an initial hint. Don't use set_hint_di() because |
731 // first_di() may be out of bounds if data_size is 0. | 1080 // first_di() may be out of bounds if data_size is 0. |
732 // In that situation, _hint_di is never used, but at | 1081 // In that situation, _hint_di is never used, but at |
890 | 1239 |
891 #ifndef PRODUCT | 1240 #ifndef PRODUCT |
892 void MethodData::print_data_on(outputStream* st) const { | 1241 void MethodData::print_data_on(outputStream* st) const { |
893 ResourceMark rm; | 1242 ResourceMark rm; |
894 ProfileData* data = first_data(); | 1243 ProfileData* data = first_data(); |
1244 if (_parameters_type_data_di != -1) { | |
1245 parameters_type_data()->print_data_on(st); | |
1246 } | |
895 for ( ; is_valid(data); data = next_data(data)) { | 1247 for ( ; is_valid(data); data = next_data(data)) { |
896 st->print("%d", dp_to_di(data->dp())); | 1248 st->print("%d", dp_to_di(data->dp())); |
897 st->fill_to(6); | 1249 st->fill_to(6); |
898 data->print_data_on(st); | 1250 data->print_data_on(st); |
899 } | 1251 } |
938 | 1290 |
939 void MethodData::verify_data_on(outputStream* st) { | 1291 void MethodData::verify_data_on(outputStream* st) { |
940 NEEDS_CLEANUP; | 1292 NEEDS_CLEANUP; |
941 // not yet implemented. | 1293 // not yet implemented. |
942 } | 1294 } |
1295 | |
1296 bool MethodData::profile_jsr292(methodHandle m, int bci) { | |
1297 if (m->is_compiled_lambda_form()) { | |
1298 return true; | |
1299 } | |
1300 | |
1301 Bytecode_invoke inv(m , bci); | |
1302 return inv.is_invokedynamic() || inv.is_invokehandle(); | |
1303 } | |
1304 | |
1305 int MethodData::profile_arguments_flag() { | |
1306 return TypeProfileLevel % 10; | |
1307 } | |
1308 | |
1309 bool MethodData::profile_arguments() { | |
1310 return profile_arguments_flag() > no_type_profile && profile_arguments_flag() <= type_profile_all; | |
1311 } | |
1312 | |
1313 bool MethodData::profile_arguments_jsr292_only() { | |
1314 return profile_arguments_flag() == type_profile_jsr292; | |
1315 } | |
1316 | |
1317 bool MethodData::profile_all_arguments() { | |
1318 return profile_arguments_flag() == type_profile_all; | |
1319 } | |
1320 | |
1321 bool MethodData::profile_arguments_for_invoke(methodHandle m, int bci) { | |
1322 if (!profile_arguments()) { | |
1323 return false; | |
1324 } | |
1325 | |
1326 if (profile_all_arguments()) { | |
1327 return true; | |
1328 } | |
1329 | |
1330 assert(profile_arguments_jsr292_only(), "inconsistent"); | |
1331 return profile_jsr292(m, bci); | |
1332 } | |
1333 | |
1334 int MethodData::profile_return_flag() { | |
1335 return (TypeProfileLevel % 100) / 10; | |
1336 } | |
1337 | |
1338 bool MethodData::profile_return() { | |
1339 return profile_return_flag() > no_type_profile && profile_return_flag() <= type_profile_all; | |
1340 } | |
1341 | |
1342 bool MethodData::profile_return_jsr292_only() { | |
1343 return profile_return_flag() == type_profile_jsr292; | |
1344 } | |
1345 | |
1346 bool MethodData::profile_all_return() { | |
1347 return profile_return_flag() == type_profile_all; | |
1348 } | |
1349 | |
1350 bool MethodData::profile_return_for_invoke(methodHandle m, int bci) { | |
1351 if (!profile_return()) { | |
1352 return false; | |
1353 } | |
1354 | |
1355 if (profile_all_return()) { | |
1356 return true; | |
1357 } | |
1358 | |
1359 assert(profile_return_jsr292_only(), "inconsistent"); | |
1360 return profile_jsr292(m, bci); | |
1361 } | |
1362 | |
1363 int MethodData::profile_parameters_flag() { | |
1364 return TypeProfileLevel / 100; | |
1365 } | |
1366 | |
1367 bool MethodData::profile_parameters() { | |
1368 return profile_parameters_flag() > no_type_profile && profile_parameters_flag() <= type_profile_all; | |
1369 } | |
1370 | |
1371 bool MethodData::profile_parameters_jsr292_only() { | |
1372 return profile_parameters_flag() == type_profile_jsr292; | |
1373 } | |
1374 | |
1375 bool MethodData::profile_all_parameters() { | |
1376 return profile_parameters_flag() == type_profile_all; | |
1377 } | |
1378 | |
1379 bool MethodData::profile_parameters_for_method(methodHandle m) { | |
1380 if (!profile_parameters()) { | |
1381 return false; | |
1382 } | |
1383 | |
1384 if (profile_all_parameters()) { | |
1385 return true; | |
1386 } | |
1387 | |
1388 assert(profile_parameters_jsr292_only(), "inconsistent"); | |
1389 return m->is_compiled_lambda_form(); | |
1390 } |