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

Side by Side Diff: test/mjsunit/compiler/optimized-for-in.js

Issue 2151773002: Avoid jumping to the runtime for ForInFilter (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: remove double label Created 4 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
« no previous file with comments | « test/cctest/test-api.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 17 matching lines...) Expand all
28 // Flags: --allow-natives-syntax 28 // Flags: --allow-natives-syntax
29 29
30 // Test for-in support in Crankshaft. For simplicity this tests assumes certain 30 // Test for-in support in Crankshaft. For simplicity this tests assumes certain
31 // fixed iteration order for properties and will have to be adjusted if V8 31 // fixed iteration order for properties and will have to be adjusted if V8
32 // stops following insertion order. 32 // stops following insertion order.
33 33
34 34
35 function a(t) { 35 function a(t) {
36 var result = []; 36 var result = [];
37 for (var i in t) { 37 for (var i in t) {
38 result.push(i + t[i]); 38 result.push([i, t[i]]);
39 } 39 }
40 return result.join(''); 40 return result;
41 } 41 }
42 42
43 // Check that we correctly deoptimize on map check. 43 // Check that we correctly deoptimize on map check.
44 function b(t) { 44 function b(t) {
45 var result = []; 45 var result = [];
46 for (var i in t) { 46 for (var i in t) {
47 result.push(i + t[i]); 47 result.push([i, t[i]]);
48 delete t[i]; 48 delete t[i];
49 } 49 }
50 return result.join(''); 50 return result;
51 } 51 }
52 52
53 // Check that we correctly deoptimize during preparation step. 53 // Check that we correctly deoptimize during preparation step.
54 function c(t) { 54 function c(t) {
55 var result = []; 55 var result = [];
56 for (var i in t) { 56 for (var i in t) {
57 result.push(i + t[i]); 57 result.push([i, t[i]]);
58 } 58 }
59 return result.join(''); 59 return result;
60 } 60 }
61 61
62 // Check that we deoptimize to the place after side effect in the right state. 62 // Check that we deoptimize to the place after side effect in the right state.
63 function d(t) { 63 function d(t) {
64 var result = []; 64 var result = [];
65 var o; 65 var o;
66 for (var i in (o = t())) { 66 for (var i in (o = t())) {
67 result.push(i + o[i]); 67 result.push([i, o[i]]);
68 } 68 }
69 return result.join(''); 69 return result;
70 } 70 }
71 71
72 // Check that we correctly deoptimize on map check inserted for fused load. 72 // Check that we correctly deoptimize on map check inserted for fused load.
73 function e(t) { 73 function e(t) {
74 var result = []; 74 var result = [];
75 for (var i in t) { 75 for (var i in t) {
76 delete t[i]; 76 delete t[i];
77 t[i] = i; 77 t[i] = i;
78 result.push(i + t[i]); 78 result.push([i, t[i]]);
79 } 79 }
80 return result.join(''); 80 return result;
81 } 81 }
82 82
83 // Nested for-in loops. 83 // Nested for-in loops.
84 function f(t) { 84 function f(t) {
85 var result = []; 85 var result = [];
86 for (var i in t) { 86 for (var i in t) {
87 for (var j in t) { 87 for (var j in t) {
88 result.push(i + j + t[i] + t[j]); 88 result.push([i, j, t[i], t[j]]);
89 } 89 }
90 } 90 }
91 return result.join(''); 91 return result;
92 } 92 }
93 93
94 // Deoptimization from the inner for-in loop. 94 // Deoptimization from the inner for-in loop.
95 function g(t) { 95 function g(t) {
96 var result = []; 96 var result = [];
97 for (var i in t) { 97 for (var i in t) {
98 for (var j in t) { 98 for (var j in t) {
99 result.push(i + j + t[i] + t[j]); 99 result.push([i, j, t[i], t[j]]);
100 var v = t[i]; 100 var v = t[i];
101 delete t[i]; 101 delete t[i];
102 t[i] = v; 102 t[i] = v;
103 } 103 }
104 } 104 }
105 return result.join(''); 105 return result;
106 } 106 }
107 107
108 108
109 // Break from the inner for-in loop. 109 // Break from the inner for-in loop.
110 function h(t, deopt) { 110 function h(t, deopt) {
111 var result = []; 111 var result = [];
112 for (var i in t) { 112 for (var i in t) {
113 for (var j in t) { 113 for (var j in t) {
114 result.push(i + j + t[i] + t[j]); 114 result.push([i, j, t[i], t[j]]);
115 break; 115 break;
116 } 116 }
117 } 117 }
118 deopt.deopt; 118 deopt.deopt;
119 return result.join(''); 119 return result;
120 } 120 }
121 121
122 // Continue in the inner loop. 122 // Continue in the inner loop.
123 function j(t, deopt) { 123 function j(t, deopt) {
124 var result = []; 124 var result = [];
125 for (var i in t) { 125 for (var i in t) {
126 for (var j in t) { 126 for (var j in t) {
127 result.push(i + j + t[i] + t[j]); 127 result.push([i, j, t[i], t[j]]);
128 continue; 128 continue;
129 } 129 }
130 } 130 }
131 deopt.deopt; 131 deopt.deopt;
132 return result.join(''); 132 return result;
133 } 133 }
134 134
135 // Continue of the outer loop. 135 // Continue of the outer loop.
136 function k(t, deopt) { 136 function k(t, deopt) {
137 var result = []; 137 var result = [];
138 outer: for (var i in t) { 138 outer: for (var i in t) {
139 for (var j in t) { 139 for (var j in t) {
140 result.push(i + j + t[i] + t[j]); 140 result.push([i, j, t[i], t[j]]);
141 continue outer; 141 continue outer;
142 } 142 }
143 } 143 }
144 deopt.deopt; 144 deopt.deopt;
145 return result.join(''); 145 return result;
146 } 146 }
147 147
148 // Break of the outer loop. 148 // Break of the outer loop.
149 function l(t, deopt) { 149 function l(t, deopt) {
150 var result = []; 150 var result = [];
151 outer: for (var i in t) { 151 outer: for (var i in t) {
152 for (var j in t) { 152 for (var j in t) {
153 result.push(i + j + t[i] + t[j]); 153 result.push([i, j, t[i], t[j]]);
154 break outer; 154 break outer;
155 } 155 }
156 } 156 }
157 deopt.deopt; 157 deopt.deopt;
158 return result.join(''); 158 return result;
159 } 159 }
160 160
161 // Test deoptimization from inlined frame (currently it is not inlined). 161 // Test deoptimization from inlined frame (currently it is not inlined).
162 function m0(t, deopt) { 162 function m0(t, deopt) {
163 for (var i in t) { 163 for (var i in t) {
164 for (var j in t) { 164 for (var j in t) {
165 deopt.deopt; 165 deopt.deopt;
166 return i + j + t[i] + t[j]; 166 return [i, j, t[i], t[j]];
167 } 167 }
168 } 168 }
169 } 169 }
170 170
171 function m(t, deopt) { 171 function m(t, deopt) {
172 return m0(t, deopt); 172 return m0(t, deopt);
173 } 173 }
174 174
175 175
176 function tryFunction(s, mkT, f) { 176 function tryFunction(result, mkT, f) {
177 var d = {deopt: false}; 177 var d = {deopt: false};
178 assertEquals(s, f(mkT(), d)); 178 assertEquals(result, f(mkT(), d));
179 assertEquals(s, f(mkT(), d)); 179 assertEquals(result, f(mkT(), d));
180 assertEquals(s, f(mkT(), d)); 180 assertEquals(result, f(mkT(), d));
181 %OptimizeFunctionOnNextCall(f); 181 %OptimizeFunctionOnNextCall(f);
182 assertEquals(s, f(mkT(), d)); 182 assertEquals(result, f(mkT(), d));
183 assertEquals(s, f(mkT(), {})); 183 assertEquals(result, f(mkT(), {}));
184 } 184 }
185 185
186 var s = "a1b2c3d4"; 186 var expectedResult = [["a","1"],["b","2"],["c","3"],["d","4"]];
187 function mkTable() { return { a: "1", b: "2", c: "3", d: "4" }; } 187 function mkTable() { return { a: "1", b: "2", c: "3", d: "4" }; }
188 188
189 189
190 tryFunction(s, mkTable, a); 190 tryFunction(expectedResult, mkTable, a);
191 tryFunction(s, mkTable, b); 191 tryFunction(expectedResult, mkTable, b);
192 tryFunction("0a1b2c3d", function () { return "abcd"; }, c); 192
193 tryFunction("0a1b2c3d", function () { 193 expectedResult = [["0","a"],["1","b"],["2","c"],["3","d"]];
194 tryFunction(expectedResult, function () { return "abcd"; }, c);
195 tryFunction(expectedResult, function () {
194 var cnt = false; 196 var cnt = false;
195 return function () { 197 return function () {
196 cnt = true; 198 cnt = true;
197 return "abcd"; 199 return "abcd";
198 } 200 }
199 }, d); 201 }, d);
200 tryFunction("aabbccdd", mkTable, e); 202 tryFunction([["a","a"],["b","b"],["c","c"],["d","d"]], mkTable, e);
201 203
202 function mkSmallTable() { return { a: "1", b: "2" }; } 204 function mkSmallTable() { return { a: "1", b: "2" }; }
203 205
204 tryFunction("aa11ab12ba21bb22", mkSmallTable, f); 206 tryFunction([
205 tryFunction("aa11ab12bb22ba21", mkSmallTable, g); 207 ["a","a","1","1"],["a","b","1","2"],
206 tryFunction("aa11ba21", mkSmallTable, h); 208 ["b","a","2","1"],["b","b","2","2"]],
207 tryFunction("aa11ab12ba21bb22", mkSmallTable, j); 209 mkSmallTable, f);
208 tryFunction("aa11ba21", mkSmallTable, h); 210 tryFunction([
209 tryFunction("aa11ba21", mkSmallTable, k); 211 ["a","a","1","1"],["a","b","1","2"],
210 tryFunction("aa11", mkSmallTable, l); 212 ["b","b","2","2"],["b","a","2","1"]],
211 tryFunction("aa11", mkSmallTable, m); 213 mkSmallTable, g);
214 tryFunction([["a","a","1","1"],["b","a","2","1"]], mkSmallTable, h);
215 tryFunction([
216 ["a","a","1","1"],["a","b","1","2"],
217 ["b","a","2","1"],["b","b","2","2"]],
218 mkSmallTable, j);
219 tryFunction([["a","a","1","1"],["b","a","2","1"]], mkSmallTable, h);
220 tryFunction([["a","a","1","1"],["b","a","2","1"]], mkSmallTable, k);
221 tryFunction([["a","a","1","1"]], mkSmallTable, l);
222 tryFunction(["a","a","1","1"], mkSmallTable, m);
212 223
213 // Test handling of null. 224 // Test handling of null.
214 tryFunction("", function () { 225 tryFunction("", function () {
215 return function () { return null; } 226 return function () { return null; }
216 }, function (t) { 227 }, function (t) {
217 for (var i in t()) { return i; } 228 for (var i in t()) { return i; }
218 return ""; 229 return "";
219 }); 230 });
220 231
221 // Test smis. 232 // Test smis.
222 tryFunction("", function () { 233 tryFunction("", function () {
223 return function () { return 11; } 234 return function () { return 11; }
224 }, function (t) { 235 }, function (t) {
225 for (var i in t()) { return i; } 236 for (var i in t()) { return i; }
226 return ""; 237 return "";
227 }); 238 });
228 239
229 // Test LoadFieldByIndex for out of object properties. 240 // Test LoadFieldByIndex for out of object properties.
230 function O() { this.a = 1; } 241 function O() { this.a = 1; }
231 for (var i = 0; i < 10; i++) new O(); 242 for (var i = 0; i < 10; i++) new O();
232 tryFunction("a1b2c3d4e5f6", function () { 243 tryFunction([["a",1],["b",2],["c",3],["d",4],["e",5],["f",6]], function () {
233 var o = new O(); 244 var o = new O();
234 o.b = 2; 245 o.b = 2;
235 o.c = 3; 246 o.c = 3;
236 o.d = 4; 247 o.d = 4;
237 o.e = 5; 248 o.e = 5;
238 o.f = 6; 249 o.f = 6;
239 return o; 250 return o;
240 }, function (t) { 251 }, function (t) {
241 var r = []; 252 var r = [];
242 for (var i in t) r.push(i + t[i]); 253 for (var i in t) r.push([i, t[i]]);
243 return r.join(''); 254 return r;
244 }); 255 });
245 256
246 // Test OSR inside for-in. 257 // Test OSR inside for-in.
247 function osr_inner(t, limit) { 258 function osr_inner(t, limit) {
248 var r = 1; 259 var r = 1;
249 for (var x in t) { 260 for (var x in t) {
250 if (t.hasOwnProperty(x)) { 261 if (t.hasOwnProperty(x)) {
251 for (var i = 0; i < t[x].length; i++) { 262 for (var i = 0; i < t[x].length; i++) {
252 r += t[x][i]; 263 r += t[x][i];
253 if (i === limit) %OptimizeOsr(); 264 if (i === limit) %OptimizeOsr();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 for (var i = 0; i < arr.length; i++) { 296 for (var i = 0; i < arr.length; i++) {
286 arr[i] = i + 1; 297 arr[i] = i + 1;
287 } 298 }
288 arr.push(":"); // Force deopt at the end of the loop. 299 arr.push(":"); // Force deopt at the end of the loop.
289 assertEquals("211:x1234567891011121314151617181920:y", osr_inner({x: arr, y: a rr}, (arr.length / 2) | 0)); 300 assertEquals("211:x1234567891011121314151617181920:y", osr_inner({x: arr, y: a rr}, (arr.length / 2) | 0));
290 assertEquals("7x456y", osr_outer({x: [1,2,3], y: [4,5,6]}, "x")); 301 assertEquals("7x456y", osr_outer({x: [1,2,3], y: [4,5,6]}, "x"));
291 assertEquals("101234567", osr_outer_and_deopt([1,2,3,4,5,6,7,8], "5")); 302 assertEquals("101234567", osr_outer_and_deopt([1,2,3,4,5,6,7,8], "5"));
292 } 303 }
293 304
294 test_osr(); 305 test_osr();
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698