Chromium Code Reviews| Index: runtime/vm/simulator_dbc.cc |
| diff --git a/runtime/vm/simulator_dbc.cc b/runtime/vm/simulator_dbc.cc |
| index baafca844ed13c442ee0d7286b0eec59e7583fd2..1534fd7b4a83d4be297d6a443b6fc9779fea71a7 100644 |
| --- a/runtime/vm/simulator_dbc.cc |
| +++ b/runtime/vm/simulator_dbc.cc |
| @@ -1966,54 +1966,59 @@ RawObject* Simulator::Call(const Code& code, |
| { |
| BYTECODE(Deopt, A_D); |
| const uint16_t deopt_id = rD; |
| - if (deopt_id == 0) { // Lazy deoptimization. |
| - // Preserve result of the previous call. |
| - // TODO(vegorov) we could have actually included result into the |
| - // deoptimization environment because it is passed through the stack. |
| - // If we do then we could remove special result handling from this code. |
| - RawObject* result = SP[0]; |
| - |
| - // Leaf runtime function DeoptimizeCopyFrame expects a Dart frame. |
| - // The code in this frame may not cause GC. |
| - // DeoptimizeCopyFrame and DeoptimizeFillFrame are leaf runtime calls. |
| - EnterSyntheticFrame(&FP, &SP, pc - 1); |
| - const intptr_t frame_size_in_bytes = |
| - DLRT_DeoptimizeCopyFrame(reinterpret_cast<uword>(FP), |
| - /*is_lazy_deopt=*/1); |
| - LeaveSyntheticFrame(&FP, &SP); |
| - |
| - SP = FP + (frame_size_in_bytes / kWordSize); |
| - EnterSyntheticFrame(&FP, &SP, pc - 1); |
| - DLRT_DeoptimizeFillFrame(reinterpret_cast<uword>(FP)); |
| - |
| - // We are now inside a valid frame. |
| - { |
| + const bool preserve_result = (deopt_id == 0); |
| + |
| + // Preserve result of the previous call. |
| + // TODO(vegorov) we could have actually included result into the |
| + // deoptimization environment because it is passed through the stack. |
| + // If we do then we could remove special result handling from this code. |
| + RawObject* result = SP[0]; |
|
Vyacheslav Egorov (Google)
2016/06/08 11:58:53
When not preserving result (non-lazy deopt) we nee
zra
2016/06/08 17:46:30
This and the fix below made things work.
|
| + |
| + // Leaf runtime function DeoptimizeCopyFrame expects a Dart frame. |
| + // The code in this frame may not cause GC. |
| + // DeoptimizeCopyFrame and DeoptimizeFillFrame are leaf runtime calls. |
| + EnterSyntheticFrame(&FP, &SP, pc - 1); |
|
zra
2016/06/07 22:31:29
I'm not sure I see how the locals from the optimiz
Vyacheslav Egorov (Google)
2016/06/08 11:58:53
If you look at the disassembled optimized code obj
zra
2016/06/08 17:46:30
Thanks!
|
| + const intptr_t frame_size_in_bytes = |
| + DLRT_DeoptimizeCopyFrame(reinterpret_cast<uword>(FP), |
| + /*is_lazy_deopt=*/ (deopt_id == 0) ? 1 : 0); |
| + LeaveSyntheticFrame(&FP, &SP); |
| + |
| + SP = FP + (frame_size_in_bytes / kWordSize); |
| + EnterSyntheticFrame(&FP, &SP, pc - 1); |
| + DLRT_DeoptimizeFillFrame(reinterpret_cast<uword>(FP)); |
| + |
| + // We are now inside a valid frame. |
| + { |
| + if (preserve_result) { |
| *++SP = result; // Preserve result (call below can cause GC). |
| - *++SP = 0; // Space for the result: number of materialization args. |
| - Exit(thread, FP, SP + 1, /*pc=*/0); |
| - NativeArguments native_args(thread, 0, SP, SP); |
| - INVOKE_RUNTIME(DRT_DeoptimizeMaterialize, native_args); |
| } |
| - const intptr_t materialization_arg_count = |
| - Smi::Value(RAW_CAST(Smi, *SP--)); |
| - result = *SP--; // Reload the result. It might have been relocated by GC. |
| - |
| - // Restore caller PC. |
| - pc = SavedCallerPC(FP); |
| - |
| - // Check if it is a fake PC marking the entry frame. |
| - ASSERT((reinterpret_cast<uword>(pc) & 2) == 0); |
| - |
| - // Restore SP, FP and PP. Push result and dispatch. |
| - // Note: unlike in a normal return sequence we don't need to drop |
| - // arguments - those are not part of the innermost deoptimization |
| - // environment they were dropped by FlowGraphCompiler::RecordAfterCall. |
| - SP = FrameArguments(FP, materialization_arg_count); |
| - FP = SavedCallerFP(FP); |
| - pp = SimulatorHelpers::FrameCode(FP)->ptr()->object_pool_->ptr(); |
| + *++SP = 0; // Space for the result: number of materialization args. |
| + Exit(thread, FP, SP + 1, /*pc=*/0); |
| + NativeArguments native_args(thread, 0, SP, SP); |
| + INVOKE_RUNTIME(DRT_DeoptimizeMaterialize, native_args); |
| + } |
| + const intptr_t materialization_arg_count = |
| + Smi::Value(RAW_CAST(Smi, *SP--)); |
| + if (preserve_result) { |
| + // Reload the result. It might have been relocated by GC. |
| + result = *SP--; |
| + } |
| + |
| + // Restore caller PC. |
| + pc = SavedCallerPC(FP); |
| + |
| + // Check if it is a fake PC marking the entry frame. |
| + ASSERT((reinterpret_cast<uword>(pc) & 2) == 0); |
| + |
| + // Restore SP, FP and PP. Push result and dispatch. |
| + // Note: unlike in a normal return sequence we don't need to drop |
| + // arguments - those are not part of the innermost deoptimization |
| + // environment they were dropped by FlowGraphCompiler::RecordAfterCall. |
| + SP = FrameArguments(FP, materialization_arg_count); |
|
Vyacheslav Egorov (Google)
2016/06/08 11:58:53
FrameArguments(FP, argc) points to the first argum
zra
2016/06/08 17:46:30
That makes sense, thanks.
|
| + FP = SavedCallerFP(FP); |
| + pp = SimulatorHelpers::FrameCode(FP)->ptr()->object_pool_->ptr(); |
| + if (preserve_result) { |
| *SP = result; |
| - } else { |
| - UNIMPLEMENTED(); |
| } |
| DISPATCH(); |
| } |