Chromium Code Reviews| Index: src/runtime.cc |
| diff --git a/src/runtime.cc b/src/runtime.cc |
| index 4830fafe35c323598e0bd6a49ed6f7a7ef6569ca..30250d587e84ec7bf403817fdd4ab8dfb0bcf506 100644 |
| --- a/src/runtime.cc |
| +++ b/src/runtime.cc |
| @@ -8506,7 +8506,11 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_OptimizeFunctionOnNextCall) { |
| unoptimized->kind() == Code::FUNCTION) { |
| CONVERT_ARG_HANDLE_CHECKED(String, type, 1); |
| if (type->IsOneByteEqualTo(STATIC_ASCII_VECTOR("osr"))) { |
| - for (int i = 0; i <= Code::kMaxLoopNestingMarker; i++) { |
| + // Start patching from the currently patched loop nesting level. |
| + int current_level = unoptimized->allow_osr_at_loop_nesting_level(); |
| + ASSERT(Deoptimizer::VerifyInterruptCode( |
| + isolate, unoptimized, current_level)); |
| + for (int i = current_level + 1; i <= Code::kMaxLoopNestingMarker; i++) { |
| unoptimized->set_allow_osr_at_loop_nesting_level(i); |
| isolate->runtime_profiler()->AttemptOnStackReplacement(*function); |
| } |
| @@ -8580,98 +8584,20 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileForOnStackReplacement) { |
| // We're not prepared to handle a function with arguments object. |
| ASSERT(!function->shared()->uses_arguments()); |
| - // We have hit a back edge in an unoptimized frame for a function that was |
| - // selected for on-stack replacement. Find the unoptimized code object. |
| - Handle<Code> unoptimized(function->shared()->code(), isolate); |
| - // Keep track of whether we've succeeded in optimizing. |
| - bool succeeded = unoptimized->optimizable(); |
| - if (succeeded) { |
| - // If we are trying to do OSR when there are already optimized |
| - // activations of the function, it means (a) the function is directly or |
| - // indirectly recursive and (b) an optimized invocation has been |
| - // deoptimized so that we are currently in an unoptimized activation. |
| - // Check for optimized activations of this function. |
| - JavaScriptFrameIterator it(isolate); |
| - while (succeeded && !it.done()) { |
| - JavaScriptFrame* frame = it.frame(); |
| - succeeded = !frame->is_optimized() || frame->function() != *function; |
| - it.Advance(); |
| - } |
| - } |
| - |
|
titzer
2013/09/02 17:03:35
Ah, now I see where this code came from. Why is th
Yang
2013/09/03 08:50:10
I'll have the builtin fetch the pc from stack, sub
|
| - BailoutId ast_id = BailoutId::None(); |
| - if (succeeded) { |
| - // The top JS function is this one, the PC is somewhere in the |
| - // unoptimized code. |
| - JavaScriptFrameIterator it(isolate); |
| - JavaScriptFrame* frame = it.frame(); |
| - ASSERT(frame->function() == *function); |
| - ASSERT(frame->LookupCode() == *unoptimized); |
| - ASSERT(unoptimized->contains(frame->pc())); |
| - |
| - // Use linear search of the unoptimized code's back edge table to find |
| - // the AST id matching the PC. |
| - uint32_t target_pc_offset = |
| - static_cast<uint32_t>(frame->pc() - unoptimized->instruction_start()); |
| - uint32_t loop_depth = 0; |
| - |
| - for (FullCodeGenerator::BackEdgeTableIterator back_edges(*unoptimized); |
| - !back_edges.Done(); |
| - back_edges.Next()) { |
| - if (back_edges.pc_offset() == target_pc_offset) { |
| - ast_id = back_edges.ast_id(); |
| - loop_depth = back_edges.loop_depth(); |
| - break; |
| - } |
| - } |
| - ASSERT(!ast_id.IsNone()); |
| - |
| - if (FLAG_trace_osr) { |
| - PrintF("[replacing on-stack at AST id %d, loop depth %d in ", |
| - ast_id.ToInt(), loop_depth); |
| - function->PrintName(); |
| - PrintF("]\n"); |
| - } |
| - |
| - // Try to compile the optimized code. A true return value from |
| - // CompileOptimized means that compilation succeeded, not necessarily |
| - // that optimization succeeded. |
| - if (JSFunction::CompileOptimized(function, ast_id, CLEAR_EXCEPTION) && |
| - function->IsOptimized()) { |
| - DeoptimizationInputData* data = DeoptimizationInputData::cast( |
| - function->code()->deoptimization_data()); |
| - if (data->OsrPcOffset()->value() >= 0) { |
| - if (FLAG_trace_osr) { |
| - PrintF("[on-stack replacement offset %d in optimized code]\n", |
| - data->OsrPcOffset()->value()); |
| - } |
| - ASSERT(BailoutId(data->OsrAstId()->value()) == ast_id); |
| - } else { |
| - // We may never generate the desired OSR entry if we emit an |
| - // early deoptimize. |
| - succeeded = false; |
| - } |
| - } else { |
| - succeeded = false; |
| - } |
| - } |
| - |
| - // Revert to the original interrupt calls in the original unoptimized code. |
| - if (FLAG_trace_osr) { |
| - PrintF("[restoring original interrupt calls in "); |
| - function->PrintName(); |
| - PrintF("]\n"); |
| - } |
| - Deoptimizer::RevertInterruptCode(isolate, *unoptimized); |
| - |
| // If the optimization attempt succeeded, return the AST id tagged as a |
| // smi. This tells the builtin that we need to translate the unoptimized |
| // frame to an optimized one. |
| - if (succeeded) { |
| + BailoutId ast_id = BailoutId::None(); |
| + bool success = |
| + (FLAG_concurrent_recompilation && FLAG_speculative_concurrent_osr) |
| + ? Compiler::CompileForConcurrentOSR(function, &ast_id) |
| + : Compiler::CompileForOnStackReplacement(function, &ast_id); |
| + if (success) { |
| ASSERT(function->code()->kind() == Code::OPTIMIZED_FUNCTION); |
| return Smi::FromInt(ast_id.ToInt()); |
| } else { |
| - if (function->IsMarkedForLazyRecompilation()) { |
| + if (function->IsMarkedForLazyRecompilation() || |
| + function->IsMarkedForConcurrentRecompilation()) { |
| function->ReplaceCode(function->shared()->code()); |
| } |
| return Smi::FromInt(-1); |