OLD | NEW |
1 // Copyright 2013 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 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // Test allocation folding of doubles. | 49 // Test allocation folding of doubles. |
50 | 50 |
51 function doubles() { | 51 function doubles() { |
52 var elem1 = [1.1, 1.2]; | 52 var elem1 = [1.1, 1.2]; |
53 var elem2 = [2.1, 2.2]; | 53 var elem2 = [2.1, 2.2]; |
54 return elem2; | 54 return elem2; |
55 } | 55 } |
56 | 56 |
57 doubles(); doubles(); doubles(); | 57 doubles(); doubles(); doubles(); |
58 %OptimizeFunctionOnNextCall(doubles); | 58 %OptimizeFunctionOnNextCall(doubles); |
59 var result = doubles(); | 59 result = doubles(); |
60 | 60 |
61 gc(); | 61 gc(); |
62 | 62 |
63 assertEquals(result[1], 2.2); | 63 assertEquals(result[1], 2.2); |
64 | 64 |
65 // Test allocation folding of doubles into non-doubles. | 65 // Test allocation folding of doubles into non-doubles. |
66 | 66 |
67 function doubles_int() { | 67 function doubles_int() { |
68 var elem1 = [2, 3]; | 68 var elem1 = [2, 3]; |
69 var elem2 = [2.1, 3.1]; | 69 var elem2 = [2.1, 3.1]; |
70 return elem2; | 70 return elem2; |
71 } | 71 } |
72 | 72 |
73 doubles_int(); doubles_int(); doubles_int(); | 73 doubles_int(); doubles_int(); doubles_int(); |
74 %OptimizeFunctionOnNextCall(doubles_int); | 74 %OptimizeFunctionOnNextCall(doubles_int); |
75 var result = doubles_int(); | 75 result = doubles_int(); |
76 | 76 |
77 gc(); | 77 gc(); |
78 | 78 |
79 assertEquals(result[1], 3.1); | 79 assertEquals(result[1], 3.1); |
| 80 |
| 81 // Test allocation folding over a branch. |
| 82 |
| 83 function branch_int(left) { |
| 84 var elem1 = [1, 2]; |
| 85 var elem2; |
| 86 if (left) { |
| 87 elem2 = [3, 4]; |
| 88 } else { |
| 89 elem2 = [5, 6]; |
| 90 } |
| 91 return elem2; |
| 92 } |
| 93 |
| 94 branch_int(1); branch_int(1); branch_int(1); |
| 95 %OptimizeFunctionOnNextCall(branch_int); |
| 96 result = branch_int(1); |
| 97 var result2 = branch_int(0); |
| 98 |
| 99 gc(); |
| 100 |
| 101 assertEquals(result[1], 4); |
| 102 assertEquals(result2[1], 6); |
OLD | NEW |