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

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
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 DartUtils::WriteFile, 1040 DartUtils::WriteFile,
1052 DartUtils::CloseFile, 1041 DartUtils::CloseFile,
1053 DartUtils::EntropySource, 1042 DartUtils::EntropySource,
1054 NULL); 1043 NULL);
1055 if (error != NULL) { 1044 if (error != NULL) {
1056 Log::PrintErr("VM initialization failed: %s\n", error); 1045 Log::PrintErr("VM initialization failed: %s\n", error);
1057 free(error); 1046 free(error);
1058 return 255; 1047 return 255;
1059 } 1048 }
1060 1049
1050 IsolateData* isolate_data = new IsolateData(NULL, NULL, NULL);
1061 Dart_Isolate isolate = Dart_CreateIsolate( 1051 Dart_Isolate isolate = Dart_CreateIsolate(
1062 NULL, NULL, NULL, NULL, NULL, &error); 1052 NULL, NULL, NULL, NULL, isolate_data, &error);
1063 if (isolate == NULL) { 1053 if (isolate == NULL) {
1064 Log::PrintErr("Error: %s", error); 1054 Log::PrintErr("Error: %s", error);
1065 free(error); 1055 free(error);
1066 exit(255); 1056 exit(255);
1067 } 1057 }
1068 1058
1069 Dart_Handle result; 1059 Dart_Handle result;
1070 Dart_Handle library; 1060 Dart_Handle library;
1071 Dart_EnterScope(); 1061 Dart_EnterScope();
1072 1062
1073 ASSERT(vm_isolate_snapshot_filename != NULL); 1063 ASSERT(vm_isolate_snapshot_filename != NULL);
1074 ASSERT(isolate_snapshot_filename != NULL); 1064 ASSERT(isolate_snapshot_filename != NULL);
1075 // Load up the script before a snapshot is created. 1065 // Load up the script before a snapshot is created.
1076 if (app_script_name != NULL) { 1066 if (app_script_name != NULL) {
1077 // This is the case of a custom embedder (e.g: dartium) trying to 1067 // This is the case of a custom embedder (e.g: dartium) trying to
1078 // create a full snapshot. The current isolate is set up so that we can 1068 // create a full snapshot. The current isolate is set up so that we can
1079 // invoke the dart uri resolution code like _resolveURI. App script is 1069 // invoke the dart uri resolution code like _resolveURI. App script is
1080 // loaded into a separate isolate. 1070 // loaded into a separate isolate.
1081 1071
1082 SetupForUriResolution(); 1072 SetupForUriResolution();
1083 1073
1084 // Get handle to builtin library. 1074 // Prepare builtin and its dependent libraries for use to resolve URIs.
1085 Dart_Handle builtin_lib = 1075 // Set up various closures, e.g: printing, timers etc.
1086 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); 1076 // Set up 'package root' for URI resolution.
1087 CHECK_RESULT(builtin_lib); 1077 result = DartUtils::PrepareForScriptLoading(false, false);
1088
1089 // Ensure that we mark all libraries as loaded.
1090 result = Dart_FinalizeLoading(false);
1091 CHECK_RESULT(result); 1078 CHECK_RESULT(result);
1092 1079
1093 // Prepare for script loading by setting up the 'print' and 'timer' 1080 // Set up the load port provided by the service isolate so that we can
1094 // closures and setting up 'package root' for URI resolution. 1081 // load scripts.
1095 result = 1082 result = DartUtils::SetupServiceLoadPort();
1096 DartUtils::PrepareForScriptLoading(package_root,
1097 NULL,
1098 false,
1099 false,
1100 builtin_lib);
1101 CHECK_RESULT(result); 1083 CHECK_RESULT(result);
1084
1085 // Setup package root if specified.
1086 result = DartUtils::SetupPackageRoot(package_root, NULL);
1087 CHECK_RESULT(result);
1088
1102 Dart_ExitScope(); 1089 Dart_ExitScope();
1103 Dart_ExitIsolate(); 1090 Dart_ExitIsolate();
1104 1091
1105 UriResolverIsolateScope::isolate = isolate; 1092 UriResolverIsolateScope::isolate = isolate;
1106 1093
1107 // Now we create an isolate into which we load all the code that needs to 1094 // Now we create an isolate into which we load all the code that needs to
1108 // be in the snapshot. 1095 // be in the snapshot.
1109 if (Dart_CreateIsolate(NULL, NULL, NULL, NULL, NULL, &error) == NULL) { 1096 isolate_data = new IsolateData(NULL, NULL, NULL);
1097 if (Dart_CreateIsolate(
1098 NULL, NULL, NULL, NULL, isolate_data, &error) == NULL) {
1110 fprintf(stderr, "%s", error); 1099 fprintf(stderr, "%s", error);
1111 free(error); 1100 free(error);
1112 exit(255); 1101 exit(255);
1113 } 1102 }
1114 Dart_EnterScope(); 1103 Dart_EnterScope();
1115 1104
1116 // Set up the library tag handler in such a manner that it will use the 1105 // Set up the library tag handler in such a manner that it will use the
1117 // URL mapping specified on the command line to load the libraries. 1106 // URL mapping specified on the command line to load the libraries.
1118 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); 1107 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler);
1119 CHECK_RESULT(result); 1108 CHECK_RESULT(result);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 EventHandler::Stop(); 1140 EventHandler::Stop();
1152 return 0; 1141 return 0;
1153 } 1142 }
1154 1143
1155 } // namespace bin 1144 } // namespace bin
1156 } // namespace dart 1145 } // namespace dart
1157 1146
1158 int main(int argc, char** argv) { 1147 int main(int argc, char** argv) {
1159 return dart::bin::main(argc, argv); 1148 return dart::bin::main(argc, argv);
1160 } 1149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698