OLD | NEW |
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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 | 6 |
7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 | 512 |
513 // --- Isolates --- | 513 // --- Isolates --- |
514 | 514 |
515 | 515 |
516 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* name_prefix, | 516 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* name_prefix, |
517 const uint8_t* snapshot, | 517 const uint8_t* snapshot, |
518 void* callback_data, | 518 void* callback_data, |
519 char** error) { | 519 char** error) { |
520 Isolate* isolate = Dart::CreateIsolate(name_prefix); | 520 Isolate* isolate = Dart::CreateIsolate(name_prefix); |
521 assert(isolate != NULL); | 521 assert(isolate != NULL); |
522 DARTSCOPE_NOCHECKS(isolate); | 522 { |
523 const Error& error_obj = | 523 DARTSCOPE_NOCHECKS(isolate); |
524 Error::Handle(Dart::InitializeIsolate(snapshot, callback_data)); | 524 const Error& error_obj = |
525 if (error_obj.IsNull()) { | 525 Error::Handle(Dart::InitializeIsolate(snapshot, callback_data)); |
526 START_TIMER(time_total_runtime); | 526 if (error_obj.IsNull()) { |
527 return reinterpret_cast<Dart_Isolate>(isolate); | 527 START_TIMER(time_total_runtime); |
528 } else { | 528 return reinterpret_cast<Dart_Isolate>(isolate); |
529 *error = strdup(error_obj.ToErrorCString()); | 529 } else { |
530 Dart::ShutdownIsolate(); | 530 *error = strdup(error_obj.ToErrorCString()); |
531 return reinterpret_cast<Dart_Isolate>(NULL); | 531 } |
| 532 // We need to leave the DARTSCOPE before shutting down the isolate. |
532 } | 533 } |
| 534 Dart::ShutdownIsolate(); |
| 535 return reinterpret_cast<Dart_Isolate>(NULL); |
533 } | 536 } |
534 | 537 |
535 | 538 |
536 DART_EXPORT void Dart_ShutdownIsolate() { | 539 DART_EXPORT void Dart_ShutdownIsolate() { |
537 CHECK_ISOLATE(Isolate::Current()); | 540 CHECK_ISOLATE(Isolate::Current()); |
538 STOP_TIMER(time_total_runtime); | 541 STOP_TIMER(time_total_runtime); |
539 Dart::ShutdownIsolate(); | 542 Dart::ShutdownIsolate(); |
540 } | 543 } |
541 | 544 |
542 | 545 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 } | 673 } |
671 | 674 |
672 | 675 |
673 DART_EXPORT Dart_Handle Dart_HandleMessage() { | 676 DART_EXPORT Dart_Handle Dart_HandleMessage() { |
674 Isolate* isolate = Isolate::Current(); | 677 Isolate* isolate = Isolate::Current(); |
675 // Process all OOB messages and at most one normal message. | 678 // Process all OOB messages and at most one normal message. |
676 Message* message = NULL; | 679 Message* message = NULL; |
677 Message::Priority priority = Message::kNormalPriority; | 680 Message::Priority priority = Message::kNormalPriority; |
678 do { | 681 do { |
679 DARTSCOPE(isolate); | 682 DARTSCOPE(isolate); |
| 683 // TODO(turnidge): This code is duplicated elsewhere. Consolidate. |
680 message = isolate->message_handler()->queue()->DequeueNoWait(); | 684 message = isolate->message_handler()->queue()->DequeueNoWait(); |
681 if (message == NULL) { | 685 if (message == NULL) { |
682 break; | 686 break; |
683 } | 687 } |
| 688 const Instance& msg = |
| 689 Instance::Handle(DeserializeMessage(message->data())); |
684 priority = message->priority(); | 690 priority = message->priority(); |
685 if (priority == Message::kOOBPriority) { | 691 if (priority == Message::kOOBPriority) { |
686 // TODO(turnidge): Out of band messages will not go through the | 692 // For now the only OOB messages are Mirrors messages. |
687 // regular message handler. Instead they will be dispatched to | 693 const Object& result = Object::Handle( |
688 // special vm code. Implement. | 694 DartLibraryCalls::HandleMirrorsMessage( |
689 UNIMPLEMENTED(); | 695 message->dest_port(), message->reply_port(), msg)); |
| 696 delete message; |
| 697 if (result.IsError()) { |
| 698 // TODO(turnidge): Propagating the error is probably wrong here. |
| 699 return Api::NewLocalHandle(result); |
| 700 } |
| 701 ASSERT(result.IsNull()); |
| 702 } else { |
| 703 const Object& result = Object::Handle( |
| 704 DartLibraryCalls::HandleMessage( |
| 705 message->dest_port(), message->reply_port(), msg)); |
| 706 delete message; |
| 707 if (result.IsError()) { |
| 708 return Api::NewLocalHandle(result); |
| 709 } |
| 710 ASSERT(result.IsNull()); |
690 } | 711 } |
691 const Instance& msg = | |
692 Instance::Handle(DeserializeMessage(message->data())); | |
693 const Object& result = Object::Handle( | |
694 DartLibraryCalls::HandleMessage( | |
695 message->dest_port(), message->reply_port(), msg)); | |
696 delete message; | |
697 if (result.IsError()) { | |
698 return Api::NewLocalHandle(result); | |
699 } | |
700 ASSERT(result.IsNull()); | |
701 } while (priority >= Message::kOOBPriority); | 712 } while (priority >= Message::kOOBPriority); |
702 return Api::Success(); | 713 return Api::Success(); |
703 } | 714 } |
704 | 715 |
705 | 716 |
706 DART_EXPORT bool Dart_HasLivePorts() { | 717 DART_EXPORT bool Dart_HasLivePorts() { |
707 Isolate* isolate = Isolate::Current(); | 718 Isolate* isolate = Isolate::Current(); |
708 ASSERT(isolate); | 719 ASSERT(isolate); |
709 return isolate->message_handler()->HasLivePorts(); | 720 return isolate->message_handler()->HasLivePorts(); |
710 } | 721 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 Isolate::SetCurrent(NULL); | 794 Isolate::SetCurrent(NULL); |
784 | 795 |
785 // TODO(turnidge): Check that the port is native before trying to close. | 796 // TODO(turnidge): Check that the port is native before trying to close. |
786 return PortMap::ClosePort(native_port_id); | 797 return PortMap::ClosePort(native_port_id); |
787 } | 798 } |
788 | 799 |
789 | 800 |
790 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { | 801 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { |
791 Isolate* isolate = Isolate::Current(); | 802 Isolate* isolate = Isolate::Current(); |
792 DARTSCOPE(isolate); | 803 DARTSCOPE(isolate); |
793 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); | 804 const Object& result = Object::Handle(DartLibraryCalls::NewSendPort(port_id)); |
794 ASSERT(!isolate_lib.IsNull()); | |
795 const String& class_name = | |
796 String::Handle(isolate_lib.PrivateName("_SendPortImpl")); | |
797 const String& function_name = String::Handle(String::NewSymbol("_create")); | |
798 const int kNumArguments = 1; | |
799 const Array& kNoArgumentNames = Array::Handle(); | |
800 // TODO(turnidge): Consider adding a helper function to make | |
801 // function resolution by class name and function name more concise. | |
802 const Function& function = Function::Handle( | |
803 Resolver::ResolveStatic(isolate_lib, | |
804 class_name, | |
805 function_name, | |
806 kNumArguments, | |
807 kNoArgumentNames, | |
808 Resolver::kIsQualified)); | |
809 GrowableArray<const Object*> arguments(kNumArguments); | |
810 arguments.Add(&Integer::Handle(Integer::New(port_id))); | |
811 const Object& result = Object::Handle( | |
812 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); | |
813 return Api::NewLocalHandle(result); | 805 return Api::NewLocalHandle(result); |
814 } | 806 } |
815 | 807 |
816 | 808 |
817 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { | 809 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { |
818 Isolate* isolate = Isolate::Current(); | 810 Isolate* isolate = Isolate::Current(); |
819 DARTSCOPE(isolate); | 811 DARTSCOPE(isolate); |
820 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); | 812 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); |
821 ASSERT(!isolate_lib.IsNull()); | 813 ASSERT(!isolate_lib.IsNull()); |
822 const String& class_name = | 814 const String& class_name = |
(...skipping 1927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2750 *buffer = NULL; | 2742 *buffer = NULL; |
2751 } | 2743 } |
2752 delete debug_region; | 2744 delete debug_region; |
2753 } else { | 2745 } else { |
2754 *buffer = NULL; | 2746 *buffer = NULL; |
2755 *buffer_size = 0; | 2747 *buffer_size = 0; |
2756 } | 2748 } |
2757 } | 2749 } |
2758 | 2750 |
2759 } // namespace dart | 2751 } // namespace dart |
OLD | NEW |