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 "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/text_buffer.h" | 10 #include "platform/text_buffer.h" |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 api_state_(NULL), | 767 api_state_(NULL), |
768 debugger_(NULL), | 768 debugger_(NULL), |
769 resume_request_(false), | 769 resume_request_(false), |
770 last_resume_timestamp_(OS::GetCurrentTimeMillis()), | 770 last_resume_timestamp_(OS::GetCurrentTimeMillis()), |
771 has_compiled_code_(false), | 771 has_compiled_code_(false), |
772 flags_(), | 772 flags_(), |
773 random_(), | 773 random_(), |
774 simulator_(NULL), | 774 simulator_(NULL), |
775 mutex_(new Mutex()), | 775 mutex_(new Mutex()), |
776 saved_stack_limit_(0), | 776 saved_stack_limit_(0), |
| 777 deferred_interrupts_mask_(0), |
| 778 deferred_interrupts_(0), |
777 stack_overflow_flags_(0), | 779 stack_overflow_flags_(0), |
778 stack_overflow_count_(0), | 780 stack_overflow_count_(0), |
779 message_handler_(NULL), | 781 message_handler_(NULL), |
780 spawn_state_(NULL), | 782 spawn_state_(NULL), |
781 is_runnable_(false), | 783 is_runnable_(false), |
782 gc_prologue_callback_(NULL), | 784 gc_prologue_callback_(NULL), |
783 gc_epilogue_callback_(NULL), | 785 gc_epilogue_callback_(NULL), |
784 defer_finalization_count_(0), | 786 defer_finalization_count_(0), |
785 deopt_context_(NULL), | 787 deopt_context_(NULL), |
786 compiler_stats_(NULL), | 788 compiler_stats_(NULL), |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 } | 1024 } |
1023 saved_stack_limit_ = limit; | 1025 saved_stack_limit_ = limit; |
1024 } | 1026 } |
1025 | 1027 |
1026 | 1028 |
1027 void Isolate::ClearStackLimit() { | 1029 void Isolate::ClearStackLimit() { |
1028 SetStackLimit(~static_cast<uword>(0)); | 1030 SetStackLimit(~static_cast<uword>(0)); |
1029 } | 1031 } |
1030 | 1032 |
1031 | 1033 |
1032 void Isolate::ScheduleInterrupts(uword interrupt_bits) { | |
1033 MutexLocker ml(mutex_); | |
1034 ASSERT((interrupt_bits & ~kInterruptsMask) == 0); // Must fit in mask. | |
1035 if (stack_limit_ == saved_stack_limit_) { | |
1036 stack_limit_ = (~static_cast<uword>(0)) & ~kInterruptsMask; | |
1037 } | |
1038 stack_limit_ |= interrupt_bits; | |
1039 } | |
1040 | |
1041 | |
1042 void Isolate::DoneLoading() { | 1034 void Isolate::DoneLoading() { |
1043 GrowableObjectArray& libs = GrowableObjectArray::Handle(current_zone(), | 1035 GrowableObjectArray& libs = GrowableObjectArray::Handle(current_zone(), |
1044 object_store()->libraries()); | 1036 object_store()->libraries()); |
1045 Library& lib = Library::Handle(current_zone()); | 1037 Library& lib = Library::Handle(current_zone()); |
1046 intptr_t num_libs = libs.Length(); | 1038 intptr_t num_libs = libs.Length(); |
1047 for (intptr_t i = 0; i < num_libs; i++) { | 1039 for (intptr_t i = 0; i < num_libs; i++) { |
1048 lib ^= libs.At(i); | 1040 lib ^= libs.At(i); |
1049 // If this library was loaded with Dart_LoadLibrary, it was marked | 1041 // If this library was loaded with Dart_LoadLibrary, it was marked |
1050 // as 'load in progres'. Set the status to 'loaded'. | 1042 // as 'load in progres'. Set the status to 'loaded'. |
1051 if (lib.LoadInProgress()) { | 1043 if (lib.LoadInProgress()) { |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1432 | 1424 |
1433 | 1425 |
1434 void Isolate::Run() { | 1426 void Isolate::Run() { |
1435 message_handler()->Run(Dart::thread_pool(), | 1427 message_handler()->Run(Dart::thread_pool(), |
1436 RunIsolate, | 1428 RunIsolate, |
1437 ShutdownIsolate, | 1429 ShutdownIsolate, |
1438 reinterpret_cast<uword>(this)); | 1430 reinterpret_cast<uword>(this)); |
1439 } | 1431 } |
1440 | 1432 |
1441 | 1433 |
| 1434 void Isolate::ScheduleInterrupts(uword interrupt_bits) { |
| 1435 MutexLocker ml(mutex_); |
| 1436 ASSERT((interrupt_bits & ~kInterruptsMask) == 0); // Must fit in mask. |
| 1437 |
| 1438 // Check to see if any of the requested interrupts should be deferred. |
| 1439 uword defer_bits = interrupt_bits & deferred_interrupts_mask_; |
| 1440 if (defer_bits != 0) { |
| 1441 deferred_interrupts_ |= defer_bits; |
| 1442 interrupt_bits &= ~deferred_interrupts_mask_; |
| 1443 if (interrupt_bits == 0) { |
| 1444 return; |
| 1445 } |
| 1446 } |
| 1447 |
| 1448 if (stack_limit_ == saved_stack_limit_) { |
| 1449 stack_limit_ = (~static_cast<uword>(0)) & ~kInterruptsMask; |
| 1450 } |
| 1451 stack_limit_ |= interrupt_bits; |
| 1452 } |
| 1453 |
| 1454 |
1442 uword Isolate::GetAndClearInterrupts() { | 1455 uword Isolate::GetAndClearInterrupts() { |
1443 MutexLocker ml(mutex_); | 1456 MutexLocker ml(mutex_); |
1444 if (stack_limit_ == saved_stack_limit_) { | 1457 if (stack_limit_ == saved_stack_limit_) { |
1445 return 0; // No interrupt was requested. | 1458 return 0; // No interrupt was requested. |
1446 } | 1459 } |
1447 uword interrupt_bits = stack_limit_ & kInterruptsMask; | 1460 uword interrupt_bits = stack_limit_ & kInterruptsMask; |
1448 stack_limit_ = saved_stack_limit_; | 1461 stack_limit_ = saved_stack_limit_; |
1449 return interrupt_bits; | 1462 return interrupt_bits; |
1450 } | 1463 } |
1451 | 1464 |
1452 | 1465 |
| 1466 void Isolate::DeferMessageInterrupts() { |
| 1467 MutexLocker ml(mutex_); |
| 1468 ASSERT(deferred_interrupts_mask_ == 0); |
| 1469 deferred_interrupts_mask_ = kMessageInterrupt; |
| 1470 |
| 1471 if (stack_limit_ != saved_stack_limit_) { |
| 1472 // Defer any interrupts which are currently pending. |
| 1473 deferred_interrupts_ = stack_limit_ & deferred_interrupts_mask_; |
| 1474 |
| 1475 // Clear deferrable interrupts, if present. |
| 1476 stack_limit_ &= ~deferred_interrupts_mask_; |
| 1477 |
| 1478 if ((stack_limit_ & kInterruptsMask) == 0) { |
| 1479 // No other pending interrupts. Restore normal stack limit. |
| 1480 stack_limit_ = saved_stack_limit_; |
| 1481 } |
| 1482 } |
| 1483 } |
| 1484 |
| 1485 |
| 1486 void Isolate::RestoreMessageInterrupts() { |
| 1487 MutexLocker ml(mutex_); |
| 1488 ASSERT(deferred_interrupts_mask_ == kMessageInterrupt); |
| 1489 deferred_interrupts_mask_ = 0; |
| 1490 if (deferred_interrupts_ != 0) { |
| 1491 if (stack_limit_ == saved_stack_limit_) { |
| 1492 stack_limit_ = (~static_cast<uword>(0)) & ~kInterruptsMask; |
| 1493 } |
| 1494 stack_limit_ |= deferred_interrupts_; |
| 1495 deferred_interrupts_ = 0; |
| 1496 } |
| 1497 } |
| 1498 |
| 1499 |
1453 RawError* Isolate::HandleInterrupts() { | 1500 RawError* Isolate::HandleInterrupts() { |
1454 uword interrupt_bits = GetAndClearInterrupts(); | 1501 uword interrupt_bits = GetAndClearInterrupts(); |
1455 if ((interrupt_bits & kVMInterrupt) != 0) { | 1502 if ((interrupt_bits & kVMInterrupt) != 0) { |
1456 if (store_buffer()->Overflowed()) { | 1503 if (store_buffer()->Overflowed()) { |
1457 if (FLAG_verbose_gc) { | 1504 if (FLAG_verbose_gc) { |
1458 OS::PrintErr("Scavenge scheduled by store buffer overflow.\n"); | 1505 OS::PrintErr("Scavenge scheduled by store buffer overflow.\n"); |
1459 } | 1506 } |
1460 heap()->CollectGarbage(Heap::kNew); | 1507 heap()->CollectGarbage(Heap::kNew); |
1461 } | 1508 } |
1462 } | 1509 } |
(...skipping 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2630 void IsolateSpawnState::DecrementSpawnCount() { | 2677 void IsolateSpawnState::DecrementSpawnCount() { |
2631 ASSERT(spawn_count_monitor_ != NULL); | 2678 ASSERT(spawn_count_monitor_ != NULL); |
2632 ASSERT(spawn_count_ != NULL); | 2679 ASSERT(spawn_count_ != NULL); |
2633 MonitorLocker ml(spawn_count_monitor_); | 2680 MonitorLocker ml(spawn_count_monitor_); |
2634 ASSERT(*spawn_count_ > 0); | 2681 ASSERT(*spawn_count_ > 0); |
2635 *spawn_count_ = *spawn_count_ - 1; | 2682 *spawn_count_ = *spawn_count_ - 1; |
2636 ml.Notify(); | 2683 ml.Notify(); |
2637 } | 2684 } |
2638 | 2685 |
2639 } // namespace dart | 2686 } // namespace dart |
OLD | NEW |