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

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: Some updates Created 7 years, 10 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/code-stubs-x64.cc ('K') | « 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 29 // Flags: --track-allocation-sites --noalways-opt
30 30
31 // Test element kind of objects. 31 // Test element kind of objects.
32 // Since --smi-only-arrays affects builtins, its default setting at compile 32 // Since --smi-only-arrays affects builtins, its default setting at compile
33 // time sticks if built with snapshot. If --smi-only-arrays is deactivated 33 // time sticks if built with snapshot. If --smi-only-arrays is deactivated
34 // by default, only a no-snapshot build actually has smi-only arrays enabled 34 // by default, only a no-snapshot build actually has smi-only arrays enabled
35 // in this test case. Depending on whether smi-only arrays are actually 35 // in this test case. Depending on whether smi-only arrays are actually
36 // enabled, this test takes the appropriate code path to check smi-only arrays. 36 // enabled, this test takes the appropriate code path to check smi-only arrays.
37 37
38 support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); 38 support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8));
39 39
(...skipping 29 matching lines...) Expand all
69 function assertKind(expected, obj, name_opt) { 69 function assertKind(expected, obj, name_opt) {
70 if (!support_smi_only_arrays && 70 if (!support_smi_only_arrays &&
71 expected == elements_kind.fast_smi_only) { 71 expected == elements_kind.fast_smi_only) {
72 expected = elements_kind.fast; 72 expected = elements_kind.fast;
73 } 73 }
74 assertEquals(expected, getKind(obj), name_opt); 74 assertEquals(expected, getKind(obj), name_opt);
75 } 75 }
76 76
77 if (support_smi_only_arrays) { 77 if (support_smi_only_arrays) {
78 function fastliteralcase(literal, value) { 78 function fastliteralcase(literal, value) {
79 // var literal = [1, 2, 3];
80 literal[0] = value; 79 literal[0] = value;
81 return literal; 80 return literal;
82 } 81 }
83 82
84 function get_standard_literal() { 83 function get_standard_literal() {
85 var literal = [1, 2, 3]; 84 var literal = [1, 2, 3];
86 return literal; 85 return literal;
87 } 86 }
88 87
89 // Case: [1,2,3] as allocation site 88 // Case: [1,2,3] as allocation site
90 obj = fastliteralcase(get_standard_literal(), 1); 89 obj = fastliteralcase(get_standard_literal(), 1);
91 assertKind(elements_kind.fast_smi_only, obj); 90 assertKind(elements_kind.fast_smi_only, obj);
92 obj = fastliteralcase(get_standard_literal(), 1.5); 91 obj = fastliteralcase(get_standard_literal(), 1.5);
93 assertKind(elements_kind.fast_double, obj); 92 assertKind(elements_kind.fast_double, obj);
94 obj = fastliteralcase(get_standard_literal(), 2); 93 obj = fastliteralcase(get_standard_literal(), 2);
95 assertKind(elements_kind.fast_double, obj); 94 assertKind(elements_kind.fast_double, obj);
96 95
97 obj = fastliteralcase([5, 3, 2], 1.5); 96 // The test below is in a loop because arrays that live
98 assertKind(elements_kind.fast_double, obj); 97 // at global scope without the chance of being recreated
99 obj = fastliteralcase([3, 6, 2], 1.5); 98 // don't have allocation site information attached.
100 assertKind(elements_kind.fast_double, obj); 99 for(i=0;i<2;i++) {
101 obj = fastliteralcase([2, 6, 3], 2); 100 obj = fastliteralcase([5, 3, 2], 1.5);
102 assertKind(elements_kind.fast_smi_only, obj); 101 assertKind(elements_kind.fast_double, obj);
102 obj = fastliteralcase([3, 6, 2], 1.5);
103 assertKind(elements_kind.fast_double, obj);
104 obj = fastliteralcase([2, 6, 3], 2);
105 assertKind(elements_kind.fast_smi_only, obj);
106 }
103 107
104 // Verify that we will not pretransition the double->fast path. 108 // Verify that we will not pretransition the double->fast path.
105 obj = fastliteralcase(get_standard_literal(), "elliot"); 109 obj = fastliteralcase(get_standard_literal(), "elliot");
106 assertKind(elements_kind.fast, obj); 110 assertKind(elements_kind.fast, obj);
107 111
108 // This fails until we turn off optimistic transitions to the 112 // This fails until we turn off optimistic transitions to the
109 // most general elements kind seen on keyed stores. It's a goal 113 // most general elements kind seen on keyed stores. It's a goal
110 // to turn it off, but for now we need it. 114 // to turn it off, but for now we need it.
111 // obj = fastliteralcase(3); 115 // obj = fastliteralcase(3);
112 // assertKind(elements_kind.fast_double, obj); 116 // assertKind(elements_kind.fast_double, obj);
113 117
118 // Make sure this works in crankshafted code too.
119 %OptimizeFunctionOnNextCall(get_standard_literal);
120 get_standard_literal();
121 obj = get_standard_literal();
122 assertKind(elements_kind.fast_double, obj);
123
114 function fastliteralcase_smifast(value) { 124 function fastliteralcase_smifast(value) {
115 var literal = [1, 2, 3, 4]; 125 var literal = [1, 2, 3, 4];
116 literal[0] = value; 126 literal[0] = value;
117 return literal; 127 return literal;
118 } 128 }
119 129
120 obj = fastliteralcase_smifast(1); 130 obj = fastliteralcase_smifast(1);
121 assertKind(elements_kind.fast_smi_only, obj); 131 assertKind(elements_kind.fast_smi_only, obj);
122 obj = fastliteralcase_smifast("carter"); 132 obj = fastliteralcase_smifast("carter");
123 assertKind(elements_kind.fast, obj); 133 assertKind(elements_kind.fast, obj);
124 obj = fastliteralcase_smifast(2); 134 obj = fastliteralcase_smifast(2);
125 assertKind(elements_kind.fast, obj); 135 assertKind(elements_kind.fast, obj);
136
137 // Make sure we handle nested arrays
138 function get_nested_literal() {
139 var literal = [[1,2,3,4], [2], [3]];
140 return literal;
141 }
142
143 obj = get_nested_literal();
144 assertKind(elements_kind.fast, obj);
145 assertKind(elements_kind.fast_smi_only, obj[0]);
146 assertKind(elements_kind.fast_smi_only, obj[1]);
147 assertKind(elements_kind.fast_smi_only, obj[2]);
148 obj[0][0] = 3.5;
149 obj[2][0] = "hello";
150 assertKind(elements_kind.fast_double, obj[0]);
151 assertKind(elements_kind.fast_smi_only, obj[1]);
152 assertKind(elements_kind.fast, obj[2]);
153 obj = get_nested_literal();
154 assertKind(elements_kind.fast, obj);
155 assertKind(elements_kind.fast_double, obj[0]);
156 assertKind(elements_kind.fast_smi_only, obj[1]);
157 assertKind(elements_kind.fast, obj[2]);
158
159 // A more complex nested literal case.
160 function get_deep_nested_literal() {
161 var literal = [[1], [[2], "hello"], 3, [4]];
162 return literal;
163 }
164
165 obj = get_deep_nested_literal();
166 assertKind(elements_kind.fast_smi_only, obj[0]);
167 assertKind(elements_kind.fast, obj[1]);
168 assertKind(elements_kind.fast_smi_only, obj[1][0]);
169 assertKind(elements_kind.fast_smi_only, obj[3]);
170 obj[0][0] = 3.5;
171 obj[1][0][0] = "goodbye";
172
173 assertKind(elements_kind.fast_double, obj[0]);
174 assertKind(elements_kind.fast, obj[1]);
175 assertKind(elements_kind.fast, obj[1][0]);
176 assertKind(elements_kind.fast_smi_only, obj[3]);
177
178 obj = get_deep_nested_literal();
179
180 assertKind(elements_kind.fast_double, obj[0]);
181 assertKind(elements_kind.fast, obj[1]);
182 assertKind(elements_kind.fast, obj[1][0]);
183 assertKind(elements_kind.fast_smi_only, obj[3]);
184
185 // A literal in an object
186 function get_object_literal() {
187 var literal = {
188 array: [1,2,3],
189 data: 3.5
190 };
191 return literal;
192 }
193
194 obj = get_object_literal();
195 assertKind(elements_kind.fast_smi_only, obj.array);
196 obj.array[1] = 3.5;
197 assertKind(elements_kind.fast_double, obj.array);
198 obj = get_object_literal();
199 assertKind(elements_kind.fast_double, obj.array);
200
201 function get_nested_object_literal() {
202 var literal = {
203 array: [[1],[2],[3]],
204 data: 3.5
205 };
206 return literal;
207 }
208
209 obj = get_nested_object_literal();
210 assertKind(elements_kind.fast, obj.array);
211 assertKind(elements_kind.fast_smi_only, obj.array[1]);
212 obj.array[1][0] = 3.5;
213 assertKind(elements_kind.fast_double, obj.array[1]);
214 obj = get_nested_object_literal();
215 assertKind(elements_kind.fast_double, obj.array[1]);
216
217 %OptimizeFunctionOnNextCall(get_nested_object_literal);
218 get_nested_object_literal();
219 obj = get_nested_object_literal();
220 assertKind(elements_kind.fast_double, obj.array[1]);
126 } 221 }
OLDNEW
« src/x64/code-stubs-x64.cc ('K') | « src/x64/lithium-codegen-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698