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

Side by Side Diff: test/mjsunit/array-constructor-feedback.js

Issue 55933002: Inline array constructor. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added comment to CreateArrayDispatchOneArgument Created 7 years, 1 month 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/stub-cache-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
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // We also lost our ability to record kind feedback, as the site 131 // We also lost our ability to record kind feedback, as the site
132 // is megamorphic now. 132 // is megamorphic now.
133 assertKind(elements_kind.fast_smi_only, b); 133 assertKind(elements_kind.fast_smi_only, b);
134 assertOptimized(bar0); 134 assertOptimized(bar0);
135 b[0] = 3.5; 135 b[0] = 3.5;
136 c = bar0(Array); 136 c = bar0(Array);
137 assertKind(elements_kind.fast_smi_only, c); 137 assertKind(elements_kind.fast_smi_only, c);
138 })(); 138 })();
139 139
140 140
141 // Test: Ensure that bailouts from the stub don't deopt a crankshafted 141 // Test: Ensure that inlined array calls in crankshaft learn from deopts
142 // method with a call to that stub. 142 // based on the move to a dictionary for the array.
143 (function() { 143 (function() {
144 function bar(len) { 144 function bar(len) {
145 return new Array(len); 145 return new Array(len);
146 } 146 }
147 a = bar(10); 147 a = bar(10);
148 a[0] = "a string"; 148 a[0] = "a string";
149 a = bar(10); 149 a = bar(10);
150 assertKind(elements_kind.fast, a); 150 assertKind(elements_kind.fast, a);
151 %OptimizeFunctionOnNextCall(bar); 151 %OptimizeFunctionOnNextCall(bar);
152 a = bar(10); 152 a = bar(10);
153 assertKind(elements_kind.fast, a); 153 assertKind(elements_kind.fast, a);
154 assertOptimized(bar); 154 assertOptimized(bar);
155 // The stub bails out, but the method call should be fine. 155 // bar should deopt because the length is too large.
156 a = bar(100000); 156 a = bar(100000);
157 assertUnoptimized(bar);
158 assertKind(elements_kind.dictionary, a);
159 // The allocation site now has feedback that means the array constructor
160 // will not be inlined.
161 %OptimizeFunctionOnNextCall(bar);
162 a = bar(100000);
163 assertKind(elements_kind.dictionary, a);
157 assertOptimized(bar); 164 assertOptimized(bar);
158 assertKind(elements_kind.dictionary, a);
159 165
160 // If the argument isn't a smi, it bails out as well 166 // If the argument isn't a smi, it bails out as well
161 a = bar("oops"); 167 a = bar("oops");
162 assertOptimized(bar); 168 assertOptimized(bar);
163 assertKind(elements_kind.fast, a); 169 assertKind(elements_kind.fast, a);
164 170
165 function barn(one, two, three) { 171 function barn(one, two, three) {
166 return new Array(one, two, three); 172 return new Array(one, two, three);
167 } 173 }
168 174
169 barn(1, 2, 3); 175 barn(1, 2, 3);
170 barn(1, 2, 3); 176 barn(1, 2, 3);
171 %OptimizeFunctionOnNextCall(barn); 177 %OptimizeFunctionOnNextCall(barn);
172 barn(1, 2, 3); 178 barn(1, 2, 3);
173 assertOptimized(barn); 179 assertOptimized(barn);
174 a = barn(1, "oops", 3); 180 a = barn(1, "oops", 3);
175 // The stub should bail out but the method should remain optimized. 181 // The method should deopt, but learn from the failure to avoid inlining
182 // the array.
176 assertKind(elements_kind.fast, a); 183 assertKind(elements_kind.fast, a);
184 assertUnoptimized(barn);
185 %OptimizeFunctionOnNextCall(barn);
186 a = barn(1, "oops", 3);
177 assertOptimized(barn); 187 assertOptimized(barn);
178 })(); 188 })();
179 189
180 190
181 // Test: When a method with array constructor is crankshafted, the type 191 // Test: When a method with array constructor is crankshafted, the type
182 // feedback for elements kind is baked in. Verify that transitions don't 192 // feedback for elements kind is baked in. Verify that transitions don't
183 // change it anymore 193 // change it anymore
184 (function() { 194 (function() {
185 function bar() { 195 function bar() {
186 return new Array(); 196 return new Array();
(...skipping 25 matching lines...) Expand all
212 assertTrue(a instanceof Array); 222 assertTrue(a instanceof Array);
213 223
214 var contextB = Realm.create(); 224 var contextB = Realm.create();
215 Realm.eval(contextB, "function bar2() { return new Array(); };"); 225 Realm.eval(contextB, "function bar2() { return new Array(); };");
216 Realm.eval(contextB, "bar2(); bar2();"); 226 Realm.eval(contextB, "bar2(); bar2();");
217 Realm.eval(contextB, "%OptimizeFunctionOnNextCall(bar2);"); 227 Realm.eval(contextB, "%OptimizeFunctionOnNextCall(bar2);");
218 Realm.eval(contextB, "bar2();"); 228 Realm.eval(contextB, "bar2();");
219 assertFalse(Realm.eval(contextB, "bar2();") instanceof Array); 229 assertFalse(Realm.eval(contextB, "bar2();") instanceof Array);
220 assertTrue(Realm.eval(contextB, "bar2() instanceof Array")); 230 assertTrue(Realm.eval(contextB, "bar2() instanceof Array"));
221 })(); 231 })();
232
233 // Test: create array with packed feedback, then optimize/inline
234 // function. Verify that if we ask for a holey array then we deopt.
235 // Reoptimization will proceed with the correct feedback and we
236 // won't deopt anymore.
237 (function() {
238 function bar(len) { return new Array(len); }
239 bar(0);
240 bar(0);
241 %OptimizeFunctionOnNextCall(bar);
242 a = bar(0);
243 assertOptimized(bar);
244 assertFalse(isHoley(a));
245 a = bar(1); // ouch!
246 assertUnoptimized(bar);
247 assertTrue(isHoley(a));
248 // Try again
249 %OptimizeFunctionOnNextCall(bar);
250 a = bar(100);
251 assertOptimized(bar);
252 assertTrue(isHoley(a));
253 a = bar(0);
254 assertOptimized(bar);
255 assertTrue(isHoley(a));
256 })();
222 } 257 }
OLDNEW
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698