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

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

Issue 145323002: Post-meetup feature extravaganza. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 11 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "platform/json.h" 9 #include "platform/json.h"
10 #include "lib/mirrors.h" 10 #include "lib/mirrors.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // Allow the embedder to handle message notification. 97 // Allow the embedder to handle message notification.
98 (*callback)(Api::CastIsolate(isolate_)); 98 (*callback)(Api::CastIsolate(isolate_));
99 } 99 }
100 } 100 }
101 101
102 102
103 bool IsolateMessageHandler::HandleMessage(Message* message) { 103 bool IsolateMessageHandler::HandleMessage(Message* message) {
104 StartIsolateScope start_scope(isolate_); 104 StartIsolateScope start_scope(isolate_);
105 StackZone zone(isolate_); 105 StackZone zone(isolate_);
106 HandleScope handle_scope(isolate_); 106 HandleScope handle_scope(isolate_);
107 // TODO(turnidge): Rework collection total dart execution. This can
108 // overcount when other things (gc, compilation) are active.
109 TIMERSCOPE(time_dart_execution);
107 110
108 // If the message is in band we lookup the receive port to dispatch to. If 111 // If the message is in band we lookup the receive port to dispatch to. If
109 // the receive port is closed, we drop the message without deserializing it. 112 // the receive port is closed, we drop the message without deserializing it.
110 Object& receive_port = Object::Handle(); 113 Object& receive_port = Object::Handle();
111 if (!message->IsOOB()) { 114 if (!message->IsOOB()) {
112 receive_port = DartLibraryCalls::LookupReceivePort(message->dest_port()); 115 receive_port = DartLibraryCalls::LookupReceivePort(message->dest_port());
113 if (receive_port.IsError()) { 116 if (receive_port.IsError()) {
114 return ProcessUnhandledException(Object::null_instance(), 117 return ProcessUnhandledException(Object::null_instance(),
115 Error::Cast(receive_port)); 118 Error::Cast(receive_port));
116 } 119 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 single_step_(false), 296 single_step_(false),
294 random_(), 297 random_(),
295 simulator_(NULL), 298 simulator_(NULL),
296 long_jump_base_(NULL), 299 long_jump_base_(NULL),
297 timer_list_(), 300 timer_list_(),
298 deopt_id_(0), 301 deopt_id_(0),
299 mutex_(new Mutex()), 302 mutex_(new Mutex()),
300 stack_limit_(0), 303 stack_limit_(0),
301 saved_stack_limit_(0), 304 saved_stack_limit_(0),
302 message_handler_(NULL), 305 message_handler_(NULL),
303 spawn_data_(0), 306 spawn_state_(NULL),
304 is_runnable_(false), 307 is_runnable_(false),
305 gc_prologue_callbacks_(), 308 gc_prologue_callbacks_(),
306 gc_epilogue_callbacks_(), 309 gc_epilogue_callbacks_(),
307 defer_finalization_count_(0), 310 defer_finalization_count_(0),
308 deopt_context_(NULL), 311 deopt_context_(NULL),
309 stacktrace_(NULL), 312 stacktrace_(NULL),
310 stack_frame_index_(-1), 313 stack_frame_index_(-1),
311 object_histogram_(NULL), 314 object_histogram_(NULL),
312 object_id_ring_(NULL), 315 object_id_ring_(NULL),
313 profiler_data_(NULL), 316 profiler_data_(NULL),
(...skipping 15 matching lines...) Expand all
329 delete debugger_; 332 delete debugger_;
330 #if defined(USING_SIMULATOR) 333 #if defined(USING_SIMULATOR)
331 delete simulator_; 334 delete simulator_;
332 #endif 335 #endif
333 delete mutex_; 336 delete mutex_;
334 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. 337 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate.
335 delete message_handler_; 338 delete message_handler_;
336 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate. 339 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate.
337 ASSERT(deopt_context_ == NULL); // No deopt in progress when isolate deleted. 340 ASSERT(deopt_context_ == NULL); // No deopt in progress when isolate deleted.
338 delete object_histogram_; 341 delete object_histogram_;
342 delete spawn_state_;
339 } 343 }
340 344
341 void Isolate::SetCurrent(Isolate* current) { 345 void Isolate::SetCurrent(Isolate* current) {
342 Isolate* old_current = Current(); 346 Isolate* old_current = Current();
343 if (old_current != current) { 347 if (old_current != current) {
344 Profiler::EndExecution(old_current); 348 Profiler::EndExecution(old_current);
345 Thread::SetThreadLocal(isolate_key, reinterpret_cast<uword>(current)); 349 Thread::SetThreadLocal(isolate_key, reinterpret_cast<uword>(current));
346 Profiler::BeginExecution(current); 350 Profiler::BeginExecution(current);
347 } 351 }
348 } 352 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 // a StackResource, which requires a current isolate. 495 // a StackResource, which requires a current isolate.
492 mutex_->Lock(); 496 mutex_->Lock();
493 // Check if we are in a valid state to make the isolate runnable. 497 // Check if we are in a valid state to make the isolate runnable.
494 if (is_runnable_ == true) { 498 if (is_runnable_ == true) {
495 mutex_->Unlock(); 499 mutex_->Unlock();
496 return false; // Already runnable. 500 return false; // Already runnable.
497 } 501 }
498 // Set the isolate as runnable and if we are being spawned schedule 502 // Set the isolate as runnable and if we are being spawned schedule
499 // isolate on thread pool for execution. 503 // isolate on thread pool for execution.
500 is_runnable_ = true; 504 is_runnable_ = true;
501 IsolateSpawnState* state = reinterpret_cast<IsolateSpawnState*>(spawn_data()); 505 IsolateSpawnState* state = spawn_state();
502 if (state != NULL) { 506 if (state != NULL) {
503 ASSERT(this == state->isolate()); 507 ASSERT(this == state->isolate());
504 Run(); 508 Run();
505 } 509 }
506 mutex_->Unlock(); 510 mutex_->Unlock();
507 return true; 511 return true;
508 } 512 }
509 513
510 514
511 static void StoreError(Isolate* isolate, const Object& obj) { 515 static void StoreError(Isolate* isolate, const Object& obj) {
512 ASSERT(obj.IsError()); 516 ASSERT(obj.IsError());
513 isolate->object_store()->set_sticky_error(Error::Cast(obj)); 517 isolate->object_store()->set_sticky_error(Error::Cast(obj));
514 } 518 }
515 519
516 520
517 static bool RunIsolate(uword parameter) { 521 static bool RunIsolate(uword parameter) {
518 Isolate* isolate = reinterpret_cast<Isolate*>(parameter); 522 Isolate* isolate = reinterpret_cast<Isolate*>(parameter);
519 IsolateSpawnState* state = NULL; 523 IsolateSpawnState* state = NULL;
520 { 524 {
525 // TODO(turnidge): Is this locking required here at all anymore?
521 MutexLocker ml(isolate->mutex()); 526 MutexLocker ml(isolate->mutex());
522 state = reinterpret_cast<IsolateSpawnState*>(isolate->spawn_data()); 527 state = isolate->spawn_state();
523 isolate->set_spawn_data(0);
524 } 528 }
525 { 529 {
526 StartIsolateScope start_scope(isolate); 530 StartIsolateScope start_scope(isolate);
527 StackZone zone(isolate); 531 StackZone zone(isolate);
528 HandleScope handle_scope(isolate); 532 HandleScope handle_scope(isolate);
529 if (!ClassFinalizer::ProcessPendingClasses()) { 533 if (!ClassFinalizer::ProcessPendingClasses()) {
530 // Error is in sticky error already. 534 // Error is in sticky error already.
531 return false; 535 return false;
532 } 536 }
533 537
534 // Set up specific unhandled exception handler. 538 // Set up specific unhandled exception handler.
535 const String& callback_name = String::Handle( 539 const String& callback_name = String::Handle(
536 isolate, String::New(state->exception_callback_name())); 540 isolate, String::New(state->exception_callback_name()));
537 isolate->object_store()-> 541 isolate->object_store()->
538 set_unhandled_exception_handler(callback_name); 542 set_unhandled_exception_handler(callback_name);
539 543
540 Object& result = Object::Handle(); 544 Object& result = Object::Handle();
541 result = state->ResolveFunction(); 545 result = state->ResolveFunction();
542 bool is_spawn_uri = state->is_spawn_uri(); 546 bool is_spawn_uri = state->is_spawn_uri();
543 delete state;
544 state = NULL;
545 if (result.IsError()) { 547 if (result.IsError()) {
546 StoreError(isolate, result); 548 StoreError(isolate, result);
547 return false; 549 return false;
548 } 550 }
549 ASSERT(result.IsFunction()); 551 ASSERT(result.IsFunction());
550 Function& func = Function::Handle(isolate); 552 Function& func = Function::Handle(isolate);
551 func ^= result.raw(); 553 func ^= result.raw();
552 func = func.ImplicitClosureFunction(); 554 func = func.ImplicitClosureFunction();
553 555
554 // Instead of directly invoking the entry point we call '_startIsolate' with 556 // Instead of directly invoking the entry point we call '_startIsolate' with
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 return func.raw(); 1123 return func.raw();
1122 } 1124 }
1123 1125
1124 1126
1125 void IsolateSpawnState::Cleanup() { 1127 void IsolateSpawnState::Cleanup() {
1126 SwitchIsolateScope switch_scope(isolate()); 1128 SwitchIsolateScope switch_scope(isolate());
1127 Dart::ShutdownIsolate(); 1129 Dart::ShutdownIsolate();
1128 } 1130 }
1129 1131
1130 } // namespace dart 1132 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698