OLD | NEW |
(Empty) | |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 27 |
| 28 // Flags: --allow-natives-syntax --expose-gc |
| 29 |
| 30 var a = new Int32Array(1024); |
| 31 |
| 32 function test_base(base,cond) { |
| 33 a[base + 1] = 1; |
| 34 a[base + 4] = 2; |
| 35 a[base + 3] = 3; |
| 36 a[base + 2] = 4; |
| 37 a[base + 4] = base + 4; |
| 38 if (cond) { |
| 39 a[base + 1] = 1; |
| 40 a[base + 2] = 2; |
| 41 a[base + 2] = 3; |
| 42 a[base + 2] = 4; |
| 43 a[base + 4] = base + 4; |
| 44 } else { |
| 45 a[base + 6] = 1; |
| 46 a[base + 4] = 2; |
| 47 a[base + 3] = 3; |
| 48 a[base + 2] = 4; |
| 49 a[base + 4] = base - 4; |
| 50 } |
| 51 } |
| 52 |
| 53 function check_test_base(base,cond) { |
| 54 if (cond) { |
| 55 assertEquals(1, a[base + 1]); |
| 56 assertEquals(4, a[base + 2]); |
| 57 assertEquals(base + 4, a[base + 4]); |
| 58 } else { |
| 59 assertEquals(1, a[base + 6]); |
| 60 assertEquals(3, a[base + 3]); |
| 61 assertEquals(4, a[base + 2]); |
| 62 assertEquals(base - 4, a[base + 4]); |
| 63 } |
| 64 } |
| 65 |
| 66 |
| 67 function test_minus(base,cond) { |
| 68 a[base - 1] = 1; |
| 69 a[base - 2] = 2; |
| 70 a[base + 4] = 3; |
| 71 a[base] = 4; |
| 72 a[base + 4] = base + 4; |
| 73 if (cond) { |
| 74 a[base - 4] = 1; |
| 75 a[base + 5] = 2; |
| 76 a[base + 3] = 3; |
| 77 a[base + 2] = 4; |
| 78 a[base + 4] = base + 4; |
| 79 } else { |
| 80 a[base + 6] = 1; |
| 81 a[base + 4] = 2; |
| 82 a[base + 3] = 3; |
| 83 a[base + 2] = 4; |
| 84 a[base + 4] = base - 4; |
| 85 } |
| 86 } |
| 87 |
| 88 function check_test_minus(base,cond) { |
| 89 if (cond) { |
| 90 assertEquals(2, a[base + 5]); |
| 91 assertEquals(3, a[base + 3]); |
| 92 assertEquals(4, a[base + 2]); |
| 93 assertEquals(base + 4, a[base + 4]); |
| 94 } else { |
| 95 assertEquals(1, a[base + 6]); |
| 96 assertEquals(3, a[base + 3]); |
| 97 assertEquals(4, a[base + 2]); |
| 98 assertEquals(base - 4, a[base + 4]); |
| 99 } |
| 100 } |
| 101 |
| 102 test_base(1,true); |
| 103 test_base(2,true); |
| 104 test_base(1,false); |
| 105 test_base(2,false); |
| 106 %OptimizeFunctionOnNextCall(test_base); |
| 107 test_base(3,true); |
| 108 check_test_base(3,true); |
| 109 test_base(3,false); |
| 110 check_test_base(3,false); |
| 111 |
| 112 test_minus(5,true); |
| 113 test_minus(6,true); |
| 114 %OptimizeFunctionOnNextCall(test_minus); |
| 115 test_minus(7,true); |
| 116 check_test_minus(7,true); |
| 117 test_minus(7,false); |
| 118 check_test_minus(7,false); |
| 119 |
| 120 // Optimization status: |
| 121 // YES: 1 |
| 122 // NO: 2 |
| 123 // ALWAYS: 3 |
| 124 // NEVER: 4 |
| 125 |
| 126 if (false) { |
| 127 test_base(5,true); |
| 128 test_base(6,true); |
| 129 test_base(5,false); |
| 130 test_base(6,false); |
| 131 %OptimizeFunctionOnNextCall(test_base); |
| 132 test_base(-2,true); |
| 133 assertTrue(%GetOptimizationStatus(test_base) != 1); |
| 134 |
| 135 test_base(5,true); |
| 136 test_base(6,true); |
| 137 test_base(5,false); |
| 138 test_base(6,false); |
| 139 %OptimizeFunctionOnNextCall(test_base); |
| 140 test_base(2048,true); |
| 141 assertTrue(%GetOptimizationStatus(test_base) != 1); |
| 142 } |
| 143 |
| 144 gc(); |
| 145 |
OLD | NEW |