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) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode");
AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy());
Handle<Code> cached_code;
if (GetCodeFromOptimizedCodeCache(function, BailoutId::None())
.ToHandle(&cached_code)) {
if (FLAG_trace_opt) {
PrintF("[found optimized code for ");
function->ShortPrint();
PrintF(" during unoptimized compile]\n");
if (function->shared()->is_compiled()) {
// Function has already been compiled, get the optimized code if possible,
// otherwise return baseline code.
Handle<Code> cached_code;
if (GetCodeFromOptimizedCodeCache(function, BailoutId::None())
.ToHandle(&cached_code)) {
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() &&
function->shared()->marked_for_tier_up()) {
DCHECK(FLAG_mark_shared_functions_for_tier_up);
if (function->shared()->marked_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) {
PrintF("[optimizing method ");
function->ShortPrint();
PrintF(" eagerly (shared function marked for tier up)]\n");
}
if (FLAG_trace_opt) {
PrintF("[optimizing method ");
function->ShortPrint();
PrintF(" eagerly (shared function marked for tier up)]\n");
}
Handle<Code> code;
if (GetOptimizedCodeMaybeLater(function).ToHandle(&code)) {
return code;
Handle<Code> code;
if (GetOptimizedCodeMaybeLater(function).ToHandle(&code)) {
return code;
}
}
}
if (function->shared()->is_compiled()) {
return Handle<Code>(function->shared()->code());
}
if (function->shared()->HasBytecodeArray()) {
Handle<Code> entry = isolate->builtins()->InterpreterEntryTrampoline();
function->shared()->ReplaceCode(*entry);
return entry;
}
} else {
// Function doesn't have any baseline compiled code, compile now.
DCHECK(!function->shared()->HasBytecodeArray());
ParseInfo parse_info(handle(function->shared()));
Zone compile_zone(isolate->allocator(), ZONE_NAME);
CompilationInfo info(&compile_zone, &parse_info, isolate, function);
if (FLAG_experimental_preparser_scope_analysis) {
Handle<SharedFunctionInfo> shared(function->shared());
Handle<Script> script(Script::cast(function->shared()->script()));
if (script->HasPreparsedScopeData()) {
parse_info.preparsed_scope_data()->Deserialize(
script->preparsed_scope_data());
ParseInfo parse_info(handle(function->shared()));
Zone compile_zone(isolate->allocator(), ZONE_NAME);
CompilationInfo info(&compile_zone, &parse_info, isolate, function);
if (FLAG_experimental_preparser_scope_analysis) {
Handle<SharedFunctionInfo> shared(function->shared());
Handle<Script> script(Script::cast(function->shared()->script()));
if (script->HasPreparsedScopeData()) {
parse_info.preparsed_scope_data()->Deserialize(
script->preparsed_scope_data());
}
}
}
Compiler::ConcurrencyMode inner_function_mode =
FLAG_compiler_dispatcher_eager_inner ? Compiler::CONCURRENT
: Compiler::NOT_CONCURRENT;
Handle<Code> result;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, result, GetUnoptimizedCode(&info, inner_function_mode), Code);
if (FLAG_always_opt && !info.shared_info()->HasAsmWasmData()) {
Handle<Code> opt_code;
if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT)
.ToHandle(&opt_code)) {
result = opt_code;
Compiler::ConcurrencyMode inner_function_mode =
FLAG_compiler_dispatcher_eager_inner ? Compiler::CONCURRENT
: Compiler::NOT_CONCURRENT;
Handle<Code> result;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, result, GetUnoptimizedCode(&info, inner_function_mode), Code);
if (FLAG_always_opt && !info.shared_info()->HasAsmWasmData()) {
Handle<Code> opt_code;
if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT)
.ToHandle(&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