| OLD | NEW |
| 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 <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 if (name_len == 0) { | 133 if (name_len == 0) { |
| 134 Log::PrintErr("No name given to -D option\n"); | 134 Log::PrintErr("No name given to -D option\n"); |
| 135 return false; | 135 return false; |
| 136 } | 136 } |
| 137 // Split name=value into name and value. | 137 // Split name=value into name and value. |
| 138 name = reinterpret_cast<char*>(malloc(name_len + 1)); | 138 name = reinterpret_cast<char*>(malloc(name_len + 1)); |
| 139 strncpy(name, arg, name_len); | 139 strncpy(name, arg, name_len); |
| 140 name[name_len] = '\0'; | 140 name[name_len] = '\0'; |
| 141 value = strdup(equals_pos + 1); | 141 value = strdup(equals_pos + 1); |
| 142 } | 142 } |
| 143 HashMap::Entry* entry = environment->Lookup( | 143 HashMap::Entry* entry = environment->Lookup(GetHashmapKeyFromString(name), |
| 144 GetHashmapKeyFromString(name), HashMap::StringHash(name), true); | 144 HashMap::StringHash(name), true); |
| 145 ASSERT(entry != NULL); // Lookup adds an entry if key not found. | 145 ASSERT(entry != NULL); // Lookup adds an entry if key not found. |
| 146 entry->value = value; | 146 entry->value = value; |
| 147 return true; | 147 return true; |
| 148 } | 148 } |
| 149 | 149 |
| 150 | 150 |
| 151 static Dart_Handle EnvironmentCallback(Dart_Handle name) { | 151 static Dart_Handle EnvironmentCallback(Dart_Handle name) { |
| 152 uint8_t* utf8_array; | 152 uint8_t* utf8_array; |
| 153 intptr_t utf8_len; | 153 intptr_t utf8_len; |
| 154 Dart_Handle result = Dart_Null(); | 154 Dart_Handle result = Dart_Null(); |
| 155 Dart_Handle handle = Dart_StringToUTF8(name, &utf8_array, &utf8_len); | 155 Dart_Handle handle = Dart_StringToUTF8(name, &utf8_array, &utf8_len); |
| 156 if (Dart_IsError(handle)) { | 156 if (Dart_IsError(handle)) { |
| 157 handle = Dart_ThrowException( | 157 handle = Dart_ThrowException( |
| 158 DartUtils::NewDartArgumentError(Dart_GetError(handle))); | 158 DartUtils::NewDartArgumentError(Dart_GetError(handle))); |
| 159 } else { | 159 } else { |
| 160 char* name_chars = reinterpret_cast<char*>(malloc(utf8_len + 1)); | 160 char* name_chars = reinterpret_cast<char*>(malloc(utf8_len + 1)); |
| 161 memmove(name_chars, utf8_array, utf8_len); | 161 memmove(name_chars, utf8_array, utf8_len); |
| 162 name_chars[utf8_len] = '\0'; | 162 name_chars[utf8_len] = '\0'; |
| 163 const char* value = NULL; | 163 const char* value = NULL; |
| 164 if (environment != NULL) { | 164 if (environment != NULL) { |
| 165 HashMap::Entry* entry = environment->Lookup( | 165 HashMap::Entry* entry = |
| 166 GetHashmapKeyFromString(name_chars), | 166 environment->Lookup(GetHashmapKeyFromString(name_chars), |
| 167 HashMap::StringHash(name_chars), | 167 HashMap::StringHash(name_chars), false); |
| 168 false); | |
| 169 if (entry != NULL) { | 168 if (entry != NULL) { |
| 170 value = reinterpret_cast<char*>(entry->value); | 169 value = reinterpret_cast<char*>(entry->value); |
| 171 } | 170 } |
| 172 } | 171 } |
| 173 if (value != NULL) { | 172 if (value != NULL) { |
| 174 result = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(value), | 173 result = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(value), |
| 175 strlen(value)); | 174 strlen(value)); |
| 176 } | 175 } |
| 177 free(name_chars); | 176 free(name_chars); |
| 178 } | 177 } |
| 179 return result; | 178 return result; |
| 180 } | 179 } |
| 181 | 180 |
| 182 | 181 |
| 183 | |
| 184 static const char* ProcessOption(const char* option, const char* name) { | 182 static const char* ProcessOption(const char* option, const char* name) { |
| 185 const intptr_t length = strlen(name); | 183 const intptr_t length = strlen(name); |
| 186 if (strncmp(option, name, length) == 0) { | 184 if (strncmp(option, name, length) == 0) { |
| 187 return (option + length); | 185 return (option + length); |
| 188 } | 186 } |
| 189 return NULL; | 187 return NULL; |
| 190 } | 188 } |
| 191 | 189 |
| 192 | 190 |
| 193 static bool ProcessVmIsolateSnapshotOption(const char* option) { | 191 static bool ProcessVmIsolateSnapshotOption(const char* option) { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 int i = 1; | 302 int i = 1; |
| 305 | 303 |
| 306 // Parse out the vm options. | 304 // Parse out the vm options. |
| 307 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) { | 305 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) { |
| 308 if (ProcessVmIsolateSnapshotOption(argv[i]) || | 306 if (ProcessVmIsolateSnapshotOption(argv[i]) || |
| 309 ProcessIsolateSnapshotOption(argv[i]) || | 307 ProcessIsolateSnapshotOption(argv[i]) || |
| 310 ProcessAssemblyOption(argv[i]) || | 308 ProcessAssemblyOption(argv[i]) || |
| 311 ProcessInstructionsBlobOption(argv[i]) || | 309 ProcessInstructionsBlobOption(argv[i]) || |
| 312 ProcessRodataBlobOption(argv[i]) || | 310 ProcessRodataBlobOption(argv[i]) || |
| 313 ProcessEmbedderEntryPointsManifestOption(argv[i]) || | 311 ProcessEmbedderEntryPointsManifestOption(argv[i]) || |
| 314 ProcessURLmappingOption(argv[i]) || | 312 ProcessURLmappingOption(argv[i]) || ProcessPackageRootOption(argv[i]) || |
| 315 ProcessPackageRootOption(argv[i]) || | 313 ProcessPackagesOption(argv[i]) || ProcessEnvironmentOption(argv[i])) { |
| 316 ProcessPackagesOption(argv[i]) || | |
| 317 ProcessEnvironmentOption(argv[i])) { | |
| 318 i += 1; | 314 i += 1; |
| 319 continue; | 315 continue; |
| 320 } | 316 } |
| 321 vm_options->AddArgument(argv[i]); | 317 vm_options->AddArgument(argv[i]); |
| 322 i += 1; | 318 i += 1; |
| 323 } | 319 } |
| 324 | 320 |
| 325 // Get the script name. | 321 // Get the script name. |
| 326 if (i < argc) { | 322 if (i < argc) { |
| 327 *script_name = argv[i]; | 323 *script_name = argv[i]; |
| 328 i += 1; | 324 i += 1; |
| 329 } else { | 325 } else { |
| 330 *script_name = NULL; | 326 *script_name = NULL; |
| 331 } | 327 } |
| 332 | 328 |
| 333 // Verify consistency of arguments. | 329 // Verify consistency of arguments. |
| 334 if ((commandline_package_root != NULL) && | 330 if ((commandline_package_root != NULL) && |
| 335 (commandline_packages_file != NULL)) { | 331 (commandline_packages_file != NULL)) { |
| 336 Log::PrintErr("Specifying both a packages directory and a packages " | 332 Log::PrintErr( |
| 337 "file is invalid.\n"); | 333 "Specifying both a packages directory and a packages " |
| 334 "file is invalid.\n"); |
| 338 return -1; | 335 return -1; |
| 339 } | 336 } |
| 340 | 337 |
| 341 if (vm_isolate_snapshot_filename == NULL) { | 338 if (vm_isolate_snapshot_filename == NULL) { |
| 342 Log::PrintErr("No vm isolate snapshot output file specified.\n\n"); | 339 Log::PrintErr("No vm isolate snapshot output file specified.\n\n"); |
| 343 return -1; | 340 return -1; |
| 344 } | 341 } |
| 345 | 342 |
| 346 if (isolate_snapshot_filename == NULL) { | 343 if (isolate_snapshot_filename == NULL) { |
| 347 Log::PrintErr("No isolate snapshot output file specified.\n\n"); | 344 Log::PrintErr("No isolate snapshot output file specified.\n\n"); |
| 348 return -1; | 345 return -1; |
| 349 } | 346 } |
| 350 | 347 |
| 351 bool precompiled_as_assembly = assembly_filename != NULL; | 348 bool precompiled_as_assembly = assembly_filename != NULL; |
| 352 bool precompiled_as_blobs = (instructions_blob_filename != NULL) || | 349 bool precompiled_as_blobs = |
| 353 (rodata_blob_filename != NULL); | 350 (instructions_blob_filename != NULL) || (rodata_blob_filename != NULL); |
| 354 if (precompiled_as_assembly && precompiled_as_blobs) { | 351 if (precompiled_as_assembly && precompiled_as_blobs) { |
| 355 Log::PrintErr( | 352 Log::PrintErr( |
| 356 "Cannot request a precompiled snapshot simultaneously as " | 353 "Cannot request a precompiled snapshot simultaneously as " |
| 357 "assembly (--assembly=<output.file>) and as blobs " | 354 "assembly (--assembly=<output.file>) and as blobs " |
| 358 "(--instructions-blob=<output.file> and " | 355 "(--instructions-blob=<output.file> and " |
| 359 "--rodata-blob=<output.file>)\n\n"); | 356 "--rodata-blob=<output.file>)\n\n"); |
| 360 return -1; | 357 return -1; |
| 361 } | 358 } |
| 362 if ((instructions_blob_filename != NULL) != (rodata_blob_filename != NULL)) { | 359 if ((instructions_blob_filename != NULL) != (rodata_blob_filename != NULL)) { |
| 363 Log::PrintErr( | 360 Log::PrintErr( |
| 364 "Requesting a precompiled snapshot as blobs requires both " | 361 "Requesting a precompiled snapshot as blobs requires both " |
| 365 "(--instructions-blob=<output.file> and " | 362 "(--instructions-blob=<output.file> and " |
| 366 "--rodata-blob=<output.file>)\n\n"); | 363 "--rodata-blob=<output.file>)\n\n"); |
| 367 return -1; | 364 return -1; |
| 368 } | 365 } |
| 369 if (IsSnapshottingForPrecompilation() && | 366 if (IsSnapshottingForPrecompilation() && (entry_points_files->count() == 0)) { |
| 370 (entry_points_files->count() == 0)) { | |
| 371 Log::PrintErr( | 367 Log::PrintErr( |
| 372 "Specifying an instructions snapshot filename indicates precompilation" | 368 "Specifying an instructions snapshot filename indicates precompilation" |
| 373 ". But no embedder entry points manifest was specified.\n\n"); | 369 ". But no embedder entry points manifest was specified.\n\n"); |
| 374 return -1; | 370 return -1; |
| 375 } | 371 } |
| 376 | 372 |
| 377 return 0; | 373 return 0; |
| 378 } | 374 } |
| 379 | 375 |
| 380 | 376 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 static Dart_Handle LoadUrlContents(const char* uri_string) { | 423 static Dart_Handle LoadUrlContents(const char* uri_string) { |
| 428 bool failed = false; | 424 bool failed = false; |
| 429 char* result_string = NULL; | 425 char* result_string = NULL; |
| 430 uint8_t* payload = NULL; | 426 uint8_t* payload = NULL; |
| 431 intptr_t payload_length = 0; | 427 intptr_t payload_length = 0; |
| 432 // Switch to the UriResolver Isolate and load the script. | 428 // Switch to the UriResolver Isolate and load the script. |
| 433 { | 429 { |
| 434 UriResolverIsolateScope scope; | 430 UriResolverIsolateScope scope; |
| 435 | 431 |
| 436 Dart_Handle resolved_uri = Dart_NewStringFromCString(uri_string); | 432 Dart_Handle resolved_uri = Dart_NewStringFromCString(uri_string); |
| 437 Dart_Handle result = Loader::LoadUrlContents(resolved_uri, | 433 Dart_Handle result = |
| 438 &payload, | 434 Loader::LoadUrlContents(resolved_uri, &payload, &payload_length); |
| 439 &payload_length); | |
| 440 if (Dart_IsError(result)) { | 435 if (Dart_IsError(result)) { |
| 441 failed = true; | 436 failed = true; |
| 442 result_string = strdup(Dart_GetError(result)); | 437 result_string = strdup(Dart_GetError(result)); |
| 443 } | 438 } |
| 444 } | 439 } |
| 445 // Switch back to the isolate from which we generate the snapshot and | 440 // Switch back to the isolate from which we generate the snapshot and |
| 446 // create the source string for the specified uri. | 441 // create the source string for the specified uri. |
| 447 Dart_Handle result; | 442 Dart_Handle result; |
| 448 if (!failed) { | 443 if (!failed) { |
| 449 result = Dart_NewStringFromUTF8(payload, payload_length); | 444 result = Dart_NewStringFromUTF8(payload, payload_length); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 468 Dart_Handle result = DartUtils::ResolveUriInWorkingDirectory( | 463 Dart_Handle result = DartUtils::ResolveUriInWorkingDirectory( |
| 469 DartUtils::NewString(script_uri)); | 464 DartUtils::NewString(script_uri)); |
| 470 if (Dart_IsError(result)) { | 465 if (Dart_IsError(result)) { |
| 471 failed = true; | 466 failed = true; |
| 472 result_string = strdup(Dart_GetError(result)); | 467 result_string = strdup(Dart_GetError(result)); |
| 473 } else { | 468 } else { |
| 474 result_string = strdup(DartUtils::GetStringValue(result)); | 469 result_string = strdup(DartUtils::GetStringValue(result)); |
| 475 } | 470 } |
| 476 } | 471 } |
| 477 | 472 |
| 478 Dart_Handle result = failed ? Dart_NewApiError(result_string) : | 473 Dart_Handle result = failed ? Dart_NewApiError(result_string) |
| 479 DartUtils::NewString(result_string); | 474 : DartUtils::NewString(result_string); |
| 480 free(result_string); | 475 free(result_string); |
| 481 return result; | 476 return result; |
| 482 } | 477 } |
| 483 | 478 |
| 484 | 479 |
| 485 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) { | 480 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) { |
| 486 // First resolve the specified script uri with respect to the original | 481 // First resolve the specified script uri with respect to the original |
| 487 // working directory. | 482 // working directory. |
| 488 Dart_Handle resolved_uri = ResolveUriInWorkingDirectory(script_name); | 483 Dart_Handle resolved_uri = ResolveUriInWorkingDirectory(script_name); |
| 489 if (Dart_IsError(resolved_uri)) { | 484 if (Dart_IsError(resolved_uri)) { |
| 490 return resolved_uri; | 485 return resolved_uri; |
| 491 } | 486 } |
| 492 // Now load the contents of the specified uri. | 487 // Now load the contents of the specified uri. |
| 493 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_uri); | 488 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_uri); |
| 494 Dart_Handle source = LoadUrlContents(resolved_uri_string); | 489 Dart_Handle source = LoadUrlContents(resolved_uri_string); |
| 495 | 490 |
| 496 if (Dart_IsError(source)) { | 491 if (Dart_IsError(source)) { |
| 497 return source; | 492 return source; |
| 498 } | 493 } |
| 499 if (IsSnapshottingForPrecompilation()) { | 494 if (IsSnapshottingForPrecompilation()) { |
| 500 return Dart_LoadScript(resolved_uri, Dart_Null(), source, 0, 0); | 495 return Dart_LoadScript(resolved_uri, Dart_Null(), source, 0, 0); |
| 501 } else { | 496 } else { |
| 502 return Dart_LoadLibrary(resolved_uri, Dart_Null(), source, 0, 0); | 497 return Dart_LoadLibrary(resolved_uri, Dart_Null(), source, 0, 0); |
| 503 } | 498 } |
| 504 } | 499 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 519 Dart_Handle library, | 514 Dart_Handle library, |
| 520 Dart_Handle url) { | 515 Dart_Handle url) { |
| 521 if (!Dart_IsLibrary(library)) { | 516 if (!Dart_IsLibrary(library)) { |
| 522 return Dart_NewApiError("not a library"); | 517 return Dart_NewApiError("not a library"); |
| 523 } | 518 } |
| 524 Dart_Handle library_url = Dart_LibraryUrl(library); | 519 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 525 if (Dart_IsError(library_url)) { | 520 if (Dart_IsError(library_url)) { |
| 526 return Dart_NewApiError("accessing library url failed"); | 521 return Dart_NewApiError("accessing library url failed"); |
| 527 } | 522 } |
| 528 const char* library_url_string = DartUtils::GetStringValue(library_url); | 523 const char* library_url_string = DartUtils::GetStringValue(library_url); |
| 529 const char* mapped_library_url_string = DartUtils::MapLibraryUrl( | 524 const char* mapped_library_url_string = |
| 530 library_url_string); | 525 DartUtils::MapLibraryUrl(library_url_string); |
| 531 if (mapped_library_url_string != NULL) { | 526 if (mapped_library_url_string != NULL) { |
| 532 library_url = ResolveUriInWorkingDirectory(mapped_library_url_string); | 527 library_url = ResolveUriInWorkingDirectory(mapped_library_url_string); |
| 533 library_url_string = DartUtils::GetStringValue(library_url); | 528 library_url_string = DartUtils::GetStringValue(library_url); |
| 534 } | 529 } |
| 535 | 530 |
| 536 if (!Dart_IsString(url)) { | 531 if (!Dart_IsString(url)) { |
| 537 return Dart_NewApiError("url is not a string"); | 532 return Dart_NewApiError("url is not a string"); |
| 538 } | 533 } |
| 539 const char* url_string = DartUtils::GetStringValue(url); | 534 const char* url_string = DartUtils::GetStringValue(url); |
| 540 const char* mapped_url_string = DartUtils::MapLibraryUrl(url_string); | 535 const char* mapped_url_string = DartUtils::MapLibraryUrl(url_string); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 558 return Builtin::LoadLibrary(url, builtinId); | 553 return Builtin::LoadLibrary(url, builtinId); |
| 559 } | 554 } |
| 560 ASSERT(tag == Dart_kSourceTag); | 555 ASSERT(tag == Dart_kSourceTag); |
| 561 return DartUtils::NewError("Unable to part '%s' ", url_string); | 556 return DartUtils::NewError("Unable to part '%s' ", url_string); |
| 562 } | 557 } |
| 563 | 558 |
| 564 if (libraryBuiltinId != Builtin::kInvalidLibrary) { | 559 if (libraryBuiltinId != Builtin::kInvalidLibrary) { |
| 565 // Special case for parting sources of a builtin library. | 560 // Special case for parting sources of a builtin library. |
| 566 if (tag == Dart_kSourceTag) { | 561 if (tag == Dart_kSourceTag) { |
| 567 return Dart_LoadSource(library, url, Dart_Null(), | 562 return Dart_LoadSource(library, url, Dart_Null(), |
| 568 Builtin::PartSource(libraryBuiltinId, url_string), 0, 0); | 563 Builtin::PartSource(libraryBuiltinId, url_string), |
| 564 0, 0); |
| 569 } | 565 } |
| 570 ASSERT(tag == Dart_kImportTag); | 566 ASSERT(tag == Dart_kImportTag); |
| 571 return DartUtils::NewError("Unable to import '%s' ", url_string); | 567 return DartUtils::NewError("Unable to import '%s' ", url_string); |
| 572 } | 568 } |
| 573 | 569 |
| 574 Dart_Handle resolved_url = url; | 570 Dart_Handle resolved_url = url; |
| 575 if (mapped_url_string != NULL) { | 571 if (mapped_url_string != NULL) { |
| 576 // Mapped urls are relative to working directory. | 572 // Mapped urls are relative to working directory. |
| 577 resolved_url = ResolveUriInWorkingDirectory(mapped_url_string); | 573 resolved_url = ResolveUriInWorkingDirectory(mapped_url_string); |
| 578 if (Dart_IsError(resolved_url)) { | 574 if (Dart_IsError(resolved_url)) { |
| 579 return resolved_url; | 575 return resolved_url; |
| 580 } | 576 } |
| 581 } | 577 } |
| 582 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_url); | 578 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_url); |
| 583 Dart_Handle source = LoadUrlContents(resolved_uri_string); | 579 Dart_Handle source = LoadUrlContents(resolved_uri_string); |
| 584 if (Dart_IsError(source)) { | 580 if (Dart_IsError(source)) { |
| 585 return source; | 581 return source; |
| 586 } | 582 } |
| 587 if (tag == Dart_kImportTag) { | 583 if (tag == Dart_kImportTag) { |
| 588 return Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 584 return Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
| 589 } else { | 585 } else { |
| 590 ASSERT(tag == Dart_kSourceTag); | 586 ASSERT(tag == Dart_kSourceTag); |
| 591 return Dart_LoadSource(library, url, Dart_Null(), source, 0, 0); | 587 return Dart_LoadSource(library, url, Dart_Null(), source, 0, 0); |
| 592 } | 588 } |
| 593 } | 589 } |
| 594 | 590 |
| 595 | 591 |
| 596 static Dart_Handle LoadGenericSnapshotCreationScript( | 592 static Dart_Handle LoadGenericSnapshotCreationScript( |
| 597 Builtin::BuiltinLibraryId id) { | 593 Builtin::BuiltinLibraryId id) { |
| 598 Dart_Handle source = Builtin::Source(id); | 594 Dart_Handle source = Builtin::Source(id); |
| 599 if (Dart_IsError(source)) { | 595 if (Dart_IsError(source)) { |
| 600 return source; // source contains the error string. | 596 return source; // source contains the error string. |
| 601 } | 597 } |
| 602 Dart_Handle lib; | 598 Dart_Handle lib; |
| 603 // Load the builtin library to make it available in the snapshot | 599 // Load the builtin library to make it available in the snapshot |
| 604 // for importing. | 600 // for importing. |
| 605 lib = Builtin::LoadAndCheckLibrary(id); | 601 lib = Builtin::LoadAndCheckLibrary(id); |
| 606 ASSERT(!Dart_IsError(lib)); | 602 ASSERT(!Dart_IsError(lib)); |
| 607 return lib; | 603 return lib; |
| 608 } | 604 } |
| 609 | 605 |
| 610 | 606 |
| 607 // clang-format off |
| 611 static void PrintUsage() { | 608 static void PrintUsage() { |
| 612 Log::PrintErr( | 609 Log::PrintErr( |
| 613 "Usage: \n" | 610 "Usage: \n" |
| 614 " gen_snapshot [<vm-flags>] [<options>] [<dart-script-file>] \n" | 611 " gen_snapshot [<vm-flags>] [<options>] [<dart-script-file>] \n" |
| 615 " \n" | 612 " \n" |
| 616 " Writes a snapshot of <dart-script-file> to the specified snapshot files. \n" | 613 " Writes a snapshot of <dart-script-file> to the specified snapshot files. \n" |
| 617 " If no <dart-script-file> is passed, a generic snapshot of all the corelibs\n" | 614 " If no <dart-script-file> is passed, a generic snapshot of all the corelibs\n" |
| 618 " is created. It is required to specify the VM isolate snapshot and the \n" | 615 " is created. It is required to specify the VM isolate snapshot and the \n" |
| 619 " isolate snapshot. The other flags are related to precompilation and are \n" | 616 " isolate snapshot. The other flags are related to precompilation and are \n" |
| 620 " optional. \n" | 617 " optional. \n" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 " \n" | 659 " \n" |
| 663 " --instructions_blob=<file> (Precompilation only) Contains the \n" | 660 " --instructions_blob=<file> (Precompilation only) Contains the \n" |
| 664 " --rodata_blob=<file> instructions and read-only data that \n" | 661 " --rodata_blob=<file> instructions and read-only data that \n" |
| 665 " must be mapped into the target binary \n" | 662 " must be mapped into the target binary \n" |
| 666 " \n" | 663 " \n" |
| 667 " --embedder_entry_points_manifest=<file> (Precompilation or app \n" | 664 " --embedder_entry_points_manifest=<file> (Precompilation or app \n" |
| 668 " snapshots) Contains embedder's entry \n" | 665 " snapshots) Contains embedder's entry \n" |
| 669 " points into Dart code from the C API. \n" | 666 " points into Dart code from the C API. \n" |
| 670 "\n"); | 667 "\n"); |
| 671 } | 668 } |
| 669 // clang-format on |
| 672 | 670 |
| 673 | 671 |
| 674 static void VerifyLoaded(Dart_Handle library) { | 672 static void VerifyLoaded(Dart_Handle library) { |
| 675 if (Dart_IsError(library)) { | 673 if (Dart_IsError(library)) { |
| 676 const char* err_msg = Dart_GetError(library); | 674 const char* err_msg = Dart_GetError(library); |
| 677 Log::PrintErr("Errors encountered while loading: %s\n", err_msg); | 675 Log::PrintErr("Errors encountered while loading: %s\n", err_msg); |
| 678 CHECK_RESULT(library); | 676 CHECK_RESULT(library); |
| 679 } | 677 } |
| 680 ASSERT(Dart_IsLibrary(library)); | 678 ASSERT(Dart_IsLibrary(library)); |
| 681 } | 679 } |
| 682 | 680 |
| 683 | 681 |
| 684 static const char StubNativeFunctionName[] = "StubNativeFunction"; | 682 static const char StubNativeFunctionName[] = "StubNativeFunction"; |
| 685 | 683 |
| 686 | 684 |
| 687 void StubNativeFunction(Dart_NativeArguments arguments) { | 685 void StubNativeFunction(Dart_NativeArguments arguments) { |
| 688 // This is a stub function for the resolver | 686 // This is a stub function for the resolver |
| 689 UNREACHABLE(); | 687 UNREACHABLE(); |
| 690 } | 688 } |
| 691 | 689 |
| 692 | 690 |
| 693 static Dart_NativeFunction StubNativeLookup(Dart_Handle name, | 691 static Dart_NativeFunction StubNativeLookup(Dart_Handle name, |
| 694 int argument_count, | 692 int argument_count, |
| 695 bool* auto_setup_scope) { | 693 bool* auto_setup_scope) { |
| 696 return &StubNativeFunction; | 694 return &StubNativeFunction; |
| 697 } | 695 } |
| 698 | 696 |
| 699 | 697 |
| 700 static const uint8_t* StubNativeSymbol(Dart_NativeFunction nf) { | 698 static const uint8_t* StubNativeSymbol(Dart_NativeFunction nf) { |
| 701 return reinterpret_cast<const uint8_t *>(StubNativeFunctionName); | 699 return reinterpret_cast<const uint8_t*>(StubNativeFunctionName); |
| 702 } | 700 } |
| 703 | 701 |
| 704 | 702 |
| 705 static void SetupStubNativeResolver(size_t lib_index, | 703 static void SetupStubNativeResolver(size_t lib_index, |
| 706 const Dart_QualifiedFunctionName* entry) { | 704 const Dart_QualifiedFunctionName* entry) { |
| 707 // TODO(24686): Remove this. | 705 // TODO(24686): Remove this. |
| 708 Dart_Handle library_string = Dart_NewStringFromCString(entry->library_uri); | 706 Dart_Handle library_string = Dart_NewStringFromCString(entry->library_uri); |
| 709 DART_CHECK_VALID(library_string); | 707 DART_CHECK_VALID(library_string); |
| 710 Dart_Handle library = Dart_LookupLibrary(library_string); | 708 Dart_Handle library = Dart_LookupLibrary(library_string); |
| 711 // Embedder entry points may be setup in libraries that have not been | 709 // Embedder entry points may be setup in libraries that have not been |
| 712 // explicitly loaded by the application script. In such cases, library lookup | 710 // explicitly loaded by the application script. In such cases, library lookup |
| 713 // will fail. Manually load those libraries. | 711 // will fail. Manually load those libraries. |
| 714 if (Dart_IsError(library)) { | 712 if (Dart_IsError(library)) { |
| 715 static const uint32_t kLoadBufferMaxSize = 128; | 713 static const uint32_t kLoadBufferMaxSize = 128; |
| 716 char* load_buffer = | 714 char* load_buffer = |
| 717 reinterpret_cast<char*>(calloc(kLoadBufferMaxSize, sizeof(char))); | 715 reinterpret_cast<char*>(calloc(kLoadBufferMaxSize, sizeof(char))); |
| 718 snprintf(load_buffer, | 716 snprintf(load_buffer, kLoadBufferMaxSize, "import '%s';", |
| 719 kLoadBufferMaxSize, | |
| 720 "import '%s';", | |
| 721 DartUtils::GetStringValue(library_string)); | 717 DartUtils::GetStringValue(library_string)); |
| 722 Dart_Handle script_handle = Dart_NewStringFromCString(load_buffer); | 718 Dart_Handle script_handle = Dart_NewStringFromCString(load_buffer); |
| 723 memset(load_buffer, 0, kLoadBufferMaxSize); | 719 memset(load_buffer, 0, kLoadBufferMaxSize); |
| 724 snprintf(load_buffer, | 720 snprintf(load_buffer, kLoadBufferMaxSize, "dart:_snapshot_%zu", lib_index); |
| 725 kLoadBufferMaxSize, | |
| 726 "dart:_snapshot_%zu", | |
| 727 lib_index); | |
| 728 Dart_Handle script_url = Dart_NewStringFromCString(load_buffer); | 721 Dart_Handle script_url = Dart_NewStringFromCString(load_buffer); |
| 729 free(load_buffer); | 722 free(load_buffer); |
| 730 Dart_Handle loaded = Dart_LoadLibrary(script_url, Dart_Null(), | 723 Dart_Handle loaded = |
| 731 script_handle, 0, 0); | 724 Dart_LoadLibrary(script_url, Dart_Null(), script_handle, 0, 0); |
| 732 DART_CHECK_VALID(loaded); | 725 DART_CHECK_VALID(loaded); |
| 733 | 726 |
| 734 // Do a fresh lookup | 727 // Do a fresh lookup |
| 735 library = Dart_LookupLibrary(library_string); | 728 library = Dart_LookupLibrary(library_string); |
| 736 } | 729 } |
| 737 | 730 |
| 738 DART_CHECK_VALID(library); | 731 DART_CHECK_VALID(library); |
| 739 Dart_Handle result = Dart_SetNativeResolver(library, | 732 Dart_Handle result = |
| 740 &StubNativeLookup, | 733 Dart_SetNativeResolver(library, &StubNativeLookup, &StubNativeSymbol); |
| 741 &StubNativeSymbol); | |
| 742 DART_CHECK_VALID(result); | 734 DART_CHECK_VALID(result); |
| 743 } | 735 } |
| 744 | 736 |
| 745 | 737 |
| 746 static void ImportNativeEntryPointLibrariesIntoRoot( | 738 static void ImportNativeEntryPointLibrariesIntoRoot( |
| 747 const Dart_QualifiedFunctionName* entries) { | 739 const Dart_QualifiedFunctionName* entries) { |
| 748 if (entries == NULL) { | 740 if (entries == NULL) { |
| 749 return; | 741 return; |
| 750 } | 742 } |
| 751 | 743 |
| 752 size_t index = 0; | 744 size_t index = 0; |
| 753 while (true) { | 745 while (true) { |
| 754 Dart_QualifiedFunctionName entry = entries[index++]; | 746 Dart_QualifiedFunctionName entry = entries[index++]; |
| 755 if (entry.library_uri == NULL) { | 747 if (entry.library_uri == NULL) { |
| 756 // The termination sentinel has null members. | 748 // The termination sentinel has null members. |
| 757 break; | 749 break; |
| 758 } | 750 } |
| 759 Dart_Handle entry_library = | 751 Dart_Handle entry_library = |
| 760 Dart_LookupLibrary(Dart_NewStringFromCString(entry.library_uri)); | 752 Dart_LookupLibrary(Dart_NewStringFromCString(entry.library_uri)); |
| 761 DART_CHECK_VALID(entry_library); | 753 DART_CHECK_VALID(entry_library); |
| 762 Dart_Handle import_result = Dart_LibraryImportLibrary( | 754 Dart_Handle import_result = Dart_LibraryImportLibrary( |
| 763 entry_library, Dart_RootLibrary(), Dart_EmptyString()); | 755 entry_library, Dart_RootLibrary(), Dart_EmptyString()); |
| 764 DART_CHECK_VALID(import_result); | 756 DART_CHECK_VALID(import_result); |
| 765 } | 757 } |
| 766 } | 758 } |
| 767 | 759 |
| 768 | 760 |
| 769 static void SetupStubNativeResolversForPrecompilation( | 761 static void SetupStubNativeResolversForPrecompilation( |
| 770 const Dart_QualifiedFunctionName* entries) { | 762 const Dart_QualifiedFunctionName* entries) { |
| 771 | |
| 772 if (entries == NULL) { | 763 if (entries == NULL) { |
| 773 return; | 764 return; |
| 774 } | 765 } |
| 775 | 766 |
| 776 // Setup native resolvers for all libraries found in the manifest. | 767 // Setup native resolvers for all libraries found in the manifest. |
| 777 size_t index = 0; | 768 size_t index = 0; |
| 778 while (true) { | 769 while (true) { |
| 779 Dart_QualifiedFunctionName entry = entries[index++]; | 770 Dart_QualifiedFunctionName entry = entries[index++]; |
| 780 if (entry.library_uri == NULL) { | 771 if (entry.library_uri == NULL) { |
| 781 // The termination sentinel has null members. | 772 // The termination sentinel has null members. |
| 782 break; | 773 break; |
| 783 } | 774 } |
| 784 // Setup stub resolvers on loaded libraries | 775 // Setup stub resolvers on loaded libraries |
| 785 SetupStubNativeResolver(index, &entry); | 776 SetupStubNativeResolver(index, &entry); |
| 786 } | 777 } |
| 787 } | 778 } |
| 788 | 779 |
| 789 | 780 |
| 790 static void CleanupEntryPointItem(const Dart_QualifiedFunctionName *entry) { | 781 static void CleanupEntryPointItem(const Dart_QualifiedFunctionName* entry) { |
| 791 if (entry == NULL) { | 782 if (entry == NULL) { |
| 792 return; | 783 return; |
| 793 } | 784 } |
| 794 // The allocation used for these entries is zero'ed. So even in error cases, | 785 // The allocation used for these entries is zero'ed. So even in error cases, |
| 795 // references to some entries will be null. Calling this on an already cleaned | 786 // references to some entries will be null. Calling this on an already cleaned |
| 796 // up entry is programmer error. | 787 // up entry is programmer error. |
| 797 free(const_cast<char*>(entry->library_uri)); | 788 free(const_cast<char*>(entry->library_uri)); |
| 798 free(const_cast<char*>(entry->class_name)); | 789 free(const_cast<char*>(entry->class_name)); |
| 799 free(const_cast<char*>(entry->function_name)); | 790 free(const_cast<char*>(entry->function_name)); |
| 800 } | 791 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 case 2: | 832 case 2: |
| 842 return "Function"; | 833 return "Function"; |
| 843 default: | 834 default: |
| 844 return "Unknown"; | 835 return "Unknown"; |
| 845 } | 836 } |
| 846 return NULL; | 837 return NULL; |
| 847 } | 838 } |
| 848 | 839 |
| 849 | 840 |
| 850 static bool ParseEntryPointsManifestSingleLine( | 841 static bool ParseEntryPointsManifestSingleLine( |
| 851 const char* line, Dart_QualifiedFunctionName* entry, char** error) { | 842 const char* line, |
| 843 Dart_QualifiedFunctionName* entry, |
| 844 char** error) { |
| 852 bool success = true; | 845 bool success = true; |
| 853 size_t offset = 0; | 846 size_t offset = 0; |
| 854 for (uint8_t i = 0; i < 3; i++) { | 847 for (uint8_t i = 0; i < 3; i++) { |
| 855 const char* component = strchr(line + offset, i == 2 ? '\n' : ','); | 848 const char* component = strchr(line + offset, i == 2 ? '\n' : ','); |
| 856 if (component == NULL) { | 849 if (component == NULL) { |
| 857 success = false; | 850 success = false; |
| 858 *error = ParserErrorStringCreate( | 851 *error = ParserErrorStringCreate( |
| 859 "Manifest entries must be comma separated and newline terminated. " | 852 "Manifest entries must be comma separated and newline terminated. " |
| 860 "Could not parse '%s' on line '%s'", | 853 "Could not parse '%s' on line '%s'", |
| 861 ParseEntryNameForIndex(i), line); | 854 ParseEntryNameForIndex(i), line); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 | 1003 |
| 1011 static void CreateAndWriteSnapshot() { | 1004 static void CreateAndWriteSnapshot() { |
| 1012 ASSERT(!IsSnapshottingForPrecompilation()); | 1005 ASSERT(!IsSnapshottingForPrecompilation()); |
| 1013 Dart_Handle result; | 1006 Dart_Handle result; |
| 1014 uint8_t* vm_isolate_buffer = NULL; | 1007 uint8_t* vm_isolate_buffer = NULL; |
| 1015 intptr_t vm_isolate_size = 0; | 1008 intptr_t vm_isolate_size = 0; |
| 1016 uint8_t* isolate_buffer = NULL; | 1009 uint8_t* isolate_buffer = NULL; |
| 1017 intptr_t isolate_size = 0; | 1010 intptr_t isolate_size = 0; |
| 1018 | 1011 |
| 1019 // First create a snapshot. | 1012 // First create a snapshot. |
| 1020 result = Dart_CreateSnapshot(&vm_isolate_buffer, | 1013 result = Dart_CreateSnapshot(&vm_isolate_buffer, &vm_isolate_size, |
| 1021 &vm_isolate_size, | 1014 &isolate_buffer, &isolate_size); |
| 1022 &isolate_buffer, | |
| 1023 &isolate_size); | |
| 1024 CHECK_RESULT(result); | 1015 CHECK_RESULT(result); |
| 1025 | 1016 |
| 1026 // Now write the vm isolate and isolate snapshots out to the | 1017 // Now write the vm isolate and isolate snapshots out to the |
| 1027 // specified file and exit. | 1018 // specified file and exit. |
| 1028 WriteSnapshotFile(vm_isolate_snapshot_filename, | 1019 WriteSnapshotFile(vm_isolate_snapshot_filename, vm_isolate_buffer, |
| 1029 vm_isolate_buffer, | |
| 1030 vm_isolate_size); | 1020 vm_isolate_size); |
| 1031 WriteSnapshotFile(isolate_snapshot_filename, | 1021 WriteSnapshotFile(isolate_snapshot_filename, isolate_buffer, isolate_size); |
| 1032 isolate_buffer, | |
| 1033 isolate_size); | |
| 1034 Dart_ExitScope(); | 1022 Dart_ExitScope(); |
| 1035 | 1023 |
| 1036 // Shutdown the isolate. | 1024 // Shutdown the isolate. |
| 1037 Dart_ShutdownIsolate(); | 1025 Dart_ShutdownIsolate(); |
| 1038 } | 1026 } |
| 1039 | 1027 |
| 1040 | 1028 |
| 1041 static void CreateAndWritePrecompiledSnapshot( | 1029 static void CreateAndWritePrecompiledSnapshot( |
| 1042 Dart_QualifiedFunctionName* standalone_entry_points) { | 1030 Dart_QualifiedFunctionName* standalone_entry_points) { |
| 1043 ASSERT(IsSnapshottingForPrecompilation()); | 1031 ASSERT(IsSnapshottingForPrecompilation()); |
| 1044 Dart_Handle result; | 1032 Dart_Handle result; |
| 1045 | 1033 |
| 1046 // Precompile with specified embedder entry points | 1034 // Precompile with specified embedder entry points |
| 1047 result = Dart_Precompile(standalone_entry_points, true); | 1035 result = Dart_Precompile(standalone_entry_points, true); |
| 1048 CHECK_RESULT(result); | 1036 CHECK_RESULT(result); |
| 1049 | 1037 |
| 1050 // Create a precompiled snapshot. | 1038 // Create a precompiled snapshot. |
| 1051 bool as_assembly = assembly_filename != NULL; | 1039 bool as_assembly = assembly_filename != NULL; |
| 1052 if (as_assembly) { | 1040 if (as_assembly) { |
| 1053 uint8_t* assembly_buffer = NULL; | 1041 uint8_t* assembly_buffer = NULL; |
| 1054 intptr_t assembly_size = 0; | 1042 intptr_t assembly_size = 0; |
| 1055 result = Dart_CreatePrecompiledSnapshotAssembly(&assembly_buffer, | 1043 result = Dart_CreatePrecompiledSnapshotAssembly(&assembly_buffer, |
| 1056 &assembly_size); | 1044 &assembly_size); |
| 1057 CHECK_RESULT(result); | 1045 CHECK_RESULT(result); |
| 1058 WriteSnapshotFile(assembly_filename, | 1046 WriteSnapshotFile(assembly_filename, assembly_buffer, assembly_size); |
| 1059 assembly_buffer, | |
| 1060 assembly_size); | |
| 1061 } else { | 1047 } else { |
| 1062 uint8_t* vm_isolate_buffer = NULL; | 1048 uint8_t* vm_isolate_buffer = NULL; |
| 1063 intptr_t vm_isolate_size = 0; | 1049 intptr_t vm_isolate_size = 0; |
| 1064 uint8_t* isolate_buffer = NULL; | 1050 uint8_t* isolate_buffer = NULL; |
| 1065 intptr_t isolate_size = 0; | 1051 intptr_t isolate_size = 0; |
| 1066 uint8_t* instructions_blob_buffer = NULL; | 1052 uint8_t* instructions_blob_buffer = NULL; |
| 1067 intptr_t instructions_blob_size = 0; | 1053 intptr_t instructions_blob_size = 0; |
| 1068 uint8_t* rodata_blob_buffer = NULL; | 1054 uint8_t* rodata_blob_buffer = NULL; |
| 1069 intptr_t rodata_blob_size = 0; | 1055 intptr_t rodata_blob_size = 0; |
| 1070 result = Dart_CreatePrecompiledSnapshotBlob(&vm_isolate_buffer, | 1056 result = Dart_CreatePrecompiledSnapshotBlob( |
| 1071 &vm_isolate_size, | 1057 &vm_isolate_buffer, &vm_isolate_size, &isolate_buffer, &isolate_size, |
| 1072 &isolate_buffer, | 1058 &instructions_blob_buffer, &instructions_blob_size, &rodata_blob_buffer, |
| 1073 &isolate_size, | 1059 &rodata_blob_size); |
| 1074 &instructions_blob_buffer, | |
| 1075 &instructions_blob_size, | |
| 1076 &rodata_blob_buffer, | |
| 1077 &rodata_blob_size); | |
| 1078 CHECK_RESULT(result); | 1060 CHECK_RESULT(result); |
| 1079 WriteSnapshotFile(vm_isolate_snapshot_filename, | 1061 WriteSnapshotFile(vm_isolate_snapshot_filename, vm_isolate_buffer, |
| 1080 vm_isolate_buffer, | |
| 1081 vm_isolate_size); | 1062 vm_isolate_size); |
| 1082 WriteSnapshotFile(isolate_snapshot_filename, | 1063 WriteSnapshotFile(isolate_snapshot_filename, isolate_buffer, isolate_size); |
| 1083 isolate_buffer, | 1064 WriteSnapshotFile(instructions_blob_filename, instructions_blob_buffer, |
| 1084 isolate_size); | |
| 1085 WriteSnapshotFile(instructions_blob_filename, | |
| 1086 instructions_blob_buffer, | |
| 1087 instructions_blob_size); | 1065 instructions_blob_size); |
| 1088 WriteSnapshotFile(rodata_blob_filename, | 1066 WriteSnapshotFile(rodata_blob_filename, rodata_blob_buffer, |
| 1089 rodata_blob_buffer, | |
| 1090 rodata_blob_size); | 1067 rodata_blob_size); |
| 1091 } | 1068 } |
| 1092 | 1069 |
| 1093 Dart_ExitScope(); | 1070 Dart_ExitScope(); |
| 1094 | 1071 |
| 1095 // Shutdown the isolate. | 1072 // Shutdown the isolate. |
| 1096 Dart_ShutdownIsolate(); | 1073 Dart_ShutdownIsolate(); |
| 1097 } | 1074 } |
| 1098 | 1075 |
| 1099 | 1076 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1129 } | 1106 } |
| 1130 | 1107 |
| 1131 | 1108 |
| 1132 static Dart_Isolate CreateServiceIsolate(const char* script_uri, | 1109 static Dart_Isolate CreateServiceIsolate(const char* script_uri, |
| 1133 const char* main, | 1110 const char* main, |
| 1134 const char* package_root, | 1111 const char* package_root, |
| 1135 const char* package_config, | 1112 const char* package_config, |
| 1136 Dart_IsolateFlags* flags, | 1113 Dart_IsolateFlags* flags, |
| 1137 void* data, | 1114 void* data, |
| 1138 char** error) { | 1115 char** error) { |
| 1139 IsolateData* isolate_data = new IsolateData(script_uri, | 1116 IsolateData* isolate_data = |
| 1140 package_root, | 1117 new IsolateData(script_uri, package_root, package_config); |
| 1141 package_config); | |
| 1142 Dart_Isolate isolate = NULL; | 1118 Dart_Isolate isolate = NULL; |
| 1143 isolate = Dart_CreateIsolate(script_uri, | 1119 isolate = |
| 1144 main, | 1120 Dart_CreateIsolate(script_uri, main, NULL, NULL, isolate_data, error); |
| 1145 NULL, | |
| 1146 NULL, | |
| 1147 isolate_data, | |
| 1148 error); | |
| 1149 | 1121 |
| 1150 if (isolate == NULL) { | 1122 if (isolate == NULL) { |
| 1151 Log::PrintErr("Error: Could not create service isolate"); | 1123 Log::PrintErr("Error: Could not create service isolate"); |
| 1152 return NULL; | 1124 return NULL; |
| 1153 } | 1125 } |
| 1154 | 1126 |
| 1155 Dart_EnterScope(); | 1127 Dart_EnterScope(); |
| 1156 if (!Dart_IsServiceIsolate(isolate)) { | 1128 if (!Dart_IsServiceIsolate(isolate)) { |
| 1157 Log::PrintErr("Error: We only expect to create the service isolate"); | 1129 Log::PrintErr("Error: We only expect to create the service isolate"); |
| 1158 return NULL; | 1130 return NULL; |
| 1159 } | 1131 } |
| 1160 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); | 1132 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); |
| 1161 // Setup the native resolver. | 1133 // Setup the native resolver. |
| 1162 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 1134 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 1163 Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 1135 Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
| 1164 if (Dart_IsError(result)) { | 1136 if (Dart_IsError(result)) { |
| 1165 Log::PrintErr("Error: Could not set tag handler for service isolate"); | 1137 Log::PrintErr("Error: Could not set tag handler for service isolate"); |
| 1166 return NULL; | 1138 return NULL; |
| 1167 } | 1139 } |
| 1168 CHECK_RESULT(result); | 1140 CHECK_RESULT(result); |
| 1169 ASSERT(Dart_IsServiceIsolate(isolate)); | 1141 ASSERT(Dart_IsServiceIsolate(isolate)); |
| 1170 // Load embedder specific bits and return. Will not start http server. | 1142 // Load embedder specific bits and return. Will not start http server. |
| 1171 if (!VmService::Setup("127.0.0.1", | 1143 if (!VmService::Setup("127.0.0.1", -1, false /* running_precompiled */, |
| 1172 -1, | |
| 1173 false /* running_precompiled */, | |
| 1174 false /* server dev mode */)) { | 1144 false /* server dev mode */)) { |
| 1175 *error = strdup(VmService::GetErrorMessage()); | 1145 *error = strdup(VmService::GetErrorMessage()); |
| 1176 return NULL; | 1146 return NULL; |
| 1177 } | 1147 } |
| 1178 Dart_ExitScope(); | 1148 Dart_ExitScope(); |
| 1179 Dart_ExitIsolate(); | 1149 Dart_ExitIsolate(); |
| 1180 return isolate; | 1150 return isolate; |
| 1181 } | 1151 } |
| 1182 | 1152 |
| 1183 | 1153 |
| 1184 int main(int argc, char** argv) { | 1154 int main(int argc, char** argv) { |
| 1185 const int EXTRA_VM_ARGUMENTS = 2; | 1155 const int EXTRA_VM_ARGUMENTS = 2; |
| 1186 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); | 1156 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); |
| 1187 | 1157 |
| 1188 // Initialize the URL mapping array. | 1158 // Initialize the URL mapping array. |
| 1189 CommandLineOptions cmdline_url_mapping(argc); | 1159 CommandLineOptions cmdline_url_mapping(argc); |
| 1190 DartUtils::url_mapping = &cmdline_url_mapping; | 1160 DartUtils::url_mapping = &cmdline_url_mapping; |
| 1191 | 1161 |
| 1192 // Initialize the entrypoints array. | 1162 // Initialize the entrypoints array. |
| 1193 CommandLineOptions entry_points_files_array(argc); | 1163 CommandLineOptions entry_points_files_array(argc); |
| 1194 entry_points_files = &entry_points_files_array; | 1164 entry_points_files = &entry_points_files_array; |
| 1195 | 1165 |
| 1196 // Parse command line arguments. | 1166 // Parse command line arguments. |
| 1197 if (ParseArguments(argc, | 1167 if (ParseArguments(argc, argv, &vm_options, &app_script_name) < 0) { |
| 1198 argv, | |
| 1199 &vm_options, | |
| 1200 &app_script_name) < 0) { | |
| 1201 PrintUsage(); | 1168 PrintUsage(); |
| 1202 return 255; | 1169 return 255; |
| 1203 } | 1170 } |
| 1204 | 1171 |
| 1205 Thread::InitOnce(); | 1172 Thread::InitOnce(); |
| 1206 Loader::InitOnce(); | 1173 Loader::InitOnce(); |
| 1207 DartUtils::SetOriginalWorkingDirectory(); | 1174 DartUtils::SetOriginalWorkingDirectory(); |
| 1208 // Start event handler. | 1175 // Start event handler. |
| 1209 TimerUtils::InitOnce(); | 1176 TimerUtils::InitOnce(); |
| 1210 EventHandler::Start(); | 1177 EventHandler::Start(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 init_params.file_close = DartUtils::CloseFile; | 1209 init_params.file_close = DartUtils::CloseFile; |
| 1243 init_params.entropy_source = DartUtils::EntropySource; | 1210 init_params.entropy_source = DartUtils::EntropySource; |
| 1244 | 1211 |
| 1245 char* error = Dart_Initialize(&init_params); | 1212 char* error = Dart_Initialize(&init_params); |
| 1246 if (error != NULL) { | 1213 if (error != NULL) { |
| 1247 Log::PrintErr("VM initialization failed: %s\n", error); | 1214 Log::PrintErr("VM initialization failed: %s\n", error); |
| 1248 free(error); | 1215 free(error); |
| 1249 return 255; | 1216 return 255; |
| 1250 } | 1217 } |
| 1251 | 1218 |
| 1252 IsolateData* isolate_data = new IsolateData(NULL, | 1219 IsolateData* isolate_data = new IsolateData(NULL, commandline_package_root, |
| 1253 commandline_package_root, | |
| 1254 commandline_packages_file); | 1220 commandline_packages_file); |
| 1255 Dart_Isolate isolate = Dart_CreateIsolate( | 1221 Dart_Isolate isolate = |
| 1256 NULL, NULL, NULL, NULL, isolate_data, &error); | 1222 Dart_CreateIsolate(NULL, NULL, NULL, NULL, isolate_data, &error); |
| 1257 if (isolate == NULL) { | 1223 if (isolate == NULL) { |
| 1258 Log::PrintErr("Error: %s", error); | 1224 Log::PrintErr("Error: %s", error); |
| 1259 free(error); | 1225 free(error); |
| 1260 exit(255); | 1226 exit(255); |
| 1261 } | 1227 } |
| 1262 | 1228 |
| 1263 Dart_Handle result; | 1229 Dart_Handle result; |
| 1264 Dart_Handle library; | 1230 Dart_Handle library; |
| 1265 Dart_EnterScope(); | 1231 Dart_EnterScope(); |
| 1266 | 1232 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1293 commandline_packages_file); | 1259 commandline_packages_file); |
| 1294 CHECK_RESULT(result); | 1260 CHECK_RESULT(result); |
| 1295 | 1261 |
| 1296 UriResolverIsolateScope::isolate = isolate; | 1262 UriResolverIsolateScope::isolate = isolate; |
| 1297 Dart_ExitScope(); | 1263 Dart_ExitScope(); |
| 1298 Dart_ExitIsolate(); | 1264 Dart_ExitIsolate(); |
| 1299 | 1265 |
| 1300 // Now we create an isolate into which we load all the code that needs to | 1266 // Now we create an isolate into which we load all the code that needs to |
| 1301 // be in the snapshot. | 1267 // be in the snapshot. |
| 1302 isolate_data = new IsolateData(NULL, NULL, NULL); | 1268 isolate_data = new IsolateData(NULL, NULL, NULL); |
| 1303 if (Dart_CreateIsolate( | 1269 if (Dart_CreateIsolate(NULL, NULL, NULL, NULL, isolate_data, &error) == |
| 1304 NULL, NULL, NULL, NULL, isolate_data, &error) == NULL) { | 1270 NULL) { |
| 1305 fprintf(stderr, "%s", error); | 1271 fprintf(stderr, "%s", error); |
| 1306 free(error); | 1272 free(error); |
| 1307 exit(255); | 1273 exit(255); |
| 1308 } | 1274 } |
| 1309 Dart_EnterScope(); | 1275 Dart_EnterScope(); |
| 1310 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 1276 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
| 1311 CHECK_RESULT(result); | 1277 CHECK_RESULT(result); |
| 1312 | 1278 |
| 1313 // Set up the library tag handler in such a manner that it will use the | 1279 // Set up the library tag handler in such a manner that it will use the |
| 1314 // URL mapping specified on the command line to load the libraries. | 1280 // URL mapping specified on the command line to load the libraries. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 EventHandler::Stop(); | 1336 EventHandler::Stop(); |
| 1371 return 0; | 1337 return 0; |
| 1372 } | 1338 } |
| 1373 | 1339 |
| 1374 } // namespace bin | 1340 } // namespace bin |
| 1375 } // namespace dart | 1341 } // namespace dart |
| 1376 | 1342 |
| 1377 int main(int argc, char** argv) { | 1343 int main(int argc, char** argv) { |
| 1378 return dart::bin::main(argc, argv); | 1344 return dart::bin::main(argc, argv); |
| 1379 } | 1345 } |
| OLD | NEW |