[TurboFan] Don't cache tagged templates in the feedback vector

In the rare case that a tagged template is not initialized before
optimization time, we currently cache this created template in the
feedback vector. If we stop doing this, we simplify the interface
usefully for concurrent compilation and pay little for it.

Bug: v8:7790
Change-Id: Ifc82b0eb931a706767596febd4f4b312e167fd25
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1690837
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62590}
This commit is contained in:
Mike Stanton 2019-07-09 10:06:56 +02:00 committed by Commit Bot
parent 925b17ba2f
commit c134e421a2
2 changed files with 56 additions and 1 deletions

View File

@ -2079,9 +2079,13 @@ void BytecodeGraphBuilder::VisitGetTemplateObject() {
// It's not observable when the template object is created, so we
// can just create it eagerly during graph building and bake in
// the JSArray constant here.
//
// It simplifies the compiler interface if we don't set this value
// in the feedback vector, especially as we consider concurrent
// compilation. We can count on the {cached_value} to be re-created
// later by bytecode if necessary.
cached_value = TemplateObjectDescription::GetTemplateObject(
isolate(), native_context(), description, shared_info(), slot.ToInt());
nexus.vector().Set(slot, *cached_value);
} else {
cached_value =
handle(JSArray::cast(nexus.GetFeedback()->GetHeapObjectAssumeStrong()),

View File

@ -0,0 +1,51 @@
// Copyright 2019 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
// Case One: the template is already initialized before compilation.
let saved_array;
function tagged_function(a) {
saved_array = a;
return "something";
}
function foo(b) {
let a = tagged_function`hello ${b}`;
return a + " " + b;
}
%PrepareFunctionForOptimization(foo);
foo();
foo();
%OptimizeFunctionOnNextCall(foo);
foo();
// Case Two: the template hasn't been initialized at the point we
// do optimized compile.
function bar(b) {
if (b) {
let a = tagged_function`initialized late ${b}`;
b = a;
}
return b;
}
%PrepareFunctionForOptimization(bar);
bar();
bar();
%OptimizeFunctionOnNextCall(bar);
bar(true);
let saved_array_from_optimized_call = saved_array;
// Finally, ensure that if the function is deoptimized, the tagged-template
// code still runs. This is useful to test because TurboFan doesn't cache
// the tagged template in the feedback vector if it has to create it.
%DeoptimizeFunction(bar);
bar(true);
// Furthermore, we want to ensure that the JSArray passed to the function
// is the same.
assertSame(saved_array_from_optimized_call, saved_array);