Index: src/platform-cygwin.cc |
diff --git a/src/platform-cygwin.cc b/src/platform-cygwin.cc |
index 418a05e226148bb4b28fedb627d8eb62d195b7f8..e13a3a6de5303e4d2ce2bc94b98dfeefb13bfc12 100644 |
--- a/src/platform-cygwin.cc |
+++ b/src/platform-cygwin.cc |
@@ -623,168 +623,6 @@ Semaphore* OS::CreateSemaphore(int count) { |
} |
-// ---------------------------------------------------------------------------- |
-// Cygwin profiler support. |
-// |
-// On Cygwin we use the same sampler implementation as on win32. |
- |
-class Sampler::PlatformData : public Malloced { |
- public: |
- // Get a handle to the calling thread. This is the thread that we are |
- // going to profile. We need to make a copy of the handle because we are |
- // going to use it in the sampler thread. Using GetThreadHandle() will |
- // not work in this case. We're using OpenThread because DuplicateHandle |
- // for some reason doesn't work in Chrome's sandbox. |
- PlatformData() |
- : profiled_thread_(OpenThread(THREAD_GET_CONTEXT | |
- THREAD_SUSPEND_RESUME | |
- THREAD_QUERY_INFORMATION, |
- false, |
- GetCurrentThreadId())), |
- profiled_thread_id_(ThreadId::Current()) {} |
- |
- ~PlatformData() { |
- if (profiled_thread_ != NULL) { |
- CloseHandle(profiled_thread_); |
- profiled_thread_ = NULL; |
- } |
- } |
- |
- HANDLE profiled_thread() { return profiled_thread_; } |
- ThreadId profiled_thread_id() { return profiled_thread_id_; } |
- |
- private: |
- HANDLE profiled_thread_; |
- ThreadId profiled_thread_id_; |
-}; |
- |
- |
-class SamplerThread : public Thread { |
- public: |
- static const int kSamplerThreadStackSize = 64 * KB; |
- |
- explicit SamplerThread(int interval) |
- : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), |
- interval_(interval) {} |
- |
- static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } |
- static void TearDown() { delete mutex_; } |
- |
- static void AddActiveSampler(Sampler* sampler) { |
- ScopedLock lock(mutex_); |
- SamplerRegistry::AddActiveSampler(sampler); |
- if (instance_ == NULL) { |
- instance_ = new SamplerThread(sampler->interval()); |
- instance_->StartSynchronously(); |
- } else { |
- ASSERT(instance_->interval_ == sampler->interval()); |
- } |
- } |
- |
- static void RemoveActiveSampler(Sampler* sampler) { |
- ScopedLock lock(mutex_); |
- SamplerRegistry::RemoveActiveSampler(sampler); |
- if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { |
- instance_->Join(); |
- delete instance_; |
- instance_ = NULL; |
- } |
- } |
- |
- // Implement Thread::Run(). |
- virtual void Run() { |
- SamplerRegistry::State state; |
- while ((state = SamplerRegistry::GetState()) != |
- SamplerRegistry::HAS_NO_SAMPLERS) { |
- // When CPU profiling is enabled both JavaScript and C++ code is |
- // profiled. We must not suspend. |
- if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) { |
- SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this); |
- } |
- OS::Sleep(interval_); |
- } |
- } |
- |
- static void DoCpuProfile(Sampler* sampler, void* raw_sampler_thread) { |
- if (!sampler->isolate()->IsInitialized()) return; |
- if (!sampler->IsProfiling()) return; |
- SamplerThread* sampler_thread = |
- reinterpret_cast<SamplerThread*>(raw_sampler_thread); |
- sampler_thread->SampleContext(sampler); |
- } |
- |
- void SampleContext(Sampler* sampler) { |
- HANDLE profiled_thread = sampler->platform_data()->profiled_thread(); |
- if (profiled_thread == NULL) return; |
- |
- // Context used for sampling the register state of the profiled thread. |
- CONTEXT context; |
- memset(&context, 0, sizeof(context)); |
- |
- Isolate* isolate = sampler->isolate(); |
-#if defined(USE_SIMULATOR) |
-#if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS |
- ThreadId thread_id = sampler->platform_data()->profiled_thread_id(); |
- Isolate::PerIsolateThreadData* per_thread_data = isolate-> |
- FindPerThreadDataForThread(thread_id); |
- if (!per_thread_data) return; |
- Simulator* sim = per_thread_data->simulator(); |
- // Check if there is active simulator before allocating TickSample. |
- if (!sim) return; |
-#endif |
-#endif // USE_SIMULATOR |
- TickSample sample_obj; |
- TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); |
- if (sample == NULL) sample = &sample_obj; |
- |
- static const DWORD kSuspendFailed = static_cast<DWORD>(-1); |
- if (SuspendThread(profiled_thread) == kSuspendFailed) return; |
- sample->state = isolate->current_vm_state(); |
- |
- context.ContextFlags = CONTEXT_FULL; |
- if (GetThreadContext(profiled_thread, &context) != 0) { |
-#if defined(USE_SIMULATOR) |
-#if V8_TARGET_ARCH_ARM |
- sample->pc = reinterpret_cast<Address>(sim->get_register(Simulator::pc)); |
- sample->sp = reinterpret_cast<Address>(sim->get_register(Simulator::sp)); |
- sample->fp = reinterpret_cast<Address>(sim->get_register(Simulator::r11)); |
-#elif V8_TARGET_ARCH_MIPS |
- sample->pc = reinterpret_cast<Address>(sim->get_register(Simulator::pc)); |
- sample->sp = reinterpret_cast<Address>(sim->get_register(Simulator::sp)); |
- sample->fp = reinterpret_cast<Address>(sim->get_register(Simulator::fp)); |
-#endif |
-#else |
-#if V8_HOST_ARCH_X64 |
- sample->pc = reinterpret_cast<Address>(context.Rip); |
- sample->sp = reinterpret_cast<Address>(context.Rsp); |
- sample->fp = reinterpret_cast<Address>(context.Rbp); |
-#else |
- sample->pc = reinterpret_cast<Address>(context.Eip); |
- sample->sp = reinterpret_cast<Address>(context.Esp); |
- sample->fp = reinterpret_cast<Address>(context.Ebp); |
-#endif |
-#endif // USE_SIMULATOR |
- sampler->SampleStack(sample); |
- sampler->Tick(sample); |
- } |
- ResumeThread(profiled_thread); |
- } |
- |
- const int interval_; |
- |
- // Protects the process wide state below. |
- static Mutex* mutex_; |
- static SamplerThread* instance_; |
- |
- private: |
- DISALLOW_COPY_AND_ASSIGN(SamplerThread); |
-}; |
- |
- |
-Mutex* SamplerThread::mutex_ = NULL; |
-SamplerThread* SamplerThread::instance_ = NULL; |
- |
- |
void OS::SetUp() { |
// Seed the random number generator. |
// Convert the current time to a 64-bit integer first, before converting it |
@@ -794,44 +632,12 @@ void OS::SetUp() { |
uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); |
srandom(static_cast<unsigned int>(seed)); |
limit_mutex = CreateMutex(); |
- SamplerThread::SetUp(); |
} |
void OS::TearDown() { |
- SamplerThread::TearDown(); |
delete limit_mutex; |
} |
-Sampler::Sampler(Isolate* isolate, int interval) |
- : isolate_(isolate), |
- interval_(interval), |
- profiling_(false), |
- active_(false), |
- samples_taken_(0) { |
- data_ = new PlatformData; |
-} |
- |
- |
-Sampler::~Sampler() { |
- ASSERT(!IsActive()); |
- delete data_; |
-} |
- |
- |
-void Sampler::Start() { |
- ASSERT(!IsActive()); |
- SetActive(true); |
- SamplerThread::AddActiveSampler(this); |
-} |
- |
- |
-void Sampler::Stop() { |
- ASSERT(IsActive()); |
- SamplerThread::RemoveActiveSampler(this); |
- SetActive(false); |
-} |
- |
- |
} } // namespace v8::internal |