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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 } | 348 } |
349 if (name != NULL) { | 349 if (name != NULL) { |
350 print_dependencies = true; | 350 print_dependencies = true; |
351 return true; | 351 return true; |
352 } | 352 } |
353 return false; | 353 return false; |
354 } | 354 } |
355 | 355 |
356 static bool ProcessEmbedderEntryPointsManifestOption(const char* option) { | 356 static bool ProcessEmbedderEntryPointsManifestOption(const char* option) { |
357 const char* name = ProcessOption(option, "--embedder_entry_points_manifest="); | 357 const char* name = ProcessOption(option, "--embedder_entry_points_manifest="); |
| 358 if (name == NULL) { |
| 359 name = ProcessOption(option, "--embedder-entry-points-manifest="); |
| 360 } |
358 if (name != NULL) { | 361 if (name != NULL) { |
359 entry_points_files->AddArgument(name); | 362 entry_points_files->AddArgument(name); |
360 return true; | 363 return true; |
361 } | 364 } |
362 return false; | 365 return false; |
363 } | 366 } |
364 | 367 |
365 | 368 |
366 static bool ProcessLoadCompilationTraceOption(const char* option) { | 369 static bool ProcessLoadCompilationTraceOption(const char* option) { |
367 const char* name = ProcessOption(option, "--load_compilation_trace="); | 370 const char* name = ProcessOption(option, "--load_compilation_trace="); |
| 371 if (name == NULL) { |
| 372 name = ProcessOption(option, "--load-compilation-trace="); |
| 373 } |
368 if (name != NULL) { | 374 if (name != NULL) { |
369 load_compilation_trace_filename = name; | 375 load_compilation_trace_filename = name; |
370 return true; | 376 return true; |
371 } | 377 } |
372 return false; | 378 return false; |
373 } | 379 } |
374 | 380 |
375 | 381 |
376 static bool ProcessPackageRootOption(const char* option) { | 382 static bool ProcessPackageRootOption(const char* option) { |
377 const char* name = ProcessOption(option, "--package_root="); | 383 const char* name = ProcessOption(option, "--package_root="); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 if (Dart_IsError(resolved_uri)) { | 690 if (Dart_IsError(resolved_uri)) { |
685 return resolved_uri; | 691 return resolved_uri; |
686 } | 692 } |
687 // Now load the contents of the specified uri. | 693 // Now load the contents of the specified uri. |
688 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_uri); | 694 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_uri); |
689 Dart_Handle source = LoadUrlContents(resolved_uri_string); | 695 Dart_Handle source = LoadUrlContents(resolved_uri_string); |
690 | 696 |
691 if (Dart_IsError(source)) { | 697 if (Dart_IsError(source)) { |
692 return source; | 698 return source; |
693 } | 699 } |
694 if (snapshot_kind == kCore) { | 700 if (snapshot_kind == kCore || snapshot_kind == kCoreJIT) { |
695 return Dart_LoadLibrary(resolved_uri, Dart_Null(), source, 0, 0); | 701 return Dart_LoadLibrary(resolved_uri, Dart_Null(), source, 0, 0); |
696 } else { | 702 } else { |
697 return Dart_LoadScript(resolved_uri, Dart_Null(), source, 0, 0); | 703 return Dart_LoadScript(resolved_uri, Dart_Null(), source, 0, 0); |
698 } | 704 } |
699 } | 705 } |
700 | 706 |
701 | 707 |
702 static Builtin::BuiltinLibraryId BuiltinId(const char* url) { | 708 static Builtin::BuiltinLibraryId BuiltinId(const char* url) { |
703 if (DartUtils::IsDartBuiltinLibURL(url)) { | 709 if (DartUtils::IsDartBuiltinLibURL(url)) { |
704 return Builtin::kBuiltinLibrary; | 710 return Builtin::kBuiltinLibrary; |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 false /* trace_loading */)) { | 1535 false /* trace_loading */)) { |
1530 *error = strdup(VmService::GetErrorMessage()); | 1536 *error = strdup(VmService::GetErrorMessage()); |
1531 return NULL; | 1537 return NULL; |
1532 } | 1538 } |
1533 Dart_ExitScope(); | 1539 Dart_ExitScope(); |
1534 Dart_ExitIsolate(); | 1540 Dart_ExitIsolate(); |
1535 return isolate; | 1541 return isolate; |
1536 } | 1542 } |
1537 | 1543 |
1538 | 1544 |
1539 static MappedMemory* MapFile(const char* filename, File::MapType type) { | 1545 static MappedMemory* MapFile(const char* filename, |
| 1546 File::MapType type, |
| 1547 const uint8_t** buffer) { |
1540 File* file = File::Open(filename, File::kRead); | 1548 File* file = File::Open(filename, File::kRead); |
1541 if (file == NULL) { | 1549 if (file == NULL) { |
1542 Log::PrintErr("Failed to open: %s\n", filename); | 1550 Log::PrintErr("Failed to open: %s\n", filename); |
1543 exit(kErrorExitCode); | 1551 exit(kErrorExitCode); |
1544 } | 1552 } |
1545 MappedMemory* mapping = file->Map(type, 0, file->Length()); | 1553 intptr_t length = file->Length(); |
| 1554 if (length == 0) { |
| 1555 // Can't map an empty file. |
| 1556 *buffer = NULL; |
| 1557 return NULL; |
| 1558 } |
| 1559 MappedMemory* mapping = file->Map(type, 0, length); |
1546 if (mapping == NULL) { | 1560 if (mapping == NULL) { |
1547 Log::PrintErr("Failed to read: %s\n", vm_snapshot_data_filename); | 1561 Log::PrintErr("Failed to read: %s\n", filename); |
1548 exit(kErrorExitCode); | 1562 exit(kErrorExitCode); |
1549 } | 1563 } |
1550 file->Release(); | 1564 file->Release(); |
| 1565 *buffer = reinterpret_cast<const uint8_t*>(mapping->address()); |
1551 return mapping; | 1566 return mapping; |
1552 } | 1567 } |
1553 | 1568 |
1554 | 1569 |
1555 int main(int argc, char** argv) { | 1570 int main(int argc, char** argv) { |
1556 const int EXTRA_VM_ARGUMENTS = 2; | 1571 const int EXTRA_VM_ARGUMENTS = 2; |
1557 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); | 1572 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); |
1558 | 1573 |
1559 // Initialize the URL mapping array. | 1574 // Initialize the URL mapping array. |
1560 CommandLineOptions cmdline_url_mapping(argc); | 1575 CommandLineOptions cmdline_url_mapping(argc); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1612 init_params.file_write = DartUtils::WriteFile; | 1627 init_params.file_write = DartUtils::WriteFile; |
1613 init_params.file_close = DartUtils::CloseFile; | 1628 init_params.file_close = DartUtils::CloseFile; |
1614 init_params.entropy_source = DartUtils::EntropySource; | 1629 init_params.entropy_source = DartUtils::EntropySource; |
1615 | 1630 |
1616 MappedMemory* mapped_vm_snapshot_data = NULL; | 1631 MappedMemory* mapped_vm_snapshot_data = NULL; |
1617 MappedMemory* mapped_vm_snapshot_instructions = NULL; | 1632 MappedMemory* mapped_vm_snapshot_instructions = NULL; |
1618 MappedMemory* mapped_isolate_snapshot_data = NULL; | 1633 MappedMemory* mapped_isolate_snapshot_data = NULL; |
1619 MappedMemory* mapped_isolate_snapshot_instructions = NULL; | 1634 MappedMemory* mapped_isolate_snapshot_instructions = NULL; |
1620 if (snapshot_kind == kScript) { | 1635 if (snapshot_kind == kScript) { |
1621 mapped_vm_snapshot_data = | 1636 mapped_vm_snapshot_data = |
1622 MapFile(vm_snapshot_data_filename, File::kReadOnly); | 1637 MapFile(vm_snapshot_data_filename, File::kReadOnly, |
1623 init_params.vm_snapshot_data = | 1638 &init_params.vm_snapshot_data); |
1624 reinterpret_cast<const uint8_t*>(mapped_vm_snapshot_data->address()); | |
1625 | 1639 |
1626 if (vm_snapshot_instructions_filename != NULL) { | 1640 if (vm_snapshot_instructions_filename != NULL) { |
1627 mapped_vm_snapshot_instructions = | 1641 mapped_vm_snapshot_instructions = |
1628 MapFile(vm_snapshot_instructions_filename, File::kReadExecute); | 1642 MapFile(vm_snapshot_instructions_filename, File::kReadExecute, |
1629 init_params.vm_snapshot_instructions = reinterpret_cast<const uint8_t*>( | 1643 &init_params.vm_snapshot_instructions); |
1630 mapped_vm_snapshot_instructions->address()); | |
1631 } | 1644 } |
1632 | 1645 |
1633 mapped_isolate_snapshot_data = | 1646 mapped_isolate_snapshot_data = |
1634 MapFile(isolate_snapshot_data_filename, File::kReadOnly); | 1647 MapFile(isolate_snapshot_data_filename, File::kReadOnly, |
1635 isolate_snapshot_data = reinterpret_cast<const uint8_t*>( | 1648 &isolate_snapshot_data); |
1636 mapped_isolate_snapshot_data->address()); | |
1637 | 1649 |
1638 if (isolate_snapshot_instructions_filename != NULL) { | 1650 if (isolate_snapshot_instructions_filename != NULL) { |
1639 mapped_isolate_snapshot_instructions = | 1651 mapped_isolate_snapshot_instructions = |
1640 MapFile(isolate_snapshot_instructions_filename, File::kReadExecute); | 1652 MapFile(isolate_snapshot_instructions_filename, File::kReadExecute, |
1641 isolate_snapshot_instructions = reinterpret_cast<const uint8_t*>( | 1653 &isolate_snapshot_instructions); |
1642 mapped_isolate_snapshot_instructions->address()); | |
1643 } | 1654 } |
1644 } | 1655 } |
1645 | 1656 |
1646 char* error = Dart_Initialize(&init_params); | 1657 char* error = Dart_Initialize(&init_params); |
1647 if (error != NULL) { | 1658 if (error != NULL) { |
1648 Log::PrintErr("VM initialization failed: %s\n", error); | 1659 Log::PrintErr("VM initialization failed: %s\n", error); |
1649 free(error); | 1660 free(error); |
1650 return kErrorExitCode; | 1661 return kErrorExitCode; |
1651 } | 1662 } |
1652 | 1663 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1818 Dart_ExitScope(); | 1829 Dart_ExitScope(); |
1819 Dart_ShutdownIsolate(); | 1830 Dart_ShutdownIsolate(); |
1820 } | 1831 } |
1821 error = Dart_Cleanup(); | 1832 error = Dart_Cleanup(); |
1822 if (error != NULL) { | 1833 if (error != NULL) { |
1823 Log::PrintErr("VM cleanup failed: %s\n", error); | 1834 Log::PrintErr("VM cleanup failed: %s\n", error); |
1824 free(error); | 1835 free(error); |
1825 } | 1836 } |
1826 EventHandler::Stop(); | 1837 EventHandler::Stop(); |
1827 delete mapped_vm_snapshot_data; | 1838 delete mapped_vm_snapshot_data; |
| 1839 delete mapped_vm_snapshot_instructions; |
1828 delete mapped_isolate_snapshot_data; | 1840 delete mapped_isolate_snapshot_data; |
| 1841 delete mapped_isolate_snapshot_instructions; |
1829 return 0; | 1842 return 0; |
1830 } | 1843 } |
1831 | 1844 |
1832 } // namespace bin | 1845 } // namespace bin |
1833 } // namespace dart | 1846 } // namespace dart |
1834 | 1847 |
1835 int main(int argc, char** argv) { | 1848 int main(int argc, char** argv) { |
1836 return dart::bin::main(argc, argv); | 1849 return dart::bin::main(argc, argv); |
1837 } | 1850 } |
OLD | NEW |