[interpreter] Fix canonicalization when preserving bytecode.

This fixes canonicalization of {SharedFunctionInfo} objects in the
{Compiler::GetSharedFunctionInfo} method when bytecode is preserved.
Eager compilation is only triggered when no code is present.

R=rmcilroy@chromium.org
TEST=mjsunit/regress/regress-crbug-638551
BUG=chromium:638551

Review-Url: https://codereview.chromium.org/2245263006
Cr-Commit-Position: refs/heads/master@{#38709}
This commit is contained in:
mstarzinger 2016-08-18 03:42:30 -07:00 committed by Commit bot
parent 0a0285bf5d
commit 8ab555cc15
2 changed files with 28 additions and 8 deletions

View File

@ -1758,16 +1758,18 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo(
maybe_existing = script->FindSharedFunctionInfo(literal); maybe_existing = script->FindSharedFunctionInfo(literal);
} }
// We found an existing shared function info. If it's already compiled, // We found an existing shared function info. If it has any sort of code
// don't worry about compiling it, and simply return it. If it's not yet // attached, don't worry about compiling and simply return it. Otherwise,
// compiled, continue to decide whether to eagerly compile. // continue to decide whether to eagerly compile.
// Carry on if we are compiling eager to obtain code for debugging, // Note that we also carry on if we are compiling eager to obtain code for
// unless we already have code with debut break slots. // debugging, unless we already have code with debug break slots.
Handle<SharedFunctionInfo> existing; Handle<SharedFunctionInfo> existing;
if (maybe_existing.ToHandle(&existing) && existing->is_compiled()) { if (maybe_existing.ToHandle(&existing)) {
DCHECK(!existing->is_toplevel()); DCHECK(!existing->is_toplevel());
if (!outer_info->is_debug() || existing->HasDebugCode()) { if (existing->HasBaselineCode() || existing->HasBytecodeArray()) {
return existing; if (!outer_info->is_debug() || existing->HasDebugCode()) {
return existing;
}
} }
} }

View File

@ -0,0 +1,18 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --expose-gc --ignition-staging --no-lazy
function f() {
for (var i = 0; i < 10; i++) if (i == 5) %OptimizeOsr();
function g() {}
%OptimizeFunctionOnNextCall(g);
g();
}
f();
gc(); // Make sure that ...
gc(); // ... code flushing ...
gc(); // ... clears code ...
gc(); // ... attached to {g}.
f();