Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: runtime/bin/main.cc

Issue 2694103004: Cleanup app snapshots on isolate/vm exit. (Closed)
Patch Set: merge Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/isolate_data.cc ('k') | runtime/bin/snapshot_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 99
100 // Global flag that is used to indicate that we want to trace resolution of 100 // Global flag that is used to indicate that we want to trace resolution of
101 // URIs and the loading of libraries, parts and scripts. 101 // URIs and the loading of libraries, parts and scripts.
102 static bool trace_loading = false; 102 static bool trace_loading = false;
103 103
104 104
105 static char* app_script_uri = NULL; 105 static char* app_script_uri = NULL;
106 static const uint8_t* app_isolate_snapshot_data = NULL; 106 static const uint8_t* app_isolate_snapshot_data = NULL;
107 static const uint8_t* app_isolate_snapshot_instructions = NULL; 107 static const uint8_t* app_isolate_snapshot_instructions = NULL;
108 static AppSnapshot* app_snapshot = NULL;
108 109
109 110
110 static Dart_Isolate main_isolate = NULL; 111 static Dart_Isolate main_isolate = NULL;
111 112
112 113
113 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "localhost"; 114 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "localhost";
114 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; 115 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181;
115 // VM Service options. 116 // VM Service options.
116 static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP; 117 static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP;
117 // The 0 port is a magic value which results in the first available port 118 // The 0 port is a magic value which results in the first available port
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 packages_config = commandline_packages_file; 810 packages_config = commandline_packages_file;
810 } 811 }
811 } 812 }
812 813
813 #if defined(DART_PRECOMPILED_RUNTIME) 814 #if defined(DART_PRECOMPILED_RUNTIME)
814 // AOT: All isolates start from the app snapshot. 815 // AOT: All isolates start from the app snapshot.
815 bool isolate_run_app_snapshot = true; 816 bool isolate_run_app_snapshot = true;
816 const uint8_t* isolate_snapshot_data = app_isolate_snapshot_data; 817 const uint8_t* isolate_snapshot_data = app_isolate_snapshot_data;
817 const uint8_t* isolate_snapshot_instructions = 818 const uint8_t* isolate_snapshot_instructions =
818 app_isolate_snapshot_instructions; 819 app_isolate_snapshot_instructions;
820 AppSnapshot* app_snapshot = NULL;
819 #else 821 #else
820 // JIT: Main isolate starts from the app snapshot, if any. Other isolates 822 // JIT: Main isolate starts from the app snapshot, if any. Other isolates
821 // use the core libraries snapshot. 823 // use the core libraries snapshot.
822 bool isolate_run_app_snapshot = false; 824 bool isolate_run_app_snapshot = false;
823 const uint8_t* isolate_snapshot_data = core_isolate_snapshot_data; 825 const uint8_t* isolate_snapshot_data = core_isolate_snapshot_data;
824 const uint8_t* isolate_snapshot_instructions = 826 const uint8_t* isolate_snapshot_instructions =
825 core_isolate_snapshot_instructions; 827 core_isolate_snapshot_instructions;
828 AppSnapshot* app_snapshot = NULL;
826 if ((app_isolate_snapshot_data != NULL) && 829 if ((app_isolate_snapshot_data != NULL) &&
827 (is_main_isolate || ((app_script_uri != NULL) && 830 (is_main_isolate || ((app_script_uri != NULL) &&
828 (strcmp(script_uri, app_script_uri) == 0)))) { 831 (strcmp(script_uri, app_script_uri) == 0)))) {
829 isolate_run_app_snapshot = true; 832 isolate_run_app_snapshot = true;
830 isolate_snapshot_data = app_isolate_snapshot_data; 833 isolate_snapshot_data = app_isolate_snapshot_data;
831 isolate_snapshot_instructions = app_isolate_snapshot_instructions; 834 isolate_snapshot_instructions = app_isolate_snapshot_instructions;
832 } else if (!is_main_isolate) { 835 } else if (!is_main_isolate) {
833 const uint8_t* file_vm_snapshot_data = NULL; 836 app_snapshot = Snapshot::TryReadAppSnapshot(script_uri);
834 const uint8_t* file_vm_snapshot_instructions = NULL; 837 if (app_snapshot != NULL) {
835 const uint8_t* file_isolate_snapshot_data = NULL;
836 const uint8_t* file_isolate_snapshot_instructions = NULL;
837 if (Snapshot::ReadAppSnapshot(
838 script_uri, &file_vm_snapshot_data, &file_vm_snapshot_instructions,
839 &file_isolate_snapshot_data, &file_isolate_snapshot_instructions)) {
840 // TODO(rmacnak): We are leaking the snapshot when the isolate shuts down.
841 isolate_run_app_snapshot = true; 838 isolate_run_app_snapshot = true;
842 isolate_snapshot_data = file_isolate_snapshot_data; 839 const uint8_t* ignore_vm_snapshot_data;
843 isolate_snapshot_instructions = file_isolate_snapshot_instructions; 840 const uint8_t* ignore_vm_snapshot_instructions;
841 app_snapshot->SetBuffers(
842 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions,
843 &isolate_snapshot_data, &isolate_snapshot_instructions);
844 } 844 }
845 } 845 }
846 #endif 846 #endif
847 847
848 const uint8_t* kernel_file = NULL; 848 const uint8_t* kernel_file = NULL;
849 intptr_t kernel_length = -1; 849 intptr_t kernel_length = -1;
850 bool is_kernel = false; 850 bool is_kernel = false;
851 851
852 if (!is_kernel_isolate && !is_service_isolate) { 852 if (!is_kernel_isolate && !is_service_isolate) {
853 if (use_dart_frontend) { 853 if (use_dart_frontend) {
(...skipping 20 matching lines...) Expand all
874 } 874 }
875 } 875 }
876 876
877 void* kernel_program = NULL; 877 void* kernel_program = NULL;
878 if (is_kernel) { 878 if (is_kernel) {
879 kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length); 879 kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length);
880 free(const_cast<uint8_t*>(kernel_file)); 880 free(const_cast<uint8_t*>(kernel_file));
881 } 881 }
882 882
883 IsolateData* isolate_data = 883 IsolateData* isolate_data =
884 new IsolateData(script_uri, package_root, packages_config); 884 new IsolateData(script_uri, package_root, packages_config, app_snapshot);
885 // If the script is a Kernel binary, then we will try to bootstrap from the 885 // If the script is a Kernel binary, then we will try to bootstrap from the
886 // script. 886 // script.
887 Dart_Isolate isolate = 887 Dart_Isolate isolate =
888 is_kernel ? Dart_CreateIsolateFromKernel(script_uri, main, kernel_program, 888 is_kernel ? Dart_CreateIsolateFromKernel(script_uri, main, kernel_program,
889 flags, isolate_data, error) 889 flags, isolate_data, error)
890 : Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, 890 : Dart_CreateIsolate(script_uri, main, isolate_snapshot_data,
891 isolate_snapshot_instructions, flags, 891 isolate_snapshot_instructions, flags,
892 isolate_data, error); 892 isolate_data, error);
893 if (isolate == NULL) { 893 if (isolate == NULL) {
894 delete isolate_data; 894 delete isolate_data;
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 Thread::InitOnce(); 1632 Thread::InitOnce();
1633 1633
1634 Loader::InitOnce(); 1634 Loader::InitOnce();
1635 1635
1636 if (!DartUtils::SetOriginalWorkingDirectory()) { 1636 if (!DartUtils::SetOriginalWorkingDirectory()) {
1637 OSError err; 1637 OSError err;
1638 Log::PrintErr("Error determining current directory: %s\n", err.message()); 1638 Log::PrintErr("Error determining current directory: %s\n", err.message());
1639 Platform::Exit(kErrorExitCode); 1639 Platform::Exit(kErrorExitCode);
1640 } 1640 }
1641 1641
1642 if (Snapshot::ReadAppSnapshot( 1642 app_snapshot = Snapshot::TryReadAppSnapshot(script_name);
1643 script_name, &vm_snapshot_data, &vm_snapshot_instructions, 1643 if (app_snapshot != NULL) {
1644 &app_isolate_snapshot_data, &app_isolate_snapshot_instructions)) {
1645 vm_run_app_snapshot = true; 1644 vm_run_app_snapshot = true;
1645 app_snapshot->SetBuffers(&vm_snapshot_data, &vm_snapshot_instructions,
1646 &app_isolate_snapshot_data,
1647 &app_isolate_snapshot_instructions);
1646 } 1648 }
1647 1649
1648 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME) 1650 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
1649 // Constant true if PRODUCT or DART_PRECOMPILED_RUNTIME. 1651 // Constant true if PRODUCT or DART_PRECOMPILED_RUNTIME.
1650 if ((gen_snapshot_kind != kNone) || vm_run_app_snapshot) { 1652 if ((gen_snapshot_kind != kNone) || vm_run_app_snapshot) {
1651 vm_options.AddArgument("--load_deferred_eagerly"); 1653 vm_options.AddArgument("--load_deferred_eagerly");
1652 } 1654 }
1653 #endif 1655 #endif
1654 1656
1655 if (gen_snapshot_kind == kAppJIT) { 1657 if (gen_snapshot_kind == kAppJIT) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1711 // Terminate process exit-code handler. 1713 // Terminate process exit-code handler.
1712 Process::TerminateExitCodeHandler(); 1714 Process::TerminateExitCodeHandler();
1713 1715
1714 error = Dart_Cleanup(); 1716 error = Dart_Cleanup();
1715 if (error != NULL) { 1717 if (error != NULL) {
1716 Log::PrintErr("VM cleanup failed: %s\n", error); 1718 Log::PrintErr("VM cleanup failed: %s\n", error);
1717 free(error); 1719 free(error);
1718 } 1720 }
1719 EventHandler::Stop(); 1721 EventHandler::Stop();
1720 1722
1723 delete app_snapshot;
1721 free(app_script_uri); 1724 free(app_script_uri);
1722 1725
1723 // Free copied argument strings if converted. 1726 // Free copied argument strings if converted.
1724 if (argv_converted) { 1727 if (argv_converted) {
1725 for (int i = 0; i < argc; i++) { 1728 for (int i = 0; i < argc; i++) {
1726 free(argv[i]); 1729 free(argv[i]);
1727 } 1730 }
1728 } 1731 }
1729 1732
1730 // Free environment if any. 1733 // Free environment if any.
1731 if (environment != NULL) { 1734 if (environment != NULL) {
1732 for (HashMap::Entry* p = environment->Start(); p != NULL; 1735 for (HashMap::Entry* p = environment->Start(); p != NULL;
1733 p = environment->Next(p)) { 1736 p = environment->Next(p)) {
1734 free(p->key); 1737 free(p->key);
1735 free(p->value); 1738 free(p->value);
1736 } 1739 }
1737 delete environment; 1740 delete environment;
1738 } 1741 }
1739 1742
1740 Platform::Exit(Process::GlobalExitCode()); 1743 Platform::Exit(Process::GlobalExitCode());
1741 } 1744 }
1742 1745
1743 } // namespace bin 1746 } // namespace bin
1744 } // namespace dart 1747 } // namespace dart
1745 1748
1746 int main(int argc, char** argv) { 1749 int main(int argc, char** argv) {
1747 dart::bin::main(argc, argv); 1750 dart::bin::main(argc, argv);
1748 UNREACHABLE(); 1751 UNREACHABLE();
1749 } 1752 }
OLDNEW
« no previous file with comments | « runtime/bin/isolate_data.cc ('k') | runtime/bin/snapshot_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698