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 "vm/isolate.h" | 5 #include "vm/isolate.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "lib/mirrors.h" | 9 #include "lib/mirrors.h" |
10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 (*callback)(Api::CastIsolate(isolate_)); | 82 (*callback)(Api::CastIsolate(isolate_)); |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 | 86 |
87 bool IsolateMessageHandler::HandleMessage(Message* message) { | 87 bool IsolateMessageHandler::HandleMessage(Message* message) { |
88 StartIsolateScope start_scope(isolate_); | 88 StartIsolateScope start_scope(isolate_); |
89 StackZone zone(isolate_); | 89 StackZone zone(isolate_); |
90 HandleScope handle_scope(isolate_); | 90 HandleScope handle_scope(isolate_); |
91 | 91 |
| 92 // If the message is in band we lookup the receive port to dispatch to. If |
| 93 // the receive port is closed, we drop the message without deserializing it. |
| 94 Object& receive_port = Object::Handle(); |
| 95 if (!message->IsOOB()) { |
| 96 receive_port = DartLibraryCalls::LookupReceivePort(message->dest_port()); |
| 97 if (receive_port.IsError()) { |
| 98 return ProcessUnhandledException(Instance::Handle(), |
| 99 Error::Cast(receive_port)); |
| 100 } |
| 101 if (receive_port.IsNull()) { |
| 102 delete message; |
| 103 return true; |
| 104 } |
| 105 } |
| 106 |
92 // Parse the message. | 107 // Parse the message. |
93 SnapshotReader reader(message->data(), message->len(), | 108 SnapshotReader reader(message->data(), message->len(), |
94 Snapshot::kMessage, Isolate::Current()); | 109 Snapshot::kMessage, Isolate::Current()); |
95 const Object& msg_obj = Object::Handle(reader.ReadObject()); | 110 const Object& msg_obj = Object::Handle(reader.ReadObject()); |
96 if (msg_obj.IsError()) { | 111 if (msg_obj.IsError()) { |
97 // An error occurred while reading the message. | 112 // An error occurred while reading the message. |
98 return ProcessUnhandledException(Instance::Handle(), Error::Cast(msg_obj)); | 113 return ProcessUnhandledException(Instance::Handle(), Error::Cast(msg_obj)); |
99 } | 114 } |
100 if (!msg_obj.IsNull() && !msg_obj.IsInstance()) { | 115 if (!msg_obj.IsNull() && !msg_obj.IsInstance()) { |
101 // TODO(turnidge): We need to decide what an isolate does with | 116 // TODO(turnidge): We need to decide what an isolate does with |
102 // malformed messages. If they (eventually) come from a remote | 117 // malformed messages. If they (eventually) come from a remote |
103 // machine, then it might make sense to drop the message entirely. | 118 // machine, then it might make sense to drop the message entirely. |
104 // In the case that the message originated locally, which is | 119 // In the case that the message originated locally, which is |
105 // always true for now, then this should never occur. | 120 // always true for now, then this should never occur. |
106 UNREACHABLE(); | 121 UNREACHABLE(); |
107 } | 122 } |
108 | 123 |
109 Instance& msg = Instance::Handle(); | 124 Instance& msg = Instance::Handle(); |
110 msg ^= msg_obj.raw(); // Can't use Instance::Cast because may be null. | 125 msg ^= msg_obj.raw(); // Can't use Instance::Cast because may be null. |
111 | 126 |
112 bool success = true; | 127 bool success = true; |
113 if (message->IsOOB()) { | 128 if (message->IsOOB()) { |
114 // For now the only OOB messages are Mirrors messages. | 129 // For now the only OOB messages are Mirrors messages. |
115 HandleMirrorsMessage(isolate_, message->reply_port(), msg); | 130 HandleMirrorsMessage(isolate_, message->reply_port(), msg); |
116 } else { | 131 } else { |
117 const Object& result = Object::Handle( | 132 const Object& result = Object::Handle( |
118 DartLibraryCalls::HandleMessage( | 133 DartLibraryCalls::HandleMessage( |
119 message->dest_port(), message->reply_port(), msg)); | 134 receive_port, message->reply_port(), msg)); |
120 if (result.IsError()) { | 135 if (result.IsError()) { |
121 success = ProcessUnhandledException(msg, Error::Cast(result)); | 136 success = ProcessUnhandledException(msg, Error::Cast(result)); |
122 } else { | 137 } else { |
123 ASSERT(result.IsNull()); | 138 ASSERT(result.IsNull()); |
124 } | 139 } |
125 } | 140 } |
126 delete message; | 141 delete message; |
127 return success; | 142 return success; |
128 } | 143 } |
129 | 144 |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 | 616 |
602 | 617 |
603 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor, | 618 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor, |
604 bool visit_prologue_weak_handles) { | 619 bool visit_prologue_weak_handles) { |
605 if (api_state() != NULL) { | 620 if (api_state() != NULL) { |
606 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles); | 621 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles); |
607 } | 622 } |
608 } | 623 } |
609 | 624 |
610 } // namespace dart | 625 } // namespace dart |
OLD | NEW |