| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "api.h" | 30 #include "api.h" |
| 31 #include "bootstrapper.h" |
| 31 #include "debug.h" | 32 #include "debug.h" |
| 32 #include "execution.h" | 33 #include "execution.h" |
| 33 #include "v8threads.h" | 34 #include "v8threads.h" |
| 34 #include "regexp-stack.h" | 35 #include "regexp-stack.h" |
| 35 | 36 |
| 36 namespace v8 { | 37 namespace v8 { |
| 37 | 38 |
| 38 static internal::Thread::LocalStorageKey thread_state_key = | 39 static internal::Thread::LocalStorageKey thread_state_key = |
| 39 internal::Thread::CreateThreadLocalKey(); | 40 internal::Thread::CreateThreadLocalKey(); |
| 40 | 41 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // had prepared back in the free list, since we didn't need it after all. | 113 // had prepared back in the free list, since we didn't need it after all. |
| 113 if (lazily_archived_thread_.IsSelf()) { | 114 if (lazily_archived_thread_.IsSelf()) { |
| 114 lazily_archived_thread_.Initialize(ThreadHandle::INVALID); | 115 lazily_archived_thread_.Initialize(ThreadHandle::INVALID); |
| 115 ASSERT(Thread::GetThreadLocal(thread_state_key) == | 116 ASSERT(Thread::GetThreadLocal(thread_state_key) == |
| 116 lazily_archived_thread_state_); | 117 lazily_archived_thread_state_); |
| 117 lazily_archived_thread_state_->LinkInto(ThreadState::FREE_LIST); | 118 lazily_archived_thread_state_->LinkInto(ThreadState::FREE_LIST); |
| 118 lazily_archived_thread_state_ = NULL; | 119 lazily_archived_thread_state_ = NULL; |
| 119 Thread::SetThreadLocal(thread_state_key, NULL); | 120 Thread::SetThreadLocal(thread_state_key, NULL); |
| 120 return true; | 121 return true; |
| 121 } | 122 } |
| 123 |
| 124 // Make sure that the preemption thread cannot modify the thread state while |
| 125 // it is being archived or restored. |
| 126 ExecutionAccess access; |
| 127 |
| 122 // If there is another thread that was lazily archived then we have to really | 128 // If there is another thread that was lazily archived then we have to really |
| 123 // archive it now. | 129 // archive it now. |
| 124 if (lazily_archived_thread_.IsValid()) { | 130 if (lazily_archived_thread_.IsValid()) { |
| 125 EagerlyArchiveThread(); | 131 EagerlyArchiveThread(); |
| 126 } | 132 } |
| 127 ThreadState* state = | 133 ThreadState* state = |
| 128 reinterpret_cast<ThreadState*>(Thread::GetThreadLocal(thread_state_key)); | 134 reinterpret_cast<ThreadState*>(Thread::GetThreadLocal(thread_state_key)); |
| 129 if (state == NULL) { | 135 if (state == NULL) { |
| 130 return false; | 136 return false; |
| 131 } | 137 } |
| 132 char* from = state->data(); | 138 char* from = state->data(); |
| 133 from = HandleScopeImplementer::RestoreThread(from); | 139 from = HandleScopeImplementer::RestoreThread(from); |
| 134 from = Top::RestoreThread(from); | 140 from = Top::RestoreThread(from); |
| 135 from = Debug::RestoreDebug(from); | 141 from = Debug::RestoreDebug(from); |
| 136 from = StackGuard::RestoreStackGuard(from); | 142 from = StackGuard::RestoreStackGuard(from); |
| 137 from = RegExpStack::RestoreStack(from); | 143 from = RegExpStack::RestoreStack(from); |
| 144 from = Bootstrapper::RestoreState(from); |
| 138 Thread::SetThreadLocal(thread_state_key, NULL); | 145 Thread::SetThreadLocal(thread_state_key, NULL); |
| 139 state->Unlink(); | 146 state->Unlink(); |
| 140 state->LinkInto(ThreadState::FREE_LIST); | 147 state->LinkInto(ThreadState::FREE_LIST); |
| 141 return true; | 148 return true; |
| 142 } | 149 } |
| 143 | 150 |
| 144 | 151 |
| 145 void ThreadManager::Lock() { | 152 void ThreadManager::Lock() { |
| 146 mutex_->Lock(); | 153 mutex_->Lock(); |
| 147 mutex_owner_.Initialize(ThreadHandle::SELF); | 154 mutex_owner_.Initialize(ThreadHandle::SELF); |
| 148 ASSERT(IsLockedByCurrentThread()); | 155 ASSERT(IsLockedByCurrentThread()); |
| 149 } | 156 } |
| 150 | 157 |
| 151 | 158 |
| 152 void ThreadManager::Unlock() { | 159 void ThreadManager::Unlock() { |
| 153 mutex_owner_.Initialize(ThreadHandle::INVALID); | 160 mutex_owner_.Initialize(ThreadHandle::INVALID); |
| 154 mutex_->Unlock(); | 161 mutex_->Unlock(); |
| 155 } | 162 } |
| 156 | 163 |
| 157 | 164 |
| 158 static int ArchiveSpacePerThread() { | 165 static int ArchiveSpacePerThread() { |
| 159 return HandleScopeImplementer::ArchiveSpacePerThread() + | 166 return HandleScopeImplementer::ArchiveSpacePerThread() + |
| 160 Top::ArchiveSpacePerThread() + | 167 Top::ArchiveSpacePerThread() + |
| 161 Debug::ArchiveSpacePerThread() + | 168 Debug::ArchiveSpacePerThread() + |
| 162 StackGuard::ArchiveSpacePerThread() + | 169 StackGuard::ArchiveSpacePerThread() + |
| 163 RegExpStack::ArchiveSpacePerThread(); | 170 RegExpStack::ArchiveSpacePerThread() + |
| 171 Bootstrapper::ArchiveSpacePerThread(); |
| 164 } | 172 } |
| 165 | 173 |
| 166 | 174 |
| 167 ThreadState* ThreadState::free_anchor_ = new ThreadState(); | 175 ThreadState* ThreadState::free_anchor_ = new ThreadState(); |
| 168 ThreadState* ThreadState::in_use_anchor_ = new ThreadState(); | 176 ThreadState* ThreadState::in_use_anchor_ = new ThreadState(); |
| 169 | 177 |
| 170 | 178 |
| 171 ThreadState::ThreadState() : next_(this), previous_(this) { | 179 ThreadState::ThreadState() : next_(this), previous_(this) { |
| 172 } | 180 } |
| 173 | 181 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 243 |
| 236 void ThreadManager::EagerlyArchiveThread() { | 244 void ThreadManager::EagerlyArchiveThread() { |
| 237 ThreadState* state = lazily_archived_thread_state_; | 245 ThreadState* state = lazily_archived_thread_state_; |
| 238 state->LinkInto(ThreadState::IN_USE_LIST); | 246 state->LinkInto(ThreadState::IN_USE_LIST); |
| 239 char* to = state->data(); | 247 char* to = state->data(); |
| 240 to = HandleScopeImplementer::ArchiveThread(to); | 248 to = HandleScopeImplementer::ArchiveThread(to); |
| 241 to = Top::ArchiveThread(to); | 249 to = Top::ArchiveThread(to); |
| 242 to = Debug::ArchiveDebug(to); | 250 to = Debug::ArchiveDebug(to); |
| 243 to = StackGuard::ArchiveStackGuard(to); | 251 to = StackGuard::ArchiveStackGuard(to); |
| 244 to = RegExpStack::ArchiveStack(to); | 252 to = RegExpStack::ArchiveStack(to); |
| 253 to = Bootstrapper::ArchiveState(to); |
| 245 lazily_archived_thread_.Initialize(ThreadHandle::INVALID); | 254 lazily_archived_thread_.Initialize(ThreadHandle::INVALID); |
| 246 lazily_archived_thread_state_ = NULL; | 255 lazily_archived_thread_state_ = NULL; |
| 247 } | 256 } |
| 248 | 257 |
| 249 | 258 |
| 250 void ThreadManager::Iterate(ObjectVisitor* v) { | 259 void ThreadManager::Iterate(ObjectVisitor* v) { |
| 251 // Expecting no threads during serialization/deserialization | 260 // Expecting no threads during serialization/deserialization |
| 252 for (ThreadState* state = ThreadState::FirstInUse(); | 261 for (ThreadState* state = ThreadState::FirstInUse(); |
| 253 state != NULL; | 262 state != NULL; |
| 254 state = state->Next()) { | 263 state = state->Next()) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 // Acknowledge the preemption by the receiving thread. | 346 // Acknowledge the preemption by the receiving thread. |
| 338 void ContextSwitcher::PreemptionReceived() { | 347 void ContextSwitcher::PreemptionReceived() { |
| 339 ASSERT(Locker::IsLocked()); | 348 ASSERT(Locker::IsLocked()); |
| 340 // There is currently no accounting being done for this. But could be in the | 349 // There is currently no accounting being done for this. But could be in the |
| 341 // future, which is why we leave this in. | 350 // future, which is why we leave this in. |
| 342 } | 351 } |
| 343 | 352 |
| 344 | 353 |
| 345 } // namespace internal | 354 } // namespace internal |
| 346 } // namespace v8 | 355 } // namespace v8 |
| OLD | NEW |