OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 |
| 29 |
28 // Test that we can inline a function that calls another function. | 30 // Test that we can inline a function that calls another function. |
29 function TestInlineX(o) { | 31 function TestInlineX(o) { |
30 // Effect context. | 32 // Effect context. |
31 o.g(); | 33 o.g(); |
32 // Value context. | 34 // Value context. |
33 var x = o.g(); | 35 var x = o.g(); |
34 assertEquals(42, x); | 36 assertEquals(42, x); |
35 assertEquals(42, o.g()); | 37 assertEquals(42, o.g()); |
36 // Test context. | 38 // Test context. |
37 if (!o.g()) { | 39 if (!o.g()) { |
38 assertTrue(false); // Should not happen. | 40 assertTrue(false); // Should not happen. |
39 } | 41 } |
40 } | 42 } |
41 | 43 |
42 var o2 = {}; | 44 var o2 = {}; |
43 o2.size = function() { return 42; } | 45 o2.size = function() { return 42; } |
44 o2.g = function() { return this.size(); }; | 46 o2.g = function() { return this.size(); }; |
45 for (var i = 0; i < 10000; i++) TestInlineX(o2); | 47 for (var i = 0; i < 5; i++) TestInlineX(o2); |
| 48 %OptimizeFunctionOnNextCall(TestInlineX); |
| 49 TestInlineX(o2); |
46 TestInlineX({g: o2.g, size:o2.size}); | 50 TestInlineX({g: o2.g, size:o2.size}); |
47 | 51 |
48 | 52 |
49 // Test that we can inline a call on a non-variable receiver. | 53 // Test that we can inline a call on a non-variable receiver. |
50 function TestInlineX2(o) { | 54 function TestInlineX2(o) { |
51 // Effect context. | 55 // Effect context. |
52 o.h(); | 56 o.h(); |
53 // Value context. | 57 // Value context. |
54 var x = o.h(); | 58 var x = o.h(); |
55 assertEquals(42, x); | 59 assertEquals(42, x); |
56 assertEquals(42, o.h()); | 60 assertEquals(42, o.h()); |
57 // Test context. | 61 // Test context. |
58 if (!o.h()) { | 62 if (!o.h()) { |
59 assertTrue(false); // Should not happen. | 63 assertTrue(false); // Should not happen. |
60 } | 64 } |
61 } | 65 } |
62 | 66 |
63 var obj = {} | 67 var obj = {} |
64 obj.foo = function() { return 42; } | 68 obj.foo = function() { return 42; } |
65 var o3 = {}; | 69 var o3 = {}; |
66 o3.v = obj; | 70 o3.v = obj; |
67 o3.h = function() { return this.v.foo(); }; | 71 o3.h = function() { return this.v.foo(); }; |
68 for (var i = 0; i < 10000; i++) TestInlineX2(o3); | 72 for (var i = 0; i < 5; i++) TestInlineX2(o3); |
| 73 %OptimizeFunctionOnNextCall(TestInlineX2); |
| 74 TestInlineX2(o3); |
69 TestInlineX2({h: o3.h, v:obj}); | 75 TestInlineX2({h: o3.h, v:obj}); |
70 | 76 |
71 | 77 |
72 // Test that we can inline a call on a non-variable receiver. | 78 // Test that we can inline a call on a non-variable receiver. |
73 function TestInlineFG(o) { | 79 function TestInlineFG(o) { |
74 // Effect context. | 80 // Effect context. |
75 o.h(); | 81 o.h(); |
76 // Value context. | 82 // Value context. |
77 var x = o.h(); | 83 var x = o.h(); |
78 assertEquals(42, x); | 84 assertEquals(42, x); |
79 assertEquals(42, o.h()); | 85 assertEquals(42, o.h()); |
80 // Test context. | 86 // Test context. |
81 if (!o.h()) { | 87 if (!o.h()) { |
82 assertTrue(false); // Should not happen. | 88 assertTrue(false); // Should not happen. |
83 } | 89 } |
84 } | 90 } |
85 | 91 |
86 var obj = {} | 92 var obj = {} |
87 obj.g = function() { return 42; } | 93 obj.g = function() { return 42; } |
88 var o3 = {}; | 94 var o3 = {}; |
89 o3.v = obj; | 95 o3.v = obj; |
90 o3.f = function() { return this.v; } | 96 o3.f = function() { return this.v; } |
91 o3.h = function() { return this.f().g(); }; | 97 o3.h = function() { return this.f().g(); }; |
92 for (var i = 0; i < 10000; i++) TestInlineFG(o3); | 98 for (var i = 0; i < 5; i++) TestInlineFG(o3); |
| 99 %OptimizeFunctionOnNextCall(TestInlineFG); |
| 100 TestInlineFG(o3); |
93 TestInlineFG({h: o3.h, f: o3.f, v:obj}); | 101 TestInlineFG({h: o3.h, f: o3.f, v:obj}); |
OLD | NEW |