Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: runtime/vm/isolate.cc

Issue 8297004: Allow embedders to provide custom message delivery for an isolate. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
siva 2011/10/14 21:01:52 The style has been to leave a blank line here (i.e
turnidge 2011/10/14 23:08:02 Done.
8
9 #include "vm/assert.h" 8 #include "vm/assert.h"
10 #include "vm/bigint_store.h" 9 #include "vm/bigint_store.h"
11 #include "vm/code_index_table.h" 10 #include "vm/code_index_table.h"
12 #include "vm/compiler_stats.h" 11 #include "vm/compiler_stats.h"
13 #include "vm/dart_api_state.h" 12 #include "vm/dart_api_state.h"
14 #include "vm/debuginfo.h" 13 #include "vm/debuginfo.h"
15 #include "vm/heap.h" 14 #include "vm/heap.h"
15 #include "vm/message_queue.h"
16 #include "vm/object_store.h" 16 #include "vm/object_store.h"
17 #include "vm/parser.h" 17 #include "vm/parser.h"
18 #include "vm/port.h" 18 #include "vm/port.h"
19 #include "vm/random.h" 19 #include "vm/random.h"
20 #include "vm/stack_frame.h" 20 #include "vm/stack_frame.h"
21 #include "vm/stub_code.h" 21 #include "vm/stub_code.h"
22 #include "vm/thread.h" 22 #include "vm/thread.h"
23 #include "vm/timer.h" 23 #include "vm/timer.h"
24 #include "vm/visitor.h" 24 #include "vm/visitor.h"
25 25
siva 2011/10/14 21:01:52 extra blank line here.
turnidge 2011/10/14 23:08:02 Done.
26
26 namespace dart { 27 namespace dart {
27 28
28 DEFINE_FLAG(bool, report_invocation_count, false, 29 DEFINE_FLAG(bool, report_invocation_count, false,
29 "Count function invocations and report."); 30 "Count function invocations and report.");
30 DECLARE_FLAG(bool, generate_gdb_symbols); 31 DECLARE_FLAG(bool, generate_gdb_symbols);
31 32
32 33
33 Isolate::Isolate() 34 Isolate::Isolate()
34 : store_buffer_(), 35 : store_buffer_(),
35 monitor_(NULL),
36 message_queue_(NULL), 36 message_queue_(NULL),
37 post_message_callback_(NULL),
38 close_port_callback_(NULL),
37 active_ports_(0), 39 active_ports_(0),
38 heap_(NULL), 40 heap_(NULL),
39 object_store_(NULL), 41 object_store_(NULL),
40 top_resource_(NULL), 42 top_resource_(NULL),
41 top_context_(Context::null()), 43 top_context_(Context::null()),
42 current_zone_(NULL), 44 current_zone_(NULL),
43 #if defined(DEBUG) 45 #if defined(DEBUG)
44 no_gc_scope_depth_(0), 46 no_gc_scope_depth_(0),
45 no_handle_scope_depth_(0), 47 no_handle_scope_depth_(0),
46 top_handle_scope_(NULL), 48 top_handle_scope_(NULL),
47 #endif 49 #endif
48 random_seed_(Random::kDefaultRandomSeed), 50 random_seed_(Random::kDefaultRandomSeed),
49 bigint_store_(NULL), 51 bigint_store_(NULL),
50 top_exit_frame_info_(0), 52 top_exit_frame_info_(0),
51 init_callback_data_(NULL), 53 init_callback_data_(NULL),
52 library_tag_handler_(NULL), 54 library_tag_handler_(NULL),
53 api_state_(NULL), 55 api_state_(NULL),
54 stub_code_(NULL), 56 stub_code_(NULL),
55 code_index_table_(NULL), 57 code_index_table_(NULL),
56 long_jump_base_(NULL), 58 long_jump_base_(NULL),
57 timer_list_(), 59 timer_list_(),
58 stack_limit_(0), 60 stack_limit_(0),
59 stack_limit_on_overflow_exception_(0), 61 stack_limit_on_overflow_exception_(0),
60 ast_node_id_(AstNode::kInvalidId) { 62 ast_node_id_(AstNode::kInvalidId) {
61 } 63 }
62 64
63 65
64 Isolate::~Isolate() { 66 Isolate::~Isolate() {
65 delete monitor_;
66 delete message_queue_; 67 delete message_queue_;
67 delete heap_; 68 delete heap_;
68 delete object_store_; 69 delete object_store_;
69 // Do not delete stack resources: top_resource_ and current_zone_. 70 // Do not delete stack resources: top_resource_ and current_zone_.
70 delete bigint_store_; 71 delete bigint_store_;
71 delete api_state_; 72 delete api_state_;
72 delete stub_code_; 73 delete stub_code_;
73 delete code_index_table_; 74 delete code_index_table_;
74 } 75 }
75 76
76 77
78 static bool StandardPostMessageCallback(Dart_Isolate dart_isolate,
79 Dart_Port dest_port,
80 Dart_Port reply_port,
81 Dart_Message dart_message) {
82 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate);
83 ASSERT(isolate != NULL);
84 PortMessage* message = new PortMessage(dest_port, reply_port, dart_message);
85 isolate->message_queue()->Enqueue(message);
86 return true;
87 }
88
89
90 static void StandardClosePortCallback(Dart_Isolate dart_isolate,
91 Dart_Port port) {
92 // Remove the pending messages for this port.
93 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate);
94 ASSERT(isolate != NULL);
95 if (port == kCloseAllPorts) {
96 isolate->message_queue()->FlushAll();
97 } else {
98 isolate->message_queue()->Flush(port);
99 }
100 }
101
102
77 Isolate* Isolate::Init() { 103 Isolate* Isolate::Init() {
78 Isolate* result = new Isolate(); 104 Isolate* result = new Isolate();
79 ASSERT(result != NULL); 105 ASSERT(result != NULL);
80 106
81 // TODO(5411455): For now just set the recently created isolate as 107 // TODO(5411455): For now just set the recently created isolate as
82 // the current isolate. 108 // the current isolate.
83 SetCurrent(result); 109 SetCurrent(result);
84 110
85 // Setup the isolate monitor. 111 // Set up the isolate message queue.
86 Monitor* monitor = new Monitor();
87 ASSERT(monitor != NULL);
88 result->set_monitor(monitor);
89
90 MessageQueue* queue = new MessageQueue(); 112 MessageQueue* queue = new MessageQueue();
91 ASSERT(queue != NULL); 113 ASSERT(queue != NULL);
92 result->set_message_queue(queue); 114 result->set_message_queue(queue);
115 result->set_post_message_callback(&StandardPostMessageCallback);
116 result->set_close_port_callback(&StandardClosePortCallback);
93 117
94 // Setup the Dart API state. 118 // Setup the Dart API state.
95 ApiState* state = new ApiState(); 119 ApiState* state = new ApiState();
96 ASSERT(state != NULL); 120 ASSERT(state != NULL);
97 result->set_api_state(state); 121 result->set_api_state(state);
98 122
99 // Initialize stack top and limit in case we are running the isolate in the 123 // Initialize stack top and limit in case we are running the isolate in the
100 // main thread. 124 // main thread.
101 // TODO(5411455): Need to figure out how to set the stack limit for the 125 // TODO(5411455): Need to figure out how to set the stack limit for the
102 // main thread. 126 // main thread.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 ASSERT(this == Isolate::Current()); 196 ASSERT(this == Isolate::Current());
173 ASSERT(top_resource_ == NULL); 197 ASSERT(top_resource_ == NULL);
174 ASSERT((heap_ == NULL) || heap_->Verify()); 198 ASSERT((heap_ == NULL) || heap_->Verify());
175 199
176 // Close all the ports owned by this isolate. 200 // Close all the ports owned by this isolate.
177 PortMap::ClosePorts(); 201 PortMap::ClosePorts();
178 202
179 delete message_queue(); 203 delete message_queue();
180 set_message_queue(NULL); 204 set_message_queue(NULL);
181 205
182 // Remove the monitor associated with this isolate.
183 delete monitor();
184 set_monitor(NULL);
185
186 // Dump all accumalated timer data for the isolate. 206 // Dump all accumalated timer data for the isolate.
187 timer_list_.ReportTimers(); 207 timer_list_.ReportTimers();
188 if (FLAG_report_invocation_count) { 208 if (FLAG_report_invocation_count) {
189 PrintInvokedFunctions(); 209 PrintInvokedFunctions();
190 } 210 }
191 CompilerStats::Print(); 211 CompilerStats::Print();
192 if (FLAG_generate_gdb_symbols) { 212 if (FLAG_generate_gdb_symbols) {
193 DebugInfo::UnregisterAllSections(); 213 DebugInfo::UnregisterAllSections();
194 } 214 }
195 215
196 // TODO(5411455): For now just make sure there are no current isolates 216 // TODO(5411455): For now just make sure there are no current isolates
197 // as we are shutting down the isolate. 217 // as we are shutting down the isolate.
198 SetCurrent(NULL); 218 SetCurrent(NULL);
199 } 219 }
200 220
201 221
202 Dart_IsolateInitCallback Isolate::init_callback_ = NULL; 222 Dart_IsolateInitCallback Isolate::init_callback_ = NULL;
203 223
204 224
205 void Isolate::SetInitCallback(Dart_IsolateInitCallback callback) { 225 void Isolate::SetInitCallback(Dart_IsolateInitCallback callback) {
206 init_callback_ = callback; 226 init_callback_ = callback;
207 } 227 }
208 228
209 229
210 Dart_IsolateInitCallback Isolate::InitCallback() { 230 Dart_IsolateInitCallback Isolate::InitCallback() {
211 return init_callback_; 231 return init_callback_;
212 } 232 }
213 233
214 234
235 void Isolate::StandardRunLoop() {
236 ASSERT(long_jump_base() != NULL);
237 ASSERT(post_message_callback() == &StandardPostMessageCallback);
238 ASSERT(close_port_callback() == &StandardClosePortCallback);
239
240 while (active_ports() > 0) {
241 Zone zone;
242 HandleScope handle_scope;
243
244 PortMessage* message = message_queue()->Dequeue();
245 if (message == NULL) {
246 message_queue()->Wait(0);
247 message = message_queue()->Dequeue();
248 }
siva 2011/10/14 21:01:52 Why not make the Dequeue method wait if there is n
turnidge 2011/10/14 23:08:02 Done. Thanks, that's better.
249 if (message) {
250 Dart_HandleMessage(
251 message->dest_port(), message->reply_port(), message->data());
252 // message->Handle();
siva 2011/10/14 21:01:52 Is this commented out code still necessary?
turnidge 2011/10/14 23:08:02 Removed.
253 delete message;
254 }
255 }
256 }
257
258
215 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, 259 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor,
216 bool validate_frames) { 260 bool validate_frames) {
217 ASSERT(visitor != NULL); 261 ASSERT(visitor != NULL);
218 262
219 // Visit objects in the object store. 263 // Visit objects in the object store.
220 object_store()->VisitObjectPointers(visitor); 264 object_store()->VisitObjectPointers(visitor);
221 265
222 // Visit objects in per isolate stubs. 266 // Visit objects in per isolate stubs.
223 StubCode::VisitObjectPointers(visitor); 267 StubCode::VisitObjectPointers(visitor);
224 268
(...skipping 16 matching lines...) Expand all
241 // Visit all objects in the code index table. 285 // Visit all objects in the code index table.
242 if (code_index_table() != NULL) { 286 if (code_index_table() != NULL) {
243 code_index_table()->VisitObjectPointers(visitor); 287 code_index_table()->VisitObjectPointers(visitor);
244 } 288 }
245 289
246 // Visit the top context which is stored in the isolate. 290 // Visit the top context which is stored in the isolate.
247 visitor->VisitPointer(reinterpret_cast<RawObject**>(&top_context_)); 291 visitor->VisitPointer(reinterpret_cast<RawObject**>(&top_context_));
248 } 292 }
249 293
250 } // namespace dart 294 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698