| 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 |
| 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 --expose-gc --inline-construct | 28 // Flags: --allow-natives-syntax --inline-construct |
| 29 | 29 |
| 30 // Test that inlined object allocation works for different layouts of | 30 // Test that inlined object allocation works for different layouts of |
| 31 // objects (e.g. in object properties, slack tracking in progress or | 31 // objects (e.g. in object properties, slack tracking in progress or |
| 32 // changing of function prototypes) | 32 // changing of function prototypes) |
| 33 | 33 |
| 34 function test_helper(construct, a, b) { | 34 function test_helper(construct, a, b) { |
| 35 return new construct(a, b); | 35 return new construct(a, b); |
| 36 } | 36 } |
| 37 | 37 |
| 38 function test(construct) { | 38 function test(construct) { |
| 39 %DeoptimizeFunction(test); | 39 %DeoptimizeFunction(test); |
| 40 test_helper(construct, 0, 0); | 40 test_helper(construct, 0, 0); |
| 41 test_helper(construct, 0, 0); | 41 test_helper(construct, 0, 0); |
| 42 %OptimizeFunctionOnNextCall(test_helper); | 42 %OptimizeFunctionOnNextCall(test_helper); |
| 43 // Test adding a new property after allocation was inlined. | 43 // Test adding a new property after allocation was inlined. |
| 44 var o = test_helper(construct, 1, 2); | 44 var o = test_helper(construct, 1, 2); |
| 45 o.z = 3; | 45 o.z = 3; |
| 46 assertEquals(1, o.x); | 46 assertEquals(1, o.x); |
| 47 assertEquals(2, o.y); | 47 assertEquals(2, o.y); |
| 48 assertEquals(3, o.z); | 48 assertEquals(3, o.z); |
| 49 // Test changing the prototype after allocation was inlined. | 49 // Test changing the prototype after allocation was inlined. |
| 50 construct.prototype = { z:6 }; | 50 construct.prototype = { z:6 }; |
| 51 var o = test_helper(construct, 4, 5); | 51 var o = test_helper(construct, 4, 5); |
| 52 assertEquals(4, o.x); | 52 assertEquals(4, o.x); |
| 53 assertEquals(5, o.y); | 53 assertEquals(5, o.y); |
| 54 assertEquals(6, o.z); | 54 assertEquals(6, o.z); |
| 55 %DeoptimizeFunction(test_helper); | 55 %DeoptimizeFunction(test_helper); |
| 56 gc(); // Makes V8 forget about type information for test_helper. | 56 %ClearFunctionTypeFeedback(test_helper); |
| 57 } | 57 } |
| 58 | 58 |
| 59 function finalize_slack_tracking(construct) { | 59 function finalize_slack_tracking(construct) { |
| 60 // Value chosen based on kGenerousAllocationCount = 8. | 60 // Value chosen based on kGenerousAllocationCount = 8. |
| 61 for (var i = 0; i < 8; i++) { | 61 for (var i = 0; i < 8; i++) { |
| 62 new construct(0, 0); | 62 new construct(0, 0); |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 | 66 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 81 finalize_slack_tracking(ConstructInObjectUnused); | 81 finalize_slack_tracking(ConstructInObjectUnused); |
| 82 test(ConstructInObjectUnused); | 82 test(ConstructInObjectUnused); |
| 83 | 83 |
| 84 | 84 |
| 85 // Test inlined allocation while slack tracking is still in progress. | 85 // Test inlined allocation while slack tracking is still in progress. |
| 86 function ConstructWhileSlackTracking(a, b) { | 86 function ConstructWhileSlackTracking(a, b) { |
| 87 this.x = a; | 87 this.x = a; |
| 88 this.y = b; | 88 this.y = b; |
| 89 } | 89 } |
| 90 test(ConstructWhileSlackTracking); | 90 test(ConstructWhileSlackTracking); |
| OLD | NEW |