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

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
« no previous file with comments | « runtime/vm/isolate.h ('k') | runtime/vm/message.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/compiler_stats.h" 9 #include "vm/compiler_stats.h"
10 #include "vm/dart_api_state.h" 10 #include "vm/dart_api_state.h"
11 #include "vm/dart_entry.h" 11 #include "vm/dart_entry.h"
12 #include "vm/debugger.h" 12 #include "vm/debugger.h"
13 #include "vm/debuginfo.h" 13 #include "vm/debuginfo.h"
14 #include "vm/heap.h" 14 #include "vm/heap.h"
15 #include "vm/message.h" 15 #include "vm/message_handler.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
26 namespace dart { 26 namespace dart {
27 27
28 DEFINE_FLAG(bool, report_usage_count, false, 28 DEFINE_FLAG(bool, report_usage_count, false,
29 "Track function usage and report."); 29 "Track function usage and report.");
30 DEFINE_FLAG(bool, trace_isolates, false, 30 DEFINE_FLAG(bool, trace_isolates, false,
31 "Trace isolate creation and shut down."); 31 "Trace isolate creation and shut down.");
32 DECLARE_FLAG(bool, generate_gdb_symbols); 32 DECLARE_FLAG(bool, generate_gdb_symbols);
33 33
34 34
35 class IsolateMessageHandler : public MessageHandler { 35 class IsolateMessageHandler : public MessageHandler {
36 public: 36 public:
37 explicit IsolateMessageHandler(Isolate* isolate); 37 explicit IsolateMessageHandler(Isolate* isolate);
38 ~IsolateMessageHandler(); 38 ~IsolateMessageHandler();
39 39
40 const char* name() const; 40 const char* name() const;
41 void MessageNotify(Message::Priority priority); 41 void MessageNotify(Message::Priority priority);
42 bool HandleMessage(Message* message);
42 43
43 #if defined(DEBUG) 44 #if defined(DEBUG)
44 // Check that it is safe to access this handler. 45 // Check that it is safe to access this handler.
45 void CheckAccess(); 46 void CheckAccess();
46 #endif 47 #endif
47 private: 48 private:
48 Isolate* isolate_; 49 Isolate* isolate_;
49 }; 50 };
50 51
51 52
(...skipping 16 matching lines...) Expand all
68 isolate_->ScheduleInterrupts(Isolate::kMessageInterrupt); 69 isolate_->ScheduleInterrupts(Isolate::kMessageInterrupt);
69 } 70 }
70 Dart_MessageNotifyCallback callback = isolate_->message_notify_callback(); 71 Dart_MessageNotifyCallback callback = isolate_->message_notify_callback();
71 if (callback) { 72 if (callback) {
72 // Allow the embedder to handle message notification. 73 // Allow the embedder to handle message notification.
73 (*callback)(Api::CastIsolate(isolate_)); 74 (*callback)(Api::CastIsolate(isolate_));
74 } 75 }
75 } 76 }
76 77
77 78
79 static RawInstance* DeserializeMessage(void* data) {
80 // Create a snapshot object using the buffer.
81 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data);
82 ASSERT(snapshot->IsMessageSnapshot());
83
84 // Read object back from the snapshot.
85 SnapshotReader reader(snapshot, Isolate::Current());
86 Instance& instance = Instance::Handle();
87 instance ^= reader.ReadObject();
88 return instance.raw();
89 }
90
91
92 bool IsolateMessageHandler::HandleMessage(Message* message) {
93 StartIsolateScope start_scope(isolate_);
94 Zone zone(isolate_);
95 HandleScope handle_scope(isolate_);
96
97 const Instance& msg =
98 Instance::Handle(DeserializeMessage(message->data()));
99 if (message->IsOOB()) {
100 // For now the only OOB messages are Mirrors messages.
101 const Object& result = Object::Handle(
102 DartLibraryCalls::HandleMirrorsMessage(
103 message->dest_port(), message->reply_port(), msg));
104 delete message;
105 if (result.IsError()) {
106 // TODO(turnidge): Propagating the error is probably wrong here.
107 Error& error = Error::Handle();
108 error ^= result.raw();
109 isolate_->object_store()->set_sticky_error(error);
110 return false;
111 }
112 ASSERT(result.IsNull());
113 } else {
114 const Object& result = Object::Handle(
115 DartLibraryCalls::HandleMessage(
116 message->dest_port(), message->reply_port(), msg));
117 delete message;
118 if (result.IsError()) {
119 Error& error = Error::Handle();
120 error ^= result.raw();
121 isolate_->object_store()->set_sticky_error(error);
122 return false;
123 }
124 ASSERT(result.IsNull());
125 }
126 return true;
127 }
128
129
78 #if defined(DEBUG) 130 #if defined(DEBUG)
79 void IsolateMessageHandler::CheckAccess() { 131 void IsolateMessageHandler::CheckAccess() {
80 ASSERT(isolate_ == Isolate::Current()); 132 ASSERT(isolate_ == Isolate::Current());
81 } 133 }
82 #endif 134 #endif
83 135
84 136
85 #if defined(DEBUG) 137 #if defined(DEBUG)
86 // static 138 // static
87 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) { 139 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) {
(...skipping 15 matching lines...) Expand all
103 init_callback_data_(NULL), 155 init_callback_data_(NULL),
104 library_tag_handler_(NULL), 156 library_tag_handler_(NULL),
105 api_state_(NULL), 157 api_state_(NULL),
106 stub_code_(NULL), 158 stub_code_(NULL),
107 debugger_(NULL), 159 debugger_(NULL),
108 long_jump_base_(NULL), 160 long_jump_base_(NULL),
109 timer_list_(), 161 timer_list_(),
110 ast_node_id_(AstNode::kNoId), 162 ast_node_id_(AstNode::kNoId),
111 mutex_(new Mutex()), 163 mutex_(new Mutex()),
112 stack_limit_(0), 164 stack_limit_(0),
113 saved_stack_limit_(0) { 165 saved_stack_limit_(0),
166 message_handler_(NULL),
167 spawn_data_(NULL) {
114 } 168 }
115 169
116 170
117 Isolate::~Isolate() { 171 Isolate::~Isolate() {
118 delete [] name_; 172 delete [] name_;
119 delete heap_; 173 delete heap_;
120 delete object_store_; 174 delete object_store_;
121 delete api_state_; 175 delete api_state_;
122 delete stub_code_; 176 delete stub_code_;
123 delete debugger_; 177 delete debugger_;
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 void Isolate::SetInterruptCallback(Dart_IsolateInterruptCallback cb) { 414 void Isolate::SetInterruptCallback(Dart_IsolateInterruptCallback cb) {
361 interrupt_callback_ = cb; 415 interrupt_callback_ = cb;
362 } 416 }
363 417
364 418
365 Dart_IsolateInterruptCallback Isolate::InterruptCallback() { 419 Dart_IsolateInterruptCallback Isolate::InterruptCallback() {
366 return interrupt_callback_; 420 return interrupt_callback_;
367 } 421 }
368 422
369 423
370 static RawInstance* DeserializeMessage(void* data) {
371 // Create a snapshot object using the buffer.
372 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data);
373 ASSERT(snapshot->IsMessageSnapshot());
374
375 // Read object back from the snapshot.
376 SnapshotReader reader(snapshot, Isolate::Current());
377 Instance& instance = Instance::Handle();
378 instance ^= reader.ReadObject();
379 return instance.raw();
380 }
381
382
383
384 RawError* Isolate::StandardRunLoop() {
385 ASSERT(message_notify_callback() == NULL);
386 ASSERT(message_handler() != NULL);
387
388 while (message_handler()->HasLivePorts()) {
389 ASSERT(this == Isolate::Current());
390 Zone zone(this);
391 HandleScope handle_scope(this);
392
393 // TODO(turnidge): This code is duplicated elsewhere. Consolidate.
394 Message* message = message_handler()->queue()->Dequeue(0);
395 if (message != NULL) {
396 const Instance& msg =
397 Instance::Handle(DeserializeMessage(message->data()));
398 if (message->priority() >= Message::kOOBPriority) {
399 // For now the only OOB messages are Mirrors messages.
400 const Object& result = Object::Handle(
401 DartLibraryCalls::HandleMirrorsMessage(
402 message->dest_port(), message->reply_port(), msg));
403 delete message;
404 if (result.IsError()) {
405 // TODO(turnidge): Propagating the error is probably wrong here.
406 Error& error = Error::Handle();
407 error ^= result.raw();
408 return error.raw();
409 }
410 ASSERT(result.IsNull());
411 } else {
412 const Object& result = Object::Handle(
413 DartLibraryCalls::HandleMessage(
414 message->dest_port(), message->reply_port(), msg));
415 delete message;
416 if (result.IsError()) {
417 Error& error = Error::Handle();
418 error ^= result.raw();
419 return error.raw();
420 }
421 ASSERT(result.IsNull());
422 }
423 }
424 }
425
426 // Indicates success.
427 return Error::null();
428 }
429
430
431 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, 424 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor,
432 bool visit_prologue_weak_handles, 425 bool visit_prologue_weak_handles,
433 bool validate_frames) { 426 bool validate_frames) {
434 ASSERT(visitor != NULL); 427 ASSERT(visitor != NULL);
435 428
436 // Visit objects in the object store. 429 // Visit objects in the object store.
437 object_store()->VisitObjectPointers(visitor); 430 object_store()->VisitObjectPointers(visitor);
438 431
439 // Visit objects in per isolate stubs. 432 // Visit objects in per isolate stubs.
440 StubCode::VisitObjectPointers(visitor); 433 StubCode::VisitObjectPointers(visitor);
(...skipping 23 matching lines...) Expand all
464 457
465 458
466 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor, 459 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor,
467 bool visit_prologue_weak_handles) { 460 bool visit_prologue_weak_handles) {
468 if (api_state() != NULL) { 461 if (api_state() != NULL) {
469 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles); 462 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles);
470 } 463 }
471 } 464 }
472 465
473 } // namespace dart 466 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/isolate.h ('k') | runtime/vm/message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698