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