Chromium Code Reviews| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 /** | 161 /** |
| 162 * The members of instantiated interceptor classes: maps a member name to the | 162 * The members of instantiated interceptor classes: maps a member name to the |
| 163 * list of members that have that name. This map is used by the codegen to | 163 * list of members that have that name. This map is used by the codegen to |
| 164 * know whether a send must be intercepted or not. | 164 * know whether a send must be intercepted or not. |
| 165 */ | 165 */ |
| 166 final Map<String, Set<Element>> interceptedElements; | 166 final Map<String, Set<Element>> interceptedElements; |
| 167 // TODO(sra): Not all methods in the Set always require an interceptor. A | 167 // TODO(sra): Not all methods in the Set always require an interceptor. A |
| 168 // method may be mixed into a true interceptor *and* a plain class. For the | 168 // method may be mixed into a true interceptor *and* a plain class. For the |
| 169 // method to work on the interceptor class it needs to use the explicit | 169 // method to work on the interceptor class it needs to use the explicit |
| 170 // receiver. This constrains the call on a known plain receiver to pass the | 170 // receiver. This constrains the call on a known plain receiver to pass the |
| 171 // explicit receiver. https://code.google.com/p/dart/issues/detail?id=8942 | 171 // explicit receiver. https://code.google.com/p/dart/issues/detail?id=8942 |
|
floitsch
2013/12/18 19:20:12
Update comment.
sra1
2013/12/19 03:28:15
Done.
| |
| 172 | 172 |
| 173 /** | 173 /** |
| 174 * The members of mixin classes that are mixed into an instantiated | |
| 175 * interceptor class. This is a cached subset of [interceptedElements]. | |
| 176 * These members must be invoked with a correct explicit receiver even when | |
| 177 * the receiver is not an intercepted class because the function uses the | |
| 178 * explicit interceptor parameter since it may be called on an intercepted | |
| 179 * class. | |
| 180 */ | |
| 181 final Map<SourceString, Set<Element>> interceptedMixinElements = | |
| 182 new Map<SourceString, Set<Element>>(); | |
| 183 | |
| 184 /** | |
| 174 * A map of specialized versions of the [getInterceptorMethod]. | 185 * A map of specialized versions of the [getInterceptorMethod]. |
| 175 * Since [getInterceptorMethod] is a hot method at runtime, we're | 186 * Since [getInterceptorMethod] is a hot method at runtime, we're |
| 176 * always specializing it based on the incoming type. The keys in | 187 * always specializing it based on the incoming type. The keys in |
| 177 * the map are the names of these specialized versions. Note that | 188 * the map are the names of these specialized versions. Note that |
| 178 * the generic version that contains all possible type checks is | 189 * the generic version that contains all possible type checks is |
| 179 * also stored in this map. | 190 * also stored in this map. |
| 180 */ | 191 */ |
| 181 final Map<String, Set<ClassElement>> specializedGetInterceptors; | 192 final Map<String, Set<ClassElement>> specializedGetInterceptors; |
| 182 | 193 |
| 183 /** | 194 /** |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 } | 371 } |
| 361 | 372 |
| 362 bool isInterceptedName(String name) { | 373 bool isInterceptedName(String name) { |
| 363 return interceptedElements[name] != null; | 374 return interceptedElements[name] != null; |
| 364 } | 375 } |
| 365 | 376 |
| 366 bool isInterceptedSelector(Selector selector) { | 377 bool isInterceptedSelector(Selector selector) { |
| 367 return interceptedElements[selector.name] != null; | 378 return interceptedElements[selector.name] != null; |
| 368 } | 379 } |
| 369 | 380 |
| 381 /** | |
| 382 * Returns `true` iff [selector] matches an element defined in a class mixed | |
| 383 * into an intercepted class. These selectors are not eligible for the 'dummy | |
| 384 * explicit receiver' optimization. | |
| 385 */ | |
| 386 bool isInterceptedMixinSelector(Selector selector) { | |
| 387 Set<Element> elements = interceptedMixinElements.putIfAbsent( | |
| 388 selector.name, | |
| 389 () { | |
| 390 Set<Element> elements = interceptedElements[selector.name]; | |
| 391 if (elements == null) return null; | |
| 392 return elements | |
| 393 .where((element) => | |
| 394 classesMixedIntoNativeClasses.contains( | |
| 395 element.getEnclosingClass())) | |
| 396 .toSet(); | |
| 397 }); | |
| 398 | |
| 399 if (elements == null) return false; | |
| 400 if (elements.isEmpty) return false; | |
| 401 return elements.any((element) => selector.applies(element, compiler)); | |
| 402 } | |
| 403 | |
| 370 final Map<String, Set<ClassElement>> interceptedClassesCache = | 404 final Map<String, Set<ClassElement>> interceptedClassesCache = |
| 371 new Map<String, Set<ClassElement>>(); | 405 new Map<String, Set<ClassElement>>(); |
| 372 | 406 |
| 373 /** | 407 /** |
| 374 * Returns a set of interceptor classes that contain a member named | 408 * Returns a set of interceptor classes that contain a member named |
| 375 * [name]. Returns [:null:] if there is no class. | 409 * [name]. Returns [:null:] if there is no class. |
| 376 */ | 410 */ |
| 377 Set<ClassElement> getInterceptedClassesOn(String name) { | 411 Set<ClassElement> getInterceptedClassesOn(String name) { |
| 378 Set<Element> intercepted = interceptedElements[name]; | 412 Set<Element> intercepted = interceptedElements[name]; |
| 379 if (intercepted == null) return null; | 413 if (intercepted == null) return null; |
| (...skipping 1482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1862 copy(constant.values); | 1896 copy(constant.values); |
| 1863 copy(constant.protoValue); | 1897 copy(constant.protoValue); |
| 1864 copy(constant); | 1898 copy(constant); |
| 1865 } | 1899 } |
| 1866 | 1900 |
| 1867 void visitConstructed(ConstructedConstant constant) { | 1901 void visitConstructed(ConstructedConstant constant) { |
| 1868 copy(constant.fields); | 1902 copy(constant.fields); |
| 1869 copy(constant); | 1903 copy(constant); |
| 1870 } | 1904 } |
| 1871 } | 1905 } |
| OLD | NEW |