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

Side by Side Diff: test/mjsunit/ensure-growing-store-learns.js

Issue 368263003: Use a stub in crankshaft for grow store arrays. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Performance fixes. Created 6 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/ia32/lithium-ia32.cc ('K') | « src/runtime.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
(Empty)
1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27
28 // Flags: --allow-natives-syntax --noverify-heap
29
30 // --noverify-heap is set because the test is too slow with it on.
31
32 // Ensure that keyed stores work, and optimized functions learn if the
33 // store required change to dictionary mode. Verify that stores that grow
34 // the array into large object space don't cause a deopt.
35 (function() {
36 var a = [];
37
38 function foo(a, i) {
39 a[i] = 5.3;
40 }
41
42 foo(a, 1);
43 foo(a, 2);
44 foo(a, 3);
45 %OptimizeFunctionOnNextCall(foo);
46 a[3] = 0;
47 foo(a, 3);
48 assertEquals(a[3], 5.3);
49 foo(a, 50000);
50 assertUnoptimized(foo);
51 assertTrue(%HasDictionaryElements(a));
52
53 var b = [];
54 foo(b, 1);
55 foo(b, 2);
56 // Put b in dictionary mode.
57 b[10000] = 5;
58 assertTrue(%HasDictionaryElements(b));
59 foo(b, 3);
60 %OptimizeFunctionOnNextCall(foo);
61 foo(b, 50000);
62 assertOptimized(foo);
63 assertTrue(%HasDictionaryElements(b));
64 })();
65
66
67 (function() {
68 var a = new Array(10);
69
70 function foo2(a, i) {
71 a[i] = 50;
72 }
73
74 // The KeyedStoreIC will learn GROW_MODE.
75 foo2(a, 10);
76 foo2(a, 12);
77 foo2(a, 31);
78 %OptimizeFunctionOnNextCall(foo2);
79 foo2(a, 40);
80 assertOptimized(foo2);
81 assertTrue(%HasFastSmiElements(a));
82
83 // Grow a large array into large object space through the keyed store
84 // without deoptimizing. Grow by 10s. If we set elements too sparsely, the
85 // array will convert to dictionary mode.
86 a = new Array(99999);
87 assertTrue(%HasFastSmiElements(a));
88 for (var i = 0; i < 263000; i += 10) {
89 foo2(a, i);
90 }
91
92 // Verify that we are over 1 page in size, and foo2 remains optimized.
93 // This means we've smoothly transitioned to allocating in large object
94 // space.
95 assertTrue(%HasFastSmiElements(a));
96 assertTrue(a.length * 4 > (1024 * 1024));
97 assertOptimized(foo2);
98 })();
99
100
101 // Verify that it works with non-arrays too.
102 (function() {
103 // Get an object to create a fast elements array. It takes some effort.
104 var o = {};
105 function foo(a, i) {
106 a[i] = 50;
107 }
108 assertTrue(%HasFastSmiOrObjectElements(o));
109
110 foo(o, 0);
111 foo(o, 1);
112 %OptimizeFunctionOnNextCall(foo);
113 // 16 should be enough to make the elements array grow, but not go to
114 // dictionary mode.
115 foo(o, 16);
116 assertOptimized(foo);
117 foo(o, 32000);
118 assertUnoptimized(foo);
119 assertTrue(%HasDictionaryElements(o));
120 })();
OLDNEW
« src/ia32/lithium-ia32.cc ('K') | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698