| 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 uword 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::CompareAndSwapWord( | 18 if (AtomicOperations::CompareAndSwapUint32( |
| 19 reinterpret_cast<uword*>(addr), old_state, 0) != old_state) { | 19 reinterpret_cast<uint32_t*>(addr), 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 thread->set_execution_state(Thread::kThreadInBlockedState); | 32 thread->set_execution_state(Thread::kThreadInBlockedState); |
| 33 thread->EnterSafepoint(); | 33 thread->EnterSafepoint(); |
| 34 Monitor::WaitResult result = monitor_->Wait(millis); | 34 Monitor::WaitResult result = monitor_->Wait(millis); |
| 35 // First try a fast update of the thread state to indicate it is not at a | 35 // First try a fast update of the thread state to indicate it is not at a |
| 36 // safepoint anymore. | 36 // safepoint anymore. |
| 37 uword old_state = Thread::SetAtSafepoint(true, 0); | 37 uint32_t old_state = Thread::SetAtSafepoint(true, 0); |
| 38 uword addr = | 38 uword addr = |
| 39 reinterpret_cast<uword>(thread) + Thread::safepoint_state_offset(); | 39 reinterpret_cast<uword>(thread) + Thread::safepoint_state_offset(); |
| 40 if (AtomicOperations::CompareAndSwapWord( | 40 if (AtomicOperations::CompareAndSwapUint32( |
| 41 reinterpret_cast<uword*>(addr), old_state, 0) != old_state) { | 41 reinterpret_cast<uint32_t*>(addr), old_state, 0) != old_state) { |
| 42 // Fast update failed which means we could potentially be in the middle | 42 // Fast update failed which means we could potentially be in the middle |
| 43 // of a safepoint operation and need to block for it. | 43 // of a safepoint operation and need to block for it. |
| 44 monitor_->Exit(); | 44 monitor_->Exit(); |
| 45 SafepointHandler* handler = thread->isolate()->safepoint_handler(); | 45 SafepointHandler* handler = thread->isolate()->safepoint_handler(); |
| 46 handler->ExitSafepointUsingLock(thread); | 46 handler->ExitSafepointUsingLock(thread); |
| 47 monitor_->Enter(); | 47 monitor_->Enter(); |
| 48 } | 48 } |
| 49 thread->set_execution_state(Thread::kThreadInVM); | 49 thread->set_execution_state(Thread::kThreadInVM); |
| 50 return result; | 50 return result; |
| 51 } | 51 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 | 92 |
| 93 Monitor::WaitResult SafepointMonitorLocker::Wait(int64_t millis) { | 93 Monitor::WaitResult SafepointMonitorLocker::Wait(int64_t millis) { |
| 94 Thread* thread = Thread::Current(); | 94 Thread* thread = Thread::Current(); |
| 95 if (thread != NULL) { | 95 if (thread != NULL) { |
| 96 thread->set_execution_state(Thread::kThreadInBlockedState); | 96 thread->set_execution_state(Thread::kThreadInBlockedState); |
| 97 thread->EnterSafepoint(); | 97 thread->EnterSafepoint(); |
| 98 Monitor::WaitResult result = monitor_->Wait(millis); | 98 Monitor::WaitResult result = monitor_->Wait(millis); |
| 99 // First try a fast update of the thread state to indicate it is not at a | 99 // First try a fast update of the thread state to indicate it is not at a |
| 100 // safepoint anymore. | 100 // safepoint anymore. |
| 101 uword old_state = Thread::SetAtSafepoint(true, 0); | 101 uint32_t old_state = Thread::SetAtSafepoint(true, 0); |
| 102 uword addr = | 102 uword addr = |
| 103 reinterpret_cast<uword>(thread) + Thread::safepoint_state_offset(); | 103 reinterpret_cast<uword>(thread) + Thread::safepoint_state_offset(); |
| 104 if (AtomicOperations::CompareAndSwapWord( | 104 if (AtomicOperations::CompareAndSwapUint32( |
| 105 reinterpret_cast<uword*>(addr), old_state, 0) != old_state) { | 105 reinterpret_cast<uint32_t*>(addr), old_state, 0) != old_state) { |
| 106 // Fast update failed which means we could potentially be in the middle | 106 // Fast update failed which means we could potentially be in the middle |
| 107 // of a safepoint operation and need to block for it. | 107 // of a safepoint operation and need to block for it. |
| 108 monitor_->Exit(); | 108 monitor_->Exit(); |
| 109 SafepointHandler* handler = thread->isolate()->safepoint_handler(); | 109 SafepointHandler* handler = thread->isolate()->safepoint_handler(); |
| 110 handler->ExitSafepointUsingLock(thread); | 110 handler->ExitSafepointUsingLock(thread); |
| 111 monitor_->Enter(); | 111 monitor_->Enter(); |
| 112 } | 112 } |
| 113 thread->set_execution_state(Thread::kThreadInVM); | 113 thread->set_execution_state(Thread::kThreadInVM); |
| 114 return result; | 114 return result; |
| 115 } else { | 115 } else { |
| 116 return monitor_->Wait(millis); | 116 return monitor_->Wait(millis); |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 } // namespace dart | 120 } // namespace dart |
| OLD | NEW |