OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Generate a snapshot file after loading all the scripts specified on the | 5 // Generate a snapshot file after loading all the scripts specified on the |
6 // command line. | 6 // command line. |
7 | 7 |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 } \ | 51 } \ |
52 Dart_ExitScope(); \ | 52 Dart_ExitScope(); \ |
53 Dart_ShutdownIsolate(); \ | 53 Dart_ShutdownIsolate(); \ |
54 exit(exit_code); \ | 54 exit(exit_code); \ |
55 } | 55 } |
56 | 56 |
57 | 57 |
58 // The core snapshot to use when creating isolates. Normally NULL, but loaded | 58 // The core snapshot to use when creating isolates. Normally NULL, but loaded |
59 // from a file when creating script snapshots. | 59 // from a file when creating script snapshots. |
60 const uint8_t* isolate_snapshot_data = NULL; | 60 const uint8_t* isolate_snapshot_data = NULL; |
| 61 const uint8_t* isolate_snapshot_instructions = NULL; |
61 | 62 |
62 | 63 |
63 // Global state that indicates whether a snapshot is to be created and | 64 // Global state that indicates whether a snapshot is to be created and |
64 // if so which file to write the snapshot into. | 65 // if so which file to write the snapshot into. |
65 enum SnapshotKind { | 66 enum SnapshotKind { |
66 kCore, | 67 kCore, |
| 68 kCoreJIT, |
67 kScript, | 69 kScript, |
68 kAppAOTBlobs, | 70 kAppAOTBlobs, |
69 kAppAOTAssembly, | 71 kAppAOTAssembly, |
70 }; | 72 }; |
71 static SnapshotKind snapshot_kind = kCore; | 73 static SnapshotKind snapshot_kind = kCore; |
72 static const char* vm_snapshot_data_filename = NULL; | 74 static const char* vm_snapshot_data_filename = NULL; |
73 static const char* vm_snapshot_instructions_filename = NULL; | 75 static const char* vm_snapshot_instructions_filename = NULL; |
74 static const char* isolate_snapshot_data_filename = NULL; | 76 static const char* isolate_snapshot_data_filename = NULL; |
75 static const char* isolate_snapshot_instructions_filename = NULL; | 77 static const char* isolate_snapshot_instructions_filename = NULL; |
76 static const char* assembly_filename = NULL; | 78 static const char* assembly_filename = NULL; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 205 |
204 | 206 |
205 static bool ProcessSnapshotKindOption(const char* option) { | 207 static bool ProcessSnapshotKindOption(const char* option) { |
206 const char* kind = ProcessOption(option, "--snapshot_kind="); | 208 const char* kind = ProcessOption(option, "--snapshot_kind="); |
207 if (kind == NULL) { | 209 if (kind == NULL) { |
208 kind = ProcessOption(option, "--snapshot-kind="); | 210 kind = ProcessOption(option, "--snapshot-kind="); |
209 } | 211 } |
210 if (kind == NULL) { | 212 if (kind == NULL) { |
211 return false; | 213 return false; |
212 } | 214 } |
213 if (strcmp(kind, "core") == 0) { | 215 if (strcmp(kind, "core-jit") == 0) { |
| 216 snapshot_kind = kCoreJIT; |
| 217 return true; |
| 218 } else if (strcmp(kind, "core") == 0) { |
214 snapshot_kind = kCore; | 219 snapshot_kind = kCore; |
215 return true; | 220 return true; |
216 } else if (strcmp(kind, "script") == 0) { | 221 } else if (strcmp(kind, "script") == 0) { |
217 snapshot_kind = kScript; | 222 snapshot_kind = kScript; |
218 return true; | 223 return true; |
219 } else if (strcmp(kind, "app-aot-blobs") == 0) { | 224 } else if (strcmp(kind, "app-aot-blobs") == 0) { |
220 snapshot_kind = kAppAOTBlobs; | 225 snapshot_kind = kAppAOTBlobs; |
221 return true; | 226 return true; |
222 } else if (strcmp(kind, "app-aot-assembly") == 0) { | 227 } else if (strcmp(kind, "app-aot-assembly") == 0) { |
223 snapshot_kind = kAppAOTAssembly; | 228 snapshot_kind = kAppAOTAssembly; |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 case kCore: { | 451 case kCore: { |
447 if ((vm_snapshot_data_filename == NULL) || | 452 if ((vm_snapshot_data_filename == NULL) || |
448 (isolate_snapshot_data_filename == NULL)) { | 453 (isolate_snapshot_data_filename == NULL)) { |
449 Log::PrintErr( | 454 Log::PrintErr( |
450 "Building a core snapshot requires specifying output files for " | 455 "Building a core snapshot requires specifying output files for " |
451 "--vm_snapshot_data and --isolate_snapshot_data.\n\n"); | 456 "--vm_snapshot_data and --isolate_snapshot_data.\n\n"); |
452 return -1; | 457 return -1; |
453 } | 458 } |
454 break; | 459 break; |
455 } | 460 } |
| 461 case kCoreJIT: { |
| 462 if ((vm_snapshot_data_filename == NULL) || |
| 463 (vm_snapshot_instructions_filename == NULL) || |
| 464 (isolate_snapshot_data_filename == NULL) || |
| 465 (isolate_snapshot_instructions_filename == NULL)) { |
| 466 Log::PrintErr( |
| 467 "Building a core JIT snapshot requires specifying output " |
| 468 "files for --vm_snapshot_data, --vm_snapshot_instructions, " |
| 469 "--isolate_snapshot_data and --isolate_snapshot_instructions.\n\n"); |
| 470 return -1; |
| 471 } |
| 472 break; |
| 473 } |
456 case kScript: { | 474 case kScript: { |
457 if ((vm_snapshot_data_filename == NULL) || | 475 if ((vm_snapshot_data_filename == NULL) || |
458 (isolate_snapshot_data_filename == NULL) || | 476 (isolate_snapshot_data_filename == NULL) || |
459 (script_snapshot_filename == NULL) || (*script_name == NULL)) { | 477 (script_snapshot_filename == NULL) || (*script_name == NULL)) { |
460 Log::PrintErr( | 478 Log::PrintErr( |
461 "Building a script snapshot requires specifying input files for " | 479 "Building a script snapshot requires specifying input files for " |
462 "--vm_snapshot_data and --isolate_snapshot_data, an output file " | 480 "--vm_snapshot_data and --isolate_snapshot_data, an output file " |
463 "for --script_snapshot, and a Dart script.\n\n"); | 481 "for --script_snapshot, and a Dart script.\n\n"); |
464 return -1; | 482 return -1; |
465 } | 483 } |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 case kCore: | 701 case kCore: |
684 success &= file->Print("%s ", vm_snapshot_data_filename); | 702 success &= file->Print("%s ", vm_snapshot_data_filename); |
685 success &= file->Print("%s ", isolate_snapshot_data_filename); | 703 success &= file->Print("%s ", isolate_snapshot_data_filename); |
686 break; | 704 break; |
687 case kScript: | 705 case kScript: |
688 success &= file->Print("%s ", script_snapshot_filename); | 706 success &= file->Print("%s ", script_snapshot_filename); |
689 break; | 707 break; |
690 case kAppAOTAssembly: | 708 case kAppAOTAssembly: |
691 success &= file->Print("%s ", assembly_filename); | 709 success &= file->Print("%s ", assembly_filename); |
692 break; | 710 break; |
| 711 case kCoreJIT: |
693 case kAppAOTBlobs: | 712 case kAppAOTBlobs: |
694 success &= file->Print("%s ", vm_snapshot_data_filename); | 713 success &= file->Print("%s ", vm_snapshot_data_filename); |
695 success &= file->Print("%s ", vm_snapshot_instructions_filename); | 714 success &= file->Print("%s ", vm_snapshot_instructions_filename); |
696 success &= file->Print("%s ", isolate_snapshot_data_filename); | 715 success &= file->Print("%s ", isolate_snapshot_data_filename); |
697 success &= file->Print("%s ", isolate_snapshot_instructions_filename); | 716 success &= file->Print("%s ", isolate_snapshot_instructions_filename); |
698 break; | 717 break; |
699 } | 718 } |
700 | 719 |
701 success &= file->Print(": "); | 720 success &= file->Print(": "); |
702 } | 721 } |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1265 // First create a snapshot. | 1284 // First create a snapshot. |
1266 result = Dart_CreateSnapshot(&vm_snapshot_data_buffer, &vm_snapshot_data_size, | 1285 result = Dart_CreateSnapshot(&vm_snapshot_data_buffer, &vm_snapshot_data_size, |
1267 &isolate_snapshot_data_buffer, | 1286 &isolate_snapshot_data_buffer, |
1268 &isolate_snapshot_data_size); | 1287 &isolate_snapshot_data_size); |
1269 CHECK_RESULT(result); | 1288 CHECK_RESULT(result); |
1270 | 1289 |
1271 // Now write the vm isolate and isolate snapshots out to the | 1290 // Now write the vm isolate and isolate snapshots out to the |
1272 // specified file and exit. | 1291 // specified file and exit. |
1273 WriteSnapshotFile(vm_snapshot_data_filename, vm_snapshot_data_buffer, | 1292 WriteSnapshotFile(vm_snapshot_data_filename, vm_snapshot_data_buffer, |
1274 vm_snapshot_data_size); | 1293 vm_snapshot_data_size); |
| 1294 if (vm_snapshot_instructions_filename != NULL) { |
| 1295 WriteSnapshotFile(vm_snapshot_instructions_filename, NULL, 0); |
| 1296 } |
1275 WriteSnapshotFile(isolate_snapshot_data_filename, | 1297 WriteSnapshotFile(isolate_snapshot_data_filename, |
1276 isolate_snapshot_data_buffer, isolate_snapshot_data_size); | 1298 isolate_snapshot_data_buffer, isolate_snapshot_data_size); |
| 1299 if (isolate_snapshot_instructions_filename != NULL) { |
| 1300 WriteSnapshotFile(isolate_snapshot_instructions_filename, NULL, 0); |
| 1301 } |
1277 } | 1302 } |
1278 | 1303 |
1279 | 1304 |
| 1305 static void CreateAndWriteCoreJITSnapshot() { |
| 1306 ASSERT(snapshot_kind == kCoreJIT); |
| 1307 ASSERT(vm_snapshot_data_filename != NULL); |
| 1308 ASSERT(vm_snapshot_instructions_filename != NULL); |
| 1309 ASSERT(isolate_snapshot_data_filename != NULL); |
| 1310 ASSERT(isolate_snapshot_instructions_filename != NULL); |
| 1311 |
| 1312 Dart_Handle result; |
| 1313 uint8_t* vm_snapshot_data_buffer = NULL; |
| 1314 intptr_t vm_snapshot_data_size = 0; |
| 1315 uint8_t* vm_snapshot_instructions_buffer = NULL; |
| 1316 intptr_t vm_snapshot_instructions_size = 0; |
| 1317 uint8_t* isolate_snapshot_data_buffer = NULL; |
| 1318 intptr_t isolate_snapshot_data_size = 0; |
| 1319 uint8_t* isolate_snapshot_instructions_buffer = NULL; |
| 1320 intptr_t isolate_snapshot_instructions_size = 0; |
| 1321 |
| 1322 // First create a snapshot. |
| 1323 result = Dart_CreateCoreJITSnapshotAsBlobs( |
| 1324 &vm_snapshot_data_buffer, &vm_snapshot_data_size, |
| 1325 &vm_snapshot_instructions_buffer, &vm_snapshot_instructions_size, |
| 1326 &isolate_snapshot_data_buffer, &isolate_snapshot_data_size, |
| 1327 &isolate_snapshot_instructions_buffer, |
| 1328 &isolate_snapshot_instructions_size); |
| 1329 CHECK_RESULT(result); |
| 1330 |
| 1331 // Now write the vm isolate and isolate snapshots out to the |
| 1332 // specified file and exit. |
| 1333 WriteSnapshotFile(vm_snapshot_data_filename, vm_snapshot_data_buffer, |
| 1334 vm_snapshot_data_size); |
| 1335 WriteSnapshotFile(vm_snapshot_instructions_filename, |
| 1336 vm_snapshot_instructions_buffer, |
| 1337 vm_snapshot_instructions_size); |
| 1338 WriteSnapshotFile(isolate_snapshot_data_filename, |
| 1339 isolate_snapshot_data_buffer, isolate_snapshot_data_size); |
| 1340 WriteSnapshotFile(isolate_snapshot_instructions_filename, |
| 1341 isolate_snapshot_instructions_buffer, |
| 1342 isolate_snapshot_instructions_size); |
| 1343 } |
| 1344 |
| 1345 |
1280 static void CreateAndWriteScriptSnapshot() { | 1346 static void CreateAndWriteScriptSnapshot() { |
1281 ASSERT(snapshot_kind == kScript); | 1347 ASSERT(snapshot_kind == kScript); |
1282 ASSERT(script_snapshot_filename != NULL); | 1348 ASSERT(script_snapshot_filename != NULL); |
1283 | 1349 |
1284 // First create a snapshot. | 1350 // First create a snapshot. |
1285 uint8_t* buffer = NULL; | 1351 uint8_t* buffer = NULL; |
1286 intptr_t size = 0; | 1352 intptr_t size = 0; |
1287 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); | 1353 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); |
1288 CHECK_RESULT(result); | 1354 CHECK_RESULT(result); |
1289 | 1355 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 static Dart_Isolate CreateServiceIsolate(const char* script_uri, | 1447 static Dart_Isolate CreateServiceIsolate(const char* script_uri, |
1382 const char* main, | 1448 const char* main, |
1383 const char* package_root, | 1449 const char* package_root, |
1384 const char* package_config, | 1450 const char* package_config, |
1385 Dart_IsolateFlags* flags, | 1451 Dart_IsolateFlags* flags, |
1386 void* data, | 1452 void* data, |
1387 char** error) { | 1453 char** error) { |
1388 IsolateData* isolate_data = | 1454 IsolateData* isolate_data = |
1389 new IsolateData(script_uri, package_root, package_config, NULL); | 1455 new IsolateData(script_uri, package_root, package_config, NULL); |
1390 Dart_Isolate isolate = NULL; | 1456 Dart_Isolate isolate = NULL; |
1391 isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, NULL, | 1457 isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, |
1392 NULL, isolate_data, error); | 1458 isolate_snapshot_instructions, NULL, |
| 1459 isolate_data, error); |
1393 | 1460 |
1394 if (isolate == NULL) { | 1461 if (isolate == NULL) { |
1395 Log::PrintErr("Error: Could not create service isolate\n"); | 1462 Log::PrintErr("Error: Could not create service isolate\n"); |
1396 return NULL; | 1463 return NULL; |
1397 } | 1464 } |
1398 | 1465 |
1399 Dart_EnterScope(); | 1466 Dart_EnterScope(); |
1400 if (!Dart_IsServiceIsolate(isolate)) { | 1467 if (!Dart_IsServiceIsolate(isolate)) { |
1401 Log::PrintErr("Error: We only expect to create the service isolate\n"); | 1468 Log::PrintErr("Error: We only expect to create the service isolate\n"); |
1402 return NULL; | 1469 return NULL; |
(...skipping 14 matching lines...) Expand all Loading... |
1417 false /* trace_loading */)) { | 1484 false /* trace_loading */)) { |
1418 *error = strdup(VmService::GetErrorMessage()); | 1485 *error = strdup(VmService::GetErrorMessage()); |
1419 return NULL; | 1486 return NULL; |
1420 } | 1487 } |
1421 Dart_ExitScope(); | 1488 Dart_ExitScope(); |
1422 Dart_ExitIsolate(); | 1489 Dart_ExitIsolate(); |
1423 return isolate; | 1490 return isolate; |
1424 } | 1491 } |
1425 | 1492 |
1426 | 1493 |
| 1494 static MappedMemory* MapFile(const char* filename, File::MapType type) { |
| 1495 File* file = File::Open(filename, File::kRead); |
| 1496 if (file == NULL) { |
| 1497 Log::PrintErr("Failed to open: %s\n", filename); |
| 1498 exit(kErrorExitCode); |
| 1499 } |
| 1500 MappedMemory* mapping = file->Map(type, 0, file->Length()); |
| 1501 if (mapping == NULL) { |
| 1502 Log::PrintErr("Failed to read: %s\n", vm_snapshot_data_filename); |
| 1503 exit(kErrorExitCode); |
| 1504 } |
| 1505 file->Release(); |
| 1506 return mapping; |
| 1507 } |
| 1508 |
| 1509 |
1427 int main(int argc, char** argv) { | 1510 int main(int argc, char** argv) { |
1428 const int EXTRA_VM_ARGUMENTS = 2; | 1511 const int EXTRA_VM_ARGUMENTS = 2; |
1429 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); | 1512 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); |
1430 | 1513 |
1431 // Initialize the URL mapping array. | 1514 // Initialize the URL mapping array. |
1432 CommandLineOptions cmdline_url_mapping(argc); | 1515 CommandLineOptions cmdline_url_mapping(argc); |
1433 DartUtils::url_mapping = &cmdline_url_mapping; | 1516 DartUtils::url_mapping = &cmdline_url_mapping; |
1434 | 1517 |
1435 // Initialize the entrypoints array. | 1518 // Initialize the entrypoints array. |
1436 CommandLineOptions entry_points_files_array(argc); | 1519 CommandLineOptions entry_points_files_array(argc); |
(...skipping 13 matching lines...) Expand all Loading... |
1450 EventHandler::Start(); | 1533 EventHandler::Start(); |
1451 | 1534 |
1452 #if !defined(PRODUCT) | 1535 #if !defined(PRODUCT) |
1453 // Constant true in PRODUCT mode. | 1536 // Constant true in PRODUCT mode. |
1454 vm_options.AddArgument("--load_deferred_eagerly"); | 1537 vm_options.AddArgument("--load_deferred_eagerly"); |
1455 #endif | 1538 #endif |
1456 | 1539 |
1457 if (IsSnapshottingForPrecompilation()) { | 1540 if (IsSnapshottingForPrecompilation()) { |
1458 vm_options.AddArgument("--precompilation"); | 1541 vm_options.AddArgument("--precompilation"); |
1459 } | 1542 } |
| 1543 if (snapshot_kind == kCoreJIT) { |
| 1544 vm_options.AddArgument("--fields_may_be_reset"); |
| 1545 vm_options.AddArgument("--link_natives_lazily"); |
| 1546 #if !defined(PRODUCT) |
| 1547 vm_options.AddArgument("--collect_code=false"); |
| 1548 #endif |
| 1549 } |
1460 | 1550 |
1461 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1551 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
1462 | 1552 |
1463 // Initialize the Dart VM. | 1553 // Initialize the Dart VM. |
1464 // Note: We don't expect isolates to be created from dart code during | 1554 // Note: We don't expect isolates to be created from dart code during |
1465 // core library snapshot generation. However for the case when a full | 1555 // core library snapshot generation. However for the case when a full |
1466 // snasphot is generated from a script (app_script_name != NULL) we will | 1556 // snasphot is generated from a script (app_script_name != NULL) we will |
1467 // need the service isolate to resolve URI and load code. | 1557 // need the service isolate to resolve URI and load code. |
1468 | 1558 |
1469 Dart_InitializeParams init_params; | 1559 Dart_InitializeParams init_params; |
1470 memset(&init_params, 0, sizeof(init_params)); | 1560 memset(&init_params, 0, sizeof(init_params)); |
1471 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; | 1561 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; |
1472 if (app_script_name != NULL) { | 1562 if (app_script_name != NULL) { |
1473 init_params.create = CreateServiceIsolate; | 1563 init_params.create = CreateServiceIsolate; |
1474 } | 1564 } |
1475 init_params.file_open = DartUtils::OpenFile; | 1565 init_params.file_open = DartUtils::OpenFile; |
1476 init_params.file_read = DartUtils::ReadFile; | 1566 init_params.file_read = DartUtils::ReadFile; |
1477 init_params.file_write = DartUtils::WriteFile; | 1567 init_params.file_write = DartUtils::WriteFile; |
1478 init_params.file_close = DartUtils::CloseFile; | 1568 init_params.file_close = DartUtils::CloseFile; |
1479 init_params.entropy_source = DartUtils::EntropySource; | 1569 init_params.entropy_source = DartUtils::EntropySource; |
1480 | 1570 |
1481 MappedMemory* mapped_vm_snapshot_data = NULL; | 1571 MappedMemory* mapped_vm_snapshot_data = NULL; |
| 1572 MappedMemory* mapped_vm_snapshot_instructions = NULL; |
1482 MappedMemory* mapped_isolate_snapshot_data = NULL; | 1573 MappedMemory* mapped_isolate_snapshot_data = NULL; |
| 1574 MappedMemory* mapped_isolate_snapshot_instructions = NULL; |
1483 if (snapshot_kind == kScript) { | 1575 if (snapshot_kind == kScript) { |
1484 File* file = File::Open(vm_snapshot_data_filename, File::kRead); | 1576 mapped_vm_snapshot_data = |
1485 if (file == NULL) { | 1577 MapFile(vm_snapshot_data_filename, File::kReadOnly); |
1486 Log::PrintErr("Failed to open: %s\n", vm_snapshot_data_filename); | |
1487 return kErrorExitCode; | |
1488 } | |
1489 mapped_vm_snapshot_data = file->Map(File::kReadOnly, 0, file->Length()); | |
1490 if (mapped_vm_snapshot_data == NULL) { | |
1491 Log::PrintErr("Failed to read: %s\n", vm_snapshot_data_filename); | |
1492 return kErrorExitCode; | |
1493 } | |
1494 file->Release(); | |
1495 init_params.vm_snapshot_data = | 1578 init_params.vm_snapshot_data = |
1496 reinterpret_cast<const uint8_t*>(mapped_vm_snapshot_data->address()); | 1579 reinterpret_cast<const uint8_t*>(mapped_vm_snapshot_data->address()); |
1497 | 1580 |
1498 file = File::Open(isolate_snapshot_data_filename, File::kRead); | 1581 if (vm_snapshot_instructions_filename != NULL) { |
1499 if (file == NULL) { | 1582 mapped_vm_snapshot_instructions = |
1500 Log::PrintErr("Failed to open: %s\n", isolate_snapshot_data_filename); | 1583 MapFile(vm_snapshot_instructions_filename, File::kReadExecute); |
1501 return kErrorExitCode; | 1584 init_params.vm_snapshot_instructions = reinterpret_cast<const uint8_t*>( |
| 1585 mapped_vm_snapshot_instructions->address()); |
1502 } | 1586 } |
| 1587 |
1503 mapped_isolate_snapshot_data = | 1588 mapped_isolate_snapshot_data = |
1504 file->Map(File::kReadOnly, 0, file->Length()); | 1589 MapFile(isolate_snapshot_data_filename, File::kReadOnly); |
1505 if (mapped_isolate_snapshot_data == NULL) { | |
1506 Log::PrintErr("Failed to read: %s\n", isolate_snapshot_data_filename); | |
1507 return kErrorExitCode; | |
1508 } | |
1509 file->Release(); | |
1510 isolate_snapshot_data = reinterpret_cast<const uint8_t*>( | 1590 isolate_snapshot_data = reinterpret_cast<const uint8_t*>( |
1511 mapped_isolate_snapshot_data->address()); | 1591 mapped_isolate_snapshot_data->address()); |
| 1592 |
| 1593 if (isolate_snapshot_instructions_filename != NULL) { |
| 1594 mapped_isolate_snapshot_instructions = |
| 1595 MapFile(isolate_snapshot_instructions_filename, File::kReadExecute); |
| 1596 isolate_snapshot_instructions = reinterpret_cast<const uint8_t*>( |
| 1597 mapped_isolate_snapshot_instructions->address()); |
| 1598 } |
1512 } | 1599 } |
1513 | 1600 |
1514 char* error = Dart_Initialize(&init_params); | 1601 char* error = Dart_Initialize(&init_params); |
1515 if (error != NULL) { | 1602 if (error != NULL) { |
1516 Log::PrintErr("VM initialization failed: %s\n", error); | 1603 Log::PrintErr("VM initialization failed: %s\n", error); |
1517 free(error); | 1604 free(error); |
1518 return kErrorExitCode; | 1605 return kErrorExitCode; |
1519 } | 1606 } |
1520 | 1607 |
1521 IsolateData* isolate_data = new IsolateData(NULL, commandline_package_root, | 1608 IsolateData* isolate_data = new IsolateData(NULL, commandline_package_root, |
1522 commandline_packages_file, NULL); | 1609 commandline_packages_file, NULL); |
1523 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, isolate_snapshot_data, | 1610 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, isolate_snapshot_data, |
1524 NULL, NULL, isolate_data, &error); | 1611 isolate_snapshot_instructions, NULL, |
| 1612 isolate_data, &error); |
1525 if (isolate == NULL) { | 1613 if (isolate == NULL) { |
1526 Log::PrintErr("Error: %s\n", error); | 1614 Log::PrintErr("Error: %s\n", error); |
1527 free(error); | 1615 free(error); |
1528 exit(kErrorExitCode); | 1616 exit(kErrorExitCode); |
1529 } | 1617 } |
1530 | 1618 |
1531 Dart_Handle result; | 1619 Dart_Handle result; |
1532 Dart_Handle library; | 1620 Dart_Handle library; |
1533 Dart_EnterScope(); | 1621 Dart_EnterScope(); |
1534 | 1622 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1579 void* kernel_program = NULL; | 1667 void* kernel_program = NULL; |
1580 if (is_kernel_file) { | 1668 if (is_kernel_file) { |
1581 kernel_program = Dart_ReadKernelBinary(kernel, kernel_length); | 1669 kernel_program = Dart_ReadKernelBinary(kernel, kernel_length); |
1582 free(const_cast<uint8_t*>(kernel)); | 1670 free(const_cast<uint8_t*>(kernel)); |
1583 } | 1671 } |
1584 | 1672 |
1585 Dart_Isolate isolate = | 1673 Dart_Isolate isolate = |
1586 is_kernel_file | 1674 is_kernel_file |
1587 ? Dart_CreateIsolateFromKernel(NULL, NULL, kernel_program, NULL, | 1675 ? Dart_CreateIsolateFromKernel(NULL, NULL, kernel_program, NULL, |
1588 isolate_data, &error) | 1676 isolate_data, &error) |
1589 : Dart_CreateIsolate(NULL, NULL, isolate_snapshot_data, NULL, NULL, | 1677 : Dart_CreateIsolate(NULL, NULL, isolate_snapshot_data, |
| 1678 isolate_snapshot_instructions, NULL, |
1590 isolate_data, &error); | 1679 isolate_data, &error); |
1591 if (isolate == NULL) { | 1680 if (isolate == NULL) { |
1592 Log::PrintErr("%s\n", error); | 1681 Log::PrintErr("%s\n", error); |
1593 free(error); | 1682 free(error); |
1594 exit(kErrorExitCode); | 1683 exit(kErrorExitCode); |
1595 } | 1684 } |
1596 Dart_EnterScope(); | 1685 Dart_EnterScope(); |
1597 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 1686 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
1598 CHECK_RESULT(result); | 1687 CHECK_RESULT(result); |
1599 | 1688 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1633 | 1722 |
1634 // Ensure that we mark all libraries as loaded. | 1723 // Ensure that we mark all libraries as loaded. |
1635 result = Dart_FinalizeLoading(false); | 1724 result = Dart_FinalizeLoading(false); |
1636 CHECK_RESULT(result); | 1725 CHECK_RESULT(result); |
1637 | 1726 |
1638 if (!dependencies_only) { | 1727 if (!dependencies_only) { |
1639 switch (snapshot_kind) { | 1728 switch (snapshot_kind) { |
1640 case kCore: | 1729 case kCore: |
1641 CreateAndWriteCoreSnapshot(); | 1730 CreateAndWriteCoreSnapshot(); |
1642 break; | 1731 break; |
| 1732 case kCoreJIT: |
| 1733 CreateAndWriteCoreJITSnapshot(); |
| 1734 break; |
1643 case kScript: | 1735 case kScript: |
1644 CreateAndWriteScriptSnapshot(); | 1736 CreateAndWriteScriptSnapshot(); |
1645 break; | 1737 break; |
1646 case kAppAOTBlobs: | 1738 case kAppAOTBlobs: |
1647 case kAppAOTAssembly: | 1739 case kAppAOTAssembly: |
1648 CreateAndWritePrecompiledSnapshot(entry_points); | 1740 CreateAndWritePrecompiledSnapshot(entry_points); |
1649 break; | 1741 break; |
1650 default: | 1742 default: |
1651 UNREACHABLE(); | 1743 UNREACHABLE(); |
1652 } | 1744 } |
1653 } | 1745 } |
1654 | 1746 |
1655 CreateAndWriteDependenciesFile(); | 1747 CreateAndWriteDependenciesFile(); |
1656 | 1748 |
1657 Dart_ExitScope(); | 1749 Dart_ExitScope(); |
1658 Dart_ShutdownIsolate(); | 1750 Dart_ShutdownIsolate(); |
1659 | 1751 |
1660 CleanupEntryPointsCollection(entry_points); | 1752 CleanupEntryPointsCollection(entry_points); |
1661 | 1753 |
1662 Dart_EnterIsolate(UriResolverIsolateScope::isolate); | 1754 Dart_EnterIsolate(UriResolverIsolateScope::isolate); |
1663 Dart_ShutdownIsolate(); | 1755 Dart_ShutdownIsolate(); |
1664 } else { | 1756 } else { |
1665 SetupForGenericSnapshotCreation(); | 1757 SetupForGenericSnapshotCreation(); |
1666 CreateAndWriteCoreSnapshot(); | 1758 switch (snapshot_kind) { |
| 1759 case kCore: |
| 1760 CreateAndWriteCoreSnapshot(); |
| 1761 break; |
| 1762 case kCoreJIT: |
| 1763 CreateAndWriteCoreJITSnapshot(); |
| 1764 break; |
| 1765 default: |
| 1766 UNREACHABLE(); |
| 1767 break; |
| 1768 } |
1667 | 1769 |
1668 Dart_ExitScope(); | 1770 Dart_ExitScope(); |
1669 Dart_ShutdownIsolate(); | 1771 Dart_ShutdownIsolate(); |
1670 } | 1772 } |
1671 error = Dart_Cleanup(); | 1773 error = Dart_Cleanup(); |
1672 if (error != NULL) { | 1774 if (error != NULL) { |
1673 Log::PrintErr("VM cleanup failed: %s\n", error); | 1775 Log::PrintErr("VM cleanup failed: %s\n", error); |
1674 free(error); | 1776 free(error); |
1675 } | 1777 } |
1676 EventHandler::Stop(); | 1778 EventHandler::Stop(); |
1677 delete mapped_vm_snapshot_data; | 1779 delete mapped_vm_snapshot_data; |
1678 delete mapped_isolate_snapshot_data; | 1780 delete mapped_isolate_snapshot_data; |
1679 return 0; | 1781 return 0; |
1680 } | 1782 } |
1681 | 1783 |
1682 } // namespace bin | 1784 } // namespace bin |
1683 } // namespace dart | 1785 } // namespace dart |
1684 | 1786 |
1685 int main(int argc, char** argv) { | 1787 int main(int argc, char** argv) { |
1686 return dart::bin::main(argc, argv); | 1788 return dart::bin::main(argc, argv); |
1687 } | 1789 } |
OLD | NEW |