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 --expose-gc | 28 // Flags: --allow-natives-syntax --expose-gc |
29 // Flags: --noalways-opt | 29 // Flags: --no-always-opt --crankshaft |
| 30 |
| 31 assertFalse(isNeverOptimize()); |
| 32 assertFalse(isAlwaysOptimize()); |
30 | 33 |
31 // Test element kind of objects. | 34 // Test element kind of objects. |
32 | 35 |
33 var elements_kind = { | 36 var elements_kind = { |
34 fast_smi_only : 'fast smi only elements', | 37 fast_smi_only : 'fast smi only elements', |
35 fast : 'fast elements', | 38 fast : 'fast elements', |
36 fast_double : 'fast double elements', | 39 fast_double : 'fast double elements', |
37 dictionary : 'dictionary elements', | 40 dictionary : 'dictionary elements', |
38 external_byte : 'external byte elements', | 41 external_byte : 'external byte elements', |
39 external_unsigned_byte : 'external unsigned byte elements', | 42 external_unsigned_byte : 'external unsigned byte elements', |
(...skipping 25 matching lines...) Expand all Loading... |
65 // Test: ensure that crankshafted array constructor sites are deopted | 68 // Test: ensure that crankshafted array constructor sites are deopted |
66 // if another function is used. | 69 // if another function is used. |
67 (function() { | 70 (function() { |
68 function bar0(t) { | 71 function bar0(t) { |
69 return new t(); | 72 return new t(); |
70 } | 73 } |
71 a = bar0(Array); | 74 a = bar0(Array); |
72 a[0] = 3.5; | 75 a[0] = 3.5; |
73 b = bar0(Array); | 76 b = bar0(Array); |
74 assertKind(elements_kind.fast_double, b); | 77 assertKind(elements_kind.fast_double, b); |
75 %OptimizeFunctionOnNextCall(bar0); | 78 %OptimizeFunctionOnNextCall(bar0); |
76 b = bar0(Array); | 79 b = bar0(Array); |
77 assertKind(elements_kind.fast_double, b); | 80 assertKind(elements_kind.fast_double, b); |
78 assertOptimized(bar0); | 81 assertOptimized(bar0); |
79 // bar0 should deopt | 82 // bar0 should deopt |
80 b = bar0(Object); | 83 b = bar0(Object); |
81 assertUnoptimized(bar0) | 84 assertUnoptimized(bar0) |
82 // When it's re-optimized, we should call through the full stub | 85 // When it's re-optimized, we should call through the full stub |
83 bar0(Array); | 86 bar0(Array); |
84 %OptimizeFunctionOnNextCall(bar0); | 87 %OptimizeFunctionOnNextCall(bar0); |
85 b = bar0(Array); | 88 b = bar0(Array); |
86 // This only makes sense to test if we allow crankshafting | 89 // This only makes sense to test if we allow crankshafting |
87 if (4 != %GetOptimizationStatus(bar0)) { | 90 // We also lost our ability to record kind feedback, as the site |
88 // We also lost our ability to record kind feedback, as the site | 91 // is megamorphic now. |
89 // is megamorphic now. | 92 assertKind(elements_kind.fast_smi_only, b); |
90 assertKind(elements_kind.fast_smi_only, b); | 93 assertOptimized(bar0); |
91 assertOptimized(bar0); | 94 b[0] = 3.5; |
92 b[0] = 3.5; | 95 c = bar0(Array); |
93 c = bar0(Array); | 96 assertKind(elements_kind.fast_smi_only, c); |
94 assertKind(elements_kind.fast_smi_only, c); | |
95 } | |
96 })(); | 97 })(); |
97 | 98 |
98 | 99 |
99 // Test: Ensure that inlined array calls in crankshaft learn from deopts | 100 // Test: Ensure that inlined array calls in crankshaft learn from deopts |
100 // based on the move to a dictionary for the array. | 101 // based on the move to a dictionary for the array. |
101 (function() { | 102 (function() { |
102 function bar(len) { | 103 function bar(len) { |
103 return new Array(len); | 104 return new Array(len); |
104 } | 105 } |
105 a = bar(10); | 106 a = bar(10); |
(...skipping 28 matching lines...) Expand all Loading... |
134 | 135 |
135 // Test: When a method with array constructor is crankshafted, the type | 136 // Test: When a method with array constructor is crankshafted, the type |
136 // feedback for elements kind is baked in. Verify that transitions don't | 137 // feedback for elements kind is baked in. Verify that transitions don't |
137 // change it anymore | 138 // change it anymore |
138 (function() { | 139 (function() { |
139 function bar() { | 140 function bar() { |
140 return new Array(); | 141 return new Array(); |
141 } | 142 } |
142 a = bar(); | 143 a = bar(); |
143 bar(); | 144 bar(); |
144 %OptimizeFunctionOnNextCall(bar); | 145 %OptimizeFunctionOnNextCall(bar); |
145 b = bar(); | 146 b = bar(); |
146 // This only makes sense to test if we allow crankshafting | 147 // This only makes sense to test if we allow crankshafting |
147 if (4 != %GetOptimizationStatus(bar)) { | 148 assertOptimized(bar); |
148 assertOptimized(bar); | 149 %DebugPrint(3); |
149 %DebugPrint(3); | 150 b[0] = 3.5; |
150 b[0] = 3.5; | 151 c = bar(); |
151 c = bar(); | 152 assertKind(elements_kind.fast_smi_only, c); |
152 assertKind(elements_kind.fast_smi_only, c); | 153 assertOptimized(bar); |
153 assertOptimized(bar); | |
154 } | |
155 })(); | 154 })(); |
156 | 155 |
157 | 156 |
158 // Test: create arrays in two contexts, verifying that the correct | 157 // Test: create arrays in two contexts, verifying that the correct |
159 // map for Array in that context will be used. | 158 // map for Array in that context will be used. |
160 (function() { | 159 (function() { |
161 function bar() { return new Array(); } | 160 function bar() { return new Array(); } |
162 bar(); | 161 bar(); |
163 bar(); | 162 bar(); |
164 %OptimizeFunctionOnNextCall(bar); | 163 %OptimizeFunctionOnNextCall(bar); |
165 a = bar(); | 164 a = bar(); |
166 assertTrue(a instanceof Array); | 165 assertTrue(a instanceof Array); |
167 | 166 |
168 var contextB = Realm.create(); | 167 var contextB = Realm.create(); |
169 Realm.eval(contextB, "function bar2() { return new Array(); };"); | 168 Realm.eval(contextB, "function bar2() { return new Array(); };"); |
170 Realm.eval(contextB, "bar2(); bar2();"); | 169 Realm.eval(contextB, "bar2(); bar2();"); |
171 Realm.eval(contextB, "%OptimizeFunctionOnNextCall(bar2);"); | 170 Realm.eval(contextB, "%OptimizeFunctionOnNextCall(bar2);"); |
172 Realm.eval(contextB, "bar2();"); | 171 Realm.eval(contextB, "bar2();"); |
173 assertFalse(Realm.eval(contextB, "bar2();") instanceof Array); | 172 assertFalse(Realm.eval(contextB, "bar2();") instanceof Array); |
174 assertTrue(Realm.eval(contextB, "bar2() instanceof Array")); | 173 assertTrue(Realm.eval(contextB, "bar2() instanceof Array")); |
175 })(); | 174 })(); |
176 | 175 |
177 // Test: create array with packed feedback, then optimize function, which | 176 // Test: create array with packed feedback, then optimize function, which |
178 // should deal with arguments that create holey arrays. | 177 // should deal with arguments that create holey arrays. |
179 (function() { | 178 (function() { |
180 function bar(len) { return new Array(len); } | 179 function bar(len) { return new Array(len); } |
181 bar(0); | 180 bar(0); |
182 bar(0); | 181 bar(0); |
183 %OptimizeFunctionOnNextCall(bar); | 182 %OptimizeFunctionOnNextCall(bar); |
184 a = bar(0); | 183 a = bar(0); |
185 assertOptimized(bar); | 184 assertOptimized(bar); |
186 assertFalse(isHoley(a)); | 185 assertFalse(isHoley(a)); |
187 a = bar(1); // ouch! | 186 a = bar(1); // ouch! |
188 assertOptimized(bar); | 187 assertOptimized(bar); |
189 assertTrue(isHoley(a)); | 188 assertTrue(isHoley(a)); |
190 a = bar(100); | 189 a = bar(100); |
191 assertTrue(isHoley(a)); | 190 assertTrue(isHoley(a)); |
192 a = bar(0); | 191 a = bar(0); |
193 assertOptimized(bar); | 192 assertOptimized(bar); |
194 // Crankshafted functions don't use mementos, so feedback still | 193 // Crankshafted functions don't use mementos, so feedback still |
195 // indicates a packed array is desired. (unless --nocrankshaft is in use). | 194 // indicates a packed array is desired. |
196 if (4 != %GetOptimizationStatus(bar)) { | 195 assertFalse(isHoley(a)); |
197 assertFalse(isHoley(a)); | |
198 } | |
199 })(); | 196 })(); |
200 | 197 |
201 // Test: Make sure that crankshaft continues with feedback for large arrays. | 198 // Test: Make sure that crankshaft continues with feedback for large arrays. |
202 (function() { | 199 (function() { |
203 function bar(len) { return new Array(len); } | 200 function bar(len) { return new Array(len); } |
204 var size = 100001; | 201 var size = 100001; |
205 // Perform a gc, because we are allocating a very large array and if a gc | 202 // Perform a gc, because we are allocating a very large array and if a gc |
206 // happens during the allocation we could lose our memento. | 203 // happens during the allocation we could lose our memento. |
207 gc(); | 204 gc(); |
208 bar(size)[0] = 'string'; | 205 bar(size)[0] = 'string'; |
209 var res = bar(size); | 206 var res = bar(size); |
210 assertKind(elements_kind.fast, bar(size)); | 207 assertKind(elements_kind.fast, bar(size)); |
211 %OptimizeFunctionOnNextCall(bar); | 208 %OptimizeFunctionOnNextCall(bar); |
212 assertKind(elements_kind.fast, bar(size)); | 209 assertKind(elements_kind.fast, bar(size)); |
213 // But there is a limit, based on the size of the old generation, currently | 210 // But there is a limit, based on the size of the old generation, currently |
214 // 22937600, but double it to prevent the test being too brittle. | 211 // 22937600, but double it to prevent the test being too brittle. |
215 var large_size = 22937600 * 2; | 212 var large_size = 22937600 * 2; |
216 assertKind(elements_kind.dictionary, bar(large_size)); | 213 assertKind(elements_kind.dictionary, bar(large_size)); |
217 })(); | 214 })(); |
OLD | NEW |