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

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

Issue 2715463003: Add option to gen_snapshot for creating a Makefile describing a snapshot's dependencies. (Closed)
Patch Set: . Created 3 years, 9 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/loader.h ('k') | runtime/bin/vmservice/loader.dart » ('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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 5
6 #include "bin/loader.h" 6 #include "bin/loader.h"
7 7
8 #include "bin/builtin.h" 8 #include "bin/builtin.h"
9 #include "bin/dartutils.h" 9 #include "bin/dartutils.h"
10 #include "bin/extensions.h" 10 #include "bin/extensions.h"
11 #include "bin/file.h" 11 #include "bin/file.h"
12 #include "bin/lockers.h" 12 #include "bin/lockers.h"
13 #include "bin/utils.h" 13 #include "bin/utils.h"
14 #include "include/dart_tools_api.h" 14 #include "include/dart_tools_api.h"
15 15
16 namespace dart { 16 namespace dart {
17 namespace bin { 17 namespace bin {
18 18
19 // Development flag. 19 // Development flag.
20 static bool trace_loader = false; 20 static bool trace_loader = false;
21 // Keep in sync with loader.dart. 21 // Keep in sync with loader.dart.
22 static const intptr_t _Dart_kImportExtension = 9; 22 static const intptr_t _Dart_kImportExtension = 9;
23 static const intptr_t _Dart_kResolveAsFilePath = 10;
23 24
24 Loader::Loader(IsolateData* isolate_data) 25 Loader::Loader(IsolateData* isolate_data)
25 : port_(ILLEGAL_PORT), 26 : port_(ILLEGAL_PORT),
26 isolate_data_(isolate_data), 27 isolate_data_(isolate_data),
27 error_(Dart_Null()), 28 error_(Dart_Null()),
28 monitor_(NULL), 29 monitor_(NULL),
29 pending_operations_(0), 30 pending_operations_(0),
30 results_(NULL), 31 results_(NULL),
31 results_length_(0), 32 results_length_(0),
32 results_capacity_(0), 33 results_capacity_(0),
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 Dart_ListSetAt(request, 5, library_url); 177 Dart_ListSetAt(request, 5, library_url);
177 178
178 if (Dart_Post(loader_port, request)) { 179 if (Dart_Post(loader_port, request)) {
179 MonitorLocker ml(monitor_); 180 MonitorLocker ml(monitor_);
180 pending_operations_++; 181 pending_operations_++;
181 } 182 }
182 } 183 }
183 184
184 185
185 // Forward a request from the tag handler to the service isolate. 186 // Forward a request from the tag handler to the service isolate.
186 void Loader::SendRequest(Dart_LibraryTag tag, 187 void Loader::SendRequest(intptr_t tag,
187 Dart_Handle url, 188 Dart_Handle url,
188 Dart_Handle library_url) { 189 Dart_Handle library_url) {
189 // This port delivers loading messages to the service isolate. 190 // This port delivers loading messages to the service isolate.
190 Dart_Port loader_port = Builtin::LoadPort(); 191 Dart_Port loader_port = Builtin::LoadPort();
191 ASSERT(loader_port != ILLEGAL_PORT); 192 ASSERT(loader_port != ILLEGAL_PORT);
192 193
193 Dart_Handle request = Dart_NewList(6); 194 Dart_Handle request = Dart_NewList(6);
194 Dart_ListSetAt(request, 0, trace_loader ? Dart_True() : Dart_False()); 195 Dart_ListSetAt(request, 0, trace_loader ? Dart_True() : Dart_False());
195 Dart_ListSetAt(request, 1, Dart_NewInteger(Dart_GetMainPortId())); 196 Dart_ListSetAt(request, 1, Dart_NewInteger(Dart_GetMainPortId()));
196 Dart_ListSetAt(request, 2, Dart_NewInteger(tag)); 197 Dart_ListSetAt(request, 2, Dart_NewInteger(tag));
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 // Remember the error if we encountered one. 418 // Remember the error if we encountered one.
418 loader->error_ = dart_result; 419 loader->error_ = dart_result;
419 return false; 420 return false;
420 } 421 }
421 } 422 }
422 423
423 return true; 424 return true;
424 } 425 }
425 426
426 427
427 bool Loader::ProcessUrlLoadResultLocked(Loader* loader, 428 bool Loader::ProcessPayloadResultLocked(Loader* loader,
428 Loader::IOResult* result) { 429 Loader::IOResult* result) {
429 // A negative result tag indicates a loading error occurred in the service 430 // A negative result tag indicates a loading error occurred in the service
430 // isolate. The payload is a C string of the error message. 431 // isolate. The payload is a C string of the error message.
431 if (result->tag < 0) { 432 if (result->tag < 0) {
432 Dart_Handle error = 433 Dart_Handle error =
433 Dart_NewStringFromUTF8(result->payload, result->payload_length); 434 Dart_NewStringFromUTF8(result->payload, result->payload_length);
434 loader->error_ = Dart_NewUnhandledExceptionError(error); 435 loader->error_ = Dart_NewUnhandledExceptionError(error);
435 return false; 436 return false;
436 } 437 }
437 loader->payload_length_ = result->payload_length; 438 loader->payload_length_ = result->payload_length;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 511
511 result = Extensions::LoadExtension(lib_path, extension_path, importer); 512 result = Extensions::LoadExtension(lib_path, extension_path, importer);
512 free(lib_path); 513 free(lib_path);
513 RETURN_ERROR(result); 514 RETURN_ERROR(result);
514 } 515 }
515 516
516 return Dart_True(); 517 return Dart_True();
517 } 518 }
518 519
519 520
520 Dart_Handle Loader::LoadUrlContents(Dart_Handle url, 521 Dart_Handle Loader::SendAndProcessReply(intptr_t tag,
521 uint8_t** payload, 522 Dart_Handle url,
522 intptr_t* payload_length) { 523 uint8_t** payload,
524 intptr_t* payload_length) {
523 IsolateData* isolate_data = 525 IsolateData* isolate_data =
524 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); 526 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData());
525 ASSERT(isolate_data != NULL); 527 ASSERT(isolate_data != NULL);
526 ASSERT(!isolate_data->HasLoader()); 528 ASSERT(!isolate_data->HasLoader());
527 Loader* loader = NULL; 529 Loader* loader = NULL;
528 530
529 // Setup the loader. The constructor does a bunch of leg work. 531 // Setup the loader. The constructor does a bunch of leg work.
530 loader = new Loader(isolate_data); 532 loader = new Loader(isolate_data);
531 loader->Init(isolate_data->package_root, isolate_data->packages_file, 533 loader->Init(isolate_data->package_root, isolate_data->packages_file,
532 DartUtils::original_working_directory, NULL); 534 DartUtils::original_working_directory, NULL);
533 ASSERT(loader != NULL); 535 ASSERT(loader != NULL);
534 ASSERT(isolate_data->HasLoader()); 536 ASSERT(isolate_data->HasLoader());
535 537
536 // Now send a load request to the service isolate. 538 // Now send a load request to the service isolate.
537 loader->SendRequest(Dart_kScriptTag, url, Dart_Null()); 539 loader->SendRequest(tag, url, Dart_Null());
538 540
539 // Wait for a reply to the load request. 541 // Wait for a reply to the load request.
540 loader->BlockUntilComplete(ProcessUrlLoadResultLocked); 542 loader->BlockUntilComplete(ProcessPayloadResultLocked);
541 543
542 // Copy fields from the loader before deleting it. 544 // Copy fields from the loader before deleting it.
543 // The payload array itself which was malloced above is freed by 545 // The payload array itself which was malloced above is freed by
544 // the caller of LoadUrlContents. 546 // the caller of LoadUrlContents.
545 Dart_Handle error = loader->error(); 547 Dart_Handle error = loader->error();
546 *payload = loader->payload_; 548 *payload = loader->payload_;
547 *payload_length = loader->payload_length_; 549 *payload_length = loader->payload_length_;
548 550
549 // Destroy the loader. The destructor does a bunch of leg work. 551 // Destroy the loader. The destructor does a bunch of leg work.
550 delete loader; 552 delete loader;
551 553
552 // An error occurred during loading. 554 // An error occurred during loading.
553 if (!Dart_IsNull(error)) { 555 if (!Dart_IsNull(error)) {
554 return error; 556 return error;
555 } 557 }
556 return Dart_Null(); 558 return Dart_Null();
557 } 559 }
558 560
559 561
562 Dart_Handle Loader::LoadUrlContents(Dart_Handle url,
563 uint8_t** payload,
564 intptr_t* payload_length) {
565 return SendAndProcessReply(Dart_kScriptTag, url, payload, payload_length);
566 }
567
568
569 Dart_Handle Loader::ResolveAsFilePath(Dart_Handle url,
570 uint8_t** payload,
571 intptr_t* payload_length) {
572 return SendAndProcessReply(_Dart_kResolveAsFilePath, url, payload,
573 payload_length);
574 }
575
576
560 Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag, 577 Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag,
561 Dart_Handle library, 578 Dart_Handle library,
562 Dart_Handle url) { 579 Dart_Handle url) {
563 if (tag == Dart_kCanonicalizeUrl) { 580 if (tag == Dart_kCanonicalizeUrl) {
564 Dart_Handle library_url = Dart_LibraryUrl(library); 581 Dart_Handle library_url = Dart_LibraryUrl(library);
565 if (Dart_IsError(library_url)) { 582 if (Dart_IsError(library_url)) {
566 return library_url; 583 return library_url;
567 } 584 }
568 return Dart_DefaultCanonicalizeUrl(library_url, url); 585 return Dart_DefaultCanonicalizeUrl(library_url, url);
569 } 586 }
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 MutexLocker ml(loader_infos_lock_); 838 MutexLocker ml(loader_infos_lock_);
822 Loader* loader = LoaderForLocked(dest_port_id); 839 Loader* loader = LoaderForLocked(dest_port_id);
823 if (loader == NULL) { 840 if (loader == NULL) {
824 return; 841 return;
825 } 842 }
826 loader->QueueMessage(message); 843 loader->QueueMessage(message);
827 } 844 }
828 845
829 } // namespace bin 846 } // namespace bin
830 } // namespace dart 847 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/loader.h ('k') | runtime/bin/vmservice/loader.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698