 Chromium Code Reviews
 Chromium Code Reviews Issue 9431030:
  Support OSR in for-in loops.  (Closed) 
  Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
    
  
    Issue 9431030:
  Support OSR in for-in loops.  (Closed) 
  Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge| OLD | NEW | 
|---|---|
| 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 o.c = 3; | 235 o.c = 3; | 
| 236 o.d = 4; | 236 o.d = 4; | 
| 237 o.e = 5; | 237 o.e = 5; | 
| 238 o.f = 6; | 238 o.f = 6; | 
| 239 return o; | 239 return o; | 
| 240 }, function (t) { | 240 }, function (t) { | 
| 241 var r = []; | 241 var r = []; | 
| 242 for (var i in t) r.push(i + t[i]); | 242 for (var i in t) r.push(i + t[i]); | 
| 243 return r.join(''); | 243 return r.join(''); | 
| 244 }); | 244 }); | 
| 245 | |
| 246 // Test OSR inside for-in. | |
| 247 function osr_inner(t, limit) { | |
| 248 var r = 1; | |
| 249 for (var x in t) { | |
| 250 for (var i = 0; i < t[x].length; i++) { | |
| 251 r += t[x][i]; | |
| 252 if (i === limit) { | |
| 253 %OptimizeFunctionOnNextCall(osr_inner, "osr"); | |
| 254 } | |
| 255 } | |
| 256 r += x; | |
| 257 } | |
| 258 return r; | |
| 259 } | |
| 260 | |
| 261 function osr_outer(t, osr_after) { | |
| 262 var r = 1; | |
| 263 for (var x in t) { | |
| 264 for (var i = 0; i < t[x].length; i++) { | |
| 265 r += t[x][i]; | |
| 266 } | |
| 267 if (x === osr_after) { | |
| 268 %OptimizeFunctionOnNextCall(osr_outer, "osr"); | |
| 269 } | |
| 270 r += x; | |
| 271 } | |
| 272 return r; | |
| 273 } | |
| 274 | |
| 275 function osr_outer_and_deopt(t, osr_after) { | |
| 276 var r = 1; | |
| 277 for (var x in t) { | |
| 278 r += x; | |
| 279 if (x == osr_after) { | |
| 280 %OptimizeFunctionOnNextCall(osr_outer_and_deopt, "osr"); | |
| 281 } | |
| 282 } | |
| 283 return r; | |
| 284 } | |
| 285 | |
| 286 function test_osr() { | |
| 287 with ({}) {} // Disable optimizations of this function. | |
| 288 var arr = new Array(20); | |
| 289 for (var i = 0; i < arr.length; i++) { | |
| 290 arr[i] = i + 1; | |
| 291 } | |
| 292 arr.push(":"); // Force deopt at the end of the loop. | |
| 293 assertEquals("211:x", osr_inner({x: arr}, (arr.length / 2) | 0)); | |
| 294 assertEquals("7x456y", osr_outer({x: [1,2,3], y: [4,5,6]}, "x")); | |
| 295 assertEquals("101234567", osr_outer_and_deopt([1,2,3,4,5,6,7,8], "5")); | |
| 
fschneider
2012/02/22 16:22:39
You could check the optimization status with %GetO
 | |
| 296 } | |
| 297 | |
| 298 test_osr(); | |
| OLD | NEW |