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

Side by Side Diff: test/mjsunit/allocation-site-info.js

Issue 12114054: Supporting AllocationSiteInfo for Nested arrays (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressing a port compile failure Created 7 years, 9 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
« no previous file with comments | « src/x64/lithium-codegen-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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 // Flags: --allow-natives-syntax --smi-only-arrays --expose-gc 28 // Flags: --allow-natives-syntax --smi-only-arrays --expose-gc
29 // Flags: --track-allocation-sites --nooptimize-constructed-arrays 29 // Flags: --track-allocation-sites --noalways-opt
30 // Flags: --nooptimize-constructed-arrays
30 31
31 // TODO(mvstanton): remove --nooptimize-constructed-arrays and enable 32 // TODO(mvstanton): remove --nooptimize-constructed-arrays and enable
32 // the constructed array code below when the feature is turned on 33 // the constructed array code below when the feature is turned on
33 // by default. 34 // by default.
34 35
35 // Test element kind of objects. 36 // Test element kind of objects.
36 // Since --smi-only-arrays affects builtins, its default setting at compile 37 // Since --smi-only-arrays affects builtins, its default setting at compile
37 // time sticks if built with snapshot. If --smi-only-arrays is deactivated 38 // time sticks if built with snapshot. If --smi-only-arrays is deactivated
38 // by default, only a no-snapshot build actually has smi-only arrays enabled 39 // by default, only a no-snapshot build actually has smi-only arrays enabled
39 // in this test case. Depending on whether smi-only arrays are actually 40 // in this test case. Depending on whether smi-only arrays are actually
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 140 }
140 141
141 // Case: [1,2,3] as allocation site 142 // Case: [1,2,3] as allocation site
142 obj = fastliteralcase(get_standard_literal(), 1); 143 obj = fastliteralcase(get_standard_literal(), 1);
143 assertKind(elements_kind.fast_smi_only, obj); 144 assertKind(elements_kind.fast_smi_only, obj);
144 obj = fastliteralcase(get_standard_literal(), 1.5); 145 obj = fastliteralcase(get_standard_literal(), 1.5);
145 assertKind(elements_kind.fast_double, obj); 146 assertKind(elements_kind.fast_double, obj);
146 obj = fastliteralcase(get_standard_literal(), 2); 147 obj = fastliteralcase(get_standard_literal(), 2);
147 assertKind(elements_kind.fast_double, obj); 148 assertKind(elements_kind.fast_double, obj);
148 149
149 obj = fastliteralcase([5, 3, 2], 1.5); 150 // The test below is in a loop because arrays that live
150 assertKind(elements_kind.fast_double, obj); 151 // at global scope without the chance of being recreated
151 obj = fastliteralcase([3, 6, 2], 1.5); 152 // don't have allocation site information attached.
152 assertKind(elements_kind.fast_double, obj); 153 for(i=0;i<2;i++) {
153 obj = fastliteralcase([2, 6, 3], 2); 154 obj = fastliteralcase([5, 3, 2], 1.5);
154 assertKind(elements_kind.fast_smi_only, obj); 155 assertKind(elements_kind.fast_double, obj);
156 obj = fastliteralcase([3, 6, 2], 1.5);
157 assertKind(elements_kind.fast_double, obj);
158 obj = fastliteralcase([2, 6, 3], 2);
159 assertKind(elements_kind.fast_smi_only, obj);
160 }
155 161
156 // Verify that we will not pretransition the double->fast path. 162 // Verify that we will not pretransition the double->fast path.
157 obj = fastliteralcase(get_standard_literal(), "elliot"); 163 obj = fastliteralcase(get_standard_literal(), "elliot");
158 assertKind(elements_kind.fast, obj); 164 assertKind(elements_kind.fast, obj);
159 // This fails until we turn off optimistic transitions to the 165 // This fails until we turn off optimistic transitions to the
160 // most general elements kind seen on keyed stores. It's a goal 166 // most general elements kind seen on keyed stores. It's a goal
161 // to turn it off, but for now we need it. 167 // to turn it off, but for now we need it.
162 // obj = fastliteralcase(3); 168 // obj = fastliteralcase(3);
163 // assertKind(elements_kind.fast_double, obj); 169 // assertKind(elements_kind.fast_double, obj);
164 170
171 // Make sure this works in crankshafted code too.
172 %OptimizeFunctionOnNextCall(get_standard_literal);
173 get_standard_literal();
174 obj = get_standard_literal();
175 assertKind(elements_kind.fast_double, obj);
176
165 function fastliteralcase_smifast(value) { 177 function fastliteralcase_smifast(value) {
166 var literal = [1, 2, 3, 4]; 178 var literal = [1, 2, 3, 4];
167 literal[0] = value; 179 literal[0] = value;
168 return literal; 180 return literal;
169 } 181 }
170 182
171 obj = fastliteralcase_smifast(1); 183 obj = fastliteralcase_smifast(1);
172 assertKind(elements_kind.fast_smi_only, obj); 184 assertKind(elements_kind.fast_smi_only, obj);
173 obj = fastliteralcase_smifast("carter"); 185 obj = fastliteralcase_smifast("carter");
174 assertKind(elements_kind.fast, obj); 186 assertKind(elements_kind.fast, obj);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 return a; 274 return a;
263 } 275 }
264 276
265 obj = newarraycase_list_smiobj(1); 277 obj = newarraycase_list_smiobj(1);
266 assertKind(elements_kind.fast_smi_only, obj); 278 assertKind(elements_kind.fast_smi_only, obj);
267 obj = newarraycase_list_smiobj("coates"); 279 obj = newarraycase_list_smiobj("coates");
268 assertKind(elements_kind.fast, obj); 280 assertKind(elements_kind.fast, obj);
269 obj = newarraycase_list_smiobj(2); 281 obj = newarraycase_list_smiobj(2);
270 assertKind(elements_kind.fast, obj); 282 assertKind(elements_kind.fast, obj);
271 } 283 }
284
285 // Make sure we handle nested arrays
286 function get_nested_literal() {
287 var literal = [[1,2,3,4], [2], [3]];
288 return literal;
289 }
290
291 obj = get_nested_literal();
292 assertKind(elements_kind.fast, obj);
293 assertKind(elements_kind.fast_smi_only, obj[0]);
294 assertKind(elements_kind.fast_smi_only, obj[1]);
295 assertKind(elements_kind.fast_smi_only, obj[2]);
296 obj[0][0] = 3.5;
297 obj[2][0] = "hello";
298 assertKind(elements_kind.fast_double, obj[0]);
299 assertKind(elements_kind.fast_smi_only, obj[1]);
300 assertKind(elements_kind.fast, obj[2]);
301 obj = get_nested_literal();
302 assertKind(elements_kind.fast, obj);
303 assertKind(elements_kind.fast_double, obj[0]);
304 assertKind(elements_kind.fast_smi_only, obj[1]);
305 assertKind(elements_kind.fast, obj[2]);
306
307 // A more complex nested literal case.
308 function get_deep_nested_literal() {
309 var literal = [[1], [[2], "hello"], 3, [4]];
310 return literal;
311 }
312
313 obj = get_deep_nested_literal();
314 assertKind(elements_kind.fast_smi_only, obj[0]);
315 assertKind(elements_kind.fast, obj[1]);
316 assertKind(elements_kind.fast_smi_only, obj[1][0]);
317 assertKind(elements_kind.fast_smi_only, obj[3]);
318 obj[0][0] = 3.5;
319 obj[1][0][0] = "goodbye";
320
321 assertKind(elements_kind.fast_double, obj[0]);
322 assertKind(elements_kind.fast, obj[1]);
323 assertKind(elements_kind.fast, obj[1][0]);
324 assertKind(elements_kind.fast_smi_only, obj[3]);
325
326 obj = get_deep_nested_literal();
327
328 assertKind(elements_kind.fast_double, obj[0]);
329 assertKind(elements_kind.fast, obj[1]);
330 assertKind(elements_kind.fast, obj[1][0]);
331 assertKind(elements_kind.fast_smi_only, obj[3]);
332
333 // A literal in an object
334 function get_object_literal() {
335 var literal = {
336 array: [1,2,3],
337 data: 3.5
338 };
339 return literal;
340 }
341
342 obj = get_object_literal();
343 assertKind(elements_kind.fast_smi_only, obj.array);
344 obj.array[1] = 3.5;
345 assertKind(elements_kind.fast_double, obj.array);
346 obj = get_object_literal();
347 assertKind(elements_kind.fast_double, obj.array);
348
349 function get_nested_object_literal() {
350 var literal = {
351 array: [[1],[2],[3]],
352 data: 3.5
353 };
354 return literal;
355 }
356
357 obj = get_nested_object_literal();
358 assertKind(elements_kind.fast, obj.array);
359 assertKind(elements_kind.fast_smi_only, obj.array[1]);
360 obj.array[1][0] = 3.5;
361 assertKind(elements_kind.fast_double, obj.array[1]);
362 obj = get_nested_object_literal();
363 assertKind(elements_kind.fast_double, obj.array[1]);
364
365 %OptimizeFunctionOnNextCall(get_nested_object_literal);
366 get_nested_object_literal();
367 obj = get_nested_object_literal();
368 assertKind(elements_kind.fast_double, obj.array[1]);
272 } 369 }
OLDNEW
« no previous file with comments | « src/x64/lithium-codegen-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698