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

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

Issue 1270323002: Revert VM thread cleanup (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
« no previous file with comments | « runtime/bin/gen_snapshot.cc ('k') | runtime/bin/process.cc » ('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 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 // Terminate process exit-code handler. 111 Dart_Cleanup();
112 Process::TerminateExitCodeHandler();
113
114 char* error = Dart_Cleanup();
115 if (error != NULL) {
116 Log::PrintErr("VM cleanup failed: %s\n", error);
117 free(error);
118 }
119 112
120 exit(exit_code); 113 exit(exit_code);
121 } 114 }
122 115
123 116
124 // The environment provided through the command line using -D options. 117 // The environment provided through the command line using -D options.
125 static dart::HashMap* environment = NULL; 118 static dart::HashMap* environment = NULL;
126 119
127 static bool IsValidFlag(const char* name, 120 static bool IsValidFlag(const char* name,
128 const char* prefix, 121 const char* prefix,
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 Dart_Isolate isolate = NULL; 617 Dart_Isolate isolate = NULL;
625 618
626 isolate = Dart_CreateIsolate(script_uri, 619 isolate = Dart_CreateIsolate(script_uri,
627 main, 620 main,
628 isolate_snapshot_buffer, 621 isolate_snapshot_buffer,
629 flags, 622 flags,
630 isolate_data, 623 isolate_data,
631 error); 624 error);
632 625
633 if (isolate == NULL) { 626 if (isolate == NULL) {
634 delete isolate_data;
635 return NULL; 627 return NULL;
636 } 628 }
637 629
638 Dart_EnterScope(); 630 Dart_EnterScope();
639 631
640 if (isolate_snapshot_buffer != NULL) { 632 if (isolate_snapshot_buffer != NULL) {
641 // Setup the native resolver as the snapshot does not carry it. 633 // Setup the native resolver as the snapshot does not carry it.
642 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); 634 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
643 Builtin::SetNativeResolver(Builtin::kIOLibrary); 635 Builtin::SetNativeResolver(Builtin::kIOLibrary);
644 } 636 }
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 bool print_msg = verbose_debug_seen || (debug_port == 0); 1022 bool print_msg = verbose_debug_seen || (debug_port == 0);
1031 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); 1023 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port);
1032 if (print_msg) { 1024 if (print_msg) {
1033 Log::Print("Debugger listening on port %d\n", debug_port); 1025 Log::Print("Debugger listening on port %d\n", debug_port);
1034 } 1026 }
1035 } else { 1027 } else {
1036 DebuggerConnectionHandler::InitForVmService(); 1028 DebuggerConnectionHandler::InitForVmService();
1037 } 1029 }
1038 1030
1039 // Initialize the Dart VM. 1031 // Initialize the Dart VM.
1040 char* error = Dart_Initialize(vm_isolate_snapshot_buffer, 1032 if (!Dart_Initialize(vm_isolate_snapshot_buffer,
1041 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, 1033 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate,
1042 DartUtils::OpenFile, 1034 DartUtils::OpenFile,
1043 DartUtils::ReadFile, 1035 DartUtils::ReadFile,
1044 DartUtils::WriteFile, 1036 DartUtils::WriteFile,
1045 DartUtils::CloseFile, 1037 DartUtils::CloseFile,
1046 DartUtils::EntropySource); 1038 DartUtils::EntropySource)) {
1047 if (error != NULL) { 1039 fprintf(stderr, "%s", "VM initialization failed\n");
1048 fprintf(stderr, "VM initialization failed: %s\n", error);
1049 fflush(stderr); 1040 fflush(stderr);
1050 free(error);
1051 exit(kErrorExitCode); 1041 exit(kErrorExitCode);
1052 } 1042 }
1053 1043
1054 Dart_RegisterIsolateServiceRequestCallback( 1044 Dart_RegisterIsolateServiceRequestCallback(
1055 "getIO", &ServiceGetIOHandler, NULL); 1045 "getIO", &ServiceGetIOHandler, NULL);
1056 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, 1046 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback,
1057 &ServiceStreamCancelCallback); 1047 &ServiceStreamCancelCallback);
1058 1048
1059 // Call CreateIsolateAndSetup which creates an isolate and loads up 1049 // Call CreateIsolateAndSetup which creates an isolate and loads up
1060 // the specified application script. 1050 // the specified application script.
1051 char* error = NULL;
1061 int exit_code = 0; 1052 int exit_code = 0;
1062 char* isolate_name = BuildIsolateName(script_name, "main"); 1053 char* isolate_name = BuildIsolateName(script_name, "main");
1063 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, 1054 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name,
1064 "main", 1055 "main",
1065 commandline_package_root, 1056 commandline_package_root,
1066 commandline_packages_file, 1057 commandline_packages_file,
1067 NULL, 1058 NULL,
1068 &error, 1059 &error,
1069 &exit_code); 1060 &exit_code);
1070 if (isolate == NULL) { 1061 if (isolate == NULL) {
1071 Log::PrintErr("%s\n", error); 1062 Log::PrintErr("%s\n", error);
1072 free(error); 1063 free(error);
1073 error = NULL;
1074 delete [] isolate_name; 1064 delete [] isolate_name;
1075 Process::TerminateExitCodeHandler();
1076 error = Dart_Cleanup();
1077 if (error != NULL) {
1078 Log::PrintErr("VM cleanup failed: %s\n", error);
1079 free(error);
1080 }
1081 exit((exit_code != 0) ? exit_code : kErrorExitCode); 1065 exit((exit_code != 0) ? exit_code : kErrorExitCode);
1082 } 1066 }
1083 delete [] isolate_name; 1067 delete [] isolate_name;
1084 1068
1085 Dart_EnterIsolate(isolate); 1069 Dart_EnterIsolate(isolate);
1086 ASSERT(isolate == Dart_CurrentIsolate()); 1070 ASSERT(isolate == Dart_CurrentIsolate());
1087 ASSERT(isolate != NULL); 1071 ASSERT(isolate != NULL);
1088 Dart_Handle result; 1072 Dart_Handle result;
1089 1073
1090 Dart_EnterScope(); 1074 Dart_EnterScope();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 result = Dart_RunLoop(); 1158 result = Dart_RunLoop();
1175 DartExitOnError(result); 1159 DartExitOnError(result);
1176 } 1160 }
1177 1161
1178 Dart_ExitScope(); 1162 Dart_ExitScope();
1179 // Shutdown the isolate. 1163 // Shutdown the isolate.
1180 Dart_ShutdownIsolate(); 1164 Dart_ShutdownIsolate();
1181 // Terminate process exit-code handler. 1165 // Terminate process exit-code handler.
1182 Process::TerminateExitCodeHandler(); 1166 Process::TerminateExitCodeHandler();
1183 1167
1184 error = Dart_Cleanup(); 1168 Dart_Cleanup();
1185 if (error != NULL) {
1186 Log::PrintErr("VM cleanup failed: %s\n", error);
1187 free(error);
1188 }
1189 1169
1190 // Free copied argument strings if converted. 1170 // Free copied argument strings if converted.
1191 if (argv_converted) { 1171 if (argv_converted) {
1192 for (int i = 0; i < argc; i++) free(argv[i]); 1172 for (int i = 0; i < argc; i++) free(argv[i]);
1193 } 1173 }
1194 1174
1195 // Free environment if any. 1175 // Free environment if any.
1196 if (environment != NULL) { 1176 if (environment != NULL) {
1197 for (HashMap::Entry* p = environment->Start(); 1177 for (HashMap::Entry* p = environment->Start();
1198 p != NULL; 1178 p != NULL;
1199 p = environment->Next(p)) { 1179 p = environment->Next(p)) {
1200 free(p->key); 1180 free(p->key);
1201 free(p->value); 1181 free(p->value);
1202 } 1182 }
1203 delete environment; 1183 delete environment;
1204 } 1184 }
1205 1185
1206 exit(Process::GlobalExitCode()); 1186 exit(Process::GlobalExitCode());
1207 } 1187 }
1208 1188
1209 } // namespace bin 1189 } // namespace bin
1210 } // namespace dart 1190 } // namespace dart
1211 1191
1212 int main(int argc, char** argv) { 1192 int main(int argc, char** argv) {
1213 dart::bin::main(argc, argv); 1193 dart::bin::main(argc, argv);
1214 UNREACHABLE(); 1194 UNREACHABLE();
1215 } 1195 }
OLDNEW
« no previous file with comments | « runtime/bin/gen_snapshot.cc ('k') | runtime/bin/process.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698