| OLD | NEW |
| 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 "vm/code_observers.h" | 10 #include "vm/code_observers.h" |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 Simulator* sim = Simulator::Current(); // May allocate a simulator. | 593 Simulator* sim = Simulator::Current(); // May allocate a simulator. |
| 594 ASSERT(simulator() == sim); // This isolate's simulator is the current one. | 594 ASSERT(simulator() == sim); // This isolate's simulator is the current one. |
| 595 stack_top_value = sim->StackTop(); | 595 stack_top_value = sim->StackTop(); |
| 596 // The overflow area is accounted for by the simulator. | 596 // The overflow area is accounted for by the simulator. |
| 597 #endif | 597 #endif |
| 598 SetStackLimit(stack_top_value - GetSpecifiedStackSize()); | 598 SetStackLimit(stack_top_value - GetSpecifiedStackSize()); |
| 599 } | 599 } |
| 600 | 600 |
| 601 | 601 |
| 602 void Isolate::SetStackLimit(uword limit) { | 602 void Isolate::SetStackLimit(uword limit) { |
| 603 // The isolate setting the stack limit is not necessarily the isolate which |
| 604 // the stack limit is being set on. |
| 603 MutexLocker ml(mutex_); | 605 MutexLocker ml(mutex_); |
| 604 if (stack_limit_ == saved_stack_limit_) { | 606 if (stack_limit_ == saved_stack_limit_) { |
| 605 // No interrupt pending, set stack_limit_ too. | 607 // No interrupt pending, set stack_limit_ too. |
| 606 stack_limit_ = limit; | 608 stack_limit_ = limit; |
| 607 } | 609 } |
| 608 saved_stack_limit_ = limit; | 610 saved_stack_limit_ = limit; |
| 609 } | 611 } |
| 610 | 612 |
| 611 | 613 |
| 612 bool Isolate::GetStackBounds(uword* lower, uword* upper) { | 614 bool Isolate::GetStackBounds(uword* lower, uword* upper) { |
| 613 uword stack_lower = stack_limit(); | 615 uword stack_lower = stack_limit(); |
| 614 if (stack_lower == kUwordMax) { | 616 if (stack_lower == kUwordMax) { |
| 615 stack_lower = saved_stack_limit(); | 617 stack_lower = saved_stack_limit(); |
| 616 } | 618 } |
| 617 if (stack_lower == kUwordMax) { | 619 if (stack_lower == kUwordMax) { |
| 618 return false; | 620 return false; |
| 619 } | 621 } |
| 620 uword stack_upper = stack_lower + GetSpecifiedStackSize(); | 622 uword stack_upper = stack_lower + GetSpecifiedStackSize(); |
| 621 *lower = stack_lower; | 623 *lower = stack_lower; |
| 622 *upper = stack_upper; | 624 *upper = stack_upper; |
| 623 return true; | 625 return true; |
| 624 } | 626 } |
| 625 | 627 |
| 626 | 628 |
| 627 void Isolate::ScheduleInterrupts(uword interrupt_bits) { | 629 void Isolate::ScheduleInterrupts(uword interrupt_bits) { |
| 628 // TODO(turnidge): Can't use MutexLocker here because MutexLocker is | 630 MutexLocker ml(mutex_); |
| 629 // a StackResource, which requires a current isolate. Should | |
| 630 // MutexLocker really be a StackResource? | |
| 631 mutex_->Lock(); | |
| 632 ASSERT((interrupt_bits & ~kInterruptsMask) == 0); // Must fit in mask. | 631 ASSERT((interrupt_bits & ~kInterruptsMask) == 0); // Must fit in mask. |
| 633 if (stack_limit_ == saved_stack_limit_) { | 632 if (stack_limit_ == saved_stack_limit_) { |
| 634 stack_limit_ = (~static_cast<uword>(0)) & ~kInterruptsMask; | 633 stack_limit_ = (~static_cast<uword>(0)) & ~kInterruptsMask; |
| 635 } | 634 } |
| 636 stack_limit_ |= interrupt_bits; | 635 stack_limit_ |= interrupt_bits; |
| 637 mutex_->Unlock(); | |
| 638 } | 636 } |
| 639 | 637 |
| 640 | 638 |
| 641 void Isolate::DoneLoading() { | 639 void Isolate::DoneLoading() { |
| 642 GrowableObjectArray& libs = | 640 GrowableObjectArray& libs = |
| 643 GrowableObjectArray::Handle(this, object_store()->libraries()); | 641 GrowableObjectArray::Handle(this, object_store()->libraries()); |
| 644 Library& lib = Library::Handle(this); | 642 Library& lib = Library::Handle(this); |
| 645 intptr_t num_libs = libs.Length(); | 643 intptr_t num_libs = libs.Length(); |
| 646 for (intptr_t i = 0; i < num_libs; i++) { | 644 for (intptr_t i = 0; i < num_libs; i++) { |
| 647 lib ^= libs.At(i); | 645 lib ^= libs.At(i); |
| 648 // If this library was loaded with Dart_LoadLibrary, it was marked | 646 // If this library was loaded with Dart_LoadLibrary, it was marked |
| 649 // as 'load in progres'. Set the status to 'loaded'. | 647 // as 'load in progres'. Set the status to 'loaded'. |
| 650 if (lib.LoadInProgress()) { | 648 if (lib.LoadInProgress()) { |
| 651 lib.SetLoaded(); | 649 lib.SetLoaded(); |
| 652 } | 650 } |
| 653 } | 651 } |
| 654 } | 652 } |
| 655 | 653 |
| 656 | 654 |
| 657 bool Isolate::MakeRunnable() { | 655 bool Isolate::MakeRunnable() { |
| 658 ASSERT(Isolate::Current() == NULL); | 656 ASSERT(Isolate::Current() == NULL); |
| 659 // Can't use MutexLocker here because MutexLocker is | 657 MutexLocker ml(mutex_); |
| 660 // a StackResource, which requires a current isolate. | |
| 661 mutex_->Lock(); | |
| 662 // Check if we are in a valid state to make the isolate runnable. | 658 // Check if we are in a valid state to make the isolate runnable. |
| 663 if (is_runnable_ == true) { | 659 if (is_runnable_ == true) { |
| 664 mutex_->Unlock(); | |
| 665 return false; // Already runnable. | 660 return false; // Already runnable. |
| 666 } | 661 } |
| 667 // Set the isolate as runnable and if we are being spawned schedule | 662 // Set the isolate as runnable and if we are being spawned schedule |
| 668 // isolate on thread pool for execution. | 663 // isolate on thread pool for execution. |
| 669 is_runnable_ = true; | 664 is_runnable_ = true; |
| 670 if (!Service::IsServiceIsolate(this)) { | 665 if (!Service::IsServiceIsolate(this)) { |
| 671 message_handler()->set_pause_on_start(FLAG_pause_isolates_on_start); | 666 message_handler()->set_pause_on_start(FLAG_pause_isolates_on_start); |
| 672 message_handler()->set_pause_on_exit(FLAG_pause_isolates_on_exit); | 667 message_handler()->set_pause_on_exit(FLAG_pause_isolates_on_exit); |
| 673 } | 668 } |
| 674 IsolateSpawnState* state = spawn_state(); | 669 IsolateSpawnState* state = spawn_state(); |
| 675 if (state != NULL) { | 670 if (state != NULL) { |
| 676 ASSERT(this == state->isolate()); | 671 ASSERT(this == state->isolate()); |
| 677 Run(); | 672 Run(); |
| 678 } | 673 } |
| 679 mutex_->Unlock(); | |
| 680 return true; | 674 return true; |
| 681 } | 675 } |
| 682 | 676 |
| 683 | 677 |
| 684 bool Isolate::VerifyPauseCapability(const Capability& capability) const { | 678 bool Isolate::VerifyPauseCapability(const Capability& capability) const { |
| 685 return !capability.IsNull() && (pause_capability() == capability.Id()); | 679 return !capability.IsNull() && (pause_capability() == capability.Id()); |
| 686 } | 680 } |
| 687 | 681 |
| 688 | 682 |
| 689 bool Isolate::AddResumeCapability(const Capability& capability) { | 683 bool Isolate::AddResumeCapability(const Capability& capability) { |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1407 return func.raw(); | 1401 return func.raw(); |
| 1408 } | 1402 } |
| 1409 | 1403 |
| 1410 | 1404 |
| 1411 void IsolateSpawnState::Cleanup() { | 1405 void IsolateSpawnState::Cleanup() { |
| 1412 SwitchIsolateScope switch_scope(I); | 1406 SwitchIsolateScope switch_scope(I); |
| 1413 Dart::ShutdownIsolate(); | 1407 Dart::ShutdownIsolate(); |
| 1414 } | 1408 } |
| 1415 | 1409 |
| 1416 } // namespace dart | 1410 } // namespace dart |
| OLD | NEW |