OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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" |
11 #include "vm/dart_api_impl.h" | 11 #include "vm/dart_api_impl.h" |
12 #include "vm/dart_api_state.h" | 12 #include "vm/dart_api_state.h" |
13 #include "vm/dart_entry.h" | 13 #include "vm/dart_entry.h" |
14 #include "vm/debuginfo.h" | 14 #include "vm/debuginfo.h" |
15 #include "vm/exceptions.h" | 15 #include "vm/exceptions.h" |
16 #include "vm/growable_array.h" | 16 #include "vm/growable_array.h" |
17 #include "vm/longjump.h" | 17 #include "vm/longjump.h" |
18 #include "vm/message_queue.h" | |
18 #include "vm/native_entry.h" | 19 #include "vm/native_entry.h" |
19 #include "vm/object.h" | 20 #include "vm/object.h" |
20 #include "vm/object_store.h" | 21 #include "vm/object_store.h" |
21 #include "vm/port.h" | 22 #include "vm/port.h" |
22 #include "vm/resolver.h" | 23 #include "vm/resolver.h" |
23 #include "vm/snapshot.h" | 24 #include "vm/snapshot.h" |
24 #include "vm/stack_frame.h" | 25 #include "vm/stack_frame.h" |
25 #include "vm/timer.h" | 26 #include "vm/timer.h" |
26 #include "vm/verifier.h" | 27 #include "vm/verifier.h" |
27 | 28 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 ASSERT(state.IsValidPersistentHandle(object)); | 189 ASSERT(state.IsValidPersistentHandle(object)); |
189 return reinterpret_cast<PersistentHandle*>(object); | 190 return reinterpret_cast<PersistentHandle*>(object); |
190 } | 191 } |
191 | 192 |
192 | 193 |
193 Dart_Isolate Api::CastIsolate(Isolate* isolate) { | 194 Dart_Isolate Api::CastIsolate(Isolate* isolate) { |
194 return reinterpret_cast<Dart_Isolate>(isolate); | 195 return reinterpret_cast<Dart_Isolate>(isolate); |
195 } | 196 } |
196 | 197 |
197 | 198 |
198 Dart_Message Api::CastMessage(uint8_t* message) { | |
199 return reinterpret_cast<Dart_Message>(message); | |
200 } | |
201 | |
202 | |
203 Dart_Handle Api::Success() { | 199 Dart_Handle Api::Success() { |
204 Isolate* isolate = Isolate::Current(); | 200 Isolate* isolate = Isolate::Current(); |
205 ASSERT(isolate != NULL); | 201 ASSERT(isolate != NULL); |
206 ApiState* state = isolate->api_state(); | 202 ApiState* state = isolate->api_state(); |
207 ASSERT(state != NULL); | 203 ASSERT(state != NULL); |
208 PersistentHandle* true_handle = state->True(); | 204 PersistentHandle* true_handle = state->True(); |
209 return reinterpret_cast<Dart_Handle>(true_handle); | 205 return reinterpret_cast<Dart_Handle>(true_handle); |
210 } | 206 } |
211 | 207 |
212 | 208 |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
660 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 656 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
661 } | 657 } |
662 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 658 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
663 iso->ScheduleInterrupts(Isolate::kApiInterrupt); | 659 iso->ScheduleInterrupts(Isolate::kApiInterrupt); |
664 } | 660 } |
665 | 661 |
666 | 662 |
667 // --- Messages and Ports --- | 663 // --- Messages and Ports --- |
668 | 664 |
669 | 665 |
670 DART_EXPORT void Dart_SetMessageCallbacks( | 666 DART_EXPORT void Dart_SetMessageNotifyCallback( |
671 Dart_PostMessageCallback post_message_callback, | 667 Dart_MessageNotifyCallback message_notify_callback) { |
672 Dart_ClosePortCallback close_port_callback) { | |
673 Isolate* isolate = Isolate::Current(); | 668 Isolate* isolate = Isolate::Current(); |
674 CHECK_ISOLATE(isolate); | 669 CHECK_ISOLATE(isolate); |
675 ASSERT(post_message_callback != NULL); | 670 isolate->set_message_notify_callback(message_notify_callback); |
676 ASSERT(close_port_callback != NULL); | |
677 isolate->set_post_message_callback(post_message_callback); | |
678 isolate->set_close_port_callback(close_port_callback); | |
679 } | 671 } |
680 | 672 |
681 | 673 |
682 DART_EXPORT Dart_Handle Dart_RunLoop() { | 674 DART_EXPORT Dart_Handle Dart_RunLoop() { |
683 Isolate* isolate = Isolate::Current(); | 675 Isolate* isolate = Isolate::Current(); |
684 DARTSCOPE(isolate); | 676 DARTSCOPE(isolate); |
685 | 677 |
686 LongJump* base = isolate->long_jump_base(); | 678 LongJump* base = isolate->long_jump_base(); |
687 LongJump jump; | 679 LongJump jump; |
688 Dart_Handle result; | 680 Dart_Handle result; |
(...skipping 20 matching lines...) Expand all Loading... | |
709 ASSERT(snapshot->IsMessageSnapshot()); | 701 ASSERT(snapshot->IsMessageSnapshot()); |
710 | 702 |
711 // Read object back from the snapshot. | 703 // Read object back from the snapshot. |
712 SnapshotReader reader(snapshot, Isolate::Current()); | 704 SnapshotReader reader(snapshot, Isolate::Current()); |
713 Instance& instance = Instance::Handle(); | 705 Instance& instance = Instance::Handle(); |
714 instance ^= reader.ReadObject(); | 706 instance ^= reader.ReadObject(); |
715 return instance.raw(); | 707 return instance.raw(); |
716 } | 708 } |
717 | 709 |
718 | 710 |
719 DART_EXPORT Dart_Handle Dart_HandleMessage(Dart_Port dest_port_id, | 711 DART_EXPORT Dart_Handle Dart_HandleMessage() { |
720 Dart_Port reply_port_id, | 712 Isolate* isolate = Isolate::Current(); |
721 Dart_Message dart_message) { | 713 // Process all OOB messages and at most one normal message. |
722 DARTSCOPE(Isolate::Current()); | 714 Message* message = NULL; |
723 const Instance& msg = Instance::Handle(DeserializeMessage(dart_message)); | 715 do { |
724 // TODO(turnidge): Should this call be wrapped in a longjmp? | 716 DARTSCOPE(isolate); |
725 const Object& result = | 717 message = isolate->message_queue()->DequeueNoWait(); |
726 Object::Handle(DartLibraryCalls::HandleMessage(dest_port_id, | 718 if (message == NULL) { |
727 reply_port_id, | 719 break; |
728 msg)); | 720 } |
729 if (result.IsError()) { | 721 if (message->priority() == Message::kOOBPriority) { |
730 return Api::NewLocalHandle(result); | 722 UNIMPLEMENTED(); |
731 } | 723 } |
732 ASSERT(result.IsNull()); | 724 const Instance& msg = |
725 Instance::Handle(DeserializeMessage(message->data())); | |
726 const Object& result = Object::Handle( | |
727 DartLibraryCalls::HandleMessage( | |
728 message->dest_port(), message->reply_port(), msg)); | |
729 delete message; | |
730 if (result.IsError()) { | |
731 return Api::NewLocalHandle(result); | |
732 } | |
733 ASSERT(result.IsNull()); | |
734 } while (message->priority() <= Message::kOOBPriority); | |
Anton Muhin
2012/01/12 12:58:16
you have deleted message couple of lines above, no
Anton Muhin
2012/01/12 12:58:16
up to you, but it's hard to remember if normal pri
turnidge
2012/01/12 19:01:55
Yikes. Fixed.
turnidge
2012/01/12 19:01:55
Changed to an == for now.
| |
733 return Api::Success(); | 735 return Api::Success(); |
734 } | 736 } |
735 | 737 |
736 | 738 |
737 DART_EXPORT bool Dart_HasLivePorts() { | 739 DART_EXPORT bool Dart_HasLivePorts() { |
738 Isolate* isolate = Isolate::Current(); | 740 Isolate* isolate = Isolate::Current(); |
739 ASSERT(isolate); | 741 ASSERT(isolate); |
740 return isolate->live_ports() > 0; | 742 return isolate->live_ports() > 0; |
741 } | 743 } |
742 | 744 |
743 | 745 |
744 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 746 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
745 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 747 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
746 return reinterpret_cast<uint8_t*>(new_ptr); | 748 return reinterpret_cast<uint8_t*>(new_ptr); |
747 } | 749 } |
748 | 750 |
749 | 751 |
750 DART_EXPORT bool Dart_PostIntArray(Dart_Port port_id, | 752 DART_EXPORT bool Dart_PostIntArray(Dart_Port port_id, |
751 intptr_t len, | 753 intptr_t len, |
752 intptr_t* data) { | 754 intptr_t* data) { |
753 uint8_t* buffer = NULL; | 755 uint8_t* buffer = NULL; |
754 MessageWriter writer(&buffer, &allocator); | 756 MessageWriter writer(&buffer, &allocator); |
755 | 757 |
756 writer.WriteMessage(len, data); | 758 writer.WriteMessage(len, data); |
757 | 759 |
758 // Post the message at the given port. | 760 // Post the message at the given port. |
759 return PortMap::PostMessage(port_id, kNoReplyPort, Api::CastMessage(buffer)); | 761 return PortMap::PostMessage(new Message( |
762 port_id, Message::kIllegalPort, buffer, Message::kNormalPriority)); | |
760 } | 763 } |
761 | 764 |
762 | 765 |
763 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { | 766 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { |
764 Isolate* isolate = Isolate::Current(); | 767 Isolate* isolate = Isolate::Current(); |
765 CHECK_ISOLATE(isolate); | 768 CHECK_ISOLATE(isolate); |
766 DARTSCOPE_NOCHECKS(isolate); | 769 DARTSCOPE_NOCHECKS(isolate); |
767 const Object& object = Object::Handle(Api::UnwrapHandle(handle)); | 770 const Object& object = Object::Handle(Api::UnwrapHandle(handle)); |
768 uint8_t* data = NULL; | 771 uint8_t* data = NULL; |
769 SnapshotWriter writer(Snapshot::kMessage, &data, &allocator); | 772 SnapshotWriter writer(Snapshot::kMessage, &data, &allocator); |
770 writer.WriteObject(object.raw()); | 773 writer.WriteObject(object.raw()); |
771 writer.FinalizeBuffer(); | 774 writer.FinalizeBuffer(); |
772 return PortMap::PostMessage(port_id, kNoReplyPort, Api::CastMessage(data)); | 775 return PortMap::PostMessage(new Message( |
776 port_id, Message::kIllegalPort, data, Message::kNormalPriority)); | |
773 } | 777 } |
774 | 778 |
775 | 779 |
776 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { | 780 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { |
777 Isolate* isolate = Isolate::Current(); | 781 Isolate* isolate = Isolate::Current(); |
778 DARTSCOPE(isolate); | 782 DARTSCOPE(isolate); |
779 const String& class_name = String::Handle(String::NewSymbol("SendPortImpl")); | 783 const String& class_name = String::Handle(String::NewSymbol("SendPortImpl")); |
780 const String& function_name = String::Handle(String::NewSymbol("_create")); | 784 const String& function_name = String::Handle(String::NewSymbol("_create")); |
781 const int kNumArguments = 1; | 785 const int kNumArguments = 1; |
782 const Array& kNoArgumentNames = Array::Handle(); | 786 const Array& kNoArgumentNames = Array::Handle(); |
(...skipping 1719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2502 } | 2506 } |
2503 delete debug_region; | 2507 delete debug_region; |
2504 } else { | 2508 } else { |
2505 *buffer = NULL; | 2509 *buffer = NULL; |
2506 *buffer_size = 0; | 2510 *buffer_size = 0; |
2507 } | 2511 } |
2508 } | 2512 } |
2509 | 2513 |
2510 | 2514 |
2511 } // namespace dart | 2515 } // namespace dart |
OLD | NEW |