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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 | 383 |
384 static bool ProcessPlatformOption(const char* filename, | 384 static bool ProcessPlatformOption(const char* filename, |
385 CommandLineOptions* vm_options) { | 385 CommandLineOptions* vm_options) { |
386 ASSERT(filename != NULL); | 386 ASSERT(filename != NULL); |
387 if (filename[0] == '\0') { | 387 if (filename[0] == '\0') { |
388 return false; | 388 return false; |
389 } | 389 } |
390 dfe.set_platform_binary_filename(filename); | 390 dfe.set_platform_binary_filename(filename); |
391 return true; | 391 return true; |
392 } | 392 } |
393 | |
394 static bool ProcessVmServiceIOOption(const char* filename, | |
395 CommandLineOptions* vm_options) { | |
396 ASSERT(filename != NULL); | |
397 if (filename[0] == '\0') { | |
398 return false; | |
399 } | |
400 dfe.set_vmservice_io_binary_filename(filename); | |
401 return true; | |
402 } | |
393 #endif | 403 #endif |
394 | 404 |
395 | 405 |
396 static bool ProcessUseBlobsOption(const char* arg, | 406 static bool ProcessUseBlobsOption(const char* arg, |
397 CommandLineOptions* vm_options) { | 407 CommandLineOptions* vm_options) { |
398 ASSERT(arg != NULL); | 408 ASSERT(arg != NULL); |
399 if (*arg != '\0') { | 409 if (*arg != '\0') { |
400 return false; | 410 return false; |
401 } | 411 } |
402 use_blobs = true; | 412 use_blobs = true; |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 {"-v", ProcessVerboseOption}, | 620 {"-v", ProcessVerboseOption}, |
611 {"--verbose", ProcessVerboseOption}, | 621 {"--verbose", ProcessVerboseOption}, |
612 {"--version", ProcessVersionOption}, | 622 {"--version", ProcessVersionOption}, |
613 | 623 |
614 // VM specific options to the standalone dart program. | 624 // VM specific options to the standalone dart program. |
615 {"--compile_all", ProcessCompileAllOption}, | 625 {"--compile_all", ProcessCompileAllOption}, |
616 {"--parse_all", ProcessParseAllOption}, | 626 {"--parse_all", ProcessParseAllOption}, |
617 #if !defined(DART_PRECOMPILED_RUNTIME) | 627 #if !defined(DART_PRECOMPILED_RUNTIME) |
618 {"--dfe=", ProcessFrontendOption}, | 628 {"--dfe=", ProcessFrontendOption}, |
619 {"--platform=", ProcessPlatformOption}, | 629 {"--platform=", ProcessPlatformOption}, |
630 {"--vmservice_io=", ProcessVmServiceIOOption}, | |
siva
2017/06/13 02:12:02
Can we derive the location of this file from the e
sivachandra
2017/06/14 19:25:57
I proposed a way to reduce the number of options h
| |
620 #endif | 631 #endif |
621 {"--enable-vm-service", ProcessEnableVmServiceOption}, | 632 {"--enable-vm-service", ProcessEnableVmServiceOption}, |
622 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, | 633 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, |
623 {"--observe", ProcessObserveOption}, | 634 {"--observe", ProcessObserveOption}, |
624 {"--snapshot=", ProcessSnapshotFilenameOption}, | 635 {"--snapshot=", ProcessSnapshotFilenameOption}, |
625 {"--snapshot-kind=", ProcessSnapshotKindOption}, | 636 {"--snapshot-kind=", ProcessSnapshotKindOption}, |
626 {"--snapshot-depfile=", ProcessSnapshotDepsFilenameOption}, | 637 {"--snapshot-depfile=", ProcessSnapshotDepsFilenameOption}, |
627 {"--use-blobs", ProcessUseBlobsOption}, | 638 {"--use-blobs", ProcessUseBlobsOption}, |
628 {"--save-compilation-trace=", ProcessSaveCompilationTraceOption}, | 639 {"--save-compilation-trace=", ProcessSaveCompilationTraceOption}, |
629 {"--load-compilation-trace=", ProcessLoadCompilationTraceOption}, | 640 {"--load-compilation-trace=", ProcessLoadCompilationTraceOption}, |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1021 const char* main, | 1032 const char* main, |
1022 const char* package_root, | 1033 const char* package_root, |
1023 const char* packages_config, | 1034 const char* packages_config, |
1024 Dart_IsolateFlags* flags, | 1035 Dart_IsolateFlags* flags, |
1025 char** error, | 1036 char** error, |
1026 int* exit_code) { | 1037 int* exit_code) { |
1027 ASSERT(script_uri != NULL); | 1038 ASSERT(script_uri != NULL); |
1028 | 1039 |
1029 #if defined(DART_PRECOMPILED_RUNTIME) | 1040 #if defined(DART_PRECOMPILED_RUNTIME) |
1030 // AOT: All isolates start from the app snapshot. | 1041 // AOT: All isolates start from the app snapshot. |
1031 bool isolate_run_app_snapshot = true; | 1042 bool skip_library_load = true; |
1032 const uint8_t* isolate_snapshot_data = app_isolate_snapshot_data; | 1043 const uint8_t* isolate_snapshot_data = app_isolate_snapshot_data; |
1033 const uint8_t* isolate_snapshot_instructions = | 1044 const uint8_t* isolate_snapshot_instructions = |
1034 app_isolate_snapshot_instructions; | 1045 app_isolate_snapshot_instructions; |
1035 #else | 1046 #else |
1036 // JIT: Service isolate uses the core libraries snapshot. | 1047 // JIT: Service isolate uses the core libraries snapshot. |
1037 bool isolate_run_app_snapshot = false; | 1048 bool skip_library_load = false; |
1038 const uint8_t* isolate_snapshot_data = core_isolate_snapshot_data; | 1049 const uint8_t* isolate_snapshot_data = core_isolate_snapshot_data; |
1039 const uint8_t* isolate_snapshot_instructions = | 1050 const uint8_t* isolate_snapshot_instructions = |
1040 core_isolate_snapshot_instructions; | 1051 core_isolate_snapshot_instructions; |
1041 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 1052 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
1042 | 1053 |
1054 Dart_Isolate isolate = NULL; | |
1043 IsolateData* isolate_data = | 1055 IsolateData* isolate_data = |
1044 new IsolateData(script_uri, package_root, packages_config, NULL); | 1056 new IsolateData(script_uri, package_root, packages_config, NULL); |
1045 Dart_Isolate isolate = Dart_CreateIsolate( | 1057 #if defined(DART_PRECOMPILED_RUNTIME) |
1046 script_uri, main, isolate_snapshot_data, isolate_snapshot_instructions, | 1058 isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, |
1047 flags, isolate_data, error); | 1059 isolate_snapshot_instructions, flags, |
1060 isolate_data, error); | |
1061 #else | |
1062 if (dfe.UsePlatformBinary()) { | |
1063 isolate = Dart_CreateIsolateFromKernel( | |
1064 script_uri, NULL, dfe.kernel_platform(), flags, isolate_data, error); | |
1065 if (isolate != NULL) { | |
1066 Dart_EnterScope(); | |
1067 Dart_Handle library = Dart_LoadKernel(dfe.kernel_vmservice_io()); | |
1068 if (Dart_IsError(library)) { | |
1069 Dart_ShutdownIsolate(); | |
siva
2017/06/13 02:12:02
Why does shutdown isolate need to be called here?
sivachandra
2017/06/14 19:25:57
I thought ShutdownIsolate reverses the side effect
siva
2017/06/21 20:01:26
You are right I did not see that the isolate was c
| |
1070 isolate = NULL; | |
1071 } else { | |
1072 skip_library_load = true; | |
1073 } | |
1074 } | |
1075 } else { | |
1076 isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, | |
1077 isolate_snapshot_instructions, flags, | |
1078 isolate_data, error); | |
1079 } | |
1080 #endif // !defined(DART_PRECOMPILED_RUNTIME) | |
1048 if (isolate == NULL) { | 1081 if (isolate == NULL) { |
1049 delete isolate_data; | 1082 delete isolate_data; |
1050 return NULL; | 1083 return NULL; |
1051 } | 1084 } |
1052 | 1085 |
1053 Dart_EnterScope(); | 1086 Dart_EnterScope(); |
1054 | 1087 |
1055 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); | 1088 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); |
1056 CHECK_RESULT(result); | 1089 CHECK_RESULT(result); |
1057 | 1090 |
1058 // Load embedder specific bits and return. | 1091 // Load embedder specific bits and return. |
1059 bool skip_library_load = isolate_run_app_snapshot; | |
1060 if (!VmService::Setup(vm_service_server_ip, vm_service_server_port, | 1092 if (!VmService::Setup(vm_service_server_ip, vm_service_server_port, |
1061 skip_library_load, vm_service_dev_mode, | 1093 skip_library_load, vm_service_dev_mode, |
1062 trace_loading)) { | 1094 trace_loading)) { |
1063 *error = strdup(VmService::GetErrorMessage()); | 1095 *error = strdup(VmService::GetErrorMessage()); |
1064 return NULL; | 1096 return NULL; |
1065 } | 1097 } |
1066 if (compile_all) { | 1098 if (compile_all) { |
1067 result = Dart_CompileAll(); | 1099 result = Dart_CompileAll(); |
1068 CHECK_RESULT(result); | 1100 CHECK_RESULT(result); |
1069 } | 1101 } |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1823 if (gen_snapshot_kind == kAppAOT) { | 1855 if (gen_snapshot_kind == kAppAOT) { |
1824 vm_options.AddArgument("--precompilation"); | 1856 vm_options.AddArgument("--precompilation"); |
1825 } | 1857 } |
1826 #if defined(DART_PRECOMPILED_RUNTIME) | 1858 #if defined(DART_PRECOMPILED_RUNTIME) |
1827 vm_options.AddArgument("--precompilation"); | 1859 vm_options.AddArgument("--precompilation"); |
1828 #endif | 1860 #endif |
1829 if (gen_snapshot_kind == kAppJIT) { | 1861 if (gen_snapshot_kind == kAppJIT) { |
1830 Process::SetExitHook(SnapshotOnExitHook); | 1862 Process::SetExitHook(SnapshotOnExitHook); |
1831 } | 1863 } |
1832 | 1864 |
1865 #if !defined(DART_PRECOMPILED_RUNTIME) | |
1866 // If a kernel platform binary file is specified, read it. This | |
1867 // step will become redundant once we have the snapshot version | |
1868 // of the kernel core/platform libraries. | |
1869 if (dfe.UsePlatformBinary()) { | |
1870 if (dfe.ReadPlatform() == NULL) { | |
1871 Log::PrintErr("The platform binary is not a valid Dart Kernel file."); | |
1872 Platform::Exit(kErrorExitCode); | |
1873 } | |
1874 if (dfe.ReadVMServiceIO() == NULL) { | |
1875 Log::PrintErr("Could not read dart:vmservice_io binary file."); | |
1876 Platform::Exit(kErrorExitCode); | |
1877 } | |
1878 } | |
1879 #endif | |
1880 | |
1833 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1881 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
1834 | 1882 |
1835 // Start event handler. | 1883 // Start event handler. |
1836 TimerUtils::InitOnce(); | 1884 TimerUtils::InitOnce(); |
1837 EventHandler::Start(); | 1885 EventHandler::Start(); |
1838 | 1886 |
1839 // Initialize the Dart VM. | 1887 // Initialize the Dart VM. |
1840 Dart_InitializeParams init_params; | 1888 Dart_InitializeParams init_params; |
1841 memset(&init_params, 0, sizeof(init_params)); | 1889 memset(&init_params, 0, sizeof(init_params)); |
1842 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; | 1890 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; |
(...skipping 14 matching lines...) Expand all Loading... | |
1857 EventHandler::Stop(); | 1905 EventHandler::Stop(); |
1858 Log::PrintErr("VM initialization failed: %s\n", error); | 1906 Log::PrintErr("VM initialization failed: %s\n", error); |
1859 free(error); | 1907 free(error); |
1860 Platform::Exit(kErrorExitCode); | 1908 Platform::Exit(kErrorExitCode); |
1861 } | 1909 } |
1862 | 1910 |
1863 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, | 1911 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, |
1864 &ServiceStreamCancelCallback); | 1912 &ServiceStreamCancelCallback); |
1865 Dart_SetFileModifiedCallback(&FileModifiedCallback); | 1913 Dart_SetFileModifiedCallback(&FileModifiedCallback); |
1866 | 1914 |
1867 #if !defined(DART_PRECOMPILED_RUNTIME) | |
1868 // If a kernel platform binary file is specified, read it. This | |
1869 // step will become redundant once we have the snapshot version | |
1870 // of the kernel core/platform libraries. | |
1871 if (dfe.UsePlatformBinary()) { | |
1872 if (dfe.ReadPlatform() == NULL) { | |
1873 Log::PrintErr("The platform binary is not a valid Dart Kernel file."); | |
1874 Platform::Exit(kErrorExitCode); | |
1875 } | |
1876 } | |
1877 #endif | |
1878 | |
1879 // Run the main isolate until we aren't told to restart. | 1915 // Run the main isolate until we aren't told to restart. |
1880 while (RunMainIsolate(script_name, &dart_options)) { | 1916 while (RunMainIsolate(script_name, &dart_options)) { |
1881 Log::PrintErr("Restarting VM\n"); | 1917 Log::PrintErr("Restarting VM\n"); |
1882 } | 1918 } |
1883 | 1919 |
1884 // Terminate process exit-code handler. | 1920 // Terminate process exit-code handler. |
1885 Process::TerminateExitCodeHandler(); | 1921 Process::TerminateExitCodeHandler(); |
1886 | 1922 |
1887 error = Dart_Cleanup(); | 1923 error = Dart_Cleanup(); |
1888 if (error != NULL) { | 1924 if (error != NULL) { |
(...skipping 26 matching lines...) Expand all Loading... | |
1915 Platform::Exit(Process::GlobalExitCode()); | 1951 Platform::Exit(Process::GlobalExitCode()); |
1916 } | 1952 } |
1917 | 1953 |
1918 } // namespace bin | 1954 } // namespace bin |
1919 } // namespace dart | 1955 } // namespace dart |
1920 | 1956 |
1921 int main(int argc, char** argv) { | 1957 int main(int argc, char** argv) { |
1922 dart::bin::main(argc, argv); | 1958 dart::bin::main(argc, argv); |
1923 UNREACHABLE(); | 1959 UNREACHABLE(); |
1924 } | 1960 } |
OLD | NEW |