Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
8259276: C2: Empty expression stack when reexecuting tableswitch/look…
Browse files Browse the repository at this point in the history
…upswitch instructions after deoptimization

Reviewed-by: dlong, kvn, thartmann
  • Loading branch information
Vladimir Ivanov committed Jan 25, 2021
1 parent c5ab7c3 commit 81e730e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/hotspot/share/opto/graphKit.cpp
Expand Up @@ -823,8 +823,7 @@ bool GraphKit::dead_locals_are_killed() {

#endif //ASSERT

// Helper function for enforcing certain bytecodes to reexecute if
// deoptimization happens
// Helper function for enforcing certain bytecodes to reexecute if deoptimization happens.
static bool should_reexecute_implied_by_bytecode(JVMState *jvms, bool is_anewarray) {
ciMethod* cur_method = jvms->method();
int cur_bci = jvms->bci();
Expand All @@ -839,8 +838,9 @@ static bool should_reexecute_implied_by_bytecode(JVMState *jvms, bool is_anewarr
// is limited by dimensions and guarded by flag so in some cases
// multianewarray() runtime calls will be generated and
// the bytecode should not be reexecutes (stack will not be reset).
} else
} else {
return false;
}
}

// Helper function for adding JVMState and debug information to node
Expand Down Expand Up @@ -894,6 +894,12 @@ void GraphKit::add_safepoint_edges(SafePointNode* call, bool must_throw) {
// deoptimization happens. We set the reexecute state for them here
if (out_jvms->is_reexecute_undefined() && //don't change if already specified
should_reexecute_implied_by_bytecode(out_jvms, call->is_AllocateArray())) {
#ifdef ASSERT
int inputs = 0, not_used; // initialized by GraphKit::compute_stack_effects()
assert(method() == youngest_jvms->method(), "sanity");
assert(compute_stack_effects(inputs, not_used), "unknown bytecode: %s", Bytecodes::name(java_bc()));
assert(out_jvms->sp() >= (uint)inputs, "not enough operands for reexecution");
#endif // ASSERT
out_jvms->set_should_reexecute(true); //NOTE: youngest_jvms not changed
}

Expand Down
12 changes: 8 additions & 4 deletions src/hotspot/share/opto/parse2.cpp
Expand Up @@ -419,7 +419,6 @@ static void merge_ranges(SwitchRange* ranges, int& rp) {

//-------------------------------do_tableswitch--------------------------------
void Parse::do_tableswitch() {
Node* lookup = pop();
// Get information about tableswitch
int default_dest = iter().get_dest_table(0);
int lo_index = iter().get_int_table(1);
Expand All @@ -429,6 +428,7 @@ void Parse::do_tableswitch() {
if (len < 1) {
// If this is a backward branch, add safepoint
maybe_add_safepoint(default_dest);
pop(); // the effect of the instruction execution on the operand stack
merge(default_dest);
return;
}
Expand Down Expand Up @@ -485,22 +485,24 @@ void Parse::do_tableswitch() {
}

// Safepoint in case if backward branch observed
if( makes_backward_branch && UseLoopSafepoints )
if (makes_backward_branch && UseLoopSafepoints) {
add_safepoint();
}

Node* lookup = pop(); // lookup value
jump_switch_ranges(lookup, &ranges[0], &ranges[rp]);
}


//------------------------------do_lookupswitch--------------------------------
void Parse::do_lookupswitch() {
Node *lookup = pop(); // lookup value
// Get information about lookupswitch
int default_dest = iter().get_dest_table(0);
int len = iter().get_int_table(1);

if (len < 1) { // If this is a backward branch, add safepoint
maybe_add_safepoint(default_dest);
pop(); // the effect of the instruction execution on the operand stack
merge(default_dest);
return;
}
Expand Down Expand Up @@ -577,9 +579,11 @@ void Parse::do_lookupswitch() {
}

// Safepoint in case backward branch observed
if (makes_backward_branch && UseLoopSafepoints)
if (makes_backward_branch && UseLoopSafepoints) {
add_safepoint();
}

Node *lookup = pop(); // lookup value
jump_switch_ranges(lookup, &ranges[0], &ranges[rp]);
}

Expand Down

1 comment on commit 81e730e

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.