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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/native_generator.dart

Issue 1264303002: dart2js: fix a few TODOs in the startup emitter. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Emit affinity tag only once. Created 5 years, 4 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 class NativeGenerator { 7 class NativeGenerator {
8 8
9 static bool needsIsolateAffinityTagInitialization(JavaScriptBackend backend) { 9 static bool needsIsolateAffinityTagInitialization(JavaScriptBackend backend) {
10 return backend.needToInitializeIsolateAffinityTag; 10 return backend.needToInitializeIsolateAffinityTag;
11 } 11 }
12 12
13 /// Generates the code for isolate affinity tags. 13 /// Generates the code for isolate affinity tags.
14 /// 14 ///
15 /// Independently Dart programs on the same page must not interfer and 15 /// Independently Dart programs on the same page must not interfer and
16 /// this code sets up the variables needed to guarantee that behavior. 16 /// this code sets up the variables needed to guarantee that behavior.
17 static jsAst.Statement generateIsolateAffinityTagInitialization( 17 static jsAst.Statement generateIsolateAffinityTagInitialization(
18 JavaScriptBackend backend, 18 JavaScriptBackend backend,
19 jsAst.Expression generateEmbeddedGlobalAccess(String global), 19 jsAst.Expression generateEmbeddedGlobalAccess(String global),
20 jsAst.Expression convertToFastObject) { 20 jsAst.Expression internStringFunction) {
21 assert(backend.needToInitializeIsolateAffinityTag); 21 assert(backend.needToInitializeIsolateAffinityTag);
22 22
23 jsAst.Expression getIsolateTagAccess = 23 jsAst.Expression getIsolateTagAccess =
24 generateEmbeddedGlobalAccess(embeddedNames.GET_ISOLATE_TAG); 24 generateEmbeddedGlobalAccess(embeddedNames.GET_ISOLATE_TAG);
25 jsAst.Expression isolateTagAccess = 25 jsAst.Expression isolateTagAccess =
26 generateEmbeddedGlobalAccess(embeddedNames.ISOLATE_TAG); 26 generateEmbeddedGlobalAccess(embeddedNames.ISOLATE_TAG);
27 jsAst.Expression dispatchPropertyNameAccess = 27 jsAst.Expression dispatchPropertyNameAccess =
28 generateEmbeddedGlobalAccess(embeddedNames.DISPATCH_PROPERTY_NAME); 28 generateEmbeddedGlobalAccess(embeddedNames.DISPATCH_PROPERTY_NAME);
29 29
30 return js.statement(''' 30 return js.statement('''
31 !function() { 31 !function() {
32 // On V8, the 'intern' function converts a string to a symbol, which 32 var intern = #internStringFunction;
33 // makes property access much faster.
34 function intern(s) {
35 var o = {};
36 o[s] = 1;
37 return Object.keys(#convertToFastObject(o))[0];
38 }
39 33
40 #getIsolateTag = function(name) { 34 #getIsolateTag = function(name) {
41 return intern("___dart_" + name + #isolateTag); 35 return intern("___dart_" + name + #isolateTag);
42 }; 36 };
43 37
44 // To ensure that different programs loaded into the same context (page) 38 // To ensure that different programs loaded into the same context (page)
45 // use distinct dispatch properies, we place an object on `Object` to 39 // use distinct dispatch properies, we place an object on `Object` to
46 // contain the names already in use. 40 // contain the names already in use.
47 var tableProperty = "___dart_isolate_tags_"; 41 var tableProperty = "___dart_isolate_tags_";
48 var usedProperties = Object[tableProperty] || 42 var usedProperties = Object[tableProperty] ||
49 (Object[tableProperty] = Object.create(null)); 43 (Object[tableProperty] = Object.create(null));
50 44
51 var rootProperty = "_${generateIsolateTagRoot()}"; 45 var rootProperty = "_${generateIsolateTagRoot()}";
52 for (var i = 0; ; i++) { 46 for (var i = 0; ; i++) {
53 var property = intern(rootProperty + "_" + i + "_"); 47 var property = intern(rootProperty + "_" + i + "_");
54 if (!(property in usedProperties)) { 48 if (!(property in usedProperties)) {
55 usedProperties[property] = 1; 49 usedProperties[property] = 1;
56 #isolateTag = property; 50 #isolateTag = property;
57 break; 51 break;
58 } 52 }
59 } 53 }
60 if (#initializeDispatchProperty) { 54 if (#initializeDispatchProperty) {
61 #dispatchPropertyName = #getIsolateTag("dispatch_record"); 55 #dispatchPropertyName = #getIsolateTag("dispatch_record");
62 } 56 }
63 }(); 57 }();
64 ''', 58 ''',
65 {'initializeDispatchProperty': backend.needToInitializeDispatchProperty, 59 {'initializeDispatchProperty': backend.needToInitializeDispatchProperty,
66 'convertToFastObject': convertToFastObject, 60 'internStringFunction': internStringFunction,
67 'getIsolateTag': getIsolateTagAccess, 61 'getIsolateTag': getIsolateTagAccess,
68 'isolateTag': isolateTagAccess, 62 'isolateTag': isolateTagAccess,
69 'dispatchPropertyName': dispatchPropertyNameAccess}); 63 'dispatchPropertyName': dispatchPropertyNameAccess});
70 } 64 }
71 65
72 static String generateIsolateTagRoot() { 66 static String generateIsolateTagRoot() {
73 // TODO(sra): MD5 of contributing source code or URIs? 67 // TODO(sra): MD5 of contributing source code or URIs?
74 return 'ZxYxX'; 68 return 'ZxYxX';
75 } 69 }
76 70
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 198 }
205 ''', {'info': infoAccess, 199 ''', {'info': infoAccess,
206 'constructor': constructorAccess, 200 'constructor': constructorAccess,
207 'subclassRead': subclassRead, 201 'subclassRead': subclassRead,
208 'interceptorsByTagAccess': interceptorsByTagAccess, 202 'interceptorsByTagAccess': interceptorsByTagAccess,
209 'leafTagsAccess': leafTagsAccess, 203 'leafTagsAccess': leafTagsAccess,
210 'nativeSuperclassTagName': embeddedNames.NATIVE_SUPERCLASS_TAG_NAME, 204 'nativeSuperclassTagName': embeddedNames.NATIVE_SUPERCLASS_TAG_NAME,
211 'allowNativesSubclassing': true}); 205 'allowNativesSubclassing': true});
212 } 206 }
213 } 207 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698