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" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 namespace dart { | 29 namespace dart { |
30 | 30 |
31 DEFINE_FLAG(bool, report_invocation_count, false, | 31 DEFINE_FLAG(bool, report_invocation_count, false, |
32 "Count function invocations and report."); | 32 "Count function invocations and report."); |
33 DECLARE_FLAG(bool, generate_gdb_symbols); | 33 DECLARE_FLAG(bool, generate_gdb_symbols); |
34 | 34 |
35 | 35 |
36 Isolate::Isolate() | 36 Isolate::Isolate() |
37 : store_buffer_(), | 37 : store_buffer_(), |
38 message_queue_(NULL), | 38 message_queue_(NULL), |
39 post_message_callback_(NULL), | 39 message_notify_callback_(NULL), |
40 close_port_callback_(NULL), | |
41 num_ports_(0), | 40 num_ports_(0), |
42 live_ports_(0), | 41 live_ports_(0), |
43 main_port_(0), | 42 main_port_(0), |
44 heap_(NULL), | 43 heap_(NULL), |
45 object_store_(NULL), | 44 object_store_(NULL), |
46 top_resource_(NULL), | 45 top_resource_(NULL), |
47 top_context_(Context::null()), | 46 top_context_(Context::null()), |
48 current_zone_(NULL), | 47 current_zone_(NULL), |
49 #if defined(DEBUG) | 48 #if defined(DEBUG) |
50 no_gc_scope_depth_(0), | 49 no_gc_scope_depth_(0), |
(...skipping 25 matching lines...) Expand all Loading... | |
76 // Do not delete stack resources: top_resource_ and current_zone_. | 75 // Do not delete stack resources: top_resource_ and current_zone_. |
77 delete bigint_store_; | 76 delete bigint_store_; |
78 delete api_state_; | 77 delete api_state_; |
79 delete stub_code_; | 78 delete stub_code_; |
80 delete code_index_table_; | 79 delete code_index_table_; |
81 delete mutex_; | 80 delete mutex_; |
82 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. | 81 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. |
83 } | 82 } |
84 | 83 |
85 | 84 |
86 static bool StandardPostMessageCallback(Dart_Isolate dart_isolate, | 85 void Isolate::PostMessage(Message* message) { |
87 Dart_Port dest_port, | 86 message_queue()->Enqueue(message); |
88 Dart_Port reply_port, | 87 if (message->priority() <= Message::kOOBPriority) { |
Ivan Posva
2012/01/23 22:00:43
Shouldn't this be ">="? Only priorities of OOB and
turnidge
2012/01/23 22:32:52
Yes. Fixed. (I reversed the order during impleme
| |
89 Dart_Message dart_message) { | 88 // Handle out of band messages even if the isolate is busy. |
90 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); | 89 ScheduleInterrupts(Isolate::kMessageInterrupt); |
91 ASSERT(isolate != NULL); | 90 } |
92 PortMessage* message = new PortMessage(dest_port, reply_port, dart_message); | 91 |
93 isolate->message_queue()->Enqueue(message); | 92 Dart_MessageNotifyCallback callback = message_notify_callback(); |
94 return true; | 93 if (callback) { |
94 // Allow the embedder to handle message notification. | |
95 (*callback)(Api::CastIsolate(this)); | |
96 } | |
95 } | 97 } |
96 | 98 |
97 | 99 |
98 static void StandardClosePortCallback(Dart_Isolate dart_isolate, | 100 void Isolate::ClosePort(Dart_Port port) { |
99 Dart_Port port) { | 101 message_queue()->Flush(port); |
100 // Remove the pending messages for this port. | 102 } |
101 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); | 103 |
102 ASSERT(isolate != NULL); | 104 |
103 if (port == kCloseAllPorts) { | 105 void Isolate::CloseAllPorts() { |
104 isolate->message_queue()->FlushAll(); | 106 message_queue()->FlushAll(); |
105 } else { | |
106 isolate->message_queue()->Flush(port); | |
107 } | |
108 } | 107 } |
109 | 108 |
110 | 109 |
111 Isolate* Isolate::Init() { | 110 Isolate* Isolate::Init() { |
112 Isolate* result = new Isolate(); | 111 Isolate* result = new Isolate(); |
113 ASSERT(result != NULL); | 112 ASSERT(result != NULL); |
114 | 113 |
115 // TODO(5411455): For now just set the recently created isolate as | 114 // TODO(5411455): For now just set the recently created isolate as |
116 // the current isolate. | 115 // the current isolate. |
117 SetCurrent(result); | 116 SetCurrent(result); |
118 | 117 |
119 // Set up the isolate message queue. | 118 // Set up the isolate message queue. |
120 MessageQueue* queue = new MessageQueue(); | 119 MessageQueue* queue = new MessageQueue(); |
121 ASSERT(queue != NULL); | 120 ASSERT(queue != NULL); |
122 result->set_message_queue(queue); | 121 result->set_message_queue(queue); |
123 result->set_post_message_callback(&StandardPostMessageCallback); | |
124 result->set_close_port_callback(&StandardClosePortCallback); | |
125 | 122 |
126 // Setup the Dart API state. | 123 // Setup the Dart API state. |
127 ApiState* state = new ApiState(); | 124 ApiState* state = new ApiState(); |
128 ASSERT(state != NULL); | 125 ASSERT(state != NULL); |
129 result->set_api_state(state); | 126 result->set_api_state(state); |
130 | 127 |
131 // Initialize stack top and limit in case we are running the isolate in the | 128 // Initialize stack top and limit in case we are running the isolate in the |
132 // main thread. | 129 // main thread. |
133 // TODO(5411455): Need to figure out how to set the stack limit for the | 130 // TODO(5411455): Need to figure out how to set the stack limit for the |
134 // main thread. | 131 // main thread. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 SnapshotReader reader(snapshot, Isolate::Current()); | 294 SnapshotReader reader(snapshot, Isolate::Current()); |
298 Instance& instance = Instance::Handle(); | 295 Instance& instance = Instance::Handle(); |
299 instance ^= reader.ReadObject(); | 296 instance ^= reader.ReadObject(); |
300 return instance.raw(); | 297 return instance.raw(); |
301 } | 298 } |
302 | 299 |
303 | 300 |
304 | 301 |
305 RawObject* Isolate::StandardRunLoop() { | 302 RawObject* Isolate::StandardRunLoop() { |
306 ASSERT(long_jump_base() != NULL); | 303 ASSERT(long_jump_base() != NULL); |
307 ASSERT(post_message_callback() == &StandardPostMessageCallback); | 304 ASSERT(message_notify_callback() == NULL); |
308 ASSERT(close_port_callback() == &StandardClosePortCallback); | |
309 | 305 |
310 while (live_ports() > 0) { | 306 while (live_ports() > 0) { |
311 ASSERT(this == Isolate::Current()); | 307 ASSERT(this == Isolate::Current()); |
312 Zone zone(this); | 308 Zone zone(this); |
313 HandleScope handle_scope(this); | 309 HandleScope handle_scope(this); |
314 | 310 |
315 PortMessage* message = message_queue()->Dequeue(0); | 311 Message* message = message_queue()->Dequeue(0); |
316 if (message != NULL) { | 312 if (message != NULL) { |
313 if (message->priority() == Message::kOOBPriority) { | |
314 UNIMPLEMENTED(); | |
Ivan Posva
2012/01/23 22:00:43
ditto. Short comment needed.
turnidge
2012/01/23 22:32:52
Done.
| |
315 } | |
317 const Instance& msg = | 316 const Instance& msg = |
318 Instance::Handle(DeserializeMessage(message->data())); | 317 Instance::Handle(DeserializeMessage(message->data())); |
319 const Object& result = Object::Handle( | 318 const Object& result = Object::Handle( |
320 DartLibraryCalls::HandleMessage( | 319 DartLibraryCalls::HandleMessage( |
321 message->dest_port(), message->reply_port(), msg)); | 320 message->dest_port(), message->reply_port(), msg)); |
322 delete message; | 321 delete message; |
323 if (result.IsUnhandledException()) { | 322 if (result.IsError()) { |
324 return result.raw(); | 323 return result.raw(); |
325 } | 324 } |
325 ASSERT(result.IsNull()); | |
326 } | 326 } |
327 } | 327 } |
328 | 328 |
329 // Indicates success. | 329 // Indicates success. |
330 return Object::null(); | 330 return Object::null(); |
331 } | 331 } |
332 | 332 |
333 | 333 |
334 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, | 334 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, |
335 bool validate_frames) { | 335 bool validate_frames) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
377 } | 377 } |
378 | 378 |
379 | 379 |
380 void Isolate::VisitWeakObjectPointers(ObjectPointerVisitor* visitor) { | 380 void Isolate::VisitWeakObjectPointers(ObjectPointerVisitor* visitor) { |
381 if (api_state() != NULL) { | 381 if (api_state() != NULL) { |
382 api_state()->VisitWeakObjectPointers(visitor); | 382 api_state()->VisitWeakObjectPointers(visitor); |
383 } | 383 } |
384 } | 384 } |
385 | 385 |
386 } // namespace dart | 386 } // namespace dart |
OLD | NEW |