| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 90 // dart functions and not run anything. | 90 // dart functions and not run anything. | 
| 91 static bool compile_all = false; | 91 static bool compile_all = false; | 
| 92 static bool parse_all = false; | 92 static bool parse_all = false; | 
| 93 | 93 | 
| 94 | 94 | 
| 95 // Global flag that is used to indicate that we want to use blobs/mmap instead | 95 // Global flag that is used to indicate that we want to use blobs/mmap instead | 
| 96 // of assembly/shared libraries for precompilation. | 96 // of assembly/shared libraries for precompilation. | 
| 97 static bool use_blobs = false; | 97 static bool use_blobs = false; | 
| 98 | 98 | 
| 99 | 99 | 
| 100 // Global flag that is used to indicate that we want to compile everything in |  | 
| 101 // the same way as precompilation before main, then continue running in the |  | 
| 102 // same process. |  | 
| 103 // Always set this with dart_noopt. |  | 
| 104 #if defined(DART_PRECOMPILER) && !defined(DART_NO_SNAPSHOT) |  | 
| 105 static const bool is_noopt = true; |  | 
| 106 #else |  | 
| 107 static const bool is_noopt = false; |  | 
| 108 #endif |  | 
| 109 |  | 
| 110 |  | 
| 111 extern const char* kPrecompiledVMIsolateSymbolName; | 100 extern const char* kPrecompiledVMIsolateSymbolName; | 
| 112 extern const char* kPrecompiledIsolateSymbolName; | 101 extern const char* kPrecompiledIsolateSymbolName; | 
| 113 extern const char* kPrecompiledInstructionsSymbolName; | 102 extern const char* kPrecompiledInstructionsSymbolName; | 
| 114 extern const char* kPrecompiledDataSymbolName; | 103 extern const char* kPrecompiledDataSymbolName; | 
| 115 | 104 | 
| 116 | 105 | 
| 117 // Global flag that is used to indicate that we want to trace resolution of | 106 // Global flag that is used to indicate that we want to trace resolution of | 
| 118 // URIs and the loading of libraries, parts and scripts. | 107 // URIs and the loading of libraries, parts and scripts. | 
| 119 static bool trace_loading = false; | 108 static bool trace_loading = false; | 
| 120 | 109 | 
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 723   if ((commandline_package_root != NULL) && | 712   if ((commandline_package_root != NULL) && | 
| 724       (strlen(commandline_package_root) == 0)) { | 713       (strlen(commandline_package_root) == 0)) { | 
| 725     Log::PrintErr("Empty package root specified.\n"); | 714     Log::PrintErr("Empty package root specified.\n"); | 
| 726     return -1; | 715     return -1; | 
| 727   } | 716   } | 
| 728   if ((commandline_packages_file != NULL) && | 717   if ((commandline_packages_file != NULL) && | 
| 729       (strlen(commandline_packages_file) == 0)) { | 718       (strlen(commandline_packages_file) == 0)) { | 
| 730     Log::PrintErr("Empty package file name specified.\n"); | 719     Log::PrintErr("Empty package file name specified.\n"); | 
| 731     return -1; | 720     return -1; | 
| 732   } | 721   } | 
| 733   if (is_noopt && gen_snapshot_kind != kNone) { |  | 
| 734     Log::PrintErr("Generating a snapshot with dart_noopt is invalid.\n"); |  | 
| 735     return -1; |  | 
| 736   } |  | 
| 737   if ((gen_snapshot_kind != kNone) && (snapshot_filename == NULL)) { | 722   if ((gen_snapshot_kind != kNone) && (snapshot_filename == NULL)) { | 
| 738     Log::PrintErr("Generating a snapshot requires a filename (--snapshot).\n"); | 723     Log::PrintErr("Generating a snapshot requires a filename (--snapshot).\n"); | 
| 739     return -1; | 724     return -1; | 
| 740   } | 725   } | 
| 741   if ((gen_snapshot_kind != kNone) && run_app_snapshot) { | 726   if ((gen_snapshot_kind != kNone) && run_app_snapshot) { | 
| 742     Log::PrintErr( | 727     Log::PrintErr( | 
| 743         "Specifying an option to generate a snapshot and" | 728         "Specifying an option to generate a snapshot and" | 
| 744         " run using a snapshot is invalid.\n"); | 729         " run using a snapshot is invalid.\n"); | 
| 745     return -1; | 730     return -1; | 
| 746   } | 731   } | 
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 823 | 808 | 
| 824 // Returns true on success, false on failure. | 809 // Returns true on success, false on failure. | 
| 825 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, | 810 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, | 
| 826                                                 const char* main, | 811                                                 const char* main, | 
| 827                                                 const char* package_root, | 812                                                 const char* package_root, | 
| 828                                                 const char* packages_config, | 813                                                 const char* packages_config, | 
| 829                                                 Dart_IsolateFlags* flags, | 814                                                 Dart_IsolateFlags* flags, | 
| 830                                                 char** error, | 815                                                 char** error, | 
| 831                                                 int* exit_code) { | 816                                                 int* exit_code) { | 
| 832   ASSERT(script_uri != NULL); | 817   ASSERT(script_uri != NULL); | 
| 833 |  | 
| 834   const bool needs_load_port = true; |  | 
| 835 #if defined(PRODUCT) |  | 
| 836   const bool run_service_isolate = needs_load_port; |  | 
| 837 #else |  | 
| 838   // Always create the service isolate in DEBUG and RELEASE modes for profiling, |  | 
| 839   // even if we don't need it for loading. |  | 
| 840   const bool run_service_isolate = true; |  | 
| 841 #endif  // PRODUCT |  | 
| 842   if (!run_service_isolate && |  | 
| 843       (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0)) { |  | 
| 844     return NULL; |  | 
| 845   } |  | 
| 846   if (strcmp(script_uri, DART_KERNEL_ISOLATE_NAME) == 0) { | 818   if (strcmp(script_uri, DART_KERNEL_ISOLATE_NAME) == 0) { | 
| 847     if (!use_dart_frontend) { | 819     if (!use_dart_frontend) { | 
| 848       *error = strdup("Kernel isolate not supported."); | 820       *error = strdup("Kernel isolate not supported."); | 
| 849       return NULL; | 821       return NULL; | 
| 850     } else { | 822     } else { | 
| 851       if (packages_config == NULL) { | 823       if (packages_config == NULL) { | 
| 852         packages_config = commandline_packages_file; | 824         packages_config = commandline_packages_file; | 
| 853       } | 825       } | 
| 854     } | 826     } | 
| 855   } | 827   } | 
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 918     Dart_ExitIsolate(); | 890     Dart_ExitIsolate(); | 
| 919     return isolate; | 891     return isolate; | 
| 920   } | 892   } | 
| 921 | 893 | 
| 922   // Prepare builtin and other core libraries for use to resolve URIs. | 894   // Prepare builtin and other core libraries for use to resolve URIs. | 
| 923   // Set up various closures, e.g: printing, timers etc. | 895   // Set up various closures, e.g: printing, timers etc. | 
| 924   // Set up 'package root' for URI resolution. | 896   // Set up 'package root' for URI resolution. | 
| 925   result = DartUtils::PrepareForScriptLoading(false, trace_loading); | 897   result = DartUtils::PrepareForScriptLoading(false, trace_loading); | 
| 926   CHECK_RESULT(result); | 898   CHECK_RESULT(result); | 
| 927 | 899 | 
| 928   if (needs_load_port) { | 900   // Set up the load port provided by the service isolate so that we can | 
| 929     // Set up the load port provided by the service isolate so that we can | 901   // load scripts. | 
| 930     // load scripts. | 902   result = DartUtils::SetupServiceLoadPort(); | 
| 931     result = DartUtils::SetupServiceLoadPort(); | 903   CHECK_RESULT(result); | 
| 932     CHECK_RESULT(result); |  | 
| 933   } |  | 
| 934 | 904 | 
| 935   if (Dart_IsKernelIsolate(isolate)) { | 905   if (Dart_IsKernelIsolate(isolate)) { | 
| 936     script_uri = frontend_filename; | 906     script_uri = frontend_filename; | 
| 937   } | 907   } | 
| 938 | 908 | 
| 939   // Setup package root if specified. | 909   // Setup package root if specified. | 
| 940   result = DartUtils::SetupPackageRoot(package_root, packages_config); | 910   result = DartUtils::SetupPackageRoot(package_root, packages_config); | 
| 941   CHECK_RESULT(result); | 911   CHECK_RESULT(result); | 
| 942 | 912 | 
| 943   result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 913   result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1652     GenerateScriptSnapshot(); | 1622     GenerateScriptSnapshot(); | 
| 1653   } else { | 1623   } else { | 
| 1654     // Lookup the library of the root script. | 1624     // Lookup the library of the root script. | 
| 1655     Dart_Handle root_lib = Dart_RootLibrary(); | 1625     Dart_Handle root_lib = Dart_RootLibrary(); | 
| 1656     // Import the root library into the builtin library so that we can easily | 1626     // Import the root library into the builtin library so that we can easily | 
| 1657     // lookup the main entry point exported from the root library. | 1627     // lookup the main entry point exported from the root library. | 
| 1658     IsolateData* isolate_data = | 1628     IsolateData* isolate_data = | 
| 1659         reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); | 1629         reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); | 
| 1660     result = Dart_LibraryImportLibrary(isolate_data->builtin_lib(), root_lib, | 1630     result = Dart_LibraryImportLibrary(isolate_data->builtin_lib(), root_lib, | 
| 1661                                        Dart_Null()); | 1631                                        Dart_Null()); | 
| 1662     if (is_noopt || (gen_snapshot_kind == kAppAOT) || | 1632     if ((gen_snapshot_kind == kAppAOT) || (gen_snapshot_kind == kAppJIT)) { | 
| 1663         (gen_snapshot_kind == kAppJIT)) { |  | 
| 1664       // Load the embedder's portion of the VM service's Dart code so it will | 1633       // Load the embedder's portion of the VM service's Dart code so it will | 
| 1665       // be included in the app snapshot. | 1634       // be included in the app snapshot. | 
| 1666       if (!VmService::LoadForGenPrecompiled()) { | 1635       if (!VmService::LoadForGenPrecompiled()) { | 
| 1667         Log::PrintErr("VM service loading failed: %s\n", | 1636         Log::PrintErr("VM service loading failed: %s\n", | 
| 1668                       VmService::GetErrorMessage()); | 1637                       VmService::GetErrorMessage()); | 
| 1669         exit(kErrorExitCode); | 1638         exit(kErrorExitCode); | 
| 1670       } | 1639       } | 
| 1671     } | 1640     } | 
| 1672 | 1641 | 
| 1673     if (compile_all) { | 1642     if (compile_all) { | 
| 1674       result = Dart_CompileAll(); | 1643       result = Dart_CompileAll(); | 
| 1675       CHECK_RESULT(result); | 1644       CHECK_RESULT(result); | 
| 1676     } | 1645     } | 
| 1677 | 1646 | 
| 1678     if (parse_all) { | 1647     if (parse_all) { | 
| 1679       result = Dart_ParseAll(); | 1648       result = Dart_ParseAll(); | 
| 1680       CHECK_RESULT(result); | 1649       CHECK_RESULT(result); | 
| 1681       Dart_ExitScope(); | 1650       Dart_ExitScope(); | 
| 1682       // Shutdown the isolate. | 1651       // Shutdown the isolate. | 
| 1683       Dart_ShutdownIsolate(); | 1652       Dart_ShutdownIsolate(); | 
| 1684       return false; | 1653       return false; | 
| 1685     } | 1654     } | 
| 1686 | 1655 | 
| 1687     if (is_noopt || (gen_snapshot_kind == kAppAOT)) { | 1656     if (gen_snapshot_kind == kAppAOT) { | 
| 1688       Dart_QualifiedFunctionName standalone_entry_points[] = { | 1657       Dart_QualifiedFunctionName standalone_entry_points[] = { | 
| 1689           {"dart:_builtin", "::", "_getMainClosure"}, | 1658           {"dart:_builtin", "::", "_getMainClosure"}, | 
| 1690           {"dart:_builtin", "::", "_getPrintClosure"}, | 1659           {"dart:_builtin", "::", "_getPrintClosure"}, | 
| 1691           {"dart:_builtin", "::", "_getUriBaseClosure"}, | 1660           {"dart:_builtin", "::", "_getUriBaseClosure"}, | 
| 1692           {"dart:_builtin", "::", "_resolveInWorkingDirectory"}, | 1661           {"dart:_builtin", "::", "_resolveInWorkingDirectory"}, | 
| 1693           {"dart:_builtin", "::", "_setWorkingDirectory"}, | 1662           {"dart:_builtin", "::", "_setWorkingDirectory"}, | 
| 1694           {"dart:_builtin", "::", "_setPackageRoot"}, | 1663           {"dart:_builtin", "::", "_setPackageRoot"}, | 
| 1695           {"dart:_builtin", "::", "_setPackagesMap"}, | 1664           {"dart:_builtin", "::", "_setPackagesMap"}, | 
| 1696           {"dart:_builtin", "::", "_libraryFilePath"}, | 1665           {"dart:_builtin", "::", "_libraryFilePath"}, | 
| 1697           {"dart:io", "::", "_makeUint8ListView"}, | 1666           {"dart:io", "::", "_makeUint8ListView"}, | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1730           ErrorExit(kErrorExitCode, "Failed to read JIT feedback.\n"); | 1699           ErrorExit(kErrorExitCode, "Failed to read JIT feedback.\n"); | 
| 1731         } | 1700         } | 
| 1732         feedback_length = file->Length(); | 1701         feedback_length = file->Length(); | 
| 1733         feedback_buffer = reinterpret_cast<uint8_t*>(malloc(feedback_length)); | 1702         feedback_buffer = reinterpret_cast<uint8_t*>(malloc(feedback_length)); | 
| 1734         if (!file->ReadFully(feedback_buffer, feedback_length)) { | 1703         if (!file->ReadFully(feedback_buffer, feedback_length)) { | 
| 1735           ErrorExit(kErrorExitCode, "Failed to read JIT feedback.\n"); | 1704           ErrorExit(kErrorExitCode, "Failed to read JIT feedback.\n"); | 
| 1736         } | 1705         } | 
| 1737         file->Release(); | 1706         file->Release(); | 
| 1738       } | 1707       } | 
| 1739 | 1708 | 
| 1740       const bool reset_fields = gen_snapshot_kind == kAppAOT; | 1709       result = Dart_Precompile(standalone_entry_points, feedback_buffer, | 
| 1741       result = Dart_Precompile(standalone_entry_points, reset_fields, | 1710                                feedback_length); | 
| 1742                                feedback_buffer, feedback_length); |  | 
| 1743       if (feedback_buffer != NULL) { | 1711       if (feedback_buffer != NULL) { | 
| 1744         free(feedback_buffer); | 1712         free(feedback_buffer); | 
| 1745       } | 1713       } | 
| 1746       CHECK_RESULT(result); | 1714       CHECK_RESULT(result); | 
| 1747     } | 1715     } | 
| 1748 | 1716 | 
| 1749     if (gen_snapshot_kind == kAppAOT) { | 1717     if (gen_snapshot_kind == kAppAOT) { | 
| 1750       GeneratePrecompiledSnapshot(); | 1718       GeneratePrecompiledSnapshot(); | 
| 1751     } else { | 1719     } else { | 
| 1752       if (Dart_IsNull(root_lib)) { | 1720       if (Dart_IsNull(root_lib)) { | 
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1960     vm_options.AddArgument("--load_deferred_eagerly"); | 1928     vm_options.AddArgument("--load_deferred_eagerly"); | 
| 1961   } | 1929   } | 
| 1962 #endif | 1930 #endif | 
| 1963 | 1931 | 
| 1964   if (gen_snapshot_kind == kAppJIT) { | 1932   if (gen_snapshot_kind == kAppJIT) { | 
| 1965     vm_options.AddArgument("--fields_may_be_reset"); | 1933     vm_options.AddArgument("--fields_may_be_reset"); | 
| 1966 #if !defined(PRODUCT) | 1934 #if !defined(PRODUCT) | 
| 1967     vm_options.AddArgument("--collect_code=false"); | 1935     vm_options.AddArgument("--collect_code=false"); | 
| 1968 #endif | 1936 #endif | 
| 1969   } | 1937   } | 
| 1970   if ((gen_snapshot_kind == kAppAOT) || is_noopt) { | 1938   if (gen_snapshot_kind == kAppAOT) { | 
| 1971     vm_options.AddArgument("--precompilation"); | 1939     vm_options.AddArgument("--precompilation"); | 
| 1972   } | 1940   } | 
| 1973 #if defined(DART_PRECOMPILED_RUNTIME) | 1941 #if defined(DART_PRECOMPILED_RUNTIME) | 
| 1974   vm_options.AddArgument("--precompilation"); | 1942   vm_options.AddArgument("--precompilation"); | 
| 1975 #endif | 1943 #endif | 
| 1976   if (gen_snapshot_kind == kAppJIT) { | 1944   if (gen_snapshot_kind == kAppJIT) { | 
| 1977     Process::SetExitHook(SnapshotOnExitHook); | 1945     Process::SetExitHook(SnapshotOnExitHook); | 
| 1978   } | 1946   } | 
| 1979 | 1947 | 
| 1980   Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1948   Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2048   Platform::Exit(Process::GlobalExitCode()); | 2016   Platform::Exit(Process::GlobalExitCode()); | 
| 2049 } | 2017 } | 
| 2050 | 2018 | 
| 2051 }  // namespace bin | 2019 }  // namespace bin | 
| 2052 }  // namespace dart | 2020 }  // namespace dart | 
| 2053 | 2021 | 
| 2054 int main(int argc, char** argv) { | 2022 int main(int argc, char** argv) { | 
| 2055   dart::bin::main(argc, argv); | 2023   dart::bin::main(argc, argv); | 
| 2056   UNREACHABLE(); | 2024   UNREACHABLE(); | 
| 2057 } | 2025 } | 
| OLD | NEW | 
|---|