Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <string.h> | 6 #include <string.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
| 10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "bin/utils.h" | 27 #include "bin/utils.h" |
| 28 #include "bin/vmservice_impl.h" | 28 #include "bin/vmservice_impl.h" |
| 29 #include "platform/globals.h" | 29 #include "platform/globals.h" |
| 30 #include "platform/growable_array.h" | 30 #include "platform/growable_array.h" |
| 31 #include "platform/hashmap.h" | 31 #include "platform/hashmap.h" |
| 32 #include "platform/text_buffer.h" | 32 #include "platform/text_buffer.h" |
| 33 #if !defined(DART_PRECOMPILER) | 33 #if !defined(DART_PRECOMPILER) |
| 34 #include "zlib/zlib.h" | 34 #include "zlib/zlib.h" |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 #include "vm/kernel.h" | |
| 38 | |
| 37 namespace dart { | 39 namespace dart { |
| 38 namespace bin { | 40 namespace bin { |
| 39 | 41 |
| 40 // Snapshot pieces if we link in a snapshot, otherwise initialized to NULL. | 42 // Snapshot pieces if we link in a snapshot, otherwise initialized to NULL. |
| 41 extern const uint8_t* vm_snapshot_data; | 43 extern const uint8_t* vm_snapshot_data; |
| 42 extern const uint8_t* vm_snapshot_instructions; | 44 extern const uint8_t* vm_snapshot_instructions; |
| 43 extern const uint8_t* core_isolate_snapshot_data; | 45 extern const uint8_t* core_isolate_snapshot_data; |
| 44 extern const uint8_t* core_isolate_snapshot_instructions; | 46 extern const uint8_t* core_isolate_snapshot_instructions; |
| 45 | 47 |
| 46 /** | 48 /** |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 60 kAppAOT, | 62 kAppAOT, |
| 61 kAppJIT, | 63 kAppJIT, |
| 62 }; | 64 }; |
| 63 static SnapshotKind gen_snapshot_kind = kNone; | 65 static SnapshotKind gen_snapshot_kind = kNone; |
| 64 static const char* snapshot_deps_filename = NULL; | 66 static const char* snapshot_deps_filename = NULL; |
| 65 | 67 |
| 66 static bool use_dart_frontend = false; | 68 static bool use_dart_frontend = false; |
| 67 | 69 |
| 68 static const char* frontend_filename = NULL; | 70 static const char* frontend_filename = NULL; |
| 69 | 71 |
| 72 // True if the VM should boostrap the SDK from a binary (.dill) file. The | |
| 73 // filename points into an argv buffer and does not need to be freed. | |
| 74 static bool use_platform_binary = false; | |
| 75 static const char* platform_binary_filename = NULL; | |
| 76 | |
| 70 // Value of the --save-feedback flag. | 77 // Value of the --save-feedback flag. |
| 71 // (This pointer points into an argv buffer and does not need to be | 78 // (This pointer points into an argv buffer and does not need to be |
| 72 // free'd.) | 79 // free'd.) |
| 73 static const char* save_feedback_filename = NULL; | 80 static const char* save_feedback_filename = NULL; |
| 74 | 81 |
| 75 // Value of the --load-feedback flag. | 82 // Value of the --load-feedback flag. |
| 76 // (This pointer points into an argv buffer and does not need to be | 83 // (This pointer points into an argv buffer and does not need to be |
| 77 // free'd.) | 84 // free'd.) |
| 78 static const char* load_feedback_filename = NULL; | 85 static const char* load_feedback_filename = NULL; |
| 79 | 86 |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 if (filename[0] == '\0') { | 333 if (filename[0] == '\0') { |
| 327 return false; | 334 return false; |
| 328 } | 335 } |
| 329 use_dart_frontend = true; | 336 use_dart_frontend = true; |
| 330 frontend_filename = filename; | 337 frontend_filename = filename; |
| 331 vm_options->AddArgument("--use-dart-frontend"); | 338 vm_options->AddArgument("--use-dart-frontend"); |
| 332 return true; | 339 return true; |
| 333 } | 340 } |
| 334 | 341 |
| 335 | 342 |
| 343 static bool ProcessPlatformOption(const char* filename, | |
| 344 CommandLineOptions* vm_options) { | |
| 345 ASSERT(filename != NULL); | |
| 346 if (filename[0] == '\0') { | |
| 347 return false; | |
| 348 } | |
| 349 use_platform_binary = true; | |
|
Vyacheslav Egorov (Google)
2017/04/05 12:21:23
Should not this platform binary be also passed dow
Kevin Millikin (Google)
2017/04/25 18:20:29
Yes, let's add that in a separate change.
| |
| 350 platform_binary_filename = filename; | |
| 351 return true; | |
| 352 } | |
| 353 | |
| 354 | |
| 336 static bool ProcessUseBlobsOption(const char* arg, | 355 static bool ProcessUseBlobsOption(const char* arg, |
| 337 CommandLineOptions* vm_options) { | 356 CommandLineOptions* vm_options) { |
| 338 ASSERT(arg != NULL); | 357 ASSERT(arg != NULL); |
| 339 if (*arg != '\0') { | 358 if (*arg != '\0') { |
| 340 return false; | 359 return false; |
| 341 } | 360 } |
| 342 use_blobs = true; | 361 use_blobs = true; |
| 343 return true; | 362 return true; |
| 344 } | 363 } |
| 345 | 364 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 550 {"--packages=", ProcessPackagesOption}, | 569 {"--packages=", ProcessPackagesOption}, |
| 551 {"--package-root=", ProcessPackageRootOption}, | 570 {"--package-root=", ProcessPackageRootOption}, |
| 552 {"-v", ProcessVerboseOption}, | 571 {"-v", ProcessVerboseOption}, |
| 553 {"--verbose", ProcessVerboseOption}, | 572 {"--verbose", ProcessVerboseOption}, |
| 554 {"--version", ProcessVersionOption}, | 573 {"--version", ProcessVersionOption}, |
| 555 | 574 |
| 556 // VM specific options to the standalone dart program. | 575 // VM specific options to the standalone dart program. |
| 557 {"--compile_all", ProcessCompileAllOption}, | 576 {"--compile_all", ProcessCompileAllOption}, |
| 558 {"--parse_all", ProcessParseAllOption}, | 577 {"--parse_all", ProcessParseAllOption}, |
| 559 {"--dfe=", ProcessFrontendOption}, | 578 {"--dfe=", ProcessFrontendOption}, |
| 579 {"--platform=", ProcessPlatformOption}, | |
| 560 {"--enable-vm-service", ProcessEnableVmServiceOption}, | 580 {"--enable-vm-service", ProcessEnableVmServiceOption}, |
| 561 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, | 581 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, |
| 562 {"--observe", ProcessObserveOption}, | 582 {"--observe", ProcessObserveOption}, |
| 563 {"--snapshot=", ProcessSnapshotFilenameOption}, | 583 {"--snapshot=", ProcessSnapshotFilenameOption}, |
| 564 {"--snapshot-kind=", ProcessSnapshotKindOption}, | 584 {"--snapshot-kind=", ProcessSnapshotKindOption}, |
| 565 {"--snapshot-depfile=", ProcessSnapshotDepsFilenameOption}, | 585 {"--snapshot-depfile=", ProcessSnapshotDepsFilenameOption}, |
| 566 {"--use-blobs", ProcessUseBlobsOption}, | 586 {"--use-blobs", ProcessUseBlobsOption}, |
| 567 {"--save-feedback=", ProcessSaveFeedbackOption}, | 587 {"--save-feedback=", ProcessSaveFeedbackOption}, |
| 568 {"--load-feedback=", ProcessLoadFeedbackOption}, | 588 {"--load-feedback=", ProcessLoadFeedbackOption}, |
| 569 {"--trace-loading", ProcessTraceLoadingOption}, | 589 {"--trace-loading", ProcessTraceLoadingOption}, |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 846 isolate_run_app_snapshot = true; | 866 isolate_run_app_snapshot = true; |
| 847 const uint8_t* ignore_vm_snapshot_data; | 867 const uint8_t* ignore_vm_snapshot_data; |
| 848 const uint8_t* ignore_vm_snapshot_instructions; | 868 const uint8_t* ignore_vm_snapshot_instructions; |
| 849 app_snapshot->SetBuffers( | 869 app_snapshot->SetBuffers( |
| 850 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, | 870 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, |
| 851 &isolate_snapshot_data, &isolate_snapshot_instructions); | 871 &isolate_snapshot_data, &isolate_snapshot_instructions); |
| 852 } | 872 } |
| 853 } | 873 } |
| 854 #endif | 874 #endif |
| 855 | 875 |
| 856 const uint8_t* kernel_file = NULL; | 876 IsolateData* isolate_data = |
|
Vyacheslav Egorov (Google)
2017/04/05 12:21:23
Was there any reason to move isolate_data creation
Kevin Millikin (Google)
2017/04/25 18:20:29
I used it earlier in an intermediate state, but yo
| |
| 857 intptr_t kernel_length = -1; | 877 new IsolateData(script_uri, package_root, packages_config, app_snapshot); |
| 858 bool is_kernel = false; | 878 if (is_main_isolate && (snapshot_deps_filename != NULL)) { |
| 879 isolate_data->set_dependencies(new MallocGrowableArray<char*>()); | |
| 880 } | |
| 881 void* kernel_platform = NULL; | |
| 882 void* kernel_program = NULL; | |
| 883 if (!is_kernel_isolate && !is_service_isolate) { | |
| 884 if (use_platform_binary) { | |
| 885 const uint8_t* platform_file = NULL; | |
| 886 intptr_t platform_length = -1; | |
| 887 bool success = TryReadKernel(platform_binary_filename, &platform_file, | |
| 888 &platform_length); | |
| 889 if (!success) { | |
| 890 *error = strdup("The platform binary is not a valid Dart Kernel file."); | |
| 891 *exit_code = kErrorExitCode; | |
| 892 return NULL; | |
|
kustermann
2017/04/05 11:47:07
Maybe 'delete isolate_data' here.
Kevin Millikin (Google)
2017/04/25 18:20:29
Thank you. Well spotted.
| |
| 893 } | |
| 894 kernel_platform = Dart_ReadKernelBinary(platform_file, platform_length); | |
| 895 free(const_cast<uint8_t*>(platform_file)); | |
| 896 } | |
| 859 | 897 |
| 860 if (!is_kernel_isolate && !is_service_isolate) { | 898 bool is_kernel = false; |
| 899 const uint8_t* kernel_file = NULL; | |
| 900 intptr_t kernel_length = -1; | |
| 861 if (use_dart_frontend) { | 901 if (use_dart_frontend) { |
| 862 Dart_KernelCompilationResult result = Dart_CompileToKernel(script_uri); | 902 Dart_KernelCompilationResult result = Dart_CompileToKernel(script_uri); |
| 863 *error = result.error; // Copy error message (if any). | 903 *error = result.error; // Copy error message (if any). |
| 864 switch (result.status) { | 904 switch (result.status) { |
| 865 case Dart_KernelCompilationStatus_Ok: | 905 case Dart_KernelCompilationStatus_Ok: |
| 866 is_kernel = true; | 906 is_kernel = true; |
| 867 kernel_file = result.kernel; | 907 kernel_file = result.kernel; |
| 868 kernel_length = result.kernel_size; | 908 kernel_length = result.kernel_size; |
| 869 break; | 909 break; |
| 870 case Dart_KernelCompilationStatus_Error: | 910 case Dart_KernelCompilationStatus_Error: |
| 871 *exit_code = kCompilationErrorExitCode; | 911 *exit_code = kCompilationErrorExitCode; |
| 872 return NULL; | 912 return NULL; |
|
Vyacheslav Egorov (Google)
2017/04/05 12:21:23
This leaks isolate data and kernel_platform.
Kevin Millikin (Google)
2017/04/25 18:20:29
Thank you. Well spotted. I delete kernel_platfor
| |
| 873 case Dart_KernelCompilationStatus_Crash: | 913 case Dart_KernelCompilationStatus_Crash: |
| 874 *exit_code = kDartFrontendErrorExitCode; | 914 *exit_code = kDartFrontendErrorExitCode; |
| 875 return NULL; | 915 return NULL; |
| 876 case Dart_KernelCompilationStatus_Unknown: | 916 case Dart_KernelCompilationStatus_Unknown: |
| 877 *exit_code = kErrorExitCode; | 917 *exit_code = kErrorExitCode; |
| 878 return NULL; | 918 return NULL; |
| 879 } | 919 } |
| 880 } else if (!isolate_run_app_snapshot) { | 920 } else if (!isolate_run_app_snapshot) { |
| 881 is_kernel = TryReadKernel(script_uri, &kernel_file, &kernel_length); | 921 is_kernel = TryReadKernel(script_uri, &kernel_file, &kernel_length); |
| 882 } | 922 } |
| 923 | |
| 924 if (is_kernel) { | |
| 925 kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length); | |
| 926 free(const_cast<uint8_t*>(kernel_file)); | |
| 927 } | |
| 883 } | 928 } |
| 884 | 929 |
| 885 void* kernel_program = NULL; | |
| 886 if (is_kernel) { | |
| 887 kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length); | |
| 888 free(const_cast<uint8_t*>(kernel_file)); | |
| 889 } | |
| 890 | |
| 891 IsolateData* isolate_data = | |
| 892 new IsolateData(script_uri, package_root, packages_config, app_snapshot); | |
| 893 if (is_main_isolate && (snapshot_deps_filename != NULL)) { | |
| 894 isolate_data->set_dependencies(new MallocGrowableArray<char*>()); | |
| 895 } | |
| 896 // If the script is a Kernel binary, then we will try to bootstrap from the | |
| 897 // script. | |
| 898 Dart_Isolate isolate = | 930 Dart_Isolate isolate = |
| 899 is_kernel ? Dart_CreateIsolateFromKernel(script_uri, main, kernel_program, | 931 kernel_platform != NULL |
|
kustermann
2017/04/05 11:47:07
Consider adding another case for 'kernel_program !
Kevin Millikin (Google)
2017/04/25 18:20:29
Good suggestion, left for a separate change.
| |
| 900 flags, isolate_data, error) | 932 ? Dart_CreateIsolateFromKernel(script_uri, main, kernel_platform, |
| 901 : Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, | 933 flags, isolate_data, error) |
| 902 isolate_snapshot_instructions, flags, | 934 : Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, |
| 903 isolate_data, error); | 935 isolate_snapshot_instructions, flags, |
| 936 isolate_data, error); | |
| 904 if (isolate == NULL) { | 937 if (isolate == NULL) { |
| 905 delete isolate_data; | 938 delete isolate_data; |
| 906 return NULL; | 939 return NULL; |
| 907 } | 940 } |
| 908 | 941 |
| 909 Dart_EnterScope(); | 942 Dart_EnterScope(); |
| 910 | 943 |
| 911 // Set up the library tag handler for this isolate. | 944 // Set up the library tag handler for this isolate. |
| 912 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); | 945 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); |
| 913 CHECK_RESULT(result); | 946 CHECK_RESULT(result); |
| 914 | 947 |
| 915 if (is_kernel) { | 948 if (kernel_program != NULL) { |
| 916 Dart_Handle result = Dart_LoadKernel(kernel_program); | 949 Dart_Handle result = Dart_LoadKernel(kernel_program); |
| 917 CHECK_RESULT(result); | 950 CHECK_RESULT(result); |
| 918 } | 951 } |
| 919 if (is_kernel || (isolate_snapshot_data != NULL)) { | 952 if ((kernel_platform != NULL) || (isolate_snapshot_data != NULL)) { |
| 920 // Setup the native resolver as the snapshot does not carry it. | 953 // Setup the native resolver as the snapshot does not carry it. |
| 921 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 954 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
| 922 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 955 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
| 923 } | 956 } |
| 924 if (isolate_run_app_snapshot) { | 957 if (isolate_run_app_snapshot) { |
| 925 Dart_Handle result = Loader::ReloadNativeExtensions(); | 958 Dart_Handle result = Loader::ReloadNativeExtensions(); |
| 926 CHECK_RESULT(result); | 959 CHECK_RESULT(result); |
| 927 } | 960 } |
| 928 | 961 |
| 929 if (Dart_IsServiceIsolate(isolate)) { | 962 if (Dart_IsServiceIsolate(isolate)) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 979 CHECK_RESULT(result); | 1012 CHECK_RESULT(result); |
| 980 ASSERT(app_script_uri == NULL); | 1013 ASSERT(app_script_uri == NULL); |
| 981 app_script_uri = strdup(resolved_script_uri); | 1014 app_script_uri = strdup(resolved_script_uri); |
| 982 } | 1015 } |
| 983 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 1016 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| 984 } else { | 1017 } else { |
| 985 // Load the specified application script into the newly created isolate. | 1018 // Load the specified application script into the newly created isolate. |
| 986 Dart_Handle uri = | 1019 Dart_Handle uri = |
| 987 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)); | 1020 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)); |
| 988 CHECK_RESULT(uri); | 1021 CHECK_RESULT(uri); |
| 989 if (!is_kernel) { | 1022 if (kernel_platform == NULL) { |
| 990 result = Loader::LibraryTagHandler(Dart_kScriptTag, Dart_Null(), uri); | 1023 result = Loader::LibraryTagHandler(Dart_kScriptTag, Dart_Null(), uri); |
| 991 CHECK_RESULT(result); | 1024 CHECK_RESULT(result); |
| 992 } else { | 1025 } else { |
| 993 // Various core-library parts will send requests to the Loader to resolve | 1026 // Various core-library parts will send requests to the Loader to resolve |
| 994 // relative URIs and perform other related tasks. We need Loader to be | 1027 // relative URIs and perform other related tasks. We need Loader to be |
| 995 // initialized for this to work because loading from Kernel binary | 1028 // initialized for this to work because loading from Kernel binary |
| 996 // bypasses normal source code loading paths that initialize it. | 1029 // bypasses normal source code loading paths that initialize it. |
| 997 Loader::InitForSnapshot(script_uri); | 1030 Loader::InitForSnapshot(script_uri); |
| 998 } | 1031 } |
| 999 | 1032 |
| (...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1718 Platform::Exit(Process::GlobalExitCode()); | 1751 Platform::Exit(Process::GlobalExitCode()); |
| 1719 } | 1752 } |
| 1720 | 1753 |
| 1721 } // namespace bin | 1754 } // namespace bin |
| 1722 } // namespace dart | 1755 } // namespace dart |
| 1723 | 1756 |
| 1724 int main(int argc, char** argv) { | 1757 int main(int argc, char** argv) { |
| 1725 dart::bin::main(argc, argv); | 1758 dart::bin::main(argc, argv); |
| 1726 UNREACHABLE(); | 1759 UNREACHABLE(); |
| 1727 } | 1760 } |
| OLD | NEW |