OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 --smi-only-arrays | 28 // Flags: --allow-natives-syntax |
29 // Flags: --nostress-opt | 29 // Flags: --nostress-opt |
30 | 30 |
31 support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); | 31 // This code exists to eliminate the learning influence of AllocationSites |
32 | 32 // on the following tests. |
33 if (support_smi_only_arrays) { | 33 var __sequence = 0; |
34 print("Tests include smi-only arrays."); | 34 function make_array_string(length) { |
35 } else { | 35 this.__sequence = this.__sequence + 1; |
36 print("Tests do NOT include smi-only arrays."); | 36 return "/* " + this.__sequence + " */ new Array(" + length + ");"; |
| 37 } |
| 38 function make_array(length) { |
| 39 return eval(make_array_string(length)); |
37 } | 40 } |
38 | 41 |
39 if (support_smi_only_arrays) { | 42 function test(test_double, test_object, set, length) { |
40 // This code exists to eliminate the learning influence of AllocationSites | 43 // We apply the same operations to two identical arrays. The first array |
41 // on the following tests. | 44 // triggers an IC miss, upon which the conversion stub is generated, but the |
42 var __sequence = 0; | 45 // actual conversion is done in runtime. The second array, arriving at |
43 function make_array_string(length) { | 46 // the previously patched IC, is then converted using the conversion stub. |
44 this.__sequence = this.__sequence + 1; | 47 var array_1 = make_array(length); |
45 return "/* " + this.__sequence + " */ new Array(" + length + ");"; | 48 var array_2 = make_array(length); |
46 } | 49 |
47 function make_array(length) { | 50 // false, true, nice setter function, 20 |
48 return eval(make_array_string(length)); | 51 assertTrue(%HasFastSmiElements(array_1)); |
| 52 assertTrue(%HasFastSmiElements(array_2)); |
| 53 for (var i = 0; i < length; i++) { |
| 54 if (i == length - 5 && test_double) { |
| 55 // Trigger conversion to fast double elements at length-5. |
| 56 set(array_1, i, 0.5); |
| 57 set(array_2, i, 0.5); |
| 58 assertTrue(%HasFastDoubleElements(array_1)); |
| 59 assertTrue(%HasFastDoubleElements(array_2)); |
| 60 } else if (i == length - 3 && test_object) { |
| 61 // Trigger conversion to fast object elements at length-3. |
| 62 set(array_1, i, 'object'); |
| 63 set(array_2, i, 'object'); |
| 64 assertTrue(%HasFastObjectElements(array_1)); |
| 65 assertTrue(%HasFastObjectElements(array_2)); |
| 66 } else if (i != length - 7) { |
| 67 // Set the element to an integer but leave a hole at length-7. |
| 68 set(array_1, i, 2*i+1); |
| 69 set(array_2, i, 2*i+1); |
| 70 } |
49 } | 71 } |
50 | 72 |
51 function test(test_double, test_object, set, length) { | 73 for (var i = 0; i < length; i++) { |
52 // We apply the same operations to two identical arrays. The first array | 74 if (i == length - 5 && test_double) { |
53 // triggers an IC miss, upon which the conversion stub is generated, but the | 75 assertEquals(0.5, array_1[i]); |
54 // actual conversion is done in runtime. The second array, arriving at | 76 assertEquals(0.5, array_2[i]); |
55 // the previously patched IC, is then converted using the conversion stub. | 77 } else if (i == length - 3 && test_object) { |
56 var array_1 = make_array(length); | 78 assertEquals('object', array_1[i]); |
57 var array_2 = make_array(length); | 79 assertEquals('object', array_2[i]); |
58 | 80 } else if (i != length - 7) { |
59 // false, true, nice setter function, 20 | 81 assertEquals(2*i+1, array_1[i]); |
60 assertTrue(%HasFastSmiElements(array_1)); | 82 assertEquals(2*i+1, array_2[i]); |
61 assertTrue(%HasFastSmiElements(array_2)); | 83 } else { |
62 for (var i = 0; i < length; i++) { | 84 assertEquals(undefined, array_1[i]); |
63 if (i == length - 5 && test_double) { | 85 assertEquals(undefined, array_2[i]); |
64 // Trigger conversion to fast double elements at length-5. | |
65 set(array_1, i, 0.5); | |
66 set(array_2, i, 0.5); | |
67 assertTrue(%HasFastDoubleElements(array_1)); | |
68 assertTrue(%HasFastDoubleElements(array_2)); | |
69 } else if (i == length - 3 && test_object) { | |
70 // Trigger conversion to fast object elements at length-3. | |
71 set(array_1, i, 'object'); | |
72 set(array_2, i, 'object'); | |
73 assertTrue(%HasFastObjectElements(array_1)); | |
74 assertTrue(%HasFastObjectElements(array_2)); | |
75 } else if (i != length - 7) { | |
76 // Set the element to an integer but leave a hole at length-7. | |
77 set(array_1, i, 2*i+1); | |
78 set(array_2, i, 2*i+1); | |
79 } | |
80 } | 86 } |
81 | |
82 for (var i = 0; i < length; i++) { | |
83 if (i == length - 5 && test_double) { | |
84 assertEquals(0.5, array_1[i]); | |
85 assertEquals(0.5, array_2[i]); | |
86 } else if (i == length - 3 && test_object) { | |
87 assertEquals('object', array_1[i]); | |
88 assertEquals('object', array_2[i]); | |
89 } else if (i != length - 7) { | |
90 assertEquals(2*i+1, array_1[i]); | |
91 assertEquals(2*i+1, array_2[i]); | |
92 } else { | |
93 assertEquals(undefined, array_1[i]); | |
94 assertEquals(undefined, array_2[i]); | |
95 } | |
96 } | |
97 | |
98 assertEquals(length, array_1.length); | |
99 assertEquals(length, array_2.length); | |
100 } | 87 } |
101 | 88 |
102 function run_test(test_double, test_object, set, length) { | 89 assertEquals(length, array_1.length); |
103 test(test_double, test_object, set, length); | 90 assertEquals(length, array_2.length); |
| 91 } |
| 92 |
| 93 function run_test(test_double, test_object, set, length) { |
| 94 test(test_double, test_object, set, length); |
104 %ClearFunctionTypeFeedback(test); | 95 %ClearFunctionTypeFeedback(test); |
105 } | 96 } |
106 | 97 |
107 run_test(false, false, function(a,i,v){ a[i] = v; }, 20); | 98 run_test(false, false, function(a,i,v){ a[i] = v; }, 20); |
108 run_test(true, false, function(a,i,v){ a[i] = v; }, 20); | 99 run_test(true, false, function(a,i,v){ a[i] = v; }, 20); |
109 run_test(false, true, function(a,i,v){ a[i] = v; }, 20); | 100 run_test(false, true, function(a,i,v){ a[i] = v; }, 20); |
110 run_test(true, true, function(a,i,v){ a[i] = v; }, 20); | 101 run_test(true, true, function(a,i,v){ a[i] = v; }, 20); |
111 | 102 |
112 run_test(false, false, function(a,i,v){ a[i] = v; }, 10000); | 103 run_test(false, false, function(a,i,v){ a[i] = v; }, 10000); |
113 run_test(true, false, function(a,i,v){ a[i] = v; }, 10000); | 104 run_test(true, false, function(a,i,v){ a[i] = v; }, 10000); |
114 run_test(false, true, function(a,i,v){ a[i] = v; }, 10000); | 105 run_test(false, true, function(a,i,v){ a[i] = v; }, 10000); |
115 run_test(true, true, function(a,i,v){ a[i] = v; }, 10000); | 106 run_test(true, true, function(a,i,v){ a[i] = v; }, 10000); |
116 | 107 |
117 // Check COW arrays | 108 // Check COW arrays |
118 function get_cow() { return [1, 2, 3]; } | 109 function get_cow() { return [1, 2, 3]; } |
119 | 110 |
120 function transition(x) { x[0] = 1.5; } | 111 function transition(x) { x[0] = 1.5; } |
121 | 112 |
122 var ignore = get_cow(); | 113 var ignore = get_cow(); |
123 transition(ignore); // Handled by runtime. | 114 transition(ignore); // Handled by runtime. |
124 var a = get_cow(); | 115 var a = get_cow(); |
125 var b = get_cow(); | 116 var b = get_cow(); |
126 transition(a); // Handled by IC. | 117 transition(a); // Handled by IC. |
127 assertEquals(1.5, a[0]); | 118 assertEquals(1.5, a[0]); |
128 assertEquals(1, b[0]); | 119 assertEquals(1, b[0]); |
129 } else { | |
130 print("Test skipped because smi only arrays are not supported."); | |
131 } | |
OLD | NEW |