Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: runtime/bin/main.cc

Issue 2622053002: Refactor snapshots pieces to include a section for loading instructions into the heap of a regular … (Closed)
Patch Set: . Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/gen_snapshot.cc ('k') | runtime/bin/run_vm_tests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 16 matching lines...) Expand all
27 #include "platform/globals.h" 27 #include "platform/globals.h"
28 #include "platform/hashmap.h" 28 #include "platform/hashmap.h"
29 #include "platform/text_buffer.h" 29 #include "platform/text_buffer.h"
30 #if !defined(DART_PRECOMPILER) 30 #if !defined(DART_PRECOMPILER)
31 #include "zlib/zlib.h" 31 #include "zlib/zlib.h"
32 #endif 32 #endif
33 33
34 namespace dart { 34 namespace dart {
35 namespace bin { 35 namespace bin {
36 36
37 // vm_isolate_snapshot_buffer points to a snapshot for the vm isolate if we 37 // Snapshot pieces if we link in a snapshot, otherwise initialized to NULL.
38 // link in a snapshot otherwise it is initialized to NULL. 38 extern const uint8_t* vm_snapshot_data;
39 extern const uint8_t* vm_isolate_snapshot_buffer; 39 extern const uint8_t* vm_snapshot_instructions;
40 40 extern const uint8_t* core_isolate_snapshot_data;
41 // isolate_snapshot_buffer points to a snapshot for an isolate if we link in a 41 extern const uint8_t* core_isolate_snapshot_instructions;
42 // snapshot otherwise it is initialized to NULL.
43 extern const uint8_t* core_isolate_snapshot_buffer;
44
45 42
46 /** 43 /**
47 * Global state used to control and store generation of application snapshots 44 * Global state used to control and store generation of application snapshots
48 * An application snapshot can be generated and run using the following 45 * An application snapshot can be generated and run using the following
49 * command 46 * command
50 * dart --snapshot-kind=app-jit --snapshot=<app_snapshot_filename> 47 * dart --snapshot-kind=app-jit --snapshot=<app_snapshot_filename>
51 * <script_uri> [<script_options>] 48 * <script_uri> [<script_options>]
52 * To Run the application snapshot generated above, use : 49 * To Run the application snapshot generated above, use :
53 * dart <app_snapshot_filename> [<script_options>] 50 * dart <app_snapshot_filename> [<script_options>]
54 */ 51 */
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 // dart functions and not run anything. 88 // dart functions and not run anything.
92 static bool compile_all = false; 89 static bool compile_all = false;
93 static bool parse_all = false; 90 static bool parse_all = false;
94 91
95 92
96 // Global flag that is used to indicate that we want to use blobs/mmap instead 93 // Global flag that is used to indicate that we want to use blobs/mmap instead
97 // of assembly/shared libraries for precompilation. 94 // of assembly/shared libraries for precompilation.
98 static bool use_blobs = false; 95 static bool use_blobs = false;
99 96
100 97
101 extern const char* kPrecompiledVMIsolateSymbolName; 98 extern const char* kVmSnapshotDataSymbolName;
102 extern const char* kPrecompiledIsolateSymbolName; 99 extern const char* kVmSnapshotInstructionsSymbolName;
103 extern const char* kPrecompiledInstructionsSymbolName; 100 extern const char* kIsolateSnapshotDataSymbolName;
104 extern const char* kPrecompiledDataSymbolName; 101 extern const char* kIsolateSnapshotInstructionsSymbolName;
105 102
106 103
107 // Global flag that is used to indicate that we want to trace resolution of 104 // Global flag that is used to indicate that we want to trace resolution of
108 // URIs and the loading of libraries, parts and scripts. 105 // URIs and the loading of libraries, parts and scripts.
109 static bool trace_loading = false; 106 static bool trace_loading = false;
110 107
111 108
112 static char* app_script_uri = NULL; 109 static char* app_script_uri = NULL;
113 static const uint8_t* app_isolate_snapshot_buffer = NULL; 110 static const uint8_t* app_isolate_snapshot_data = NULL;
111 static const uint8_t* app_isolate_snapshot_instructions = NULL;
114 112
115 113
116 static Dart_Isolate main_isolate = NULL; 114 static Dart_Isolate main_isolate = NULL;
117 115
118 116
119 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "localhost"; 117 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "localhost";
120 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; 118 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181;
121 // VM Service options. 119 // VM Service options.
122 static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP; 120 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 121 // The 0 port is a magic value which results in the first available port
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 } else { 826 } else {
829 if (packages_config == NULL) { 827 if (packages_config == NULL) {
830 packages_config = commandline_packages_file; 828 packages_config = commandline_packages_file;
831 } 829 }
832 } 830 }
833 } 831 }
834 832
835 #if defined(DART_PRECOMPILED_RUNTIME) 833 #if defined(DART_PRECOMPILED_RUNTIME)
836 // AOT: All isolates start from the app snapshot. 834 // AOT: All isolates start from the app snapshot.
837 bool isolate_run_app_snapshot = true; 835 bool isolate_run_app_snapshot = true;
838 const uint8_t* isolate_snapshot_buffer = app_isolate_snapshot_buffer; 836 const uint8_t* isolate_snapshot_data = app_isolate_snapshot_data;
837 const uint8_t* isolate_snapshot_instructions =
838 app_isolate_snapshot_instructions;
839 #else 839 #else
840 // JIT: Main isolate starts from the app snapshot, if any. Other use the 840 // JIT: Main isolate starts from the app snapshot, if any. Other isolates
841 // core libraries snapshot. 841 // use the core libraries snapshot.
842 bool isolate_run_app_snapshot = false; 842 bool isolate_run_app_snapshot = false;
843 const uint8_t* isolate_snapshot_buffer = core_isolate_snapshot_buffer; 843 const uint8_t* isolate_snapshot_data = core_isolate_snapshot_data;
844 if ((app_isolate_snapshot_buffer != NULL) && 844 const uint8_t* isolate_snapshot_instructions =
845 core_isolate_snapshot_instructions;
846 if ((app_isolate_snapshot_data != NULL) &&
845 (is_main_isolate || ((app_script_uri != NULL) && 847 (is_main_isolate || ((app_script_uri != NULL) &&
846 (strcmp(script_uri, app_script_uri) == 0)))) { 848 (strcmp(script_uri, app_script_uri) == 0)))) {
847 isolate_run_app_snapshot = true; 849 isolate_run_app_snapshot = true;
848 isolate_snapshot_buffer = app_isolate_snapshot_buffer; 850 isolate_snapshot_data = app_isolate_snapshot_data;
851 isolate_snapshot_instructions = app_isolate_snapshot_instructions;
849 } 852 }
850 #endif 853 #endif
851 854
852 // 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
853 // script. 856 // script.
854 const uint8_t* kernel_file = NULL; 857 const uint8_t* kernel_file = NULL;
855 intptr_t kernel_length = -1; 858 intptr_t kernel_length = -1;
856 const bool is_kernel = 859 const bool is_kernel =
857 !isolate_run_app_snapshot && 860 !isolate_run_app_snapshot &&
858 TryReadKernel(script_uri, &kernel_file, &kernel_length); 861 TryReadKernel(script_uri, &kernel_file, &kernel_length);
859 862
860 void* kernel_program = NULL; 863 void* kernel_program = NULL;
861 if (is_kernel) { 864 if (is_kernel) {
862 kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length); 865 kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length);
863 free(const_cast<uint8_t*>(kernel_file)); 866 free(const_cast<uint8_t*>(kernel_file));
864 } 867 }
865 868
866 IsolateData* isolate_data = 869 IsolateData* isolate_data =
867 new IsolateData(script_uri, package_root, packages_config); 870 new IsolateData(script_uri, package_root, packages_config);
868 Dart_Isolate isolate = 871 Dart_Isolate isolate =
869 is_kernel ? Dart_CreateIsolateFromKernel(script_uri, main, kernel_program, 872 is_kernel ? Dart_CreateIsolateFromKernel(script_uri, main, kernel_program,
870 flags, isolate_data, error) 873 flags, isolate_data, error)
871 : Dart_CreateIsolate(script_uri, main, isolate_snapshot_buffer, 874 : Dart_CreateIsolate(script_uri, main, isolate_snapshot_data,
872 flags, isolate_data, error); 875 isolate_snapshot_instructions, flags,
876 isolate_data, error);
873 if (isolate == NULL) { 877 if (isolate == NULL) {
874 delete isolate_data; 878 delete isolate_data;
875 return NULL; 879 return NULL;
876 } 880 }
877 881
878 Dart_EnterScope(); 882 Dart_EnterScope();
879 883
880 // Set up the library tag handler for this isolate. 884 // Set up the library tag handler for this isolate.
881 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); 885 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler);
882 CHECK_RESULT(result); 886 CHECK_RESULT(result);
883 887
884 if (is_kernel) { 888 if (is_kernel) {
885 Dart_Handle result = Dart_LoadKernel(kernel_program); 889 Dart_Handle result = Dart_LoadKernel(kernel_program);
886 CHECK_RESULT(result); 890 CHECK_RESULT(result);
887 } 891 }
888 if (is_kernel || (isolate_snapshot_buffer != NULL)) { 892 if (is_kernel || (isolate_snapshot_data != NULL)) {
889 // Setup the native resolver as the snapshot does not carry it. 893 // Setup the native resolver as the snapshot does not carry it.
890 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); 894 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
891 Builtin::SetNativeResolver(Builtin::kIOLibrary); 895 Builtin::SetNativeResolver(Builtin::kIOLibrary);
892 } 896 }
893 if (isolate_run_app_snapshot) { 897 if (isolate_run_app_snapshot) {
894 Dart_Handle result = Loader::ReloadNativeExtensions(); 898 Dart_Handle result = Loader::ReloadNativeExtensions();
895 CHECK_RESULT(result); 899 CHECK_RESULT(result);
896 } 900 }
897 901
898 if (Dart_IsServiceIsolate(isolate)) { 902 if (Dart_IsServiceIsolate(isolate)) {
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 } 1287 }
1284 } 1288 }
1285 1289
1286 1290
1287 static const int64_t kAppSnapshotHeaderSize = 5 * sizeof(int64_t); // NOLINT 1291 static const int64_t kAppSnapshotHeaderSize = 5 * sizeof(int64_t); // NOLINT
1288 static const int64_t kAppSnapshotMagicNumber = 0xf6f6dcdc; 1292 static const int64_t kAppSnapshotMagicNumber = 0xf6f6dcdc;
1289 static const int64_t kAppSnapshotPageSize = 4 * KB; 1293 static const int64_t kAppSnapshotPageSize = 4 * KB;
1290 1294
1291 1295
1292 static bool ReadAppSnapshotBlobs(const char* script_name, 1296 static bool ReadAppSnapshotBlobs(const char* script_name,
1293 const uint8_t** vmisolate_buffer, 1297 const uint8_t** vm_data_buffer,
1294 const uint8_t** isolate_buffer, 1298 const uint8_t** vm_instructions_buffer,
1295 const uint8_t** instructions_buffer, 1299 const uint8_t** isolate_data_buffer,
1296 const uint8_t** rodata_buffer) { 1300 const uint8_t** isolate_instructions_buffer) {
1297 File* file = File::Open(script_name, File::kRead); 1301 File* file = File::Open(script_name, File::kRead);
1298 if (file == NULL) { 1302 if (file == NULL) {
1299 return false; 1303 return false;
1300 } 1304 }
1301 if (file->Length() < kAppSnapshotHeaderSize) { 1305 if (file->Length() < kAppSnapshotHeaderSize) {
1302 file->Release(); 1306 file->Release();
1303 return false; 1307 return false;
1304 } 1308 }
1305 int64_t header[5]; 1309 int64_t header[5];
1306 ASSERT(sizeof(header) == kAppSnapshotHeaderSize); 1310 ASSERT(sizeof(header) == kAppSnapshotHeaderSize);
1307 if (!file->ReadFully(&header, kAppSnapshotHeaderSize)) { 1311 if (!file->ReadFully(&header, kAppSnapshotHeaderSize)) {
1308 file->Release(); 1312 file->Release();
1309 return false; 1313 return false;
1310 } 1314 }
1311 if (header[0] != kAppSnapshotMagicNumber) { 1315 if (header[0] != kAppSnapshotMagicNumber) {
1312 file->Release(); 1316 file->Release();
1313 return false; 1317 return false;
1314 } 1318 }
1315 1319
1316 int64_t vmisolate_size = header[1]; 1320 int64_t vm_data_size = header[1];
1317 int64_t vmisolate_position = 1321 int64_t vm_data_position =
1318 Utils::RoundUp(file->Position(), kAppSnapshotPageSize); 1322 Utils::RoundUp(file->Position(), kAppSnapshotPageSize);
1319 int64_t isolate_size = header[2]; 1323 int64_t vm_instructions_size = header[2];
1320 int64_t isolate_position = 1324 int64_t vm_instructions_position = vm_data_position + vm_data_size;
1321 Utils::RoundUp(vmisolate_position + vmisolate_size, kAppSnapshotPageSize); 1325 if (vm_instructions_size != 0) {
1322 int64_t rodata_size = header[3]; 1326 vm_instructions_position =
1323 int64_t rodata_position = isolate_position + isolate_size; 1327 Utils::RoundUp(vm_instructions_position, kAppSnapshotPageSize);
1324 if (rodata_size != 0) {
1325 rodata_position = Utils::RoundUp(rodata_position, kAppSnapshotPageSize);
1326 } 1328 }
1327 int64_t instructions_size = header[4]; 1329 int64_t isolate_data_size = header[3];
1328 int64_t instructions_position = rodata_position + rodata_size; 1330 int64_t isolate_data_position = Utils::RoundUp(
1329 if (instructions_size != 0) { 1331 vm_instructions_position + vm_instructions_size, kAppSnapshotPageSize);
1330 instructions_position = 1332 int64_t isolate_instructions_size = header[4];
1331 Utils::RoundUp(instructions_position, kAppSnapshotPageSize); 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);
1332 } 1338 }
1333 1339
1334 void* read_only_buffer = 1340 if (vm_data_size != 0) {
1335 file->Map(File::kReadOnly, vmisolate_position, 1341 *vm_data_buffer = reinterpret_cast<const uint8_t*>(
1336 instructions_position - vmisolate_position); 1342 file->Map(File::kReadOnly, vm_data_position, vm_data_size));
1337 if (read_only_buffer == NULL) { 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) {
1338 Log::PrintErr("Failed to memory map snapshot\n"); 1361 Log::PrintErr("Failed to memory map snapshot\n");
1339 Platform::Exit(kErrorExitCode); 1362 Platform::Exit(kErrorExitCode);
1340 } 1363 }
1341 1364
1342 if (vmisolate_size != 0) { 1365 if (isolate_instructions_size == 0) {
1343 *vmisolate_buffer = reinterpret_cast<const uint8_t*>(read_only_buffer) + 1366 *isolate_instructions_buffer = NULL;
1344 (vmisolate_position - vmisolate_position);
1345 }
1346 *isolate_buffer = reinterpret_cast<const uint8_t*>(read_only_buffer) +
1347 (isolate_position - vmisolate_position);
1348 if (rodata_size == 0) {
1349 *rodata_buffer = NULL;
1350 } else { 1367 } else {
1351 *rodata_buffer = reinterpret_cast<const uint8_t*>(read_only_buffer) + 1368 *isolate_instructions_buffer = reinterpret_cast<const uint8_t*>(
1352 (rodata_position - vmisolate_position); 1369 file->Map(File::kReadExecute, isolate_instructions_position,
1353 } 1370 isolate_instructions_size));
1354 1371 if (*isolate_instructions_buffer == NULL) {
1355 if (instructions_size == 0) {
1356 *instructions_buffer = NULL;
1357 } else {
1358 *instructions_buffer = reinterpret_cast<const uint8_t*>(
1359 file->Map(File::kReadExecute, instructions_position, header[4]));
1360 if (*instructions_buffer == NULL) {
1361 Log::PrintErr("Failed to memory map snapshot\n"); 1372 Log::PrintErr("Failed to memory map snapshot\n");
1362 Platform::Exit(kErrorExitCode); 1373 Platform::Exit(kErrorExitCode);
1363 } 1374 }
1364 } 1375 }
1365 1376
1366 file->Release(); 1377 file->Release();
1367 return true; 1378 return true;
1368 } 1379 }
1369 1380
1370 1381
1371 #if defined(DART_PRECOMPILED_RUNTIME) 1382 #if defined(DART_PRECOMPILED_RUNTIME)
1372 static bool ReadAppSnapshotDynamicLibrary(const char* script_name, 1383 static bool ReadAppSnapshotDynamicLibrary(
1373 const uint8_t** vmisolate_buffer, 1384 const char* script_name,
1374 const uint8_t** isolate_buffer, 1385 const uint8_t** vm_data_buffer,
1375 const uint8_t** instructions_buffer, 1386 const uint8_t** vm_instructions_buffer,
1376 const uint8_t** rodata_buffer) { 1387 const uint8_t** isolate_data_buffer,
1388 const uint8_t** isolate_instructions_buffer) {
1377 void* library = Extensions::LoadExtensionLibrary(script_name); 1389 void* library = Extensions::LoadExtensionLibrary(script_name);
1378 if (library == NULL) { 1390 if (library == NULL) {
1379 return false; 1391 return false;
1380 } 1392 }
1381 1393
1382 *vmisolate_buffer = reinterpret_cast<const uint8_t*>( 1394 *vm_data_buffer = reinterpret_cast<const uint8_t*>(
1383 Extensions::ResolveSymbol(library, kPrecompiledVMIsolateSymbolName)); 1395 Extensions::ResolveSymbol(library, kVmSnapshotDataSymbolName));
1384 if (*vmisolate_buffer == NULL) { 1396 if (*vm_data_buffer == NULL) {
1385 Log::PrintErr("Failed to resolve symbol '%s'\n", 1397 Log::PrintErr("Failed to resolve symbol '%s'\n", kVmSnapshotDataSymbolName);
1386 kPrecompiledVMIsolateSymbolName);
1387 Platform::Exit(kErrorExitCode); 1398 Platform::Exit(kErrorExitCode);
1388 } 1399 }
1389 1400
1390 *isolate_buffer = reinterpret_cast<const uint8_t*>( 1401 *vm_instructions_buffer = reinterpret_cast<const uint8_t*>(
1391 Extensions::ResolveSymbol(library, kPrecompiledIsolateSymbolName)); 1402 Extensions::ResolveSymbol(library, kVmSnapshotInstructionsSymbolName));
1392 if (*isolate_buffer == NULL) { 1403 if (*vm_instructions_buffer == NULL) {
1393 Log::PrintErr("Failed to resolve symbol '%s'\n", 1404 Log::PrintErr("Failed to resolve symbol '%s'\n",
1394 kPrecompiledIsolateSymbolName); 1405 kVmSnapshotInstructionsSymbolName);
1395 Platform::Exit(kErrorExitCode); 1406 Platform::Exit(kErrorExitCode);
1396 } 1407 }
1397 1408
1398 *instructions_buffer = reinterpret_cast<const uint8_t*>( 1409 *isolate_data_buffer = reinterpret_cast<const uint8_t*>(
1399 Extensions::ResolveSymbol(library, kPrecompiledInstructionsSymbolName)); 1410 Extensions::ResolveSymbol(library, kIsolateSnapshotDataSymbolName));
1400 if (*instructions_buffer == NULL) { 1411 if (*isolate_data_buffer == NULL) {
1401 Log::PrintErr("Failed to resolve symbol '%s'\n", 1412 Log::PrintErr("Failed to resolve symbol '%s'\n",
1402 kPrecompiledInstructionsSymbolName); 1413 kIsolateSnapshotDataSymbolName);
1403 Platform::Exit(kErrorExitCode); 1414 Platform::Exit(kErrorExitCode);
1404 } 1415 }
1405 1416
1406 *rodata_buffer = reinterpret_cast<const uint8_t*>( 1417 *isolate_instructions_buffer =
1407 Extensions::ResolveSymbol(library, kPrecompiledDataSymbolName)); 1418 reinterpret_cast<const uint8_t*>(Extensions::ResolveSymbol(
1408 if (*rodata_buffer == NULL) { 1419 library, kIsolateSnapshotInstructionsSymbolName));
1420 if (*isolate_instructions_buffer == NULL) {
1409 Log::PrintErr("Failed to resolve symbol '%s'\n", 1421 Log::PrintErr("Failed to resolve symbol '%s'\n",
1410 kPrecompiledDataSymbolName); 1422 kIsolateSnapshotInstructionsSymbolName);
1411 Platform::Exit(kErrorExitCode); 1423 Platform::Exit(kErrorExitCode);
1412 } 1424 }
1413 1425
1414 return true; 1426 return true;
1415 } 1427 }
1416 #endif // defined(DART_PRECOMPILED_RUNTIME) 1428 #endif // defined(DART_PRECOMPILED_RUNTIME)
1417 1429
1418 1430
1419 static bool ReadAppSnapshot(const char* script_name, 1431 static bool ReadAppSnapshot(const char* script_name,
1420 const uint8_t** vmisolate_buffer, 1432 const uint8_t** vm_data_buffer,
1421 const uint8_t** isolate_buffer, 1433 const uint8_t** vm_instructions_buffer,
1422 const uint8_t** instructions_buffer, 1434 const uint8_t** isolate_data_buffer,
1423 const uint8_t** rodata_buffer) { 1435 const uint8_t** isolate_instructions_buffer) {
1424 if (File::GetType(script_name, true) != File::kIsFile) { 1436 if (File::GetType(script_name, true) != File::kIsFile) {
1425 // If 'script_name' refers to a pipe, don't read to check for an app 1437 // If 'script_name' refers to a pipe, don't read to check for an app
1426 // snapshot since we cannot rewind if it isn't (and couldn't mmap it in 1438 // snapshot since we cannot rewind if it isn't (and couldn't mmap it in
1427 // anyway if it was). 1439 // anyway if it was).
1428 return false; 1440 return false;
1429 } 1441 }
1430 if (ReadAppSnapshotBlobs(script_name, vmisolate_buffer, isolate_buffer, 1442 if (ReadAppSnapshotBlobs(script_name, vm_data_buffer, vm_instructions_buffer,
1431 instructions_buffer, rodata_buffer)) { 1443 isolate_data_buffer, isolate_instructions_buffer)) {
1432 return true; 1444 return true;
1433 } 1445 }
1434 #if defined(DART_PRECOMPILED_RUNTIME) 1446 #if defined(DART_PRECOMPILED_RUNTIME)
1435 // For testing AOT with the standalone embedder, we also support loading 1447 // For testing AOT with the standalone embedder, we also support loading
1436 // from a dynamic library to simulate what happens on iOS. 1448 // from a dynamic library to simulate what happens on iOS.
1437 return ReadAppSnapshotDynamicLibrary(script_name, vmisolate_buffer, 1449 return ReadAppSnapshotDynamicLibrary(
1438 isolate_buffer, instructions_buffer, 1450 script_name, vm_data_buffer, vm_instructions_buffer, isolate_data_buffer,
1439 rodata_buffer); 1451 isolate_instructions_buffer);
1440 #else 1452 #else
1441 return false; 1453 return false;
1442 #endif // defined(DART_PRECOMPILED_RUNTIME) 1454 #endif // defined(DART_PRECOMPILED_RUNTIME)
1443 } 1455 }
1444 1456
1445 1457
1446 static bool WriteInt64(File* file, int64_t size) { 1458 static bool WriteInt64(File* file, int64_t size) {
1447 return file->WriteFully(&size, sizeof(size)); 1459 return file->WriteFully(&size, sizeof(size));
1448 } 1460 }
1449 1461
1450 1462
1451 static void WriteAppSnapshot(const char* filename, 1463 static void WriteAppSnapshot(const char* filename,
1452 uint8_t* vmisolate_buffer, 1464 uint8_t* vm_data_buffer,
1453 intptr_t vmisolate_size, 1465 intptr_t vm_data_size,
1454 uint8_t* isolate_buffer, 1466 uint8_t* vm_instructions_buffer,
1455 intptr_t isolate_size, 1467 intptr_t vm_instructions_size,
1456 uint8_t* instructions_buffer, 1468 uint8_t* isolate_data_buffer,
1457 intptr_t instructions_size, 1469 intptr_t isolate_data_size,
1458 uint8_t* rodata_buffer, 1470 uint8_t* isolate_instructions_buffer,
1459 intptr_t rodata_size) { 1471 intptr_t isolate_instructions_size) {
1460 File* file = File::Open(filename, File::kWriteTruncate); 1472 File* file = File::Open(filename, File::kWriteTruncate);
1461 if (file == NULL) { 1473 if (file == NULL) {
1462 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename); 1474 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename);
1463 } 1475 }
1464 1476
1465 file->WriteFully(&kAppSnapshotMagicNumber, sizeof(kAppSnapshotMagicNumber)); 1477 file->WriteFully(&kAppSnapshotMagicNumber, sizeof(kAppSnapshotMagicNumber));
1466 WriteInt64(file, vmisolate_size); 1478 WriteInt64(file, vm_data_size);
1467 WriteInt64(file, isolate_size); 1479 WriteInt64(file, vm_instructions_size);
1468 WriteInt64(file, rodata_size); 1480 WriteInt64(file, isolate_data_size);
1469 WriteInt64(file, instructions_size); 1481 WriteInt64(file, isolate_instructions_size);
1470 ASSERT(file->Position() == kAppSnapshotHeaderSize); 1482 ASSERT(file->Position() == kAppSnapshotHeaderSize);
1471 1483
1472 file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize)); 1484 file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize));
1473 if (!file->WriteFully(vmisolate_buffer, vmisolate_size)) { 1485 if (!file->WriteFully(vm_data_buffer, vm_data_size)) {
1474 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename); 1486 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename);
1475 } 1487 }
1476 1488
1477 file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize)); 1489 if (vm_instructions_size != 0) {
1478 if (!file->WriteFully(isolate_buffer, isolate_size)) {
1479 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename);
1480 }
1481
1482 if (rodata_size != 0) {
1483 file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize)); 1490 file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize));
1484 if (!file->WriteFully(rodata_buffer, rodata_size)) { 1491 if (!file->WriteFully(vm_instructions_buffer, vm_instructions_size)) {
1485 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", 1492 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n",
1486 filename); 1493 filename);
1487 } 1494 }
1488 } 1495 }
1489 1496
1490 if (instructions_size != 0) { 1497 file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize));
1498 if (!file->WriteFully(isolate_data_buffer, isolate_data_size)) {
1499 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", filename);
1500 }
1501
1502 if (isolate_instructions_size != 0) {
1491 file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize)); 1503 file->SetPosition(Utils::RoundUp(file->Position(), kAppSnapshotPageSize));
1492 if (!file->WriteFully(instructions_buffer, instructions_size)) { 1504 if (!file->WriteFully(isolate_instructions_buffer,
1505 isolate_instructions_size)) {
1493 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n", 1506 ErrorExit(kErrorExitCode, "Unable to write snapshot file '%s'\n",
1494 filename); 1507 filename);
1495 } 1508 }
1496 } 1509 }
1497 1510
1498 file->Flush(); 1511 file->Flush();
1499 file->Release(); 1512 file->Release();
1500 } 1513 }
1501 1514
1502 1515
1503 static void GenerateScriptSnapshot() { 1516 static void GenerateScriptSnapshot() {
1504 // First create a snapshot. 1517 // First create a snapshot.
1505 uint8_t* buffer = NULL; 1518 uint8_t* buffer = NULL;
1506 intptr_t size = 0; 1519 intptr_t size = 0;
1507 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); 1520 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size);
1508 if (Dart_IsError(result)) { 1521 if (Dart_IsError(result)) {
1509 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); 1522 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1510 } 1523 }
1511 1524
1512 WriteSnapshotFile(snapshot_filename, true, buffer, size); 1525 WriteSnapshotFile(snapshot_filename, true, buffer, size);
1513 } 1526 }
1514 1527
1515 1528
1516 static void GeneratePrecompiledSnapshot() { 1529 static void GenerateAppAOTSnapshotAsBlobs() {
1517 uint8_t* vm_isolate_buffer = NULL; 1530 uint8_t* vm_data_buffer = NULL;
1518 intptr_t vm_isolate_size = 0; 1531 intptr_t vm_data_size = 0;
1519 uint8_t* isolate_buffer = NULL; 1532 uint8_t* vm_instructions_buffer = NULL;
1520 intptr_t isolate_size = 0; 1533 intptr_t vm_instructions_size = 0;
1521 uint8_t* assembly_buffer = NULL; 1534 uint8_t* isolate_data_buffer = NULL;
1522 intptr_t assembly_size = 0; 1535 intptr_t isolate_data_size = 0;
1523 uint8_t* instructions_blob_buffer = NULL; 1536 uint8_t* isolate_instructions_buffer = NULL;
1524 intptr_t instructions_blob_size = 0; 1537 intptr_t isolate_instructions_size = 0;
1525 uint8_t* rodata_blob_buffer = NULL; 1538 Dart_Handle result = Dart_CreateAppAOTSnapshotAsBlobs(
1526 intptr_t rodata_blob_size = 0; 1539 &vm_data_buffer, &vm_data_size, &vm_instructions_buffer,
1527 Dart_Handle result; 1540 &vm_instructions_size, &isolate_data_buffer, &isolate_data_size,
1528 if (use_blobs) { 1541 &isolate_instructions_buffer, &isolate_instructions_size);
1529 result = Dart_CreateAppAOTSnapshotAsBlobs(
1530 &vm_isolate_buffer, &vm_isolate_size, &isolate_buffer, &isolate_size,
1531 &instructions_blob_buffer, &instructions_blob_size, &rodata_blob_buffer,
1532 &rodata_blob_size);
1533 } else {
1534 result =
1535 Dart_CreateAppAOTSnapshotAsAssembly(&assembly_buffer, &assembly_size);
1536 }
1537 if (Dart_IsError(result)) { 1542 if (Dart_IsError(result)) {
1538 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); 1543 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1539 } 1544 }
1545 WriteAppSnapshot(snapshot_filename, vm_data_buffer, vm_data_size,
1546 vm_instructions_buffer, vm_instructions_size,
1547 isolate_data_buffer, isolate_data_size,
1548 isolate_instructions_buffer, isolate_instructions_size);
1549 }
1550
1551 static void GenerateAppAOTSnapshotAsAssembly() {
1552 uint8_t* assembly_buffer = NULL;
1553 intptr_t assembly_size = 0;
1554 Dart_Handle result =
1555 Dart_CreateAppAOTSnapshotAsAssembly(&assembly_buffer, &assembly_size);
1556 if (Dart_IsError(result)) {
1557 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1558 }
1559 WriteSnapshotFile(snapshot_filename, false, assembly_buffer, assembly_size);
1560 }
1561
1562
1563 static void GenerateAppAOTSnapshot() {
1540 if (use_blobs) { 1564 if (use_blobs) {
1541 WriteAppSnapshot(snapshot_filename, vm_isolate_buffer, vm_isolate_size, 1565 GenerateAppAOTSnapshotAsBlobs();
1542 isolate_buffer, isolate_size, instructions_blob_buffer,
1543 instructions_blob_size, rodata_blob_buffer,
1544 rodata_blob_size);
1545 } else { 1566 } else {
1546 WriteSnapshotFile(snapshot_filename, false, assembly_buffer, assembly_size); 1567 GenerateAppAOTSnapshotAsAssembly();
1547 } 1568 }
1548 } 1569 }
1549 1570
1550 1571
1551 static void GenerateAppJITSnapshot() { 1572 static void GenerateAppJITSnapshot() {
1552 #if defined(TARGET_ARCH_X64) 1573 #if defined(TARGET_ARCH_X64)
1553 uint8_t* vm_isolate_buffer = NULL; 1574 uint8_t* isolate_data_buffer = NULL;
1554 intptr_t vm_isolate_size = 0; 1575 intptr_t isolate_data_size = 0;
1555 uint8_t* isolate_buffer = NULL; 1576 uint8_t* isolate_instructions_buffer = NULL;
1556 intptr_t isolate_size = 0; 1577 intptr_t isolate_instructions_size = 0;
1557 uint8_t* instructions_blob_buffer = NULL;
1558 intptr_t instructions_blob_size = 0;
1559 uint8_t* rodata_blob_buffer = NULL;
1560 intptr_t rodata_blob_size = 0;
1561 Dart_Handle result = Dart_CreateAppJITSnapshotAsBlobs( 1578 Dart_Handle result = Dart_CreateAppJITSnapshotAsBlobs(
1562 &isolate_buffer, &isolate_size, &instructions_blob_buffer, 1579 &isolate_data_buffer, &isolate_data_size, &isolate_instructions_buffer,
1563 &instructions_blob_size, &rodata_blob_buffer, &rodata_blob_size); 1580 &isolate_instructions_size);
1564 if (Dart_IsError(result)) { 1581 if (Dart_IsError(result)) {
1565 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); 1582 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1566 } 1583 }
1567 WriteAppSnapshot(snapshot_filename, vm_isolate_buffer, vm_isolate_size, 1584 WriteAppSnapshot(snapshot_filename, NULL, 0, NULL, 0, isolate_data_buffer,
1568 isolate_buffer, isolate_size, instructions_blob_buffer, 1585 isolate_data_size, isolate_instructions_buffer,
1569 instructions_blob_size, rodata_blob_buffer, 1586 isolate_instructions_size);
1570 rodata_blob_size);
1571 #else 1587 #else
1572 uint8_t* isolate_buffer = NULL; 1588 uint8_t* isolate_buffer = NULL;
1573 intptr_t isolate_size = 0; 1589 intptr_t isolate_size = 0;
1574 1590
1575 Dart_Handle result = 1591 Dart_Handle result =
1576 Dart_CreateSnapshot(NULL, NULL, &isolate_buffer, &isolate_size); 1592 Dart_CreateSnapshot(NULL, NULL, &isolate_buffer, &isolate_size);
1577 if (Dart_IsError(result)) { 1593 if (Dart_IsError(result)) {
1578 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); 1594 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1579 } 1595 }
1580 1596
1581 WriteAppSnapshot(snapshot_filename, NULL, 0, isolate_buffer, isolate_size, 1597 WriteAppSnapshot(snapshot_filename, NULL, 0, NULL, 0, isolate_buffer,
1582 NULL, 0, NULL, 0); 1598 isolate_size, NULL, 0);
1583 #endif // defined(TARGET_ARCH_X64) 1599 #endif // defined(TARGET_ARCH_X64)
1584 } 1600 }
1585 1601
1586 1602
1587 #define CHECK_RESULT(result) \ 1603 #define CHECK_RESULT(result) \
1588 if (Dart_IsError(result)) { \ 1604 if (Dart_IsError(result)) { \
1589 if (Dart_IsVMRestartRequest(result)) { \ 1605 if (Dart_IsVMRestartRequest(result)) { \
1590 Dart_ExitScope(); \ 1606 Dart_ExitScope(); \
1591 Dart_ShutdownIsolate(); \ 1607 Dart_ShutdownIsolate(); \
1592 return true; \ 1608 return true; \
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1740 1756
1741 result = Dart_Precompile(standalone_entry_points, feedback_buffer, 1757 result = Dart_Precompile(standalone_entry_points, feedback_buffer,
1742 feedback_length); 1758 feedback_length);
1743 if (feedback_buffer != NULL) { 1759 if (feedback_buffer != NULL) {
1744 free(feedback_buffer); 1760 free(feedback_buffer);
1745 } 1761 }
1746 CHECK_RESULT(result); 1762 CHECK_RESULT(result);
1747 } 1763 }
1748 1764
1749 if (gen_snapshot_kind == kAppAOT) { 1765 if (gen_snapshot_kind == kAppAOT) {
1750 GeneratePrecompiledSnapshot(); 1766 GenerateAppAOTSnapshot();
1751 } else { 1767 } else {
1752 if (Dart_IsNull(root_lib)) { 1768 if (Dart_IsNull(root_lib)) {
1753 ErrorExit(kErrorExitCode, "Unable to find root library for '%s'\n", 1769 ErrorExit(kErrorExitCode, "Unable to find root library for '%s'\n",
1754 script_name); 1770 script_name);
1755 } 1771 }
1756 1772
1757 // The helper function _getMainClosure creates a closure for the main 1773 // The helper function _getMainClosure creates a closure for the main
1758 // entry point which is either explicitly or implictly exported from the 1774 // entry point which is either explicitly or implictly exported from the
1759 // root library. 1775 // root library.
1760 Dart_Handle main_closure = 1776 Dart_Handle main_closure =
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1938 Thread::InitOnce(); 1954 Thread::InitOnce();
1939 1955
1940 Loader::InitOnce(); 1956 Loader::InitOnce();
1941 1957
1942 if (!DartUtils::SetOriginalWorkingDirectory()) { 1958 if (!DartUtils::SetOriginalWorkingDirectory()) {
1943 OSError err; 1959 OSError err;
1944 Log::PrintErr("Error determining current directory: %s\n", err.message()); 1960 Log::PrintErr("Error determining current directory: %s\n", err.message());
1945 Platform::Exit(kErrorExitCode); 1961 Platform::Exit(kErrorExitCode);
1946 } 1962 }
1947 1963
1948 const uint8_t* instructions_snapshot = NULL; 1964 if (ReadAppSnapshot(script_name, &vm_snapshot_data, &vm_snapshot_instructions,
1949 const uint8_t* data_snapshot = NULL; 1965 &app_isolate_snapshot_data,
1950 if (ReadAppSnapshot(script_name, &vm_isolate_snapshot_buffer, 1966 &app_isolate_snapshot_instructions)) {
1951 &app_isolate_snapshot_buffer, &instructions_snapshot,
1952 &data_snapshot)) {
1953 vm_run_app_snapshot = true; 1967 vm_run_app_snapshot = true;
1954 } 1968 }
1955 1969
1956 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME) 1970 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
1957 // Constant true if PRODUCT or DART_PRECOMPILED_RUNTIME. 1971 // Constant true if PRODUCT or DART_PRECOMPILED_RUNTIME.
1958 if ((gen_snapshot_kind != kNone) || vm_run_app_snapshot) { 1972 if ((gen_snapshot_kind != kNone) || vm_run_app_snapshot) {
1959 vm_options.AddArgument("--load_deferred_eagerly"); 1973 vm_options.AddArgument("--load_deferred_eagerly");
1960 } 1974 }
1961 #endif 1975 #endif
1962 1976
(...skipping 16 matching lines...) Expand all
1979 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 1993 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
1980 1994
1981 // Start event handler. 1995 // Start event handler.
1982 TimerUtils::InitOnce(); 1996 TimerUtils::InitOnce();
1983 EventHandler::Start(); 1997 EventHandler::Start();
1984 1998
1985 // Initialize the Dart VM. 1999 // Initialize the Dart VM.
1986 Dart_InitializeParams init_params; 2000 Dart_InitializeParams init_params;
1987 memset(&init_params, 0, sizeof(init_params)); 2001 memset(&init_params, 0, sizeof(init_params));
1988 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; 2002 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION;
1989 init_params.vm_isolate_snapshot = vm_isolate_snapshot_buffer; 2003 init_params.vm_snapshot_data = vm_snapshot_data;
1990 init_params.instructions_snapshot = instructions_snapshot; 2004 init_params.vm_snapshot_instructions = vm_snapshot_instructions;
1991 init_params.data_snapshot = data_snapshot;
1992 init_params.create = CreateIsolateAndSetup; 2005 init_params.create = CreateIsolateAndSetup;
1993 init_params.shutdown = ShutdownIsolate; 2006 init_params.shutdown = ShutdownIsolate;
1994 init_params.file_open = DartUtils::OpenFile; 2007 init_params.file_open = DartUtils::OpenFile;
1995 init_params.file_read = DartUtils::ReadFile; 2008 init_params.file_read = DartUtils::ReadFile;
1996 init_params.file_write = DartUtils::WriteFile; 2009 init_params.file_write = DartUtils::WriteFile;
1997 init_params.file_close = DartUtils::CloseFile; 2010 init_params.file_close = DartUtils::CloseFile;
1998 init_params.entropy_source = DartUtils::EntropySource; 2011 init_params.entropy_source = DartUtils::EntropySource;
1999 init_params.get_service_assets = GetVMServiceAssetsArchiveCallback; 2012 init_params.get_service_assets = GetVMServiceAssetsArchiveCallback;
2000 2013
2001 char* error = Dart_Initialize(&init_params); 2014 char* error = Dart_Initialize(&init_params);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2049 Platform::Exit(Process::GlobalExitCode()); 2062 Platform::Exit(Process::GlobalExitCode());
2050 } 2063 }
2051 2064
2052 } // namespace bin 2065 } // namespace bin
2053 } // namespace dart 2066 } // namespace dart
2054 2067
2055 int main(int argc, char** argv) { 2068 int main(int argc, char** argv) {
2056 dart::bin::main(argc, argv); 2069 dart::bin::main(argc, argv);
2057 UNREACHABLE(); 2070 UNREACHABLE();
2058 } 2071 }
OLDNEW
« no previous file with comments | « runtime/bin/gen_snapshot.cc ('k') | runtime/bin/run_vm_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698