OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 assertEquals(99, o2.b.x); | 296 assertEquals(99, o2.b.x); |
297 } | 297 } |
298 deep(); deep(); | 298 deep(); deep(); |
299 %OptimizeFunctionOnNextCall(deep); | 299 %OptimizeFunctionOnNextCall(deep); |
300 deep(); deep(); | 300 deep(); deep(); |
301 delete deopt.deopt; | 301 delete deopt.deopt; |
302 deep(); deep(); | 302 deep(); deep(); |
303 })(); | 303 })(); |
304 | 304 |
305 | 305 |
| 306 // Test non-shallow nested graph of captured objects with duplicates |
| 307 (function testDeepDuplicate() { |
| 308 function constructor1() { |
| 309 this.x = 23; |
| 310 } |
| 311 function constructor2(nested) { |
| 312 this.a = 17; |
| 313 this.b = nested; |
| 314 this.c = 42; |
| 315 } |
| 316 function deep(shouldDeopt) { |
| 317 var o1 = new constructor1(); |
| 318 var o2 = new constructor2(o1); |
| 319 var o3 = new constructor2(o1); |
| 320 assertEquals(17, o2.a); |
| 321 assertEquals(23, o2.b.x); |
| 322 assertEquals(42, o2.c); |
| 323 o3.c = 54; |
| 324 o1.x = 99; |
| 325 if (shouldDeopt) %DeoptimizeFunction(deep); |
| 326 assertEquals(99, o1.x); |
| 327 assertEquals(99, o2.b.x); |
| 328 assertEquals(99, o3.b.x); |
| 329 assertEquals(54, o3.c); |
| 330 assertEquals(17, o3.a); |
| 331 assertEquals(42, o2.c); |
| 332 assertEquals(17, o2.a); |
| 333 o3.b.x = 1; |
| 334 assertEquals(1, o1.x); |
| 335 } |
| 336 deep(false); deep(false); |
| 337 %OptimizeFunctionOnNextCall(deep); |
| 338 deep(false); deep(false); |
| 339 deep(true); deep(true); |
| 340 })(); |
| 341 |
| 342 |
| 343 // Test non-shallow nested graph of captured objects with inline |
| 344 (function testDeepInline() { |
| 345 function h() { |
| 346 return { y : 3 }; |
| 347 } |
| 348 |
| 349 function g(x) { |
| 350 var u = { x : h() }; |
| 351 %DeoptimizeFunction(f); |
| 352 return u; |
| 353 } |
| 354 |
| 355 function f() { |
| 356 var l = { dummy : { } }; |
| 357 var r = g(l); |
| 358 assertEquals(3, r.x.y); |
| 359 } |
| 360 |
| 361 f(); f(); f(); |
| 362 %OptimizeFunctionOnNextCall(f); |
| 363 f(); |
| 364 })(); |
| 365 |
| 366 |
| 367 // Test two nested objects |
| 368 (function testTwoNestedObjects() { |
| 369 function f() { |
| 370 var l = { x : { y : 111 } }; |
| 371 var l2 = { x : { y : 111 } }; |
| 372 %DeoptimizeFunction(f); |
| 373 assertEquals(111, l.x.y); |
| 374 assertEquals(111, l2.x.y); |
| 375 } |
| 376 |
| 377 f(); f(); f(); |
| 378 %OptimizeFunctionOnNextCall(f); |
| 379 f(); |
| 380 })(); |
| 381 |
| 382 |
| 383 // Test a nested object and a duplicate |
| 384 (function testTwoObjectsWithDuplicate() { |
| 385 function f() { |
| 386 var l = { x : { y : 111 } }; |
| 387 var dummy = { d : 0 }; |
| 388 var l2 = l.x; |
| 389 %DeoptimizeFunction(f); |
| 390 assertEquals(111, l.x.y); |
| 391 assertEquals(111, l2.y); |
| 392 assertEquals(0, dummy.d); |
| 393 } |
| 394 |
| 395 f(); f(); f(); |
| 396 %OptimizeFunctionOnNextCall(f); |
| 397 f(); |
| 398 })(); |
| 399 |
| 400 |
306 // Test materialization of a field that requires a Smi value. | 401 // Test materialization of a field that requires a Smi value. |
307 (function testSmiField() { | 402 (function testSmiField() { |
308 var deopt = { deopt:false }; | 403 var deopt = { deopt:false }; |
309 function constructor() { | 404 function constructor() { |
310 this.x = 1; | 405 this.x = 1; |
311 } | 406 } |
312 function field(x) { | 407 function field(x) { |
313 var o = new constructor(); | 408 var o = new constructor(); |
314 o.x = x; | 409 o.x = x; |
315 deopt.deopt | 410 deopt.deopt |
(...skipping 18 matching lines...) Expand all Loading... |
334 o.x = x; | 429 o.x = x; |
335 deopt.deopt | 430 deopt.deopt |
336 assertEquals(x, o.x); | 431 assertEquals(x, o.x); |
337 } | 432 } |
338 field({}); field({}); | 433 field({}); field({}); |
339 %OptimizeFunctionOnNextCall(field); | 434 %OptimizeFunctionOnNextCall(field); |
340 field({}); field({}); | 435 field({}); field({}); |
341 delete deopt.deopt; | 436 delete deopt.deopt; |
342 field(1); field(2); | 437 field(1); field(2); |
343 })(); | 438 })(); |
OLD | NEW |