| OLD | NEW |
| 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" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 Dart_ListSetAt(request, 4, url); | 199 Dart_ListSetAt(request, 4, url); |
| 200 Dart_ListSetAt(request, 5, library_url); | 200 Dart_ListSetAt(request, 5, library_url); |
| 201 | 201 |
| 202 if (Dart_Post(loader_port, request)) { | 202 if (Dart_Post(loader_port, request)) { |
| 203 MonitorLocker ml(monitor_); | 203 MonitorLocker ml(monitor_); |
| 204 pending_operations_++; | 204 pending_operations_++; |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 | 208 |
| 209 // Forward a request from the tag handler to the kernel isolate. | |
| 210 // [ tag, send port, url ] | |
| 211 void Loader::SendKernelRequest(Dart_LibraryTag tag, Dart_Handle url) { | |
| 212 // This port delivers loading messages to the Kernel isolate. | |
| 213 Dart_Port kernel_port = Dart_KernelPort(); | |
| 214 ASSERT(kernel_port != ILLEGAL_PORT); | |
| 215 | |
| 216 Dart_Handle request = Dart_NewList(3); | |
| 217 Dart_ListSetAt(request, 0, Dart_NewInteger(tag)); | |
| 218 Dart_ListSetAt(request, 1, Dart_NewSendPort(port_)); | |
| 219 Dart_ListSetAt(request, 2, url); | |
| 220 if (Dart_Post(kernel_port, request)) { | |
| 221 MonitorLocker ml(monitor_); | |
| 222 pending_operations_++; | |
| 223 } | |
| 224 } | |
| 225 | |
| 226 | |
| 227 void Loader::QueueMessage(Dart_CObject* message) { | 209 void Loader::QueueMessage(Dart_CObject* message) { |
| 228 MonitorLocker ml(monitor_); | 210 MonitorLocker ml(monitor_); |
| 229 if (results_length_ == results_capacity_) { | 211 if (results_length_ == results_capacity_) { |
| 230 // Grow to an initial capacity or double in size. | 212 // Grow to an initial capacity or double in size. |
| 231 results_capacity_ = (results_capacity_ == 0) ? 4 : results_capacity_ * 2; | 213 results_capacity_ = (results_capacity_ == 0) ? 4 : results_capacity_ * 2; |
| 232 results_ = reinterpret_cast<IOResult*>( | 214 results_ = reinterpret_cast<IOResult*>( |
| 233 realloc(results_, sizeof(IOResult) * results_capacity_)); | 215 realloc(results_, sizeof(IOResult) * results_capacity_)); |
| 234 ASSERT(results_ != NULL); | 216 ASSERT(results_ != NULL); |
| 235 } | 217 } |
| 236 ASSERT(results_ != NULL); | 218 ASSERT(results_ != NULL); |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 // work with the service isolate. | 618 // work with the service isolate. |
| 637 // Use the existing loader. | 619 // Use the existing loader. |
| 638 loader = isolate_data->loader(); | 620 loader = isolate_data->loader(); |
| 639 } | 621 } |
| 640 ASSERT(loader != NULL); | 622 ASSERT(loader != NULL); |
| 641 ASSERT(isolate_data->HasLoader()); | 623 ASSERT(isolate_data->HasLoader()); |
| 642 | 624 |
| 643 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { | 625 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { |
| 644 loader->SendImportExtensionRequest(url, Dart_LibraryUrl(library)); | 626 loader->SendImportExtensionRequest(url, Dart_LibraryUrl(library)); |
| 645 } else { | 627 } else { |
| 646 if (Dart_KernelIsolateIsRunning()) { | 628 loader->SendRequest(tag, url, (library != Dart_Null()) |
| 647 loader->SendKernelRequest(tag, url); | 629 ? Dart_LibraryUrl(library) |
| 648 } else { | 630 : Dart_Null()); |
| 649 loader->SendRequest(tag, url, (library != Dart_Null()) | |
| 650 ? Dart_LibraryUrl(library) | |
| 651 : Dart_Null()); | |
| 652 } | |
| 653 } | 631 } |
| 654 | 632 |
| 633 |
| 655 if (blocking_call) { | 634 if (blocking_call) { |
| 656 // The outer invocation of the tag handler will block here until all nested | 635 // The outer invocation of the tag handler will block here until all nested |
| 657 // invocations complete. | 636 // invocations complete. |
| 658 loader->BlockUntilComplete(ProcessResultLocked); | 637 loader->BlockUntilComplete(ProcessResultLocked); |
| 659 | 638 |
| 660 // Remember the error (if any). | 639 // Remember the error (if any). |
| 661 Dart_Handle error = loader->error(); | 640 Dart_Handle error = loader->error(); |
| 662 // Destroy the loader. The destructor does a bunch of leg work. | 641 // Destroy the loader. The destructor does a bunch of leg work. |
| 663 delete loader; | 642 delete loader; |
| 664 | 643 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 MutexLocker ml(loader_infos_lock_); | 800 MutexLocker ml(loader_infos_lock_); |
| 822 Loader* loader = LoaderForLocked(dest_port_id); | 801 Loader* loader = LoaderForLocked(dest_port_id); |
| 823 if (loader == NULL) { | 802 if (loader == NULL) { |
| 824 return; | 803 return; |
| 825 } | 804 } |
| 826 loader->QueueMessage(message); | 805 loader->QueueMessage(message); |
| 827 } | 806 } |
| 828 | 807 |
| 829 } // namespace bin | 808 } // namespace bin |
| 830 } // namespace dart | 809 } // namespace dart |
| OLD | NEW |