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 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 expected = elements_kind.fast; | 78 expected = elements_kind.fast; |
79 } | 79 } |
80 assertEquals(expected, getKind(obj), name_opt); | 80 assertEquals(expected, getKind(obj), name_opt); |
81 } | 81 } |
82 | 82 |
83 if (support_smi_only_arrays) { | 83 if (support_smi_only_arrays) { |
84 | 84 |
85 // Verify that basic elements kind feedback works for non-constructor | 85 // Verify that basic elements kind feedback works for non-constructor |
86 // array calls (as long as the call is made through an IC, and not | 86 // array calls (as long as the call is made through an IC, and not |
87 // a CallStub). | 87 // a CallStub). |
88 // (function (){ | 88 (function (){ |
89 // function create0() { | 89 function create0() { |
90 // return Array(); | 90 return Array(); |
91 // } | 91 } |
92 | 92 |
93 // // Calls through ICs need warm up through uninitialized, then | 93 // Calls through ICs need warm up through uninitialized, then |
94 // // premonomorphic first. | 94 // premonomorphic first. |
95 // create0(); | 95 create0(); |
96 // create0(); | 96 a = create0(); |
97 // a = create0(); | 97 assertKind(elements_kind.fast_smi_only, a); |
98 // assertKind(elements_kind.fast_smi_only, a); | 98 a[0] = 3.5; |
99 // a[0] = 3.5; | 99 b = create0(); |
100 // b = create0(); | 100 assertKind(elements_kind.fast_double, b); |
101 // assertKind(elements_kind.fast_double, b); | |
102 | 101 |
103 // function create1(arg) { | 102 function create1(arg) { |
104 // return Array(arg); | 103 return Array(arg); |
105 // } | 104 } |
106 | 105 |
107 // create1(0); | 106 create1(0); |
108 // create1(0); | 107 create1(0); |
109 // a = create1(0); | 108 a = create1(0); |
110 // assertFalse(isHoley(a)); | 109 assertFalse(isHoley(a)); |
111 // assertKind(elements_kind.fast_smi_only, a); | 110 assertKind(elements_kind.fast_smi_only, a); |
112 // a[0] = "hello"; | 111 a[0] = "hello"; |
113 // b = create1(10); | 112 b = create1(10); |
114 // assertTrue(isHoley(b)); | 113 assertTrue(isHoley(b)); |
115 // assertKind(elements_kind.fast, b); | 114 assertKind(elements_kind.fast, b); |
116 | 115 |
117 // a = create1(100000); | 116 a = create1(100000); |
118 // assertKind(elements_kind.dictionary, a); | 117 assertKind(elements_kind.dictionary, a); |
119 | 118 |
120 // function create3(arg1, arg2, arg3) { | 119 function create3(arg1, arg2, arg3) { |
121 // return Array(arg1, arg2, arg3); | 120 return Array(arg1, arg2, arg3); |
122 // } | 121 } |
123 | 122 |
124 // create3(); | 123 create3(1,2,3); |
125 // create3(); | 124 create3(1,2,3); |
126 // a = create3(1,2,3); | 125 a = create3(1,2,3); |
127 // a[0] = 3.5; | 126 a[0] = 3.035; |
128 // b = create3(1,2,3); | 127 assertKind(elements_kind.fast_double, a); |
129 // assertKind(elements_kind.fast_double, b); | 128 b = create3(1,2,3); |
130 // assertFalse(isHoley(b)); | 129 assertKind(elements_kind.fast_double, b); |
131 // })(); | 130 assertFalse(isHoley(b)); |
| 131 })(); |
132 | 132 |
133 | 133 |
134 // Verify that keyed calls work | 134 // Verify that keyed calls work |
135 // (function (){ | 135 (function (){ |
136 // function create0(name) { | 136 function create0(name) { |
137 // return this[name](); | 137 return this[name](); |
138 // } | 138 } |
139 | 139 |
140 // name = "Array"; | 140 name = "Array"; |
141 // create0(name); | 141 create0(name); |
142 // create0(name); | 142 create0(name); |
143 // a = create0(name); | 143 a = create0(name); |
144 // a[0] = 3.5; | 144 a[0] = 3.5; |
145 // b = create0(name); | 145 b = create0(name); |
146 // assertKind(elements_kind.fast_double, b); | 146 assertKind(elements_kind.fast_double, b); |
147 // })(); | 147 })(); |
148 | 148 |
149 | 149 |
150 // Verify that the IC can't be spoofed by patching | 150 // Verify that feedback is turned off if the call site goes megamorphic. |
| 151 (function (){ |
| 152 function foo(arg) { return arg(); } |
| 153 foo(Array); |
| 154 foo(function() {}); |
| 155 foo(Array); |
| 156 |
| 157 gc(); |
| 158 |
| 159 a = foo(Array); |
| 160 a[0] = 3.5; |
| 161 b = foo(Array); |
| 162 // b doesn't benefit from elements kind feedback at a megamorphic site. |
| 163 assertKind(elements_kind.fast_smi_only, b); |
| 164 })(); |
| 165 |
| 166 |
| 167 // Verify that crankshaft consumes type feedback. |
151 (function (){ | 168 (function (){ |
152 function create0() { | 169 function create0() { |
153 return Array(); | 170 return Array(); |
154 } | 171 } |
155 | 172 |
156 create0(); | 173 create0(); |
157 create0(); | 174 create0(); |
158 a = create0(); | 175 a = create0(); |
159 assertKind(elements_kind.fast_smi_only, a); | 176 a[0] = 3.5; |
160 var oldArray = this.Array; | 177 %OptimizeFunctionOnNextCall(create0); |
161 this.Array = function() { return ["hi"]; }; | 178 create0(); |
| 179 create0(); |
162 b = create0(); | 180 b = create0(); |
163 assertEquals(["hi"], b); | 181 assertKind(elements_kind.fast_double, b); |
164 this.Array = oldArray; | 182 assertOptimized(create0); |
| 183 |
| 184 function create1(arg) { |
| 185 return Array(arg); |
| 186 } |
| 187 |
| 188 create1(8); |
| 189 create1(8); |
| 190 a = create1(8); |
| 191 a[0] = 3.5; |
| 192 %OptimizeFunctionOnNextCall(create1); |
| 193 b = create1(8); |
| 194 assertKind(elements_kind.fast_double, b); |
| 195 assertOptimized(create1); |
| 196 |
| 197 function createN(arg1, arg2, arg3) { |
| 198 return Array(arg1, arg2, arg3); |
| 199 } |
| 200 |
| 201 createN(1, 2, 3); |
| 202 createN(1, 2, 3); |
| 203 a = createN(1, 2, 3); |
| 204 a[0] = 3.5; |
| 205 %OptimizeFunctionOnNextCall(createN); |
| 206 b = createN(1, 2, 3); |
| 207 assertKind(elements_kind.fast_double, b); |
| 208 assertOptimized(createN); |
165 })(); | 209 })(); |
166 | 210 |
167 // Verify that calls are still made through an IC after crankshaft, | |
168 // though the type information is reset. | |
169 // TODO(mvstanton): instead, consume the type feedback gathered up | |
170 // until crankshaft time. | |
171 // (function (){ | |
172 // function create0() { | |
173 // return Array(); | |
174 // } | |
175 | |
176 // create0(); | |
177 // create0(); | |
178 // a = create0(); | |
179 // a[0] = 3.5; | |
180 // %OptimizeFunctionOnNextCall(create0); | |
181 // create0(); | |
182 // // This test only makes sense if crankshaft is allowed | |
183 // if (4 != %GetOptimizationStatus(create0)) { | |
184 // create0(); | |
185 // b = create0(); | |
186 // assertKind(elements_kind.fast_smi_only, b); | |
187 // b[0] = 3.5; | |
188 // c = create0(); | |
189 // assertKind(elements_kind.fast_double, c); | |
190 // assertOptimized(create0); | |
191 // } | |
192 // })(); | |
193 | |
194 | |
195 // Verify that cross context calls work | 211 // Verify that cross context calls work |
196 (function (){ | 212 (function (){ |
197 var realmA = Realm.current(); | 213 var realmA = Realm.current(); |
198 var realmB = Realm.create(); | 214 var realmB = Realm.create(); |
199 assertEquals(0, realmA); | 215 assertEquals(0, realmA); |
200 assertEquals(1, realmB); | 216 assertEquals(1, realmB); |
201 | 217 |
202 function instanceof_check(type) { | 218 function instanceof_check(type) { |
203 assertTrue(type() instanceof type); | 219 assertTrue(type() instanceof type); |
204 assertTrue(type(5) instanceof type); | 220 assertTrue(type(5) instanceof type); |
205 assertTrue(type(1,2,3) instanceof type); | 221 assertTrue(type(1,2,3) instanceof type); |
206 } | 222 } |
207 | 223 |
208 var realmBArray = Realm.eval(realmB, "Array"); | 224 var realmBArray = Realm.eval(realmB, "Array"); |
209 instanceof_check(Array); | 225 instanceof_check(Array); |
210 instanceof_check(Array); | 226 instanceof_check(Array); |
211 instanceof_check(Array); | 227 instanceof_check(Array); |
212 instanceof_check(realmBArray); | 228 instanceof_check(realmBArray); |
213 instanceof_check(realmBArray); | 229 instanceof_check(realmBArray); |
214 instanceof_check(realmBArray); | 230 instanceof_check(realmBArray); |
215 })(); | 231 })(); |
216 } | 232 } |
OLD | NEW |