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

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

Issue 1405183002: Bring up the service isolate and use it for package resolution in gen_snapshot (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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/dartutils.cc ('k') | no next file » | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // Generate a snapshot file after loading all the scripts specified on the 5 // Generate a snapshot file after loading all the scripts specified on the
6 // command line. 6 // command line.
7 7
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 #include <stdio.h> 10 #include <stdio.h>
11 11
12 #include "include/dart_api.h" 12 #include "include/dart_api.h"
13 13
14 #include "bin/builtin.h" 14 #include "bin/builtin.h"
15 #include "bin/dartutils.h" 15 #include "bin/dartutils.h"
16 #include "bin/eventhandler.h"
16 #include "bin/file.h" 17 #include "bin/file.h"
17 #include "bin/log.h" 18 #include "bin/log.h"
18 #include "bin/thread.h" 19 #include "bin/thread.h"
20 #include "bin/vmservice_impl.h"
19 21
20 #include "platform/globals.h" 22 #include "platform/globals.h"
21 23
22 24
23 namespace dart { 25 namespace dart {
24 namespace bin { 26 namespace bin {
25 27
26 #define CHECK_RESULT(result) \ 28 #define CHECK_RESULT(result) \
27 if (Dart_IsError(result)) { \ 29 if (Dart_IsError(result)) { \
28 Log::PrintErr("Error: %s", Dart_GetError(result)); \ 30 Log::PrintErr("Error: %s", Dart_GetError(result)); \
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 if (Dart_IsError(result)) { 510 if (Dart_IsError(result)) {
509 const char* err_msg = Dart_GetError(library); 511 const char* err_msg = Dart_GetError(library);
510 Log::PrintErr("Errors encountered while loading: %s\n", err_msg); 512 Log::PrintErr("Errors encountered while loading: %s\n", err_msg);
511 Dart_ExitScope(); 513 Dart_ExitScope();
512 Dart_ShutdownIsolate(); 514 Dart_ShutdownIsolate();
513 exit(255); 515 exit(255);
514 } 516 }
515 } 517 }
516 518
517 519
520 static Dart_Isolate CreateServiceIsolate(const char* script_uri,
521 const char* main,
522 const char* package_root,
523 const char** package_map,
524 Dart_IsolateFlags* flags,
525 void* data,
526 char** error) {
527 Dart_Isolate isolate = NULL;
528 isolate = Dart_CreateIsolate(script_uri,
529 main,
530 NULL,
531 NULL,
532 NULL,
533 error);
534
535 if (isolate == NULL) {
536 Log::PrintErr("Error: Could not create service isolate");
537 return NULL;
538 }
539
540 Dart_EnterScope();
541 if (!Dart_IsServiceIsolate(isolate)) {
542 Log::PrintErr("Error: We only expect to create the service isolate");
543 return NULL;
544 }
545 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler);
546 // Setup the native resolver.
547 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
548 Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary);
549 if (Dart_IsError(result)) {
550 Log::PrintErr("Error: Could not set tag handler for service isolate");
551 return NULL;
552 }
553 CHECK_RESULT(result);
554 ASSERT(Dart_IsServiceIsolate(isolate));
555 // Load embedder specific bits and return. Will not start http server.
556 if (!VmService::Setup("127.0.0.1", -1)) {
557 *error = strdup(VmService::GetErrorMessage());
558 return NULL;
559 }
560 Dart_ExitScope();
561 Dart_ExitIsolate();
562 return isolate;
563 }
564
565
518 int main(int argc, char** argv) { 566 int main(int argc, char** argv) {
519 const int EXTRA_VM_ARGUMENTS = 2; 567 const int EXTRA_VM_ARGUMENTS = 2;
520 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); 568 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS);
521 569
522 // Initialize the URL mapping array. 570 // Initialize the URL mapping array.
523 CommandLineOptions url_mapping_array(argc); 571 CommandLineOptions url_mapping_array(argc);
524 url_mapping = &url_mapping_array; 572 url_mapping = &url_mapping_array;
525 573
526 // Parse command line arguments. 574 // Parse command line arguments.
527 if (ParseArguments(argc, 575 if (ParseArguments(argc,
528 argv, 576 argv,
529 &vm_options, 577 &vm_options,
530 &app_script_name) < 0) { 578 &app_script_name) < 0) {
531 PrintUsage(); 579 PrintUsage();
532 return 255; 580 return 255;
533 } 581 }
534 582
535 Thread::InitOnce(); 583 Thread::InitOnce();
536 DartUtils::SetOriginalWorkingDirectory(); 584 DartUtils::SetOriginalWorkingDirectory();
585 // Start event handler.
586 EventHandler::Start();
537 587
538 vm_options.AddArgument("--load_deferred_eagerly"); 588 vm_options.AddArgument("--load_deferred_eagerly");
539 // Workaround until issue 21620 is fixed. 589 // Workaround until issue 21620 is fixed.
540 // (https://github.com/dart-lang/sdk/issues/21620) 590 // (https://github.com/dart-lang/sdk/issues/21620)
541 vm_options.AddArgument("--no-concurrent_sweep"); 591 vm_options.AddArgument("--no-concurrent_sweep");
542 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 592 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
543 593
544 // Initialize the Dart VM. 594 // Initialize the Dart VM.
545 // Note: We don't expect isolates to be created from dart code during 595 // Note: We don't expect isolates to be created from dart code during
546 // snapshot generation. 596 // snapshot generation.
547 char* error = Dart_Initialize(NULL, NULL, 597 char* error = Dart_Initialize(
548 NULL, NULL, NULL, NULL, 598 NULL,
599 NULL,
600 CreateServiceIsolate,
601 NULL,
602 NULL,
603 NULL,
549 DartUtils::OpenFile, 604 DartUtils::OpenFile,
550 DartUtils::ReadFile, 605 DartUtils::ReadFile,
551 DartUtils::WriteFile, 606 DartUtils::WriteFile,
552 DartUtils::CloseFile, 607 DartUtils::CloseFile,
553 DartUtils::EntropySource); 608 DartUtils::EntropySource);
554 if (error != NULL) { 609 if (error != NULL) {
555 Log::PrintErr("VM initialization failed: %s\n", error); 610 Log::PrintErr("VM initialization failed: %s\n", error);
556 free(error); 611 free(error);
557 return 255; 612 return 255;
558 } 613 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 result = Dart_FinalizeLoading(false); 679 result = Dart_FinalizeLoading(false);
625 CHECK_RESULT(result); 680 CHECK_RESULT(result);
626 CreateAndWriteSnapshot(); 681 CreateAndWriteSnapshot();
627 682
628 Dart_EnterIsolate(UriResolverIsolateScope::isolate); 683 Dart_EnterIsolate(UriResolverIsolateScope::isolate);
629 Dart_ShutdownIsolate(); 684 Dart_ShutdownIsolate();
630 } else { 685 } else {
631 SetupForGenericSnapshotCreation(); 686 SetupForGenericSnapshotCreation();
632 CreateAndWriteSnapshot(); 687 CreateAndWriteSnapshot();
633 } 688 }
689 EventHandler::Stop();
634 return 0; 690 return 0;
635 } 691 }
636 692
637 } // namespace bin 693 } // namespace bin
638 } // namespace dart 694 } // namespace dart
639 695
640 int main(int argc, char** argv) { 696 int main(int argc, char** argv) {
641 return dart::bin::main(argc, argv); 697 return dart::bin::main(argc, argv);
642 } 698 }
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698