195 |
195 |
196 |
196 |
197 // negative filter: should callee NOT be inlined? |
197 // negative filter: should callee NOT be inlined? |
198 bool InlineTree::should_not_inline(ciMethod *callee_method, |
198 bool InlineTree::should_not_inline(ciMethod *callee_method, |
199 ciMethod* caller_method, |
199 ciMethod* caller_method, |
|
200 JVMState* jvms, |
200 WarmCallInfo* wci_result) { |
201 WarmCallInfo* wci_result) { |
201 |
202 |
202 const char* fail_msg = NULL; |
203 const char* fail_msg = NULL; |
203 |
204 |
204 // First check all inlining restrictions which are required for correctness |
205 // First check all inlining restrictions which are required for correctness |
224 } |
225 } |
225 |
226 |
226 // don't inline exception code unless the top method belongs to an |
227 // don't inline exception code unless the top method belongs to an |
227 // exception class |
228 // exception class |
228 if (callee_method->holder()->is_subclass_of(C->env()->Throwable_klass())) { |
229 if (callee_method->holder()->is_subclass_of(C->env()->Throwable_klass())) { |
229 ciMethod* top_method = caller_jvms() ? caller_jvms()->of_depth(1)->method() : method(); |
230 ciMethod* top_method = jvms->caller() != NULL ? jvms->caller()->of_depth(1)->method() : method(); |
230 if (!top_method->holder()->is_subclass_of(C->env()->Throwable_klass())) { |
231 if (!top_method->holder()->is_subclass_of(C->env()->Throwable_klass())) { |
231 wci_result->set_profit(wci_result->profit() * 0.1); |
232 wci_result->set_profit(wci_result->profit() * 0.1); |
232 } |
233 } |
233 } |
234 } |
234 |
235 |
326 |
327 |
327 //-----------------------------try_to_inline----------------------------------- |
328 //-----------------------------try_to_inline----------------------------------- |
328 // return true if ok |
329 // return true if ok |
329 // Relocated from "InliningClosure::try_to_inline" |
330 // Relocated from "InliningClosure::try_to_inline" |
330 bool InlineTree::try_to_inline(ciMethod* callee_method, ciMethod* caller_method, |
331 bool InlineTree::try_to_inline(ciMethod* callee_method, ciMethod* caller_method, |
331 int caller_bci, ciCallProfile& profile, |
332 int caller_bci, JVMState* jvms, ciCallProfile& profile, |
332 WarmCallInfo* wci_result, bool& should_delay) { |
333 WarmCallInfo* wci_result, bool& should_delay) { |
333 |
334 |
334 // Old algorithm had funny accumulating BC-size counters |
335 // Old algorithm had funny accumulating BC-size counters |
335 if (UseOldInlining && ClipInlining |
336 if (UseOldInlining && ClipInlining |
336 && (int)count_inline_bcs() >= DesiredMethodLimit) { |
337 && (int)count_inline_bcs() >= DesiredMethodLimit) { |
344 |
345 |
345 if (!should_inline(callee_method, caller_method, caller_bci, profile, |
346 if (!should_inline(callee_method, caller_method, caller_bci, profile, |
346 wci_result)) { |
347 wci_result)) { |
347 return false; |
348 return false; |
348 } |
349 } |
349 if (should_not_inline(callee_method, caller_method, wci_result)) { |
350 if (should_not_inline(callee_method, caller_method, jvms, wci_result)) { |
350 return false; |
351 return false; |
351 } |
352 } |
352 |
353 |
353 if (InlineAccessors && callee_method->is_accessor()) { |
354 if (InlineAccessors && callee_method->is_accessor()) { |
354 // accessor methods are not subject to any of the following limits. |
355 // accessor methods are not subject to any of the following limits. |
395 should_delay = true; |
396 should_delay = true; |
396 } |
397 } |
397 } |
398 } |
398 |
399 |
399 // detect direct and indirect recursive inlining |
400 // detect direct and indirect recursive inlining |
400 if (!callee_method->is_compiled_lambda_form()) { |
401 { |
401 // count the current method and the callee |
402 // count the current method and the callee |
402 int inline_level = (method() == callee_method) ? 1 : 0; |
403 const bool is_compiled_lambda_form = callee_method->is_compiled_lambda_form(); |
403 if (inline_level > MaxRecursiveInlineLevel) { |
404 int inline_level = 0; |
404 set_msg("recursively inlining too deep"); |
405 if (!is_compiled_lambda_form) { |
405 return false; |
406 if (method() == callee_method) { |
|
407 inline_level++; |
|
408 } |
406 } |
409 } |
407 // count callers of current method and callee |
410 // count callers of current method and callee |
408 JVMState* jvms = caller_jvms(); |
411 Node* callee_argument0 = is_compiled_lambda_form ? jvms->map()->argument(jvms, 0)->uncast() : NULL; |
409 while (jvms != NULL && jvms->has_method()) { |
412 for (JVMState* j = jvms->caller(); j != NULL && j->has_method(); j = j->caller()) { |
410 if (jvms->method() == callee_method) { |
413 if (j->method() == callee_method) { |
411 inline_level++; |
414 if (is_compiled_lambda_form) { |
412 if (inline_level > MaxRecursiveInlineLevel) { |
415 // Since compiled lambda forms are heavily reused we allow recursive inlining. If it is truly |
413 set_msg("recursively inlining too deep"); |
416 // a recursion (using the same "receiver") we limit inlining otherwise we can easily blow the |
414 return false; |
417 // compiler stack. |
|
418 Node* caller_argument0 = j->map()->argument(j, 0)->uncast(); |
|
419 if (caller_argument0 == callee_argument0) { |
|
420 inline_level++; |
|
421 } |
|
422 } else { |
|
423 inline_level++; |
415 } |
424 } |
416 } |
425 } |
417 jvms = jvms->caller(); |
426 } |
|
427 if (inline_level > MaxRecursiveInlineLevel) { |
|
428 set_msg("recursive inlining is too deep"); |
|
429 return false; |
418 } |
430 } |
419 } |
431 } |
420 |
432 |
421 int size = callee_method->code_size_for_inlining(); |
433 int size = callee_method->code_size_for_inlining(); |
422 |
434 |
534 } |
546 } |
535 |
547 |
536 // Check if inlining policy says no. |
548 // Check if inlining policy says no. |
537 WarmCallInfo wci = *(initial_wci); |
549 WarmCallInfo wci = *(initial_wci); |
538 bool success = try_to_inline(callee_method, caller_method, caller_bci, |
550 bool success = try_to_inline(callee_method, caller_method, caller_bci, |
539 profile, &wci, should_delay); |
551 jvms, profile, &wci, should_delay); |
540 |
552 |
541 #ifndef PRODUCT |
553 #ifndef PRODUCT |
542 if (UseOldInlining && InlineWarmCalls |
554 if (UseOldInlining && InlineWarmCalls |
543 && (PrintOpto || C->print_inlining())) { |
555 && (PrintOpto || C->print_inlining())) { |
544 bool cold = wci.is_cold(); |
556 bool cold = wci.is_cold(); |