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