Commit 311808ee authored by Théotime Grohens's avatar Théotime Grohens Committed by Commit Bot

[dataview] Deopt in TurboFan instead of raising exceptions

This CL simplifies the implementation of inlined DataView
methods in TurboFan. It removes the explicit exception handling,
and just deopts and relies on the baseline code to handle
exceptions instead.

It also adapts the DataView test files in mjsunit/compiler/
accordingly.

Change-Id: I013c76970e1480df2b755d17d397bd0f9f26f0ec
Reviewed-on: https://chromium-review.googlesource.com/1148207
Commit-Queue: Théotime Grohens <theotime@google.com>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54648}
parent e0670b22
This diff is collapsed.
// 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 --no-always-opt
// Check that there are no deopt loops for DataView methods.
var buffer = new ArrayBuffer(64);
var dataview = new DataView(buffer, 8, 24);
// Check DataView getters.
function readUint8(offset) {
return dataview.getUint8(offset);
}
function warmupRead(f) {
f(0);
f(1);
%OptimizeFunctionOnNextCall(f);
f(2);
f(3);
}
warmupRead(readUint8);
assertOptimized(readUint8);
readUint8(0.5); // Deopts.
assertUnoptimized(readUint8);
warmupRead(readUint8);
assertOptimized(readUint8);
readUint8(1.5); // Doesn't deopt because getUint8 didn't get inlined this time.
assertOptimized(readUint8);
// Check DataView setters.
function writeUint8(offset, value) {
dataview.setUint8(offset, value);
}
function warmupWrite(f) {
f(0, 0);
f(0, 1);
%OptimizeFunctionOnNextCall(f);
f(0, 2);
f(0, 3);
}
warmupWrite(writeUint8);
assertOptimized(writeUint8);
writeUint8(0.5, 0); // Deopts.
assertUnoptimized(writeUint8);
warmupWrite(writeUint8);
assertOptimized(writeUint8);
writeUint8(1.5, 0); // Doesn't deopt.
assertOptimized(writeUint8);
......@@ -131,43 +131,56 @@ assertEquals(b4, readFloat64(16));
dataview.setFloat64(16, b4, true);
assertEquals(b4, readFloat64(16, true));
// TurboFan out of bounds read, throw with exception handler.
// TurboFan out of bounds reads deopt.
assertOptimized(readInt8Handled);
assertInstanceof(readInt8Handled(24), RangeError);
assertOptimized(readInt8Handled);
assertUnoptimized(readInt8Handled);
assertOptimized(readInt16Handled);
assertInstanceof(readInt16Handled(23), RangeError);
assertOptimized(readInt16Handled);
assertUnoptimized(readInt16Handled);
assertOptimized(readInt32Handled);
assertInstanceof(readInt32Handled(21), RangeError);
assertOptimized(readInt32Handled);
assertUnoptimized(readInt32Handled);
// Without exception handler.
assertOptimized(readUint8);
assertThrows(() => readUint8(24));
assertOptimized(readUint8);
assertUnoptimized(readUint8);
assertOptimized(readFloat32);
assertThrows(() => readFloat32(21));
assertOptimized(readFloat32);
assertUnoptimized(readFloat32);
assertOptimized(readFloat64);
assertThrows(() => readFloat64(17));
assertOptimized(readFloat64);
assertUnoptimized(readFloat64);
// TurboFan deoptimizations.
assertOptimized(readInt8Handled);
assertInstanceof(readInt8Handled(-1), RangeError); // Negative Smi deopts.
assertUnoptimized(readInt8Handled);
warmup(readInt8Handled);
assertOptimized(readInt8Handled);
assertEquals(values[3], readInt8Handled(3.14)); // Non-Smi index deopts.
assertUnoptimized(readInt8Handled);
// TurboFan neutered buffer.
warmup(readInt8Handled);
assertOptimized(readInt8Handled);
%ArrayBufferNeuter(buffer);
assertInstanceof(readInt8Handled(0), TypeError);
assertOptimized(readInt8Handled);
// Negative Smi deopts.
(function() {
function readInt8Handled(offset) {
try { return dataview.getInt8(offset); } catch (e) { return e; }
}
warmup(readInt8Handled);
assertOptimized(readInt8Handled);
assertInstanceof(readInt8Handled(-1), RangeError);
assertUnoptimized(readInt8Handled);
})();
// Non-Smi index deopts.
(function() {
function readUint8(offset) { return dataview.getUint8(offset); }
warmup(readUint8);
assertOptimized(readUint8);
assertEquals(values[3], readUint8(3.14));
assertUnoptimized(readUint8);
})();
// TurboFan neutered buffer deopts.
(function() {
function readInt8Handled(offset) {
try { return dataview.getInt8(offset); } catch (e) { return e; }
}
warmup(readInt8Handled);
%ArrayBufferNeuter(buffer);
assertOptimized(readInt8Handled);
assertInstanceof(readInt8Handled(0), TypeError);
assertUnoptimized(readInt8Handled);
})();
......@@ -117,15 +117,15 @@ assertEquals(b4, dataview.getFloat64(8));
writeFloat64(8, b4, true);
assertEquals(b4, dataview.getFloat64(8, true));
// TurboFan out of bounds read, throw with exception handler.
// TurboFan out of bounds read, deopt.
assertOptimized(writeInt8Handled);
assertInstanceof(writeInt8Handled(24, 0), RangeError);
assertOptimized(writeInt8Handled);
assertUnoptimized(writeInt8Handled);
// Without exception handler.
// Without exception handler, deopt too.
assertOptimized(writeUint8);
assertThrows(() => writeUint8(24, 0));
assertOptimized(writeUint8);
assertUnoptimized(writeUint8);
// None of the stores wrote out of bounds.
var bytes = new Uint8Array(buffer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment