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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; | 120 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; |
121 // VM Service options. | 121 // VM Service options. |
122 static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP; | 122 static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP; |
123 // The 0 port is a magic value which results in the first available port | 123 // The 0 port is a magic value which results in the first available port |
124 // being allocated. | 124 // being allocated. |
125 static int vm_service_server_port = -1; | 125 static int vm_service_server_port = -1; |
126 // True when we are running in development mode and cross origin security | 126 // True when we are running in development mode and cross origin security |
127 // checks are disabled. | 127 // checks are disabled. |
128 static bool vm_service_dev_mode = false; | 128 static bool vm_service_dev_mode = false; |
129 | 129 |
130 // Exit code indicating an internal Dart Frontend error. | |
131 static const int kDartFrontendErrorExitCode = 252; | |
130 // Exit code indicating an API error. | 132 // Exit code indicating an API error. |
131 static const int kApiErrorExitCode = 253; | 133 static const int kApiErrorExitCode = 253; |
132 // Exit code indicating a compilation error. | 134 // Exit code indicating a compilation error. |
133 static const int kCompilationErrorExitCode = 254; | 135 static const int kCompilationErrorExitCode = 254; |
134 // Exit code indicating an unhandled error that is not a compilation error. | 136 // Exit code indicating an unhandled error that is not a compilation error. |
135 static const int kErrorExitCode = 255; | 137 static const int kErrorExitCode = 255; |
136 // Exit code indicating a vm restart request. Never returned to the user. | 138 // Exit code indicating a vm restart request. Never returned to the user. |
137 static const int kRestartRequestExitCode = 1000; | 139 static const int kRestartRequestExitCode = 1000; |
138 | 140 |
139 static void ErrorExit(int exit_code, const char* format, ...) { | 141 static void ErrorExit(int exit_code, const char* format, ...) { |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
804 } \ | 806 } \ |
805 Dart_ExitScope(); \ | 807 Dart_ExitScope(); \ |
806 Dart_ShutdownIsolate(); \ | 808 Dart_ShutdownIsolate(); \ |
807 return NULL; \ | 809 return NULL; \ |
808 } | 810 } |
809 | 811 |
810 | 812 |
811 static void SnapshotOnExitHook(int64_t exit_code); | 813 static void SnapshotOnExitHook(int64_t exit_code); |
812 | 814 |
813 | 815 |
814 // Returns true on success, false on failure. | 816 // Returns true on success, false on failure. |
kustermann
2017/01/30 12:14:23
This comment says it returns true/false, but it se
Vyacheslav Egorov (Google)
2017/01/30 19:34:12
Done.
| |
815 static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate, | 817 static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate, |
816 const char* script_uri, | 818 const char* script_uri, |
817 const char* main, | 819 const char* main, |
818 const char* package_root, | 820 const char* package_root, |
819 const char* packages_config, | 821 const char* packages_config, |
820 Dart_IsolateFlags* flags, | 822 Dart_IsolateFlags* flags, |
821 char** error, | 823 char** error, |
822 int* exit_code) { | 824 int* exit_code) { |
823 ASSERT(script_uri != NULL); | 825 ASSERT(script_uri != NULL); |
824 if (strcmp(script_uri, DART_KERNEL_ISOLATE_NAME) == 0) { | 826 const bool is_kernel_isolate = |
827 strcmp(script_uri, DART_KERNEL_ISOLATE_NAME) == 0; | |
828 if (is_kernel_isolate) { | |
825 if (!use_dart_frontend) { | 829 if (!use_dart_frontend) { |
826 *error = strdup("Kernel isolate not supported."); | 830 *error = strdup("Kernel isolate not supported."); |
827 return NULL; | 831 return NULL; |
828 } else { | 832 } else { |
829 if (packages_config == NULL) { | 833 if (packages_config == NULL) { |
830 packages_config = commandline_packages_file; | 834 packages_config = commandline_packages_file; |
831 } | 835 } |
832 } | 836 } |
833 } | 837 } |
834 | 838 |
835 #if defined(DART_PRECOMPILED_RUNTIME) | 839 #if defined(DART_PRECOMPILED_RUNTIME) |
836 // AOT: All isolates start from the app snapshot. | 840 // AOT: All isolates start from the app snapshot. |
837 bool isolate_run_app_snapshot = true; | 841 bool isolate_run_app_snapshot = true; |
838 const uint8_t* isolate_snapshot_buffer = app_isolate_snapshot_buffer; | 842 const uint8_t* isolate_snapshot_buffer = app_isolate_snapshot_buffer; |
839 #else | 843 #else |
840 // JIT: Main isolate starts from the app snapshot, if any. Other use the | 844 // JIT: Main isolate starts from the app snapshot, if any. Other use the |
841 // core libraries snapshot. | 845 // core libraries snapshot. |
842 bool isolate_run_app_snapshot = false; | 846 bool isolate_run_app_snapshot = false; |
843 const uint8_t* isolate_snapshot_buffer = core_isolate_snapshot_buffer; | 847 const uint8_t* isolate_snapshot_buffer = core_isolate_snapshot_buffer; |
844 if ((app_isolate_snapshot_buffer != NULL) && | 848 if ((app_isolate_snapshot_buffer != NULL) && |
845 (is_main_isolate || ((app_script_uri != NULL) && | 849 (is_main_isolate || ((app_script_uri != NULL) && |
846 (strcmp(script_uri, app_script_uri) == 0)))) { | 850 (strcmp(script_uri, app_script_uri) == 0)))) { |
847 isolate_run_app_snapshot = true; | 851 isolate_run_app_snapshot = true; |
848 isolate_snapshot_buffer = app_isolate_snapshot_buffer; | 852 isolate_snapshot_buffer = app_isolate_snapshot_buffer; |
849 } | 853 } |
850 #endif | 854 #endif |
851 | 855 |
856 const uint8_t* kernel_file = NULL; | |
857 intptr_t kernel_length = -1; | |
858 bool is_kernel = false; | |
859 | |
860 if (use_dart_frontend && !is_kernel_isolate && !is_service_isolate) { | |
861 Dart_KernelCompilationResult result = Dart_CompileToKernel(script_uri); | |
hausner
2017/01/24 00:50:55
Calling the front end here only works because it r
Vyacheslav Egorov (Google)
2017/01/30 19:34:12
Yep, your understanding of the current situation i
| |
862 *error = result.error; // Copy error message (if any). | |
863 switch (result.status) { | |
864 case Dart_KernelCompilationStatus_Ok: | |
865 is_kernel = true; | |
866 kernel_file = result.kernel; | |
867 kernel_length = result.kernel_size; | |
868 break; | |
869 case Dart_KernelCompilationStatus_Error: | |
870 *exit_code = kCompilationErrorExitCode; | |
871 return NULL; | |
872 case Dart_KernelCompilationStatus_Crash: | |
873 *exit_code = kDartFrontendErrorExitCode; | |
874 return NULL; | |
875 case Dart_KernelCompilationStatus_Unknown: | |
siva
2017/01/24 02:38:02
This return code seems to happen only when the ker
Vyacheslav Egorov (Google)
2017/01/30 19:34:13
Done.
| |
876 return NULL; | |
877 } | |
878 } | |
879 | |
852 // If the script is a Kernel binary, then we will try to bootstrap from the | 880 // If the script is a Kernel binary, then we will try to bootstrap from the |
853 // script. | 881 // script. |
854 const uint8_t* kernel_file = NULL; | 882 if (!is_kernel && !isolate_run_app_snapshot) { |
855 intptr_t kernel_length = -1; | 883 is_kernel = TryReadKernel(script_uri, &kernel_file, &kernel_length); |
856 const bool is_kernel = | 884 } |
857 !isolate_run_app_snapshot && | |
858 TryReadKernel(script_uri, &kernel_file, &kernel_length); | |
859 | 885 |
860 void* kernel_program = NULL; | 886 void* kernel_program = NULL; |
861 if (is_kernel) { | 887 if (is_kernel) { |
862 kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length); | 888 kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length); |
863 free(const_cast<uint8_t*>(kernel_file)); | 889 free(const_cast<uint8_t*>(kernel_file)); |
864 } | 890 } |
865 | 891 |
866 IsolateData* isolate_data = | 892 IsolateData* isolate_data = |
867 new IsolateData(script_uri, package_root, packages_config); | 893 new IsolateData(script_uri, package_root, packages_config); |
868 Dart_Isolate isolate = | 894 Dart_Isolate isolate = |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
932 // Setup package root if specified. | 958 // Setup package root if specified. |
933 result = DartUtils::SetupPackageRoot(package_root, packages_config); | 959 result = DartUtils::SetupPackageRoot(package_root, packages_config); |
934 CHECK_RESULT(result); | 960 CHECK_RESULT(result); |
935 | 961 |
936 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 962 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
937 CHECK_RESULT(result); | 963 CHECK_RESULT(result); |
938 | 964 |
939 if (!Dart_IsKernelIsolate(isolate) && use_dart_frontend) { | 965 if (!Dart_IsKernelIsolate(isolate) && use_dart_frontend) { |
940 // This must be the main script to be loaded. Wait for Kernel isolate | 966 // This must be the main script to be loaded. Wait for Kernel isolate |
941 // to finish initialization. | 967 // to finish initialization. |
942 Dart_Port port = Dart_ServiceWaitForKernelPort(); | 968 Dart_Port port = Dart_ServiceWaitForKernelPort(); |
hausner
2017/01/24 00:50:55
Haven't we waited for the kernel isolate to be rea
siva
2017/01/24 02:38:02
Maybe move this up to just before where Dart_Compi
Vyacheslav Egorov (Google)
2017/01/30 19:34:12
Removed this code.
| |
943 if (port == ILLEGAL_PORT) { | 969 if (port == ILLEGAL_PORT) { |
944 *error = strdup("Error while initializing Kernel isolate"); | 970 *error = strdup("Error while initializing Kernel isolate"); |
945 return NULL; | 971 return NULL; |
946 } | 972 } |
973 | |
974 Loader::InitForSnapshot(script_uri); | |
hausner
2017/01/24 00:50:55
Why is this call needed here? This seems to be app
Vyacheslav Egorov (Google)
2017/01/30 19:34:13
Some parts of core-libraries (e.g. Isolate methods
| |
947 } | 975 } |
948 | 976 |
949 if (isolate_run_app_snapshot) { | 977 if (isolate_run_app_snapshot) { |
950 result = DartUtils::SetupIOLibrary(script_uri); | 978 result = DartUtils::SetupIOLibrary(script_uri); |
951 CHECK_RESULT(result); | 979 CHECK_RESULT(result); |
952 Loader::InitForSnapshot(script_uri); | 980 Loader::InitForSnapshot(script_uri); |
953 #if !defined(DART_PRECOMPILED_RUNTIME) | 981 #if !defined(DART_PRECOMPILED_RUNTIME) |
954 if (is_main_isolate) { | 982 if (is_main_isolate) { |
955 // Find the canonical uri of the app snapshot. We'll use this to decide if | 983 // Find the canonical uri of the app snapshot. We'll use this to decide if |
956 // other isolates should use the app snapshot or the core snapshot. | 984 // other isolates should use the app snapshot or the core snapshot. |
957 const char* resolved_script_uri = NULL; | 985 const char* resolved_script_uri = NULL; |
958 result = Dart_StringToCString( | 986 result = Dart_StringToCString( |
959 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)), | 987 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)), |
960 &resolved_script_uri); | 988 &resolved_script_uri); |
961 CHECK_RESULT(result); | 989 CHECK_RESULT(result); |
962 ASSERT(app_script_uri == NULL); | 990 ASSERT(app_script_uri == NULL); |
963 app_script_uri = strdup(resolved_script_uri); | 991 app_script_uri = strdup(resolved_script_uri); |
964 } | 992 } |
965 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 993 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
966 } else { | 994 } else { |
967 // Load the specified application script into the newly created isolate. | 995 // Load the specified application script into the newly created isolate. |
968 Dart_Handle uri = | 996 Dart_Handle uri = |
969 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)); | 997 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)); |
970 CHECK_RESULT(uri); | 998 CHECK_RESULT(uri); |
971 if (!is_kernel) { | 999 if (!is_kernel) { |
972 result = Loader::LibraryTagHandler(Dart_kScriptTag, Dart_Null(), uri); | 1000 result = Loader::LibraryTagHandler(Dart_kScriptTag, Dart_Null(), uri); |
973 CHECK_RESULT(result); | 1001 CHECK_RESULT(result); |
974 } | 1002 } |
hausner
2017/01/24 00:50:55
else {
// Do the InitForSnapshot() call here?
}
Vyacheslav Egorov (Google)
2017/01/30 19:34:12
Done.
| |
975 | 1003 |
976 Dart_TimelineEvent("LoadScript", Dart_TimelineGetMicros(), | 1004 Dart_TimelineEvent("LoadScript", Dart_TimelineGetMicros(), |
977 Dart_GetMainPortId(), Dart_Timeline_Event_Async_End, 0, | 1005 Dart_GetMainPortId(), Dart_Timeline_Event_Async_End, 0, |
978 NULL, NULL); | 1006 NULL, NULL); |
979 | 1007 |
980 result = DartUtils::SetupIOLibrary(script_uri); | 1008 result = DartUtils::SetupIOLibrary(script_uri); |
981 CHECK_RESULT(result); | 1009 CHECK_RESULT(result); |
982 } | 1010 } |
983 | 1011 |
984 // Make the isolate runnable so that it is ready to handle messages. | 1012 // Make the isolate runnable so that it is ready to handle messages. |
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2049 Platform::Exit(Process::GlobalExitCode()); | 2077 Platform::Exit(Process::GlobalExitCode()); |
2050 } | 2078 } |
2051 | 2079 |
2052 } // namespace bin | 2080 } // namespace bin |
2053 } // namespace dart | 2081 } // namespace dart |
2054 | 2082 |
2055 int main(int argc, char** argv) { | 2083 int main(int argc, char** argv) { |
2056 dart::bin::main(argc, argv); | 2084 dart::bin::main(argc, argv); |
2057 UNREACHABLE(); | 2085 UNREACHABLE(); |
2058 } | 2086 } |
OLD | NEW |