2019-11-18 19:11:06 +00:00
|
|
|
// 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.
|
|
|
|
|
2022-04-28 14:22:23 +00:00
|
|
|
// Flags: --allow-natives-syntax --turbofan --no-always-turbofan
|
2021-08-10 08:33:17 +00:00
|
|
|
// Flags: --concurrent-recompilation
|
2019-11-18 19:11:06 +00:00
|
|
|
|
|
|
|
function foo(x) { bar(x) }
|
|
|
|
function bar(x) { x.p }
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
%PrepareFunctionForOptimization(bar);
|
|
|
|
|
|
|
|
// Create map transitions such that a's final map is not stable.
|
|
|
|
var dummy = [];
|
|
|
|
dummy.p = 0;
|
|
|
|
dummy.q = 0;
|
|
|
|
|
|
|
|
var a = [];
|
|
|
|
a.p = 42;
|
|
|
|
|
|
|
|
var b = [];
|
|
|
|
b.p = 42;
|
|
|
|
|
|
|
|
// Warm-up.
|
|
|
|
foo(a);
|
|
|
|
foo(a);
|
|
|
|
|
|
|
|
// Trigger optimization of bar but don't yet complete it.
|
2021-08-10 08:33:17 +00:00
|
|
|
%DisableOptimizationFinalization();
|
2019-11-18 19:11:06 +00:00
|
|
|
%OptimizeFunctionOnNextCall(bar, "concurrent");
|
|
|
|
foo(a);
|
|
|
|
%PrepareFunctionForOptimization(bar);
|
2021-08-10 08:33:17 +00:00
|
|
|
%WaitForBackgroundOptimization();
|
2019-11-18 19:11:06 +00:00
|
|
|
|
|
|
|
// Change a's map from PACKED_SMI_ELEMENTS to PACKED_ELEMENTS and run bar in the
|
|
|
|
// interpreter (via foo) s.t. bar's load feedback changes accordingly.
|
|
|
|
a[0] = {};
|
|
|
|
foo(a);
|
2021-08-10 08:33:17 +00:00
|
|
|
assertUnoptimized(bar);
|
2019-11-18 19:11:06 +00:00
|
|
|
|
|
|
|
// Now finish the optimization of bar, which was based on the old
|
|
|
|
// PACKED_SMI_ELEMENTS feedback.
|
2021-08-10 08:33:17 +00:00
|
|
|
%FinalizeOptimization();
|
2019-11-18 19:11:06 +00:00
|
|
|
assertOptimized(bar);
|
|
|
|
// If we were to call the optimized bar now, it would deopt.
|
|
|
|
|
|
|
|
// Instead we trigger optimization of foo, which will inline bar (this time
|
|
|
|
// based on the new PACKED_ELEMENTS map.
|
2022-02-23 13:48:02 +00:00
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
2019-11-18 19:11:06 +00:00
|
|
|
foo(a);
|
|
|
|
assertOptimized(foo);
|
|
|
|
%PrepareFunctionForOptimization(foo);
|
|
|
|
assertOptimized(bar);
|
|
|
|
|
|
|
|
// Now call the optimized foo on an object that has the old PACKED_SMI_ELEMENTS
|
|
|
|
// map. This will lead to an eager deopt of foo when the inlined bar sees that
|
|
|
|
// old map.
|
|
|
|
foo(b);
|
|
|
|
assertUnoptimized(foo);
|
|
|
|
assertOptimized(bar);
|
|
|
|
|
|
|
|
// Now ensure there is no deopt-loop. There used to be a deopt-loop because, as
|
|
|
|
// a result of over-eager checkpoint elimination, we used to deopt into foo
|
|
|
|
// (right before the call to bar) rather than into bar (right before the load).
|
2022-02-23 13:48:02 +00:00
|
|
|
%OptimizeFunctionOnNextCall(foo);
|
2019-11-18 19:11:06 +00:00
|
|
|
foo(b);
|
|
|
|
assertOptimized(foo);
|