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

Side by Side Diff: src/v8threads.cc

Issue 171115: Linux profiler: check whether signal handler is called in the VM thread. (Closed)
Patch Set: Now dealing with multiple threads correctly, added test. Created 11 years, 3 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
« no previous file with comments | « src/v8threads.h ('k') | test/cctest/test-log.cc » ('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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 return in_use_anchor_->Next(); 234 return in_use_anchor_->Next();
235 } 235 }
236 236
237 237
238 ThreadState* ThreadState::Next() { 238 ThreadState* ThreadState::Next() {
239 if (next_ == in_use_anchor_) return NULL; 239 if (next_ == in_use_anchor_) return NULL;
240 return next_; 240 return next_;
241 } 241 }
242 242
243 243
244 int ThreadManager::next_id_ = 0; 244 int ThreadManager::last_id_ = 0;
Søren Thygesen Gjesse 2009/09/04 09:29:57 Please add a comment about that a thread cannot ha
Mikhail Naganov 2009/09/04 11:09:22 Done.
245 Mutex* ThreadManager::mutex_ = OS::CreateMutex(); 245 Mutex* ThreadManager::mutex_ = OS::CreateMutex();
246 ThreadHandle ThreadManager::mutex_owner_(ThreadHandle::INVALID); 246 ThreadHandle ThreadManager::mutex_owner_(ThreadHandle::INVALID);
247 ThreadHandle ThreadManager::lazily_archived_thread_(ThreadHandle::INVALID); 247 ThreadHandle ThreadManager::lazily_archived_thread_(ThreadHandle::INVALID);
248 ThreadState* ThreadManager::lazily_archived_thread_state_ = NULL; 248 ThreadState* ThreadManager::lazily_archived_thread_state_ = NULL;
249 249
250 250
251 void ThreadManager::ArchiveThread() { 251 void ThreadManager::ArchiveThread() {
252 ASSERT(!lazily_archived_thread_.IsValid()); 252 ASSERT(!lazily_archived_thread_.IsValid());
253 ASSERT(Thread::GetThreadLocal(thread_state_key) == NULL); 253 ASSERT(!IsArchived());
254 ThreadState* state = ThreadState::GetFree(); 254 ThreadState* state = ThreadState::GetFree();
255 state->Unlink(); 255 state->Unlink();
256 Thread::SetThreadLocal(thread_state_key, reinterpret_cast<void*>(state)); 256 Thread::SetThreadLocal(thread_state_key, reinterpret_cast<void*>(state));
257 lazily_archived_thread_.Initialize(ThreadHandle::SELF); 257 lazily_archived_thread_.Initialize(ThreadHandle::SELF);
258 lazily_archived_thread_state_ = state; 258 lazily_archived_thread_state_ = state;
259 ASSERT(state->id() == kInvalidId); 259 ASSERT(state->id() == kInvalidId);
260 state->set_id(CurrentId()); 260 state->set_id(CurrentId());
261 ASSERT(state->id() != kInvalidId); 261 ASSERT(state->id() != kInvalidId);
262 } 262 }
263 263
(...skipping 10 matching lines...) Expand all
274 to = Debug::ArchiveDebug(to); 274 to = Debug::ArchiveDebug(to);
275 #endif 275 #endif
276 to = StackGuard::ArchiveStackGuard(to); 276 to = StackGuard::ArchiveStackGuard(to);
277 to = RegExpStack::ArchiveStack(to); 277 to = RegExpStack::ArchiveStack(to);
278 to = Bootstrapper::ArchiveState(to); 278 to = Bootstrapper::ArchiveState(to);
279 lazily_archived_thread_.Initialize(ThreadHandle::INVALID); 279 lazily_archived_thread_.Initialize(ThreadHandle::INVALID);
280 lazily_archived_thread_state_ = NULL; 280 lazily_archived_thread_state_ = NULL;
281 } 281 }
282 282
283 283
284 bool ThreadManager::IsArchived() {
285 return Thread::HasThreadLocal(thread_state_key);
286 }
287
288
284 void ThreadManager::Iterate(ObjectVisitor* v) { 289 void ThreadManager::Iterate(ObjectVisitor* v) {
285 // Expecting no threads during serialization/deserialization 290 // Expecting no threads during serialization/deserialization
286 for (ThreadState* state = ThreadState::FirstInUse(); 291 for (ThreadState* state = ThreadState::FirstInUse();
287 state != NULL; 292 state != NULL;
288 state = state->Next()) { 293 state = state->Next()) {
289 char* data = state->data(); 294 char* data = state->data();
290 data = HandleScopeImplementer::Iterate(v, data); 295 data = HandleScopeImplementer::Iterate(v, data);
291 data = Top::Iterate(v, data); 296 data = Top::Iterate(v, data);
292 } 297 }
293 } 298 }
(...skipping 20 matching lines...) Expand all
314 } 319 }
315 } 320 }
316 321
317 322
318 int ThreadManager::CurrentId() { 323 int ThreadManager::CurrentId() {
319 return Thread::GetThreadLocalInt(thread_id_key); 324 return Thread::GetThreadLocalInt(thread_id_key);
320 } 325 }
321 326
322 327
323 void ThreadManager::AssignId() { 328 void ThreadManager::AssignId() {
324 if (!Thread::HasThreadLocal(thread_id_key)) { 329 if (!HasId()) {
325 ASSERT(Locker::IsLocked()); 330 ASSERT(Locker::IsLocked());
326 int thread_id = next_id_++; 331 int thread_id = ++last_id_;
Søren Thygesen Gjesse 2009/09/04 09:29:57 Maybe assert thread_id > 0.
Mikhail Naganov 2009/09/04 11:09:22 Done.
327 Thread::SetThreadLocalInt(thread_id_key, thread_id); 332 Thread::SetThreadLocalInt(thread_id_key, thread_id);
328 Top::set_thread_id(thread_id); 333 Top::set_thread_id(thread_id);
329 } 334 }
330 } 335 }
331 336
332 337
338 bool ThreadManager::HasId() {
339 return Thread::HasThreadLocal(thread_id_key);
340 }
341
342
333 void ThreadManager::TerminateExecution(int thread_id) { 343 void ThreadManager::TerminateExecution(int thread_id) {
334 for (ThreadState* state = ThreadState::FirstInUse(); 344 for (ThreadState* state = ThreadState::FirstInUse();
335 state != NULL; 345 state != NULL;
336 state = state->Next()) { 346 state = state->Next()) {
337 if (thread_id == state->id()) { 347 if (thread_id == state->id()) {
338 state->set_terminate_on_restore(true); 348 state->set_terminate_on_restore(true);
339 } 349 }
340 } 350 }
341 } 351 }
342 352
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 // Acknowledge the preemption by the receiving thread. 407 // Acknowledge the preemption by the receiving thread.
398 void ContextSwitcher::PreemptionReceived() { 408 void ContextSwitcher::PreemptionReceived() {
399 ASSERT(Locker::IsLocked()); 409 ASSERT(Locker::IsLocked());
400 // There is currently no accounting being done for this. But could be in the 410 // There is currently no accounting being done for this. But could be in the
401 // future, which is why we leave this in. 411 // future, which is why we leave this in.
402 } 412 }
403 413
404 414
405 } // namespace internal 415 } // namespace internal
406 } // namespace v8 416 } // namespace v8
OLDNEW
« no previous file with comments | « src/v8threads.h ('k') | test/cctest/test-log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698