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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 isolate_->ScheduleInterrupts(Isolate::kMessageInterrupt); | 73 isolate_->ScheduleInterrupts(Isolate::kMessageInterrupt); |
74 } | 74 } |
75 Dart_MessageNotifyCallback callback = isolate_->message_notify_callback(); | 75 Dart_MessageNotifyCallback callback = isolate_->message_notify_callback(); |
76 if (callback) { | 76 if (callback) { |
77 // Allow the embedder to handle message notification. | 77 // Allow the embedder to handle message notification. |
78 (*callback)(Api::CastIsolate(isolate_)); | 78 (*callback)(Api::CastIsolate(isolate_)); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 | 82 |
83 static RawInstance* DeserializeMessage(void* data) { | |
84 // Create a snapshot object using the buffer. | |
85 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); | |
86 ASSERT(snapshot->IsMessageSnapshot()); | |
87 | |
88 // Read object back from the snapshot. | |
89 SnapshotReader reader(snapshot, Isolate::Current()); | |
90 Instance& instance = Instance::Handle(); | |
91 instance ^= reader.ReadObject(); | |
92 return instance.raw(); | |
93 } | |
94 | |
95 | |
96 bool IsolateMessageHandler::HandleMessage(Message* message) { | 83 bool IsolateMessageHandler::HandleMessage(Message* message) { |
97 StartIsolateScope start_scope(isolate_); | 84 StartIsolateScope start_scope(isolate_); |
98 Zone zone(isolate_); | 85 Zone zone(isolate_); |
99 HandleScope handle_scope(isolate_); | 86 HandleScope handle_scope(isolate_); |
100 | 87 |
101 const Instance& msg = | 88 // Parse the message. |
102 Instance::Handle(DeserializeMessage(message->data())); | 89 SnapshotReader reader(message->data(), message->len(), |
| 90 Snapshot::kMessage, Isolate::Current()); |
| 91 const Object& msg_obj = Object::Handle(reader.ReadObject()); |
| 92 if (!msg_obj.IsNull() && !msg_obj.IsInstance()) { |
| 93 // TODO(turnidge): We need to decide what an isolate does with |
| 94 // malformed messages. If they (eventually) come from a remote |
| 95 // machine, then it might make sense to drop the message entirely. |
| 96 // In the case that the message originated locally, which is |
| 97 // always true for now, then this should never occur. |
| 98 UNREACHABLE(); |
| 99 } |
| 100 |
| 101 Instance& msg = Instance::Handle(); |
| 102 msg ^= msg_obj.raw(); // Can't use Instance::Cast because may be null. |
| 103 |
103 if (message->IsOOB()) { | 104 if (message->IsOOB()) { |
104 // For now the only OOB messages are Mirrors messages. | 105 // For now the only OOB messages are Mirrors messages. |
105 HandleMirrorsMessage(isolate_, message->reply_port(), msg); | 106 HandleMirrorsMessage(isolate_, message->reply_port(), msg); |
106 delete message; | 107 delete message; |
107 } else { | 108 } else { |
108 const Object& result = Object::Handle( | 109 const Object& result = Object::Handle( |
109 DartLibraryCalls::HandleMessage( | 110 DartLibraryCalls::HandleMessage( |
110 message->dest_port(), message->reply_port(), msg)); | 111 message->dest_port(), message->reply_port(), msg)); |
111 delete message; | 112 delete message; |
112 if (result.IsError()) { | 113 if (result.IsError()) { |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 | 469 |
469 | 470 |
470 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor, | 471 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor, |
471 bool visit_prologue_weak_handles) { | 472 bool visit_prologue_weak_handles) { |
472 if (api_state() != NULL) { | 473 if (api_state() != NULL) { |
473 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles); | 474 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles); |
474 } | 475 } |
475 } | 476 } |
476 | 477 |
477 } // namespace dart | 478 } // namespace dart |
OLD | NEW |