v8/test/mjsunit/compiler/dataview-detached.js
Mythri A 06697f7a82 Rename stress_flush_bytecode to stress_flush_code
stress_flush_bytecode controls stress flushing of both bytecode and
baseline code. So rename the flag to better reflect its functionality

Bug: v8:11947
Change-Id: Ie6c124a476c3a7c6eabd1d75de030ee15fe78e32
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3062567
Commit-Queue: Mythri Alle <mythria@chromium.org>
Reviewed-by: Michael Achenbach <machenbach@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#76043}
2021-08-02 19:02:57 +00:00

409 lines
11 KiB
JavaScript

// Copyright 2018 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 --opt --noalways-opt --no-stress-flush-code
// Invalidate the detaching protector.
%ArrayBufferDetach(new ArrayBuffer(1));
// Check DataView.prototype.getInt8() optimization.
(function() {
const ab = new ArrayBuffer(1);
const dv = new DataView(ab);
function foo(dv) {
return dv.getInt8(0);
}
%PrepareFunctionForOptimization(foo);
assertEquals(0, foo(dv));
assertEquals(0, foo(dv));
%OptimizeFunctionOnNextCall(foo);
assertEquals(0, foo(dv));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.getUint8() optimization.
(function() {
const ab = new ArrayBuffer(1);
const dv = new DataView(ab);
function foo(dv) {
return dv.getUint8(0);
}
%PrepareFunctionForOptimization(foo);
assertEquals(0, foo(dv));
assertEquals(0, foo(dv));
%OptimizeFunctionOnNextCall(foo);
assertEquals(0, foo(dv));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.getInt16() optimization.
(function() {
const ab = new ArrayBuffer(2);
const dv = new DataView(ab);
function foo(dv) {
return dv.getInt16(0, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(0, foo(dv));
assertEquals(0, foo(dv));
%OptimizeFunctionOnNextCall(foo);
assertEquals(0, foo(dv));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.getUint16() optimization.
(function() {
const ab = new ArrayBuffer(2);
const dv = new DataView(ab);
function foo(dv) {
return dv.getUint16(0, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(0, foo(dv));
assertEquals(0, foo(dv));
%OptimizeFunctionOnNextCall(foo);
assertEquals(0, foo(dv));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.getInt32() optimization.
(function() {
const ab = new ArrayBuffer(4);
const dv = new DataView(ab);
function foo(dv) {
return dv.getInt32(0, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(0, foo(dv));
assertEquals(0, foo(dv));
%OptimizeFunctionOnNextCall(foo);
assertEquals(0, foo(dv));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.getUint32() optimization.
(function() {
const ab = new ArrayBuffer(4);
const dv = new DataView(ab);
function foo(dv) {
return dv.getUint32(0, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(0, foo(dv));
assertEquals(0, foo(dv));
%OptimizeFunctionOnNextCall(foo);
assertEquals(0, foo(dv));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.getFloat32() optimization.
(function() {
const ab = new ArrayBuffer(4);
const dv = new DataView(ab);
function foo(dv) {
return dv.getFloat32(0, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(0, foo(dv));
assertEquals(0, foo(dv));
%OptimizeFunctionOnNextCall(foo);
assertEquals(0, foo(dv));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.getFloat64() optimization.
(function() {
const ab = new ArrayBuffer(8);
const dv = new DataView(ab);
function foo(dv) {
return dv.getFloat64(0, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(0, foo(dv));
assertEquals(0, foo(dv));
%OptimizeFunctionOnNextCall(foo);
assertEquals(0, foo(dv));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.setInt8() optimization.
(function() {
const ab = new ArrayBuffer(1);
const dv = new DataView(ab);
function foo(dv, x) {
return dv.setInt8(0, x);
}
%PrepareFunctionForOptimization(foo);
assertEquals(undefined, foo(dv, 1));
assertEquals(1, dv.getInt8(0));
assertEquals(undefined, foo(dv, 2));
assertEquals(2, dv.getInt8(0));
%OptimizeFunctionOnNextCall(foo);
assertEquals(undefined, foo(dv, 3));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv, 4), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv, 5), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.setUint8() optimization.
(function() {
const ab = new ArrayBuffer(1);
const dv = new DataView(ab);
function foo(dv, x) {
return dv.setUint8(0, x);
}
%PrepareFunctionForOptimization(foo);
assertEquals(undefined, foo(dv, 1));
assertEquals(1, dv.getUint8(0));
assertEquals(undefined, foo(dv, 2));
assertEquals(2, dv.getUint8(0));
%OptimizeFunctionOnNextCall(foo);
assertEquals(undefined, foo(dv, 3));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv, 4), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv, 5), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.setInt16() optimization.
(function() {
const ab = new ArrayBuffer(2);
const dv = new DataView(ab);
function foo(dv, x) {
return dv.setInt16(0, x, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(undefined, foo(dv, 1));
assertEquals(1, dv.getInt16(0, true));
assertEquals(undefined, foo(dv, 2));
assertEquals(2, dv.getInt16(0, true));
%OptimizeFunctionOnNextCall(foo);
assertEquals(undefined, foo(dv, 3));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv, 4), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv, 5), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.setUint16() optimization.
(function() {
const ab = new ArrayBuffer(2);
const dv = new DataView(ab);
function foo(dv, x) {
return dv.setUint16(0, x, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(undefined, foo(dv, 1));
assertEquals(1, dv.getUint16(0, true));
assertEquals(undefined, foo(dv, 2));
assertEquals(2, dv.getUint16(0, true));
%OptimizeFunctionOnNextCall(foo);
assertEquals(undefined, foo(dv, 3));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv, 4), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv, 5), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.setInt32() optimization.
(function() {
const ab = new ArrayBuffer(4);
const dv = new DataView(ab);
function foo(dv, x) {
return dv.setInt32(0, x, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(undefined, foo(dv, 1));
assertEquals(1, dv.getInt32(0, true));
assertEquals(undefined, foo(dv, 2));
assertEquals(2, dv.getInt32(0, true));
%OptimizeFunctionOnNextCall(foo);
assertEquals(undefined, foo(dv, 3));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv, 4), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv, 5), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.setUint32() optimization.
(function() {
const ab = new ArrayBuffer(4);
const dv = new DataView(ab);
function foo(dv, x) {
return dv.setUint32(0, x, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(undefined, foo(dv, 1));
assertEquals(1, dv.getUint32(0, true));
assertEquals(undefined, foo(dv, 2));
assertEquals(2, dv.getUint32(0, true));
%OptimizeFunctionOnNextCall(foo);
assertEquals(undefined, foo(dv, 3));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv, 4), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv, 5), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.setFloat32() optimization.
(function() {
const ab = new ArrayBuffer(4);
const dv = new DataView(ab);
function foo(dv, x) {
return dv.setFloat32(0, x, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(undefined, foo(dv, 1));
assertEquals(1, dv.getFloat32(0, true));
assertEquals(undefined, foo(dv, 2));
assertEquals(2, dv.getFloat32(0, true));
%OptimizeFunctionOnNextCall(foo);
assertEquals(undefined, foo(dv, 3));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv, 4), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv, 5), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.setFloat64() optimization.
(function() {
const ab = new ArrayBuffer(8);
const dv = new DataView(ab);
function foo(dv, x) {
return dv.setFloat64(0, x, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(undefined, foo(dv, 1));
assertEquals(1, dv.getFloat64(0, true));
assertEquals(undefined, foo(dv, 2));
assertEquals(2, dv.getFloat64(0, true));
%OptimizeFunctionOnNextCall(foo);
assertEquals(undefined, foo(dv, 3));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv, 4), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv, 5), TypeError);
assertOptimized(foo);
})();