OLD | NEW |
---|---|
1 // Copyright 2011 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 |
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 |
29 | 29 |
30 function f(x) { | 30 var result = []; |
31 var ret = -1; | 31 |
32 switch(x){ | 32 function branch(b) { |
33 if (b == "deopt") { | |
34 %DeoptimizeFunction(f); | |
35 return "c"; | |
36 } | |
37 | |
38 return b ? "a" : "b"; | |
39 } | |
40 | |
titzer
2013/12/10 14:27:09
I would like to see several more tests for this op
| |
41 function f(label, b1, b2) { | |
42 switch (label) { | |
43 case "string": | |
44 result.push(1); | |
45 break; | |
46 case branch(b1) + branch(b2): | |
47 result.push(2); | |
48 break; | |
49 case 10: | |
50 result.push(3); | |
51 break; | |
33 default: | 52 default: |
34 case 0: | 53 branch(b1); |
35 ret = 0; | 54 result.push(4); |
36 break; | 55 break; |
37 case 1: | 56 case 30: |
38 ret = 1; | 57 result.push(5); |
39 break; | |
40 case 2: | |
41 ret = 2; | |
42 break; | |
43 case 3: | |
44 ret = 3; | |
45 break; | |
46 case 4: | |
47 ret = 4; | |
48 break; | 58 break; |
49 } | 59 } |
50 return ret; | 60 } |
51 }; | |
52 | 61 |
53 for (var i = 0; i < 3; i++) assertEquals(i, f(i)); | 62 function assertResult(r, label, b1, b2) { |
63 f(label, b1, b2); | |
64 assertEquals(result, r); | |
65 result = []; | |
66 } | |
54 | 67 |
68 // Warmup. | |
69 assertResult([2], "aa", true, true); | |
70 assertResult([2], "ab", true, false); | |
71 assertResult([2], "ba", false, true); | |
72 assertResult([2], "bb", false, false); | |
73 assertResult([4], "other"); | |
74 assertResult([5], 30); | |
75 %OptimizeFunctionOnNextCall(f); | |
76 // Test regular behavior. | |
77 assertResult([2], "aa", true, true); | |
78 assertResult([1], "string"); | |
79 assertResult([4], "other"); | |
80 assertResult([5], 30); | |
81 | |
82 // Test deopt at the beginning of the case label evaluation. | |
83 assertResult([2], "ca", "deopt", true); | |
84 %OptimizeFunctionOnNextCall(f); | |
85 assertResult([4], "ca", "deopt", false); | |
55 %OptimizeFunctionOnNextCall(f); | 86 %OptimizeFunctionOnNextCall(f); |
56 | 87 |
57 assertEquals(0, f(0)); | 88 // Test deopt in the middle of the case label evaluation. |
58 assertEquals(1, f(1)); | 89 assertResult([2], "ac", true, "deopt"); |
90 %OptimizeFunctionOnNextCall(f); | |
91 assertResult([4], "ac", false, "deopt"); | |
OLD | NEW |