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

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

Issue 2952913002: Reland "Load service isolate from a .dill file." (Closed)
Patch Set: Exact same patch Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/dfe.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 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 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 if (value != NULL) { 819 if (value != NULL) {
820 result = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(value), 820 result = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(value),
821 strlen(value)); 821 strlen(value));
822 } 822 }
823 free(name_chars); 823 free(name_chars);
824 } 824 }
825 return result; 825 return result;
826 } 826 }
827 827
828 828
829 #define SAVE_ERROR_AND_EXIT(result) \
830 *error = strdup(Dart_GetError(result)); \
831 if (Dart_IsCompilationError(result)) { \
832 *exit_code = kCompilationErrorExitCode; \
833 } else if (Dart_IsApiError(result)) { \
834 *exit_code = kApiErrorExitCode; \
835 } else { \
836 *exit_code = kErrorExitCode; \
837 } \
838 Dart_ExitScope(); \
839 Dart_ShutdownIsolate(); \
840 return NULL;
841
842
829 #define CHECK_RESULT(result) \ 843 #define CHECK_RESULT(result) \
830 if (Dart_IsError(result)) { \ 844 if (Dart_IsError(result)) { \
831 *error = strdup(Dart_GetError(result)); \ 845 SAVE_ERROR_AND_EXIT(result); \
832 if (Dart_IsCompilationError(result)) { \
833 *exit_code = kCompilationErrorExitCode; \
834 } else if (Dart_IsApiError(result)) { \
835 *exit_code = kApiErrorExitCode; \
836 } else { \
837 *exit_code = kErrorExitCode; \
838 } \
839 Dart_ExitScope(); \
840 Dart_ShutdownIsolate(); \
841 return NULL; \
842 } 846 }
843 847
844 848
849 #define CHECK_RESULT_CLEANUP(result, cleanup) \
850 if (Dart_IsError(result)) { \
851 delete (cleanup); \
852 SAVE_ERROR_AND_EXIT(result); \
853 }
854
855
845 static void SnapshotOnExitHook(int64_t exit_code) { 856 static void SnapshotOnExitHook(int64_t exit_code) {
846 if (Dart_CurrentIsolate() != main_isolate) { 857 if (Dart_CurrentIsolate() != main_isolate) {
847 Log::PrintErr( 858 Log::PrintErr(
848 "A snapshot was requested, but a secondary isolate " 859 "A snapshot was requested, but a secondary isolate "
849 "performed a hard exit (%" Pd64 ").\n", 860 "performed a hard exit (%" Pd64 ").\n",
850 exit_code); 861 exit_code);
851 Platform::Exit(kErrorExitCode); 862 Platform::Exit(kErrorExitCode);
852 } 863 }
853 if (exit_code == 0) { 864 if (exit_code == 0) {
854 Snapshot::GenerateAppJIT(snapshot_filename); 865 Snapshot::GenerateAppJIT(snapshot_filename);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 } else {
1066 isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data,
1067 isolate_snapshot_instructions, flags,
1068 isolate_data, error);
1069 }
1070 #endif // !defined(DART_PRECOMPILED_RUNTIME)
1048 if (isolate == NULL) { 1071 if (isolate == NULL) {
1049 delete isolate_data; 1072 delete isolate_data;
1050 return NULL; 1073 return NULL;
1051 } 1074 }
1052 1075
1053 Dart_EnterScope(); 1076 Dart_EnterScope();
1054 1077
1055 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); 1078 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler);
1056 CHECK_RESULT(result); 1079 CHECK_RESULT(result);
1057 1080
1081 #if !defined(DART_PRECOMPILED_RUNTIME)
1082 if (dfe.UsePlatformBinary()) {
1083 Dart_Handle library = Dart_LoadKernel(dfe.kernel_vmservice_io());
1084 CHECK_RESULT_CLEANUP(library, isolate_data);
1085 skip_library_load = true;
1086 }
1087 #endif // !defined(DART_PRECOMPILED_RUNTIME)
1088
1058 // Load embedder specific bits and return. 1089 // 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, 1090 if (!VmService::Setup(vm_service_server_ip, vm_service_server_port,
1061 skip_library_load, vm_service_dev_mode, 1091 skip_library_load, vm_service_dev_mode,
1062 trace_loading)) { 1092 trace_loading)) {
1063 *error = strdup(VmService::GetErrorMessage()); 1093 *error = strdup(VmService::GetErrorMessage());
1064 return NULL; 1094 return NULL;
1065 } 1095 }
1066 if (compile_all) { 1096 if (compile_all) {
1067 result = Dart_CompileAll(); 1097 result = Dart_CompileAll();
1068 CHECK_RESULT(result); 1098 CHECK_RESULT(result);
1069 } 1099 }
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 if (gen_snapshot_kind == kAppAOT) { 1855 if (gen_snapshot_kind == kAppAOT) {
1826 vm_options.AddArgument("--precompilation"); 1856 vm_options.AddArgument("--precompilation");
1827 } 1857 }
1828 #if defined(DART_PRECOMPILED_RUNTIME) 1858 #if defined(DART_PRECOMPILED_RUNTIME)
1829 vm_options.AddArgument("--precompilation"); 1859 vm_options.AddArgument("--precompilation");
1830 #endif 1860 #endif
1831 if (gen_snapshot_kind == kAppJIT) { 1861 if (gen_snapshot_kind == kAppJIT) {
1832 Process::SetExitHook(SnapshotOnExitHook); 1862 Process::SetExitHook(SnapshotOnExitHook);
1833 } 1863 }
1834 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
1835 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 1881 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
1836 1882
1837 // Start event handler. 1883 // Start event handler.
1838 TimerUtils::InitOnce(); 1884 TimerUtils::InitOnce();
1839 EventHandler::Start(); 1885 EventHandler::Start();
1840 1886
1841 // Initialize the Dart VM. 1887 // Initialize the Dart VM.
1842 Dart_InitializeParams init_params; 1888 Dart_InitializeParams init_params;
1843 memset(&init_params, 0, sizeof(init_params)); 1889 memset(&init_params, 0, sizeof(init_params));
1844 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; 1890 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION;
(...skipping 14 matching lines...) Expand all
1859 EventHandler::Stop(); 1905 EventHandler::Stop();
1860 Log::PrintErr("VM initialization failed: %s\n", error); 1906 Log::PrintErr("VM initialization failed: %s\n", error);
1861 free(error); 1907 free(error);
1862 Platform::Exit(kErrorExitCode); 1908 Platform::Exit(kErrorExitCode);
1863 } 1909 }
1864 1910
1865 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, 1911 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback,
1866 &ServiceStreamCancelCallback); 1912 &ServiceStreamCancelCallback);
1867 Dart_SetFileModifiedCallback(&FileModifiedCallback); 1913 Dart_SetFileModifiedCallback(&FileModifiedCallback);
1868 1914
1869 #if !defined(DART_PRECOMPILED_RUNTIME)
1870 // If a kernel platform binary file is specified, read it. This
1871 // step will become redundant once we have the snapshot version
1872 // of the kernel core/platform libraries.
1873 if (dfe.UsePlatformBinary()) {
1874 if (dfe.ReadPlatform() == NULL) {
1875 Log::PrintErr("The platform binary is not a valid Dart Kernel file.");
1876 Platform::Exit(kErrorExitCode);
1877 }
1878 }
1879 #endif
1880
1881 // Run the main isolate until we aren't told to restart. 1915 // Run the main isolate until we aren't told to restart.
1882 while (RunMainIsolate(script_name, &dart_options)) { 1916 while (RunMainIsolate(script_name, &dart_options)) {
1883 Log::PrintErr("Restarting VM\n"); 1917 Log::PrintErr("Restarting VM\n");
1884 } 1918 }
1885 1919
1886 // Terminate process exit-code handler. 1920 // Terminate process exit-code handler.
1887 Process::TerminateExitCodeHandler(); 1921 Process::TerminateExitCodeHandler();
1888 1922
1889 error = Dart_Cleanup(); 1923 error = Dart_Cleanup();
1890 if (error != NULL) { 1924 if (error != NULL) {
(...skipping 26 matching lines...) Expand all
1917 Platform::Exit(Process::GlobalExitCode()); 1951 Platform::Exit(Process::GlobalExitCode());
1918 } 1952 }
1919 1953
1920 } // namespace bin 1954 } // namespace bin
1921 } // namespace dart 1955 } // namespace dart
1922 1956
1923 int main(int argc, char** argv) { 1957 int main(int argc, char** argv) {
1924 dart::bin::main(argc, argv); 1958 dart::bin::main(argc, argv);
1925 UNREACHABLE(); 1959 UNREACHABLE();
1926 } 1960 }
OLDNEW
« no previous file with comments | « runtime/bin/dfe.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698