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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
680 message = isolate->message_handler()->queue()->DequeueNoWait(); | 683 message = isolate->message_handler()->queue()->DequeueNoWait(); |
681 if (message == NULL) { | 684 if (message == NULL) { |
682 break; | 685 break; |
683 } | 686 } |
| 687 const Instance& msg = |
| 688 Instance::Handle(DeserializeMessage(message->data())); |
684 priority = message->priority(); | 689 priority = message->priority(); |
685 if (priority == Message::kOOBPriority) { | 690 if (priority == Message::kOOBPriority) { |
686 // TODO(turnidge): Out of band messages will not go through the | 691 // For now the only OOB messages are Mirrors messages. |
687 // regular message handler. Instead they will be dispatched to | 692 const Object& result = Object::Handle( |
688 // special vm code. Implement. | 693 DartLibraryCalls::HandleMirrorsMessage( |
689 UNIMPLEMENTED(); | 694 message->dest_port(), message->reply_port(), msg)); |
| 695 delete message; |
| 696 if (result.IsError()) { |
| 697 // TODO(turnidge): Propagating the error is probably wrong here. |
| 698 return Api::NewLocalHandle(result); |
| 699 } |
| 700 ASSERT(result.IsNull()); |
| 701 } else { |
| 702 const Object& result = Object::Handle( |
| 703 DartLibraryCalls::HandleMessage( |
| 704 message->dest_port(), message->reply_port(), msg)); |
| 705 delete message; |
| 706 if (result.IsError()) { |
| 707 return Api::NewLocalHandle(result); |
| 708 } |
| 709 ASSERT(result.IsNull()); |
690 } | 710 } |
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); | 711 } while (priority >= Message::kOOBPriority); |
702 return Api::Success(); | 712 return Api::Success(); |
703 } | 713 } |
704 | 714 |
705 | 715 |
706 DART_EXPORT bool Dart_HasLivePorts() { | 716 DART_EXPORT bool Dart_HasLivePorts() { |
707 Isolate* isolate = Isolate::Current(); | 717 Isolate* isolate = Isolate::Current(); |
708 ASSERT(isolate); | 718 ASSERT(isolate); |
709 return isolate->message_handler()->HasLivePorts(); | 719 return isolate->message_handler()->HasLivePorts(); |
710 } | 720 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 Isolate::SetCurrent(NULL); | 793 Isolate::SetCurrent(NULL); |
784 | 794 |
785 // TODO(turnidge): Check that the port is native before trying to close. | 795 // TODO(turnidge): Check that the port is native before trying to close. |
786 return PortMap::ClosePort(native_port_id); | 796 return PortMap::ClosePort(native_port_id); |
787 } | 797 } |
788 | 798 |
789 | 799 |
790 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { | 800 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { |
791 Isolate* isolate = Isolate::Current(); | 801 Isolate* isolate = Isolate::Current(); |
792 DARTSCOPE(isolate); | 802 DARTSCOPE(isolate); |
793 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); | 803 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); | 804 return Api::NewLocalHandle(result); |
814 } | 805 } |
815 | 806 |
816 | 807 |
817 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { | 808 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { |
818 Isolate* isolate = Isolate::Current(); | 809 Isolate* isolate = Isolate::Current(); |
819 DARTSCOPE(isolate); | 810 DARTSCOPE(isolate); |
820 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); | 811 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); |
821 ASSERT(!isolate_lib.IsNull()); | 812 ASSERT(!isolate_lib.IsNull()); |
822 const String& class_name = | 813 const String& class_name = |
(...skipping 1927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2750 *buffer = NULL; | 2741 *buffer = NULL; |
2751 } | 2742 } |
2752 delete debug_region; | 2743 delete debug_region; |
2753 } else { | 2744 } else { |
2754 *buffer = NULL; | 2745 *buffer = NULL; |
2755 *buffer_size = 0; | 2746 *buffer_size = 0; |
2756 } | 2747 } |
2757 } | 2748 } |
2758 | 2749 |
2759 } // namespace dart | 2750 } // namespace dart |
OLD | NEW |