| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/lockers.h" | 6 #include "vm/lockers.h" |
| 7 #include "vm/safepoint.h" | 7 #include "vm/safepoint.h" |
| 8 | 8 |
| 9 namespace dart { | 9 namespace dart { |
| 10 | 10 |
| 11 | 11 |
| 12 static void updateThreadState(Thread* thread) { | 12 static void updateThreadState(Thread* thread) { |
| 13 // First try a fast update of the thread state to indicate it is not at a | 13 // First try a fast update of the thread state to indicate it is not at a |
| 14 // safepoint anymore. | 14 // safepoint anymore. |
| 15 uint32_t old_state = Thread::SetAtSafepoint(true, 0); | 15 uint32_t old_state = Thread::SetAtSafepoint(true, 0); |
| 16 uword addr = | 16 uword addr = |
| 17 reinterpret_cast<uword>(thread) + Thread::safepoint_state_offset(); | 17 reinterpret_cast<uword>(thread) + Thread::safepoint_state_offset(); |
| 18 if (AtomicOperations::CompareAndSwapUint32( | 18 if (AtomicOperations::CompareAndSwapUint32(reinterpret_cast<uint32_t*>(addr), |
| 19 reinterpret_cast<uint32_t*>(addr), old_state, 0) != old_state) { | 19 old_state, 0) != old_state) { |
| 20 // Fast update failed which means we could potentially be in the middle | 20 // Fast update failed which means we could potentially be in the middle |
| 21 // of a safepoint operation and need to block for it. | 21 // of a safepoint operation and need to block for it. |
| 22 SafepointHandler* handler = thread->isolate()->safepoint_handler(); | 22 SafepointHandler* handler = thread->isolate()->safepoint_handler(); |
| 23 handler->ExitSafepointUsingLock(thread); | 23 handler->ExitSafepointUsingLock(thread); |
| 24 } | 24 } |
| 25 thread->set_execution_state(Thread::kThreadInVM); | 25 thread->set_execution_state(Thread::kThreadInVM); |
| 26 } | 26 } |
| 27 | 27 |
| 28 | 28 |
| 29 Monitor::WaitResult MonitorLocker::WaitWithSafepointCheck(Thread* thread, | 29 Monitor::WaitResult MonitorLocker::WaitWithSafepointCheck(Thread* thread, |
| 30 int64_t millis) { | 30 int64_t millis) { |
| 31 ASSERT(thread == Thread::Current()); | 31 ASSERT(thread == Thread::Current()); |
| 32 ASSERT(thread->execution_state() == Thread::kThreadInVM); | 32 ASSERT(thread->execution_state() == Thread::kThreadInVM); |
| 33 thread->set_execution_state(Thread::kThreadInBlockedState); | 33 thread->set_execution_state(Thread::kThreadInBlockedState); |
| 34 thread->EnterSafepoint(); | 34 thread->EnterSafepoint(); |
| 35 Monitor::WaitResult result = monitor_->Wait(millis); | 35 Monitor::WaitResult result = monitor_->Wait(millis); |
| 36 // First try a fast update of the thread state to indicate it is not at a | 36 // First try a fast update of the thread state to indicate it is not at a |
| 37 // safepoint anymore. | 37 // safepoint anymore. |
| 38 uint32_t old_state = Thread::SetAtSafepoint(true, 0); | 38 uint32_t old_state = Thread::SetAtSafepoint(true, 0); |
| 39 uword addr = | 39 uword addr = |
| 40 reinterpret_cast<uword>(thread) + Thread::safepoint_state_offset(); | 40 reinterpret_cast<uword>(thread) + Thread::safepoint_state_offset(); |
| 41 if (AtomicOperations::CompareAndSwapUint32( | 41 if (AtomicOperations::CompareAndSwapUint32(reinterpret_cast<uint32_t*>(addr), |
| 42 reinterpret_cast<uint32_t*>(addr), old_state, 0) != old_state) { | 42 old_state, 0) != old_state) { |
| 43 // Fast update failed which means we could potentially be in the middle | 43 // Fast update failed which means we could potentially be in the middle |
| 44 // of a safepoint operation and need to block for it. | 44 // of a safepoint operation and need to block for it. |
| 45 monitor_->Exit(); | 45 monitor_->Exit(); |
| 46 SafepointHandler* handler = thread->isolate()->safepoint_handler(); | 46 SafepointHandler* handler = thread->isolate()->safepoint_handler(); |
| 47 handler->ExitSafepointUsingLock(thread); | 47 handler->ExitSafepointUsingLock(thread); |
| 48 monitor_->Enter(); | 48 monitor_->Enter(); |
| 49 } | 49 } |
| 50 thread->set_execution_state(Thread::kThreadInVM); | 50 thread->set_execution_state(Thread::kThreadInVM); |
| 51 return result; | 51 return result; |
| 52 } | 52 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 monitor_->Enter(); | 112 monitor_->Enter(); |
| 113 } | 113 } |
| 114 thread->set_execution_state(Thread::kThreadInVM); | 114 thread->set_execution_state(Thread::kThreadInVM); |
| 115 return result; | 115 return result; |
| 116 } else { | 116 } else { |
| 117 return monitor_->Wait(millis); | 117 return monitor_->Wait(millis); |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 } // namespace dart | 121 } // namespace dart |
| OLD | NEW |