comparison src/share/vm/opto/bytecodeInfo.cpp @ 18041:52b4284cb496

Merge with jdk8u20-b26
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 15 Oct 2014 16:02:50 +0200
parents 89152779163c 73c839dda17e
children 7848fc12602b
comparison
equal deleted inserted replaced
17606:45d7b2c7029d 18041:52b4284cb496
48 _max_inline_level(max_inline_level), 48 _max_inline_level(max_inline_level),
49 _count_inline_bcs(method()->code_size_for_inlining()), 49 _count_inline_bcs(method()->code_size_for_inlining()),
50 _subtrees(c->comp_arena(), 2, 0, NULL), 50 _subtrees(c->comp_arena(), 2, 0, NULL),
51 _msg(NULL) 51 _msg(NULL)
52 { 52 {
53 NOT_PRODUCT(_count_inlines = 0;) 53 #ifndef PRODUCT
54 _count_inlines = 0;
55 _forced_inline = false;
56 #endif
54 if (_caller_jvms != NULL) { 57 if (_caller_jvms != NULL) {
55 // Keep a private copy of the caller_jvms: 58 // Keep a private copy of the caller_jvms:
56 _caller_jvms = new (C) JVMState(caller_jvms->method(), caller_tree->caller_jvms()); 59 _caller_jvms = new (C) JVMState(caller_jvms->method(), caller_tree->caller_jvms());
57 _caller_jvms->set_bci(caller_jvms->bci()); 60 _caller_jvms->set_bci(caller_jvms->bci());
58 assert(!caller_jvms->should_reexecute(), "there should be no reexecute bytecode with inlining"); 61 assert(!caller_jvms->should_reexecute(), "there should be no reexecute bytecode with inlining");
59 } 62 }
60 assert(_caller_jvms->same_calls_as(caller_jvms), "consistent JVMS"); 63 assert(_caller_jvms->same_calls_as(caller_jvms), "consistent JVMS");
61 assert((caller_tree == NULL ? 0 : caller_tree->stack_depth() + 1) == stack_depth(), "correct (redundant) depth parameter"); 64 assert((caller_tree == NULL ? 0 : caller_tree->stack_depth() + 1) == stack_depth(), "correct (redundant) depth parameter");
62 assert(caller_bci == this->caller_bci(), "correct (redundant) bci parameter"); 65 assert(caller_bci == this->caller_bci(), "correct (redundant) bci parameter");
63 if (UseOldInlining) { 66 // Update hierarchical counts, count_inline_bcs() and count_inlines()
64 // Update hierarchical counts, count_inline_bcs() and count_inlines() 67 InlineTree *caller = (InlineTree *)caller_tree;
65 InlineTree *caller = (InlineTree *)caller_tree; 68 for( ; caller != NULL; caller = ((InlineTree *)(caller->caller_tree())) ) {
66 for( ; caller != NULL; caller = ((InlineTree *)(caller->caller_tree())) ) { 69 caller->_count_inline_bcs += count_inline_bcs();
67 caller->_count_inline_bcs += count_inline_bcs(); 70 NOT_PRODUCT(caller->_count_inlines++;)
68 NOT_PRODUCT(caller->_count_inlines++;) 71 }
69 }
70 }
71 }
72
73 InlineTree::InlineTree(Compile* c, ciMethod* callee_method, JVMState* caller_jvms,
74 float site_invoke_ratio, int max_inline_level) :
75 C(c),
76 _caller_jvms(caller_jvms),
77 _caller_tree(NULL),
78 _method(callee_method),
79 _site_invoke_ratio(site_invoke_ratio),
80 _max_inline_level(max_inline_level),
81 _count_inline_bcs(method()->code_size()),
82 _msg(NULL)
83 {
84 NOT_PRODUCT(_count_inlines = 0;)
85 assert(!UseOldInlining, "do not use for old stuff");
86 } 72 }
87 73
88 /** 74 /**
89 * Return true when EA is ON and a java constructor is called or 75 * Return true when EA is ON and a java constructor is called or
90 * a super constructor is called from an inlined java constructor. 76 * a super constructor is called from an inlined java constructor.
126 if (C->print_inlining() && Verbose) { 112 if (C->print_inlining() && Verbose) {
127 CompileTask::print_inline_indent(inline_level()); 113 CompileTask::print_inline_indent(inline_level());
128 tty->print_cr("Inlined method is hot: "); 114 tty->print_cr("Inlined method is hot: ");
129 } 115 }
130 set_msg("force inline by CompilerOracle"); 116 set_msg("force inline by CompilerOracle");
131 return true; 117 _forced_inline = true;
132 } 118 return true;
119 }
120
121 #ifndef PRODUCT
122 int inline_depth = inline_level()+1;
123 if (ciReplay::should_inline(C->replay_inline_data(), callee_method, caller_bci, inline_depth)) {
124 set_msg("force inline by ciReplay");
125 _forced_inline = true;
126 return true;
127 }
128 #endif
133 129
134 int size = callee_method->code_size_for_inlining(); 130 int size = callee_method->code_size_for_inlining();
135 131
136 // Check for too many throws (and not too huge) 132 // Check for too many throws (and not too huge)
137 if(callee_method->interpreter_throwout_count() > InlineThrowCount && 133 if(callee_method->interpreter_throwout_count() > InlineThrowCount &&
141 CompileTask::print_inline_indent(inline_level()); 137 CompileTask::print_inline_indent(inline_level());
142 tty->print_cr("Inlined method with many throws (throws=%d):", callee_method->interpreter_throwout_count()); 138 tty->print_cr("Inlined method with many throws (throws=%d):", callee_method->interpreter_throwout_count());
143 } 139 }
144 set_msg("many throws"); 140 set_msg("many throws");
145 return true; 141 return true;
146 }
147
148 if (!UseOldInlining) {
149 set_msg("!UseOldInlining");
150 return true; // size and frequency are represented in a new way
151 } 142 }
152 143
153 int default_max_inline_size = C->max_inline_size(); 144 int default_max_inline_size = C->max_inline_size();
154 int inline_small_code_size = InlineSmallCode / 4; 145 int inline_small_code_size = InlineSmallCode / 4;
155 int max_inline_size = default_max_inline_size; 146 int max_inline_size = default_max_inline_size;
211 fail_msg = "native method"; 202 fail_msg = "native method";
212 } else if ( callee_method->dont_inline()) { 203 } else if ( callee_method->dont_inline()) {
213 fail_msg = "don't inline by annotation"; 204 fail_msg = "don't inline by annotation";
214 } 205 }
215 206
216 if (!UseOldInlining) {
217 if (fail_msg != NULL) {
218 *wci_result = *(WarmCallInfo::always_cold());
219 set_msg(fail_msg);
220 return true;
221 }
222
223 if (callee_method->has_unloaded_classes_in_signature()) {
224 wci_result->set_profit(wci_result->profit() * 0.1);
225 }
226
227 // don't inline exception code unless the top method belongs to an
228 // exception class
229 if (callee_method->holder()->is_subclass_of(C->env()->Throwable_klass())) {
230 ciMethod* top_method = jvms->caller() != NULL ? jvms->caller()->of_depth(1)->method() : method();
231 if (!top_method->holder()->is_subclass_of(C->env()->Throwable_klass())) {
232 wci_result->set_profit(wci_result->profit() * 0.1);
233 }
234 }
235
236 if (callee_method->has_compiled_code() &&
237 callee_method->instructions_size() > InlineSmallCode) {
238 wci_result->set_profit(wci_result->profit() * 0.1);
239 // %%% adjust wci_result->size()?
240 }
241
242 return false;
243 }
244
245 // one more inlining restriction 207 // one more inlining restriction
246 if (fail_msg == NULL && callee_method->has_unloaded_classes_in_signature()) { 208 if (fail_msg == NULL && callee_method->has_unloaded_classes_in_signature()) {
247 fail_msg = "unloaded signature classes"; 209 fail_msg = "unloaded signature classes";
248 } 210 }
249 211
262 set_msg("disallowed by CompilerOracle"); 224 set_msg("disallowed by CompilerOracle");
263 return true; 225 return true;
264 } 226 }
265 227
266 #ifndef PRODUCT 228 #ifndef PRODUCT
229 int caller_bci = jvms->bci();
230 int inline_depth = inline_level()+1;
231 if (ciReplay::should_inline(C->replay_inline_data(), callee_method, caller_bci, inline_depth)) {
232 set_msg("force inline by ciReplay");
233 return false;
234 }
235
236 if (ciReplay::should_not_inline(C->replay_inline_data(), callee_method, caller_bci, inline_depth)) {
237 set_msg("disallowed by ciReplay");
238 return true;
239 }
240
267 if (ciReplay::should_not_inline(callee_method)) { 241 if (ciReplay::should_not_inline(callee_method)) {
268 set_msg("disallowed by ciReplay"); 242 set_msg("disallowed by ciReplay");
269 return true; 243 return true;
270 } 244 }
271 #endif 245 #endif
330 // Relocated from "InliningClosure::try_to_inline" 304 // Relocated from "InliningClosure::try_to_inline"
331 bool InlineTree::try_to_inline(ciMethod* callee_method, ciMethod* caller_method, 305 bool InlineTree::try_to_inline(ciMethod* callee_method, ciMethod* caller_method,
332 int caller_bci, JVMState* jvms, ciCallProfile& profile, 306 int caller_bci, JVMState* jvms, ciCallProfile& profile,
333 WarmCallInfo* wci_result, bool& should_delay) { 307 WarmCallInfo* wci_result, bool& should_delay) {
334 308
335 // Old algorithm had funny accumulating BC-size counters 309 if (ClipInlining && (int)count_inline_bcs() >= DesiredMethodLimit) {
336 if (UseOldInlining && ClipInlining
337 && (int)count_inline_bcs() >= DesiredMethodLimit) {
338 if (!callee_method->force_inline() || !IncrementalInline) { 310 if (!callee_method->force_inline() || !IncrementalInline) {
339 set_msg("size > DesiredMethodLimit"); 311 set_msg("size > DesiredMethodLimit");
340 return false; 312 return false;
341 } else if (!C->inlining_incrementally()) { 313 } else if (!C->inlining_incrementally()) {
342 should_delay = true; 314 should_delay = true;
343 } 315 }
344 } 316 }
345 317
318 _forced_inline = false; // Reset
346 if (!should_inline(callee_method, caller_method, caller_bci, profile, 319 if (!should_inline(callee_method, caller_method, caller_bci, profile,
347 wci_result)) { 320 wci_result)) {
348 return false; 321 return false;
349 } 322 }
350 if (should_not_inline(callee_method, caller_method, jvms, wci_result)) { 323 if (should_not_inline(callee_method, caller_method, jvms, wci_result)) {
371 } 344 }
372 } 345 }
373 346
374 if ((!UseInterpreter || CompileTheWorld) && 347 if ((!UseInterpreter || CompileTheWorld) &&
375 is_init_with_ea(callee_method, caller_method, C)) { 348 is_init_with_ea(callee_method, caller_method, C)) {
376
377 // Escape Analysis stress testing when running Xcomp or CTW: 349 // Escape Analysis stress testing when running Xcomp or CTW:
378 // inline constructors even if they are not reached. 350 // inline constructors even if they are not reached.
379 351 } else if (forced_inline()) {
352 // Inlining was forced by CompilerOracle or ciReplay
380 } else if (profile.count() == 0) { 353 } else if (profile.count() == 0) {
381 // don't inline unreached call sites 354 // don't inline unreached call sites
382 set_msg("call site not reached"); 355 set_msg("call site not reached");
383 return false; 356 return false;
384 } 357 }
386 359
387 if (!C->do_inlining() && InlineAccessors) { 360 if (!C->do_inlining() && InlineAccessors) {
388 set_msg("not an accessor"); 361 set_msg("not an accessor");
389 return false; 362 return false;
390 } 363 }
364
365 // Limit inlining depth in case inlining is forced or
366 // _max_inline_level was increased to compensate for lambda forms.
367 if (inline_level() > MaxForceInlineLevel) {
368 set_msg("MaxForceInlineLevel");
369 return false;
370 }
391 if (inline_level() > _max_inline_level) { 371 if (inline_level() > _max_inline_level) {
392 if (callee_method->force_inline() && inline_level() > MaxForceInlineLevel) {
393 set_msg("MaxForceInlineLevel");
394 return false;
395 }
396 if (!callee_method->force_inline() || !IncrementalInline) { 372 if (!callee_method->force_inline() || !IncrementalInline) {
397 set_msg("inlining too deep"); 373 set_msg("inlining too deep");
398 return false; 374 return false;
399 } else if (!C->inlining_incrementally()) { 375 } else if (!C->inlining_incrementally()) {
400 should_delay = true; 376 should_delay = true;
434 } 410 }
435 } 411 }
436 412
437 int size = callee_method->code_size_for_inlining(); 413 int size = callee_method->code_size_for_inlining();
438 414
439 if (UseOldInlining && ClipInlining 415 if (ClipInlining && (int)count_inline_bcs() + size >= DesiredMethodLimit) {
440 && (int)count_inline_bcs() + size >= DesiredMethodLimit) {
441 if (!callee_method->force_inline() || !IncrementalInline) { 416 if (!callee_method->force_inline() || !IncrementalInline) {
442 set_msg("size > DesiredMethodLimit"); 417 set_msg("size > DesiredMethodLimit");
443 return false; 418 return false;
444 } else if (!C->inlining_incrementally()) { 419 } else if (!C->inlining_incrementally()) {
445 should_delay = true; 420 should_delay = true;
553 WarmCallInfo wci = *(initial_wci); 528 WarmCallInfo wci = *(initial_wci);
554 bool success = try_to_inline(callee_method, caller_method, caller_bci, 529 bool success = try_to_inline(callee_method, caller_method, caller_bci,
555 jvms, profile, &wci, should_delay); 530 jvms, profile, &wci, should_delay);
556 531
557 #ifndef PRODUCT 532 #ifndef PRODUCT
558 if (UseOldInlining && InlineWarmCalls 533 if (InlineWarmCalls && (PrintOpto || C->print_inlining())) {
559 && (PrintOpto || C->print_inlining())) {
560 bool cold = wci.is_cold(); 534 bool cold = wci.is_cold();
561 bool hot = !cold && wci.is_hot(); 535 bool hot = !cold && wci.is_hot();
562 bool old_cold = !success; 536 bool old_cold = !success;
563 if (old_cold != cold || (Verbose || WizardMode)) { 537 if (old_cold != cold || (Verbose || WizardMode)) {
564 if (msg() == NULL) { 538 if (msg() == NULL) {
568 old_cold ? "cold" : "hot", msg()); 542 old_cold ? "cold" : "hot", msg());
569 wci.print(); 543 wci.print();
570 } 544 }
571 } 545 }
572 #endif 546 #endif
573 if (UseOldInlining) { 547 if (success) {
574 if (success) { 548 wci = *(WarmCallInfo::always_hot());
575 wci = *(WarmCallInfo::always_hot()); 549 } else {
576 } else { 550 wci = *(WarmCallInfo::always_cold());
577 wci = *(WarmCallInfo::always_cold()); 551 }
578 } 552
579 }
580 if (!InlineWarmCalls) { 553 if (!InlineWarmCalls) {
581 if (!wci.is_cold() && !wci.is_hot()) { 554 if (!wci.is_cold() && !wci.is_hot()) {
582 // Do not inline the warm calls. 555 // Do not inline the warm calls.
583 wci = *(WarmCallInfo::always_cold()); 556 wci = *(WarmCallInfo::always_cold());
584 } 557 }
588 // Inline! 561 // Inline!
589 if (msg() == NULL) { 562 if (msg() == NULL) {
590 set_msg("inline (hot)"); 563 set_msg("inline (hot)");
591 } 564 }
592 print_inlining(callee_method, caller_bci, true /* success */); 565 print_inlining(callee_method, caller_bci, true /* success */);
593 if (UseOldInlining) 566 build_inline_tree_for_callee(callee_method, jvms, caller_bci);
594 build_inline_tree_for_callee(callee_method, jvms, caller_bci);
595 if (InlineWarmCalls && !wci.is_hot()) 567 if (InlineWarmCalls && !wci.is_hot())
596 return new (C) WarmCallInfo(wci); // copy to heap 568 return new (C) WarmCallInfo(wci); // copy to heap
597 return WarmCallInfo::always_hot(); 569 return WarmCallInfo::always_hot();
598 } 570 }
599 571
698 iltp = sub; 670 iltp = sub;
699 } 671 }
700 return iltp; 672 return iltp;
701 } 673 }
702 674
675 // Count number of nodes in this subtree
676 int InlineTree::count() const {
677 int result = 1;
678 for (int i = 0 ; i < _subtrees.length(); i++) {
679 result += _subtrees.at(i)->count();
680 }
681 return result;
682 }
683
684 void InlineTree::dump_replay_data(outputStream* out) {
685 out->print(" %d %d ", inline_level(), caller_bci());
686 method()->dump_name_as_ascii(out);
687 for (int i = 0 ; i < _subtrees.length(); i++) {
688 _subtrees.at(i)->dump_replay_data(out);
689 }
690 }
703 691
704 692
705 #ifndef PRODUCT 693 #ifndef PRODUCT
706 void InlineTree::print_impl(outputStream* st, int indent) const { 694 void InlineTree::print_impl(outputStream* st, int indent) const {
707 for (int i = 0; i < indent; i++) st->print(" "); 695 for (int i = 0; i < indent; i++) st->print(" ");
708 st->print(" @ %d ", caller_bci()); 696 st->print(" @ %d", caller_bci());
709 method()->print_short_name(st); 697 method()->print_short_name(st);
710 st->cr(); 698 st->cr();
711 699
712 for (int i = 0 ; i < _subtrees.length(); i++) { 700 for (int i = 0 ; i < _subtrees.length(); i++) {
713 _subtrees.at(i)->print_impl(st, indent + 2); 701 _subtrees.at(i)->print_impl(st, indent + 2);