OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 | 28 // Flags: --allow-natives-syntax --noalways-opt |
29 | 29 |
30 (function DeoptimizeArgCallFunctionGeneric() { | 30 function GrandGrandParent() {} |
31 var a = []; | 31 GrandGrandParent.prototype = Object.freeze({constant: 2}); |
32 | 32 |
33 function f1(method, array, elem, deopt) { | 33 function GrandParent() {} |
34 assertEquals('push', method); | 34 GrandParent.prototype = Object.create(GrandGrandParent.prototype); |
35 } | |
36 | 35 |
37 function f2() { } | 36 function Parent() {} |
| 37 Parent.prototype = Object.create(GrandParent.prototype); |
38 | 38 |
39 function bar(x, deopt, f) { | 39 function Child() {} |
40 f('push', a, [x], deopt + 0); | 40 Child.prototype = Object.create(Parent.prototype); |
41 } | |
42 | 41 |
43 function foo() { return bar(arguments[0], arguments[1], arguments[2]); } | 42 Child.prototype.method1 = function() { |
44 function baz(f, deopt) { return foo("x", deopt, f); } | 43 return this.constant * this.constant; |
45 | 44 }; |
46 baz(f1, 0); | |
47 baz(f2, 0); | |
48 %OptimizeFunctionOnNextCall(baz); | |
49 baz(f1, "deopt"); | |
50 })(); | |
51 | 45 |
52 | 46 |
53 (function DeoptimizeArgGlobalFunctionGeneric() { | 47 var a = new Child(); |
54 var a = []; | 48 assertEquals(a.method1(), 4); |
| 49 a.method1(); |
| 50 %OptimizeFunctionOnNextCall(a.method1); |
| 51 assertEquals(a.method1(), 4); |
| 52 assertEquals(a.method1(), 4); |
55 | 53 |
56 var f1; | 54 // Immutable properties cannot be shadowed so the only way |
| 55 // is to snip the whole chain |
| 56 a.__proto__.__proto__ = {constant: 4}; |
57 | 57 |
58 f1 = function(method, array, elem, deopt) { | 58 assertEquals(a.method1(), 16); |
59 assertEquals('push', method); | 59 assertEquals(a.method1(), 16); |
60 } | 60 %OptimizeFunctionOnNextCall(a.method1); |
| 61 assertEquals(a.method1(), 16); |
| 62 assertEquals(a.method1(), 16); |
61 | 63 |
62 function bar(x, deopt, f) { | 64 var ceil = Math.ceil; |
63 f1('push', a, [x], deopt + 0); | 65 function GetMathPi() { |
64 } | 66 return ceil(Math.PI * Math.PI); |
| 67 } |
65 | 68 |
66 function foo() { return bar(arguments[0], arguments[1]); } | 69 assertEquals(GetMathPi(), 10); |
67 function baz(deopt) { return foo("x", deopt); } | 70 GetMathPi(); |
68 | 71 |
69 baz(0); | 72 %OptimizeFunctionOnNextCall(GetMathPi); |
70 baz(0); | 73 |
71 %OptimizeFunctionOnNextCall(baz); | 74 assertEquals(GetMathPi(), 10); |
72 baz("deopt"); | 75 assertEquals(GetMathPi(), 10); |
73 })(); | |
74 | 76 |
75 | 77 |
76 (function DeoptimizeArgCallFunctionRuntime() { | |
77 var a = []; | |
78 | 78 |
79 var f1; | 79 new Function("Math = {PI: 1}")(); |
80 | 80 |
81 f1 = function(method, array, elem, deopt) { | 81 assertEquals(GetMathPi(), 1); |
82 assertEquals('push', method); | 82 assertEquals(GetMathPi(), 1); |
83 } | |
84 | 83 |
85 function bar(x, deopt) { | 84 %OptimizeFunctionOnNextCall(GetMathPi); |
86 %_CallFunction(null, 'push', [x][0], ((deopt + 0), 1), f1); | |
87 } | |
88 | 85 |
89 function foo() { return bar(arguments[0], arguments[1]); } | 86 assertEquals(GetMathPi(), 1); |
90 function baz(deopt) { return foo(0, deopt); } | 87 assertEquals(GetMathPi(), 1); |
91 | |
92 baz(0); | |
93 baz(0); | |
94 %OptimizeFunctionOnNextCall(baz); | |
95 baz("deopt"); | |
96 })(); | |
OLD | NEW |