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 |
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 --expose-gc | 28 // Flags: --allow-natives-syntax --expose-gc |
29 | 29 |
30 // Limit the number of stress runs to reduce polymorphism it defeats some of the | 30 // Limit the number of stress runs to reduce polymorphism it defeats some of the |
31 // assumptions made about how elements transitions work because transition stubs | 31 // assumptions made about how elements transitions work because transition stubs |
32 // end up going generic. | 32 // end up going generic. |
33 // Flags: --stress-runs=2 | 33 // Flags: --stress-runs=2 |
34 | 34 |
35 // Test element kind of objects. | |
36 // Since --smi-only-arrays affects builtins, its default setting at compile | |
37 // time sticks if built with snapshot. If --smi-only-arrays is deactivated | |
38 // by default, only a no-snapshot build actually has smi-only arrays enabled | |
39 // in this test case. Depending on whether smi-only arrays are actually | |
40 // enabled, this test takes the appropriate code path to check smi-only arrays. | |
41 | |
42 support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); | |
43 | |
44 if (support_smi_only_arrays) { | |
45 print("Tests include smi-only arrays."); | |
46 } else { | |
47 print("Tests do NOT include smi-only arrays."); | |
48 } | |
49 | |
50 var elements_kind = { | 35 var elements_kind = { |
51 fast_smi_only : 'fast smi only elements', | 36 fast_smi_only : 'fast smi only elements', |
52 fast : 'fast elements', | 37 fast : 'fast elements', |
53 fast_double : 'fast double elements', | 38 fast_double : 'fast double elements', |
54 dictionary : 'dictionary elements', | 39 dictionary : 'dictionary elements', |
55 external_byte : 'external byte elements', | 40 external_byte : 'external byte elements', |
56 external_unsigned_byte : 'external unsigned byte elements', | 41 external_unsigned_byte : 'external unsigned byte elements', |
57 external_short : 'external short elements', | 42 external_short : 'external short elements', |
58 external_unsigned_short : 'external unsigned short elements', | 43 external_unsigned_short : 'external unsigned short elements', |
59 external_int : 'external int elements', | 44 external_int : 'external int elements', |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 78 } |
94 if (%HasExternalDoubleElements(obj)) { | 79 if (%HasExternalDoubleElements(obj)) { |
95 return elements_kind.external_double; | 80 return elements_kind.external_double; |
96 } | 81 } |
97 if (%HasExternalPixelElements(obj)) { | 82 if (%HasExternalPixelElements(obj)) { |
98 return elements_kind.external_pixel; | 83 return elements_kind.external_pixel; |
99 } | 84 } |
100 } | 85 } |
101 | 86 |
102 function assertKind(expected, obj, name_opt) { | 87 function assertKind(expected, obj, name_opt) { |
103 if (!support_smi_only_arrays && | |
104 expected == elements_kind.fast_smi_only) { | |
105 expected = elements_kind.fast; | |
106 } | |
107 assertEquals(expected, getKind(obj), name_opt); | 88 assertEquals(expected, getKind(obj), name_opt); |
108 } | 89 } |
109 | 90 |
110 %NeverOptimizeFunction(construct_smis); | 91 %NeverOptimizeFunction(construct_smis); |
111 | 92 |
112 // This code exists to eliminate the learning influence of AllocationSites | 93 // This code exists to eliminate the learning influence of AllocationSites |
113 // on the following tests. | 94 // on the following tests. |
114 var __sequence = 0; | 95 var __sequence = 0; |
115 function make_array_string() { | 96 function make_array_string() { |
116 this.__sequence = this.__sequence + 1; | 97 this.__sequence = this.__sequence + 1; |
(...skipping 19 matching lines...) Expand all Loading... |
136 } | 117 } |
137 | 118 |
138 %NeverOptimizeFunction(convert_mixed); | 119 %NeverOptimizeFunction(convert_mixed); |
139 function convert_mixed(array, value, kind) { | 120 function convert_mixed(array, value, kind) { |
140 array[1] = value; | 121 array[1] = value; |
141 assertKind(kind, array); | 122 assertKind(kind, array); |
142 assertEquals(value, array[1]); | 123 assertEquals(value, array[1]); |
143 } | 124 } |
144 | 125 |
145 function test1() { | 126 function test1() { |
146 if (!support_smi_only_arrays) return; | |
147 | |
148 // Test transition chain SMI->DOUBLE->FAST (crankshafted function will | 127 // Test transition chain SMI->DOUBLE->FAST (crankshafted function will |
149 // transition to FAST directly). | 128 // transition to FAST directly). |
150 var smis = construct_smis(); | 129 var smis = construct_smis(); |
151 convert_mixed(smis, 1.5, elements_kind.fast_double); | 130 convert_mixed(smis, 1.5, elements_kind.fast_double); |
152 | 131 |
153 var doubles = construct_doubles(); | 132 var doubles = construct_doubles(); |
154 convert_mixed(doubles, "three", elements_kind.fast); | 133 convert_mixed(doubles, "three", elements_kind.fast); |
155 | 134 |
156 convert_mixed(construct_smis(), "three", elements_kind.fast); | 135 convert_mixed(construct_smis(), "three", elements_kind.fast); |
157 convert_mixed(construct_doubles(), "three", elements_kind.fast); | 136 convert_mixed(construct_doubles(), "three", elements_kind.fast); |
158 | 137 |
159 smis = construct_smis(); | 138 smis = construct_smis(); |
160 doubles = construct_doubles(); | 139 doubles = construct_doubles(); |
161 convert_mixed(smis, 1, elements_kind.fast); | 140 convert_mixed(smis, 1, elements_kind.fast); |
162 convert_mixed(doubles, 1, elements_kind.fast); | 141 convert_mixed(doubles, 1, elements_kind.fast); |
163 assertTrue(%HaveSameMap(smis, doubles)); | 142 assertTrue(%HaveSameMap(smis, doubles)); |
164 } | 143 } |
165 | 144 |
166 test1(); | 145 test1(); |
167 gc(); // clear IC state | 146 gc(); // clear IC state |
168 test1(); | 147 test1(); |
169 gc(); // clear IC state | 148 gc(); // clear IC state |
170 %OptimizeFunctionOnNextCall(test1); | 149 %OptimizeFunctionOnNextCall(test1); |
171 test1(); | 150 test1(); |
172 gc(); // clear IC state | 151 gc(); // clear IC state |
OLD | NEW |