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

Side by Side Diff: runtime/bin/gen_snapshot.cc

Issue 1663963002: - reorganize DartUtils::PrepareForScriptLoading so that it does not have the wait for service load … (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: code-review-comments Created 4 years, 10 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
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | runtime/bin/isolate_data.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // Generate a snapshot file after loading all the scripts specified on the 5 // Generate a snapshot file after loading all the scripts specified on the
6 // command line. 6 // command line.
7 7
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 249
250 static Dart_Handle ResolveUriInWorkingDirectory(const char* script_uri) { 250 static Dart_Handle ResolveUriInWorkingDirectory(const char* script_uri) {
251 bool failed = false; 251 bool failed = false;
252 char* result_string = NULL; 252 char* result_string = NULL;
253 253
254 { 254 {
255 UriResolverIsolateScope scope; 255 UriResolverIsolateScope scope;
256 256
257 // Run DartUtils::ResolveUriInWorkingDirectory in context of uri resolver 257 // Run DartUtils::ResolveUriInWorkingDirectory in context of uri resolver
258 // isolate. 258 // isolate.
259 Dart_Handle builtin_lib =
260 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
261 CHECK_RESULT(builtin_lib);
262
263 Dart_Handle result = DartUtils::ResolveUriInWorkingDirectory( 259 Dart_Handle result = DartUtils::ResolveUriInWorkingDirectory(
264 DartUtils::NewString(script_uri), builtin_lib); 260 DartUtils::NewString(script_uri));
265 if (Dart_IsError(result)) { 261 if (Dart_IsError(result)) {
266 failed = true; 262 failed = true;
267 result_string = strdup(Dart_GetError(result)); 263 result_string = strdup(Dart_GetError(result));
268 } else { 264 } else {
269 result_string = strdup(DartUtils::GetStringValue(result)); 265 result_string = strdup(DartUtils::GetStringValue(result));
270 } 266 }
271 } 267 }
272 268
273 Dart_Handle result = failed ? Dart_NewApiError(result_string) : 269 Dart_Handle result = failed ? Dart_NewApiError(result_string) :
274 DartUtils::NewString(result_string); 270 DartUtils::NewString(result_string);
275 free(result_string); 271 free(result_string);
276 return result; 272 return result;
277 } 273 }
278 274
279 275
280 static Dart_Handle FilePathFromUri(const char* script_uri) { 276 static Dart_Handle FilePathFromUri(const char* script_uri) {
281 bool failed = false; 277 bool failed = false;
282 char* result_string = NULL; 278 char* result_string = NULL;
283 279
284 { 280 {
285 UriResolverIsolateScope scope; 281 UriResolverIsolateScope scope;
286 282
287 // Run DartUtils::FilePathFromUri in context of uri resolver isolate. 283 // Run DartUtils::FilePathFromUri in context of uri resolver isolate.
288 Dart_Handle builtin_lib =
289 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
290 CHECK_RESULT(builtin_lib);
291
292 Dart_Handle result = DartUtils::FilePathFromUri( 284 Dart_Handle result = DartUtils::FilePathFromUri(
293 DartUtils::NewString(script_uri), builtin_lib); 285 DartUtils::NewString(script_uri));
294 if (Dart_IsError(result)) { 286 if (Dart_IsError(result)) {
295 failed = true; 287 failed = true;
296 result_string = strdup(Dart_GetError(result)); 288 result_string = strdup(Dart_GetError(result));
297 } else { 289 } else {
298 result_string = strdup(DartUtils::GetStringValue(result)); 290 result_string = strdup(DartUtils::GetStringValue(result));
299 } 291 }
300 } 292 }
301 293
302 Dart_Handle result = failed ? Dart_NewApiError(result_string) : 294 Dart_Handle result = failed ? Dart_NewApiError(result_string) :
303 DartUtils::NewString(result_string); 295 DartUtils::NewString(result_string);
304 free(result_string); 296 free(result_string);
305 return result; 297 return result;
306 } 298 }
307 299
308 300
309 static Dart_Handle ResolveUri(const char* library_uri, const char* uri) { 301 static Dart_Handle ResolveUri(const char* library_uri, const char* uri) {
310 bool failed = false; 302 bool failed = false;
311 char* result_string = NULL; 303 char* result_string = NULL;
312 304
313 { 305 {
314 UriResolverIsolateScope scope; 306 UriResolverIsolateScope scope;
315 307
316 // Run DartUtils::ResolveUri in context of uri resolver isolate. 308 // Run DartUtils::ResolveUri in context of uri resolver isolate.
317 Dart_Handle builtin_lib =
318 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
319 CHECK_RESULT(builtin_lib);
320
321 Dart_Handle result = DartUtils::ResolveUri( 309 Dart_Handle result = DartUtils::ResolveUri(
322 DartUtils::NewString(library_uri), 310 DartUtils::NewString(library_uri), DartUtils::NewString(uri));
323 DartUtils::NewString(uri),
324 builtin_lib);
325 if (Dart_IsError(result)) { 311 if (Dart_IsError(result)) {
326 failed = true; 312 failed = true;
327 result_string = strdup(Dart_GetError(result)); 313 result_string = strdup(Dart_GetError(result));
328 } else { 314 } else {
329 result_string = strdup(DartUtils::GetStringValue(result)); 315 result_string = strdup(DartUtils::GetStringValue(result));
330 } 316 }
331 } 317 }
332 318
333 Dart_Handle result = failed ? Dart_NewApiError(result_string) : 319 Dart_Handle result = failed ? Dart_NewApiError(result_string) :
334 DartUtils::NewString(result_string); 320 DartUtils::NewString(result_string);
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 } 938 }
953 939
954 940
955 static Dart_Isolate CreateServiceIsolate(const char* script_uri, 941 static Dart_Isolate CreateServiceIsolate(const char* script_uri,
956 const char* main, 942 const char* main,
957 const char* package_root, 943 const char* package_root,
958 const char* package_config, 944 const char* package_config,
959 Dart_IsolateFlags* flags, 945 Dart_IsolateFlags* flags,
960 void* data, 946 void* data,
961 char** error) { 947 char** error) {
948 IsolateData* isolate_data = new IsolateData(script_uri,
949 package_root,
950 package_config);
962 Dart_Isolate isolate = NULL; 951 Dart_Isolate isolate = NULL;
963 isolate = Dart_CreateIsolate(script_uri, 952 isolate = Dart_CreateIsolate(script_uri,
964 main, 953 main,
965 NULL, 954 NULL,
966 NULL, 955 NULL,
967 NULL, 956 isolate_data,
968 error); 957 error);
969 958
970 if (isolate == NULL) { 959 if (isolate == NULL) {
971 Log::PrintErr("Error: Could not create service isolate"); 960 Log::PrintErr("Error: Could not create service isolate");
972 return NULL; 961 return NULL;
973 } 962 }
974 963
975 Dart_EnterScope(); 964 Dart_EnterScope();
976 if (!Dart_IsServiceIsolate(isolate)) { 965 if (!Dart_IsServiceIsolate(isolate)) {
977 Log::PrintErr("Error: We only expect to create the service isolate"); 966 Log::PrintErr("Error: We only expect to create the service isolate");
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 DartUtils::WriteFile, 1037 DartUtils::WriteFile,
1049 DartUtils::CloseFile, 1038 DartUtils::CloseFile,
1050 DartUtils::EntropySource, 1039 DartUtils::EntropySource,
1051 NULL); 1040 NULL);
1052 if (error != NULL) { 1041 if (error != NULL) {
1053 Log::PrintErr("VM initialization failed: %s\n", error); 1042 Log::PrintErr("VM initialization failed: %s\n", error);
1054 free(error); 1043 free(error);
1055 return 255; 1044 return 255;
1056 } 1045 }
1057 1046
1047 IsolateData* isolate_data = new IsolateData(NULL, NULL, NULL);
1058 Dart_Isolate isolate = Dart_CreateIsolate( 1048 Dart_Isolate isolate = Dart_CreateIsolate(
1059 NULL, NULL, NULL, NULL, NULL, &error); 1049 NULL, NULL, NULL, NULL, isolate_data, &error);
1060 if (isolate == NULL) { 1050 if (isolate == NULL) {
1061 Log::PrintErr("Error: %s", error); 1051 Log::PrintErr("Error: %s", error);
1062 free(error); 1052 free(error);
1063 exit(255); 1053 exit(255);
1064 } 1054 }
1065 1055
1066 Dart_Handle result; 1056 Dart_Handle result;
1067 Dart_Handle library; 1057 Dart_Handle library;
1068 Dart_EnterScope(); 1058 Dart_EnterScope();
1069 1059
1070 ASSERT(vm_isolate_snapshot_filename != NULL); 1060 ASSERT(vm_isolate_snapshot_filename != NULL);
1071 ASSERT(isolate_snapshot_filename != NULL); 1061 ASSERT(isolate_snapshot_filename != NULL);
1072 // Load up the script before a snapshot is created. 1062 // Load up the script before a snapshot is created.
1073 if (app_script_name != NULL) { 1063 if (app_script_name != NULL) {
1074 // This is the case of a custom embedder (e.g: dartium) trying to 1064 // This is the case of a custom embedder (e.g: dartium) trying to
1075 // create a full snapshot. The current isolate is set up so that we can 1065 // create a full snapshot. The current isolate is set up so that we can
1076 // invoke the dart uri resolution code like _resolveURI. App script is 1066 // invoke the dart uri resolution code like _resolveURI. App script is
1077 // loaded into a separate isolate. 1067 // loaded into a separate isolate.
1078 1068
1079 SetupForUriResolution(); 1069 SetupForUriResolution();
1080 1070
1081 // Get handle to builtin library. 1071 // Prepare builtin and its dependent libraries for use to resolve URIs.
1082 Dart_Handle builtin_lib = 1072 // Set up various closures, e.g: printing, timers etc.
1083 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); 1073 // Set up 'package root' for URI resolution.
1084 CHECK_RESULT(builtin_lib); 1074 result = DartUtils::PrepareForScriptLoading(false, false);
1085
1086 // Ensure that we mark all libraries as loaded.
1087 result = Dart_FinalizeLoading(false);
1088 CHECK_RESULT(result); 1075 CHECK_RESULT(result);
1089 1076
1090 // Prepare for script loading by setting up the 'print' and 'timer' 1077 // Set up the load port provided by the service isolate so that we can
1091 // closures and setting up 'package root' for URI resolution. 1078 // load scripts.
1092 result = 1079 result = DartUtils::SetupServiceLoadPort();
1093 DartUtils::PrepareForScriptLoading(package_root,
1094 NULL,
1095 false,
1096 false,
1097 builtin_lib);
1098 CHECK_RESULT(result); 1080 CHECK_RESULT(result);
1081
1082 // Setup package root if specified.
1083 result = DartUtils::SetupPackageRoot(package_root, NULL);
1084 CHECK_RESULT(result);
1085
1099 Dart_ExitScope(); 1086 Dart_ExitScope();
1100 Dart_ExitIsolate(); 1087 Dart_ExitIsolate();
1101 1088
1102 UriResolverIsolateScope::isolate = isolate; 1089 UriResolverIsolateScope::isolate = isolate;
1103 1090
1104 // Now we create an isolate into which we load all the code that needs to 1091 // Now we create an isolate into which we load all the code that needs to
1105 // be in the snapshot. 1092 // be in the snapshot.
1106 if (Dart_CreateIsolate(NULL, NULL, NULL, NULL, NULL, &error) == NULL) { 1093 isolate_data = new IsolateData(NULL, NULL, NULL);
1094 if (Dart_CreateIsolate(
1095 NULL, NULL, NULL, NULL, isolate_data, &error) == NULL) {
1107 fprintf(stderr, "%s", error); 1096 fprintf(stderr, "%s", error);
1108 free(error); 1097 free(error);
1109 exit(255); 1098 exit(255);
1110 } 1099 }
1111 Dart_EnterScope(); 1100 Dart_EnterScope();
1112 1101
1113 // Set up the library tag handler in such a manner that it will use the 1102 // Set up the library tag handler in such a manner that it will use the
1114 // URL mapping specified on the command line to load the libraries. 1103 // URL mapping specified on the command line to load the libraries.
1115 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); 1104 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler);
1116 CHECK_RESULT(result); 1105 CHECK_RESULT(result);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 EventHandler::Stop(); 1137 EventHandler::Stop();
1149 return 0; 1138 return 0;
1150 } 1139 }
1151 1140
1152 } // namespace bin 1141 } // namespace bin
1153 } // namespace dart 1142 } // namespace dart
1154 1143
1155 int main(int argc, char** argv) { 1144 int main(int argc, char** argv) {
1156 return dart::bin::main(argc, argv); 1145 return dart::bin::main(argc, argv);
1157 } 1146 }
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | runtime/bin/isolate_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698