Commit 4e43fc65 authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[Compiler] Only look in optimized code cache if function is compiled.

We make assumptions that baseline code exists if we run the optimized code
(e.g., to deopt to the baseline code). If the baseline code has been
cleared by code flushing (only full-codegen) then it might not exist
but there is still optimized code in the map.

BUG=v8:6389

Change-Id: Id4db664afee96c2da3a36a177f425293aae9a0a3
Reviewed-on: https://chromium-review.googlesource.com/503010Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45278}
parent fe9c60c1
...@@ -1051,73 +1051,71 @@ MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) { ...@@ -1051,73 +1051,71 @@ MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode"); TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode");
AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy()); AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy());
Handle<Code> cached_code; if (function->shared()->is_compiled()) {
if (GetCodeFromOptimizedCodeCache(function, BailoutId::None()) // Function has already been compiled, get the optimized code if possible,
.ToHandle(&cached_code)) { // otherwise return baseline code.
if (FLAG_trace_opt) { Handle<Code> cached_code;
PrintF("[found optimized code for "); if (GetCodeFromOptimizedCodeCache(function, BailoutId::None())
function->ShortPrint(); .ToHandle(&cached_code)) {
PrintF(" during unoptimized compile]\n"); if (FLAG_trace_opt) {
PrintF("[found optimized code for ");
function->ShortPrint();
PrintF(" during unoptimized compile]\n");
}
DCHECK(function->shared()->is_compiled());
return cached_code;
} }
DCHECK(function->shared()->is_compiled());
return cached_code;
}
if (function->shared()->is_compiled() && if (function->shared()->marked_for_tier_up()) {
function->shared()->marked_for_tier_up()) { DCHECK(FLAG_mark_shared_functions_for_tier_up);
DCHECK(FLAG_mark_shared_functions_for_tier_up);
function->shared()->set_marked_for_tier_up(false); function->shared()->set_marked_for_tier_up(false);
if (FLAG_trace_opt) { if (FLAG_trace_opt) {
PrintF("[optimizing method "); PrintF("[optimizing method ");
function->ShortPrint(); function->ShortPrint();
PrintF(" eagerly (shared function marked for tier up)]\n"); PrintF(" eagerly (shared function marked for tier up)]\n");
} }
Handle<Code> code; Handle<Code> code;
if (GetOptimizedCodeMaybeLater(function).ToHandle(&code)) { if (GetOptimizedCodeMaybeLater(function).ToHandle(&code)) {
return code; return code;
}
} }
}
if (function->shared()->is_compiled()) {
return Handle<Code>(function->shared()->code()); return Handle<Code>(function->shared()->code());
} } else {
// Function doesn't have any baseline compiled code, compile now.
if (function->shared()->HasBytecodeArray()) { DCHECK(!function->shared()->HasBytecodeArray());
Handle<Code> entry = isolate->builtins()->InterpreterEntryTrampoline();
function->shared()->ReplaceCode(*entry);
return entry;
}
ParseInfo parse_info(handle(function->shared())); ParseInfo parse_info(handle(function->shared()));
Zone compile_zone(isolate->allocator(), ZONE_NAME); Zone compile_zone(isolate->allocator(), ZONE_NAME);
CompilationInfo info(&compile_zone, &parse_info, isolate, function); CompilationInfo info(&compile_zone, &parse_info, isolate, function);
if (FLAG_experimental_preparser_scope_analysis) { if (FLAG_experimental_preparser_scope_analysis) {
Handle<SharedFunctionInfo> shared(function->shared()); Handle<SharedFunctionInfo> shared(function->shared());
Handle<Script> script(Script::cast(function->shared()->script())); Handle<Script> script(Script::cast(function->shared()->script()));
if (script->HasPreparsedScopeData()) { if (script->HasPreparsedScopeData()) {
parse_info.preparsed_scope_data()->Deserialize( parse_info.preparsed_scope_data()->Deserialize(
script->preparsed_scope_data()); script->preparsed_scope_data());
}
} }
} Compiler::ConcurrencyMode inner_function_mode =
Compiler::ConcurrencyMode inner_function_mode = FLAG_compiler_dispatcher_eager_inner ? Compiler::CONCURRENT
FLAG_compiler_dispatcher_eager_inner ? Compiler::CONCURRENT : Compiler::NOT_CONCURRENT;
: Compiler::NOT_CONCURRENT; Handle<Code> result;
Handle<Code> result; ASSIGN_RETURN_ON_EXCEPTION(
ASSIGN_RETURN_ON_EXCEPTION( isolate, result, GetUnoptimizedCode(&info, inner_function_mode), Code);
isolate, result, GetUnoptimizedCode(&info, inner_function_mode), Code);
if (FLAG_always_opt && !info.shared_info()->HasAsmWasmData()) {
if (FLAG_always_opt && !info.shared_info()->HasAsmWasmData()) { Handle<Code> opt_code;
Handle<Code> opt_code; if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT)
if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT) .ToHandle(&opt_code)) {
.ToHandle(&opt_code)) { result = opt_code;
result = opt_code; }
} }
}
return result; return result;
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment