Index: runtime/vm/code_generator.cc |
=================================================================== |
--- runtime/vm/code_generator.cc (revision 29013) |
+++ runtime/vm/code_generator.cc (working copy) |
@@ -1418,10 +1418,22 @@ |
ASSERT(caller_code.is_optimized()); |
const Function& target_function = Function::Handle( |
caller_code.GetStaticCallTargetFunctionAt(frame->pc())); |
- const Code& target_code = Code::Handle(target_function.CurrentCode()); |
- CodePatcher::PatchStaticCallAt(frame->pc(), caller_code, |
- target_code.EntryPoint()); |
- caller_code.SetStaticCallTargetCodeAt(frame->pc(), target_code); |
+ |
+ // Check whether the code object has been detached from the target function. |
+ // If it has been detached, reattach it. |
+ Code& target_code = Code::Handle(); |
+ if (target_function.HasCode()) { |
+ target_code ^= target_function.CurrentCode(); |
+ CodePatcher::PatchStaticCallAt(frame->pc(), caller_code, |
+ target_code.EntryPoint()); |
+ caller_code.SetStaticCallTargetCodeAt(frame->pc(), target_code); |
+ } else { |
+ ASSERT(target_function.unoptimized_code() == Code::null()); |
+ target_code ^= caller_code.GetStaticCallTargetCodeAt(frame->pc()); |
+ ASSERT(!target_code.IsNull()); |
+ ASSERT(!target_code.is_optimized()); |
+ target_function.ReattachCode(target_code); |
+ } |
if (FLAG_trace_patching) { |
OS::PrintErr("FixCallersTarget: patching from %#" Px " to '%s' %#" Px "\n", |
frame->pc(), |