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 function f(x) { | 30 function f(x) { |
29 return ~x; | 31 return ~x; |
30 } | 32 } |
31 | 33 |
32 f(42); | 34 f(42); |
33 assertEquals(~12, f(12.45)); | 35 assertEquals(~12, f(12.45)); |
34 assertEquals(~42, f(42.87)); | 36 assertEquals(~42, f(42.87)); |
35 | 37 |
36 | 38 |
37 var a = 1, b = 2, c = 4, d = 8; | 39 var a = 1, b = 2, c = 4, d = 8; |
(...skipping 14 matching lines...) Expand all Loading... |
52 g = function() { return 42; }; | 54 g = function() { return 42; }; |
53 assertEquals(42, h()); | 55 assertEquals(42, h()); |
54 | 56 |
55 | 57 |
56 // Test deopt when map changes. | 58 // Test deopt when map changes. |
57 var obj = {}; | 59 var obj = {}; |
58 obj.g = g; | 60 obj.g = g; |
59 function k(o) { | 61 function k(o) { |
60 return o.g(); | 62 return o.g(); |
61 } | 63 } |
62 for (var i = 0; i < 1000000; i++) k(obj); | 64 for (var i = 0; i < 5; i++) k(obj); |
| 65 %OptimizeFunctionOnNextCall(k); |
| 66 k(obj); |
63 assertEquals(42, k(obj)); | 67 assertEquals(42, k(obj)); |
64 assertEquals(87, k({g: function() { return 87; }})); | 68 assertEquals(87, k({g: function() { return 87; }})); |
65 | 69 |
66 | 70 |
67 // Test deopt with assignments to parameters. | 71 // Test deopt with assignments to parameters. |
68 function p(x,y) { | 72 function p(x,y) { |
69 x = 42; | 73 x = 42; |
70 y = 1; | 74 y = 1; |
71 y = y << "0"; | 75 y = y << "0"; |
72 return x | y; | 76 return x | y; |
73 } | 77 } |
74 assertEquals(43, p(0,0)); | 78 assertEquals(43, p(0,0)); |
75 | 79 |
76 | 80 |
77 // Test deopt with literals on the expression stack. | 81 // Test deopt with literals on the expression stack. |
78 function LiteralToStack(x) { | 82 function LiteralToStack(x) { |
79 return 'lit[' + (x + ']'); | 83 return 'lit[' + (x + ']'); |
80 } | 84 } |
81 | 85 |
82 assertEquals('lit[-87]', LiteralToStack(-87)); | 86 assertEquals('lit[-87]', LiteralToStack(-87)); |
83 assertEquals('lit[0]', LiteralToStack(0)); | 87 assertEquals('lit[0]', LiteralToStack(0)); |
84 assertEquals('lit[42]', LiteralToStack(42)); | 88 assertEquals('lit[42]', LiteralToStack(42)); |
85 | 89 |
86 | 90 |
87 // Test deopt before call. | 91 // Test deopt before call. |
88 var str = "abc"; | 92 var str = "abc"; |
89 var r; | 93 var r; |
90 function CallCharAt(n) { return str.charAt(n); } | 94 function CallCharAt(n) { return str.charAt(n); } |
91 for (var i = 0; i < 1000000; i++) { | 95 for (var i = 0; i < 5; i++) { |
92 r = CallCharAt(0); | 96 r = CallCharAt(0); |
93 } | 97 } |
| 98 %OptimizeFunctionOnNextCall(CallCharAt); |
| 99 r = CallCharAt(0); |
94 assertEquals("a", r); | 100 assertEquals("a", r); |
95 | 101 |
96 | 102 |
97 // Test of deopt in presence of spilling. | 103 // Test of deopt in presence of spilling. |
98 function add4(a,b,c,d) { | 104 function add4(a,b,c,d) { |
99 return a+b+c+d; | 105 return a+b+c+d; |
100 } | 106 } |
101 assertEquals(0x40000003, add4(1,1,2,0x3fffffff)); | 107 assertEquals(0x40000003, add4(1,1,2,0x3fffffff)); |
OLD | NEW |