OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of js_backend; | 5 part of js_backend; |
6 | 6 |
7 const VERBOSE_OPTIMIZER_HINTS = false; | 7 const VERBOSE_OPTIMIZER_HINTS = false; |
8 | 8 |
9 class JavaScriptItemCompilationContext extends ItemCompilationContext { | 9 class JavaScriptItemCompilationContext extends ItemCompilationContext { |
10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); | 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 * generated. | 158 * generated. |
159 */ | 159 */ |
160 final Map<String, Selector> oneShotInterceptors; | 160 final Map<String, Selector> oneShotInterceptors; |
161 | 161 |
162 /** | 162 /** |
163 * The members of instantiated interceptor classes: maps a member name to the | 163 * The members of instantiated interceptor classes: maps a member name to the |
164 * list of members that have that name. This map is used by the codegen to | 164 * list of members that have that name. This map is used by the codegen to |
165 * know whether a send must be intercepted or not. | 165 * know whether a send must be intercepted or not. |
166 */ | 166 */ |
167 final Map<String, Set<Element>> interceptedElements; | 167 final Map<String, Set<Element>> interceptedElements; |
168 // TODO(sra): Not all methods in the Set always require an interceptor. A | 168 |
169 // method may be mixed into a true interceptor *and* a plain class. For the | 169 /** |
170 // method to work on the interceptor class it needs to use the explicit | 170 * The members of mixin classes that are mixed into an instantiated |
171 // receiver. This constrains the call on a known plain receiver to pass the | 171 * interceptor class. This is a cached subset of [interceptedElements]. |
172 // explicit receiver. https://code.google.com/p/dart/issues/detail?id=8942 | 172 * These members must be invoked with a correct explicit receiver even when |
| 173 * the receiver is not an intercepted class because the function uses the |
| 174 * explicit interceptor parameter since it may be called on an intercepted |
| 175 * class. |
| 176 */ |
| 177 final Map<String, Set<Element>> interceptedMixinElements = |
| 178 new Map<String, Set<Element>>(); |
173 | 179 |
174 /** | 180 /** |
175 * A map of specialized versions of the [getInterceptorMethod]. | 181 * A map of specialized versions of the [getInterceptorMethod]. |
176 * Since [getInterceptorMethod] is a hot method at runtime, we're | 182 * Since [getInterceptorMethod] is a hot method at runtime, we're |
177 * always specializing it based on the incoming type. The keys in | 183 * always specializing it based on the incoming type. The keys in |
178 * the map are the names of these specialized versions. Note that | 184 * the map are the names of these specialized versions. Note that |
179 * the generic version that contains all possible type checks is | 185 * the generic version that contains all possible type checks is |
180 * also stored in this map. | 186 * also stored in this map. |
181 */ | 187 */ |
182 final Map<String, Set<ClassElement>> specializedGetInterceptors; | 188 final Map<String, Set<ClassElement>> specializedGetInterceptors; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 } | 367 } |
362 | 368 |
363 bool isInterceptedName(String name) { | 369 bool isInterceptedName(String name) { |
364 return interceptedElements[name] != null; | 370 return interceptedElements[name] != null; |
365 } | 371 } |
366 | 372 |
367 bool isInterceptedSelector(Selector selector) { | 373 bool isInterceptedSelector(Selector selector) { |
368 return interceptedElements[selector.name] != null; | 374 return interceptedElements[selector.name] != null; |
369 } | 375 } |
370 | 376 |
| 377 /** |
| 378 * Returns `true` iff [selector] matches an element defined in a class mixed |
| 379 * into an intercepted class. These selectors are not eligible for the 'dummy |
| 380 * explicit receiver' optimization. |
| 381 */ |
| 382 bool isInterceptedMixinSelector(Selector selector) { |
| 383 Set<Element> elements = interceptedMixinElements.putIfAbsent( |
| 384 selector.name, |
| 385 () { |
| 386 Set<Element> elements = interceptedElements[selector.name]; |
| 387 if (elements == null) return null; |
| 388 return elements |
| 389 .where((element) => |
| 390 classesMixedIntoNativeClasses.contains( |
| 391 element.getEnclosingClass())) |
| 392 .toSet(); |
| 393 }); |
| 394 |
| 395 if (elements == null) return false; |
| 396 if (elements.isEmpty) return false; |
| 397 return elements.any((element) => selector.applies(element, compiler)); |
| 398 } |
| 399 |
371 final Map<String, Set<ClassElement>> interceptedClassesCache = | 400 final Map<String, Set<ClassElement>> interceptedClassesCache = |
372 new Map<String, Set<ClassElement>>(); | 401 new Map<String, Set<ClassElement>>(); |
373 | 402 |
374 /** | 403 /** |
375 * Returns a set of interceptor classes that contain a member named | 404 * Returns a set of interceptor classes that contain a member named |
376 * [name]. Returns [:null:] if there is no class. | 405 * [name]. Returns [:null:] if there is no class. |
377 */ | 406 */ |
378 Set<ClassElement> getInterceptedClassesOn(String name) { | 407 Set<ClassElement> getInterceptedClassesOn(String name) { |
379 Set<Element> intercepted = interceptedElements[name]; | 408 Set<Element> intercepted = interceptedElements[name]; |
380 if (intercepted == null) return null; | 409 if (intercepted == null) return null; |
(...skipping 1467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1848 void visitTrue(TrueConstant constant) => copy(constant); | 1877 void visitTrue(TrueConstant constant) => copy(constant); |
1849 | 1878 |
1850 void visitFalse(FalseConstant constant) => copy(constant); | 1879 void visitFalse(FalseConstant constant) => copy(constant); |
1851 | 1880 |
1852 void visitString(StringConstant constant) => copy(constant); | 1881 void visitString(StringConstant constant) => copy(constant); |
1853 | 1882 |
1854 void visitType(TypeConstant constant) => copy(constant); | 1883 void visitType(TypeConstant constant) => copy(constant); |
1855 | 1884 |
1856 void visitInterceptor(InterceptorConstant constant) => copy(constant); | 1885 void visitInterceptor(InterceptorConstant constant) => copy(constant); |
1857 | 1886 |
| 1887 void visitDummyReceiver(DummyReceiverConstant constant) => copy(constant); |
| 1888 |
1858 void visitList(ListConstant constant) { | 1889 void visitList(ListConstant constant) { |
1859 copy(constant.entries); | 1890 copy(constant.entries); |
1860 copy(constant); | 1891 copy(constant); |
1861 } | 1892 } |
1862 void visitMap(MapConstant constant) { | 1893 void visitMap(MapConstant constant) { |
1863 copy(constant.keys); | 1894 copy(constant.keys); |
1864 copy(constant.values); | 1895 copy(constant.values); |
1865 copy(constant.protoValue); | 1896 copy(constant.protoValue); |
1866 copy(constant); | 1897 copy(constant); |
1867 } | 1898 } |
1868 | 1899 |
1869 void visitConstructed(ConstructedConstant constant) { | 1900 void visitConstructed(ConstructedConstant constant) { |
1870 copy(constant.fields); | 1901 copy(constant.fields); |
1871 copy(constant); | 1902 copy(constant); |
1872 } | 1903 } |
1873 } | 1904 } |
OLD | NEW |