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 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 Snapshot::GenerateAppJIT(snapshot_filename); | 824 Snapshot::GenerateAppJIT(snapshot_filename); |
825 } | 825 } |
826 } | 826 } |
827 | 827 |
828 | 828 |
829 static Dart_Isolate IsolateSetupHelper(Dart_Isolate isolate, | 829 static Dart_Isolate IsolateSetupHelper(Dart_Isolate isolate, |
830 bool is_main_isolate, | 830 bool is_main_isolate, |
831 const char* script_uri, | 831 const char* script_uri, |
832 const char* package_root, | 832 const char* package_root, |
833 const char* packages_config, | 833 const char* packages_config, |
834 void* kernel_program, | |
835 bool set_native_resolvers, | 834 bool set_native_resolvers, |
836 bool isolate_run_app_snapshot, | 835 bool isolate_run_app_snapshot, |
837 char** error, | 836 char** error, |
838 int* exit_code) { | 837 int* exit_code) { |
839 Dart_EnterScope(); | 838 Dart_EnterScope(); |
| 839 IsolateData* isolate_data = |
| 840 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); |
| 841 void* kernel_program = isolate_data->kernel_program; |
840 | 842 |
841 // Set up the library tag handler for this isolate. | 843 // Set up the library tag handler for this isolate. |
842 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); | 844 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); |
843 CHECK_RESULT(result); | 845 CHECK_RESULT(result); |
844 | 846 |
845 if (kernel_program != NULL) { | 847 if (kernel_program != NULL) { |
846 Dart_Handle result = Dart_LoadKernel(kernel_program); | 848 Dart_Handle result = Dart_LoadKernel(kernel_program); |
847 CHECK_RESULT(result); | 849 CHECK_RESULT(result); |
848 } | 850 } |
849 if (set_native_resolvers) { | 851 if (set_native_resolvers) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 new IsolateData(script_uri, package_root, packages_config, app_snapshot); | 971 new IsolateData(script_uri, package_root, packages_config, app_snapshot); |
970 Dart_Isolate isolate = Dart_CreateIsolate( | 972 Dart_Isolate isolate = Dart_CreateIsolate( |
971 script_uri, main, isolate_snapshot_data, isolate_snapshot_instructions, | 973 script_uri, main, isolate_snapshot_data, isolate_snapshot_instructions, |
972 flags, isolate_data, error); | 974 flags, isolate_data, error); |
973 if (isolate == NULL) { | 975 if (isolate == NULL) { |
974 delete isolate_data; | 976 delete isolate_data; |
975 return NULL; | 977 return NULL; |
976 } | 978 } |
977 | 979 |
978 return IsolateSetupHelper(isolate, false, script_uri, package_root, | 980 return IsolateSetupHelper(isolate, false, script_uri, package_root, |
979 packages_config, NULL, isolate_snapshot_data, | 981 packages_config, isolate_snapshot_data, |
980 isolate_run_app_snapshot, error, exit_code); | 982 isolate_run_app_snapshot, error, exit_code); |
981 } | 983 } |
982 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 984 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
983 | 985 |
984 | 986 |
985 // Returns newly created Service Isolate on success, NULL on failure. | 987 // Returns newly created Service Isolate on success, NULL on failure. |
986 // For now we only support the service isolate coming up from sources | 988 // For now we only support the service isolate coming up from sources |
987 // which are compiled by the VM parser. | 989 // which are compiled by the VM parser. |
988 static Dart_Isolate CreateAndSetupServiceIsolate(const char* script_uri, | 990 static Dart_Isolate CreateAndSetupServiceIsolate(const char* script_uri, |
989 const char* main, | 991 const char* main, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 const char* package_root, | 1052 const char* package_root, |
1051 const char* packages_config, | 1053 const char* packages_config, |
1052 Dart_IsolateFlags* flags, | 1054 Dart_IsolateFlags* flags, |
1053 char** error, | 1055 char** error, |
1054 int* exit_code) { | 1056 int* exit_code) { |
1055 ASSERT(script_uri != NULL); | 1057 ASSERT(script_uri != NULL); |
1056 void* kernel_platform = NULL; | 1058 void* kernel_platform = NULL; |
1057 void* kernel_program = NULL; | 1059 void* kernel_program = NULL; |
1058 AppSnapshot* app_snapshot = NULL; | 1060 AppSnapshot* app_snapshot = NULL; |
1059 | 1061 |
| 1062 IsolateData* isolate_data = |
| 1063 new IsolateData(script_uri, package_root, packages_config, app_snapshot); |
| 1064 if (is_main_isolate && (snapshot_deps_filename != NULL)) { |
| 1065 isolate_data->set_dependencies(new MallocGrowableArray<char*>()); |
| 1066 } |
| 1067 |
1060 #if defined(DART_PRECOMPILED_RUNTIME) | 1068 #if defined(DART_PRECOMPILED_RUNTIME) |
1061 // AOT: All isolates start from the app snapshot. | 1069 // AOT: All isolates start from the app snapshot. |
1062 bool isolate_run_app_snapshot = true; | 1070 bool isolate_run_app_snapshot = true; |
1063 const uint8_t* isolate_snapshot_data = app_isolate_snapshot_data; | 1071 const uint8_t* isolate_snapshot_data = app_isolate_snapshot_data; |
1064 const uint8_t* isolate_snapshot_instructions = | 1072 const uint8_t* isolate_snapshot_instructions = |
1065 app_isolate_snapshot_instructions; | 1073 app_isolate_snapshot_instructions; |
1066 #else | 1074 #else |
1067 // JIT: Main isolate starts from the app snapshot, if any. Other isolates | 1075 // JIT: Main isolate starts from the app snapshot, if any. Other isolates |
1068 // use the core libraries snapshot. | 1076 // use the core libraries snapshot. |
1069 bool isolate_run_app_snapshot = false; | 1077 bool isolate_run_app_snapshot = false; |
(...skipping 10 matching lines...) Expand all Loading... |
1080 app_snapshot = Snapshot::TryReadAppSnapshot(script_uri); | 1088 app_snapshot = Snapshot::TryReadAppSnapshot(script_uri); |
1081 if (app_snapshot != NULL) { | 1089 if (app_snapshot != NULL) { |
1082 isolate_run_app_snapshot = true; | 1090 isolate_run_app_snapshot = true; |
1083 const uint8_t* ignore_vm_snapshot_data; | 1091 const uint8_t* ignore_vm_snapshot_data; |
1084 const uint8_t* ignore_vm_snapshot_instructions; | 1092 const uint8_t* ignore_vm_snapshot_instructions; |
1085 app_snapshot->SetBuffers( | 1093 app_snapshot->SetBuffers( |
1086 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, | 1094 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, |
1087 &isolate_snapshot_data, &isolate_snapshot_instructions); | 1095 &isolate_snapshot_data, &isolate_snapshot_instructions); |
1088 } | 1096 } |
1089 } | 1097 } |
1090 const uint8_t* platform_file = NULL; | 1098 if (!isolate_run_app_snapshot) { |
1091 if (dfe.UsePlatformBinary()) { | 1099 kernel_platform = dfe.kernel_platform(); |
1092 intptr_t platform_length = -1; | 1100 kernel_program = dfe.ReadScript(script_uri); |
1093 bool success = dfe.TryReadKernelFile(dfe.platform_binary_filename(), | 1101 if (kernel_program == NULL && dfe.UseDartFrontend()) { |
1094 &platform_file, &platform_length); | 1102 kernel_program = dfe.CompileAndReadScript(script_uri, error, exit_code); |
1095 if (!success) { | 1103 if (kernel_program == NULL) { |
1096 *error = strdup("The platform binary is not a valid Dart Kernel file."); | 1104 return NULL; |
1097 *exit_code = kErrorExitCode; | 1105 } |
1098 return NULL; | |
1099 } | 1106 } |
1100 kernel_platform = Dart_ReadKernelBinary(platform_file, platform_length); | 1107 isolate_data->kernel_program = kernel_program; |
1101 } | |
1102 | |
1103 bool is_kernel = false; | |
1104 const uint8_t* kernel_file = NULL; | |
1105 intptr_t kernel_length = -1; | |
1106 if (dfe.UseDartFrontend()) { | |
1107 Dart_KernelCompilationResult result = Dart_CompileToKernel(script_uri); | |
1108 *error = result.error; // Copy error message (if any). | |
1109 switch (result.status) { | |
1110 case Dart_KernelCompilationStatus_Ok: | |
1111 is_kernel = true; | |
1112 kernel_file = result.kernel; | |
1113 kernel_length = result.kernel_size; | |
1114 break; | |
1115 case Dart_KernelCompilationStatus_Error: | |
1116 *exit_code = kCompilationErrorExitCode; | |
1117 break; | |
1118 case Dart_KernelCompilationStatus_Crash: | |
1119 *exit_code = kDartFrontendErrorExitCode; | |
1120 break; | |
1121 case Dart_KernelCompilationStatus_Unknown: | |
1122 *exit_code = kErrorExitCode; | |
1123 break; | |
1124 } | |
1125 if (!is_kernel) { | |
1126 free(const_cast<uint8_t*>(platform_file)); | |
1127 delete reinterpret_cast<kernel::Program*>(kernel_platform); | |
1128 return NULL; | |
1129 } | |
1130 } else if (!isolate_run_app_snapshot) { | |
1131 is_kernel = dfe.TryReadKernelFile(script_uri, &kernel_file, &kernel_length); | |
1132 } | |
1133 | |
1134 if (is_kernel) { | |
1135 kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length); | |
1136 } | 1108 } |
1137 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 1109 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
1138 | 1110 |
1139 IsolateData* isolate_data = | |
1140 new IsolateData(script_uri, package_root, packages_config, app_snapshot); | |
1141 if (is_main_isolate && (snapshot_deps_filename != NULL)) { | |
1142 isolate_data->set_dependencies(new MallocGrowableArray<char*>()); | |
1143 } | |
1144 Dart_Isolate isolate = NULL; | 1111 Dart_Isolate isolate = NULL; |
1145 if (kernel_platform != NULL) { | 1112 if (kernel_platform != NULL) { |
1146 isolate = Dart_CreateIsolateFromKernel(script_uri, main, kernel_platform, | 1113 isolate = Dart_CreateIsolateFromKernel(script_uri, main, kernel_platform, |
1147 flags, isolate_data, error); | 1114 flags, isolate_data, error); |
1148 } else if (kernel_program != NULL) { | 1115 } else if (kernel_program != NULL) { |
1149 isolate = Dart_CreateIsolateFromKernel(script_uri, main, kernel_program, | 1116 isolate = Dart_CreateIsolateFromKernel(script_uri, main, kernel_program, |
1150 flags, isolate_data, error); | 1117 flags, isolate_data, error); |
1151 } else { | 1118 } else { |
1152 isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, | 1119 isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, |
1153 isolate_snapshot_instructions, flags, | 1120 isolate_snapshot_instructions, flags, |
1154 isolate_data, error); | 1121 isolate_data, error); |
1155 } | 1122 } |
1156 if (isolate == NULL) { | 1123 if (isolate == NULL) { |
1157 delete isolate_data; | 1124 delete isolate_data; |
1158 return NULL; | 1125 return NULL; |
1159 } | 1126 } |
1160 | 1127 |
| 1128 bool set_native_resolvers = (kernel_program || isolate_snapshot_data); |
1161 return IsolateSetupHelper(isolate, is_main_isolate, script_uri, package_root, | 1129 return IsolateSetupHelper(isolate, is_main_isolate, script_uri, package_root, |
1162 packages_config, kernel_program, | 1130 packages_config, set_native_resolvers, |
1163 (kernel_program || isolate_snapshot_data), | |
1164 isolate_run_app_snapshot, error, exit_code); | 1131 isolate_run_app_snapshot, error, exit_code); |
1165 } | 1132 } |
1166 | 1133 |
1167 #undef CHECK_RESULT | 1134 #undef CHECK_RESULT |
1168 | 1135 |
1169 | 1136 |
1170 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, | 1137 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, |
1171 const char* main, | 1138 const char* main, |
1172 const char* package_root, | 1139 const char* package_root, |
1173 const char* package_config, | 1140 const char* package_config, |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1829 EventHandler::Stop(); | 1796 EventHandler::Stop(); |
1830 Log::PrintErr("VM initialization failed: %s\n", error); | 1797 Log::PrintErr("VM initialization failed: %s\n", error); |
1831 free(error); | 1798 free(error); |
1832 Platform::Exit(kErrorExitCode); | 1799 Platform::Exit(kErrorExitCode); |
1833 } | 1800 } |
1834 | 1801 |
1835 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, | 1802 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, |
1836 &ServiceStreamCancelCallback); | 1803 &ServiceStreamCancelCallback); |
1837 Dart_SetFileModifiedCallback(&FileModifiedCallback); | 1804 Dart_SetFileModifiedCallback(&FileModifiedCallback); |
1838 | 1805 |
| 1806 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 1807 // If a kernel platform binary file is specified, read it. This |
| 1808 // step will become redundant once we have the snapshot version |
| 1809 // of the kernel core/platform libraries. |
| 1810 if (dfe.UsePlatformBinary()) { |
| 1811 if (dfe.ReadPlatform() == NULL) { |
| 1812 Log::PrintErr("The platform binary is not a valid Dart Kernel file."); |
| 1813 Platform::Exit(kErrorExitCode); |
| 1814 } |
| 1815 } |
| 1816 #endif |
| 1817 |
1839 // Run the main isolate until we aren't told to restart. | 1818 // Run the main isolate until we aren't told to restart. |
1840 while (RunMainIsolate(script_name, &dart_options)) { | 1819 while (RunMainIsolate(script_name, &dart_options)) { |
1841 Log::PrintErr("Restarting VM\n"); | 1820 Log::PrintErr("Restarting VM\n"); |
1842 } | 1821 } |
1843 | 1822 |
1844 // Terminate process exit-code handler. | 1823 // Terminate process exit-code handler. |
1845 Process::TerminateExitCodeHandler(); | 1824 Process::TerminateExitCodeHandler(); |
1846 | 1825 |
1847 error = Dart_Cleanup(); | 1826 error = Dart_Cleanup(); |
1848 if (error != NULL) { | 1827 if (error != NULL) { |
(...skipping 26 matching lines...) Expand all Loading... |
1875 Platform::Exit(Process::GlobalExitCode()); | 1854 Platform::Exit(Process::GlobalExitCode()); |
1876 } | 1855 } |
1877 | 1856 |
1878 } // namespace bin | 1857 } // namespace bin |
1879 } // namespace dart | 1858 } // namespace dart |
1880 | 1859 |
1881 int main(int argc, char** argv) { | 1860 int main(int argc, char** argv) { |
1882 dart::bin::main(argc, argv); | 1861 dart::bin::main(argc, argv); |
1883 UNREACHABLE(); | 1862 UNREACHABLE(); |
1884 } | 1863 } |
OLD | NEW |