| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 kMmapFd, kMmapFdOffset) != MAP_FAILED; | 391 kMmapFd, kMmapFdOffset) != MAP_FAILED; |
| 392 } | 392 } |
| 393 | 393 |
| 394 | 394 |
| 395 class Thread::PlatformData : public Malloced { | 395 class Thread::PlatformData : public Malloced { |
| 396 public: | 396 public: |
| 397 pthread_t thread_; // Thread handle for pthread. | 397 pthread_t thread_; // Thread handle for pthread. |
| 398 }; | 398 }; |
| 399 | 399 |
| 400 | 400 |
| 401 Thread::Thread(Isolate* isolate, const Options& options) | 401 Thread::Thread(const Options& options) |
| 402 : data_(new PlatformData), | 402 : data_(new PlatformData), |
| 403 isolate_(isolate), | |
| 404 stack_size_(options.stack_size) { | 403 stack_size_(options.stack_size) { |
| 405 set_name(options.name); | 404 set_name(options.name); |
| 406 } | 405 } |
| 407 | 406 |
| 408 | 407 |
| 409 Thread::Thread(Isolate* isolate, const char* name) | 408 Thread::Thread(const char* name) |
| 410 : data_(new PlatformData), | 409 : data_(new PlatformData), |
| 411 isolate_(isolate), | |
| 412 stack_size_(0) { | 410 stack_size_(0) { |
| 413 set_name(name); | 411 set_name(name); |
| 414 } | 412 } |
| 415 | 413 |
| 416 | 414 |
| 417 Thread::~Thread() { | 415 Thread::~Thread() { |
| 418 delete data_; | 416 delete data_; |
| 419 } | 417 } |
| 420 | 418 |
| 421 | 419 |
| 422 static void* ThreadEntry(void* arg) { | 420 static void* ThreadEntry(void* arg) { |
| 423 Thread* thread = reinterpret_cast<Thread*>(arg); | 421 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 424 // This is also initialized by the first argument to pthread_create() but we | 422 // This is also initialized by the first argument to pthread_create() but we |
| 425 // don't know which thread will run first (the original thread or the new | 423 // don't know which thread will run first (the original thread or the new |
| 426 // one) so we initialize it here too. | 424 // one) so we initialize it here too. |
| 427 thread->data()->thread_ = pthread_self(); | 425 thread->data()->thread_ = pthread_self(); |
| 428 ASSERT(thread->data()->thread_ != kNoThread); | 426 ASSERT(thread->data()->thread_ != kNoThread); |
| 429 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); | |
| 430 thread->Run(); | 427 thread->Run(); |
| 431 return NULL; | 428 return NULL; |
| 432 } | 429 } |
| 433 | 430 |
| 434 | 431 |
| 435 void Thread::set_name(const char* name) { | 432 void Thread::set_name(const char* name) { |
| 436 strncpy(name_, name, sizeof(name_)); | 433 strncpy(name_, name, sizeof(name_)); |
| 437 name_[sizeof(name_) - 1] = '\0'; | 434 name_[sizeof(name_) - 1] = '\0'; |
| 438 } | 435 } |
| 439 | 436 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 | 650 |
| 654 | 651 |
| 655 class SignalSender : public Thread { | 652 class SignalSender : public Thread { |
| 656 public: | 653 public: |
| 657 enum SleepInterval { | 654 enum SleepInterval { |
| 658 HALF_INTERVAL, | 655 HALF_INTERVAL, |
| 659 FULL_INTERVAL | 656 FULL_INTERVAL |
| 660 }; | 657 }; |
| 661 | 658 |
| 662 explicit SignalSender(int interval) | 659 explicit SignalSender(int interval) |
| 663 : Thread(NULL, "SignalSender"), | 660 : Thread("SignalSender"), |
| 664 interval_(interval) {} | 661 interval_(interval) {} |
| 665 | 662 |
| 666 static void AddActiveSampler(Sampler* sampler) { | 663 static void AddActiveSampler(Sampler* sampler) { |
| 667 ScopedLock lock(mutex_); | 664 ScopedLock lock(mutex_); |
| 668 SamplerRegistry::AddActiveSampler(sampler); | 665 SamplerRegistry::AddActiveSampler(sampler); |
| 669 if (instance_ == NULL) { | 666 if (instance_ == NULL) { |
| 670 // Install a signal handler. | 667 // Install a signal handler. |
| 671 struct sigaction sa; | 668 struct sigaction sa; |
| 672 sa.sa_sigaction = ProfilerSignalHandler; | 669 sa.sa_sigaction = ProfilerSignalHandler; |
| 673 sigemptyset(&sa.sa_mask); | 670 sigemptyset(&sa.sa_mask); |
| 674 sa.sa_flags = SA_RESTART | SA_SIGINFO; | 671 sa.sa_flags = SA_RESTART | SA_SIGINFO; |
| 675 signal_handler_installed_ = | 672 signal_handler_installed_ = |
| 676 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); | 673 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); |
| 677 | 674 |
| 678 // Start a thread that sends SIGPROF signal to VM threads. | 675 // Start a thread that sends SIGPROF signal to VM threads. |
| 679 instance_ = new SignalSender(sampler->interval()); | 676 instance_ = new SignalSender(sampler->interval()); |
| 680 instance_->Start(); | 677 instance_->Start(); |
| 681 } else { | 678 } else { |
| 682 ASSERT(instance_->interval_ == sampler->interval()); | 679 ASSERT(instance_->interval_ == sampler->interval()); |
| 683 } | 680 } |
| 684 } | 681 } |
| 685 | 682 |
| 686 static void RemoveActiveSampler(Sampler* sampler) { | 683 static void RemoveActiveSampler(Sampler* sampler) { |
| 687 ScopedLock lock(mutex_); | 684 ScopedLock lock(mutex_); |
| 688 SamplerRegistry::RemoveActiveSampler(sampler); | 685 SamplerRegistry::RemoveActiveSampler(sampler); |
| 689 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { | 686 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { |
| 690 RuntimeProfiler::WakeUpRuntimeProfilerThreadBeforeShutdown(); | 687 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); |
| 691 instance_->Join(); | |
| 692 delete instance_; | 688 delete instance_; |
| 693 instance_ = NULL; | 689 instance_ = NULL; |
| 694 | 690 |
| 695 // Restore the old signal handler. | 691 // Restore the old signal handler. |
| 696 if (signal_handler_installed_) { | 692 if (signal_handler_installed_) { |
| 697 sigaction(SIGPROF, &old_signal_handler_, 0); | 693 sigaction(SIGPROF, &old_signal_handler_, 0); |
| 698 signal_handler_installed_ = false; | 694 signal_handler_installed_ = false; |
| 699 } | 695 } |
| 700 } | 696 } |
| 701 } | 697 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 | 813 |
| 818 void Sampler::Stop() { | 814 void Sampler::Stop() { |
| 819 ASSERT(IsActive()); | 815 ASSERT(IsActive()); |
| 820 SignalSender::RemoveActiveSampler(this); | 816 SignalSender::RemoveActiveSampler(this); |
| 821 SetActive(false); | 817 SetActive(false); |
| 822 } | 818 } |
| 823 | 819 |
| 824 #endif // ENABLE_LOGGING_AND_PROFILING | 820 #endif // ENABLE_LOGGING_AND_PROFILING |
| 825 | 821 |
| 826 } } // namespace v8::internal | 822 } } // namespace v8::internal |
| OLD | NEW |