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

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

Issue 584023004: Service isolate rework (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
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_debugger_api.h" 10 #include "include/dart_debugger_api.h"
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 // The builtin library is part of the core snapshot and would already be 579 // The builtin library is part of the core snapshot and would already be
580 // available here in the case of script snapshot loading. 580 // available here in the case of script snapshot loading.
581 Dart_Handle builtin_lib = 581 Dart_Handle builtin_lib =
582 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); 582 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
583 CHECK_RESULT(builtin_lib); 583 CHECK_RESULT(builtin_lib);
584 584
585 // Prepare for script loading by setting up the 'print' and 'timer' 585 // Prepare for script loading by setting up the 'print' and 'timer'
586 // closures and setting up 'package root' for URI resolution. 586 // closures and setting up 'package root' for URI resolution.
587 result = DartUtils::PrepareForScriptLoading(package_root, builtin_lib); 587 result = DartUtils::PrepareForScriptLoading(package_root, builtin_lib);
588 CHECK_RESULT(result); 588 CHECK_RESULT(result);
589 589 if (strcmp(script_uri, "vm-service") == 0) {
590 VmService::SetupIsolate(vm_service_server_ip, vm_service_server_port);
591 Dart_ExitScope();
592 Dart_ExitIsolate();
593 return isolate;
594 }
590 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(data); 595 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(data);
591 ASSERT(isolate_data != NULL); 596 ASSERT(isolate_data != NULL);
592 ASSERT(isolate_data->script_url != NULL); 597 ASSERT(isolate_data->script_url != NULL);
593 result = DartUtils::LoadScript(isolate_data->script_url, builtin_lib); 598 result = DartUtils::LoadScript(isolate_data->script_url, builtin_lib);
594 CHECK_RESULT(result); 599 CHECK_RESULT(result);
595 600
596 // Run event-loop and wait for script loading to complete. 601 // Run event-loop and wait for script loading to complete.
597 result = Dart_RunLoop(); 602 result = Dart_RunLoop();
598 CHECK_RESULT(result); 603 CHECK_RESULT(result);
599 604
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 } 652 }
648 IsolateData* isolate_data = new IsolateData(script_uri); 653 IsolateData* isolate_data = new IsolateData(script_uri);
649 return CreateIsolateAndSetupHelper(script_uri, 654 return CreateIsolateAndSetupHelper(script_uri,
650 main, 655 main,
651 isolate_data, 656 isolate_data,
652 error, 657 error,
653 &is_compile_error); 658 &is_compile_error);
654 } 659 }
655 660
656 661
657 #define CHECK_RESULT(result) \
658 if (Dart_IsError(result)) { \
659 *error = strdup(Dart_GetError(result)); \
660 Dart_ExitScope(); \
661 Dart_ShutdownIsolate(); \
662 return NULL; \
663 } \
664
665 static Dart_Isolate CreateServiceIsolate(void* data, char** error) {
666 const char* script_uri = DartUtils::kVMServiceLibURL;
667 IsolateData* isolate_data = new IsolateData(script_uri);
668 Dart_Isolate isolate =
669 Dart_CreateIsolate(script_uri, "main", snapshot_buffer, isolate_data,
670 error);
671 if (isolate == NULL) {
672 return NULL;
673 }
674 Dart_EnterScope();
675 if (snapshot_buffer != NULL) {
676 // Setup the native resolver as the snapshot does not carry it.
677 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
678 Builtin::SetNativeResolver(Builtin::kIOLibrary);
679 }
680 // Set up the library tag handler for this isolate.
681 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler);
682 CHECK_RESULT(result);
683 result = Dart_SetEnvironmentCallback(EnvironmentCallback);
684 CHECK_RESULT(result);
685 // Prepare builtin and its dependent libraries for use to resolve URIs.
686 Dart_Handle builtin_lib =
687 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
688 CHECK_RESULT(builtin_lib);
689 // Prepare for script loading by setting up the 'print' and 'timer'
690 // closures and setting up 'package root' for URI resolution.
691 result = DartUtils::PrepareForScriptLoading(package_root, builtin_lib);
692 CHECK_RESULT(result);
693
694 Dart_ExitScope();
695 Dart_ExitIsolate();
696 return isolate;
697 }
698
699 #undef CHECK_RESULT
700
701 static void PrintVersion() { 662 static void PrintVersion() {
702 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); 663 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString());
703 } 664 }
704 665
705 666
706 static void PrintUsage() { 667 static void PrintUsage() {
707 Log::PrintErr( 668 Log::PrintErr(
708 "Usage: dart [<vm-flags>] <dart-script-file> [<dart-options>]\n" 669 "Usage: dart [<vm-flags>] <dart-script-file> [<dart-options>]\n"
709 "\n" 670 "\n"
710 "Executes the Dart script passed as <dart-script-file>.\n" 671 "Executes the Dart script passed as <dart-script-file>.\n"
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 932
972 if (!DartUtils::SetOriginalWorkingDirectory()) { 933 if (!DartUtils::SetOriginalWorkingDirectory()) {
973 OSError err; 934 OSError err;
974 fprintf(stderr, "Error determining current directory: %s\n", err.message()); 935 fprintf(stderr, "Error determining current directory: %s\n", err.message());
975 fflush(stderr); 936 fflush(stderr);
976 exit(kErrorExitCode); 937 exit(kErrorExitCode);
977 } 938 }
978 939
979 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 940 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
980 941
942 // Start event handler.
943 EventHandler::Start();
944
981 // Initialize the Dart VM. 945 // Initialize the Dart VM.
982 if (!Dart_Initialize(CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, 946 if (!Dart_Initialize(CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate,
983 DartUtils::OpenFile, 947 DartUtils::OpenFile,
984 DartUtils::ReadFile, 948 DartUtils::ReadFile,
985 DartUtils::WriteFile, 949 DartUtils::WriteFile,
986 DartUtils::CloseFile, 950 DartUtils::CloseFile,
987 DartUtils::EntropySource, 951 DartUtils::EntropySource)) {
988 CreateServiceIsolate)) {
989 fprintf(stderr, "%s", "VM initialization failed\n"); 952 fprintf(stderr, "%s", "VM initialization failed\n");
990 fflush(stderr); 953 fflush(stderr);
991 exit(kErrorExitCode); 954 exit(kErrorExitCode);
992 } 955 }
993 956
994 // Start event handler. 957
995 EventHandler::Start();
996 958
997 // Start the debugger wire protocol handler if necessary. 959 // Start the debugger wire protocol handler if necessary.
998 if (start_debugger) { 960 if (start_debugger) {
999 ASSERT(debug_port >= 0); 961 ASSERT(debug_port >= 0);
1000 bool print_msg = verbose_debug_seen || (debug_port == 0); 962 bool print_msg = verbose_debug_seen || (debug_port == 0);
1001 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); 963 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port);
1002 if (print_msg) { 964 if (print_msg) {
1003 Log::Print("Debugger listening on port %d\n", debug_port); 965 Log::Print("Debugger listening on port %d\n", debug_port);
1004 } 966 }
1005 } 967 }
1006 968
1007 ASSERT(Dart_CurrentIsolate() == NULL); 969 DebuggerConnectionHandler::InitForVmService();
1008 // Start the VM service isolate, if necessary. 970 Dart_RegisterIsolateServiceRequestCallback(
1009 if (start_vm_service) {
1010 if (!start_debugger) {
1011 DebuggerConnectionHandler::InitForVmService();
1012 }
1013 bool r = VmService::Start(vm_service_server_ip, vm_service_server_port);
1014 if (!r) {
1015 Log::PrintErr("Could not start VM Service isolate %s\n",
1016 VmService::GetErrorMessage());
1017 }
1018 Dart_RegisterIsolateServiceRequestCallback(
1019 "io", &ServiceRequestHandler, NULL); 971 "io", &ServiceRequestHandler, NULL);
1020 }
1021 ASSERT(Dart_CurrentIsolate() == NULL);
1022 972
1023 // Call CreateIsolateAndSetup which creates an isolate and loads up 973 // Call CreateIsolateAndSetup which creates an isolate and loads up
1024 // the specified application script. 974 // the specified application script.
1025 char* error = NULL; 975 char* error = NULL;
1026 bool is_compile_error = false; 976 bool is_compile_error = false;
1027 char* isolate_name = BuildIsolateName(script_name, "main"); 977 char* isolate_name = BuildIsolateName(script_name, "main");
1028 IsolateData* isolate_data = new IsolateData(script_name); 978 IsolateData* isolate_data = new IsolateData(script_name);
1029 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, 979 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name,
1030 "main", 980 "main",
1031 isolate_data, 981 isolate_data,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 exit(Process::GlobalExitCode()); 1109 exit(Process::GlobalExitCode());
1160 } 1110 }
1161 1111
1162 } // namespace bin 1112 } // namespace bin
1163 } // namespace dart 1113 } // namespace dart
1164 1114
1165 int main(int argc, char** argv) { 1115 int main(int argc, char** argv) {
1166 dart::bin::main(argc, argv); 1116 dart::bin::main(argc, argv);
1167 UNREACHABLE(); 1117 UNREACHABLE();
1168 } 1118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698