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