Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/message_handler.h" | 5 #include "vm/message_handler.h" |
| 6 | 6 |
| 7 #include "vm/dart.h" | 7 #include "vm/dart.h" |
| 8 #include "vm/lockers.h" | 8 #include "vm/lockers.h" |
| 9 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 // assigned to a thread pool. | 251 // assigned to a thread pool. |
| 252 MonitorLocker ml(&monitor_); | 252 MonitorLocker ml(&monitor_); |
| 253 ASSERT(pool_ == NULL); | 253 ASSERT(pool_ == NULL); |
| 254 #if defined(DEBUG) | 254 #if defined(DEBUG) |
| 255 CheckAccess(); | 255 CheckAccess(); |
| 256 #endif | 256 #endif |
| 257 return HandleMessages(true, false); | 257 return HandleMessages(true, false); |
| 258 } | 258 } |
| 259 | 259 |
| 260 | 260 |
| 261 MessageHandler::MessageStatus MessageHandler::HandleNormalMessages() { | |
| 262 // We can only call HandleNormalMessages when this handler is not | |
| 263 // assigned to a thread pool. | |
| 264 MonitorLocker ml(&monitor_); | |
| 265 ASSERT(pool_ == NULL); | |
| 266 #if defined(DEBUG) | |
| 267 CheckAccess(); | |
| 268 #endif | |
| 269 return HandleMessages(true, true); | |
| 270 } | |
| 271 | |
| 272 | |
| 261 MessageHandler::MessageStatus MessageHandler::HandleOOBMessages() { | 273 MessageHandler::MessageStatus MessageHandler::HandleOOBMessages() { |
| 262 if (!oob_message_handling_allowed_) { | 274 if (!oob_message_handling_allowed_) { |
| 263 return kOK; | 275 return kOK; |
| 264 } | 276 } |
| 265 MonitorLocker ml(&monitor_); | 277 MonitorLocker ml(&monitor_); |
| 266 #if defined(DEBUG) | 278 #if defined(DEBUG) |
| 267 CheckAccess(); | 279 CheckAccess(); |
| 268 #endif | 280 #endif |
| 269 return HandleMessages(false, false); | 281 return HandleMessages(false, false); |
| 270 } | 282 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 293 // function. Whenever we reacquire the monitor we *must* process | 305 // function. Whenever we reacquire the monitor we *must* process |
| 294 // all pending OOB messages, or we may miss a request for vm | 306 // all pending OOB messages, or we may miss a request for vm |
| 295 // shutdown. | 307 // shutdown. |
| 296 MonitorLocker ml(&monitor_); | 308 MonitorLocker ml(&monitor_); |
| 297 if (pause_on_start()) { | 309 if (pause_on_start()) { |
| 298 if (!paused_on_start_) { | 310 if (!paused_on_start_) { |
| 299 // Temporarily release the monitor when calling out to | 311 // Temporarily release the monitor when calling out to |
| 300 // NotifyPauseOnStart. This avoids a dead lock that can occur | 312 // NotifyPauseOnStart. This avoids a dead lock that can occur |
| 301 // when this message handler tries to post a message while a | 313 // when this message handler tries to post a message while a |
| 302 // message is being posted to it. | 314 // message is being posted to it. |
| 303 paused_on_start_ = true; | 315 PausedOnStartLocked(true); |
| 304 paused_timestamp_ = OS::GetCurrentTimeMillis(); | |
| 305 monitor_.Exit(); | 316 monitor_.Exit(); |
| 306 NotifyPauseOnStart(); | 317 NotifyPauseOnStart(); |
| 307 monitor_.Enter(); | 318 monitor_.Enter(); |
| 308 } | 319 } |
| 309 // More messages may have come in before we (re)acquired the monitor. | 320 // More messages may have come in before we (re)acquired the monitor. |
| 310 status = HandleMessages(false, false); | 321 status = HandleMessages(false, false); |
| 311 if (ShouldPause(status) && pause_on_start()) { | 322 if (ShouldPause(status) && pause_on_start()) { |
| 312 // Still paused. | 323 // Still paused. |
| 313 ASSERT(oob_queue_->IsEmpty()); | 324 ASSERT(oob_queue_->IsEmpty()); |
| 314 task_ = NULL; // No task in queue. | 325 task_ = NULL; // No task in queue. |
| 315 return; | 326 return; |
| 316 } else { | 327 } else { |
| 317 paused_on_start_ = false; | 328 // Resumed. Clear the resume request of the owning isolate. |
| 318 paused_timestamp_ = -1; | 329 Isolate* owning_isolate = isolate(); |
| 330 if (owning_isolate != NULL) { | |
| 331 owning_isolate->GetAndClearResumeRequest(); | |
| 332 } | |
|
turnidge
2016/02/03 21:33:37
I'm guessing it doesn't work to move this into Set
| |
| 333 PausedOnStartLocked(false); | |
| 319 } | 334 } |
| 320 } | 335 } |
| 321 | 336 |
| 322 if (status == kOK) { | 337 if (status == kOK) { |
| 323 if (start_callback_) { | 338 if (start_callback_) { |
| 324 // Initialize the message handler by running its start function, | 339 // Initialize the message handler by running its start function, |
| 325 // if we have one. For an isolate, this will run the isolate's | 340 // if we have one. For an isolate, this will run the isolate's |
| 326 // main() function. | 341 // main() function. |
| 327 // | 342 // |
| 328 // Release the monitor_ temporarily while we call the start callback. | 343 // Release the monitor_ temporarily while we call the start callback. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 345 if (ShouldPause(status) && pause_on_exit()) { | 360 if (ShouldPause(status) && pause_on_exit()) { |
| 346 if (!paused_on_exit_) { | 361 if (!paused_on_exit_) { |
| 347 if (FLAG_trace_service_pause_events) { | 362 if (FLAG_trace_service_pause_events) { |
| 348 OS::PrintErr("Isolate %s paused before exiting. " | 363 OS::PrintErr("Isolate %s paused before exiting. " |
| 349 "Use the Observatory to release it.\n", name()); | 364 "Use the Observatory to release it.\n", name()); |
| 350 } | 365 } |
| 351 // Temporarily release the monitor when calling out to | 366 // Temporarily release the monitor when calling out to |
| 352 // NotifyPauseOnExit. This avoids a dead lock that can | 367 // NotifyPauseOnExit. This avoids a dead lock that can |
| 353 // occur when this message handler tries to post a message | 368 // occur when this message handler tries to post a message |
| 354 // while a message is being posted to it. | 369 // while a message is being posted to it. |
| 355 paused_on_exit_ = true; | 370 PausedOnExitLocked(true); |
| 356 paused_timestamp_ = OS::GetCurrentTimeMillis(); | |
| 357 monitor_.Exit(); | 371 monitor_.Exit(); |
| 358 NotifyPauseOnExit(); | 372 NotifyPauseOnExit(); |
| 359 monitor_.Enter(); | 373 monitor_.Enter(); |
| 360 | 374 |
| 361 // More messages may have come in while we released the monitor. | 375 // More messages may have come in while we released the monitor. |
| 362 HandleMessages(false, false); | 376 HandleMessages(false, false); |
| 363 } | 377 } |
| 364 if (ShouldPause(status) && pause_on_exit()) { | 378 if (ShouldPause(status) && pause_on_exit()) { |
| 365 // Still paused. | 379 // Still paused. |
| 366 ASSERT(oob_queue_->IsEmpty()); | 380 ASSERT(oob_queue_->IsEmpty()); |
| 367 task_ = NULL; // No task in queue. | 381 task_ = NULL; // No task in queue. |
| 368 return; | 382 return; |
| 369 } else { | 383 } else { |
| 370 paused_on_exit_ = false; | 384 // Resumed. Clear the resume request of the owning isolate. |
| 371 paused_timestamp_ = -1; | 385 Isolate* owning_isolate = isolate(); |
| 386 if (owning_isolate != NULL) { | |
| 387 owning_isolate->GetAndClearResumeRequest(); | |
| 388 } | |
| 389 PausedOnExitLocked(false); | |
| 372 } | 390 } |
| 373 } | 391 } |
| 374 if (FLAG_trace_isolates) { | 392 if (FLAG_trace_isolates) { |
| 375 if (status != kOK && isolate() != NULL) { | 393 if (status != kOK && isolate() != NULL) { |
| 376 const Error& error = | 394 const Error& error = |
| 377 Error::Handle(isolate()->object_store()->sticky_error()); | 395 Error::Handle(isolate()->object_store()->sticky_error()); |
| 378 OS::Print("[-] Stopping message handler (%s):\n" | 396 OS::Print("[-] Stopping message handler (%s):\n" |
| 379 "\thandler: %s\n" | 397 "\thandler: %s\n" |
| 380 "\terror: %s\n", | 398 "\terror: %s\n", |
| 381 MessageStatusString(status), name(), error.ToCString()); | 399 MessageStatusString(status), name(), error.ToCString()); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 | 454 |
| 437 void MessageHandler::decrement_live_ports() { | 455 void MessageHandler::decrement_live_ports() { |
| 438 MonitorLocker ml(&monitor_); | 456 MonitorLocker ml(&monitor_); |
| 439 #if defined(DEBUG) | 457 #if defined(DEBUG) |
| 440 CheckAccess(); | 458 CheckAccess(); |
| 441 #endif | 459 #endif |
| 442 live_ports_--; | 460 live_ports_--; |
| 443 } | 461 } |
| 444 | 462 |
| 445 | 463 |
| 464 void MessageHandler::PausedOnStart(bool v) { | |
| 465 MonitorLocker ml(&monitor_); | |
| 466 PausedOnStartLocked(v); | |
| 467 } | |
| 468 | |
| 469 | |
| 470 void MessageHandler::PausedOnStartLocked(bool v) { | |
| 471 if (v) { | |
| 472 paused_on_start_ = true; | |
| 473 paused_timestamp_ = OS::GetCurrentTimeMillis(); | |
| 474 } else { | |
| 475 paused_on_start_ = false; | |
| 476 paused_timestamp_ = -1; | |
| 477 } | |
| 478 } | |
| 479 | |
| 480 | |
| 481 void MessageHandler::PausedOnExit(bool v) { | |
| 482 MonitorLocker ml(&monitor_); | |
| 483 PausedOnExitLocked(v); | |
| 484 } | |
| 485 | |
| 486 | |
| 487 void MessageHandler::PausedOnExitLocked(bool v) { | |
| 488 if (v) { | |
| 489 paused_on_exit_ = true; | |
| 490 paused_timestamp_ = OS::GetCurrentTimeMillis(); | |
| 491 } else { | |
| 492 paused_on_exit_ = false; | |
| 493 paused_timestamp_ = -1; | |
| 494 } | |
| 495 } | |
| 496 | |
| 497 | |
| 446 MessageHandler::AcquiredQueues::AcquiredQueues() | 498 MessageHandler::AcquiredQueues::AcquiredQueues() |
| 447 : handler_(NULL) { | 499 : handler_(NULL) { |
| 448 } | 500 } |
| 449 | 501 |
| 450 | 502 |
| 451 MessageHandler::AcquiredQueues::~AcquiredQueues() { | 503 MessageHandler::AcquiredQueues::~AcquiredQueues() { |
| 452 Reset(NULL); | 504 Reset(NULL); |
| 453 } | 505 } |
| 454 | 506 |
| 455 | 507 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 471 | 523 |
| 472 | 524 |
| 473 void MessageHandler::AcquireQueues(AcquiredQueues* acquired_queues) { | 525 void MessageHandler::AcquireQueues(AcquiredQueues* acquired_queues) { |
| 474 ASSERT(acquired_queues != NULL); | 526 ASSERT(acquired_queues != NULL); |
| 475 // No double dipping. | 527 // No double dipping. |
| 476 ASSERT(acquired_queues->handler_ == NULL); | 528 ASSERT(acquired_queues->handler_ == NULL); |
| 477 acquired_queues->Reset(this); | 529 acquired_queues->Reset(this); |
| 478 } | 530 } |
| 479 | 531 |
| 480 } // namespace dart | 532 } // namespace dart |
| OLD | NEW |