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 "vm/code_index_table.h" | 9 #include "vm/code_index_table.h" |
10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
11 #include "vm/dart_api_state.h" | 11 #include "vm/dart_api_state.h" |
12 #include "vm/dart_entry.h" | 12 #include "vm/dart_entry.h" |
13 #include "vm/debugger.h" | 13 #include "vm/debugger.h" |
14 #include "vm/debuginfo.h" | 14 #include "vm/debuginfo.h" |
15 #include "vm/heap.h" | 15 #include "vm/heap.h" |
16 #include "vm/message.h" | 16 #include "vm/message_handler.h" |
17 #include "vm/object_store.h" | 17 #include "vm/object_store.h" |
18 #include "vm/parser.h" | 18 #include "vm/parser.h" |
19 #include "vm/port.h" | 19 #include "vm/port.h" |
20 #include "vm/random.h" | 20 #include "vm/random.h" |
21 #include "vm/stack_frame.h" | 21 #include "vm/stack_frame.h" |
22 #include "vm/stub_code.h" | 22 #include "vm/stub_code.h" |
23 #include "vm/thread.h" | 23 #include "vm/thread.h" |
24 #include "vm/timer.h" | 24 #include "vm/timer.h" |
25 #include "vm/visitor.h" | 25 #include "vm/visitor.h" |
26 | 26 |
27 namespace dart { | 27 namespace dart { |
28 | 28 |
29 DEFINE_FLAG(bool, report_usage_count, false, | 29 DEFINE_FLAG(bool, report_usage_count, false, |
30 "Track function usage and report."); | 30 "Track function usage and report."); |
31 DEFINE_FLAG(bool, trace_isolates, false, | 31 DEFINE_FLAG(bool, trace_isolates, false, |
32 "Trace isolate creation and shut down."); | 32 "Trace isolate creation and shut down."); |
33 DECLARE_FLAG(bool, generate_gdb_symbols); | 33 DECLARE_FLAG(bool, generate_gdb_symbols); |
34 | 34 |
35 | 35 |
36 class IsolateMessageHandler : public MessageHandler { | 36 class IsolateMessageHandler : public MessageHandler { |
37 public: | 37 public: |
38 explicit IsolateMessageHandler(Isolate* isolate); | 38 explicit IsolateMessageHandler(Isolate* isolate); |
39 ~IsolateMessageHandler(); | 39 ~IsolateMessageHandler(); |
40 | 40 |
41 const char* name() const; | 41 const char* name() const; |
42 void MessageNotify(Message::Priority priority); | 42 void MessageNotify(Message::Priority priority); |
43 bool HandleMessage(Message* message); | |
44 char* GetErrorCString(); | |
43 | 45 |
44 #if defined(DEBUG) | 46 #if defined(DEBUG) |
45 // Check that it is safe to access this handler. | 47 // Check that it is safe to access this handler. |
46 void CheckAccess(); | 48 void CheckAccess(); |
47 #endif | 49 #endif |
48 private: | 50 private: |
49 Isolate* isolate_; | 51 Isolate* isolate_; |
50 }; | 52 }; |
51 | 53 |
52 | 54 |
(...skipping 16 matching lines...) Expand all Loading... | |
69 isolate_->ScheduleInterrupts(Isolate::kMessageInterrupt); | 71 isolate_->ScheduleInterrupts(Isolate::kMessageInterrupt); |
70 } | 72 } |
71 Dart_MessageNotifyCallback callback = isolate_->message_notify_callback(); | 73 Dart_MessageNotifyCallback callback = isolate_->message_notify_callback(); |
72 if (callback) { | 74 if (callback) { |
73 // Allow the embedder to handle message notification. | 75 // Allow the embedder to handle message notification. |
74 (*callback)(Api::CastIsolate(isolate_)); | 76 (*callback)(Api::CastIsolate(isolate_)); |
75 } | 77 } |
76 } | 78 } |
77 | 79 |
78 | 80 |
81 static RawInstance* DeserializeMessage(void* data) { | |
82 // Create a snapshot object using the buffer. | |
83 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); | |
84 ASSERT(snapshot->IsMessageSnapshot()); | |
85 | |
86 // Read object back from the snapshot. | |
87 SnapshotReader reader(snapshot, Isolate::Current()); | |
88 Instance& instance = Instance::Handle(); | |
89 instance ^= reader.ReadObject(); | |
90 return instance.raw(); | |
91 } | |
92 | |
93 | |
94 bool IsolateMessageHandler::HandleMessage(Message* message) { | |
95 SetIsolateScope set_scope(isolate_); | |
96 Zone zone(isolate_); | |
97 HandleScope handle_scope(isolate_); | |
98 | |
99 const Instance& msg = | |
100 Instance::Handle(DeserializeMessage(message->data())); | |
101 if (message->priority() >= Message::kOOBPriority) { | |
siva
2012/04/14 00:29:53
could we have something like message->IsMirrorMess
turnidge
2012/04/17 23:46:55
I've added message->IsOOB().
| |
102 // For now the only OOB messages are Mirrors messages. | |
103 const Object& result = Object::Handle( | |
104 DartLibraryCalls::HandleMirrorsMessage( | |
105 message->dest_port(), message->reply_port(), msg)); | |
106 delete message; | |
107 if (result.IsError()) { | |
108 // TODO(turnidge): Propagating the error is probably wrong here. | |
109 Error& error = Error::Handle(); | |
110 error ^= result.raw(); | |
111 isolate_->object_store()->set_sticky_error(error); | |
112 return false; | |
113 } | |
114 ASSERT(result.IsNull()); | |
115 } else { | |
116 const Object& result = Object::Handle( | |
117 DartLibraryCalls::HandleMessage( | |
118 message->dest_port(), message->reply_port(), msg)); | |
119 delete message; | |
120 if (result.IsError()) { | |
121 Error& error = Error::Handle(); | |
122 error ^= result.raw(); | |
123 isolate_->object_store()->set_sticky_error(error); | |
124 return false; | |
125 } | |
126 ASSERT(result.IsNull()); | |
127 } | |
128 return true; | |
129 } | |
130 | |
131 | |
132 char* IsolateMessageHandler::GetErrorCString() { | |
133 SetIsolateScope set_scope(isolate_); | |
134 Zone zone(isolate_); | |
135 HandleScope handle_scope(isolate_); | |
136 const Error& error = Error::Handle(isolate_->object_store()->sticky_error()); | |
137 ASSERT(!error.IsNull()); | |
138 return strdup(error.ToErrorCString()); | |
139 } | |
140 | |
141 | |
79 #if defined(DEBUG) | 142 #if defined(DEBUG) |
80 void IsolateMessageHandler::CheckAccess() { | 143 void IsolateMessageHandler::CheckAccess() { |
81 ASSERT(isolate_ == Isolate::Current()); | 144 ASSERT(isolate_ == Isolate::Current()); |
82 } | 145 } |
83 #endif | 146 #endif |
84 | 147 |
85 | 148 |
86 #if defined(DEBUG) | 149 #if defined(DEBUG) |
87 // static | 150 // static |
88 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) { | 151 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) { |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 void Isolate::SetInterruptCallback(Dart_IsolateInterruptCallback cb) { | 426 void Isolate::SetInterruptCallback(Dart_IsolateInterruptCallback cb) { |
364 interrupt_callback_ = cb; | 427 interrupt_callback_ = cb; |
365 } | 428 } |
366 | 429 |
367 | 430 |
368 Dart_IsolateInterruptCallback Isolate::InterruptCallback() { | 431 Dart_IsolateInterruptCallback Isolate::InterruptCallback() { |
369 return interrupt_callback_; | 432 return interrupt_callback_; |
370 } | 433 } |
371 | 434 |
372 | 435 |
373 static RawInstance* DeserializeMessage(void* data) { | |
374 // Create a snapshot object using the buffer. | |
375 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); | |
376 ASSERT(snapshot->IsMessageSnapshot()); | |
377 | |
378 // Read object back from the snapshot. | |
379 SnapshotReader reader(snapshot, Isolate::Current()); | |
380 Instance& instance = Instance::Handle(); | |
381 instance ^= reader.ReadObject(); | |
382 return instance.raw(); | |
383 } | |
384 | |
385 | |
386 | |
387 RawError* Isolate::StandardRunLoop() { | |
388 ASSERT(message_notify_callback() == NULL); | |
389 ASSERT(message_handler() != NULL); | |
390 | |
391 while (message_handler()->HasLivePorts()) { | |
392 ASSERT(this == Isolate::Current()); | |
393 Zone zone(this); | |
394 HandleScope handle_scope(this); | |
395 | |
396 // TODO(turnidge): This code is duplicated elsewhere. Consolidate. | |
397 Message* message = message_handler()->queue()->Dequeue(0); | |
398 if (message != NULL) { | |
399 const Instance& msg = | |
400 Instance::Handle(DeserializeMessage(message->data())); | |
401 if (message->priority() >= Message::kOOBPriority) { | |
402 // For now the only OOB messages are Mirrors messages. | |
403 const Object& result = Object::Handle( | |
404 DartLibraryCalls::HandleMirrorsMessage( | |
405 message->dest_port(), message->reply_port(), msg)); | |
406 delete message; | |
407 if (result.IsError()) { | |
408 // TODO(turnidge): Propagating the error is probably wrong here. | |
409 Error& error = Error::Handle(); | |
410 error ^= result.raw(); | |
411 return error.raw(); | |
412 } | |
413 ASSERT(result.IsNull()); | |
414 } else { | |
415 const Object& result = Object::Handle( | |
416 DartLibraryCalls::HandleMessage( | |
417 message->dest_port(), message->reply_port(), msg)); | |
418 delete message; | |
419 if (result.IsError()) { | |
420 Error& error = Error::Handle(); | |
421 error ^= result.raw(); | |
422 return error.raw(); | |
423 } | |
424 ASSERT(result.IsNull()); | |
425 } | |
426 } | |
427 } | |
428 | |
429 // Indicates success. | |
430 return Error::null(); | |
431 } | |
432 | |
433 | |
434 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, | 436 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, |
435 bool visit_prologue_weak_handles, | 437 bool visit_prologue_weak_handles, |
436 bool validate_frames) { | 438 bool validate_frames) { |
437 ASSERT(visitor != NULL); | 439 ASSERT(visitor != NULL); |
438 | 440 |
439 // Visit objects in the object store. | 441 // Visit objects in the object store. |
440 object_store()->VisitObjectPointers(visitor); | 442 object_store()->VisitObjectPointers(visitor); |
441 | 443 |
442 // Visit objects in per isolate stubs. | 444 // Visit objects in per isolate stubs. |
443 StubCode::VisitObjectPointers(visitor); | 445 StubCode::VisitObjectPointers(visitor); |
(...skipping 28 matching lines...) Expand all Loading... | |
472 | 474 |
473 | 475 |
474 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor, | 476 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor, |
475 bool visit_prologue_weak_handles) { | 477 bool visit_prologue_weak_handles) { |
476 if (api_state() != NULL) { | 478 if (api_state() != NULL) { |
477 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles); | 479 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles); |
478 } | 480 } |
479 } | 481 } |
480 | 482 |
481 } // namespace dart | 483 } // namespace dart |
OLD | NEW |