| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 --expose-gc |
| 29 | 29 |
| 30 // This is a regression test for overlapping key and value registers. | 30 // This is a regression test for overlapping key and value registers. |
| 31 function f(a) { | 31 function f(a) { |
| 32 a[0] = 0; | 32 a[0] = 0; |
| 33 a[1] = 0; | 33 a[1] = 0; |
| 34 } | 34 } |
| 35 | 35 |
| 36 var a = new Int32Array(2); | 36 var a = new Int32Array(2); |
| 37 for (var i = 0; i < 5; i++) { | 37 for (var i = 0; i < 5; i++) { |
| 38 f(a); | 38 f(a); |
| 39 } | 39 } |
| 40 %OptimizeFunctionOnNextCall(f); | 40 %OptimizeFunctionOnNextCall(f); |
| 41 f(a); | 41 f(a); |
| 42 | 42 |
| 43 assertEquals(0, a[0]); | 43 assertEquals(0, a[0]); |
| 44 assertEquals(0, a[1]); | 44 assertEquals(0, a[1]); |
| 45 | 45 |
| 46 // Test the correct behavior of the |length| property (which is read-only). | |
| 47 a = new Int32Array(42); | |
| 48 assertEquals(42, a.length); | |
| 49 a.length = 2; | |
| 50 assertEquals(42, a.length); | |
| 51 assertTrue(delete a.length); | |
| 52 a.length = 2 | |
| 53 assertEquals(2, a.length); | |
| 54 | |
| 55 // Test the correct behavior of the |BYTES_PER_ELEMENT| property (which is | 46 // Test the correct behavior of the |BYTES_PER_ELEMENT| property (which is |
| 56 // "constant", but not read-only). | 47 // "constant", but not read-only). |
| 57 a = new Int32Array(2); | 48 a = new Int32Array(2); |
| 58 assertEquals(4, a.BYTES_PER_ELEMENT); | 49 assertEquals(4, a.BYTES_PER_ELEMENT); |
| 59 a.BYTES_PER_ELEMENT = 42; | 50 a.BYTES_PER_ELEMENT = 42; |
| 60 assertEquals(42, a.BYTES_PER_ELEMENT); | 51 assertEquals(42, a.BYTES_PER_ELEMENT); |
| 61 a = new Uint8Array(2); | 52 a = new Uint8Array(2); |
| 62 assertEquals(1, a.BYTES_PER_ELEMENT); | 53 assertEquals(1, a.BYTES_PER_ELEMENT); |
| 63 a = new Int16Array(2); | 54 a = new Int16Array(2); |
| 64 assertEquals(2, a.BYTES_PER_ELEMENT); | 55 assertEquals(2, a.BYTES_PER_ELEMENT); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 81 assertEquals(2.5, array[0]); | 72 assertEquals(2.5, array[0]); |
| 82 set(array, 1, 3.5); | 73 set(array, 1, 3.5); |
| 83 assertEquals(3.5, array[1]); | 74 assertEquals(3.5, array[1]); |
| 84 for (var i = 0; i < 5; i++) { | 75 for (var i = 0; i < 5; i++) { |
| 85 assertEquals(2.5, get(array, 0)); | 76 assertEquals(2.5, get(array, 0)); |
| 86 assertEquals(3.5, array[1]); | 77 assertEquals(3.5, array[1]); |
| 87 } | 78 } |
| 88 %OptimizeFunctionOnNextCall(get); | 79 %OptimizeFunctionOnNextCall(get); |
| 89 assertEquals(2.5, get(array, 0)); | 80 assertEquals(2.5, get(array, 0)); |
| 90 assertEquals(3.5, get(array, 1)); | 81 assertEquals(3.5, get(array, 1)); |
| 82 |
| 83 // Test loads and stores. |
| 84 types = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, |
| 85 Uint32Array, PixelArray, Float32Array, Float64Array]; |
| 86 |
| 87 const kElementCount = 40; |
| 88 |
| 89 function test_load(array, sum) { |
| 90 for (var i = 0; i < kElementCount; i++) { |
| 91 sum += array[i]; |
| 92 } |
| 93 return sum; |
| 94 } |
| 95 |
| 96 function test_load_const_key(array, sum) { |
| 97 sum += array[0]; |
| 98 sum += array[1]; |
| 99 sum += array[2]; |
| 100 return sum; |
| 101 } |
| 102 |
| 103 function test_store(array, sum) { |
| 104 for (var i = 0; i < kElementCount; i++) { |
| 105 sum += array[i] = i+1; |
| 106 } |
| 107 return sum; |
| 108 } |
| 109 |
| 110 function test_store_const_key(array, sum) { |
| 111 sum += array[0] = 1; |
| 112 sum += array[1] = 2; |
| 113 sum += array[2] = 3; |
| 114 return sum; |
| 115 } |
| 116 |
| 117 function run_test(test_func, array, expected_sum_per_run) { |
| 118 for (var i = 0; i < 5; i++) test_func(array, 0); |
| 119 %OptimizeFunctionOnNextCall(test_func); |
| 120 const kRuns = 10; |
| 121 var sum = 0; |
| 122 for (var i = 0; i < kRuns; i++) { |
| 123 sum = test_func(array, sum); |
| 124 } |
| 125 assertEquals(sum, expected_sum_per_run * kRuns); |
| 126 %DeoptimizeFunction(test_func); |
| 127 gc(); // Makes V8 forget about type information for test_func. |
| 128 } |
| 129 |
| 130 for (var t = 0; t < types.length; t++) { |
| 131 var type = types[t]; |
| 132 var a = new type(kElementCount); |
| 133 for (var i = 0; i < kElementCount; i++) { |
| 134 a[i] = i; |
| 135 } |
| 136 |
| 137 // Run test functions defined above. |
| 138 run_test(test_load, a, 780); |
| 139 run_test(test_load_const_key, a, 3); |
| 140 run_test(test_store, a, 820); |
| 141 run_test(test_store_const_key, a, 6); |
| 142 |
| 143 // Test the correct behavior of the |length| property (which is read-only). |
| 144 assertEquals(kElementCount, a.length); |
| 145 a.length = 2; |
| 146 assertEquals(kElementCount, a.length); |
| 147 assertTrue(delete a.length); |
| 148 a.length = 2 |
| 149 assertEquals(2, a.length); |
| 150 } |
| OLD | NEW |