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

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

Issue 9924015: Use the ThreadPool for all isolates and native ports. Previously, (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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) 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);
43 44
44 #if defined(DEBUG) 45 #if defined(DEBUG)
45 // Check that it is safe to access this handler. 46 // Check that it is safe to access this handler.
46 void CheckAccess(); 47 void CheckAccess();
47 #endif 48 #endif
48 private: 49 private:
49 Isolate* isolate_; 50 Isolate* isolate_;
50 }; 51 };
51 52
52 53
(...skipping 16 matching lines...) Expand all
69 isolate_->ScheduleInterrupts(Isolate::kMessageInterrupt); 70 isolate_->ScheduleInterrupts(Isolate::kMessageInterrupt);
70 } 71 }
71 Dart_MessageNotifyCallback callback = isolate_->message_notify_callback(); 72 Dart_MessageNotifyCallback callback = isolate_->message_notify_callback();
72 if (callback) { 73 if (callback) {
73 // Allow the embedder to handle message notification. 74 // Allow the embedder to handle message notification.
74 (*callback)(Api::CastIsolate(isolate_)); 75 (*callback)(Api::CastIsolate(isolate_));
75 } 76 }
76 } 77 }
77 78
78 79
80 static RawInstance* DeserializeMessage(void* data) {
81 // Create a snapshot object using the buffer.
82 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data);
83 ASSERT(snapshot->IsMessageSnapshot());
84
85 // Read object back from the snapshot.
86 SnapshotReader reader(snapshot, Isolate::Current());
87 Instance& instance = Instance::Handle();
88 instance ^= reader.ReadObject();
89 return instance.raw();
90 }
91
92
93 bool IsolateMessageHandler::HandleMessage(Message* message) {
94 StartIsolateScope start_scope(isolate_);
95 Zone zone(isolate_);
96 HandleScope handle_scope(isolate_);
97
98 const Instance& msg =
99 Instance::Handle(DeserializeMessage(message->data()));
100 if (message->IsOOB()) {
101 // For now the only OOB messages are Mirrors messages.
102 const Object& result = Object::Handle(
103 DartLibraryCalls::HandleMirrorsMessage(
104 message->dest_port(), message->reply_port(), msg));
105 delete message;
106 if (result.IsError()) {
107 // TODO(turnidge): Propagating the error is probably wrong here.
108 Error& error = Error::Handle();
109 error ^= result.raw();
110 isolate_->object_store()->set_sticky_error(error);
111 return false;
112 }
113 ASSERT(result.IsNull());
114 } else {
115 const Object& result = Object::Handle(
116 DartLibraryCalls::HandleMessage(
117 message->dest_port(), message->reply_port(), msg));
118 delete message;
119 if (result.IsError()) {
120 Error& error = Error::Handle();
121 error ^= result.raw();
122 isolate_->object_store()->set_sticky_error(error);
123 return false;
124 }
125 ASSERT(result.IsNull());
126 }
127 return true;
128 }
129
130
79 #if defined(DEBUG) 131 #if defined(DEBUG)
80 void IsolateMessageHandler::CheckAccess() { 132 void IsolateMessageHandler::CheckAccess() {
81 ASSERT(isolate_ == Isolate::Current()); 133 ASSERT(isolate_ == Isolate::Current());
82 } 134 }
83 #endif 135 #endif
84 136
85 137
86 #if defined(DEBUG) 138 #if defined(DEBUG)
87 // static 139 // static
88 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) { 140 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) {
(...skipping 16 matching lines...) Expand all
105 library_tag_handler_(NULL), 157 library_tag_handler_(NULL),
106 api_state_(NULL), 158 api_state_(NULL),
107 stub_code_(NULL), 159 stub_code_(NULL),
108 code_index_table_(NULL), 160 code_index_table_(NULL),
109 debugger_(NULL), 161 debugger_(NULL),
110 long_jump_base_(NULL), 162 long_jump_base_(NULL),
111 timer_list_(), 163 timer_list_(),
112 ast_node_id_(AstNode::kNoId), 164 ast_node_id_(AstNode::kNoId),
113 mutex_(new Mutex()), 165 mutex_(new Mutex()),
114 stack_limit_(0), 166 stack_limit_(0),
115 saved_stack_limit_(0) { 167 saved_stack_limit_(0),
168 message_handler_(NULL),
169 spawn_data_(NULL) {
116 } 170 }
117 171
118 172
119 Isolate::~Isolate() { 173 Isolate::~Isolate() {
120 delete [] name_; 174 delete [] name_;
121 delete heap_; 175 delete heap_;
122 delete object_store_; 176 delete object_store_;
123 delete api_state_; 177 delete api_state_;
124 delete stub_code_; 178 delete stub_code_;
125 delete code_index_table_; 179 delete code_index_table_;
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 void Isolate::SetInterruptCallback(Dart_IsolateInterruptCallback cb) { 417 void Isolate::SetInterruptCallback(Dart_IsolateInterruptCallback cb) {
364 interrupt_callback_ = cb; 418 interrupt_callback_ = cb;
365 } 419 }
366 420
367 421
368 Dart_IsolateInterruptCallback Isolate::InterruptCallback() { 422 Dart_IsolateInterruptCallback Isolate::InterruptCallback() {
369 return interrupt_callback_; 423 return interrupt_callback_;
370 } 424 }
371 425
372 426
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, 427 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor,
435 bool visit_prologue_weak_handles, 428 bool visit_prologue_weak_handles,
436 bool validate_frames) { 429 bool validate_frames) {
437 ASSERT(visitor != NULL); 430 ASSERT(visitor != NULL);
438 431
439 // Visit objects in the object store. 432 // Visit objects in the object store.
440 object_store()->VisitObjectPointers(visitor); 433 object_store()->VisitObjectPointers(visitor);
441 434
442 // Visit objects in per isolate stubs. 435 // Visit objects in per isolate stubs.
443 StubCode::VisitObjectPointers(visitor); 436 StubCode::VisitObjectPointers(visitor);
(...skipping 28 matching lines...) Expand all
472 465
473 466
474 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor, 467 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor,
475 bool visit_prologue_weak_handles) { 468 bool visit_prologue_weak_handles) {
476 if (api_state() != NULL) { 469 if (api_state() != NULL) {
477 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles); 470 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles);
478 } 471 }
479 } 472 }
480 473
481 } // namespace dart 474 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698