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 "vm/isolate.h" | 5 #include "vm/isolate.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
9 #include "vm/assert.h" | 9 #include "vm/assert.h" |
10 #include "vm/bigint_store.h" | 10 #include "vm/bigint_store.h" |
11 #include "vm/code_index_table.h" | 11 #include "vm/code_index_table.h" |
12 #include "vm/compiler_stats.h" | 12 #include "vm/compiler_stats.h" |
13 #include "vm/dart_api_state.h" | 13 #include "vm/dart_api_state.h" |
| 14 #include "vm/dart_entry.h" |
14 #include "vm/debugger.h" | 15 #include "vm/debugger.h" |
15 #include "vm/debuginfo.h" | 16 #include "vm/debuginfo.h" |
16 #include "vm/heap.h" | 17 #include "vm/heap.h" |
17 #include "vm/message_queue.h" | 18 #include "vm/message_queue.h" |
18 #include "vm/object_store.h" | 19 #include "vm/object_store.h" |
19 #include "vm/parser.h" | 20 #include "vm/parser.h" |
20 #include "vm/port.h" | 21 #include "vm/port.h" |
21 #include "vm/random.h" | 22 #include "vm/random.h" |
22 #include "vm/stack_frame.h" | 23 #include "vm/stack_frame.h" |
23 #include "vm/stub_code.h" | 24 #include "vm/stub_code.h" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 void Isolate::SetCreateCallback(Dart_IsolateCreateCallback cb) { | 236 void Isolate::SetCreateCallback(Dart_IsolateCreateCallback cb) { |
236 create_callback_ = cb; | 237 create_callback_ = cb; |
237 } | 238 } |
238 | 239 |
239 | 240 |
240 Dart_IsolateCreateCallback Isolate::CreateCallback() { | 241 Dart_IsolateCreateCallback Isolate::CreateCallback() { |
241 return create_callback_; | 242 return create_callback_; |
242 } | 243 } |
243 | 244 |
244 | 245 |
245 void Isolate::StandardRunLoop() { | 246 static RawInstance* DeserializeMessage(void* data) { |
| 247 // Create a snapshot object using the buffer. |
| 248 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); |
| 249 ASSERT(snapshot->IsMessageSnapshot()); |
| 250 |
| 251 // Read object back from the snapshot. |
| 252 Isolate* isolate = Isolate::Current(); |
| 253 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store()); |
| 254 Instance& instance = Instance::Handle(); |
| 255 instance ^= reader.ReadObject(); |
| 256 return instance.raw(); |
| 257 } |
| 258 |
| 259 |
| 260 |
| 261 RawObject* Isolate::StandardRunLoop() { |
246 ASSERT(long_jump_base() != NULL); | 262 ASSERT(long_jump_base() != NULL); |
247 ASSERT(post_message_callback() == &StandardPostMessageCallback); | 263 ASSERT(post_message_callback() == &StandardPostMessageCallback); |
248 ASSERT(close_port_callback() == &StandardClosePortCallback); | 264 ASSERT(close_port_callback() == &StandardClosePortCallback); |
249 | 265 |
250 while (live_ports() > 0) { | 266 while (live_ports() > 0) { |
251 ASSERT(this == Isolate::Current()); | 267 ASSERT(this == Isolate::Current()); |
252 Zone zone(this); | 268 Zone zone(this); |
253 HandleScope handle_scope(this); | 269 HandleScope handle_scope(this); |
254 | 270 |
255 PortMessage* message = message_queue()->Dequeue(0); | 271 PortMessage* message = message_queue()->Dequeue(0); |
256 if (message != NULL) { | 272 if (message != NULL) { |
257 Dart_EnterScope(); | 273 const Instance& msg = |
258 Dart_Handle result = Dart_HandleMessage( | 274 Instance::Handle(DeserializeMessage(message->data())); |
259 message->dest_port(), message->reply_port(), message->data()); | 275 const Object& result = Object::Handle( |
260 if (Dart_IsError(result)) { | 276 DartLibraryCalls::HandleMessage( |
261 // TODO(turnidge): Consider passing this error out to | 277 message->dest_port(), message->reply_port(), msg)); |
262 // Dart_RunLoop so that the embedder can choose how to handle | 278 delete message; |
263 // it. | 279 if (result.IsUnhandledException()) { |
264 fprintf(stderr, "%s\n", Dart_GetError(result)); | 280 return result.raw(); |
265 Dart_ExitScope(); | |
266 exit(255); | |
267 } | 281 } |
268 Dart_ExitScope(); | |
269 delete message; | |
270 } | 282 } |
271 } | 283 } |
| 284 |
| 285 // Indicates success. |
| 286 return Object::null(); |
272 } | 287 } |
273 | 288 |
274 | 289 |
275 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, | 290 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, |
276 bool validate_frames) { | 291 bool validate_frames) { |
277 ASSERT(visitor != NULL); | 292 ASSERT(visitor != NULL); |
278 | 293 |
279 // Visit objects in the object store. | 294 // Visit objects in the object store. |
280 object_store()->VisitObjectPointers(visitor); | 295 object_store()->VisitObjectPointers(visitor); |
281 | 296 |
(...skipping 22 matching lines...) Expand all Loading... |
304 } | 319 } |
305 | 320 |
306 // Visit the top context which is stored in the isolate. | 321 // Visit the top context which is stored in the isolate. |
307 visitor->VisitPointer(reinterpret_cast<RawObject**>(&top_context_)); | 322 visitor->VisitPointer(reinterpret_cast<RawObject**>(&top_context_)); |
308 | 323 |
309 // Visit objects in the debugger. | 324 // Visit objects in the debugger. |
310 debugger()->VisitObjectPointers(visitor); | 325 debugger()->VisitObjectPointers(visitor); |
311 } | 326 } |
312 | 327 |
313 } // namespace dart | 328 } // namespace dart |
OLD | NEW |