diff options
Diffstat (limited to 'deps/v8/src/runtime/runtime-compiler.cc')
-rw-r--r-- | deps/v8/src/runtime/runtime-compiler.cc | 119 |
1 files changed, 24 insertions, 95 deletions
diff --git a/deps/v8/src/runtime/runtime-compiler.cc b/deps/v8/src/runtime/runtime-compiler.cc index 263c4f9e77..89a6fa15d2 100644 --- a/deps/v8/src/runtime/runtime-compiler.cc +++ b/deps/v8/src/runtime/runtime-compiler.cc @@ -21,6 +21,7 @@ RUNTIME_FUNCTION(Runtime_CompileLazy) { HandleScope scope(isolate); DCHECK(args.length() == 1); CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); + #ifdef DEBUG if (FLAG_trace_lazy && !function->shared()->is_compiled()) { PrintF("[unoptimized: "); @@ -28,63 +29,28 @@ RUNTIME_FUNCTION(Runtime_CompileLazy) { PrintF("]\n"); } #endif - StackLimitCheck check(isolate); - if (check.JsHasOverflowed(1 * KB)) return isolate->StackOverflow(); - // Compile the target function. - DCHECK(function->shared()->allows_lazy_compilation()); - - Handle<Code> code; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, code, - Compiler::GetLazyCode(function)); - DCHECK(code->IsJavaScriptCode()); - - function->ReplaceCode(*code); - return *code; -} - - -namespace { - -Object* CompileOptimized(Isolate* isolate, Handle<JSFunction> function, - Compiler::ConcurrencyMode mode) { StackLimitCheck check(isolate); if (check.JsHasOverflowed(1 * KB)) return isolate->StackOverflow(); - - Handle<Code> code; - if (Compiler::GetOptimizedCode(function, mode).ToHandle(&code)) { - // Optimization succeeded, return optimized code. - function->ReplaceCode(*code); - } else { - // Optimization failed, get unoptimized code. - if (isolate->has_pending_exception()) { // Possible stack overflow. - return isolate->heap()->exception(); - } - code = Handle<Code>(function->shared()->code(), isolate); - if (code->kind() != Code::FUNCTION && - code->kind() != Code::OPTIMIZED_FUNCTION) { - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate, code, Compiler::GetUnoptimizedCode(function)); - } - function->ReplaceCode(*code); + if (!Compiler::Compile(function, Compiler::KEEP_EXCEPTION)) { + return isolate->heap()->exception(); } - - DCHECK(function->code()->kind() == Code::FUNCTION || - function->code()->kind() == Code::OPTIMIZED_FUNCTION || - (function->code()->is_interpreter_entry_trampoline() && - function->shared()->HasBytecodeArray()) || - function->IsInOptimizationQueue()); + DCHECK(function->is_compiled()); return function->code(); } -} // namespace - RUNTIME_FUNCTION(Runtime_CompileOptimized_Concurrent) { HandleScope scope(isolate); DCHECK(args.length() == 1); CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); - return CompileOptimized(isolate, function, Compiler::CONCURRENT); + StackLimitCheck check(isolate); + if (check.JsHasOverflowed(1 * KB)) return isolate->StackOverflow(); + if (!Compiler::CompileOptimized(function, Compiler::CONCURRENT)) { + return isolate->heap()->exception(); + } + DCHECK(function->is_compiled()); + return function->code(); } @@ -92,7 +58,13 @@ RUNTIME_FUNCTION(Runtime_CompileOptimized_NotConcurrent) { HandleScope scope(isolate); DCHECK(args.length() == 1); CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); - return CompileOptimized(isolate, function, Compiler::NOT_CONCURRENT); + StackLimitCheck check(isolate); + if (check.JsHasOverflowed(1 * KB)) return isolate->StackOverflow(); + if (!Compiler::CompileOptimized(function, Compiler::NOT_CONCURRENT)) { + return isolate->heap()->exception(); + } + DCHECK(function->is_compiled()); + return function->code(); } @@ -150,10 +122,6 @@ RUNTIME_FUNCTION(Runtime_NotifyDeoptimized) { deoptimizer->MaterializeHeapObjects(&it); delete deoptimizer; - JavaScriptFrame* frame = it.frame(); - RUNTIME_ASSERT(frame->function()->IsJSFunction()); - DCHECK(frame->function() == *function); - // Ensure the context register is updated for materialized objects. JavaScriptFrameIterator top_it(isolate); JavaScriptFrame* top_frame = top_it.frame(); @@ -163,7 +131,10 @@ RUNTIME_FUNCTION(Runtime_NotifyDeoptimized) { return isolate->heap()->undefined_value(); } - // Search for other activations of the same function and code. + // Search for other activations of the same optimized code. + // At this point {it} is at the topmost frame of all the frames materialized + // by the deoptimizer. Note that this frame does not necessarily represent + // an activation of {function} because of potential inlined tail-calls. ActivationsFinder activations_finder(*optimized_code); activations_finder.VisitFrames(&it); isolate->thread_manager()->IterateArchivedThreads(&activations_finder); @@ -240,59 +211,17 @@ RUNTIME_FUNCTION(Runtime_CompileForOnStackReplacement) { DCHECK(caller_code->contains(frame->pc())); #endif // DEBUG - BailoutId ast_id = caller_code->TranslatePcOffsetToAstId(pc_offset); DCHECK(!ast_id.IsNone()); - // Disable concurrent OSR for asm.js, to enable frame specialization. - Compiler::ConcurrencyMode mode = (isolate->concurrent_osr_enabled() && - !function->shared()->asm_function() && - function->shared()->ast_node_count() > 512) - ? Compiler::CONCURRENT - : Compiler::NOT_CONCURRENT; - - OptimizedCompileJob* job = NULL; - if (mode == Compiler::CONCURRENT) { - // Gate the OSR entry with a stack check. - BackEdgeTable::AddStackCheck(caller_code, pc_offset); - // Poll already queued compilation jobs. - OptimizingCompileDispatcher* dispatcher = - isolate->optimizing_compile_dispatcher(); - if (dispatcher->IsQueuedForOSR(function, ast_id)) { - if (FLAG_trace_osr) { - PrintF("[OSR - Still waiting for queued: "); - function->PrintName(); - PrintF(" at AST id %d]\n", ast_id.ToInt()); - } - return NULL; - } - - job = dispatcher->FindReadyOSRCandidate(function, ast_id); - } - MaybeHandle<Code> maybe_result; - if (job != NULL) { - if (FLAG_trace_osr) { - PrintF("[OSR - Found ready: "); - function->PrintName(); - PrintF(" at AST id %d]\n", ast_id.ToInt()); - } - maybe_result = Compiler::GetConcurrentlyOptimizedCode(job); - } else if (IsSuitableForOnStackReplacement(isolate, function)) { + if (IsSuitableForOnStackReplacement(isolate, function)) { if (FLAG_trace_osr) { PrintF("[OSR - Compiling: "); function->PrintName(); PrintF(" at AST id %d]\n", ast_id.ToInt()); } - maybe_result = Compiler::GetOptimizedCode( - function, mode, ast_id, - (mode == Compiler::NOT_CONCURRENT) ? frame : nullptr); - Handle<Code> result; - if (maybe_result.ToHandle(&result) && - result.is_identical_to(isolate->builtins()->InOptimizationQueue())) { - // Optimization is queued. Return to check later. - return NULL; - } + maybe_result = Compiler::GetOptimizedCodeForOSR(function, ast_id, frame); } // Revert the patched back edge table, regardless of whether OSR succeeds. |