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

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

Issue 1275353005: VM thread shutdown. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 static void ErrorExit(int exit_code, const char* format, ...) { 101 static void ErrorExit(int exit_code, const char* format, ...) {
102 va_list arguments; 102 va_list arguments;
103 va_start(arguments, format); 103 va_start(arguments, format);
104 Log::VPrintErr(format, arguments); 104 Log::VPrintErr(format, arguments);
105 va_end(arguments); 105 va_end(arguments);
106 fflush(stderr); 106 fflush(stderr);
107 107
108 Dart_ExitScope(); 108 Dart_ExitScope();
109 Dart_ShutdownIsolate(); 109 Dart_ShutdownIsolate();
110 110
111 Dart_Cleanup(); 111 // Terminate process exit-code handler.
112 Process::TerminateExitCodeHandler();
112 113
114 char* error = Dart_Cleanup();
115 if (error != NULL) {
116 Log::PrintErr("VM cleanup failed: %s\n", error);
117 free(error);
118 }
119
120 EventHandler::Stop();
113 exit(exit_code); 121 exit(exit_code);
114 } 122 }
115 123
116 124
117 // The environment provided through the command line using -D options. 125 // The environment provided through the command line using -D options.
118 static dart::HashMap* environment = NULL; 126 static dart::HashMap* environment = NULL;
119 127
120 static bool IsValidFlag(const char* name, 128 static bool IsValidFlag(const char* name,
121 const char* prefix, 129 const char* prefix,
122 intptr_t prefix_length) { 130 intptr_t prefix_length) {
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 Dart_Isolate isolate = NULL; 625 Dart_Isolate isolate = NULL;
618 626
619 isolate = Dart_CreateIsolate(script_uri, 627 isolate = Dart_CreateIsolate(script_uri,
620 main, 628 main,
621 isolate_snapshot_buffer, 629 isolate_snapshot_buffer,
622 flags, 630 flags,
623 isolate_data, 631 isolate_data,
624 error); 632 error);
625 633
626 if (isolate == NULL) { 634 if (isolate == NULL) {
635 delete isolate_data;
627 return NULL; 636 return NULL;
628 } 637 }
629 638
630 Dart_EnterScope(); 639 Dart_EnterScope();
631 640
632 if (isolate_snapshot_buffer != NULL) { 641 if (isolate_snapshot_buffer != NULL) {
633 // Setup the native resolver as the snapshot does not carry it. 642 // Setup the native resolver as the snapshot does not carry it.
634 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); 643 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
635 Builtin::SetNativeResolver(Builtin::kIOLibrary); 644 Builtin::SetNativeResolver(Builtin::kIOLibrary);
636 } 645 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 // Load the script. 690 // Load the script.
682 result = DartUtils::LoadScript(script_uri, builtin_lib); 691 result = DartUtils::LoadScript(script_uri, builtin_lib);
683 CHECK_RESULT(result); 692 CHECK_RESULT(result);
684 693
685 // Run event-loop and wait for script loading to complete. 694 // Run event-loop and wait for script loading to complete.
686 result = Dart_RunLoop(); 695 result = Dart_RunLoop();
687 CHECK_RESULT(result); 696 CHECK_RESULT(result);
688 697
689 Platform::SetPackageRoot(package_root); 698 Platform::SetPackageRoot(package_root);
690 699
691 DartUtils::SetupIOLibrary(script_uri); 700 result = DartUtils::SetupIOLibrary(script_uri);
701 CHECK_RESULT(result);
692 702
693 // Make the isolate runnable so that it is ready to handle messages. 703 // Make the isolate runnable so that it is ready to handle messages.
694 Dart_ExitScope(); 704 Dart_ExitScope();
695 Dart_ExitIsolate(); 705 Dart_ExitIsolate();
696 bool retval = Dart_IsolateMakeRunnable(isolate); 706 bool retval = Dart_IsolateMakeRunnable(isolate);
697 if (!retval) { 707 if (!retval) {
698 *error = strdup("Invalid isolate state - Unable to make it runnable"); 708 *error = strdup("Invalid isolate state - Unable to make it runnable");
699 Dart_EnterIsolate(isolate); 709 Dart_EnterIsolate(isolate);
700 Dart_ShutdownIsolate(); 710 Dart_ShutdownIsolate();
701 return NULL; 711 return NULL;
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 bool print_msg = verbose_debug_seen || (debug_port == 0); 1032 bool print_msg = verbose_debug_seen || (debug_port == 0);
1023 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); 1033 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port);
1024 if (print_msg) { 1034 if (print_msg) {
1025 Log::Print("Debugger listening on port %d\n", debug_port); 1035 Log::Print("Debugger listening on port %d\n", debug_port);
1026 } 1036 }
1027 } else { 1037 } else {
1028 DebuggerConnectionHandler::InitForVmService(); 1038 DebuggerConnectionHandler::InitForVmService();
1029 } 1039 }
1030 1040
1031 // Initialize the Dart VM. 1041 // Initialize the Dart VM.
1032 if (!Dart_Initialize(vm_isolate_snapshot_buffer, 1042 char* error = Dart_Initialize(vm_isolate_snapshot_buffer,
Ivan Posva 2015/08/17 13:35:51 Shouldn't the API return a const char*?
zra 2015/08/18 06:23:14 free() takes a non-const pointer, so the compiler
1033 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, 1043 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate,
1034 DartUtils::OpenFile, 1044 DartUtils::OpenFile,
1035 DartUtils::ReadFile, 1045 DartUtils::ReadFile,
1036 DartUtils::WriteFile, 1046 DartUtils::WriteFile,
1037 DartUtils::CloseFile, 1047 DartUtils::CloseFile,
1038 DartUtils::EntropySource)) { 1048 DartUtils::EntropySource);
1039 fprintf(stderr, "%s", "VM initialization failed\n"); 1049 if (error != NULL) {
1050 EventHandler::Stop();
1051 fprintf(stderr, "VM initialization failed: %s\n", error);
1040 fflush(stderr); 1052 fflush(stderr);
1053 free(error);
1041 exit(kErrorExitCode); 1054 exit(kErrorExitCode);
1042 } 1055 }
1043 1056
1044 Dart_RegisterIsolateServiceRequestCallback( 1057 Dart_RegisterIsolateServiceRequestCallback(
1045 "getIO", &ServiceGetIOHandler, NULL); 1058 "getIO", &ServiceGetIOHandler, NULL);
1046 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, 1059 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback,
1047 &ServiceStreamCancelCallback); 1060 &ServiceStreamCancelCallback);
1048 1061
1049 // Call CreateIsolateAndSetup which creates an isolate and loads up 1062 // Call CreateIsolateAndSetup which creates an isolate and loads up
1050 // the specified application script. 1063 // the specified application script.
1051 char* error = NULL;
1052 int exit_code = 0; 1064 int exit_code = 0;
1053 char* isolate_name = BuildIsolateName(script_name, "main"); 1065 char* isolate_name = BuildIsolateName(script_name, "main");
1054 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, 1066 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name,
1055 "main", 1067 "main",
1056 commandline_package_root, 1068 commandline_package_root,
1057 commandline_packages_file, 1069 commandline_packages_file,
1058 NULL, 1070 NULL,
1059 &error, 1071 &error,
1060 &exit_code); 1072 &exit_code);
1061 if (isolate == NULL) { 1073 if (isolate == NULL) {
1062 Log::PrintErr("%s\n", error); 1074 Log::PrintErr("%s\n", error);
1063 free(error); 1075 free(error);
1076 error = NULL;
1064 delete [] isolate_name; 1077 delete [] isolate_name;
1078 Process::TerminateExitCodeHandler();
1079 error = Dart_Cleanup();
Florian Schneider 2015/08/19 09:02:03 Same question as Ivan: Dart::Cleanup() return a c
1080 if (error != NULL) {
1081 Log::PrintErr("VM cleanup failed: %s\n", error);
1082 free(error);
1083 }
1084 EventHandler::Stop();
1065 exit((exit_code != 0) ? exit_code : kErrorExitCode); 1085 exit((exit_code != 0) ? exit_code : kErrorExitCode);
1066 } 1086 }
1067 delete [] isolate_name; 1087 delete [] isolate_name;
1068 1088
1069 Dart_EnterIsolate(isolate); 1089 Dart_EnterIsolate(isolate);
1070 ASSERT(isolate == Dart_CurrentIsolate()); 1090 ASSERT(isolate == Dart_CurrentIsolate());
1071 ASSERT(isolate != NULL); 1091 ASSERT(isolate != NULL);
1072 Dart_Handle result; 1092 Dart_Handle result;
1073 1093
1074 Dart_EnterScope(); 1094 Dart_EnterScope();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 result = Dart_RunLoop(); 1178 result = Dart_RunLoop();
1159 DartExitOnError(result); 1179 DartExitOnError(result);
1160 } 1180 }
1161 1181
1162 Dart_ExitScope(); 1182 Dart_ExitScope();
1163 // Shutdown the isolate. 1183 // Shutdown the isolate.
1164 Dart_ShutdownIsolate(); 1184 Dart_ShutdownIsolate();
1165 // Terminate process exit-code handler. 1185 // Terminate process exit-code handler.
1166 Process::TerminateExitCodeHandler(); 1186 Process::TerminateExitCodeHandler();
1167 1187
1168 Dart_Cleanup(); 1188 error = Dart_Cleanup();
1189 if (error != NULL) {
1190 Log::PrintErr("VM cleanup failed: %s\n", error);
1191 free(error);
1192 }
1193
1194 EventHandler::Stop();
1169 1195
1170 // Free copied argument strings if converted. 1196 // Free copied argument strings if converted.
1171 if (argv_converted) { 1197 if (argv_converted) {
1172 for (int i = 0; i < argc; i++) free(argv[i]); 1198 for (int i = 0; i < argc; i++) free(argv[i]);
1173 } 1199 }
1174 1200
1175 // Free environment if any. 1201 // Free environment if any.
1176 if (environment != NULL) { 1202 if (environment != NULL) {
1177 for (HashMap::Entry* p = environment->Start(); 1203 for (HashMap::Entry* p = environment->Start();
1178 p != NULL; 1204 p != NULL;
1179 p = environment->Next(p)) { 1205 p = environment->Next(p)) {
1180 free(p->key); 1206 free(p->key);
1181 free(p->value); 1207 free(p->value);
1182 } 1208 }
1183 delete environment; 1209 delete environment;
1184 } 1210 }
1185 1211
1186 exit(Process::GlobalExitCode()); 1212 exit(Process::GlobalExitCode());
1187 } 1213 }
1188 1214
1189 } // namespace bin 1215 } // namespace bin
1190 } // namespace dart 1216 } // namespace dart
1191 1217
1192 int main(int argc, char** argv) { 1218 int main(int argc, char** argv) {
1193 dart::bin::main(argc, argv); 1219 dart::bin::main(argc, argv);
1194 UNREACHABLE(); 1220 UNREACHABLE();
1195 } 1221 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698