v8/test/mjsunit/compiler/constant-fold-cow-array.js
Benedikt Meurer 745ae2d8d7 [turbofan] Constant-fold loads from known copy-on-write arrays.
When accessing elements of a global (constant) JSArray, whose backing
store is copy-on-write, we can just constant-fold the value and insert
a check that the backing store stays the same.

Bug: v8:6816, v8:6815
Change-Id: I090bcec7b1ce72a1f9ed8625680ed91e8c67f27f
Reviewed-on: https://chromium-review.googlesource.com/662757
Reviewed-by: Yang Guo <yangguo@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47963}
2017-09-12 07:15:10 +00:00

36 lines
1.0 KiB
JavaScript

// Copyright 2017 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 --no-always-opt --opt
// Check that we properly deoptimize TurboFan'ed code when we constant-fold
// elements from a COW array and we change the length of the array.
(function() {
const a = [1, 2, 3];
const foo = () => a[0];
assertEquals(1, foo());
assertEquals(1, foo());
%OptimizeFunctionOnNextCall(foo);
assertEquals(1, foo());
assertOptimized(foo);
a.length = 1;
assertEquals(1, foo());
assertUnoptimized(foo);
})();
// Check that we properly deoptimize TurboFan'ed code when we constant-fold
// elements from a COW array and we change the element of the array.
(function() {
const a = [1, 2, 3];
const foo = () => a[0];
assertEquals(1, foo());
assertEquals(1, foo());
%OptimizeFunctionOnNextCall(foo);
assertEquals(1, foo());
assertOptimized(foo);
a[0] = 42;
assertEquals(42, foo());
assertUnoptimized(foo);
})();