Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/js_backend/native_emitter.dart

Issue 340023003: Various caches for incremental compilation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Only allocate caches when hasIncrementalCompilation is true. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 class NativeEmitter { 7 class NativeEmitter {
8 8
9 CodeEmitterTask emitter; 9 final Map<Element, ClassBuilder> cachedBuilders;
10
11 final CodeEmitterTask emitter;
10 CodeBuffer nativeBuffer; 12 CodeBuffer nativeBuffer;
11 13
12 // Native classes found in the application. 14 // Native classes found in the application.
13 Set<ClassElement> nativeClasses = new Set<ClassElement>(); 15 Set<ClassElement> nativeClasses = new Set<ClassElement>();
14 16
15 // Caches the native subtypes of a native class. 17 // Caches the native subtypes of a native class.
16 Map<ClassElement, List<ClassElement>> subtypes; 18 Map<ClassElement, List<ClassElement>> subtypes;
17 19
18 // Caches the direct native subtypes of a native class. 20 // Caches the direct native subtypes of a native class.
19 Map<ClassElement, List<ClassElement>> directSubtypes; 21 Map<ClassElement, List<ClassElement>> directSubtypes;
20 22
21 // Caches the methods that have a native body. 23 // Caches the methods that have a native body.
22 Set<FunctionElement> nativeMethods; 24 Set<FunctionElement> nativeMethods;
23 25
24 // Do we need the native emitter to take care of handling 26 // Do we need the native emitter to take care of handling
25 // noSuchMethod for us? This flag is set to true in the emitter if 27 // noSuchMethod for us? This flag is set to true in the emitter if
26 // it finds any native class that needs noSuchMethod handling. 28 // it finds any native class that needs noSuchMethod handling.
27 bool handleNoSuchMethod = false; 29 bool handleNoSuchMethod = false;
28 30
29 NativeEmitter(this.emitter) 31 NativeEmitter(CodeEmitterTask emitter)
30 : subtypes = new Map<ClassElement, List<ClassElement>>(), 32 : this.emitter = emitter,
33 subtypes = new Map<ClassElement, List<ClassElement>>(),
31 directSubtypes = new Map<ClassElement, List<ClassElement>>(), 34 directSubtypes = new Map<ClassElement, List<ClassElement>>(),
32 nativeMethods = new Set<FunctionElement>(), 35 nativeMethods = new Set<FunctionElement>(),
33 nativeBuffer = new CodeBuffer(); 36 nativeBuffer = new CodeBuffer(),
37 cachedBuilders = emitter.compiler.cacheStrategy.newMap();
34 38
35 Compiler get compiler => emitter.compiler; 39 Compiler get compiler => emitter.compiler;
36 JavaScriptBackend get backend => compiler.backend; 40 JavaScriptBackend get backend => compiler.backend;
37 41
38 String get _ => emitter.space; 42 String get _ => emitter.space;
39 String get n => emitter.n; 43 String get n => emitter.n;
40 String get N => emitter.N; 44 String get N => emitter.N;
41 45
42 jsAst.Expression get defPropFunction { 46 jsAst.Expression get defPropFunction {
43 Element element = compiler.findHelper('defineProperty'); 47 Element element = compiler.findHelper('defineProperty');
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 if (nativeAncestor != null) { 276 if (nativeAncestor != null) {
273 map 277 map
274 .putIfAbsent(nativeAncestor, () => <ClassElement>[]) 278 .putIfAbsent(nativeAncestor, () => <ClassElement>[])
275 .add(classElement); 279 .add(classElement);
276 } 280 }
277 } 281 }
278 return map; 282 return map;
279 } 283 }
280 284
281 ClassBuilder generateNativeClass(ClassElement classElement) { 285 ClassBuilder generateNativeClass(ClassElement classElement) {
286 ClassBuilder builder;
287 if (compiler.hasIncrementalSupport) {
288 builder = cachedBuilders[classElement];
289 if (builder != null) return builder;
290 builder = new ClassBuilder(backend.namer);
291 cachedBuilders[classElement] = builder;
292 } else {
293 builder = new ClassBuilder(backend.namer);
294 }
295
282 // TODO(sra): Issue #13731- this is commented out as part of custom element 296 // TODO(sra): Issue #13731- this is commented out as part of custom element
283 // constructor work. 297 // constructor work.
284 //assert(!classElement.hasBackendMembers); 298 //assert(!classElement.hasBackendMembers);
285 nativeClasses.add(classElement); 299 nativeClasses.add(classElement);
286 300
287 ClassElement superclass = classElement.superclass; 301 ClassElement superclass = classElement.superclass;
288 assert(superclass != null); 302 assert(superclass != null);
289 // Fix superclass. TODO(sra): make native classes inherit from Interceptor. 303 // Fix superclass. TODO(sra): make native classes inherit from Interceptor.
290 assert(superclass != compiler.objectClass); 304 assert(superclass != compiler.objectClass);
291 if (superclass == compiler.objectClass) { 305 if (superclass == compiler.objectClass) {
292 superclass = backend.jsInterceptorClass; 306 superclass = backend.jsInterceptorClass;
293 } 307 }
294 308
295 String superName = backend.namer.getNameOfClass(superclass); 309 String superName = backend.namer.getNameOfClass(superclass);
296 310
297 ClassBuilder builder = new ClassBuilder(backend.namer);
298 emitter.classEmitter.emitClassConstructor(classElement, builder); 311 emitter.classEmitter.emitClassConstructor(classElement, builder);
299 bool hasFields = emitter.classEmitter.emitFields( 312 bool hasFields = emitter.classEmitter.emitFields(
300 classElement, builder, superName, classIsNative: true); 313 classElement, builder, superName, classIsNative: true);
301 int propertyCount = builder.properties.length; 314 int propertyCount = builder.properties.length;
302 emitter.classEmitter.emitClassGettersSetters(classElement, builder); 315 emitter.classEmitter.emitClassGettersSetters(classElement, builder);
303 emitter.classEmitter.emitInstanceMembers(classElement, builder); 316 emitter.classEmitter.emitInstanceMembers(classElement, builder);
304 emitter.typeTestEmitter.emitIsTests(classElement, builder); 317 emitter.typeTestEmitter.emitIsTests(classElement, builder);
305 318
306 if (!hasFields && 319 if (!hasFields &&
307 builder.properties.length == propertyCount && 320 builder.properties.length == propertyCount &&
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 if (emitter.compiler.enableMinification) targetBuffer.add(';'); 471 if (emitter.compiler.enableMinification) targetBuffer.add(';');
459 targetBuffer.add(jsAst.prettyPrint( 472 targetBuffer.add(jsAst.prettyPrint(
460 new jsAst.ExpressionStatement(init), compiler)); 473 new jsAst.ExpressionStatement(init), compiler));
461 targetBuffer.add('\n'); 474 targetBuffer.add('\n');
462 } 475 }
463 476
464 targetBuffer.add(nativeBuffer); 477 targetBuffer.add(nativeBuffer);
465 targetBuffer.add('\n'); 478 targetBuffer.add('\n');
466 } 479 }
467 } 480 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698