Repository navigation
Expand file tree
/
Copy patharray-buffer-view-tracking.js
More file actions
126 lines (106 loc) · 3.01 KB
/
Copy patharray-buffer-view-tracking.js
File metadata and controls
126 lines (106 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2025 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 --track-array-buffer-views --turbofan
function foo(ta) {
return ta.length;
}
function foo2(ta) {
return ta.length;
}
%PrepareFunctionForOptimization(foo);
%PrepareFunctionForOptimization(foo2);
// Make the TA map instable to have more reliable tests.
{
let ab = new ArrayBuffer(8);
let ta = new Uint32Array(ab);
%ArrayBufferDetach(ab);
}
// Check tracking works and we don't deopt.
{
let ab = new ArrayBuffer(8);
let ta = new Uint32Array(ab);
assertEquals(2, foo(ta));
let ab2 = new ArrayBuffer(8);
let ta2 = new Uint32Array(ab2);
assertEquals(2, foo2(ta2));
%OptimizeFunctionOnNextCall(foo);
%OptimizeFunctionOnNextCall(foo2);
assertEquals(2, foo(ta));
assertOptimized(foo);
assertEquals(2, foo2(ta2));
assertOptimized(foo2);
%ArrayBufferDetach(ab);
// foo might or might not be optimized here, depending on the dependency we
// installed.
assertEquals(0, foo(ta));
// Bailout due to map change
assertUnoptimized(foo);
// If ab gets detached, we don't deopt unrelated code.
assertOptimized(foo2);
assertEquals(2, foo2(ta2));
assertOptimized(foo2);
}
// Create another instance.
{
let ab = new ArrayBuffer(8);
let ta = new Uint32Array(ab);
assertEquals(2, foo(ta));
%OptimizeFunctionOnNextCall(foo);
assertEquals(2, foo(ta));
assertOptimized(foo);
}
// Invalidate the ArrayBufferDetached protector
(function() {
const ab = new ArrayBuffer(8);
let ta1 = new Uint32Array(ab);
let ta2 = new Uint32Array(ab);
%ArrayBufferDetach(ab);
})();
// Bailout due to protector
assertUnoptimized(foo);
// Check tracking works and we don't deopt.
{
let ab = new ArrayBuffer(8);
let ta = new Uint32Array(ab);
assertEquals(2, foo(ta));
let ab2 = new ArrayBuffer(8);
let ta2 = new Uint32Array(ab2);
assertEquals(2, foo2(ta2));
%OptimizeFunctionOnNextCall(foo);
%OptimizeFunctionOnNextCall(foo2);
assertEquals(2, foo(ta));
assertOptimized(foo);
assertEquals(2, foo2(ta2));
assertOptimized(foo2);
// If ab gets detached, we don't deopt.
%ArrayBufferDetach(ab);
// foo might or might not be optimized here, depending on the dependency we
// installed.
assertEquals(0, foo(ta));
// Might get a bailout due to map change. But depending on the compiler opts
// we are polymorphic here.
// assertUnoptimized(foo);
// Other ab are unaffected
assertOptimized(foo2);
assertEquals(2, foo2(ta2));
assertOptimized(foo2);
}
// Create another instance.
{
let ab = new ArrayBuffer(8);
let ta = new Uint32Array(ab);
assertEquals(2, foo(ta));
%OptimizeFunctionOnNextCall(foo);
assertEquals(2, foo(ta));
assertOptimized(foo);
}
// Again detach untracked view
(function() {
const ab = new ArrayBuffer(8);
let ta1 = new Uint32Array(ab);
let ta2 = new Uint32Array(ab);
%ArrayBufferDetach(ab);
})();
// No bailout since we are already detached
assertOptimized(foo);