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 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 } \ | 802 } \ |
803 Dart_ExitScope(); \ | 803 Dart_ExitScope(); \ |
804 Dart_ShutdownIsolate(); \ | 804 Dart_ShutdownIsolate(); \ |
805 return NULL; \ | 805 return NULL; \ |
806 } | 806 } |
807 | 807 |
808 | 808 |
809 static void SnapshotOnExitHook(int64_t exit_code); | 809 static void SnapshotOnExitHook(int64_t exit_code); |
810 | 810 |
811 | 811 |
812 static const int64_t kAppSnapshotHeaderSize = 5 * kInt64Size; | |
813 static const int64_t kAppSnapshotMagicNumber = 0xf6f6dcdc; | |
814 static const int64_t kAppSnapshotPageSize = 4 * KB; | |
815 | |
816 | |
817 static bool ReadAppSnapshotBlobs(const char* script_name, | |
818 const uint8_t** vm_data_buffer, | |
819 const uint8_t** vm_instructions_buffer, | |
820 const uint8_t** isolate_data_buffer, | |
821 const uint8_t** isolate_instructions_buffer) { | |
822 File* file = File::Open(script_name, File::kRead); | |
823 if (file == NULL) { | |
824 return false; | |
825 } | |
826 if (file->Length() < kAppSnapshotHeaderSize) { | |
827 file->Release(); | |
828 return false; | |
829 } | |
830 int64_t header[5]; | |
831 ASSERT(sizeof(header) == kAppSnapshotHeaderSize); | |
832 if (!file->ReadFully(&header, kAppSnapshotHeaderSize)) { | |
833 file->Release(); | |
834 return false; | |
835 } | |
836 if (header[0] != kAppSnapshotMagicNumber) { | |
837 file->Release(); | |
838 return false; | |
839 } | |
840 | |
841 int64_t vm_data_size = header[1]; | |
842 int64_t vm_data_position = | |
843 Utils::RoundUp(file->Position(), kAppSnapshotPageSize); | |
844 int64_t vm_instructions_size = header[2]; | |
845 int64_t vm_instructions_position = vm_data_position + vm_data_size; | |
846 if (vm_instructions_size != 0) { | |
847 vm_instructions_position = | |
848 Utils::RoundUp(vm_instructions_position, kAppSnapshotPageSize); | |
849 } | |
850 int64_t isolate_data_size = header[3]; | |
851 int64_t isolate_data_position = Utils::RoundUp( | |
852 vm_instructions_position + vm_instructions_size, kAppSnapshotPageSize); | |
853 int64_t isolate_instructions_size = header[4]; | |
854 int64_t isolate_instructions_position = | |
855 isolate_data_position + isolate_data_size; | |
856 if (isolate_instructions_size != 0) { | |
857 isolate_instructions_position = | |
858 Utils::RoundUp(isolate_instructions_position, kAppSnapshotPageSize); | |
859 } | |
860 | |
861 if (vm_data_size != 0) { | |
862 *vm_data_buffer = reinterpret_cast<const uint8_t*>( | |
863 file->Map(File::kReadOnly, vm_data_position, vm_data_size)); | |
864 if (vm_data_buffer == NULL) { | |
865 Log::PrintErr("Failed to memory map snapshot\n"); | |
866 Platform::Exit(kErrorExitCode); | |
867 } | |
868 } | |
869 | |
870 if (vm_instructions_size != 0) { | |
871 *vm_instructions_buffer = reinterpret_cast<const uint8_t*>(file->Map( | |
872 File::kReadExecute, vm_instructions_position, vm_instructions_size)); | |
873 if (*vm_instructions_buffer == NULL) { | |
874 Log::PrintErr("Failed to memory map snapshot\n"); | |
875 Platform::Exit(kErrorExitCode); | |
876 } | |
877 } | |
878 | |
879 *isolate_data_buffer = reinterpret_cast<const uint8_t*>( | |
880 file->Map(File::kReadOnly, isolate_data_position, isolate_data_size)); | |
881 if (isolate_data_buffer == NULL) { | |
882 Log::PrintErr("Failed to memory map snapshot\n"); | |
883 Platform::Exit(kErrorExitCode); | |
884 } | |
885 | |
886 if (isolate_instructions_size == 0) { | |
887 *isolate_instructions_buffer = NULL; | |
888 } else { | |
889 *isolate_instructions_buffer = reinterpret_cast<const uint8_t*>( | |
890 file->Map(File::kReadExecute, isolate_instructions_position, | |
891 isolate_instructions_size)); | |
892 if (*isolate_instructions_buffer == NULL) { | |
893 Log::PrintErr("Failed to memory map snapshot\n"); | |
894 Platform::Exit(kErrorExitCode); | |
895 } | |
896 } | |
897 | |
898 file->Release(); | |
899 return true; | |
900 } | |
901 | |
902 | |
903 #if defined(DART_PRECOMPILED_RUNTIME) | |
904 static bool ReadAppSnapshotDynamicLibrary( | |
905 const char* script_name, | |
906 const uint8_t** vm_data_buffer, | |
907 const uint8_t** vm_instructions_buffer, | |
908 const uint8_t** isolate_data_buffer, | |
909 const uint8_t** isolate_instructions_buffer) { | |
910 void* library = Extensions::LoadExtensionLibrary(script_name); | |
911 if (library == NULL) { | |
912 return false; | |
913 } | |
914 | |
915 *vm_data_buffer = reinterpret_cast<const uint8_t*>( | |
916 Extensions::ResolveSymbol(library, kVmSnapshotDataSymbolName)); | |
917 if (*vm_data_buffer == NULL) { | |
918 Log::PrintErr("Failed to resolve symbol '%s'\n", kVmSnapshotDataSymbolName); | |
919 Platform::Exit(kErrorExitCode); | |
920 } | |
921 | |
922 *vm_instructions_buffer = reinterpret_cast<const uint8_t*>( | |
923 Extensions::ResolveSymbol(library, kVmSnapshotInstructionsSymbolName)); | |
924 if (*vm_instructions_buffer == NULL) { | |
925 Log::PrintErr("Failed to resolve symbol '%s'\n", | |
926 kVmSnapshotInstructionsSymbolName); | |
927 Platform::Exit(kErrorExitCode); | |
928 } | |
929 | |
930 *isolate_data_buffer = reinterpret_cast<const uint8_t*>( | |
931 Extensions::ResolveSymbol(library, kIsolateSnapshotDataSymbolName)); | |
932 if (*isolate_data_buffer == NULL) { | |
933 Log::PrintErr("Failed to resolve symbol '%s'\n", | |
934 kIsolateSnapshotDataSymbolName); | |
935 Platform::Exit(kErrorExitCode); | |
936 } | |
937 | |
938 *isolate_instructions_buffer = | |
939 reinterpret_cast<const uint8_t*>(Extensions::ResolveSymbol( | |
940 library, kIsolateSnapshotInstructionsSymbolName)); | |
941 if (*isolate_instructions_buffer == NULL) { | |
942 Log::PrintErr("Failed to resolve symbol '%s'\n", | |
943 kIsolateSnapshotInstructionsSymbolName); | |
944 Platform::Exit(kErrorExitCode); | |
945 } | |
946 | |
947 return true; | |
948 } | |
949 #endif // defined(DART_PRECOMPILED_RUNTIME) | |
950 | |
951 | |
952 static bool ReadAppSnapshot(const char* script_name, | |
953 const uint8_t** vm_data_buffer, | |
954 const uint8_t** vm_instructions_buffer, | |
955 const uint8_t** isolate_data_buffer, | |
956 const uint8_t** isolate_instructions_buffer) { | |
957 if (File::GetType(script_name, true) != File::kIsFile) { | |
958 // If 'script_name' refers to a pipe, don't read to check for an app | |
959 // snapshot since we cannot rewind if it isn't (and couldn't mmap it in | |
960 // anyway if it was). | |
961 return false; | |
962 } | |
963 if (ReadAppSnapshotBlobs(script_name, vm_data_buffer, vm_instructions_buffer, | |
964 isolate_data_buffer, isolate_instructions_buffer)) { | |
965 return true; | |
966 } | |
967 #if defined(DART_PRECOMPILED_RUNTIME) | |
968 // For testing AOT with the standalone embedder, we also support loading | |
969 // from a dynamic library to simulate what happens on iOS. | |
970 return ReadAppSnapshotDynamicLibrary( | |
971 script_name, vm_data_buffer, vm_instructions_buffer, isolate_data_buffer, | |
972 isolate_instructions_buffer); | |
973 #else | |
974 return false; | |
975 #endif // defined(DART_PRECOMPILED_RUNTIME) | |
976 } | |
977 | |
978 | |
979 // Returns true on success, false on failure. | 812 // Returns true on success, false on failure. |
980 static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate, | 813 static Dart_Isolate CreateIsolateAndSetupHelper(bool is_main_isolate, |
981 const char* script_uri, | 814 const char* script_uri, |
982 const char* main, | 815 const char* main, |
983 const char* package_root, | 816 const char* package_root, |
984 const char* packages_config, | 817 const char* packages_config, |
985 Dart_IsolateFlags* flags, | 818 Dart_IsolateFlags* flags, |
986 char** error, | 819 char** error, |
987 int* exit_code) { | 820 int* exit_code) { |
988 ASSERT(script_uri != NULL); | 821 ASSERT(script_uri != NULL); |
989 if (strcmp(script_uri, DART_KERNEL_ISOLATE_NAME) == 0) { | 822 if (strcmp(script_uri, DART_KERNEL_ISOLATE_NAME) == 0) { |
990 if (!use_dart_frontend) { | 823 if (!use_dart_frontend) { |
991 *error = strdup("Kernel isolate not supported."); | 824 *error = strdup("Kernel isolate not supported."); |
992 return NULL; | 825 return NULL; |
993 } | 826 } else { |
994 script_uri = frontend_filename; | 827 if (packages_config == NULL) { |
995 if (packages_config == NULL) { | 828 packages_config = commandline_packages_file; |
996 packages_config = commandline_packages_file; | 829 } |
997 } | 830 } |
998 } | 831 } |
999 | 832 |
1000 #if defined(DART_PRECOMPILED_RUNTIME) | 833 #if defined(DART_PRECOMPILED_RUNTIME) |
1001 // AOT: All isolates start from the app snapshot. | 834 // AOT: All isolates start from the app snapshot. |
1002 bool isolate_run_app_snapshot = true; | 835 bool isolate_run_app_snapshot = true; |
1003 const uint8_t* isolate_snapshot_data = app_isolate_snapshot_data; | 836 const uint8_t* isolate_snapshot_data = app_isolate_snapshot_data; |
1004 const uint8_t* isolate_snapshot_instructions = | 837 const uint8_t* isolate_snapshot_instructions = |
1005 app_isolate_snapshot_instructions; | 838 app_isolate_snapshot_instructions; |
1006 #else | 839 #else |
1007 // JIT: Main isolate starts from the app snapshot, if any. Other isolates | 840 // JIT: Main isolate starts from the app snapshot, if any. Other isolates |
1008 // use the core libraries snapshot. | 841 // use the core libraries snapshot. |
1009 bool isolate_run_app_snapshot = false; | 842 bool isolate_run_app_snapshot = false; |
1010 const uint8_t* isolate_snapshot_data = core_isolate_snapshot_data; | 843 const uint8_t* isolate_snapshot_data = core_isolate_snapshot_data; |
1011 const uint8_t* isolate_snapshot_instructions = | 844 const uint8_t* isolate_snapshot_instructions = |
1012 core_isolate_snapshot_instructions; | 845 core_isolate_snapshot_instructions; |
1013 if ((app_isolate_snapshot_data != NULL) && | 846 if ((app_isolate_snapshot_data != NULL) && |
1014 (is_main_isolate || ((app_script_uri != NULL) && | 847 (is_main_isolate || ((app_script_uri != NULL) && |
1015 (strcmp(script_uri, app_script_uri) == 0)))) { | 848 (strcmp(script_uri, app_script_uri) == 0)))) { |
1016 isolate_run_app_snapshot = true; | 849 isolate_run_app_snapshot = true; |
1017 isolate_snapshot_data = app_isolate_snapshot_data; | 850 isolate_snapshot_data = app_isolate_snapshot_data; |
1018 isolate_snapshot_instructions = app_isolate_snapshot_instructions; | 851 isolate_snapshot_instructions = app_isolate_snapshot_instructions; |
1019 } else if (!is_main_isolate) { | |
1020 const uint8_t* file_vm_snapshot_data = NULL; | |
1021 const uint8_t* file_vm_snapshot_instructions = NULL; | |
1022 const uint8_t* file_isolate_snapshot_data = NULL; | |
1023 const uint8_t* file_isolate_snapshot_instructions = NULL; | |
1024 if (ReadAppSnapshot( | |
1025 script_uri, &file_vm_snapshot_data, &file_vm_snapshot_instructions, | |
1026 &file_isolate_snapshot_data, &file_isolate_snapshot_instructions)) { | |
1027 // TODO(rmacnak): We are leaking the snapshot when the isolate shuts down. | |
1028 isolate_run_app_snapshot = true; | |
1029 isolate_snapshot_data = file_isolate_snapshot_data; | |
1030 isolate_snapshot_instructions = file_isolate_snapshot_instructions; | |
1031 } | |
1032 } | 852 } |
1033 #endif | 853 #endif |
1034 | 854 |
1035 // If the script is a Kernel binary, then we will try to bootstrap from the | 855 // If the script is a Kernel binary, then we will try to bootstrap from the |
1036 // script. | 856 // script. |
1037 const uint8_t* kernel_file = NULL; | 857 const uint8_t* kernel_file = NULL; |
1038 intptr_t kernel_length = -1; | 858 intptr_t kernel_length = -1; |
1039 const bool is_kernel = | 859 const bool is_kernel = |
1040 !isolate_run_app_snapshot && | 860 !isolate_run_app_snapshot && |
1041 TryReadKernel(script_uri, &kernel_file, &kernel_length); | 861 TryReadKernel(script_uri, &kernel_file, &kernel_length); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 // Set up various closures, e.g: printing, timers etc. | 922 // Set up various closures, e.g: printing, timers etc. |
1103 // Set up 'package root' for URI resolution. | 923 // Set up 'package root' for URI resolution. |
1104 result = DartUtils::PrepareForScriptLoading(false, trace_loading); | 924 result = DartUtils::PrepareForScriptLoading(false, trace_loading); |
1105 CHECK_RESULT(result); | 925 CHECK_RESULT(result); |
1106 | 926 |
1107 // Set up the load port provided by the service isolate so that we can | 927 // Set up the load port provided by the service isolate so that we can |
1108 // load scripts. | 928 // load scripts. |
1109 result = DartUtils::SetupServiceLoadPort(); | 929 result = DartUtils::SetupServiceLoadPort(); |
1110 CHECK_RESULT(result); | 930 CHECK_RESULT(result); |
1111 | 931 |
| 932 if (Dart_IsKernelIsolate(isolate)) { |
| 933 script_uri = frontend_filename; |
| 934 } |
| 935 |
1112 // Setup package root if specified. | 936 // Setup package root if specified. |
1113 result = DartUtils::SetupPackageRoot(package_root, packages_config); | 937 result = DartUtils::SetupPackageRoot(package_root, packages_config); |
1114 CHECK_RESULT(result); | 938 CHECK_RESULT(result); |
1115 | 939 |
1116 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 940 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
1117 CHECK_RESULT(result); | 941 CHECK_RESULT(result); |
1118 | 942 |
1119 if (!Dart_IsKernelIsolate(isolate) && use_dart_frontend) { | 943 if (!Dart_IsKernelIsolate(isolate) && use_dart_frontend) { |
1120 // This must be the main script to be loaded. Wait for Kernel isolate | 944 // This must be the main script to be loaded. Wait for Kernel isolate |
1121 // to finish initialization. | 945 // to finish initialization. |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 ErrorExit(kErrorExitCode, "Unable to write file %s for writing snapshot\n", | 1281 ErrorExit(kErrorExitCode, "Unable to write file %s for writing snapshot\n", |
1458 filename); | 1282 filename); |
1459 } | 1283 } |
1460 file->Release(); | 1284 file->Release(); |
1461 if (concat != NULL) { | 1285 if (concat != NULL) { |
1462 delete concat; | 1286 delete concat; |
1463 } | 1287 } |
1464 } | 1288 } |
1465 | 1289 |
1466 | 1290 |
| 1291 static const int64_t kAppSnapshotHeaderSize = 5 * sizeof(int64_t); // NOLINT |
| 1292 static const int64_t kAppSnapshotMagicNumber = 0xf6f6dcdc; |
| 1293 static const int64_t kAppSnapshotPageSize = 4 * KB; |
| 1294 |
| 1295 |
| 1296 static bool ReadAppSnapshotBlobs(const char* script_name, |
| 1297 const uint8_t** vm_data_buffer, |
| 1298 const uint8_t** vm_instructions_buffer, |
| 1299 const uint8_t** isolate_data_buffer, |
| 1300 const uint8_t** isolate_instructions_buffer) { |
| 1301 File* file = File::Open(script_name, File::kRead); |
| 1302 if (file == NULL) { |
| 1303 return false; |
| 1304 } |
| 1305 if (file->Length() < kAppSnapshotHeaderSize) { |
| 1306 file->Release(); |
| 1307 return false; |
| 1308 } |
| 1309 int64_t header[5]; |
| 1310 ASSERT(sizeof(header) == kAppSnapshotHeaderSize); |
| 1311 if (!file->ReadFully(&header, kAppSnapshotHeaderSize)) { |
| 1312 file->Release(); |
| 1313 return false; |
| 1314 } |
| 1315 if (header[0] != kAppSnapshotMagicNumber) { |
| 1316 file->Release(); |
| 1317 return false; |
| 1318 } |
| 1319 |
| 1320 int64_t vm_data_size = header[1]; |
| 1321 int64_t vm_data_position = |
| 1322 Utils::RoundUp(file->Position(), kAppSnapshotPageSize); |
| 1323 int64_t vm_instructions_size = header[2]; |
| 1324 int64_t vm_instructions_position = vm_data_position + vm_data_size; |
| 1325 if (vm_instructions_size != 0) { |
| 1326 vm_instructions_position = |
| 1327 Utils::RoundUp(vm_instructions_position, kAppSnapshotPageSize); |
| 1328 } |
| 1329 int64_t isolate_data_size = header[3]; |
| 1330 int64_t isolate_data_position = Utils::RoundUp( |
| 1331 vm_instructions_position + vm_instructions_size, kAppSnapshotPageSize); |
| 1332 int64_t isolate_instructions_size = header[4]; |
| 1333 int64_t isolate_instructions_position = |
| 1334 isolate_data_position + isolate_data_size; |
| 1335 if (isolate_instructions_size != 0) { |
| 1336 isolate_instructions_position = |
| 1337 Utils::RoundUp(isolate_instructions_position, kAppSnapshotPageSize); |
| 1338 } |
| 1339 |
| 1340 if (vm_data_size != 0) { |
| 1341 *vm_data_buffer = reinterpret_cast<const uint8_t*>( |
| 1342 file->Map(File::kReadOnly, vm_data_position, vm_data_size)); |
| 1343 if (vm_data_buffer == NULL) { |
| 1344 Log::PrintErr("Failed to memory map snapshot\n"); |
| 1345 Platform::Exit(kErrorExitCode); |
| 1346 } |
| 1347 } |
| 1348 |
| 1349 if (vm_instructions_size != 0) { |
| 1350 *vm_instructions_buffer = reinterpret_cast<const uint8_t*>(file->Map( |
| 1351 File::kReadExecute, vm_instructions_position, vm_instructions_size)); |
| 1352 if (*vm_instructions_buffer == NULL) { |
| 1353 Log::PrintErr("Failed to memory map snapshot\n"); |
| 1354 Platform::Exit(kErrorExitCode); |
| 1355 } |
| 1356 } |
| 1357 |
| 1358 *isolate_data_buffer = reinterpret_cast<const uint8_t*>( |
| 1359 file->Map(File::kReadOnly, isolate_data_position, isolate_data_size)); |
| 1360 if (isolate_data_buffer == NULL) { |
| 1361 Log::PrintErr("Failed to memory map snapshot\n"); |
| 1362 Platform::Exit(kErrorExitCode); |
| 1363 } |
| 1364 |
| 1365 if (isolate_instructions_size == 0) { |
| 1366 *isolate_instructions_buffer = NULL; |
| 1367 } else { |
| 1368 *isolate_instructions_buffer = reinterpret_cast<const uint8_t*>( |
| 1369 file->Map(File::kReadExecute, isolate_instructions_position, |
| 1370 isolate_instructions_size)); |
| 1371 if (*isolate_instructions_buffer == NULL) { |
| 1372 Log::PrintErr("Failed to memory map snapshot\n"); |
| 1373 Platform::Exit(kErrorExitCode); |
| 1374 } |
| 1375 } |
| 1376 |
| 1377 file->Release(); |
| 1378 return true; |
| 1379 } |
| 1380 |
| 1381 |
| 1382 #if defined(DART_PRECOMPILED_RUNTIME) |
| 1383 static bool ReadAppSnapshotDynamicLibrary( |
| 1384 const char* script_name, |
| 1385 const uint8_t** vm_data_buffer, |
| 1386 const uint8_t** vm_instructions_buffer, |
| 1387 const uint8_t** isolate_data_buffer, |
| 1388 const uint8_t** isolate_instructions_buffer) { |
| 1389 void* library = Extensions::LoadExtensionLibrary(script_name); |
| 1390 if (library == NULL) { |
| 1391 return false; |
| 1392 } |
| 1393 |
| 1394 *vm_data_buffer = reinterpret_cast<const uint8_t*>( |
| 1395 Extensions::ResolveSymbol(library, kVmSnapshotDataSymbolName)); |
| 1396 if (*vm_data_buffer == NULL) { |
| 1397 Log::PrintErr("Failed to resolve symbol '%s'\n", kVmSnapshotDataSymbolName); |
| 1398 Platform::Exit(kErrorExitCode); |
| 1399 } |
| 1400 |
| 1401 *vm_instructions_buffer = reinterpret_cast<const uint8_t*>( |
| 1402 Extensions::ResolveSymbol(library, kVmSnapshotInstructionsSymbolName)); |
| 1403 if (*vm_instructions_buffer == NULL) { |
| 1404 Log::PrintErr("Failed to resolve symbol '%s'\n", |
| 1405 kVmSnapshotInstructionsSymbolName); |
| 1406 Platform::Exit(kErrorExitCode); |
| 1407 } |
| 1408 |
| 1409 *isolate_data_buffer = reinterpret_cast<const uint8_t*>( |
| 1410 Extensions::ResolveSymbol(library, kIsolateSnapshotDataSymbolName)); |
| 1411 if (*isolate_data_buffer == NULL) { |
| 1412 Log::PrintErr("Failed to resolve symbol '%s'\n", |
| 1413 kIsolateSnapshotDataSymbolName); |
| 1414 Platform::Exit(kErrorExitCode); |
| 1415 } |
| 1416 |
| 1417 *isolate_instructions_buffer = |
| 1418 reinterpret_cast<const uint8_t*>(Extensions::ResolveSymbol( |
| 1419 library, kIsolateSnapshotInstructionsSymbolName)); |
| 1420 if (*isolate_instructions_buffer == NULL) { |
| 1421 Log::PrintErr("Failed to resolve symbol '%s'\n", |
| 1422 kIsolateSnapshotInstructionsSymbolName); |
| 1423 Platform::Exit(kErrorExitCode); |
| 1424 } |
| 1425 |
| 1426 return true; |
| 1427 } |
| 1428 #endif // defined(DART_PRECOMPILED_RUNTIME) |
| 1429 |
| 1430 |
| 1431 static bool ReadAppSnapshot(const char* script_name, |
| 1432 const uint8_t** vm_data_buffer, |
| 1433 const uint8_t** vm_instructions_buffer, |
| 1434 const uint8_t** isolate_data_buffer, |
| 1435 const uint8_t** isolate_instructions_buffer) { |
| 1436 if (File::GetType(script_name, true) != File::kIsFile) { |
| 1437 // If 'script_name' refers to a pipe, don't read to check for an app |
| 1438 // snapshot since we cannot rewind if it isn't (and couldn't mmap it in |
| 1439 // anyway if it was). |
| 1440 return false; |
| 1441 } |
| 1442 if (ReadAppSnapshotBlobs(script_name, vm_data_buffer, vm_instructions_buffer, |
| 1443 isolate_data_buffer, isolate_instructions_buffer)) { |
| 1444 return true; |
| 1445 } |
| 1446 #if defined(DART_PRECOMPILED_RUNTIME) |
| 1447 // For testing AOT with the standalone embedder, we also support loading |
| 1448 // from a dynamic library to simulate what happens on iOS. |
| 1449 return ReadAppSnapshotDynamicLibrary( |
| 1450 script_name, vm_data_buffer, vm_instructions_buffer, isolate_data_buffer, |
| 1451 isolate_instructions_buffer); |
| 1452 #else |
| 1453 return false; |
| 1454 #endif // defined(DART_PRECOMPILED_RUNTIME) |
| 1455 } |
| 1456 |
| 1457 |
1467 static bool WriteInt64(File* file, int64_t size) { | 1458 static bool WriteInt64(File* file, int64_t size) { |
1468 return file->WriteFully(&size, sizeof(size)); | 1459 return file->WriteFully(&size, sizeof(size)); |
1469 } | 1460 } |
1470 | 1461 |
1471 | 1462 |
1472 static void WriteAppSnapshot(const char* filename, | 1463 static void WriteAppSnapshot(const char* filename, |
1473 uint8_t* vm_data_buffer, | 1464 uint8_t* vm_data_buffer, |
1474 intptr_t vm_data_size, | 1465 intptr_t vm_data_size, |
1475 uint8_t* vm_instructions_buffer, | 1466 uint8_t* vm_instructions_buffer, |
1476 intptr_t vm_instructions_size, | 1467 intptr_t vm_instructions_size, |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2071 Platform::Exit(Process::GlobalExitCode()); | 2062 Platform::Exit(Process::GlobalExitCode()); |
2072 } | 2063 } |
2073 | 2064 |
2074 } // namespace bin | 2065 } // namespace bin |
2075 } // namespace dart | 2066 } // namespace dart |
2076 | 2067 |
2077 int main(int argc, char** argv) { | 2068 int main(int argc, char** argv) { |
2078 dart::bin::main(argc, argv); | 2069 dart::bin::main(argc, argv); |
2079 UNREACHABLE(); | 2070 UNREACHABLE(); |
2080 } | 2071 } |
OLD | NEW |