39 //
40 // Overlay for generic profiling data.
41
42 // Some types of data layouts need a length field.
43 bool DataLayout::needs_array_len(u1 tag) {
44 return (tag == multi_branch_data_tag) || (tag == arg_info_data_tag);
45 }
46
47 // Perform generic initialization of the data. More specific
48 // initialization occurs in overrides of ProfileData::post_initialize.
49 void DataLayout::initialize(u1 tag, u2 bci, int cell_count) {
50 _header._bits = (intptr_t)0;
51 _header._struct._tag = tag;
52 _header._struct._bci = bci;
53 for (int i = 0; i < cell_count; i++) {
54 set_cell_at(i, (intptr_t)0);
55 }
56 if (needs_array_len(tag)) {
57 set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header.
58 }
59 }
60
61 void DataLayout::clean_weak_klass_links(BoolObjectClosure* cl) {
62 ResourceMark m;
63 data_in()->clean_weak_klass_links(cl);
64 }
65
66
67 // ==================================================================
68 // ProfileData
69 //
70 // A ProfileData object is created to refer to a section of profiling
71 // data in a structured way.
72
73 // Constructor for invalid ProfileData.
74 ProfileData::ProfileData() {
75 _data = NULL;
76 }
77
78 #ifndef PRODUCT
79 void ProfileData::print_shared(outputStream* st, const char* name) {
80 st->print("bci: %d", bci());
81 st->fill_to(tab_width_one);
82 st->print("%s", name);
83 tab(st);
84 int trap = trap_state();
85 if (trap != 0) {
86 char buf[100];
87 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
88 }
89 int flags = data()->flags();
90 if (flags != 0)
91 st->print("flags(%d) ", flags);
92 }
93
94 void ProfileData::tab(outputStream* st) {
95 st->fill_to(tab_width_two);
96 }
97 #endif // !PRODUCT
98
99 // ==================================================================
100 // BitData
101 //
102 // A BitData corresponds to a one-bit flag. This is used to indicate
103 // whether a checkcast bytecode has seen a null value.
104
105
106 #ifndef PRODUCT
107 void BitData::print_data_on(outputStream* st) {
108 print_shared(st, "BitData");
109 }
110 #endif // !PRODUCT
111
112 // ==================================================================
113 // CounterData
114 //
115 // A CounterData corresponds to a simple counter.
116
117 #ifndef PRODUCT
118 void CounterData::print_data_on(outputStream* st) {
119 print_shared(st, "CounterData");
120 st->print_cr("count(%u)", count());
121 }
122 #endif // !PRODUCT
123
124 // ==================================================================
125 // JumpData
126 //
127 // A JumpData is used to access profiling information for a direct
128 // branch. It is a counter, used for counting the number of branches,
129 // plus a data displacement, used for realigning the data pointer to
130 // the corresponding target bci.
131
132 void JumpData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
133 assert(stream->bci() == bci(), "wrong pos");
134 int target;
135 Bytecodes::Code c = stream->code();
136 if (c == Bytecodes::_goto_w || c == Bytecodes::_jsr_w) {
137 target = stream->dest_w();
138 } else {
139 target = stream->dest();
140 }
141 int my_di = mdo->dp_to_di(dp());
142 int target_di = mdo->bci_to_di(target);
143 int offset = target_di - my_di;
144 set_displacement(offset);
145 }
146
147 #ifndef PRODUCT
148 void JumpData::print_data_on(outputStream* st) {
149 print_shared(st, "JumpData");
150 st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
151 }
152 #endif // !PRODUCT
153
154 // ==================================================================
155 // ReceiverTypeData
156 //
157 // A ReceiverTypeData is used to access profiling information about a
158 // dynamic type check. It consists of a counter which counts the total times
159 // that the check is reached, and a series of (Klass*, count) pairs
160 // which are used to store a type profile for the receiver of the check.
161
162 void ReceiverTypeData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
163 for (uint row = 0; row < row_limit(); row++) {
164 Klass* p = receiver(row);
165 if (p != NULL && !p->is_loader_alive(is_alive_cl)) {
166 clear_row(row);
167 }
168 }
169 }
170
171 #ifndef PRODUCT
172 void ReceiverTypeData::print_receiver_data_on(outputStream* st) {
173 uint row;
174 int entries = 0;
175 for (row = 0; row < row_limit(); row++) {
176 if (receiver(row) != NULL) entries++;
177 }
178 st->print_cr("count(%u) entries(%u)", count(), entries);
179 int total = count();
180 for (row = 0; row < row_limit(); row++) {
181 if (receiver(row) != NULL) {
182 total += receiver_count(row);
183 }
184 }
185 for (row = 0; row < row_limit(); row++) {
186 if (receiver(row) != NULL) {
187 tab(st);
188 receiver(row)->print_value_on(st);
189 st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total);
190 }
191 }
192 }
193 void ReceiverTypeData::print_data_on(outputStream* st) {
194 print_shared(st, "ReceiverTypeData");
195 print_receiver_data_on(st);
196 }
197 void VirtualCallData::print_data_on(outputStream* st) {
198 print_shared(st, "VirtualCallData");
199 print_receiver_data_on(st);
200 }
201 #endif // !PRODUCT
202
203 // ==================================================================
204 // RetData
205 //
206 // A RetData is used to access profiling information for a ret bytecode.
207 // It is composed of a count of the number of times that the ret has
208 // been executed, followed by a series of triples of the form
209 // (bci, count, di) which count the number of times that some bci was the
210 // target of the ret and cache a corresponding displacement.
211
212 void RetData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
213 for (uint row = 0; row < row_limit(); row++) {
214 set_bci_displacement(row, -1);
215 set_bci(row, no_bci);
216 }
217 // release so other threads see a consistent state. bci is used as
229 address RetData::fixup_ret(int return_bci, MethodData* h_mdo) {
230 // First find the mdp which corresponds to the return bci.
231 address mdp = h_mdo->bci_to_dp(return_bci);
232
233 // Now check to see if any of the cache slots are open.
234 for (uint row = 0; row < row_limit(); row++) {
235 if (bci(row) == no_bci) {
236 set_bci_displacement(row, mdp - dp());
237 set_bci_count(row, DataLayout::counter_increment);
238 // Barrier to ensure displacement is written before the bci; allows
239 // the interpreter to read displacement without fear of race condition.
240 release_set_bci(row, return_bci);
241 break;
242 }
243 }
244 return mdp;
245 }
246
247
248 #ifndef PRODUCT
249 void RetData::print_data_on(outputStream* st) {
250 print_shared(st, "RetData");
251 uint row;
252 int entries = 0;
253 for (row = 0; row < row_limit(); row++) {
254 if (bci(row) != no_bci) entries++;
255 }
256 st->print_cr("count(%u) entries(%u)", count(), entries);
257 for (row = 0; row < row_limit(); row++) {
258 if (bci(row) != no_bci) {
259 tab(st);
260 st->print_cr("bci(%d: count(%u) displacement(%d))",
261 bci(row), bci_count(row), bci_displacement(row));
262 }
263 }
264 }
265 #endif // !PRODUCT
266
267 // ==================================================================
268 // BranchData
269 //
270 // A BranchData is used to access profiling data for a two-way branch.
271 // It consists of taken and not_taken counts as well as a data displacement
272 // for the taken case.
273
274 void BranchData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
275 assert(stream->bci() == bci(), "wrong pos");
276 int target = stream->dest();
277 int my_di = mdo->dp_to_di(dp());
278 int target_di = mdo->bci_to_di(target);
279 int offset = target_di - my_di;
280 set_displacement(offset);
281 }
282
283 #ifndef PRODUCT
284 void BranchData::print_data_on(outputStream* st) {
285 print_shared(st, "BranchData");
286 st->print_cr("taken(%u) displacement(%d)",
287 taken(), displacement());
288 tab(st);
289 st->print_cr("not taken(%u)", not_taken());
290 }
291 #endif
292
293 // ==================================================================
294 // MultiBranchData
295 //
296 // A MultiBranchData is used to access profiling information for
297 // a multi-way branch (*switch bytecodes). It consists of a series
298 // of (count, displacement) pairs, which count the number of times each
299 // case was taken and specify the data displacment for each branch target.
300
301 int MultiBranchData::compute_cell_count(BytecodeStream* stream) {
302 int cell_count = 0;
303 if (stream->code() == Bytecodes::_tableswitch) {
304 Bytecode_tableswitch sw(stream->method()(), stream->bcp());
338 Bytecode_lookupswitch sw(stream->method()(), stream->bcp());
339 int npairs = sw.number_of_pairs();
340 assert(array_len() == per_case_cell_count * (npairs + 1), "wrong len");
341 for (int count = 0; count < npairs; count++) {
342 LookupswitchPair pair = sw.pair_at(count);
343 target = pair.offset() + bci();
344 my_di = mdo->dp_to_di(dp());
345 target_di = mdo->bci_to_di(target);
346 offset = target_di - my_di;
347 set_displacement_at(count, offset);
348 }
349 target = sw.default_offset() + bci();
350 my_di = mdo->dp_to_di(dp());
351 target_di = mdo->bci_to_di(target);
352 offset = target_di - my_di;
353 set_default_displacement(offset);
354 }
355 }
356
357 #ifndef PRODUCT
358 void MultiBranchData::print_data_on(outputStream* st) {
359 print_shared(st, "MultiBranchData");
360 st->print_cr("default_count(%u) displacement(%d)",
361 default_count(), default_displacement());
362 int cases = number_of_cases();
363 for (int i = 0; i < cases; i++) {
364 tab(st);
365 st->print_cr("count(%u) displacement(%d)",
366 count_at(i), displacement_at(i));
367 }
368 }
369 #endif
370
371 #ifndef PRODUCT
372 void ArgInfoData::print_data_on(outputStream* st) {
373 print_shared(st, "ArgInfoData");
374 int nargs = number_of_args();
375 for (int i = 0; i < nargs; i++) {
376 st->print(" 0x%x", arg_modified(i));
377 }
378 st->cr();
379 }
380
381 #endif
382 // ==================================================================
383 // MethodData*
384 //
385 // A MethodData* holds information which has been collected about
386 // a method.
387
388 MethodData* MethodData::allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS) {
389 int size = MethodData::compute_allocation_size_in_words(method);
390
391 return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD)
392 MethodData(method(), size, CHECK_NULL);
393 }
394
395 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
396 #if defined(COMPILER1) && !defined(COMPILER2)
397 return no_profile_data;
398 #else
399 switch (code) {
400 case Bytecodes::_checkcast:
401 case Bytecodes::_instanceof:
402 case Bytecodes::_aastore:
403 if (TypeProfileCasts) {
404 return ReceiverTypeData::static_cell_count();
405 } else {
406 return BitData::static_cell_count();
407 }
408 case Bytecodes::_invokespecial:
409 case Bytecodes::_invokestatic:
410 return CounterData::static_cell_count();
411 case Bytecodes::_goto:
412 case Bytecodes::_goto_w:
413 case Bytecodes::_jsr:
414 case Bytecodes::_jsr_w:
415 return JumpData::static_cell_count();
416 case Bytecodes::_invokevirtual:
417 case Bytecodes::_invokeinterface:
418 return VirtualCallData::static_cell_count();
419 case Bytecodes::_invokedynamic:
420 return CounterData::static_cell_count();
421 case Bytecodes::_ret:
422 return RetData::static_cell_count();
423 case Bytecodes::_ifeq:
424 case Bytecodes::_ifne:
425 case Bytecodes::_iflt:
426 case Bytecodes::_ifge:
427 case Bytecodes::_ifgt:
428 case Bytecodes::_ifle:
429 case Bytecodes::_if_icmpeq:
430 case Bytecodes::_if_icmpne:
431 case Bytecodes::_if_icmplt:
432 case Bytecodes::_if_icmpge:
433 case Bytecodes::_if_icmpgt:
434 case Bytecodes::_if_icmple:
435 case Bytecodes::_if_acmpeq:
436 case Bytecodes::_if_acmpne:
437 case Bytecodes::_ifnull:
438 case Bytecodes::_ifnonnull:
439 return BranchData::static_cell_count();
440 case Bytecodes::_lookupswitch:
441 case Bytecodes::_tableswitch:
442 return variable_cell_count;
443 }
444 return no_profile_data;
445 #endif
446 }
447
448 // Compute the size of the profiling information corresponding to
449 // the current bytecode.
450 int MethodData::compute_data_size(BytecodeStream* stream) {
451 int cell_count = bytecode_cell_count(stream->code());
452 if (cell_count == no_profile_data) {
453 return 0;
454 }
455 if (cell_count == variable_cell_count) {
456 cell_count = MultiBranchData::compute_cell_count(stream);
457 }
458 // Note: cell_count might be zero, meaning that there is just
459 // a DataLayout header, with no extra cells.
460 assert(cell_count >= 0, "sanity");
461 return DataLayout::compute_size_in_bytes(cell_count);
462 }
463
464 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) {
465 if (ProfileTraps) {
466 // Assume that up to 3% of BCIs with no MDP will need to allocate one.
467 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;
468 // If the method is large, let the extra BCIs grow numerous (to ~1%).
469 int one_percent_of_data
470 = (uint)data_size / (DataLayout::header_size_in_bytes()*128);
471 if (extra_data_count < one_percent_of_data)
472 extra_data_count = one_percent_of_data;
473 if (extra_data_count > empty_bc_count)
474 extra_data_count = empty_bc_count; // no need for more
475 return extra_data_count;
476 } else {
482 // profiling information about a given method. Size is in bytes.
483 int MethodData::compute_allocation_size_in_bytes(methodHandle method) {
484 int data_size = 0;
485 BytecodeStream stream(method);
486 Bytecodes::Code c;
487 int empty_bc_count = 0; // number of bytecodes lacking data
488 while ((c = stream.next()) >= 0) {
489 int size_in_bytes = compute_data_size(&stream);
490 data_size += size_in_bytes;
491 if (size_in_bytes == 0) empty_bc_count += 1;
492 }
493 int object_size = in_bytes(data_offset()) + data_size;
494
495 // Add some extra DataLayout cells (at least one) to track stray traps.
496 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count);
497 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);
498
499 // Add a cell to record information about modified arguments.
500 int arg_size = method->size_of_parameters();
501 object_size += DataLayout::compute_size_in_bytes(arg_size+1);
502 return object_size;
503 }
504
505 // Compute the size of the MethodData* necessary to store
506 // profiling information about a given method. Size is in words
507 int MethodData::compute_allocation_size_in_words(methodHandle method) {
508 int byte_size = compute_allocation_size_in_bytes(method);
509 int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord;
510 return align_object_size(word_size);
511 }
512
513 // Initialize an individual data segment. Returns the size of
514 // the segment in bytes.
515 int MethodData::initialize_data(BytecodeStream* stream,
516 int data_index) {
517 #if defined(COMPILER1) && !defined(COMPILER2)
518 return 0;
519 #else
520 int cell_count = -1;
521 int tag = DataLayout::no_tag;
522 DataLayout* data_layout = data_layout_at(data_index);
523 Bytecodes::Code c = stream->code();
524 switch (c) {
525 case Bytecodes::_checkcast:
526 case Bytecodes::_instanceof:
527 case Bytecodes::_aastore:
528 if (TypeProfileCasts) {
529 cell_count = ReceiverTypeData::static_cell_count();
530 tag = DataLayout::receiver_type_data_tag;
531 } else {
532 cell_count = BitData::static_cell_count();
533 tag = DataLayout::bit_data_tag;
534 }
535 break;
536 case Bytecodes::_invokespecial:
537 case Bytecodes::_invokestatic:
538 cell_count = CounterData::static_cell_count();
539 tag = DataLayout::counter_data_tag;
540 break;
541 case Bytecodes::_goto:
542 case Bytecodes::_goto_w:
543 case Bytecodes::_jsr:
544 case Bytecodes::_jsr_w:
545 cell_count = JumpData::static_cell_count();
546 tag = DataLayout::jump_data_tag;
547 break;
548 case Bytecodes::_invokevirtual:
549 case Bytecodes::_invokeinterface:
550 cell_count = VirtualCallData::static_cell_count();
551 tag = DataLayout::virtual_call_data_tag;
552 break;
553 case Bytecodes::_invokedynamic:
554 // %%% should make a type profile for any invokedynamic that takes a ref argument
555 cell_count = CounterData::static_cell_count();
556 tag = DataLayout::counter_data_tag;
557 break;
558 case Bytecodes::_ret:
559 cell_count = RetData::static_cell_count();
560 tag = DataLayout::ret_data_tag;
561 break;
562 case Bytecodes::_ifeq:
563 case Bytecodes::_ifne:
564 case Bytecodes::_iflt:
565 case Bytecodes::_ifge:
566 case Bytecodes::_ifgt:
567 case Bytecodes::_ifle:
568 case Bytecodes::_if_icmpeq:
569 case Bytecodes::_if_icmpne:
570 case Bytecodes::_if_icmplt:
571 case Bytecodes::_if_icmpge:
572 case Bytecodes::_if_icmpgt:
573 case Bytecodes::_if_icmple:
574 case Bytecodes::_if_acmpeq:
575 case Bytecodes::_if_acmpne:
576 case Bytecodes::_ifnull:
577 case Bytecodes::_ifnonnull:
578 cell_count = BranchData::static_cell_count();
579 tag = DataLayout::branch_data_tag;
580 break;
581 case Bytecodes::_lookupswitch:
582 case Bytecodes::_tableswitch:
583 cell_count = MultiBranchData::compute_cell_count(stream);
584 tag = DataLayout::multi_branch_data_tag;
585 break;
586 }
587 assert(tag == DataLayout::multi_branch_data_tag ||
588 cell_count == bytecode_cell_count(c), "cell counts must agree");
589 if (cell_count >= 0) {
590 assert(tag != DataLayout::no_tag, "bad tag");
591 assert(bytecode_has_profile(c), "agree w/ BHP");
592 data_layout->initialize(tag, stream->bci(), cell_count);
593 return DataLayout::compute_size_in_bytes(cell_count);
594 } else {
595 assert(!bytecode_has_profile(c), "agree w/ !BHP");
596 return 0;
597 }
598 #endif
599 }
600
601 // Get the data at an arbitrary (sort of) data index.
602 ProfileData* MethodData::data_at(int data_index) const {
603 if (out_of_bounds(data_index)) {
604 return NULL;
605 }
606 DataLayout* data_layout = data_layout_at(data_index);
607 return data_layout->data_in();
614 ShouldNotReachHere();
615 return NULL;
616 case DataLayout::bit_data_tag:
617 return new BitData(this);
618 case DataLayout::counter_data_tag:
619 return new CounterData(this);
620 case DataLayout::jump_data_tag:
621 return new JumpData(this);
622 case DataLayout::receiver_type_data_tag:
623 return new ReceiverTypeData(this);
624 case DataLayout::virtual_call_data_tag:
625 return new VirtualCallData(this);
626 case DataLayout::ret_data_tag:
627 return new RetData(this);
628 case DataLayout::branch_data_tag:
629 return new BranchData(this);
630 case DataLayout::multi_branch_data_tag:
631 return new MultiBranchData(this);
632 case DataLayout::arg_info_data_tag:
633 return new ArgInfoData(this);
634 };
635 }
636
637 // Iteration over data.
638 ProfileData* MethodData::next_data(ProfileData* current) const {
639 int current_index = dp_to_di(current->dp());
640 int next_index = current_index + current->size_in_bytes();
641 ProfileData* next = data_at(next_index);
642 return next;
643 }
644
645 // Give each of the data entries a chance to perform specific
646 // data initialization.
647 void MethodData::post_initialize(BytecodeStream* stream) {
648 ResourceMark rm;
649 ProfileData* data;
650 for (data = first_data(); is_valid(data); data = next_data(data)) {
651 stream->set_start(data->bci());
652 stream->next();
653 data->post_initialize(stream, this);
881 void MethodData::collect_statistics(KlassSizeStats *sz) const {
882 int n = sz->count(this);
883 sz->_method_data_bytes += n;
884 sz->_method_all_bytes += n;
885 sz->_rw_bytes += n;
886 }
887 #endif // INCLUDE_SERVICES
888
889 // Verification
890
891 void MethodData::verify_on(outputStream* st) {
892 guarantee(is_methodData(), "object must be method data");
893 // guarantee(m->is_perm(), "should be in permspace");
894 this->verify_data_on(st);
895 }
896
897 void MethodData::verify_data_on(outputStream* st) {
898 NEEDS_CLEANUP;
899 // not yet implemented.
900 }
|
39 //
40 // Overlay for generic profiling data.
41
42 // Some types of data layouts need a length field.
43 bool DataLayout::needs_array_len(u1 tag) {
44 return (tag == multi_branch_data_tag) || (tag == arg_info_data_tag);
45 }
46
47 // Perform generic initialization of the data. More specific
48 // initialization occurs in overrides of ProfileData::post_initialize.
49 void DataLayout::initialize(u1 tag, u2 bci, int cell_count) {
50 _header._bits = (intptr_t)0;
51 _header._struct._tag = tag;
52 _header._struct._bci = bci;
53 for (int i = 0; i < cell_count; i++) {
54 set_cell_at(i, (intptr_t)0);
55 }
56 if (needs_array_len(tag)) {
57 set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header.
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 }
64 }
65
66 void DataLayout::clean_weak_klass_links(BoolObjectClosure* cl) {
67 ResourceMark m;
68 data_in()->clean_weak_klass_links(cl);
69 }
70
71
72 // ==================================================================
73 // ProfileData
74 //
75 // A ProfileData object is created to refer to a section of profiling
76 // data in a structured way.
77
78 // Constructor for invalid ProfileData.
79 ProfileData::ProfileData() {
80 _data = NULL;
81 }
82
83 #ifndef PRODUCT
84 void ProfileData::print_shared(outputStream* st, const char* name) const {
85 st->print("bci: %d", bci());
86 st->fill_to(tab_width_one);
87 st->print("%s", name);
88 tab(st);
89 int trap = trap_state();
90 if (trap != 0) {
91 char buf[100];
92 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
93 }
94 int flags = data()->flags();
95 if (flags != 0)
96 st->print("flags(%d) ", flags);
97 }
98
99 void ProfileData::tab(outputStream* st, bool first) const {
100 st->fill_to(first ? tab_width_one : tab_width_two);
101 }
102 #endif // !PRODUCT
103
104 // ==================================================================
105 // BitData
106 //
107 // A BitData corresponds to a one-bit flag. This is used to indicate
108 // whether a checkcast bytecode has seen a null value.
109
110
111 #ifndef PRODUCT
112 void BitData::print_data_on(outputStream* st) const {
113 print_shared(st, "BitData");
114 }
115 #endif // !PRODUCT
116
117 // ==================================================================
118 // CounterData
119 //
120 // A CounterData corresponds to a simple counter.
121
122 #ifndef PRODUCT
123 void CounterData::print_data_on(outputStream* st) const {
124 print_shared(st, "CounterData");
125 st->print_cr("count(%u)", count());
126 }
127 #endif // !PRODUCT
128
129 // ==================================================================
130 // JumpData
131 //
132 // A JumpData is used to access profiling information for a direct
133 // branch. It is a counter, used for counting the number of branches,
134 // plus a data displacement, used for realigning the data pointer to
135 // the corresponding target bci.
136
137 void JumpData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
138 assert(stream->bci() == bci(), "wrong pos");
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(), 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
294 #ifndef PRODUCT
295 void ReceiverTypeData::print_receiver_data_on(outputStream* st) const {
296 uint row;
297 int entries = 0;
298 for (row = 0; row < row_limit(); row++) {
299 if (receiver(row) != NULL) entries++;
300 }
301 st->print_cr("count(%u) entries(%u)", count(), entries);
302 int total = count();
303 for (row = 0; row < row_limit(); row++) {
304 if (receiver(row) != NULL) {
305 total += receiver_count(row);
306 }
307 }
308 for (row = 0; row < row_limit(); row++) {
309 if (receiver(row) != NULL) {
310 tab(st);
311 receiver(row)->print_value_on(st);
312 st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total);
313 }
314 }
315 }
316 void ReceiverTypeData::print_data_on(outputStream* st) const {
317 print_shared(st, "ReceiverTypeData");
318 print_receiver_data_on(st);
319 }
320 void VirtualCallData::print_data_on(outputStream* st) const {
321 print_shared(st, "VirtualCallData");
322 print_receiver_data_on(st);
323 }
324 #endif // !PRODUCT
325
326 // ==================================================================
327 // RetData
328 //
329 // A RetData is used to access profiling information for a ret bytecode.
330 // It is composed of a count of the number of times that the ret has
331 // been executed, followed by a series of triples of the form
332 // (bci, count, di) which count the number of times that some bci was the
333 // target of the ret and cache a corresponding displacement.
334
335 void RetData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
336 for (uint row = 0; row < row_limit(); row++) {
337 set_bci_displacement(row, -1);
338 set_bci(row, no_bci);
339 }
340 // release so other threads see a consistent state. bci is used as
352 address RetData::fixup_ret(int return_bci, MethodData* h_mdo) {
353 // First find the mdp which corresponds to the return bci.
354 address mdp = h_mdo->bci_to_dp(return_bci);
355
356 // Now check to see if any of the cache slots are open.
357 for (uint row = 0; row < row_limit(); row++) {
358 if (bci(row) == no_bci) {
359 set_bci_displacement(row, mdp - dp());
360 set_bci_count(row, DataLayout::counter_increment);
361 // Barrier to ensure displacement is written before the bci; allows
362 // the interpreter to read displacement without fear of race condition.
363 release_set_bci(row, return_bci);
364 break;
365 }
366 }
367 return mdp;
368 }
369
370
371 #ifndef PRODUCT
372 void RetData::print_data_on(outputStream* st) const {
373 print_shared(st, "RetData");
374 uint row;
375 int entries = 0;
376 for (row = 0; row < row_limit(); row++) {
377 if (bci(row) != no_bci) entries++;
378 }
379 st->print_cr("count(%u) entries(%u)", count(), entries);
380 for (row = 0; row < row_limit(); row++) {
381 if (bci(row) != no_bci) {
382 tab(st);
383 st->print_cr("bci(%d: count(%u) displacement(%d))",
384 bci(row), bci_count(row), bci_displacement(row));
385 }
386 }
387 }
388 #endif // !PRODUCT
389
390 // ==================================================================
391 // BranchData
392 //
393 // A BranchData is used to access profiling data for a two-way branch.
394 // It consists of taken and not_taken counts as well as a data displacement
395 // for the taken case.
396
397 void BranchData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
398 assert(stream->bci() == bci(), "wrong pos");
399 int target = stream->dest();
400 int my_di = mdo->dp_to_di(dp());
401 int target_di = mdo->bci_to_di(target);
402 int offset = target_di - my_di;
403 set_displacement(offset);
404 }
405
406 #ifndef PRODUCT
407 void BranchData::print_data_on(outputStream* st) const {
408 print_shared(st, "BranchData");
409 st->print_cr("taken(%u) displacement(%d)",
410 taken(), displacement());
411 tab(st);
412 st->print_cr("not taken(%u)", not_taken());
413 }
414 #endif
415
416 // ==================================================================
417 // MultiBranchData
418 //
419 // A MultiBranchData is used to access profiling information for
420 // a multi-way branch (*switch bytecodes). It consists of a series
421 // of (count, displacement) pairs, which count the number of times each
422 // case was taken and specify the data displacment for each branch target.
423
424 int MultiBranchData::compute_cell_count(BytecodeStream* stream) {
425 int cell_count = 0;
426 if (stream->code() == Bytecodes::_tableswitch) {
427 Bytecode_tableswitch sw(stream->method()(), stream->bcp());
461 Bytecode_lookupswitch sw(stream->method()(), stream->bcp());
462 int npairs = sw.number_of_pairs();
463 assert(array_len() == per_case_cell_count * (npairs + 1), "wrong len");
464 for (int count = 0; count < npairs; count++) {
465 LookupswitchPair pair = sw.pair_at(count);
466 target = pair.offset() + bci();
467 my_di = mdo->dp_to_di(dp());
468 target_di = mdo->bci_to_di(target);
469 offset = target_di - my_di;
470 set_displacement_at(count, offset);
471 }
472 target = sw.default_offset() + bci();
473 my_di = mdo->dp_to_di(dp());
474 target_di = mdo->bci_to_di(target);
475 offset = target_di - my_di;
476 set_default_displacement(offset);
477 }
478 }
479
480 #ifndef PRODUCT
481 void MultiBranchData::print_data_on(outputStream* st) const {
482 print_shared(st, "MultiBranchData");
483 st->print_cr("default_count(%u) displacement(%d)",
484 default_count(), default_displacement());
485 int cases = number_of_cases();
486 for (int i = 0; i < cases; i++) {
487 tab(st);
488 st->print_cr("count(%u) displacement(%d)",
489 count_at(i), displacement_at(i));
490 }
491 }
492 #endif
493
494 #ifndef PRODUCT
495 void ArgInfoData::print_data_on(outputStream* st) const {
496 print_shared(st, "ArgInfoData");
497 int nargs = number_of_args();
498 for (int i = 0; i < nargs; i++) {
499 st->print(" 0x%x", arg_modified(i));
500 }
501 st->cr();
502 }
503
504 #endif
505 // ==================================================================
506 // MethodData*
507 //
508 // A MethodData* holds information which has been collected about
509 // a method.
510
511 MethodData* MethodData::allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS) {
512 int size = MethodData::compute_allocation_size_in_words(method);
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:
572 case Bytecodes::_ifnull:
573 case Bytecodes::_ifnonnull:
574 return BranchData::static_cell_count();
575 case Bytecodes::_lookupswitch:
576 case Bytecodes::_tableswitch:
577 return variable_cell_count;
578 }
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;
630 // If the method is large, let the extra BCIs grow numerous (to ~1%).
631 int one_percent_of_data
632 = (uint)data_size / (DataLayout::header_size_in_bytes()*128);
633 if (extra_data_count < one_percent_of_data)
634 extra_data_count = one_percent_of_data;
635 if (extra_data_count > empty_bc_count)
636 extra_data_count = empty_bc_count; // no need for more
637 return extra_data_count;
638 } else {
644 // profiling information about a given method. Size is in bytes.
645 int MethodData::compute_allocation_size_in_bytes(methodHandle method) {
646 int data_size = 0;
647 BytecodeStream stream(method);
648 Bytecodes::Code c;
649 int empty_bc_count = 0; // number of bytecodes lacking data
650 while ((c = stream.next()) >= 0) {
651 int size_in_bytes = compute_data_size(&stream);
652 data_size += size_in_bytes;
653 if (size_in_bytes == 0) empty_bc_count += 1;
654 }
655 int object_size = in_bytes(data_offset()) + data_size;
656
657 // Add some extra DataLayout cells (at least one) to track stray traps.
658 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count);
659 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);
660
661 // Add a cell to record information about modified arguments.
662 int arg_size = method->size_of_parameters();
663 object_size += DataLayout::compute_size_in_bytes(arg_size+1);
664
665 return object_size;
666 }
667
668 // Compute the size of the MethodData* necessary to store
669 // profiling information about a given method. Size is in words
670 int MethodData::compute_allocation_size_in_words(methodHandle method) {
671 int byte_size = compute_allocation_size_in_bytes(method);
672 int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord;
673 return align_object_size(word_size);
674 }
675
676 // Initialize an individual data segment. Returns the size of
677 // the segment in bytes.
678 int MethodData::initialize_data(BytecodeStream* stream,
679 int data_index) {
680 #if defined(COMPILER1) && !defined(COMPILER2)
681 return 0;
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:
760 case Bytecodes::_ifle:
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)) {
802 return NULL;
803 }
804 DataLayout* data_layout = data_layout_at(data_index);
805 return data_layout->data_in();
812 ShouldNotReachHere();
813 return NULL;
814 case DataLayout::bit_data_tag:
815 return new BitData(this);
816 case DataLayout::counter_data_tag:
817 return new CounterData(this);
818 case DataLayout::jump_data_tag:
819 return new JumpData(this);
820 case DataLayout::receiver_type_data_tag:
821 return new ReceiverTypeData(this);
822 case DataLayout::virtual_call_data_tag:
823 return new VirtualCallData(this);
824 case DataLayout::ret_data_tag:
825 return new RetData(this);
826 case DataLayout::branch_data_tag:
827 return new BranchData(this);
828 case DataLayout::multi_branch_data_tag:
829 return new MultiBranchData(this);
830 case DataLayout::arg_info_data_tag:
831 return new ArgInfoData(this);
832 case DataLayout::call_type_data_tag:
833 return new CallTypeData(this);
834 case DataLayout::virtual_call_type_data_tag:
835 return new VirtualCallTypeData(this);
836 };
837 }
838
839 // Iteration over data.
840 ProfileData* MethodData::next_data(ProfileData* current) const {
841 int current_index = dp_to_di(current->dp());
842 int next_index = current_index + current->size_in_bytes();
843 ProfileData* next = data_at(next_index);
844 return next;
845 }
846
847 // Give each of the data entries a chance to perform specific
848 // data initialization.
849 void MethodData::post_initialize(BytecodeStream* stream) {
850 ResourceMark rm;
851 ProfileData* data;
852 for (data = first_data(); is_valid(data); data = next_data(data)) {
853 stream->set_start(data->bci());
854 stream->next();
855 data->post_initialize(stream, this);
1083 void MethodData::collect_statistics(KlassSizeStats *sz) const {
1084 int n = sz->count(this);
1085 sz->_method_data_bytes += n;
1086 sz->_method_all_bytes += n;
1087 sz->_rw_bytes += n;
1088 }
1089 #endif // INCLUDE_SERVICES
1090
1091 // Verification
1092
1093 void MethodData::verify_on(outputStream* st) {
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
|