Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: test/mjsunit/unbox-double-arrays.js

Issue 7350021: Crankshaft support for FixedDoubleArrays (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix ia32 build Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/x64/lithium-codegen-x64.cc ('K') | « src/x64/lithium-x64.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Test dictionary -> double elements -> dictionary elements round trip 28 // Test dictionary -> double elements -> dictionary elements round trip
29 29
30 // Flags: --allow-natives-syntax --unbox-double-arrays 30 // Flags: --allow-natives-syntax --unbox-double-arrays --expose-gc
31 var large_array_size = 500000; 31 var large_array_size = 500000;
32 var approx_dict_to_elements_threshold = 69000; 32 var approx_dict_to_elements_threshold = 69000;
33 33
34 var name = 0;
35
34 function expected_array_value(i) { 36 function expected_array_value(i) {
35 if ((i % 2) == 0) { 37 if ((i % 2) == 0) {
36 return i; 38 return i;
37 } else { 39 } else {
38 return i + 0.5; 40 return i + 0.5;
39 } 41 }
40 } 42 }
41 43
42 function force_to_fast_double_array(a) { 44 function force_to_fast_double_array(a) {
43 for (var i= 0; i < approx_dict_to_elements_threshold; ++i ) { 45 for (var i= 0; i < approx_dict_to_elements_threshold; ++i ) {
44 a[i] = expected_array_value(i); 46 a[i] = expected_array_value(i);
45 } 47 }
46 assertTrue(%HasFastDoubleElements(a)); 48 assertTrue(%HasFastDoubleElements(a));
47 } 49 }
48 50
51 function flush_compiled_code() {
Mads Ager (chromium) 2011/07/19 08:03:51 Do you need both flush_compiled_code and multiple
danno 2011/07/19 12:50:17 Done.
52 gc();
53 }
54
49 function testOneArrayType(allocator) { 55 function testOneArrayType(allocator) {
50 var large_array = new allocator(500000); 56 var large_array = new allocator(500000);
51 force_to_fast_double_array(large_array); 57 force_to_fast_double_array(large_array);
52 58
53 for (var i= 0; i < approx_dict_to_elements_threshold; i += 501 ) { 59 for (var i= 0; i < approx_dict_to_elements_threshold; i += 501 ) {
54 assertEquals(expected_array_value(i), large_array[i]); 60 assertEquals(expected_array_value(i), large_array[i]);
55 } 61 }
56 62
57 function get_test_various_loads() { 63 // Multiple versions of the test function makes sure that IC/Crankshaft state
58 return function test_various_loads(a, value_5, value_6, value_7) { 64 // doesn't get reused.
59 assertTrue(%HasFastDoubleElements(a)); 65 function test_various_loads(a, value_5, value_6, value_7) {
60 assertEquals(value_5, a[5]); 66 assertTrue(%HasFastDoubleElements(a));
61 assertEquals(value_6, a[6]); 67 assertEquals(value_5, a[5]);
62 assertEquals(value_7, a[7]); 68 assertEquals(value_6, a[6]);
63 assertEquals(undefined, a[large_array_size-1]); 69 assertEquals(value_7, a[7]);
64 assertEquals(undefined, a[-1]); 70 assertEquals(undefined, a[large_array_size-1]);
65 assertEquals(large_array_size, a.length); 71 assertEquals(undefined, a[-1]);
66 assertTrue(%HasFastDoubleElements(a)); 72 assertEquals(large_array_size, a.length);
67 } 73 assertTrue(%HasFastDoubleElements(a));
68 } 74 }
69 75
70 function get_test_various_stores() { 76 function test_various_loads2(a, value_5, value_6, value_7) {
71 return function test_various_stores(a, value_5, value_6, value_7) { 77 assertTrue(%HasFastDoubleElements(a));
72 assertTrue(%HasFastDoubleElements(a)); 78 assertEquals(value_5, a[5]);
73 a[5] = value_5; 79 assertEquals(value_6, a[6]);
74 a[6] = value_6; 80 assertEquals(value_7, a[7]);
75 a[7] = value_7; 81 assertEquals(undefined, a[large_array_size-1]);
76 assertTrue(%HasFastDoubleElements(a)); 82 assertEquals(undefined, a[-1]);
77 } 83 assertEquals(large_array_size, a.length);
84 assertTrue(%HasFastDoubleElements(a));
78 } 85 }
79 86
80 // Run tests up to three times to make sure both runtime and IC implementation 87 function test_various_loads3(a, value_5, value_6, value_7) {
81 // (premonomorphic and monomorphic) of KeyedLoad access works in various 88 assertTrue(%HasFastDoubleElements(a));
82 // cases. 89 assertEquals(value_5, a[5]);
90 assertEquals(value_6, a[6]);
91 assertEquals(value_7, a[7]);
92 assertEquals(undefined, a[large_array_size-1]);
93 assertEquals(undefined, a[-1]);
94 assertEquals(large_array_size, a.length);
95 assertTrue(%HasFastDoubleElements(a));
96 }
97
98 function test_various_loads4(a, value_5, value_6, value_7) {
99 assertTrue(%HasFastDoubleElements(a));
100 assertEquals(value_5, a[5]);
101 assertEquals(value_6, a[6]);
102 assertEquals(value_7, a[7]);
103 assertEquals(undefined, a[large_array_size-1]);
104 assertEquals(undefined, a[-1]);
105 assertEquals(large_array_size, a.length);
106 assertTrue(%HasFastDoubleElements(a));
107 }
108
109 function test_various_loads5(a, value_5, value_6, value_7) {
110 assertTrue(%HasFastDoubleElements(a));
111 assertEquals(value_5, a[5]);
112 assertEquals(value_6, a[6]);
113 assertEquals(value_7, a[7]);
114 assertEquals(undefined, a[large_array_size-1]);
115 assertEquals(undefined, a[-1]);
116 assertEquals(large_array_size, a.length);
117 assertTrue(%HasFastDoubleElements(a));
118 }
119
120 function test_various_loads6(a, value_5, value_6, value_7) {
121 assertTrue(%HasFastDoubleElements(a));
122 assertEquals(value_5, a[5]);
123 assertEquals(value_6, a[6]);
124 assertEquals(value_7, a[7]);
125 assertEquals(undefined, a[large_array_size-1]);
126 assertEquals(undefined, a[-1]);
127 assertEquals(large_array_size, a.length);
128 assertTrue(%HasFastDoubleElements(a));
129 }
130
131 function test_various_stores(a, value_5, value_6, value_7) {
132 assertTrue(%HasFastDoubleElements(a));
133 a[5] = value_5;
134 a[6] = value_6;
135 a[7] = value_7;
136 assertTrue(%HasFastDoubleElements(a));
137 }
83 138
84 // Test double and integer values 139 // Test double and integer values
85 test_various_loads = get_test_various_loads();
86 test_various_loads(large_array, 140 test_various_loads(large_array,
87 expected_array_value(5), 141 expected_array_value(5),
88 expected_array_value(6), 142 expected_array_value(6),
89 expected_array_value(7)); 143 expected_array_value(7));
90 test_various_loads(large_array, 144 test_various_loads(large_array,
91 expected_array_value(5), 145 expected_array_value(5),
92 expected_array_value(6), 146 expected_array_value(6),
93 expected_array_value(7)); 147 expected_array_value(7));
94 test_various_loads(large_array, 148 test_various_loads(large_array,
95 expected_array_value(5), 149 expected_array_value(5),
96 expected_array_value(6), 150 expected_array_value(6),
97 expected_array_value(7)); 151 expected_array_value(7));
152 %OptimizeFunctionOnNextCall(test_various_loads);
153 test_various_loads(large_array,
154 expected_array_value(5),
155 expected_array_value(6),
156 expected_array_value(7));
98 157
158 flush_compiled_code();
159
99 // Test NaN values 160 // Test NaN values
100 test_various_stores = get_test_various_stores();
101 test_various_stores(large_array, NaN, -NaN, expected_array_value(7)); 161 test_various_stores(large_array, NaN, -NaN, expected_array_value(7));
102 162
103 test_various_loads(large_array, 163 test_various_loads2(large_array,
104 NaN, 164 NaN,
105 -NaN, 165 -NaN,
106 expected_array_value(7)); 166 expected_array_value(7));
107 test_various_loads(large_array, 167 test_various_loads2(large_array,
108 NaN, 168 NaN,
109 -NaN, 169 -NaN,
110 expected_array_value(7)); 170 expected_array_value(7));
111 test_various_loads(large_array, 171 test_various_loads2(large_array,
112 NaN, 172 NaN,
113 -NaN, 173 -NaN,
114 expected_array_value(7)); 174 expected_array_value(7));
175 %OptimizeFunctionOnNextCall(test_various_loads2);
176 test_various_loads2(large_array,
177 NaN,
178 -NaN,
179 expected_array_value(7));
180
181 flush_compiled_code();
115 182
116 // Test Infinity values 183 // Test Infinity values
117 test_various_stores = get_test_various_stores();
118 test_various_stores(large_array, 184 test_various_stores(large_array,
119 Infinity, 185 Infinity,
120 -Infinity, 186 -Infinity,
121 expected_array_value(7)); 187 expected_array_value(7));
122 188
123 test_various_loads(large_array, 189 test_various_loads3(large_array,
124 Infinity, 190 Infinity,
125 -Infinity, 191 -Infinity,
126 expected_array_value(7)); 192 expected_array_value(7));
127 test_various_loads(large_array, 193 test_various_loads3(large_array,
128 Infinity, 194 Infinity,
129 -Infinity, 195 -Infinity,
130 expected_array_value(7)); 196 expected_array_value(7));
131 test_various_loads(large_array, 197 test_various_loads3(large_array,
132 Infinity, 198 Infinity,
133 -Infinity, 199 -Infinity,
134 expected_array_value(7)); 200 expected_array_value(7));
201 %OptimizeFunctionOnNextCall(test_various_loads3);
202 test_various_loads3(large_array,
203 Infinity,
204 -Infinity,
205 expected_array_value(7));
206
207 flush_compiled_code();
135 208
136 // Test the hole for the default runtime implementation. 209 // Test the hole for the default runtime implementation.
137 delete large_array[5]; 210 delete large_array[5];
138 delete large_array[6]; 211 delete large_array[6];
139 test_various_loads = get_test_various_loads(); 212 test_various_loads4(large_array,
140 test_various_loads(large_array, 213 undefined,
141 undefined, 214 undefined,
142 undefined, 215 expected_array_value(7));
143 expected_array_value(7)); 216
217 flush_compiled_code();
144 218
145 // Test the keyed load IC implementation when the value is the hole. 219 // Test the keyed load IC implementation when the value is the hole.
146 test_various_loads = get_test_various_loads();
147 test_various_stores(large_array, 220 test_various_stores(large_array,
148 expected_array_value(5), 221 expected_array_value(5),
149 expected_array_value(6), 222 expected_array_value(6),
150 expected_array_value(7)); 223 expected_array_value(7));
151 test_various_loads(large_array, 224 test_various_loads5(large_array,
152 expected_array_value(5), 225 expected_array_value(5),
153 expected_array_value(6), 226 expected_array_value(6),
154 expected_array_value(7)); 227 expected_array_value(7));
155 test_various_loads(large_array, 228 test_various_loads5(large_array,
156 expected_array_value(5), 229 expected_array_value(5),
157 expected_array_value(6), 230 expected_array_value(6),
158 expected_array_value(7)); 231 expected_array_value(7));
159 delete large_array[5]; 232 delete large_array[5];
160 delete large_array[6]; 233 delete large_array[6];
161 test_various_loads(large_array, 234 test_various_loads5(large_array,
162 undefined, 235 undefined,
163 undefined, 236 undefined,
164 expected_array_value(7)); 237 expected_array_value(7));
165 test_various_loads(large_array, 238 test_various_loads5(large_array,
166 undefined, 239 undefined,
167 undefined, 240 undefined,
168 expected_array_value(7)); 241 expected_array_value(7));
169 242
170 // Test both runtime and IC variants of double array stores for normal 243 flush_compiled_code();
171 // values (double and integer). 244
172 test_various_stores = get_test_various_stores(); 245 // Make sure Crankshaft code handles the hole correctly (bailout)
173 test_various_stores(large_array,
174 expected_array_value(4),
175 expected_array_value(5),
176 expected_array_value(6));
177 test_various_loads(large_array,
178 expected_array_value(4),
179 expected_array_value(5),
180 expected_array_value(6));
181 test_various_stores(large_array, 246 test_various_stores(large_array,
182 expected_array_value(5), 247 expected_array_value(5),
183 expected_array_value(6), 248 expected_array_value(6),
184 expected_array_value(7)); 249 expected_array_value(7));
185 test_various_loads(large_array, 250 test_various_loads6(large_array,
186 expected_array_value(5), 251 expected_array_value(5),
187 expected_array_value(6), 252 expected_array_value(6),
188 expected_array_value(7)); 253 expected_array_value(7));
254 test_various_loads6(large_array,
255 expected_array_value(5),
256 expected_array_value(6),
257 expected_array_value(7));
258 %OptimizeFunctionOnNextCall(test_various_loads6);
259 test_various_loads6(large_array,
260 expected_array_value(5),
261 expected_array_value(6),
262 expected_array_value(7));
189 263
190 // Test stores of NaN to make sure they don't get mistaken for the 264 delete large_array[5];
191 // hole. Test both runtime and IC implementation. 265 delete large_array[6];
192 test_various_stores = get_test_various_stores(); 266 test_various_loads6(large_array,
193 test_various_stores(large_array, 267 undefined,
194 NaN, 268 undefined,
195 -NaN, 269 expected_array_value(7));
196 expected_array_value(6)); 270
197 test_various_loads(large_array, 271 // Test stores for non-NaN.
198 NaN, 272 %OptimizeFunctionOnNextCall(test_various_stores);
199 -NaN,
200 expected_array_value(6));
201 test_various_stores(large_array, 273 test_various_stores(large_array,
202 expected_array_value(5), 274 expected_array_value(5),
203 expected_array_value(6), 275 expected_array_value(6),
204 expected_array_value(7)); 276 expected_array_value(7));
205 test_various_loads(large_array, 277
206 expected_array_value(5), 278 test_various_stores(large_array,
207 expected_array_value(6), 279 expected_array_value(5),
208 expected_array_value(7)); 280 expected_array_value(6),
281 expected_array_value(7));
282
283 test_various_loads6(large_array,
284 expected_array_value(5),
285 expected_array_value(6),
286 expected_array_value(7));
287
288 // Test NaN behavior for stores.
209 test_various_stores(large_array, 289 test_various_stores(large_array,
210 NaN, 290 NaN,
211 -NaN, 291 -NaN,
212 expected_array_value(7)); 292 expected_array_value(7));
213 test_various_loads(large_array, 293
294 test_various_stores(large_array,
214 NaN, 295 NaN,
215 -NaN, 296 -NaN,
216 expected_array_value(7)); 297 expected_array_value(7));
217 298
218 // Test stores of Infinity to make sure they don't get mistaken for the 299 test_various_loads6(large_array,
219 // hole. Test both runtime and IC implementation. 300 NaN,
220 test_various_stores = get_test_various_stores(); 301 -NaN,
221 test_various_stores(large_array,
222 Infinity,
223 -Infinity,
224 expected_array_value(6));
225 test_various_loads(large_array,
226 Infinity,
227 -Infinity,
228 expected_array_value(6));
229 test_various_stores(large_array,
230 expected_array_value(5),
231 expected_array_value(6),
232 expected_array_value(7)); 302 expected_array_value(7));
233 test_various_loads(large_array, 303
234 expected_array_value(5), 304 // Test Infinity behavior for stores.
235 expected_array_value(6),
236 expected_array_value(7));
237 test_various_stores(large_array, 305 test_various_stores(large_array,
238 Infinity, 306 Infinity,
239 -Infinity, 307 -Infinity,
240 expected_array_value(7)); 308 expected_array_value(7));
241 test_various_loads(large_array, 309
310 test_various_stores(large_array,
242 Infinity, 311 Infinity,
243 -Infinity, 312 -Infinity,
244 expected_array_value(7)); 313 expected_array_value(7));
245 314
246 delete large_array[5]; 315 test_various_loads6(large_array,
316 Infinity,
317 -Infinity,
318 expected_array_value(7));
319
320 assertTrue(%GetOptimizationStatus(test_various_stores) != 2);
247 321
248 // Make sure that we haven't converted from fast double. 322 // Make sure that we haven't converted from fast double.
249 assertTrue(%HasFastDoubleElements(large_array)); 323 assertTrue(%HasFastDoubleElements(large_array));
250 // Cause the array to grow beyond it's JSArray length. This will double the 324 // Cause the array to grow beyond it's JSArray length. This will double the
251 // size of the capacity and force the array into "slow" dictionary case. 325 // size of the capacity and force the array into "slow" dictionary case.
252 large_array[large_array_size+1] = 50; 326 large_array[large_array_size+1] = 50;
253 assertTrue(%HasDictionaryElements(large_array)); 327 assertTrue(%HasDictionaryElements(large_array));
254 assertEquals(50, large_array[large_array_size+1]); 328 assertEquals(50, large_array[large_array_size+1]);
255 assertEquals(large_array_size+2, large_array.length); 329 assertEquals(large_array_size+2, large_array.length);
256 assertEquals(undefined, large_array[5]); 330 assertEquals(Infinity, large_array[5]);
257 assertEquals(undefined, large_array[large_array_size-1]); 331 assertEquals(undefined, large_array[large_array_size-1]);
258 assertEquals(undefined, large_array[-1]); 332 assertEquals(undefined, large_array[-1]);
259 assertEquals(large_array_size+2, large_array.length); 333 assertEquals(large_array_size+2, large_array.length);
260 334
261 // Test dictionary -> double elements -> fast elements. 335 // Test dictionary -> double elements -> fast elements.
262 var large_array2 = new allocator(large_array_size); 336 var large_array2 = new allocator(large_array_size);
263 force_to_fast_double_array(large_array2); 337 force_to_fast_double_array(large_array2);
264 delete large_array2[5]; 338 delete large_array2[5];
265 339
266 // Convert back to fast elements and make sure the contents of the array are 340 // Convert back to fast elements and make sure the contents of the array are
267 // unchanged. 341 // unchanged.
268 large_array2[25] = new Object(); 342 large_array2[25] = new Object();
269 assertTrue(%HasFastElements(large_array2)); 343 assertTrue(%HasFastElements(large_array2));
270 for (var i= 0; i < approx_dict_to_elements_threshold; i += 500 ) { 344 for (var i= 0; i < approx_dict_to_elements_threshold; i += 500 ) {
271 if (i != 25 && i != 5) { 345 if (i != 25 && i != 5) {
272 assertEquals(expected_array_value(i), large_array2[i]); 346 assertEquals(expected_array_value(i), large_array2[i]);
273 } 347 }
274 } 348 }
275 assertEquals(undefined, large_array2[5]) 349 assertEquals(undefined, large_array2[5])
276 assertEquals(undefined, large_array2[large_array_size-1]) 350 assertEquals(undefined, large_array2[large_array_size-1])
277 assertEquals(undefined, large_array2[-1]) 351 assertEquals(undefined, large_array2[-1])
278 assertEquals(large_array_size, large_array2.length); 352 assertEquals(large_array_size, large_array2.length);
279 } 353 }
280 354
281 testOneArrayType(Array); 355 testOneArrayType(Array);
OLDNEW
« src/x64/lithium-codegen-x64.cc ('K') | « src/x64/lithium-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698