]>
Commit | Line | Data |
---|---|---|
ed1e77d3 A |
1 | // Get early out-of-bound data. |
2 | function opaqueGetByValOnInt32ArrayEarlyOutOfBounds(array, index) | |
3 | { | |
4 | return array[index]; | |
5 | } | |
6 | noInline(opaqueGetByValOnInt32ArrayEarlyOutOfBounds); | |
7 | ||
8 | function testInt32ArrayEarlyOutOfBounds() | |
9 | { | |
10 | // Warm up with an immediate out of bounds. | |
11 | var int32Array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
12 | for (var i = 0; i <= 10; ++i) { | |
13 | var value = opaqueGetByValOnInt32ArrayEarlyOutOfBounds(int32Array, i); | |
14 | if ((i < 10 && value !== i) || (i >= 10 && value !== undefined)) | |
15 | throw "Failed opaqueGetByValOnInt32ArrayEarlyOutOfBounds(int32Array, i) warmup with i = " + i + " value = " + value; | |
16 | } | |
17 | ||
18 | // We then do plenty of in-bounds accesses. | |
19 | for (var i = 0; i < 1e4; ++i) { | |
20 | for (var j = 0; j < 10; ++j) { | |
21 | var value = opaqueGetByValOnInt32ArrayEarlyOutOfBounds(int32Array, j); | |
22 | if (j < 10 && value !== j) | |
23 | throw "Failed opaqueGetByValOnInt32ArrayEarlyOutOfBounds(int32Array, j) in-bounds with j = " + j + " value = " + value; | |
24 | } | |
25 | } | |
26 | ||
27 | // Followed by plenty of out-of-bounds accesses. | |
28 | for (var i = 0; i < 1e4; ++i) { | |
29 | for (var j = 0; j <= 10; ++j) { | |
30 | var value = opaqueGetByValOnInt32ArrayEarlyOutOfBounds(int32Array, j); | |
31 | if ((j < 10 && value !== j) || (j >= 10 && value !== undefined)) | |
32 | throw "Failed opaqueGetByValOnInt32ArrayEarlyOutOfBounds(int32Array, j) out-of-bounds with j = " + j + " value = " + value; | |
33 | } | |
34 | } | |
35 | } | |
36 | testInt32ArrayEarlyOutOfBounds(); | |
37 | ||
38 | // One more access, with a completely different array type. | |
39 | function testIndexingTypeChangesOnInt32Array() | |
40 | { | |
41 | var doubleArray = [-0, 5.5, -42.1]; | |
42 | var value = opaqueGetByValOnInt32ArrayEarlyOutOfBounds(doubleArray, 0); | |
43 | if (value || 1 / value !== -Infinity) | |
44 | throw "Failed opaqueGetByValOnInt32ArrayEarlyOutOfBounds(doubleArray, 0)"; | |
45 | var value = opaqueGetByValOnInt32ArrayEarlyOutOfBounds(doubleArray, 1); | |
46 | if (value !== 5.5) | |
47 | throw "Failed opaqueGetByValOnInt32ArrayEarlyOutOfBounds(doubleArray, 1)"; | |
48 | var value = opaqueGetByValOnInt32ArrayEarlyOutOfBounds(doubleArray, 2); | |
49 | if (value !== -42.1) | |
50 | throw "Failed opaqueGetByValOnInt32ArrayEarlyOutOfBounds(doubleArray, 2)"; | |
51 | } | |
52 | testIndexingTypeChangesOnInt32Array(); | |
53 | ||
54 | ||
55 | ||
56 | // Get out-of-bound data after a thousand run. | |
57 | function opaqueGetByValOnStringArrayHotOutOfBounds(array, index) | |
58 | { | |
59 | return array[index]; | |
60 | } | |
61 | noInline(opaqueGetByValOnStringArrayHotOutOfBounds); | |
62 | ||
63 | function testStringArrayHotOutOfBounds() | |
64 | { | |
65 | // Warm up with in bounds access. | |
66 | var stringArray = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; | |
67 | for (var i = 0; i < 1e2; ++i) { | |
68 | for (var j = 0; j < 10; ++j) { | |
69 | var value = opaqueGetByValOnStringArrayHotOutOfBounds(stringArray, j); | |
70 | if (value !== "" + j) | |
71 | throw "Failed opaqueGetByValOnStringArrayHotOutOfBounds(stringArray, j) in-bounds with j = " + j + " value = " + value; | |
72 | } | |
73 | } | |
74 | ||
75 | // Do a single out of bounds after warmup. | |
76 | var value = opaqueGetByValOnStringArrayHotOutOfBounds(stringArray, 10); | |
77 | if (value !== undefined) | |
78 | throw "Failed opaqueGetByValOnStringArrayHotOutOfBounds(stringArray, 10) with i = " + i + " value = " + value; | |
79 | ||
80 | // We then do plenty of in-bounds accesses. | |
81 | for (var i = 0; i < 1e3; ++i) { | |
82 | for (var j = 0; j < 10; ++j) { | |
83 | var value = opaqueGetByValOnStringArrayHotOutOfBounds(stringArray, j); | |
84 | if (value !== "" + j) | |
85 | throw "Failed opaqueGetByValOnStringArrayHotOutOfBounds(stringArray, j) in-bounds with j = " + j + " value = " + value; | |
86 | } | |
87 | } | |
88 | ||
89 | // Followed by plenty of out-of-bounds accesses. | |
90 | for (var i = 0; i < 1e3; ++i) { | |
91 | for (var j = 0; j <= 10; ++j) { | |
92 | var value = opaqueGetByValOnStringArrayHotOutOfBounds(stringArray, j); | |
93 | if ((j < 10 && value !== "" + j) || (j >= 10 && value !== undefined)) | |
94 | throw "Failed opaqueGetByValOnStringArrayHotOutOfBounds(stringArray, j) out-of-bounds with j = " + j + " value = " + value; | |
95 | } | |
96 | } | |
97 | } | |
98 | testStringArrayHotOutOfBounds(); | |
99 | ||
100 | function testIndexingTypeChangesOnStringArray() | |
101 | { | |
102 | var doubleArray = [-0, 5.5, -42.1]; | |
103 | var value = opaqueGetByValOnStringArrayHotOutOfBounds(doubleArray, 0); | |
104 | if (value || 1 / value !== -Infinity) | |
105 | throw "Failed opaqueGetByValOnStringArrayHotOutOfBounds(doubleArray, 0)"; | |
106 | var value = opaqueGetByValOnStringArrayHotOutOfBounds(doubleArray, 1); | |
107 | if (value !== 5.5) | |
108 | throw "Failed opaqueGetByValOnStringArrayHotOutOfBounds(doubleArray, 1)"; | |
109 | var value = opaqueGetByValOnStringArrayHotOutOfBounds(doubleArray, 2); | |
110 | if (value !== -42.1) | |
111 | throw "Failed opaqueGetByValOnStringArrayHotOutOfBounds(doubleArray, 2)"; | |
112 | } | |
113 | testIndexingTypeChangesOnStringArray(); | |
114 | ||
115 | ||
116 | ||
117 | // Get out-of-bound data after a thousand run, but from a different array type. | |
118 | function opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(array, index) | |
119 | { | |
120 | return array[index]; | |
121 | } | |
122 | noInline(opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds); | |
123 | ||
124 | function testStringAndInt32ArrayHotOutOfBounds() | |
125 | { | |
126 | // Warm up with in bounds access. | |
127 | var stringArray = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; | |
128 | for (var i = 0; i < 1e2; ++i) { | |
129 | for (var j = 0; j < 10; ++j) { | |
130 | var value = opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(stringArray, j); | |
131 | if (value !== "" + j) | |
132 | throw "Failed opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(stringArray, j) in-bounds with j = " + j + " value = " + value; | |
133 | } | |
134 | } | |
135 | ||
136 | // Do a single out of bounds after warmup. | |
137 | var int32Array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
138 | var value = opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(int32Array, 10); | |
139 | if (value !== undefined) | |
140 | throw "Failed opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(stringArray, 10) with i = " + i + " value = " + value; | |
141 | ||
142 | // We then do plenty of in-bounds accesses. | |
143 | for (var i = 0; i < 1e3; ++i) { | |
144 | for (var j = 0; j < 10; ++j) { | |
145 | var value = opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(stringArray, j); | |
146 | if (value !== "" + j) | |
147 | throw "Failed opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(stringArray, j) in-bounds with j = " + j + " value = " + value; | |
148 | ||
149 | var value = opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(int32Array, j); | |
150 | if (value !== j) | |
151 | throw "Failed opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(int32Array, j) in-bounds with j = " + j + " value = " + value; | |
152 | } | |
153 | } | |
154 | ||
155 | // Followed by plenty of out-of-bounds accesses. | |
156 | for (var i = 0; i < 1e3; ++i) { | |
157 | for (var j = 0; j <= 10; ++j) { | |
158 | var value = opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(int32Array, j); | |
159 | if ((j < 10 && value !== j) || (j >= 10 && value !== undefined)) | |
160 | throw "Failed opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(int32Array, j) out-of-bounds with j = " + j + " value = " + value; | |
161 | ||
162 | var value = opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(stringArray, j); | |
163 | if ((j < 10 && value !== "" + j) || (j >= 10 && value !== undefined)) | |
164 | throw "Failed opaqueGetByValOnStringAndInt32ArrayHotOutOfBounds(stringArray, j) out-of-bounds with j = " + j + " value = " + value; | |
165 | } | |
166 | } | |
167 | } | |
168 | testStringAndInt32ArrayHotOutOfBounds(); | |
169 | ||
170 | ||
171 | // Get out-of-bound data from a hole after a thousand run. | |
172 | function opaqueGetByValOnDoubleArrayHotOutOfBounds(array, index) | |
173 | { | |
174 | return array[index]; | |
175 | } | |
176 | noInline(opaqueGetByValOnDoubleArrayHotOutOfBounds); | |
177 | ||
178 | function testStringArrayHotOutOfBounds() | |
179 | { | |
180 | // Warm up with in bounds access. | |
181 | var doubleArray = new Array(10); | |
182 | for (var i = 0; i < 10; ++i) { | |
183 | if (i !== 5) | |
184 | doubleArray[i] = i + 0.5; | |
185 | } | |
186 | for (var i = 0; i < 1e2; ++i) { | |
187 | for (var j = 0; j < 10; ++j) { | |
188 | if (j !== 5) { | |
189 | var value = opaqueGetByValOnDoubleArrayHotOutOfBounds(doubleArray, j); | |
190 | if (value !== j + 0.5) | |
191 | throw "Failed opaqueGetByValOnDoubleArrayHotOutOfBounds(doubleArray, j) in-bounds with j = " + j + " value = " + value; | |
192 | } | |
193 | } | |
194 | } | |
195 | ||
196 | // Do a single out of bounds after warmup. | |
197 | var value = opaqueGetByValOnDoubleArrayHotOutOfBounds(doubleArray, 5); | |
198 | if (value !== undefined) | |
199 | throw "Failed opaqueGetByValOnDoubleArrayHotOutOfBounds(doubleArray, 5) with i = " + i + " value = " + value; | |
200 | ||
201 | // We then do plenty of in-bounds accesses. | |
202 | for (var i = 0; i < 1e3; ++i) { | |
203 | for (var j = 0; j < 10; ++j) { | |
204 | if (j !== 5) { | |
205 | var value = opaqueGetByValOnDoubleArrayHotOutOfBounds(doubleArray, j); | |
206 | if (value !== j + 0.5) | |
207 | throw "Failed opaqueGetByValOnDoubleArrayHotOutOfBounds(doubleArray, j) in-bounds with j = " + j + " value = " + value; | |
208 | } | |
209 | } | |
210 | } | |
211 | ||
212 | // Followed by plenty of out-of-bounds accesses. | |
213 | for (var i = 0; i < 1e3; ++i) { | |
214 | for (var j = 0; j < 10; ++j) { | |
215 | var value = opaqueGetByValOnDoubleArrayHotOutOfBounds(doubleArray, j); | |
216 | if ((j !== 5 && value !== j + 0.5) || (j === 10 && value !== undefined)) | |
217 | throw "Failed opaqueGetByValOnDoubleArrayHotOutOfBounds(doubleArray, j) out-of-bounds with j = " + j + " value = " + value; | |
218 | } | |
219 | } | |
220 | } | |
221 | testStringArrayHotOutOfBounds(); |