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

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

Issue 125103004: Move service into VM (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 char errbuf[256]; 517 char errbuf[256];
518 snprintf(errbuf, sizeof(errbuf), 518 snprintf(errbuf, sizeof(errbuf),
519 "Expected a library when loading script: %s", 519 "Expected a library when loading script: %s",
520 script_uri); 520 script_uri);
521 *error = strdup(errbuf); 521 *error = strdup(errbuf);
522 Dart_ExitScope(); 522 Dart_ExitScope();
523 Dart_ShutdownIsolate(); 523 Dart_ShutdownIsolate();
524 return NULL; 524 return NULL;
525 } 525 }
526 526
527
527 Platform::SetPackageRoot(package_root); 528 Platform::SetPackageRoot(package_root);
528 Dart_Handle io_lib_url = DartUtils::NewString("dart:io"); 529 Dart_Handle io_lib_url = DartUtils::NewString(DartUtils::kIOLibURL);
529 CHECK_RESULT(io_lib_url); 530 CHECK_RESULT(io_lib_url);
530 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url); 531 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url);
531 CHECK_RESULT(io_lib); 532 CHECK_RESULT(io_lib);
532 Dart_Handle platform_class_name = DartUtils::NewString("Platform"); 533 Dart_Handle platform_type = DartUtils::GetDartType(DartUtils::kIOLibURL,
533 CHECK_RESULT(platform_class_name); 534 "Platform");
534 Dart_Handle platform_type =
535 Dart_GetType(io_lib, platform_class_name, 0, NULL);
536 CHECK_RESULT(platform_type); 535 CHECK_RESULT(platform_type);
537 Dart_Handle script_name_name = DartUtils::NewString("_nativeScript"); 536 Dart_Handle script_name = DartUtils::NewString("_nativeScript");
538 CHECK_RESULT(script_name_name); 537 CHECK_RESULT(script_name);
539 Dart_Handle dart_script = DartUtils::NewString(script_uri); 538 Dart_Handle dart_script = DartUtils::NewString(script_uri);
540 CHECK_RESULT(dart_script); 539 CHECK_RESULT(dart_script);
541 Dart_Handle set_script_name = 540 Dart_Handle set_script_name =
542 Dart_SetField(platform_type, script_name_name, dart_script); 541 Dart_SetField(platform_type, script_name, dart_script);
543 CHECK_RESULT(set_script_name); 542 CHECK_RESULT(set_script_name);
544 543
545 VmService::SendIsolateStartupMessage();
546
547 // Make the isolate runnable so that it is ready to handle messages. 544 // Make the isolate runnable so that it is ready to handle messages.
548 Dart_ExitScope(); 545 Dart_ExitScope();
549 Dart_ExitIsolate(); 546 Dart_ExitIsolate();
550 bool retval = Dart_IsolateMakeRunnable(isolate); 547 bool retval = Dart_IsolateMakeRunnable(isolate);
551 if (!retval) { 548 if (!retval) {
552 *error = strdup("Invalid isolate state - Unable to make it runnable"); 549 *error = strdup("Invalid isolate state - Unable to make it runnable");
553 Dart_EnterIsolate(isolate); 550 Dart_EnterIsolate(isolate);
554 Dart_ShutdownIsolate(); 551 Dart_ShutdownIsolate();
555 return NULL; 552 return NULL;
556 } 553 }
557 554
558 return isolate; 555 return isolate;
siva 2014/01/14 18:19:00 I think we should define CHECK_RESULT in the begin
Cutch 2014/01/14 19:53:26 Done.
559 } 556 }
560 557
561 558
562 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, 559 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri,
563 const char* main, 560 const char* main,
564 void* data, char** error) { 561 void* data, char** error) {
565 bool is_compile_error = false; 562 bool is_compile_error = false;
566 if (script_uri == NULL) { 563 if (script_uri == NULL) {
567 if (data == NULL) { 564 if (data == NULL) {
568 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); 565 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate");
569 return NULL; 566 return NULL;
570 } 567 }
571 IsolateData* parent_isolate_data = reinterpret_cast<IsolateData*>(data); 568 IsolateData* parent_isolate_data = reinterpret_cast<IsolateData*>(data);
572 script_uri = parent_isolate_data->script_url; 569 script_uri = parent_isolate_data->script_url;
573 if (script_uri == NULL) { 570 if (script_uri == NULL) {
574 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); 571 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate");
575 return NULL; 572 return NULL;
576 } 573 }
577 } 574 }
578 IsolateData* isolate_data = new IsolateData(script_uri); 575 IsolateData* isolate_data = new IsolateData(script_uri);
579 return CreateIsolateAndSetupHelper(script_uri, 576 return CreateIsolateAndSetupHelper(script_uri,
580 main, 577 main,
581 isolate_data, 578 isolate_data,
582 error, 579 error,
583 &is_compile_error); 580 &is_compile_error);
584 } 581 }
585 582
586 583
584 static Dart_Isolate CreateServiceIsolate(void* data, char** error) {
585 const char* script_uri = DartUtils::kVMServiceLibURL;
586 // These two variables are used by the CHECK_RESULT macro.
587 bool is_compile_error_ = false;
588 bool *is_compile_error = &is_compile_error_;
siva 2014/01/14 18:19:00 Instead of these dummy variables define a version
Cutch 2014/01/14 19:53:26 Done.
589 IsolateData* isolate_data = new IsolateData(script_uri);
590 Dart_Isolate isolate =
591 Dart_CreateIsolate(script_uri, "main", snapshot_buffer, isolate_data,
592 error);
593 if (isolate == NULL) {
594 return NULL;
595 }
596 Dart_EnterScope();
597 if (snapshot_buffer != NULL) {
598 // Setup the native resolver as the snapshot does not carry it.
599 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
600 Builtin::SetNativeResolver(Builtin::kIOLibrary);
601 }
602 // Set up the library tag handler for this isolate.
603 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler);
604 CHECK_RESULT(result);
605 result = Dart_SetEnvironmentCallback(EnvironmentCallback);
606 CHECK_RESULT(result);
607 // Prepare builtin and its dependent libraries for use to resolve URIs.
608 Dart_Handle builtin_lib =
609 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
610 CHECK_RESULT(builtin_lib);
611 // Prepare for script loading by setting up the 'print' and 'timer'
612 // closures and setting up 'package root' for URI resolution.
613 result = DartUtils::PrepareForScriptLoading(package_root, builtin_lib);
614 CHECK_RESULT(result);
615 Platform::SetPackageRoot(package_root);
616 Dart_Handle io_lib_url = DartUtils::NewString(DartUtils::kIOLibURL);
617 CHECK_RESULT(io_lib_url);
618 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url);
619 CHECK_RESULT(io_lib);
620 Dart_Handle platform_type = DartUtils::GetDartType(DartUtils::kIOLibURL,
621 "Platform");
622 CHECK_RESULT(platform_type);
623 Dart_Handle script_name = DartUtils::NewString("_nativeScript");
624 CHECK_RESULT(script_name);
625 Dart_Handle dart_script = DartUtils::NewString(script_uri);
626 CHECK_RESULT(dart_script);
627 Dart_Handle set_script_name =
628 Dart_SetField(platform_type, script_name, dart_script);
629 CHECK_RESULT(set_script_name);
630 Dart_ExitScope();
631 Dart_ExitIsolate();
632 return isolate;
633 }
siva 2014/01/14 18:19:00 Another point, this function above looks identical
634
635
587 static void PrintVersion() { 636 static void PrintVersion() {
588 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); 637 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString());
589 } 638 }
590 639
591 640
592 static void PrintUsage() { 641 static void PrintUsage() {
593 Log::PrintErr( 642 Log::PrintErr(
594 "Usage: dart [<vm-flags>] <dart-script-file> [<dart-options>]\n" 643 "Usage: dart [<vm-flags>] <dart-script-file> [<dart-options>]\n"
595 "\n" 644 "\n"
596 "Executes the Dart script passed as <dart-script-file>.\n" 645 "Executes the Dart script passed as <dart-script-file>.\n"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 if (!Dart_IsError(error)) { 758 if (!Dart_IsError(error)) {
710 return; 759 return;
711 } 760 }
712 const int exit_code = Dart_IsCompilationError(error) ? 761 const int exit_code = Dart_IsCompilationError(error) ?
713 kCompilationErrorExitCode : kErrorExitCode; 762 kCompilationErrorExitCode : kErrorExitCode;
714 ErrorExit(exit_code, "%s\n", Dart_GetError(error)); 763 ErrorExit(exit_code, "%s\n", Dart_GetError(error));
715 } 764 }
716 765
717 766
718 static void ShutdownIsolate(void* callback_data) { 767 static void ShutdownIsolate(void* callback_data) {
719 VmService::VmServiceShutdownCallback(callback_data);
720 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); 768 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data);
721 delete isolate_data; 769 delete isolate_data;
722 } 770 }
723 771
724 772
725 static Dart_Handle GenerateScriptSource() { 773 static Dart_Handle GenerateScriptSource() {
726 Dart_Handle library_url = Dart_LibraryUrl(Dart_RootLibrary()); 774 Dart_Handle library_url = Dart_LibraryUrl(Dart_RootLibrary());
727 if (Dart_IsError(library_url)) { 775 if (Dart_IsError(library_url)) {
728 return library_url; 776 return library_url;
729 } 777 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 } 853 }
806 854
807 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 855 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
808 856
809 // Initialize the Dart VM. 857 // Initialize the Dart VM.
810 if (!Dart_Initialize(CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, 858 if (!Dart_Initialize(CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate,
811 DartUtils::OpenFile, 859 DartUtils::OpenFile,
812 DartUtils::ReadFile, 860 DartUtils::ReadFile,
813 DartUtils::WriteFile, 861 DartUtils::WriteFile,
814 DartUtils::CloseFile, 862 DartUtils::CloseFile,
815 DartUtils::EntropySource)) { 863 DartUtils::EntropySource,
864 CreateServiceIsolate)) {
siva 2014/01/14 18:19:00 Another option for the next round of refactoring i
Cutch 2014/01/14 19:53:26 Agreed, the next round of refactoring can clean th
816 fprintf(stderr, "%s", "VM initialization failed\n"); 865 fprintf(stderr, "%s", "VM initialization failed\n");
817 fflush(stderr); 866 fflush(stderr);
818 exit(kErrorExitCode); 867 exit(kErrorExitCode);
819 } 868 }
820 869
821 // Start the debugger wire protocol handler if necessary. 870 // Start the debugger wire protocol handler if necessary.
822 if (start_debugger) { 871 if (start_debugger) {
823 ASSERT(debug_port >= 0); 872 ASSERT(debug_port >= 0);
824 bool print_msg = verbose_debug_seen || (debug_port == 0); 873 bool print_msg = verbose_debug_seen || (debug_port == 0);
825 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); 874 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 exit(Process::GlobalExitCode()); 1034 exit(Process::GlobalExitCode());
986 } 1035 }
987 1036
988 } // namespace bin 1037 } // namespace bin
989 } // namespace dart 1038 } // namespace dart
990 1039
991 int main(int argc, char** argv) { 1040 int main(int argc, char** argv) {
992 dart::bin::main(argc, argv); 1041 dart::bin::main(argc, argv);
993 UNREACHABLE(); 1042 UNREACHABLE();
994 } 1043 }
OLDNEW
« no previous file with comments | « runtime/bin/gen_snapshot.cc ('k') | runtime/bin/resources.h » ('j') | runtime/vm/service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698