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