Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: src/v8threads.cc

Issue 18842: Experimental: periodic merge of the bleeding_edge branch to the... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/toiger/
Patch Set: Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/v8threads.h ('k') | src/zone.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
42
43 // Track whether this V8 instance has ever called v8::Locker. This allows the
44 // API code to verify that the lock is always held when V8 is being entered.
45 bool Locker::active_ = false;
46
47
41 // Constructor for the Locker object. Once the Locker is constructed the 48 // Constructor for the Locker object. Once the Locker is constructed the
42 // current thread will be guaranteed to have the big V8 lock. 49 // current thread will be guaranteed to have the big V8 lock.
43 Locker::Locker() : has_lock_(false), top_level_(true) { 50 Locker::Locker() : has_lock_(false), top_level_(true) {
51 // Record that the Locker has been used at least once.
52 active_ = true;
44 // Get the big lock if necessary. 53 // Get the big lock if necessary.
45 if (!internal::ThreadManager::IsLockedByCurrentThread()) { 54 if (!internal::ThreadManager::IsLockedByCurrentThread()) {
46 internal::ThreadManager::Lock(); 55 internal::ThreadManager::Lock();
47 has_lock_ = true; 56 has_lock_ = true;
48 // This may be a locker within an unlocker in which case we have to 57 // This may be a locker within an unlocker in which case we have to
49 // get the saved state for this thread and restore it. 58 // get the saved state for this thread and restore it.
50 if (internal::ThreadManager::RestoreThread()) { 59 if (internal::ThreadManager::RestoreThread()) {
51 top_level_ = false; 60 top_level_ = false;
52 } 61 }
53 } 62 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // 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.
105 if (lazily_archived_thread_.IsSelf()) { 114 if (lazily_archived_thread_.IsSelf()) {
106 lazily_archived_thread_.Initialize(ThreadHandle::INVALID); 115 lazily_archived_thread_.Initialize(ThreadHandle::INVALID);
107 ASSERT(Thread::GetThreadLocal(thread_state_key) == 116 ASSERT(Thread::GetThreadLocal(thread_state_key) ==
108 lazily_archived_thread_state_); 117 lazily_archived_thread_state_);
109 lazily_archived_thread_state_->LinkInto(ThreadState::FREE_LIST); 118 lazily_archived_thread_state_->LinkInto(ThreadState::FREE_LIST);
110 lazily_archived_thread_state_ = NULL; 119 lazily_archived_thread_state_ = NULL;
111 Thread::SetThreadLocal(thread_state_key, NULL); 120 Thread::SetThreadLocal(thread_state_key, NULL);
112 return true; 121 return true;
113 } 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
114 // 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
115 // archive it now. 129 // archive it now.
116 if (lazily_archived_thread_.IsValid()) { 130 if (lazily_archived_thread_.IsValid()) {
117 EagerlyArchiveThread(); 131 EagerlyArchiveThread();
118 } 132 }
119 ThreadState* state = 133 ThreadState* state =
120 reinterpret_cast<ThreadState*>(Thread::GetThreadLocal(thread_state_key)); 134 reinterpret_cast<ThreadState*>(Thread::GetThreadLocal(thread_state_key));
121 if (state == NULL) { 135 if (state == NULL) {
122 return false; 136 return false;
123 } 137 }
124 char* from = state->data(); 138 char* from = state->data();
125 from = HandleScopeImplementer::RestoreThread(from); 139 from = HandleScopeImplementer::RestoreThread(from);
126 from = Top::RestoreThread(from); 140 from = Top::RestoreThread(from);
127 from = Debug::RestoreDebug(from); 141 from = Debug::RestoreDebug(from);
128 from = StackGuard::RestoreStackGuard(from); 142 from = StackGuard::RestoreStackGuard(from);
129 from = RegExpStack::RestoreStack(from); 143 from = RegExpStack::RestoreStack(from);
144 from = Bootstrapper::RestoreState(from);
130 Thread::SetThreadLocal(thread_state_key, NULL); 145 Thread::SetThreadLocal(thread_state_key, NULL);
131 state->Unlink(); 146 state->Unlink();
132 state->LinkInto(ThreadState::FREE_LIST); 147 state->LinkInto(ThreadState::FREE_LIST);
133 return true; 148 return true;
134 } 149 }
135 150
136 151
137 void ThreadManager::Lock() { 152 void ThreadManager::Lock() {
138 mutex_->Lock(); 153 mutex_->Lock();
139 mutex_owner_.Initialize(ThreadHandle::SELF); 154 mutex_owner_.Initialize(ThreadHandle::SELF);
140 ASSERT(IsLockedByCurrentThread()); 155 ASSERT(IsLockedByCurrentThread());
141 } 156 }
142 157
143 158
144 void ThreadManager::Unlock() { 159 void ThreadManager::Unlock() {
145 mutex_owner_.Initialize(ThreadHandle::INVALID); 160 mutex_owner_.Initialize(ThreadHandle::INVALID);
146 mutex_->Unlock(); 161 mutex_->Unlock();
147 } 162 }
148 163
149 164
150 static int ArchiveSpacePerThread() { 165 static int ArchiveSpacePerThread() {
151 return HandleScopeImplementer::ArchiveSpacePerThread() + 166 return HandleScopeImplementer::ArchiveSpacePerThread() +
152 Top::ArchiveSpacePerThread() + 167 Top::ArchiveSpacePerThread() +
153 Debug::ArchiveSpacePerThread() + 168 Debug::ArchiveSpacePerThread() +
154 StackGuard::ArchiveSpacePerThread() + 169 StackGuard::ArchiveSpacePerThread() +
155 RegExpStack::ArchiveSpacePerThread(); 170 RegExpStack::ArchiveSpacePerThread() +
171 Bootstrapper::ArchiveSpacePerThread();
156 } 172 }
157 173
158 174
159 ThreadState* ThreadState::free_anchor_ = new ThreadState(); 175 ThreadState* ThreadState::free_anchor_ = new ThreadState();
160 ThreadState* ThreadState::in_use_anchor_ = new ThreadState(); 176 ThreadState* ThreadState::in_use_anchor_ = new ThreadState();
161 177
162 178
163 ThreadState::ThreadState() : next_(this), previous_(this) { 179 ThreadState::ThreadState() : next_(this), previous_(this) {
164 } 180 }
165 181
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 243
228 void ThreadManager::EagerlyArchiveThread() { 244 void ThreadManager::EagerlyArchiveThread() {
229 ThreadState* state = lazily_archived_thread_state_; 245 ThreadState* state = lazily_archived_thread_state_;
230 state->LinkInto(ThreadState::IN_USE_LIST); 246 state->LinkInto(ThreadState::IN_USE_LIST);
231 char* to = state->data(); 247 char* to = state->data();
232 to = HandleScopeImplementer::ArchiveThread(to); 248 to = HandleScopeImplementer::ArchiveThread(to);
233 to = Top::ArchiveThread(to); 249 to = Top::ArchiveThread(to);
234 to = Debug::ArchiveDebug(to); 250 to = Debug::ArchiveDebug(to);
235 to = StackGuard::ArchiveStackGuard(to); 251 to = StackGuard::ArchiveStackGuard(to);
236 to = RegExpStack::ArchiveStack(to); 252 to = RegExpStack::ArchiveStack(to);
253 to = Bootstrapper::ArchiveState(to);
237 lazily_archived_thread_.Initialize(ThreadHandle::INVALID); 254 lazily_archived_thread_.Initialize(ThreadHandle::INVALID);
238 lazily_archived_thread_state_ = NULL; 255 lazily_archived_thread_state_ = NULL;
239 } 256 }
240 257
241 258
242 void ThreadManager::Iterate(ObjectVisitor* v) { 259 void ThreadManager::Iterate(ObjectVisitor* v) {
243 // Expecting no threads during serialization/deserialization 260 // Expecting no threads during serialization/deserialization
244 for (ThreadState* state = ThreadState::FirstInUse(); 261 for (ThreadState* state = ThreadState::FirstInUse();
245 state != NULL; 262 state != NULL;
246 state = state->Next()) { 263 state = state->Next()) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 // Acknowledge the preemption by the receiving thread. 346 // Acknowledge the preemption by the receiving thread.
330 void ContextSwitcher::PreemptionReceived() { 347 void ContextSwitcher::PreemptionReceived() {
331 ASSERT(Locker::IsLocked()); 348 ASSERT(Locker::IsLocked());
332 // 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
333 // future, which is why we leave this in. 350 // future, which is why we leave this in.
334 } 351 }
335 352
336 353
337 } // namespace internal 354 } // namespace internal
338 } // namespace v8 355 } // namespace v8
OLDNEW
« no previous file with comments | « src/v8threads.h ('k') | src/zone.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698