| 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 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 "A snapshot was requested, but a secondary isolate " | 818 "A snapshot was requested, but a secondary isolate " |
| 819 "performed a hard exit (%" Pd64 ").\n", | 819 "performed a hard exit (%" Pd64 ").\n", |
| 820 exit_code); | 820 exit_code); |
| 821 Platform::Exit(kErrorExitCode); | 821 Platform::Exit(kErrorExitCode); |
| 822 } | 822 } |
| 823 if (exit_code == 0) { | 823 if (exit_code == 0) { |
| 824 Snapshot::GenerateAppJIT(snapshot_filename); | 824 Snapshot::GenerateAppJIT(snapshot_filename); |
| 825 } | 825 } |
| 826 } | 826 } |
| 827 | 827 |
| 828 // Returns newly created Isolate on success, NULL on failure. | |
| 829 static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate, | |
| 830 const char* script_uri, | |
| 831 const char* main, | |
| 832 const char* package_root, | |
| 833 const char* packages_config, | |
| 834 Dart_IsolateFlags* flags, | |
| 835 char** error, | |
| 836 int* exit_code) { | |
| 837 ASSERT(script_uri != NULL); | |
| 838 void* kernel_platform = NULL; | |
| 839 void* kernel_program = NULL; | |
| 840 AppSnapshot* app_snapshot = NULL; | |
| 841 | 828 |
| 842 #if defined(DART_PRECOMPILED_RUNTIME) | 829 static Dart_Isolate IsolateSetupHelper(Dart_Isolate isolate, |
| 843 // AOT: All isolates start from the app snapshot. | 830 bool is_main_isolate, |
| 844 bool isolate_run_app_snapshot = true; | 831 const char* script_uri, |
| 845 const uint8_t* isolate_snapshot_data = app_isolate_snapshot_data; | 832 const char* package_root, |
| 846 const uint8_t* isolate_snapshot_instructions = | 833 const char* packages_config, |
| 847 app_isolate_snapshot_instructions; | 834 void* kernel_program, |
| 848 #else | 835 bool set_native_resolvers, |
| 849 // JIT: Main isolate starts from the app snapshot, if any. Other isolates | 836 bool isolate_run_app_snapshot, |
| 850 // use the core libraries snapshot. | 837 char** error, |
| 851 bool isolate_run_app_snapshot = false; | 838 int* exit_code) { |
| 852 const uint8_t* isolate_snapshot_data = core_isolate_snapshot_data; | |
| 853 const uint8_t* isolate_snapshot_instructions = | |
| 854 core_isolate_snapshot_instructions; | |
| 855 const bool is_kernel_isolate = | |
| 856 strcmp(script_uri, DART_KERNEL_ISOLATE_NAME) == 0; | |
| 857 if (is_kernel_isolate) { | |
| 858 if (!dfe.UseDartFrontend()) { | |
| 859 *error = strdup("Kernel isolate not supported."); | |
| 860 return NULL; | |
| 861 } | |
| 862 script_uri = dfe.frontend_filename(); | |
| 863 if (packages_config == NULL) { | |
| 864 packages_config = commandline_packages_file; | |
| 865 } | |
| 866 } | |
| 867 if ((app_isolate_snapshot_data != NULL) && | |
| 868 (is_main_isolate || ((app_script_uri != NULL) && | |
| 869 (strcmp(script_uri, app_script_uri) == 0)))) { | |
| 870 isolate_run_app_snapshot = true; | |
| 871 isolate_snapshot_data = app_isolate_snapshot_data; | |
| 872 isolate_snapshot_instructions = app_isolate_snapshot_instructions; | |
| 873 } else if (!is_main_isolate) { | |
| 874 app_snapshot = Snapshot::TryReadAppSnapshot(script_uri); | |
| 875 if (app_snapshot != NULL) { | |
| 876 isolate_run_app_snapshot = true; | |
| 877 const uint8_t* ignore_vm_snapshot_data; | |
| 878 const uint8_t* ignore_vm_snapshot_instructions; | |
| 879 app_snapshot->SetBuffers( | |
| 880 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, | |
| 881 &isolate_snapshot_data, &isolate_snapshot_instructions); | |
| 882 } | |
| 883 } | |
| 884 const bool is_service_isolate = | |
| 885 strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0; | |
| 886 if (!is_kernel_isolate && !is_service_isolate) { | |
| 887 const uint8_t* platform_file = NULL; | |
| 888 if (dfe.UsePlatformBinary()) { | |
| 889 intptr_t platform_length = -1; | |
| 890 bool success = dfe.TryReadKernelFile(dfe.platform_binary_filename(), | |
| 891 &platform_file, &platform_length); | |
| 892 if (!success) { | |
| 893 *error = strdup("The platform binary is not a valid Dart Kernel file."); | |
| 894 *exit_code = kErrorExitCode; | |
| 895 return NULL; | |
| 896 } | |
| 897 kernel_platform = Dart_ReadKernelBinary(platform_file, platform_length); | |
| 898 } | |
| 899 | |
| 900 bool is_kernel = false; | |
| 901 const uint8_t* kernel_file = NULL; | |
| 902 intptr_t kernel_length = -1; | |
| 903 if (dfe.UseDartFrontend()) { | |
| 904 Dart_KernelCompilationResult result = Dart_CompileToKernel(script_uri); | |
| 905 *error = result.error; // Copy error message (if any). | |
| 906 switch (result.status) { | |
| 907 case Dart_KernelCompilationStatus_Ok: | |
| 908 is_kernel = true; | |
| 909 kernel_file = result.kernel; | |
| 910 kernel_length = result.kernel_size; | |
| 911 break; | |
| 912 case Dart_KernelCompilationStatus_Error: | |
| 913 *exit_code = kCompilationErrorExitCode; | |
| 914 break; | |
| 915 case Dart_KernelCompilationStatus_Crash: | |
| 916 *exit_code = kDartFrontendErrorExitCode; | |
| 917 break; | |
| 918 case Dart_KernelCompilationStatus_Unknown: | |
| 919 *exit_code = kErrorExitCode; | |
| 920 break; | |
| 921 } | |
| 922 if (!is_kernel) { | |
| 923 free(const_cast<uint8_t*>(platform_file)); | |
| 924 delete reinterpret_cast<kernel::Program*>(kernel_platform); | |
| 925 return NULL; | |
| 926 } | |
| 927 } else if (!isolate_run_app_snapshot) { | |
| 928 is_kernel = | |
| 929 dfe.TryReadKernelFile(script_uri, &kernel_file, &kernel_length); | |
| 930 } | |
| 931 | |
| 932 if (is_kernel) { | |
| 933 kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length); | |
| 934 } | |
| 935 } | |
| 936 #endif // !defined(DART_PRECOMPILED_RUNTIME) | |
| 937 | |
| 938 IsolateData* isolate_data = | |
| 939 new IsolateData(script_uri, package_root, packages_config, app_snapshot); | |
| 940 if (is_main_isolate && (snapshot_deps_filename != NULL)) { | |
| 941 isolate_data->set_dependencies(new MallocGrowableArray<char*>()); | |
| 942 } | |
| 943 Dart_Isolate isolate = NULL; | |
| 944 if (kernel_platform != NULL) { | |
| 945 isolate = Dart_CreateIsolateFromKernel(script_uri, main, kernel_platform, | |
| 946 flags, isolate_data, error); | |
| 947 } else if (kernel_program != NULL) { | |
| 948 isolate = Dart_CreateIsolateFromKernel(script_uri, main, kernel_program, | |
| 949 flags, isolate_data, error); | |
| 950 } else { | |
| 951 isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, | |
| 952 isolate_snapshot_instructions, flags, | |
| 953 isolate_data, error); | |
| 954 } | |
| 955 if (isolate == NULL) { | |
| 956 delete isolate_data; | |
| 957 return NULL; | |
| 958 } | |
| 959 | |
| 960 Dart_EnterScope(); | 839 Dart_EnterScope(); |
| 961 | 840 |
| 962 // Set up the library tag handler for this isolate. | 841 // Set up the library tag handler for this isolate. |
| 963 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); | 842 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); |
| 964 CHECK_RESULT(result); | 843 CHECK_RESULT(result); |
| 965 | 844 |
| 966 if (kernel_program != NULL) { | 845 if (kernel_program != NULL) { |
| 967 Dart_Handle result = Dart_LoadKernel(kernel_program); | 846 Dart_Handle result = Dart_LoadKernel(kernel_program); |
| 968 CHECK_RESULT(result); | 847 CHECK_RESULT(result); |
| 969 } | 848 } |
| 970 if ((kernel_platform != NULL) || (isolate_snapshot_data != NULL)) { | 849 if (set_native_resolvers) { |
| 971 // Setup the native resolver as the snapshot does not carry it. | 850 // Setup the native resolver as the snapshot does not carry it. |
| 972 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 851 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
| 973 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 852 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
| 974 } | 853 } |
| 975 if (isolate_run_app_snapshot) { | 854 if (isolate_run_app_snapshot) { |
| 976 Dart_Handle result = Loader::ReloadNativeExtensions(); | 855 Dart_Handle result = Loader::ReloadNativeExtensions(); |
| 977 CHECK_RESULT(result); | 856 CHECK_RESULT(result); |
| 978 } | 857 } |
| 979 | 858 |
| 980 if (Dart_IsServiceIsolate(isolate)) { | |
| 981 // If this is the service isolate, load embedder specific bits and return. | |
| 982 bool skip_library_load = isolate_run_app_snapshot; | |
| 983 if (!VmService::Setup(vm_service_server_ip, vm_service_server_port, | |
| 984 skip_library_load, vm_service_dev_mode, | |
| 985 trace_loading)) { | |
| 986 *error = strdup(VmService::GetErrorMessage()); | |
| 987 return NULL; | |
| 988 } | |
| 989 if (compile_all) { | |
| 990 result = Dart_CompileAll(); | |
| 991 CHECK_RESULT(result); | |
| 992 } | |
| 993 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | |
| 994 CHECK_RESULT(result); | |
| 995 Dart_ExitScope(); | |
| 996 Dart_ExitIsolate(); | |
| 997 return isolate; | |
| 998 } | |
| 999 | |
| 1000 // Prepare builtin and other core libraries for use to resolve URIs. | 859 // Prepare builtin and other core libraries for use to resolve URIs. |
| 1001 // Set up various closures, e.g: printing, timers etc. | 860 // Set up various closures, e.g: printing, timers etc. |
| 1002 // Set up 'package root' for URI resolution. | 861 // Set up 'package root' for URI resolution. |
| 1003 result = DartUtils::PrepareForScriptLoading(false, trace_loading); | 862 result = DartUtils::PrepareForScriptLoading(false, trace_loading); |
| 1004 CHECK_RESULT(result); | 863 CHECK_RESULT(result); |
| 1005 | 864 |
| 1006 // Set up the load port provided by the service isolate so that we can | 865 // Set up the load port provided by the service isolate so that we can |
| 1007 // load scripts. | 866 // load scripts. |
| 1008 result = DartUtils::SetupServiceLoadPort(); | 867 result = DartUtils::SetupServiceLoadPort(); |
| 1009 CHECK_RESULT(result); | 868 CHECK_RESULT(result); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 if (!retval) { | 922 if (!retval) { |
| 1064 *error = strdup("Invalid isolate state - Unable to make it runnable"); | 923 *error = strdup("Invalid isolate state - Unable to make it runnable"); |
| 1065 Dart_EnterIsolate(isolate); | 924 Dart_EnterIsolate(isolate); |
| 1066 Dart_ShutdownIsolate(); | 925 Dart_ShutdownIsolate(); |
| 1067 return NULL; | 926 return NULL; |
| 1068 } | 927 } |
| 1069 | 928 |
| 1070 return isolate; | 929 return isolate; |
| 1071 } | 930 } |
| 1072 | 931 |
| 932 |
| 933 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 934 // Returns newly created Kernel Isolate on success, NULL on failure. |
| 935 // For now we only support the kernel isolate coming up from an |
| 936 // application snapshot or from sources which are compiled by the |
| 937 // VM parser. |
| 938 static Dart_Isolate CreateAndSetupKernelIsolate(const char* main, |
| 939 const char* package_root, |
| 940 const char* packages_config, |
| 941 Dart_IsolateFlags* flags, |
| 942 char** error, |
| 943 int* exit_code) { |
| 944 if (!dfe.UseDartFrontend()) { |
| 945 *error = strdup("Kernel isolate not supported."); |
| 946 return NULL; |
| 947 } |
| 948 const char* script_uri = dfe.frontend_filename(); |
| 949 if (packages_config == NULL) { |
| 950 packages_config = commandline_packages_file; |
| 951 } |
| 952 |
| 953 // Kernel isolate uses an app snapshot or the core libraries snapshot. |
| 954 bool isolate_run_app_snapshot = false; |
| 955 const uint8_t* isolate_snapshot_data = core_isolate_snapshot_data; |
| 956 const uint8_t* isolate_snapshot_instructions = |
| 957 core_isolate_snapshot_instructions; |
| 958 AppSnapshot* app_snapshot = Snapshot::TryReadAppSnapshot(script_uri); |
| 959 if (app_snapshot != NULL) { |
| 960 isolate_run_app_snapshot = true; |
| 961 const uint8_t* ignore_vm_snapshot_data; |
| 962 const uint8_t* ignore_vm_snapshot_instructions; |
| 963 app_snapshot->SetBuffers( |
| 964 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, |
| 965 &isolate_snapshot_data, &isolate_snapshot_instructions); |
| 966 } |
| 967 |
| 968 IsolateData* isolate_data = |
| 969 new IsolateData(script_uri, package_root, packages_config, app_snapshot); |
| 970 Dart_Isolate isolate = Dart_CreateIsolate( |
| 971 script_uri, main, isolate_snapshot_data, isolate_snapshot_instructions, |
| 972 flags, isolate_data, error); |
| 973 if (isolate == NULL) { |
| 974 delete isolate_data; |
| 975 return NULL; |
| 976 } |
| 977 |
| 978 return IsolateSetupHelper(isolate, false, script_uri, package_root, |
| 979 packages_config, NULL, isolate_snapshot_data, |
| 980 isolate_run_app_snapshot, error, exit_code); |
| 981 } |
| 982 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| 983 |
| 984 |
| 985 // Returns newly created Service Isolate on success, NULL on failure. |
| 986 // For now we only support the service isolate coming up from sources |
| 987 // which are compiled by the VM parser. |
| 988 static Dart_Isolate CreateAndSetupServiceIsolate(const char* script_uri, |
| 989 const char* main, |
| 990 const char* package_root, |
| 991 const char* packages_config, |
| 992 Dart_IsolateFlags* flags, |
| 993 char** error, |
| 994 int* exit_code) { |
| 995 ASSERT(script_uri != NULL); |
| 996 |
| 997 #if defined(DART_PRECOMPILED_RUNTIME) |
| 998 // AOT: All isolates start from the app snapshot. |
| 999 bool isolate_run_app_snapshot = true; |
| 1000 const uint8_t* isolate_snapshot_data = app_isolate_snapshot_data; |
| 1001 const uint8_t* isolate_snapshot_instructions = |
| 1002 app_isolate_snapshot_instructions; |
| 1003 #else |
| 1004 // JIT: Service isolate uses the core libraries snapshot. |
| 1005 bool isolate_run_app_snapshot = false; |
| 1006 const uint8_t* isolate_snapshot_data = core_isolate_snapshot_data; |
| 1007 const uint8_t* isolate_snapshot_instructions = |
| 1008 core_isolate_snapshot_instructions; |
| 1009 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| 1010 |
| 1011 IsolateData* isolate_data = |
| 1012 new IsolateData(script_uri, package_root, packages_config, NULL); |
| 1013 Dart_Isolate isolate = Dart_CreateIsolate( |
| 1014 script_uri, main, isolate_snapshot_data, isolate_snapshot_instructions, |
| 1015 flags, isolate_data, error); |
| 1016 if (isolate == NULL) { |
| 1017 delete isolate_data; |
| 1018 return NULL; |
| 1019 } |
| 1020 |
| 1021 Dart_EnterScope(); |
| 1022 |
| 1023 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); |
| 1024 CHECK_RESULT(result); |
| 1025 |
| 1026 // Load embedder specific bits and return. |
| 1027 bool skip_library_load = isolate_run_app_snapshot; |
| 1028 if (!VmService::Setup(vm_service_server_ip, vm_service_server_port, |
| 1029 skip_library_load, vm_service_dev_mode, |
| 1030 trace_loading)) { |
| 1031 *error = strdup(VmService::GetErrorMessage()); |
| 1032 return NULL; |
| 1033 } |
| 1034 if (compile_all) { |
| 1035 result = Dart_CompileAll(); |
| 1036 CHECK_RESULT(result); |
| 1037 } |
| 1038 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
| 1039 CHECK_RESULT(result); |
| 1040 Dart_ExitScope(); |
| 1041 Dart_ExitIsolate(); |
| 1042 return isolate; |
| 1043 } |
| 1044 |
| 1045 |
| 1046 // Returns newly created Isolate on success, NULL on failure. |
| 1047 static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate, |
| 1048 const char* script_uri, |
| 1049 const char* main, |
| 1050 const char* package_root, |
| 1051 const char* packages_config, |
| 1052 Dart_IsolateFlags* flags, |
| 1053 char** error, |
| 1054 int* exit_code) { |
| 1055 ASSERT(script_uri != NULL); |
| 1056 void* kernel_platform = NULL; |
| 1057 void* kernel_program = NULL; |
| 1058 AppSnapshot* app_snapshot = NULL; |
| 1059 |
| 1060 #if defined(DART_PRECOMPILED_RUNTIME) |
| 1061 // AOT: All isolates start from the app snapshot. |
| 1062 bool isolate_run_app_snapshot = true; |
| 1063 const uint8_t* isolate_snapshot_data = app_isolate_snapshot_data; |
| 1064 const uint8_t* isolate_snapshot_instructions = |
| 1065 app_isolate_snapshot_instructions; |
| 1066 #else |
| 1067 // JIT: Main isolate starts from the app snapshot, if any. Other isolates |
| 1068 // use the core libraries snapshot. |
| 1069 bool isolate_run_app_snapshot = false; |
| 1070 const uint8_t* isolate_snapshot_data = core_isolate_snapshot_data; |
| 1071 const uint8_t* isolate_snapshot_instructions = |
| 1072 core_isolate_snapshot_instructions; |
| 1073 if ((app_isolate_snapshot_data != NULL) && |
| 1074 (is_main_isolate || ((app_script_uri != NULL) && |
| 1075 (strcmp(script_uri, app_script_uri) == 0)))) { |
| 1076 isolate_run_app_snapshot = true; |
| 1077 isolate_snapshot_data = app_isolate_snapshot_data; |
| 1078 isolate_snapshot_instructions = app_isolate_snapshot_instructions; |
| 1079 } else if (!is_main_isolate) { |
| 1080 app_snapshot = Snapshot::TryReadAppSnapshot(script_uri); |
| 1081 if (app_snapshot != NULL) { |
| 1082 isolate_run_app_snapshot = true; |
| 1083 const uint8_t* ignore_vm_snapshot_data; |
| 1084 const uint8_t* ignore_vm_snapshot_instructions; |
| 1085 app_snapshot->SetBuffers( |
| 1086 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, |
| 1087 &isolate_snapshot_data, &isolate_snapshot_instructions); |
| 1088 } |
| 1089 } |
| 1090 const uint8_t* platform_file = NULL; |
| 1091 if (dfe.UsePlatformBinary()) { |
| 1092 intptr_t platform_length = -1; |
| 1093 bool success = dfe.TryReadKernelFile(dfe.platform_binary_filename(), |
| 1094 &platform_file, &platform_length); |
| 1095 if (!success) { |
| 1096 *error = strdup("The platform binary is not a valid Dart Kernel file."); |
| 1097 *exit_code = kErrorExitCode; |
| 1098 return NULL; |
| 1099 } |
| 1100 kernel_platform = Dart_ReadKernelBinary(platform_file, platform_length); |
| 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 } |
| 1137 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| 1138 |
| 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; |
| 1145 if (kernel_platform != NULL) { |
| 1146 isolate = Dart_CreateIsolateFromKernel(script_uri, main, kernel_platform, |
| 1147 flags, isolate_data, error); |
| 1148 } else if (kernel_program != NULL) { |
| 1149 isolate = Dart_CreateIsolateFromKernel(script_uri, main, kernel_program, |
| 1150 flags, isolate_data, error); |
| 1151 } else { |
| 1152 isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, |
| 1153 isolate_snapshot_instructions, flags, |
| 1154 isolate_data, error); |
| 1155 } |
| 1156 if (isolate == NULL) { |
| 1157 delete isolate_data; |
| 1158 return NULL; |
| 1159 } |
| 1160 |
| 1161 return IsolateSetupHelper(isolate, is_main_isolate, script_uri, package_root, |
| 1162 packages_config, kernel_program, |
| 1163 (kernel_program || isolate_snapshot_data), |
| 1164 isolate_run_app_snapshot, error, exit_code); |
| 1165 } |
| 1166 |
| 1073 #undef CHECK_RESULT | 1167 #undef CHECK_RESULT |
| 1074 | 1168 |
| 1075 | 1169 |
| 1076 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, | 1170 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, |
| 1077 const char* main, | 1171 const char* main, |
| 1078 const char* package_root, | 1172 const char* package_root, |
| 1079 const char* package_config, | 1173 const char* package_config, |
| 1080 Dart_IsolateFlags* flags, | 1174 Dart_IsolateFlags* flags, |
| 1081 void* data, | 1175 void* data, |
| 1082 char** error) { | 1176 char** error) { |
| 1083 // The VM should never call the isolate helper with a NULL flags. | 1177 // The VM should never call the isolate helper with a NULL flags. |
| 1084 ASSERT(flags != NULL); | 1178 ASSERT(flags != NULL); |
| 1085 ASSERT(flags->version == DART_FLAGS_CURRENT_VERSION); | 1179 ASSERT(flags->version == DART_FLAGS_CURRENT_VERSION); |
| 1086 if ((package_root != NULL) && (package_config != NULL)) { | 1180 if ((package_root != NULL) && (package_config != NULL)) { |
| 1087 *error = strdup( | 1181 *error = strdup( |
| 1088 "Invalid arguments - Cannot simultaneously specify " | 1182 "Invalid arguments - Cannot simultaneously specify " |
| 1089 "package root and package map."); | 1183 "package root and package map."); |
| 1090 return NULL; | 1184 return NULL; |
| 1091 } | 1185 } |
| 1092 | 1186 |
| 1187 int exit_code = 0; |
| 1188 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 1189 if (strcmp(script_uri, DART_KERNEL_ISOLATE_NAME) == 0) { |
| 1190 return CreateAndSetupKernelIsolate(main, package_root, package_config, |
| 1191 flags, error, &exit_code); |
| 1192 } |
| 1193 #endif |
| 1194 if (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0) { |
| 1195 return CreateAndSetupServiceIsolate(script_uri, main, package_root, |
| 1196 package_config, flags, error, |
| 1197 &exit_code); |
| 1198 } |
| 1093 bool is_main_isolate = false; | 1199 bool is_main_isolate = false; |
| 1094 int exit_code = 0; | |
| 1095 return CreateIsolateAndSetupHelper(is_main_isolate, script_uri, main, | 1200 return CreateIsolateAndSetupHelper(is_main_isolate, script_uri, main, |
| 1096 package_root, package_config, flags, error, | 1201 package_root, package_config, flags, error, |
| 1097 &exit_code); | 1202 &exit_code); |
| 1098 } | 1203 } |
| 1099 | 1204 |
| 1100 | 1205 |
| 1101 static void PrintVersion() { | 1206 static void PrintVersion() { |
| 1102 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); | 1207 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); |
| 1103 } | 1208 } |
| 1104 | 1209 |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1770 Platform::Exit(Process::GlobalExitCode()); | 1875 Platform::Exit(Process::GlobalExitCode()); |
| 1771 } | 1876 } |
| 1772 | 1877 |
| 1773 } // namespace bin | 1878 } // namespace bin |
| 1774 } // namespace dart | 1879 } // namespace dart |
| 1775 | 1880 |
| 1776 int main(int argc, char** argv) { | 1881 int main(int argc, char** argv) { |
| 1777 dart::bin::main(argc, argv); | 1882 dart::bin::main(argc, argv); |
| 1778 UNREACHABLE(); | 1883 UNREACHABLE(); |
| 1779 } | 1884 } |
| OLD | NEW |