| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 kScript, | 58 kScript, |
| 59 kAppAOT, | 59 kAppAOT, |
| 60 kAppJIT, | 60 kAppJIT, |
| 61 }; | 61 }; |
| 62 static SnapshotKind gen_snapshot_kind = kNone; | 62 static SnapshotKind gen_snapshot_kind = kNone; |
| 63 | 63 |
| 64 static bool use_dart_frontend = false; | 64 static bool use_dart_frontend = false; |
| 65 | 65 |
| 66 static const char* frontend_filename = NULL; | 66 static const char* frontend_filename = NULL; |
| 67 | 67 |
| 68 // Value of the --save-feedback flag. | |
| 69 // (This pointer points into an argv buffer and does not need to be | |
| 70 // free'd.) | |
| 71 static const char* save_feedback_filename = NULL; | |
| 72 | |
| 73 // Value of the --load-feedback flag. | |
| 74 // (This pointer points into an argv buffer and does not need to be | |
| 75 // free'd.) | |
| 76 static const char* load_feedback_filename = NULL; | |
| 77 | |
| 78 // Value of the --package-root flag. | 68 // Value of the --package-root flag. |
| 79 // (This pointer points into an argv buffer and does not need to be | 69 // (This pointer points into an argv buffer and does not need to be |
| 80 // free'd.) | 70 // free'd.) |
| 81 static const char* commandline_package_root = NULL; | 71 static const char* commandline_package_root = NULL; |
| 82 | 72 |
| 83 // Value of the --packages flag. | 73 // Value of the --packages flag. |
| 84 // (This pointer points into an argv buffer and does not need to be | 74 // (This pointer points into an argv buffer and does not need to be |
| 85 // free'd.) | 75 // free'd.) |
| 86 static const char* commandline_packages_file = NULL; | 76 static const char* commandline_packages_file = NULL; |
| 87 | 77 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 CommandLineOptions* vm_options) { | 214 CommandLineOptions* vm_options) { |
| 225 ASSERT(arg != NULL); | 215 ASSERT(arg != NULL); |
| 226 if (*arg == '-') { | 216 if (*arg == '-') { |
| 227 return false; | 217 return false; |
| 228 } | 218 } |
| 229 commandline_packages_file = arg; | 219 commandline_packages_file = arg; |
| 230 return true; | 220 return true; |
| 231 } | 221 } |
| 232 | 222 |
| 233 | 223 |
| 234 static bool ProcessSaveFeedbackOption(const char* arg, | |
| 235 CommandLineOptions* vm_options) { | |
| 236 ASSERT(arg != NULL); | |
| 237 if (*arg == '-') { | |
| 238 return false; | |
| 239 } | |
| 240 save_feedback_filename = arg; | |
| 241 return true; | |
| 242 } | |
| 243 | |
| 244 | |
| 245 static bool ProcessLoadFeedbackOption(const char* arg, | |
| 246 CommandLineOptions* vm_options) { | |
| 247 ASSERT(arg != NULL); | |
| 248 if (*arg == '-') { | |
| 249 return false; | |
| 250 } | |
| 251 load_feedback_filename = arg; | |
| 252 return true; | |
| 253 } | |
| 254 | |
| 255 | |
| 256 static void* GetHashmapKeyFromString(char* key) { | 224 static void* GetHashmapKeyFromString(char* key) { |
| 257 return reinterpret_cast<void*>(key); | 225 return reinterpret_cast<void*>(key); |
| 258 } | 226 } |
| 259 | 227 |
| 260 | 228 |
| 261 static bool ExtractPortAndAddress(const char* option_value, | 229 static bool ExtractPortAndAddress(const char* option_value, |
| 262 int* out_port, | 230 int* out_port, |
| 263 const char** out_ip, | 231 const char** out_ip, |
| 264 int default_port, | 232 int default_port, |
| 265 const char* default_ip) { | 233 const char* default_ip) { |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 // VM specific options to the standalone dart program. | 557 // VM specific options to the standalone dart program. |
| 590 {"--compile_all", ProcessCompileAllOption}, | 558 {"--compile_all", ProcessCompileAllOption}, |
| 591 {"--parse_all", ProcessParseAllOption}, | 559 {"--parse_all", ProcessParseAllOption}, |
| 592 {"--dfe=", ProcessFrontendOption}, | 560 {"--dfe=", ProcessFrontendOption}, |
| 593 {"--enable-vm-service", ProcessEnableVmServiceOption}, | 561 {"--enable-vm-service", ProcessEnableVmServiceOption}, |
| 594 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, | 562 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, |
| 595 {"--observe", ProcessObserveOption}, | 563 {"--observe", ProcessObserveOption}, |
| 596 {"--snapshot=", ProcessSnapshotFilenameOption}, | 564 {"--snapshot=", ProcessSnapshotFilenameOption}, |
| 597 {"--snapshot-kind=", ProcessSnapshotKindOption}, | 565 {"--snapshot-kind=", ProcessSnapshotKindOption}, |
| 598 {"--use-blobs", ProcessUseBlobsOption}, | 566 {"--use-blobs", ProcessUseBlobsOption}, |
| 599 {"--save-feedback=", ProcessSaveFeedbackOption}, | |
| 600 {"--load-feedback=", ProcessLoadFeedbackOption}, | |
| 601 {"--trace-loading", ProcessTraceLoadingOption}, | 567 {"--trace-loading", ProcessTraceLoadingOption}, |
| 602 {"--hot-reload-test-mode", ProcessHotReloadTestModeOption}, | 568 {"--hot-reload-test-mode", ProcessHotReloadTestModeOption}, |
| 603 {"--hot-reload-rollback-test-mode", ProcessHotReloadRollbackTestModeOption}, | 569 {"--hot-reload-rollback-test-mode", ProcessHotReloadRollbackTestModeOption}, |
| 604 {"--short_socket_read", ProcessShortSocketReadOption}, | 570 {"--short_socket_read", ProcessShortSocketReadOption}, |
| 605 {"--short_socket_write", ProcessShortSocketWriteOption}, | 571 {"--short_socket_write", ProcessShortSocketWriteOption}, |
| 606 #if !defined(TARGET_OS_MACOS) | 572 #if !defined(TARGET_OS_MACOS) |
| 607 {"--root-certs-file=", ProcessRootCertsFileOption}, | 573 {"--root-certs-file=", ProcessRootCertsFileOption}, |
| 608 {"--root-certs-cache=", ProcessRootCertsCacheOption}, | 574 {"--root-certs-cache=", ProcessRootCertsCacheOption}, |
| 609 #endif // !defined(TARGET_OS_MACOS) | 575 #endif // !defined(TARGET_OS_MACOS) |
| 610 {NULL, NULL}}; | 576 {NULL, NULL}}; |
| (...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1524 isolate_buffer, isolate_size, instructions_blob_buffer, | 1490 isolate_buffer, isolate_size, instructions_blob_buffer, |
| 1525 instructions_blob_size, rodata_blob_buffer, | 1491 instructions_blob_size, rodata_blob_buffer, |
| 1526 rodata_blob_size); | 1492 rodata_blob_size); |
| 1527 } else { | 1493 } else { |
| 1528 WriteSnapshotFile(snapshot_filename, false, assembly_buffer, assembly_size); | 1494 WriteSnapshotFile(snapshot_filename, false, assembly_buffer, assembly_size); |
| 1529 } | 1495 } |
| 1530 } | 1496 } |
| 1531 | 1497 |
| 1532 | 1498 |
| 1533 #if defined(TARGET_ARCH_X64) | 1499 #if defined(TARGET_ARCH_X64) |
| 1534 static void GenerateAppJITSnapshot() { | 1500 static void GeneratePrecompiledJITSnapshot() { |
| 1535 uint8_t* vm_isolate_buffer = NULL; | 1501 uint8_t* vm_isolate_buffer = NULL; |
| 1536 intptr_t vm_isolate_size = 0; | 1502 intptr_t vm_isolate_size = 0; |
| 1537 uint8_t* isolate_buffer = NULL; | 1503 uint8_t* isolate_buffer = NULL; |
| 1538 intptr_t isolate_size = 0; | 1504 intptr_t isolate_size = 0; |
| 1539 uint8_t* instructions_blob_buffer = NULL; | 1505 uint8_t* instructions_blob_buffer = NULL; |
| 1540 intptr_t instructions_blob_size = 0; | 1506 intptr_t instructions_blob_size = 0; |
| 1541 uint8_t* rodata_blob_buffer = NULL; | 1507 uint8_t* rodata_blob_buffer = NULL; |
| 1542 intptr_t rodata_blob_size = 0; | 1508 intptr_t rodata_blob_size = 0; |
| 1543 Dart_Handle result = Dart_CreateAppJITSnapshot( | 1509 Dart_Handle result = Dart_CreateAppJITSnapshot( |
| 1544 &vm_isolate_buffer, &vm_isolate_size, &isolate_buffer, &isolate_size, | 1510 &vm_isolate_buffer, &vm_isolate_size, &isolate_buffer, &isolate_size, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1555 #endif // defined(TARGET_ARCH_X64) | 1521 #endif // defined(TARGET_ARCH_X64) |
| 1556 | 1522 |
| 1557 | 1523 |
| 1558 static void GenerateAppSnapshot() { | 1524 static void GenerateAppSnapshot() { |
| 1559 Dart_Handle result; | 1525 Dart_Handle result; |
| 1560 #if defined(TARGET_ARCH_X64) | 1526 #if defined(TARGET_ARCH_X64) |
| 1561 result = Dart_PrecompileJIT(); | 1527 result = Dart_PrecompileJIT(); |
| 1562 if (Dart_IsError(result)) { | 1528 if (Dart_IsError(result)) { |
| 1563 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1529 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
| 1564 } | 1530 } |
| 1565 GenerateAppJITSnapshot(); | 1531 GeneratePrecompiledJITSnapshot(); |
| 1566 #else | 1532 #else |
| 1567 // Create an application snapshot of the script. | 1533 // Create an application snapshot of the script. |
| 1568 uint8_t* vm_isolate_buffer = NULL; | 1534 uint8_t* vm_isolate_buffer = NULL; |
| 1569 intptr_t vm_isolate_size = 0; | 1535 intptr_t vm_isolate_size = 0; |
| 1570 uint8_t* isolate_buffer = NULL; | 1536 uint8_t* isolate_buffer = NULL; |
| 1571 intptr_t isolate_size = 0; | 1537 intptr_t isolate_size = 0; |
| 1572 | 1538 |
| 1573 result = Dart_CreateSnapshot(&vm_isolate_buffer, &vm_isolate_size, | 1539 result = Dart_CreateSnapshot(&vm_isolate_buffer, &vm_isolate_size, |
| 1574 &isolate_buffer, &isolate_size); | 1540 &isolate_buffer, &isolate_size); |
| 1575 if (Dart_IsError(result)) { | 1541 if (Dart_IsError(result)) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 {"dart:io", "_Platform", "set:_nativeScript"}, | 1680 {"dart:io", "_Platform", "set:_nativeScript"}, |
| 1715 {"dart:io", "_ProcessStartStatus", "set:_errorCode"}, | 1681 {"dart:io", "_ProcessStartStatus", "set:_errorCode"}, |
| 1716 {"dart:io", "_ProcessStartStatus", "set:_errorMessage"}, | 1682 {"dart:io", "_ProcessStartStatus", "set:_errorMessage"}, |
| 1717 {"dart:io", "_SecureFilterImpl", "get:buffers"}, | 1683 {"dart:io", "_SecureFilterImpl", "get:buffers"}, |
| 1718 {"dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE"}, | 1684 {"dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE"}, |
| 1719 {"dart:io", "_SecureFilterImpl", "get:SIZE"}, | 1685 {"dart:io", "_SecureFilterImpl", "get:SIZE"}, |
| 1720 {"dart:vmservice_io", "::", "main"}, | 1686 {"dart:vmservice_io", "::", "main"}, |
| 1721 {NULL, NULL, NULL} // Must be terminated with NULL entries. | 1687 {NULL, NULL, NULL} // Must be terminated with NULL entries. |
| 1722 }; | 1688 }; |
| 1723 | 1689 |
| 1724 uint8_t* feedback_buffer = NULL; | |
| 1725 intptr_t feedback_length = 0; | |
| 1726 if (load_feedback_filename != NULL) { | |
| 1727 File* file = File::Open(load_feedback_filename, File::kRead); | |
| 1728 if (file == NULL) { | |
| 1729 ErrorExit(kErrorExitCode, "Failed to read JIT feedback.\n"); | |
| 1730 } | |
| 1731 feedback_length = file->Length(); | |
| 1732 feedback_buffer = reinterpret_cast<uint8_t*>(malloc(feedback_length)); | |
| 1733 if (!file->ReadFully(feedback_buffer, feedback_length)) { | |
| 1734 ErrorExit(kErrorExitCode, "Failed to read JIT feedback.\n"); | |
| 1735 } | |
| 1736 file->Release(); | |
| 1737 } | |
| 1738 | |
| 1739 const bool reset_fields = gen_snapshot_kind == kAppAOT; | 1690 const bool reset_fields = gen_snapshot_kind == kAppAOT; |
| 1740 result = Dart_Precompile(standalone_entry_points, reset_fields, | 1691 result = Dart_Precompile(standalone_entry_points, reset_fields); |
| 1741 feedback_buffer, feedback_length); | |
| 1742 if (feedback_buffer != NULL) { | |
| 1743 free(feedback_buffer); | |
| 1744 } | |
| 1745 CHECK_RESULT(result); | 1692 CHECK_RESULT(result); |
| 1746 } | 1693 } |
| 1747 | 1694 |
| 1748 if (gen_snapshot_kind == kAppAOT) { | 1695 if (gen_snapshot_kind == kAppAOT) { |
| 1749 GeneratePrecompiledSnapshot(); | 1696 GeneratePrecompiledSnapshot(); |
| 1750 } else { | 1697 } else { |
| 1751 if (Dart_IsNull(root_lib)) { | 1698 if (Dart_IsNull(root_lib)) { |
| 1752 ErrorExit(kErrorExitCode, "Unable to find root library for '%s'\n", | 1699 ErrorExit(kErrorExitCode, "Unable to find root library for '%s'\n", |
| 1753 script_name); | 1700 script_name); |
| 1754 } | 1701 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1778 // Keep handling messages until the last active receive port is closed. | 1725 // Keep handling messages until the last active receive port is closed. |
| 1779 result = Dart_RunLoop(); | 1726 result = Dart_RunLoop(); |
| 1780 // Generate an app snapshot after execution if specified. | 1727 // Generate an app snapshot after execution if specified. |
| 1781 if (gen_snapshot_kind == kAppJIT) { | 1728 if (gen_snapshot_kind == kAppJIT) { |
| 1782 if (!Dart_IsCompilationError(result) && | 1729 if (!Dart_IsCompilationError(result) && |
| 1783 !Dart_IsVMRestartRequest(result)) { | 1730 !Dart_IsVMRestartRequest(result)) { |
| 1784 GenerateAppSnapshot(); | 1731 GenerateAppSnapshot(); |
| 1785 } | 1732 } |
| 1786 } | 1733 } |
| 1787 CHECK_RESULT(result); | 1734 CHECK_RESULT(result); |
| 1788 | |
| 1789 if (save_feedback_filename != NULL) { | |
| 1790 uint8_t* buffer = NULL; | |
| 1791 intptr_t size = 0; | |
| 1792 result = Dart_SaveJITFeedback(&buffer, &size); | |
| 1793 if (Dart_IsError(result)) { | |
| 1794 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | |
| 1795 } | |
| 1796 WriteSnapshotFile(save_feedback_filename, false, buffer, size); | |
| 1797 } | |
| 1798 } | 1735 } |
| 1799 } | 1736 } |
| 1800 | 1737 |
| 1801 Dart_ExitScope(); | 1738 Dart_ExitScope(); |
| 1802 // Shutdown the isolate. | 1739 // Shutdown the isolate. |
| 1803 Dart_ShutdownIsolate(); | 1740 Dart_ShutdownIsolate(); |
| 1804 | 1741 |
| 1805 // No restart. | 1742 // No restart. |
| 1806 return false; | 1743 return false; |
| 1807 } | 1744 } |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2047 Platform::Exit(Process::GlobalExitCode()); | 1984 Platform::Exit(Process::GlobalExitCode()); |
| 2048 } | 1985 } |
| 2049 | 1986 |
| 2050 } // namespace bin | 1987 } // namespace bin |
| 2051 } // namespace dart | 1988 } // namespace dart |
| 2052 | 1989 |
| 2053 int main(int argc, char** argv) { | 1990 int main(int argc, char** argv) { |
| 2054 dart::bin::main(argc, argv); | 1991 dart::bin::main(argc, argv); |
| 2055 UNREACHABLE(); | 1992 UNREACHABLE(); |
| 2056 } | 1993 } |
| OLD | NEW |