Thu, 12 Mar 2009 18:16:36 -0700
Merge
1 /*
2 * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 # include "incls/_precompiled.incl"
26 # include "incls/_methodDataOop.cpp.incl"
28 // ==================================================================
29 // DataLayout
30 //
31 // Overlay for generic profiling data.
33 // Some types of data layouts need a length field.
34 bool DataLayout::needs_array_len(u1 tag) {
35 return (tag == multi_branch_data_tag) || (tag == arg_info_data_tag);
36 }
38 // Perform generic initialization of the data. More specific
39 // initialization occurs in overrides of ProfileData::post_initialize.
40 void DataLayout::initialize(u1 tag, u2 bci, int cell_count) {
41 _header._bits = (intptr_t)0;
42 _header._struct._tag = tag;
43 _header._struct._bci = bci;
44 for (int i = 0; i < cell_count; i++) {
45 set_cell_at(i, (intptr_t)0);
46 }
47 if (needs_array_len(tag)) {
48 set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header.
49 }
50 }
52 // ==================================================================
53 // ProfileData
54 //
55 // A ProfileData object is created to refer to a section of profiling
56 // data in a structured way.
58 // Constructor for invalid ProfileData.
59 ProfileData::ProfileData() {
60 _data = NULL;
61 }
63 #ifndef PRODUCT
64 void ProfileData::print_shared(outputStream* st, const char* name) {
65 st->print("bci: %d", bci());
66 st->fill_to(tab_width_one);
67 st->print("%s", name);
68 tab(st);
69 int trap = trap_state();
70 if (trap != 0) {
71 char buf[100];
72 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
73 }
74 int flags = data()->flags();
75 if (flags != 0)
76 st->print("flags(%d) ", flags);
77 }
79 void ProfileData::tab(outputStream* st) {
80 st->fill_to(tab_width_two);
81 }
82 #endif // !PRODUCT
84 // ==================================================================
85 // BitData
86 //
87 // A BitData corresponds to a one-bit flag. This is used to indicate
88 // whether a checkcast bytecode has seen a null value.
91 #ifndef PRODUCT
92 void BitData::print_data_on(outputStream* st) {
93 print_shared(st, "BitData");
94 }
95 #endif // !PRODUCT
97 // ==================================================================
98 // CounterData
99 //
100 // A CounterData corresponds to a simple counter.
102 #ifndef PRODUCT
103 void CounterData::print_data_on(outputStream* st) {
104 print_shared(st, "CounterData");
105 st->print_cr("count(%u)", count());
106 }
107 #endif // !PRODUCT
109 // ==================================================================
110 // JumpData
111 //
112 // A JumpData is used to access profiling information for a direct
113 // branch. It is a counter, used for counting the number of branches,
114 // plus a data displacement, used for realigning the data pointer to
115 // the corresponding target bci.
117 void JumpData::post_initialize(BytecodeStream* stream, methodDataOop mdo) {
118 assert(stream->bci() == bci(), "wrong pos");
119 int target;
120 Bytecodes::Code c = stream->code();
121 if (c == Bytecodes::_goto_w || c == Bytecodes::_jsr_w) {
122 target = stream->dest_w();
123 } else {
124 target = stream->dest();
125 }
126 int my_di = mdo->dp_to_di(dp());
127 int target_di = mdo->bci_to_di(target);
128 int offset = target_di - my_di;
129 set_displacement(offset);
130 }
132 #ifndef PRODUCT
133 void JumpData::print_data_on(outputStream* st) {
134 print_shared(st, "JumpData");
135 st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
136 }
137 #endif // !PRODUCT
139 // ==================================================================
140 // ReceiverTypeData
141 //
142 // A ReceiverTypeData is used to access profiling information about a
143 // dynamic type check. It consists of a counter which counts the total times
144 // that the check is reached, and a series of (klassOop, count) pairs
145 // which are used to store a type profile for the receiver of the check.
147 void ReceiverTypeData::follow_contents() {
148 for (uint row = 0; row < row_limit(); row++) {
149 if (receiver(row) != NULL) {
150 MarkSweep::mark_and_push(adr_receiver(row));
151 }
152 }
153 }
155 #ifndef SERIALGC
156 void ReceiverTypeData::follow_contents(ParCompactionManager* cm) {
157 for (uint row = 0; row < row_limit(); row++) {
158 if (receiver(row) != NULL) {
159 PSParallelCompact::mark_and_push(cm, adr_receiver(row));
160 }
161 }
162 }
163 #endif // SERIALGC
165 void ReceiverTypeData::oop_iterate(OopClosure* blk) {
166 for (uint row = 0; row < row_limit(); row++) {
167 if (receiver(row) != NULL) {
168 blk->do_oop(adr_receiver(row));
169 }
170 }
171 }
173 void ReceiverTypeData::oop_iterate_m(OopClosure* blk, MemRegion mr) {
174 for (uint row = 0; row < row_limit(); row++) {
175 if (receiver(row) != NULL) {
176 oop* adr = adr_receiver(row);
177 if (mr.contains(adr)) {
178 blk->do_oop(adr);
179 }
180 }
181 }
182 }
184 void ReceiverTypeData::adjust_pointers() {
185 for (uint row = 0; row < row_limit(); row++) {
186 if (receiver(row) != NULL) {
187 MarkSweep::adjust_pointer(adr_receiver(row));
188 }
189 }
190 }
192 #ifndef SERIALGC
193 void ReceiverTypeData::update_pointers() {
194 for (uint row = 0; row < row_limit(); row++) {
195 if (receiver_unchecked(row) != NULL) {
196 PSParallelCompact::adjust_pointer(adr_receiver(row));
197 }
198 }
199 }
201 void ReceiverTypeData::update_pointers(HeapWord* beg_addr, HeapWord* end_addr) {
202 // The loop bounds could be computed based on beg_addr/end_addr and the
203 // boundary test hoisted outside the loop (see klassVTable for an example);
204 // however, row_limit() is small enough (2) to make that less efficient.
205 for (uint row = 0; row < row_limit(); row++) {
206 if (receiver_unchecked(row) != NULL) {
207 PSParallelCompact::adjust_pointer(adr_receiver(row), beg_addr, end_addr);
208 }
209 }
210 }
211 #endif // SERIALGC
213 #ifndef PRODUCT
214 void ReceiverTypeData::print_receiver_data_on(outputStream* st) {
215 uint row;
216 int entries = 0;
217 for (row = 0; row < row_limit(); row++) {
218 if (receiver(row) != NULL) entries++;
219 }
220 st->print_cr("count(%u) entries(%u)", count(), entries);
221 for (row = 0; row < row_limit(); row++) {
222 if (receiver(row) != NULL) {
223 tab(st);
224 receiver(row)->print_value_on(st);
225 st->print_cr("(%u)", receiver_count(row));
226 }
227 }
228 }
229 void ReceiverTypeData::print_data_on(outputStream* st) {
230 print_shared(st, "ReceiverTypeData");
231 print_receiver_data_on(st);
232 }
233 void VirtualCallData::print_data_on(outputStream* st) {
234 print_shared(st, "VirtualCallData");
235 print_receiver_data_on(st);
236 }
237 #endif // !PRODUCT
239 // ==================================================================
240 // RetData
241 //
242 // A RetData is used to access profiling information for a ret bytecode.
243 // It is composed of a count of the number of times that the ret has
244 // been executed, followed by a series of triples of the form
245 // (bci, count, di) which count the number of times that some bci was the
246 // target of the ret and cache a corresponding displacement.
248 void RetData::post_initialize(BytecodeStream* stream, methodDataOop mdo) {
249 for (uint row = 0; row < row_limit(); row++) {
250 set_bci_displacement(row, -1);
251 set_bci(row, no_bci);
252 }
253 // release so other threads see a consistent state. bci is used as
254 // a valid flag for bci_displacement.
255 OrderAccess::release();
256 }
258 // This routine needs to atomically update the RetData structure, so the
259 // caller needs to hold the RetData_lock before it gets here. Since taking
260 // the lock can block (and allow GC) and since RetData is a ProfileData is a
261 // wrapper around a derived oop, taking the lock in _this_ method will
262 // basically cause the 'this' pointer's _data field to contain junk after the
263 // lock. We require the caller to take the lock before making the ProfileData
264 // structure. Currently the only caller is InterpreterRuntime::update_mdp_for_ret
265 address RetData::fixup_ret(int return_bci, methodDataHandle h_mdo) {
266 // First find the mdp which corresponds to the return bci.
267 address mdp = h_mdo->bci_to_dp(return_bci);
269 // Now check to see if any of the cache slots are open.
270 for (uint row = 0; row < row_limit(); row++) {
271 if (bci(row) == no_bci) {
272 set_bci_displacement(row, mdp - dp());
273 set_bci_count(row, DataLayout::counter_increment);
274 // Barrier to ensure displacement is written before the bci; allows
275 // the interpreter to read displacement without fear of race condition.
276 release_set_bci(row, return_bci);
277 break;
278 }
279 }
280 return mdp;
281 }
284 #ifndef PRODUCT
285 void RetData::print_data_on(outputStream* st) {
286 print_shared(st, "RetData");
287 uint row;
288 int entries = 0;
289 for (row = 0; row < row_limit(); row++) {
290 if (bci(row) != no_bci) entries++;
291 }
292 st->print_cr("count(%u) entries(%u)", count(), entries);
293 for (row = 0; row < row_limit(); row++) {
294 if (bci(row) != no_bci) {
295 tab(st);
296 st->print_cr("bci(%d: count(%u) displacement(%d))",
297 bci(row), bci_count(row), bci_displacement(row));
298 }
299 }
300 }
301 #endif // !PRODUCT
303 // ==================================================================
304 // BranchData
305 //
306 // A BranchData is used to access profiling data for a two-way branch.
307 // It consists of taken and not_taken counts as well as a data displacement
308 // for the taken case.
310 void BranchData::post_initialize(BytecodeStream* stream, methodDataOop mdo) {
311 assert(stream->bci() == bci(), "wrong pos");
312 int target = stream->dest();
313 int my_di = mdo->dp_to_di(dp());
314 int target_di = mdo->bci_to_di(target);
315 int offset = target_di - my_di;
316 set_displacement(offset);
317 }
319 #ifndef PRODUCT
320 void BranchData::print_data_on(outputStream* st) {
321 print_shared(st, "BranchData");
322 st->print_cr("taken(%u) displacement(%d)",
323 taken(), displacement());
324 tab(st);
325 st->print_cr("not taken(%u)", not_taken());
326 }
327 #endif
329 // ==================================================================
330 // MultiBranchData
331 //
332 // A MultiBranchData is used to access profiling information for
333 // a multi-way branch (*switch bytecodes). It consists of a series
334 // of (count, displacement) pairs, which count the number of times each
335 // case was taken and specify the data displacment for each branch target.
337 int MultiBranchData::compute_cell_count(BytecodeStream* stream) {
338 int cell_count = 0;
339 if (stream->code() == Bytecodes::_tableswitch) {
340 Bytecode_tableswitch* sw = Bytecode_tableswitch_at(stream->bcp());
341 cell_count = 1 + per_case_cell_count * (1 + sw->length()); // 1 for default
342 } else {
343 Bytecode_lookupswitch* sw = Bytecode_lookupswitch_at(stream->bcp());
344 cell_count = 1 + per_case_cell_count * (sw->number_of_pairs() + 1); // 1 for default
345 }
346 return cell_count;
347 }
349 void MultiBranchData::post_initialize(BytecodeStream* stream,
350 methodDataOop mdo) {
351 assert(stream->bci() == bci(), "wrong pos");
352 int target;
353 int my_di;
354 int target_di;
355 int offset;
356 if (stream->code() == Bytecodes::_tableswitch) {
357 Bytecode_tableswitch* sw = Bytecode_tableswitch_at(stream->bcp());
358 int len = sw->length();
359 assert(array_len() == per_case_cell_count * (len + 1), "wrong len");
360 for (int count = 0; count < len; count++) {
361 target = sw->dest_offset_at(count) + bci();
362 my_di = mdo->dp_to_di(dp());
363 target_di = mdo->bci_to_di(target);
364 offset = target_di - my_di;
365 set_displacement_at(count, offset);
366 }
367 target = sw->default_offset() + bci();
368 my_di = mdo->dp_to_di(dp());
369 target_di = mdo->bci_to_di(target);
370 offset = target_di - my_di;
371 set_default_displacement(offset);
373 } else {
374 Bytecode_lookupswitch* sw = Bytecode_lookupswitch_at(stream->bcp());
375 int npairs = sw->number_of_pairs();
376 assert(array_len() == per_case_cell_count * (npairs + 1), "wrong len");
377 for (int count = 0; count < npairs; count++) {
378 LookupswitchPair *pair = sw->pair_at(count);
379 target = pair->offset() + bci();
380 my_di = mdo->dp_to_di(dp());
381 target_di = mdo->bci_to_di(target);
382 offset = target_di - my_di;
383 set_displacement_at(count, offset);
384 }
385 target = sw->default_offset() + bci();
386 my_di = mdo->dp_to_di(dp());
387 target_di = mdo->bci_to_di(target);
388 offset = target_di - my_di;
389 set_default_displacement(offset);
390 }
391 }
393 #ifndef PRODUCT
394 void MultiBranchData::print_data_on(outputStream* st) {
395 print_shared(st, "MultiBranchData");
396 st->print_cr("default_count(%u) displacement(%d)",
397 default_count(), default_displacement());
398 int cases = number_of_cases();
399 for (int i = 0; i < cases; i++) {
400 tab(st);
401 st->print_cr("count(%u) displacement(%d)",
402 count_at(i), displacement_at(i));
403 }
404 }
405 #endif
407 #ifndef PRODUCT
408 void ArgInfoData::print_data_on(outputStream* st) {
409 print_shared(st, "ArgInfoData");
410 int nargs = number_of_args();
411 for (int i = 0; i < nargs; i++) {
412 st->print(" 0x%x", arg_modified(i));
413 }
414 st->cr();
415 }
417 #endif
418 // ==================================================================
419 // methodDataOop
420 //
421 // A methodDataOop holds information which has been collected about
422 // a method.
424 int methodDataOopDesc::bytecode_cell_count(Bytecodes::Code code) {
425 switch (code) {
426 case Bytecodes::_checkcast:
427 case Bytecodes::_instanceof:
428 case Bytecodes::_aastore:
429 if (TypeProfileCasts) {
430 return ReceiverTypeData::static_cell_count();
431 } else {
432 return BitData::static_cell_count();
433 }
434 case Bytecodes::_invokespecial:
435 case Bytecodes::_invokestatic:
436 return CounterData::static_cell_count();
437 case Bytecodes::_goto:
438 case Bytecodes::_goto_w:
439 case Bytecodes::_jsr:
440 case Bytecodes::_jsr_w:
441 return JumpData::static_cell_count();
442 case Bytecodes::_invokevirtual:
443 case Bytecodes::_invokeinterface:
444 return VirtualCallData::static_cell_count();
445 case Bytecodes::_ret:
446 return RetData::static_cell_count();
447 case Bytecodes::_ifeq:
448 case Bytecodes::_ifne:
449 case Bytecodes::_iflt:
450 case Bytecodes::_ifge:
451 case Bytecodes::_ifgt:
452 case Bytecodes::_ifle:
453 case Bytecodes::_if_icmpeq:
454 case Bytecodes::_if_icmpne:
455 case Bytecodes::_if_icmplt:
456 case Bytecodes::_if_icmpge:
457 case Bytecodes::_if_icmpgt:
458 case Bytecodes::_if_icmple:
459 case Bytecodes::_if_acmpeq:
460 case Bytecodes::_if_acmpne:
461 case Bytecodes::_ifnull:
462 case Bytecodes::_ifnonnull:
463 return BranchData::static_cell_count();
464 case Bytecodes::_lookupswitch:
465 case Bytecodes::_tableswitch:
466 return variable_cell_count;
467 }
468 return no_profile_data;
469 }
471 // Compute the size of the profiling information corresponding to
472 // the current bytecode.
473 int methodDataOopDesc::compute_data_size(BytecodeStream* stream) {
474 int cell_count = bytecode_cell_count(stream->code());
475 if (cell_count == no_profile_data) {
476 return 0;
477 }
478 if (cell_count == variable_cell_count) {
479 cell_count = MultiBranchData::compute_cell_count(stream);
480 }
481 // Note: cell_count might be zero, meaning that there is just
482 // a DataLayout header, with no extra cells.
483 assert(cell_count >= 0, "sanity");
484 return DataLayout::compute_size_in_bytes(cell_count);
485 }
487 int methodDataOopDesc::compute_extra_data_count(int data_size, int empty_bc_count) {
488 if (ProfileTraps) {
489 // Assume that up to 3% of BCIs with no MDP will need to allocate one.
490 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;
491 // If the method is large, let the extra BCIs grow numerous (to ~1%).
492 int one_percent_of_data
493 = (uint)data_size / (DataLayout::header_size_in_bytes()*128);
494 if (extra_data_count < one_percent_of_data)
495 extra_data_count = one_percent_of_data;
496 if (extra_data_count > empty_bc_count)
497 extra_data_count = empty_bc_count; // no need for more
498 return extra_data_count;
499 } else {
500 return 0;
501 }
502 }
504 // Compute the size of the methodDataOop necessary to store
505 // profiling information about a given method. Size is in bytes.
506 int methodDataOopDesc::compute_allocation_size_in_bytes(methodHandle method) {
507 int data_size = 0;
508 BytecodeStream stream(method);
509 Bytecodes::Code c;
510 int empty_bc_count = 0; // number of bytecodes lacking data
511 while ((c = stream.next()) >= 0) {
512 int size_in_bytes = compute_data_size(&stream);
513 data_size += size_in_bytes;
514 if (size_in_bytes == 0) empty_bc_count += 1;
515 }
516 int object_size = in_bytes(data_offset()) + data_size;
518 // Add some extra DataLayout cells (at least one) to track stray traps.
519 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count);
520 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);
522 // Add a cell to record information about modified arguments.
523 int arg_size = method->size_of_parameters();
524 object_size += DataLayout::compute_size_in_bytes(arg_size+1);
525 return object_size;
526 }
528 // Compute the size of the methodDataOop necessary to store
529 // profiling information about a given method. Size is in words
530 int methodDataOopDesc::compute_allocation_size_in_words(methodHandle method) {
531 int byte_size = compute_allocation_size_in_bytes(method);
532 int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord;
533 return align_object_size(word_size);
534 }
536 // Initialize an individual data segment. Returns the size of
537 // the segment in bytes.
538 int methodDataOopDesc::initialize_data(BytecodeStream* stream,
539 int data_index) {
540 int cell_count = -1;
541 int tag = DataLayout::no_tag;
542 DataLayout* data_layout = data_layout_at(data_index);
543 Bytecodes::Code c = stream->code();
544 switch (c) {
545 case Bytecodes::_checkcast:
546 case Bytecodes::_instanceof:
547 case Bytecodes::_aastore:
548 if (TypeProfileCasts) {
549 cell_count = ReceiverTypeData::static_cell_count();
550 tag = DataLayout::receiver_type_data_tag;
551 } else {
552 cell_count = BitData::static_cell_count();
553 tag = DataLayout::bit_data_tag;
554 }
555 break;
556 case Bytecodes::_invokespecial:
557 case Bytecodes::_invokestatic:
558 cell_count = CounterData::static_cell_count();
559 tag = DataLayout::counter_data_tag;
560 break;
561 case Bytecodes::_goto:
562 case Bytecodes::_goto_w:
563 case Bytecodes::_jsr:
564 case Bytecodes::_jsr_w:
565 cell_count = JumpData::static_cell_count();
566 tag = DataLayout::jump_data_tag;
567 break;
568 case Bytecodes::_invokevirtual:
569 case Bytecodes::_invokeinterface:
570 cell_count = VirtualCallData::static_cell_count();
571 tag = DataLayout::virtual_call_data_tag;
572 break;
573 case Bytecodes::_ret:
574 cell_count = RetData::static_cell_count();
575 tag = DataLayout::ret_data_tag;
576 break;
577 case Bytecodes::_ifeq:
578 case Bytecodes::_ifne:
579 case Bytecodes::_iflt:
580 case Bytecodes::_ifge:
581 case Bytecodes::_ifgt:
582 case Bytecodes::_ifle:
583 case Bytecodes::_if_icmpeq:
584 case Bytecodes::_if_icmpne:
585 case Bytecodes::_if_icmplt:
586 case Bytecodes::_if_icmpge:
587 case Bytecodes::_if_icmpgt:
588 case Bytecodes::_if_icmple:
589 case Bytecodes::_if_acmpeq:
590 case Bytecodes::_if_acmpne:
591 case Bytecodes::_ifnull:
592 case Bytecodes::_ifnonnull:
593 cell_count = BranchData::static_cell_count();
594 tag = DataLayout::branch_data_tag;
595 break;
596 case Bytecodes::_lookupswitch:
597 case Bytecodes::_tableswitch:
598 cell_count = MultiBranchData::compute_cell_count(stream);
599 tag = DataLayout::multi_branch_data_tag;
600 break;
601 }
602 assert(tag == DataLayout::multi_branch_data_tag ||
603 cell_count == bytecode_cell_count(c), "cell counts must agree");
604 if (cell_count >= 0) {
605 assert(tag != DataLayout::no_tag, "bad tag");
606 assert(bytecode_has_profile(c), "agree w/ BHP");
607 data_layout->initialize(tag, stream->bci(), cell_count);
608 return DataLayout::compute_size_in_bytes(cell_count);
609 } else {
610 assert(!bytecode_has_profile(c), "agree w/ !BHP");
611 return 0;
612 }
613 }
615 // Get the data at an arbitrary (sort of) data index.
616 ProfileData* methodDataOopDesc::data_at(int data_index) {
617 if (out_of_bounds(data_index)) {
618 return NULL;
619 }
620 DataLayout* data_layout = data_layout_at(data_index);
622 switch (data_layout->tag()) {
623 case DataLayout::no_tag:
624 default:
625 ShouldNotReachHere();
626 return NULL;
627 case DataLayout::bit_data_tag:
628 return new BitData(data_layout);
629 case DataLayout::counter_data_tag:
630 return new CounterData(data_layout);
631 case DataLayout::jump_data_tag:
632 return new JumpData(data_layout);
633 case DataLayout::receiver_type_data_tag:
634 return new ReceiverTypeData(data_layout);
635 case DataLayout::virtual_call_data_tag:
636 return new VirtualCallData(data_layout);
637 case DataLayout::ret_data_tag:
638 return new RetData(data_layout);
639 case DataLayout::branch_data_tag:
640 return new BranchData(data_layout);
641 case DataLayout::multi_branch_data_tag:
642 return new MultiBranchData(data_layout);
643 case DataLayout::arg_info_data_tag:
644 return new ArgInfoData(data_layout);
645 };
646 }
648 // Iteration over data.
649 ProfileData* methodDataOopDesc::next_data(ProfileData* current) {
650 int current_index = dp_to_di(current->dp());
651 int next_index = current_index + current->size_in_bytes();
652 ProfileData* next = data_at(next_index);
653 return next;
654 }
656 // Give each of the data entries a chance to perform specific
657 // data initialization.
658 void methodDataOopDesc::post_initialize(BytecodeStream* stream) {
659 ResourceMark rm;
660 ProfileData* data;
661 for (data = first_data(); is_valid(data); data = next_data(data)) {
662 stream->set_start(data->bci());
663 stream->next();
664 data->post_initialize(stream, this);
665 }
666 }
668 // Initialize the methodDataOop corresponding to a given method.
669 void methodDataOopDesc::initialize(methodHandle method) {
670 ResourceMark rm;
672 // Set the method back-pointer.
673 _method = method();
674 set_creation_mileage(mileage_of(method()));
676 // Initialize flags and trap history.
677 _nof_decompiles = 0;
678 _nof_overflow_recompiles = 0;
679 _nof_overflow_traps = 0;
680 assert(sizeof(_trap_hist) % sizeof(HeapWord) == 0, "align");
681 Copy::zero_to_words((HeapWord*) &_trap_hist,
682 sizeof(_trap_hist) / sizeof(HeapWord));
684 // Go through the bytecodes and allocate and initialize the
685 // corresponding data cells.
686 int data_size = 0;
687 int empty_bc_count = 0; // number of bytecodes lacking data
688 BytecodeStream stream(method);
689 Bytecodes::Code c;
690 while ((c = stream.next()) >= 0) {
691 int size_in_bytes = initialize_data(&stream, data_size);
692 data_size += size_in_bytes;
693 if (size_in_bytes == 0) empty_bc_count += 1;
694 }
695 _data_size = data_size;
696 int object_size = in_bytes(data_offset()) + data_size;
698 // Add some extra DataLayout cells (at least one) to track stray traps.
699 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count);
700 int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0);
702 // Add a cell to record information about modified arguments.
703 // Set up _args_modified array after traps cells so that
704 // the code for traps cells works.
705 DataLayout *dp = data_layout_at(data_size + extra_size);
707 int arg_size = method->size_of_parameters();
708 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
710 object_size += extra_size + DataLayout::compute_size_in_bytes(arg_size+1);
712 // Set an initial hint. Don't use set_hint_di() because
713 // first_di() may be out of bounds if data_size is 0.
714 // In that situation, _hint_di is never used, but at
715 // least well-defined.
716 _hint_di = first_di();
718 post_initialize(&stream);
720 set_object_is_parsable(object_size);
721 }
723 // Get a measure of how much mileage the method has on it.
724 int methodDataOopDesc::mileage_of(methodOop method) {
725 int mileage = 0;
726 int iic = method->interpreter_invocation_count();
727 if (mileage < iic) mileage = iic;
729 InvocationCounter* ic = method->invocation_counter();
730 InvocationCounter* bc = method->backedge_counter();
732 int icval = ic->count();
733 if (ic->carry()) icval += CompileThreshold;
734 if (mileage < icval) mileage = icval;
735 int bcval = bc->count();
736 if (bc->carry()) bcval += CompileThreshold;
737 if (mileage < bcval) mileage = bcval;
738 return mileage;
739 }
741 bool methodDataOopDesc::is_mature() const {
742 uint current = mileage_of(_method);
743 uint initial = creation_mileage();
744 if (current < initial)
745 return true; // some sort of overflow
746 uint target;
747 if (ProfileMaturityPercentage <= 0)
748 target = (uint) -ProfileMaturityPercentage; // absolute value
749 else
750 target = (uint)( (ProfileMaturityPercentage * CompileThreshold) / 100 );
751 return (current >= initial + target);
752 }
754 // Translate a bci to its corresponding data index (di).
755 address methodDataOopDesc::bci_to_dp(int bci) {
756 ResourceMark rm;
757 ProfileData* data = data_before(bci);
758 ProfileData* prev = NULL;
759 for ( ; is_valid(data); data = next_data(data)) {
760 if (data->bci() >= bci) {
761 if (data->bci() == bci) set_hint_di(dp_to_di(data->dp()));
762 else if (prev != NULL) set_hint_di(dp_to_di(prev->dp()));
763 return data->dp();
764 }
765 prev = data;
766 }
767 return (address)limit_data_position();
768 }
770 // Translate a bci to its corresponding data, or NULL.
771 ProfileData* methodDataOopDesc::bci_to_data(int bci) {
772 ProfileData* data = data_before(bci);
773 for ( ; is_valid(data); data = next_data(data)) {
774 if (data->bci() == bci) {
775 set_hint_di(dp_to_di(data->dp()));
776 return data;
777 } else if (data->bci() > bci) {
778 break;
779 }
780 }
781 return bci_to_extra_data(bci, false);
782 }
784 // Translate a bci to its corresponding extra data, or NULL.
785 ProfileData* methodDataOopDesc::bci_to_extra_data(int bci, bool create_if_missing) {
786 DataLayout* dp = extra_data_base();
787 DataLayout* end = extra_data_limit();
788 DataLayout* avail = NULL;
789 for (; dp < end; dp = next_extra(dp)) {
790 // No need for "OrderAccess::load_acquire" ops,
791 // since the data structure is monotonic.
792 if (dp->tag() == DataLayout::no_tag) break;
793 if (dp->tag() == DataLayout::arg_info_data_tag) {
794 dp = end; // ArgInfoData is at the end of extra data section.
795 break;
796 }
797 if (dp->bci() == bci) {
798 assert(dp->tag() == DataLayout::bit_data_tag, "sane");
799 return new BitData(dp);
800 }
801 }
802 if (create_if_missing && dp < end) {
803 // Allocate this one. There is no mutual exclusion,
804 // so two threads could allocate different BCIs to the
805 // same data layout. This means these extra data
806 // records, like most other MDO contents, must not be
807 // trusted too much.
808 DataLayout temp;
809 temp.initialize(DataLayout::bit_data_tag, bci, 0);
810 dp->release_set_header(temp.header());
811 assert(dp->tag() == DataLayout::bit_data_tag, "sane");
812 //NO: assert(dp->bci() == bci, "no concurrent allocation");
813 return new BitData(dp);
814 }
815 return NULL;
816 }
818 ArgInfoData *methodDataOopDesc::arg_info() {
819 DataLayout* dp = extra_data_base();
820 DataLayout* end = extra_data_limit();
821 for (; dp < end; dp = next_extra(dp)) {
822 if (dp->tag() == DataLayout::arg_info_data_tag)
823 return new ArgInfoData(dp);
824 }
825 return NULL;
826 }
828 #ifndef PRODUCT
829 void methodDataOopDesc::print_data_on(outputStream* st) {
830 ResourceMark rm;
831 ProfileData* data = first_data();
832 for ( ; is_valid(data); data = next_data(data)) {
833 st->print("%d", dp_to_di(data->dp()));
834 st->fill_to(6);
835 data->print_data_on(st);
836 }
837 st->print_cr("--- Extra data:");
838 DataLayout* dp = extra_data_base();
839 DataLayout* end = extra_data_limit();
840 for (; dp < end; dp = next_extra(dp)) {
841 // No need for "OrderAccess::load_acquire" ops,
842 // since the data structure is monotonic.
843 if (dp->tag() == DataLayout::no_tag) continue;
844 if (dp->tag() == DataLayout::bit_data_tag) {
845 data = new BitData(dp);
846 } else {
847 assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo");
848 data = new ArgInfoData(dp);
849 dp = end; // ArgInfoData is at the end of extra data section.
850 }
851 st->print("%d", dp_to_di(data->dp()));
852 st->fill_to(6);
853 data->print_data_on(st);
854 }
855 }
856 #endif
858 void methodDataOopDesc::verify_data_on(outputStream* st) {
859 NEEDS_CLEANUP;
860 // not yet implemented.
861 }