8011138: C2: stack overflow in compiler thread because of recursive inlining of lambda form methods

Reviewed-by: kvn, roland
This commit is contained in:
Christian Thalinger 2013-10-04 10:11:48 -07:00
parent 02e57a0152
commit bfc53b6607
2 changed files with 31 additions and 17 deletions

View File

@ -197,6 +197,7 @@ bool InlineTree::should_inline(ciMethod* callee_method, ciMethod* caller_method,
// negative filter: should callee NOT be inlined? // negative filter: should callee NOT be inlined?
bool InlineTree::should_not_inline(ciMethod *callee_method, bool InlineTree::should_not_inline(ciMethod *callee_method,
ciMethod* caller_method, ciMethod* caller_method,
JVMState* jvms,
WarmCallInfo* wci_result) { WarmCallInfo* wci_result) {
const char* fail_msg = NULL; const char* fail_msg = NULL;
@ -226,7 +227,7 @@ bool InlineTree::should_not_inline(ciMethod *callee_method,
// don't inline exception code unless the top method belongs to an // don't inline exception code unless the top method belongs to an
// exception class // exception class
if (callee_method->holder()->is_subclass_of(C->env()->Throwable_klass())) { if (callee_method->holder()->is_subclass_of(C->env()->Throwable_klass())) {
ciMethod* top_method = caller_jvms() ? caller_jvms()->of_depth(1)->method() : method(); ciMethod* top_method = jvms->caller() != NULL ? jvms->caller()->of_depth(1)->method() : method();
if (!top_method->holder()->is_subclass_of(C->env()->Throwable_klass())) { if (!top_method->holder()->is_subclass_of(C->env()->Throwable_klass())) {
wci_result->set_profit(wci_result->profit() * 0.1); wci_result->set_profit(wci_result->profit() * 0.1);
} }
@ -328,7 +329,7 @@ bool InlineTree::should_not_inline(ciMethod *callee_method,
// return true if ok // return true if ok
// Relocated from "InliningClosure::try_to_inline" // Relocated from "InliningClosure::try_to_inline"
bool InlineTree::try_to_inline(ciMethod* callee_method, ciMethod* caller_method, bool InlineTree::try_to_inline(ciMethod* callee_method, ciMethod* caller_method,
int caller_bci, ciCallProfile& profile, int caller_bci, JVMState* jvms, ciCallProfile& profile,
WarmCallInfo* wci_result, bool& should_delay) { WarmCallInfo* wci_result, bool& should_delay) {
// Old algorithm had funny accumulating BC-size counters // Old algorithm had funny accumulating BC-size counters
@ -346,7 +347,7 @@ bool InlineTree::try_to_inline(ciMethod* callee_method, ciMethod* caller_method,
wci_result)) { wci_result)) {
return false; return false;
} }
if (should_not_inline(callee_method, caller_method, wci_result)) { if (should_not_inline(callee_method, caller_method, jvms, wci_result)) {
return false; return false;
} }
@ -397,24 +398,35 @@ bool InlineTree::try_to_inline(ciMethod* callee_method, ciMethod* caller_method,
} }
// detect direct and indirect recursive inlining // detect direct and indirect recursive inlining
if (!callee_method->is_compiled_lambda_form()) { {
// count the current method and the callee // count the current method and the callee
int inline_level = (method() == callee_method) ? 1 : 0; const bool is_compiled_lambda_form = callee_method->is_compiled_lambda_form();
if (inline_level > MaxRecursiveInlineLevel) { int inline_level = 0;
set_msg("recursively inlining too deep"); if (!is_compiled_lambda_form) {
return false; if (method() == callee_method) {
inline_level++;
}
} }
// count callers of current method and callee // count callers of current method and callee
JVMState* jvms = caller_jvms(); Node* callee_argument0 = is_compiled_lambda_form ? jvms->map()->argument(jvms, 0)->uncast() : NULL;
while (jvms != NULL && jvms->has_method()) { for (JVMState* j = jvms->caller(); j != NULL && j->has_method(); j = j->caller()) {
if (jvms->method() == callee_method) { if (j->method() == callee_method) {
inline_level++; if (is_compiled_lambda_form) {
if (inline_level > MaxRecursiveInlineLevel) { // Since compiled lambda forms are heavily reused we allow recursive inlining. If it is truly
set_msg("recursively inlining too deep"); // a recursion (using the same "receiver") we limit inlining otherwise we can easily blow the
return false; // compiler stack.
Node* caller_argument0 = j->map()->argument(j, 0)->uncast();
if (caller_argument0 == callee_argument0) {
inline_level++;
}
} else {
inline_level++;
} }
} }
jvms = jvms->caller(); }
if (inline_level > MaxRecursiveInlineLevel) {
set_msg("recursive inlining is too deep");
return false;
} }
} }
@ -536,7 +548,7 @@ WarmCallInfo* InlineTree::ok_to_inline(ciMethod* callee_method, JVMState* jvms,
// Check if inlining policy says no. // Check if inlining policy says no.
WarmCallInfo wci = *(initial_wci); WarmCallInfo wci = *(initial_wci);
bool success = try_to_inline(callee_method, caller_method, caller_bci, bool success = try_to_inline(callee_method, caller_method, caller_bci,
profile, &wci, should_delay); jvms, profile, &wci, should_delay);
#ifndef PRODUCT #ifndef PRODUCT
if (UseOldInlining && InlineWarmCalls if (UseOldInlining && InlineWarmCalls

View File

@ -73,6 +73,7 @@ protected:
bool try_to_inline(ciMethod* callee_method, bool try_to_inline(ciMethod* callee_method,
ciMethod* caller_method, ciMethod* caller_method,
int caller_bci, int caller_bci,
JVMState* jvms,
ciCallProfile& profile, ciCallProfile& profile,
WarmCallInfo* wci_result, WarmCallInfo* wci_result,
bool& should_delay); bool& should_delay);
@ -83,6 +84,7 @@ protected:
WarmCallInfo* wci_result); WarmCallInfo* wci_result);
bool should_not_inline(ciMethod* callee_method, bool should_not_inline(ciMethod* callee_method,
ciMethod* caller_method, ciMethod* caller_method,
JVMState* jvms,
WarmCallInfo* wci_result); WarmCallInfo* wci_result);
void print_inlining(ciMethod* callee_method, int caller_bci, void print_inlining(ciMethod* callee_method, int caller_bci,
bool success) const; bool success) const;