OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 | 411 |
412 | 412 |
413 class SamplerThread : public Thread { | 413 class SamplerThread : public Thread { |
414 public: | 414 public: |
415 static const int kSamplerThreadStackSize = 64 * KB; | 415 static const int kSamplerThreadStackSize = 64 * KB; |
416 | 416 |
417 explicit SamplerThread(int interval) | 417 explicit SamplerThread(int interval) |
418 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), | 418 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), |
419 interval_(interval) {} | 419 interval_(interval) {} |
420 | 420 |
421 static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } | 421 static void SetUp() { if (!mutex_) mutex_ = new Mutex(); } |
422 static void TearDown() { delete mutex_; } | 422 static void TearDown() { delete mutex_; mutex_ = NULL; } |
423 | 423 |
424 static void AddActiveSampler(Sampler* sampler) { | 424 static void AddActiveSampler(Sampler* sampler) { |
425 bool need_to_start = false; | 425 bool need_to_start = false; |
426 ScopedLock lock(mutex_); | 426 LockGuard<Mutex> lock_guard(mutex_); |
427 if (instance_ == NULL) { | 427 if (instance_ == NULL) { |
428 // Start a thread that will send SIGPROF signal to VM threads, | 428 // Start a thread that will send SIGPROF signal to VM threads, |
429 // when CPU profiling will be enabled. | 429 // when CPU profiling will be enabled. |
430 instance_ = new SamplerThread(sampler->interval()); | 430 instance_ = new SamplerThread(sampler->interval()); |
431 need_to_start = true; | 431 need_to_start = true; |
432 } | 432 } |
433 | 433 |
434 ASSERT(sampler->IsActive()); | 434 ASSERT(sampler->IsActive()); |
435 ASSERT(!instance_->active_samplers_.Contains(sampler)); | 435 ASSERT(!instance_->active_samplers_.Contains(sampler)); |
436 ASSERT(instance_->interval_ == sampler->interval()); | 436 ASSERT(instance_->interval_ == sampler->interval()); |
437 instance_->active_samplers_.Add(sampler); | 437 instance_->active_samplers_.Add(sampler); |
438 | 438 |
439 #if defined(USE_SIGNALS) | 439 #if defined(USE_SIGNALS) |
440 SignalHandler::EnsureInstalled(); | 440 SignalHandler::EnsureInstalled(); |
441 #endif | 441 #endif |
442 if (need_to_start) instance_->StartSynchronously(); | 442 if (need_to_start) instance_->StartSynchronously(); |
443 } | 443 } |
444 | 444 |
445 static void RemoveActiveSampler(Sampler* sampler) { | 445 static void RemoveActiveSampler(Sampler* sampler) { |
446 SamplerThread* instance_to_remove = NULL; | 446 SamplerThread* instance_to_remove = NULL; |
447 { | 447 { |
448 ScopedLock lock(mutex_); | 448 LockGuard<Mutex> lock_guard(mutex_); |
449 | 449 |
450 ASSERT(sampler->IsActive()); | 450 ASSERT(sampler->IsActive()); |
451 bool removed = instance_->active_samplers_.RemoveElement(sampler); | 451 bool removed = instance_->active_samplers_.RemoveElement(sampler); |
452 ASSERT(removed); | 452 ASSERT(removed); |
453 USE(removed); | 453 USE(removed); |
454 | 454 |
455 // We cannot delete the instance immediately as we need to Join() the | 455 // We cannot delete the instance immediately as we need to Join() the |
456 // thread but we are holding mutex_ and the thread may try to acquire it. | 456 // thread but we are holding mutex_ and the thread may try to acquire it. |
457 if (instance_->active_samplers_.is_empty()) { | 457 if (instance_->active_samplers_.is_empty()) { |
458 instance_to_remove = instance_; | 458 instance_to_remove = instance_; |
459 instance_ = NULL; | 459 instance_ = NULL; |
460 #if defined(USE_SIGNALS) | 460 #if defined(USE_SIGNALS) |
461 SignalHandler::Restore(); | 461 SignalHandler::Restore(); |
462 #endif | 462 #endif |
463 } | 463 } |
464 } | 464 } |
465 | 465 |
466 if (!instance_to_remove) return; | 466 if (!instance_to_remove) return; |
467 instance_to_remove->Join(); | 467 instance_to_remove->Join(); |
468 delete instance_to_remove; | 468 delete instance_to_remove; |
469 } | 469 } |
470 | 470 |
471 // Implement Thread::Run(). | 471 // Implement Thread::Run(). |
472 virtual void Run() { | 472 virtual void Run() { |
473 while (true) { | 473 while (true) { |
474 { | 474 { |
475 ScopedLock lock(mutex_); | 475 LockGuard<Mutex> lock_guard(mutex_); |
476 if (active_samplers_.is_empty()) break; | 476 if (active_samplers_.is_empty()) break; |
477 // When CPU profiling is enabled both JavaScript and C++ code is | 477 // When CPU profiling is enabled both JavaScript and C++ code is |
478 // profiled. We must not suspend. | 478 // profiled. We must not suspend. |
479 for (int i = 0; i < active_samplers_.length(); ++i) { | 479 for (int i = 0; i < active_samplers_.length(); ++i) { |
480 Sampler* sampler = active_samplers_.at(i); | 480 Sampler* sampler = active_samplers_.at(i); |
481 if (!sampler->isolate()->IsInitialized()) continue; | 481 if (!sampler->isolate()->IsInitialized()) continue; |
482 if (!sampler->IsProfiling()) continue; | 482 if (!sampler->IsProfiling()) continue; |
483 sampler->DoSample(); | 483 sampler->DoSample(); |
484 } | 484 } |
485 } | 485 } |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 #endif // USE_SIMULATOR | 657 #endif // USE_SIMULATOR |
658 SampleStack(state); | 658 SampleStack(state); |
659 } | 659 } |
660 ResumeThread(profiled_thread); | 660 ResumeThread(profiled_thread); |
661 } | 661 } |
662 | 662 |
663 #endif // USE_SIGNALS | 663 #endif // USE_SIGNALS |
664 | 664 |
665 | 665 |
666 } } // namespace v8::internal | 666 } } // namespace v8::internal |
OLD | NEW |