OLD | NEW |
---|---|
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 var foo = new Array(500000); | 30 // Flags: --allow-natives-syntax --unbox-double-arrays |
31 | 31 var large_array_size = 500000; |
32 function func(a) { | 32 var approx_dict_to_elements_threshold = 69000; |
33 for (var i= 0; i < 100000; ++i ) { | 33 |
34 a[i] = i+0.5; | 34 function expected_array_value(i) { |
35 if ((i % 2) == 0) { | |
36 return i; | |
37 } else { | |
38 return i + 0.5; | |
35 } | 39 } |
36 } | 40 } |
37 | 41 |
38 func(foo); | 42 function force_to_fast_double_array(a) { |
39 | 43 for (var i= 0; i < approx_dict_to_elements_threshold; ++i ) { |
40 for (var i= 0; i < 100000; i += 500 ) { | 44 a[i] = expected_array_value(i); |
41 assertEquals(i+0.5, foo[i]); | 45 } |
46 assertTrue(%HasFastDoubleElements(a)); | |
42 } | 47 } |
43 | 48 |
44 delete foo[5]; | 49 function testOneArrayType(allocator) { |
45 // Don't use assertEquals for comparison to undefined due to | 50 var large_array = new allocator(500000); |
46 assertTrue(undefined === foo[5]); | 51 force_to_fast_double_array(large_array); |
47 assertTrue(undefined === foo[500000-1]); | 52 |
48 assertTrue(undefined === foo[-1]); | 53 for (var i= 0; i < approx_dict_to_elements_threshold; i += 501 ) { |
49 assertEquals(500000, foo.length); | 54 assertEquals(expected_array_value(i), large_array[i]); |
50 | 55 } |
51 // Cause the array to grow beyond it's JSArray length. This will double the | 56 |
52 // size of the capacity and force the array into "slow" dictionary case. | 57 function get_test_various_loads() { |
53 foo[500001] = 50; | 58 return function test_various_loads(a, value_5, value_6, value_7) { |
54 assertEquals(50, foo[500001]); | 59 assertTrue(%HasFastDoubleElements(a)); |
55 assertEquals(500002, foo.length); | 60 assertEquals(value_5, a[5]); |
56 assertTrue(undefined === foo[5]) | 61 assertEquals(value_6, a[6]); |
57 assertTrue(undefined === foo[500000-1]) | 62 assertEquals(value_7, a[7]); |
58 assertTrue(undefined === foo[-1]) | 63 assertEquals(undefined, a[large_array_size-1]); |
59 assertEquals(500002, foo.length); | 64 assertEquals(undefined, a[-1]); |
60 | 65 assertEquals(large_array_size, a.length); |
61 // Test dictionary -> double elements -> fast elements. | 66 assertTrue(%HasFastDoubleElements(a)); |
62 | 67 } |
63 var foo2 = new Array(500000); | 68 } |
64 func(foo2); | 69 |
65 delete foo2[5]; | 70 function get_test_various_stores() { |
66 | 71 return function test_various_stores(a, value_5, value_6, value_7) { |
67 // Convert back to fast elements and make sure the contents of the array are | 72 assertTrue(%HasFastDoubleElements(a)); |
68 // unchanged. | 73 a[5] = value_5; |
69 foo2[25] = new Object(); | 74 a[6] = value_6; |
70 for (var i= 0; i < 100000; i += 500 ) { | 75 a[7] = value_7; |
71 if (i != 25 && i != 5) { | 76 assertTrue(%HasFastDoubleElements(a)); |
72 assertEquals(i+0.5, foo2[i]); | 77 } |
73 } | 78 } |
79 | |
80 // Run tests up to three times to make sure both runtime and IC implementation | |
81 // (premonomorphic and monomorphic) of KeyedLoad access works in various cases . | |
Mads Ager (chromium)
2011/07/12 12:03:26
Long line. :-)
danno
2011/07/13 08:59:52
Done.
| |
82 | |
83 // Test double and integer values | |
84 test_various_loads = get_test_various_loads(); | |
85 test_various_loads(large_array, | |
86 expected_array_value(5), | |
87 expected_array_value(6), | |
88 expected_array_value(7)); | |
89 test_various_loads(large_array, | |
90 expected_array_value(5), | |
91 expected_array_value(6), | |
92 expected_array_value(7)); | |
93 test_various_loads(large_array, | |
94 expected_array_value(5), | |
95 expected_array_value(6), | |
96 expected_array_value(7)); | |
97 | |
98 // Test NaN values | |
99 test_various_stores = get_test_various_stores(); | |
100 test_various_stores(large_array, NaN, -NaN, expected_array_value(7)); | |
101 | |
102 test_various_loads(large_array, | |
103 NaN, | |
104 -NaN, | |
105 expected_array_value(7)); | |
106 test_various_loads(large_array, | |
107 NaN, | |
108 -NaN, | |
109 expected_array_value(7)); | |
110 test_various_loads(large_array, | |
111 NaN, | |
112 -NaN, | |
113 expected_array_value(7)); | |
114 | |
115 // Test Infinity values | |
116 test_various_stores = get_test_various_stores(); | |
117 test_various_stores(large_array, Infinity, -Infinity, expected_array_value(7)) ; | |
Mads Ager (chromium)
2011/07/12 12:03:26
Long line.
danno
2011/07/13 08:59:52
Done.
| |
118 | |
119 test_various_loads(large_array, | |
120 Infinity, | |
121 -Infinity, | |
122 expected_array_value(7)); | |
123 test_various_loads(large_array, | |
124 Infinity, | |
125 -Infinity, | |
126 expected_array_value(7)); | |
127 test_various_loads(large_array, | |
128 Infinity, | |
129 -Infinity, | |
130 expected_array_value(7)); | |
131 | |
132 // Test the hole for the default runtime implementation. | |
133 delete large_array[5]; | |
134 delete large_array[6]; | |
135 test_various_loads = get_test_various_loads(); | |
136 test_various_loads(large_array, | |
137 undefined, | |
138 undefined, | |
139 expected_array_value(7)); | |
140 | |
141 // Test the keyed load IC implementation when the value is the hole. | |
142 test_various_loads = get_test_various_loads(); | |
143 test_various_stores(large_array, | |
144 expected_array_value(5), | |
145 expected_array_value(6), | |
146 expected_array_value(7)); | |
147 test_various_loads(large_array, | |
148 expected_array_value(5), | |
149 expected_array_value(6), | |
150 expected_array_value(7)); | |
151 test_various_loads(large_array, | |
152 expected_array_value(5), | |
153 expected_array_value(6), | |
154 expected_array_value(7)); | |
155 delete large_array[5]; | |
156 delete large_array[6]; | |
157 test_various_loads(large_array, | |
158 undefined, | |
159 undefined, | |
160 expected_array_value(7)); | |
161 test_various_loads(large_array, | |
162 undefined, | |
163 undefined, | |
164 expected_array_value(7)); | |
165 | |
166 // Test both runtime and IC variants of double array stores for normal | |
167 // values (double and integer). | |
168 test_various_stores = get_test_various_stores(); | |
169 test_various_stores(large_array, | |
170 expected_array_value(4), | |
171 expected_array_value(5), | |
172 expected_array_value(6)); | |
173 test_various_loads(large_array, | |
174 expected_array_value(4), | |
175 expected_array_value(5), | |
176 expected_array_value(6)); | |
177 test_various_stores(large_array, | |
178 expected_array_value(5), | |
179 expected_array_value(6), | |
180 expected_array_value(7)); | |
181 test_various_loads(large_array, | |
182 expected_array_value(5), | |
183 expected_array_value(6), | |
184 expected_array_value(7)); | |
185 | |
186 // Test stores of NaN to make sure they don't get mistaken for the | |
187 // hole. Test both runtime and IC implementation. | |
188 test_various_stores = get_test_various_stores(); | |
189 test_various_stores(large_array, | |
190 NaN, | |
191 -NaN, | |
192 expected_array_value(6)); | |
193 test_various_loads(large_array, | |
194 NaN, | |
195 -NaN, | |
196 expected_array_value(6)); | |
197 test_various_stores(large_array, | |
198 expected_array_value(5), | |
199 expected_array_value(6), | |
200 expected_array_value(7)); | |
201 test_various_loads(large_array, | |
202 expected_array_value(5), | |
203 expected_array_value(6), | |
204 expected_array_value(7)); | |
205 test_various_stores(large_array, | |
206 NaN, | |
207 -NaN, | |
208 expected_array_value(7)); | |
209 test_various_loads(large_array, | |
210 NaN, | |
211 -NaN, | |
212 expected_array_value(7)); | |
213 | |
214 // Test stores of Infinity to make sure they don't get mistaken for the | |
215 // hole. Test both runtime and IC implementation. | |
216 test_various_stores = get_test_various_stores(); | |
217 test_various_stores(large_array, | |
218 Infinity, | |
219 -Infinity, | |
220 expected_array_value(6)); | |
221 test_various_loads(large_array, | |
222 Infinity, | |
223 -Infinity, | |
224 expected_array_value(6)); | |
225 test_various_stores(large_array, | |
226 expected_array_value(5), | |
227 expected_array_value(6), | |
228 expected_array_value(7)); | |
229 test_various_loads(large_array, | |
230 expected_array_value(5), | |
231 expected_array_value(6), | |
232 expected_array_value(7)); | |
233 test_various_stores(large_array, | |
234 Infinity, | |
235 -Infinity, | |
236 expected_array_value(7)); | |
237 test_various_loads(large_array, | |
238 Infinity, | |
239 -Infinity, | |
240 expected_array_value(7)); | |
241 | |
242 delete large_array[5]; | |
243 | |
244 // Make sure that we haven't converted from fast double. | |
245 assertTrue(%HasFastDoubleElements(large_array)); | |
246 // Cause the array to grow beyond it's JSArray length. This will double the | |
247 // size of the capacity and force the array into "slow" dictionary case. | |
248 large_array[large_array_size+1] = 50; | |
249 assertTrue(%HasDictionaryElements(large_array)); | |
250 assertEquals(50, large_array[large_array_size+1]); | |
251 assertEquals(large_array_size+2, large_array.length); | |
252 assertEquals(undefined, large_array[5]); | |
253 assertEquals(undefined, large_array[large_array_size-1]); | |
254 assertEquals(undefined, large_array[-1]); | |
255 assertEquals(large_array_size+2, large_array.length); | |
256 | |
257 // Test dictionary -> double elements -> fast elements. | |
258 var large_array2 = new allocator(large_array_size); | |
259 force_to_fast_double_array(large_array2); | |
260 delete large_array2[5]; | |
261 | |
262 // Convert back to fast elements and make sure the contents of the array are | |
263 // unchanged. | |
264 large_array2[25] = new Object(); | |
265 assertTrue(%HasFastElements(large_array2)); | |
266 for (var i= 0; i < approx_dict_to_elements_threshold; i += 500 ) { | |
267 if (i != 25 && i != 5) { | |
268 assertEquals(expected_array_value(i), large_array2[i]); | |
269 } | |
270 } | |
271 assertEquals(undefined, large_array2[5]) | |
272 assertEquals(undefined, large_array2[large_array_size-1]) | |
273 assertEquals(undefined, large_array2[-1]) | |
274 assertEquals(large_array_size, large_array2.length); | |
74 } | 275 } |
75 assertTrue(undefined === foo2[5]) | 276 |
76 assertTrue(undefined === foo2[500000-1]) | 277 testOneArrayType(Array); |
77 assertTrue(undefined === foo2[-1]) | |
78 assertEquals(500000, foo2.length); | |
OLD | NEW |