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