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/bigint_store.h" | 9 #include "vm/bigint_store.h" |
10 #include "vm/code_index_table.h" | 10 #include "vm/code_index_table.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 DEFINE_FLAG(bool, report_invocation_count, false, | 30 DEFINE_FLAG(bool, report_invocation_count, false, |
31 "Count function invocations and report."); | 31 "Count function invocations and report."); |
32 DEFINE_FLAG(bool, trace_isolates, false, | 32 DEFINE_FLAG(bool, trace_isolates, false, |
33 "Trace isolate creation and shut down."); | 33 "Trace isolate creation and shut down."); |
34 DECLARE_FLAG(bool, generate_gdb_symbols); | 34 DECLARE_FLAG(bool, generate_gdb_symbols); |
35 | 35 |
36 | 36 |
37 Isolate::Isolate() | 37 Isolate::Isolate() |
38 : store_buffer_(), | 38 : store_buffer_(), |
39 message_queue_(NULL), | 39 message_queue_(NULL), |
40 post_message_callback_(NULL), | 40 message_notify_callback_(NULL), |
41 close_port_callback_(NULL), | |
42 name_(NULL), | 41 name_(NULL), |
43 num_ports_(0), | 42 num_ports_(0), |
44 live_ports_(0), | 43 live_ports_(0), |
45 main_port_(0), | 44 main_port_(0), |
46 heap_(NULL), | 45 heap_(NULL), |
47 object_store_(NULL), | 46 object_store_(NULL), |
48 top_resource_(NULL), | 47 top_resource_(NULL), |
49 top_context_(Context::null()), | 48 top_context_(Context::null()), |
50 current_zone_(NULL), | 49 current_zone_(NULL), |
51 #if defined(DEBUG) | 50 #if defined(DEBUG) |
(...skipping 28 matching lines...) Expand all Loading... |
80 delete bigint_store_; | 79 delete bigint_store_; |
81 delete api_state_; | 80 delete api_state_; |
82 delete stub_code_; | 81 delete stub_code_; |
83 delete code_index_table_; | 82 delete code_index_table_; |
84 delete debugger_; | 83 delete debugger_; |
85 delete mutex_; | 84 delete mutex_; |
86 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. | 85 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. |
87 } | 86 } |
88 | 87 |
89 | 88 |
90 static bool StandardPostMessageCallback(Dart_Isolate dart_isolate, | 89 void Isolate::PostMessage(Message* message) { |
91 Dart_Port dest_port, | 90 if (FLAG_trace_isolates) { |
92 Dart_Port reply_port, | 91 const char* source_name = "<native code>"; |
93 Dart_Message dart_message) { | 92 Isolate* source_isolate = Isolate::Current(); |
94 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); | 93 if (source_isolate) { |
95 ASSERT(isolate != NULL); | 94 source_name = source_isolate->name(); |
96 PortMessage* message = new PortMessage(dest_port, reply_port, dart_message); | 95 } |
97 isolate->message_queue()->Enqueue(message); | 96 OS::Print("[>] Posting message:\n" |
98 return true; | 97 "\tsource: %s\n" |
| 98 "\treply_port: %lld\n" |
| 99 "\tdest: %s\n" |
| 100 "\tdest_port: %lld\n", |
| 101 source_name, message->reply_port(), name(), message->dest_port()); |
| 102 } |
| 103 message_queue()->Enqueue(message); |
| 104 if (message->priority() >= Message::kOOBPriority) { |
| 105 // Handle out of band messages even if the isolate is busy. |
| 106 ScheduleInterrupts(Isolate::kMessageInterrupt); |
| 107 } |
| 108 Dart_MessageNotifyCallback callback = message_notify_callback(); |
| 109 if (callback) { |
| 110 // Allow the embedder to handle message notification. |
| 111 (*callback)(Api::CastIsolate(this)); |
| 112 } |
99 } | 113 } |
100 | 114 |
101 | 115 |
102 static void StandardClosePortCallback(Dart_Isolate dart_isolate, | 116 void Isolate::ClosePort(Dart_Port port) { |
103 Dart_Port port) { | 117 message_queue()->Flush(port); |
104 // Remove the pending messages for this port. | 118 } |
105 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); | 119 |
106 ASSERT(isolate != NULL); | 120 |
107 if (port == kCloseAllPorts) { | 121 void Isolate::CloseAllPorts() { |
108 isolate->message_queue()->FlushAll(); | 122 message_queue()->FlushAll(); |
109 } else { | |
110 isolate->message_queue()->Flush(port); | |
111 } | |
112 } | 123 } |
113 | 124 |
114 | 125 |
115 Isolate* Isolate::Init(const char* name_prefix) { | 126 Isolate* Isolate::Init(const char* name_prefix) { |
116 Isolate* result = new Isolate(); | 127 Isolate* result = new Isolate(); |
117 ASSERT(result != NULL); | 128 ASSERT(result != NULL); |
118 | 129 |
119 // TODO(5411455): For now just set the recently created isolate as | 130 // TODO(5411455): For now just set the recently created isolate as |
120 // the current isolate. | 131 // the current isolate. |
121 SetCurrent(result); | 132 SetCurrent(result); |
122 | 133 |
123 // Set up the isolate message queue. | 134 // Set up the isolate message queue. |
124 MessageQueue* queue = new MessageQueue(); | 135 MessageQueue* queue = new MessageQueue(); |
125 ASSERT(queue != NULL); | 136 ASSERT(queue != NULL); |
126 result->set_message_queue(queue); | 137 result->set_message_queue(queue); |
127 result->set_post_message_callback(&StandardPostMessageCallback); | |
128 result->set_close_port_callback(&StandardClosePortCallback); | |
129 | 138 |
130 // Setup the Dart API state. | 139 // Setup the Dart API state. |
131 ApiState* state = new ApiState(); | 140 ApiState* state = new ApiState(); |
132 ASSERT(state != NULL); | 141 ASSERT(state != NULL); |
133 result->set_api_state(state); | 142 result->set_api_state(state); |
134 | 143 |
135 // Initialize stack top and limit in case we are running the isolate in the | 144 // Initialize stack top and limit in case we are running the isolate in the |
136 // main thread. | 145 // main thread. |
137 // TODO(5411455): Need to figure out how to set the stack limit for the | 146 // TODO(5411455): Need to figure out how to set the stack limit for the |
138 // main thread. | 147 // main thread. |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 SnapshotReader reader(snapshot, Isolate::Current()); | 340 SnapshotReader reader(snapshot, Isolate::Current()); |
332 Instance& instance = Instance::Handle(); | 341 Instance& instance = Instance::Handle(); |
333 instance ^= reader.ReadObject(); | 342 instance ^= reader.ReadObject(); |
334 return instance.raw(); | 343 return instance.raw(); |
335 } | 344 } |
336 | 345 |
337 | 346 |
338 | 347 |
339 RawObject* Isolate::StandardRunLoop() { | 348 RawObject* Isolate::StandardRunLoop() { |
340 ASSERT(long_jump_base() != NULL); | 349 ASSERT(long_jump_base() != NULL); |
341 ASSERT(post_message_callback() == &StandardPostMessageCallback); | 350 ASSERT(message_notify_callback() == NULL); |
342 ASSERT(close_port_callback() == &StandardClosePortCallback); | |
343 | 351 |
344 while (live_ports() > 0) { | 352 while (live_ports() > 0) { |
345 ASSERT(this == Isolate::Current()); | 353 ASSERT(this == Isolate::Current()); |
346 Zone zone(this); | 354 Zone zone(this); |
347 HandleScope handle_scope(this); | 355 HandleScope handle_scope(this); |
348 | 356 |
349 PortMessage* message = message_queue()->Dequeue(0); | 357 Message* message = message_queue()->Dequeue(0); |
350 if (message != NULL) { | 358 if (message != NULL) { |
| 359 if (message->priority() >= Message::kOOBPriority) { |
| 360 // TODO(turnidge): Out of band messages will not go through the |
| 361 // regular message handler. Instead they will be dispatched to |
| 362 // special vm code. Implement. |
| 363 UNIMPLEMENTED(); |
| 364 } |
351 const Instance& msg = | 365 const Instance& msg = |
352 Instance::Handle(DeserializeMessage(message->data())); | 366 Instance::Handle(DeserializeMessage(message->data())); |
353 const Object& result = Object::Handle( | 367 const Object& result = Object::Handle( |
354 DartLibraryCalls::HandleMessage( | 368 DartLibraryCalls::HandleMessage( |
355 message->dest_port(), message->reply_port(), msg)); | 369 message->dest_port(), message->reply_port(), msg)); |
356 delete message; | 370 delete message; |
357 if (result.IsUnhandledException()) { | 371 if (result.IsError()) { |
358 return result.raw(); | 372 return result.raw(); |
359 } | 373 } |
| 374 ASSERT(result.IsNull()); |
360 } | 375 } |
361 } | 376 } |
362 | 377 |
363 // Indicates success. | 378 // Indicates success. |
364 return Object::null(); | 379 return Object::null(); |
365 } | 380 } |
366 | 381 |
367 | 382 |
368 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, | 383 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, |
369 bool validate_frames) { | 384 bool validate_frames) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 } | 419 } |
405 | 420 |
406 | 421 |
407 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor) { | 422 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor) { |
408 if (api_state() != NULL) { | 423 if (api_state() != NULL) { |
409 api_state()->VisitWeakHandles(visitor); | 424 api_state()->VisitWeakHandles(visitor); |
410 } | 425 } |
411 } | 426 } |
412 | 427 |
413 } // namespace dart | 428 } // namespace dart |
OLD | NEW |