Commit 719fe8c3 authored by yurys@chromium.org's avatar yurys@chromium.org

Fix cctest/test-cpu-profiler/CollectCpuProfile test on Arm and MIPS simulators

Signal handler on simulator now retrieve registers from the simulator not from the host machine.

BUG=v8:2621

Review URL: https://codereview.chromium.org/13845014

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14235 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d311208e
...@@ -371,6 +371,12 @@ Isolate::PerIsolateThreadData* ...@@ -371,6 +371,12 @@ Isolate::PerIsolateThreadData*
Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() { Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() {
ThreadId thread_id = ThreadId::Current(); ThreadId thread_id = ThreadId::Current();
return FindPerThreadDataForThread(thread_id);
}
Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread(
ThreadId thread_id) {
PerIsolateThreadData* per_thread = NULL; PerIsolateThreadData* per_thread = NULL;
{ {
ScopedLock lock(process_wide_mutex_); ScopedLock lock(process_wide_mutex_);
......
...@@ -497,6 +497,10 @@ class Isolate { ...@@ -497,6 +497,10 @@ class Isolate {
// If one does not yet exist, return null. // If one does not yet exist, return null.
PerIsolateThreadData* FindPerThreadDataForThisThread(); PerIsolateThreadData* FindPerThreadDataForThisThread();
// Find the PerThread for given (isolate, thread) combination
// If one does not yet exist, return null.
PerIsolateThreadData* FindPerThreadDataForThread(ThreadId thread_id);
#ifdef ENABLE_DEBUGGER_SUPPORT #ifdef ENABLE_DEBUGGER_SUPPORT
// Get the debugger from the default isolate. Preinitializes the // Get the debugger from the default isolate. Preinitializes the
// default isolate if needed. // default isolate if needed.
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "platform-posix.h" #include "platform-posix.h"
#include "platform.h" #include "platform.h"
#include "simulator.h"
#include "v8threads.h" #include "v8threads.h"
#include "vm-state-inl.h" #include "vm-state-inl.h"
#include "win32-headers.h" #include "win32-headers.h"
...@@ -604,11 +605,13 @@ class Sampler::PlatformData : public Malloced { ...@@ -604,11 +605,13 @@ class Sampler::PlatformData : public Malloced {
// going to use it in the sampler thread. Using GetThreadHandle() will // going to use it in the sampler thread. Using GetThreadHandle() will
// not work in this case. We're using OpenThread because DuplicateHandle // not work in this case. We're using OpenThread because DuplicateHandle
// for some reason doesn't work in Chrome's sandbox. // for some reason doesn't work in Chrome's sandbox.
PlatformData() : profiled_thread_(OpenThread(THREAD_GET_CONTEXT | PlatformData()
THREAD_SUSPEND_RESUME | : profiled_thread_(OpenThread(THREAD_GET_CONTEXT |
THREAD_QUERY_INFORMATION, THREAD_SUSPEND_RESUME |
false, THREAD_QUERY_INFORMATION,
GetCurrentThreadId())) {} false,
GetCurrentThreadId())),
profiled_thread_id_(ThreadId::Current()) {}
~PlatformData() { ~PlatformData() {
if (profiled_thread_ != NULL) { if (profiled_thread_ != NULL) {
...@@ -618,9 +621,11 @@ class Sampler::PlatformData : public Malloced { ...@@ -618,9 +621,11 @@ class Sampler::PlatformData : public Malloced {
} }
HANDLE profiled_thread() { return profiled_thread_; } HANDLE profiled_thread() { return profiled_thread_; }
ThreadId profiled_thread_id() { return profiled_thread_id_; }
private: private:
HANDLE profiled_thread_; HANDLE profiled_thread_;
ThreadId profiled_thread_id_;
}; };
...@@ -687,6 +692,17 @@ class SamplerThread : public Thread { ...@@ -687,6 +692,17 @@ class SamplerThread : public Thread {
memset(&context, 0, sizeof(context)); memset(&context, 0, sizeof(context));
Isolate* isolate = sampler->isolate(); 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_obj;
TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
if (sample == NULL) sample = &sample_obj; if (sample == NULL) sample = &sample_obj;
...@@ -697,6 +713,17 @@ class SamplerThread : public Thread { ...@@ -697,6 +713,17 @@ class SamplerThread : public Thread {
context.ContextFlags = CONTEXT_FULL; context.ContextFlags = CONTEXT_FULL;
if (GetThreadContext(profiled_thread, &context) != 0) { 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 #if V8_HOST_ARCH_X64
sample->pc = reinterpret_cast<Address>(context.Rip); sample->pc = reinterpret_cast<Address>(context.Rip);
sample->sp = reinterpret_cast<Address>(context.Rsp); sample->sp = reinterpret_cast<Address>(context.Rsp);
...@@ -706,6 +733,7 @@ class SamplerThread : public Thread { ...@@ -706,6 +733,7 @@ class SamplerThread : public Thread {
sample->sp = reinterpret_cast<Address>(context.Esp); sample->sp = reinterpret_cast<Address>(context.Esp);
sample->fp = reinterpret_cast<Address>(context.Ebp); sample->fp = reinterpret_cast<Address>(context.Ebp);
#endif #endif
#endif // USE_SIMULATOR
sampler->SampleStack(sample); sampler->SampleStack(sample);
sampler->Tick(sample); sampler->Tick(sample);
} }
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "platform-posix.h" #include "platform-posix.h"
#include "platform.h" #include "platform.h"
#include "simulator.h"
#include "vm-state-inl.h" #include "vm-state-inl.h"
...@@ -690,12 +691,16 @@ static pthread_t GetThreadID() { ...@@ -690,12 +691,16 @@ static pthread_t GetThreadID() {
class Sampler::PlatformData : public Malloced { class Sampler::PlatformData : public Malloced {
public: public:
PlatformData() : vm_tid_(GetThreadID()) {} PlatformData()
: vm_tid_(GetThreadID()),
profiled_thread_id_(ThreadId::Current()) {}
pthread_t vm_tid() const { return vm_tid_; } pthread_t vm_tid() const { return vm_tid_; }
ThreadId profiled_thread_id() { return profiled_thread_id_; }
private: private:
pthread_t vm_tid_; pthread_t vm_tid_;
ThreadId profiled_thread_id_;
}; };
...@@ -715,6 +720,18 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { ...@@ -715,6 +720,18 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
Sampler* sampler = isolate->logger()->sampler(); Sampler* sampler = isolate->logger()->sampler();
if (sampler == NULL || !sampler->IsActive()) return; if (sampler == NULL || !sampler->IsActive()) return;
#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_obj;
TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
if (sample == NULL) sample = &sample_obj; if (sample == NULL) sample = &sample_obj;
...@@ -723,6 +740,17 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { ...@@ -723,6 +740,17 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
mcontext_t& mcontext = ucontext->uc_mcontext; mcontext_t& mcontext = ucontext->uc_mcontext;
sample->state = isolate->current_vm_state(); sample->state = isolate->current_vm_state();
#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_IA32 #if V8_HOST_ARCH_IA32
sample->pc = reinterpret_cast<Address>(mcontext.mc_eip); sample->pc = reinterpret_cast<Address>(mcontext.mc_eip);
sample->sp = reinterpret_cast<Address>(mcontext.mc_esp); sample->sp = reinterpret_cast<Address>(mcontext.mc_esp);
...@@ -735,7 +763,8 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { ...@@ -735,7 +763,8 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
sample->pc = reinterpret_cast<Address>(mcontext.mc_r15); sample->pc = reinterpret_cast<Address>(mcontext.mc_r15);
sample->sp = reinterpret_cast<Address>(mcontext.mc_r13); sample->sp = reinterpret_cast<Address>(mcontext.mc_r13);
sample->fp = reinterpret_cast<Address>(mcontext.mc_r11); sample->fp = reinterpret_cast<Address>(mcontext.mc_r11);
#endif #endif // V8_HOST_ARCH_*
#endif // USE_SIMULATOR
sampler->SampleStack(sample); sampler->SampleStack(sample);
sampler->Tick(sample); sampler->Tick(sample);
} }
......
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
#include "platform-posix.h" #include "platform-posix.h"
#include "platform.h" #include "platform.h"
#include "simulator.h"
#include "v8threads.h" #include "v8threads.h"
#include "vm-state-inl.h" #include "vm-state-inl.h"
...@@ -1076,6 +1077,21 @@ static int GetThreadID() { ...@@ -1076,6 +1077,21 @@ static int GetThreadID() {
} }
class Sampler::PlatformData : public Malloced {
public:
PlatformData()
: vm_tid_(GetThreadID()),
profiled_thread_id_(ThreadId::Current()) {}
pthread_t vm_tid() const { return vm_tid_; }
ThreadId profiled_thread_id() { return profiled_thread_id_; }
private:
pthread_t vm_tid_;
ThreadId profiled_thread_id_;
};
static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
#if defined(__native_client__) #if defined(__native_client__)
// As Native Client does not support signal handling, profiling // As Native Client does not support signal handling, profiling
...@@ -1097,10 +1113,33 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { ...@@ -1097,10 +1113,33 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
Sampler* sampler = isolate->logger()->sampler(); Sampler* sampler = isolate->logger()->sampler();
if (sampler == NULL || !sampler->IsActive()) return; if (sampler == NULL || !sampler->IsActive()) return;
#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_obj;
TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
if (sample == NULL) sample = &sample_obj; if (sample == NULL) sample = &sample_obj;
#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
// Extracting the sample from the context is extremely machine dependent. // Extracting the sample from the context is extremely machine dependent.
ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
mcontext_t& mcontext = ucontext->uc_mcontext; mcontext_t& mcontext = ucontext->uc_mcontext;
...@@ -1132,23 +1171,13 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { ...@@ -1132,23 +1171,13 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
sample->sp = reinterpret_cast<Address>(mcontext.gregs[29]); sample->sp = reinterpret_cast<Address>(mcontext.gregs[29]);
sample->fp = reinterpret_cast<Address>(mcontext.gregs[30]); sample->fp = reinterpret_cast<Address>(mcontext.gregs[30]);
#endif // V8_HOST_ARCH_* #endif // V8_HOST_ARCH_*
#endif // USE_SIMULATOR
sampler->SampleStack(sample); sampler->SampleStack(sample);
sampler->Tick(sample); sampler->Tick(sample);
#endif // __native_client__ #endif // __native_client__
} }
class Sampler::PlatformData : public Malloced {
public:
PlatformData() : vm_tid_(GetThreadID()) {}
int vm_tid() const { return vm_tid_; }
private:
const int vm_tid_;
};
class SignalSender : public Thread { class SignalSender : public Thread {
public: public:
static const int kSignalSenderStackSize = 64 * KB; static const int kSignalSenderStackSize = 64 * KB;
......
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
#include "platform-posix.h" #include "platform-posix.h"
#include "platform.h" #include "platform.h"
#include "simulator.h"
#include "vm-state-inl.h" #include "vm-state-inl.h"
// Manually define these here as weak imports, rather than including execinfo.h. // Manually define these here as weak imports, rather than including execinfo.h.
...@@ -744,7 +745,9 @@ Semaphore* OS::CreateSemaphore(int count) { ...@@ -744,7 +745,9 @@ Semaphore* OS::CreateSemaphore(int count) {
class Sampler::PlatformData : public Malloced { class Sampler::PlatformData : public Malloced {
public: public:
PlatformData() : profiled_thread_(mach_thread_self()) {} PlatformData()
: profiled_thread_(mach_thread_self()),
profiled_thread_id_(ThreadId::Current()) {}
~PlatformData() { ~PlatformData() {
// Deallocate Mach port for thread. // Deallocate Mach port for thread.
...@@ -752,12 +755,14 @@ class Sampler::PlatformData : public Malloced { ...@@ -752,12 +755,14 @@ class Sampler::PlatformData : public Malloced {
} }
thread_act_t profiled_thread() { return profiled_thread_; } thread_act_t profiled_thread() { return profiled_thread_; }
ThreadId profiled_thread_id() { return profiled_thread_id_; }
private: private:
// Note: for profiled_thread_ Mach primitives are used instead of PThread's // Note: for profiled_thread_ Mach primitives are used instead of PThread's
// because the latter doesn't provide thread manipulation primitives required. // because the latter doesn't provide thread manipulation primitives required.
// For details, consult "Mac OS X Internals" book, Section 7.3. // For details, consult "Mac OS X Internals" book, Section 7.3.
thread_act_t profiled_thread_; thread_act_t profiled_thread_;
ThreadId profiled_thread_id_;
}; };
...@@ -818,6 +823,17 @@ class SamplerThread : public Thread { ...@@ -818,6 +823,17 @@ class SamplerThread : public Thread {
void SampleContext(Sampler* sampler) { void SampleContext(Sampler* sampler) {
thread_act_t profiled_thread = sampler->platform_data()->profiled_thread(); thread_act_t profiled_thread = sampler->platform_data()->profiled_thread();
Isolate* isolate = sampler->isolate(); 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_obj;
TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
if (sample == NULL) sample = &sample_obj; if (sample == NULL) sample = &sample_obj;
...@@ -851,9 +867,21 @@ class SamplerThread : public Thread { ...@@ -851,9 +867,21 @@ class SamplerThread : public Thread {
reinterpret_cast<natural_t*>(&state), reinterpret_cast<natural_t*>(&state),
&count) == KERN_SUCCESS) { &count) == KERN_SUCCESS) {
sample->state = isolate->current_vm_state(); sample->state = isolate->current_vm_state();
#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
sample->pc = reinterpret_cast<Address>(state.REGISTER_FIELD(ip)); sample->pc = reinterpret_cast<Address>(state.REGISTER_FIELD(ip));
sample->sp = reinterpret_cast<Address>(state.REGISTER_FIELD(sp)); sample->sp = reinterpret_cast<Address>(state.REGISTER_FIELD(sp));
sample->fp = reinterpret_cast<Address>(state.REGISTER_FIELD(bp)); sample->fp = reinterpret_cast<Address>(state.REGISTER_FIELD(bp));
#endif // USE_SIMULATOR
sampler->SampleStack(sample); sampler->SampleStack(sample);
sampler->Tick(sample); sampler->Tick(sample);
} }
......
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
#include "platform-posix.h" #include "platform-posix.h"
#include "platform.h" #include "platform.h"
#include "simulator.h"
#include "v8threads.h" #include "v8threads.h"
#include "vm-state-inl.h" #include "vm-state-inl.h"
...@@ -732,6 +733,22 @@ static pthread_t GetThreadID() { ...@@ -732,6 +733,22 @@ static pthread_t GetThreadID() {
return pthread_self(); return pthread_self();
} }
class Sampler::PlatformData : public Malloced {
public:
PlatformData()
: vm_tid_(GetThreadID()),
profiled_thread_id_(ThreadId::Current()) {}
pthread_t vm_tid() const { return vm_tid_; }
ThreadId profiled_thread_id() { return profiled_thread_id_; }
private:
pthread_t vm_tid_;
ThreadId profiled_thread_id_;
};
static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
USE(info); USE(info);
if (signal != SIGPROF) return; if (signal != SIGPROF) return;
...@@ -748,6 +765,18 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { ...@@ -748,6 +765,18 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
Sampler* sampler = isolate->logger()->sampler(); Sampler* sampler = isolate->logger()->sampler();
if (sampler == NULL || !sampler->IsActive()) return; if (sampler == NULL || !sampler->IsActive()) return;
#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_obj;
TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
if (sample == NULL) sample = &sample_obj; if (sample == NULL) sample = &sample_obj;
...@@ -755,6 +784,17 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { ...@@ -755,6 +784,17 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
// Extracting the sample from the context is extremely machine dependent. // Extracting the sample from the context is extremely machine dependent.
sample->state = isolate->current_vm_state(); sample->state = isolate->current_vm_state();
ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
#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
#ifdef __NetBSD__ #ifdef __NetBSD__
mcontext_t& mcontext = ucontext->uc_mcontext; mcontext_t& mcontext = ucontext->uc_mcontext;
#if V8_HOST_ARCH_IA32 #if V8_HOST_ARCH_IA32
...@@ -777,22 +817,12 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { ...@@ -777,22 +817,12 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
sample->fp = reinterpret_cast<Address>(ucontext->sc_rbp); sample->fp = reinterpret_cast<Address>(ucontext->sc_rbp);
#endif // V8_HOST_ARCH #endif // V8_HOST_ARCH
#endif // __NetBSD__ #endif // __NetBSD__
#endif // USE_SIMULATOR
sampler->SampleStack(sample); sampler->SampleStack(sample);
sampler->Tick(sample); sampler->Tick(sample);
} }
class Sampler::PlatformData : public Malloced {
public:
PlatformData() : vm_tid_(GetThreadID()) {}
pthread_t vm_tid() const { return vm_tid_; }
private:
pthread_t vm_tid_;
};
class SignalSender : public Thread { class SignalSender : public Thread {
public: public:
static const int kSignalSenderStackSize = 64 * KB; static const int kSignalSenderStackSize = 64 * KB;
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
#include "platform-posix.h" #include "platform-posix.h"
#include "platform.h" #include "platform.h"
#include "simulator.h"
#include "v8threads.h" #include "v8threads.h"
#include "vm-state-inl.h" #include "vm-state-inl.h"
...@@ -666,6 +667,22 @@ static pthread_t GetThreadID() { ...@@ -666,6 +667,22 @@ static pthread_t GetThreadID() {
return pthread_self(); return pthread_self();
} }
class Sampler::PlatformData : public Malloced {
public:
PlatformData()
: vm_tid_(GetThreadID()),
profiled_thread_id_(ThreadId::Current()) {}
pthread_t vm_tid() const { return vm_tid_; }
ThreadId profiled_thread_id() { return profiled_thread_id_; }
private:
pthread_t vm_tid_;
ThreadId profiled_thread_id_;
};
static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
USE(info); USE(info);
if (signal != SIGPROF) return; if (signal != SIGPROF) return;
...@@ -686,29 +703,43 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { ...@@ -686,29 +703,43 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
if (sample == NULL) sample = &sample_obj; if (sample == NULL) sample = &sample_obj;
#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
// Extracting the sample from the context is extremely machine dependent. // Extracting the sample from the context is extremely machine dependent.
ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
mcontext_t& mcontext = ucontext->uc_mcontext; mcontext_t& mcontext = ucontext->uc_mcontext;
sample->state = isolate->current_vm_state(); sample->state = isolate->current_vm_state();
#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
sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_PC]); sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_PC]);
sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_SP]); sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_SP]);
sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_FP]); sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_FP]);
#endif // USE_SIMULATOR
sampler->SampleStack(sample); sampler->SampleStack(sample);
sampler->Tick(sample); sampler->Tick(sample);
} }
class Sampler::PlatformData : public Malloced {
public:
PlatformData() : vm_tid_(GetThreadID()) {}
pthread_t vm_tid() const { return vm_tid_; }
private:
pthread_t vm_tid_;
};
class SignalSender : public Thread { class SignalSender : public Thread {
public: public:
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include "codegen.h" #include "codegen.h"
#include "platform.h" #include "platform.h"
#include "simulator.h"
#include "vm-state-inl.h" #include "vm-state-inl.h"
#ifdef _MSC_VER #ifdef _MSC_VER
...@@ -1981,11 +1982,13 @@ class Sampler::PlatformData : public Malloced { ...@@ -1981,11 +1982,13 @@ class Sampler::PlatformData : public Malloced {
// going to use it in the sampler thread. Using GetThreadHandle() will // going to use it in the sampler thread. Using GetThreadHandle() will
// not work in this case. We're using OpenThread because DuplicateHandle // not work in this case. We're using OpenThread because DuplicateHandle
// for some reason doesn't work in Chrome's sandbox. // for some reason doesn't work in Chrome's sandbox.
PlatformData() : profiled_thread_(OpenThread(THREAD_GET_CONTEXT | PlatformData()
THREAD_SUSPEND_RESUME | : profiled_thread_(OpenThread(THREAD_GET_CONTEXT |
THREAD_QUERY_INFORMATION, THREAD_SUSPEND_RESUME |
false, THREAD_QUERY_INFORMATION,
GetCurrentThreadId())) {} false,
GetCurrentThreadId())),
profiled_thread_id_(ThreadId::Current()) {}
~PlatformData() { ~PlatformData() {
if (profiled_thread_ != NULL) { if (profiled_thread_ != NULL) {
...@@ -1995,9 +1998,11 @@ class Sampler::PlatformData : public Malloced { ...@@ -1995,9 +1998,11 @@ class Sampler::PlatformData : public Malloced {
} }
HANDLE profiled_thread() { return profiled_thread_; } HANDLE profiled_thread() { return profiled_thread_; }
ThreadId profiled_thread_id() { return profiled_thread_id_; }
private: private:
HANDLE profiled_thread_; HANDLE profiled_thread_;
ThreadId profiled_thread_id_;
}; };
...@@ -2064,6 +2069,17 @@ class SamplerThread : public Thread { ...@@ -2064,6 +2069,17 @@ class SamplerThread : public Thread {
memset(&context, 0, sizeof(context)); memset(&context, 0, sizeof(context));
Isolate* isolate = sampler->isolate(); 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_obj;
TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
if (sample == NULL) sample = &sample_obj; if (sample == NULL) sample = &sample_obj;
...@@ -2074,6 +2090,17 @@ class SamplerThread : public Thread { ...@@ -2074,6 +2090,17 @@ class SamplerThread : public Thread {
context.ContextFlags = CONTEXT_FULL; context.ContextFlags = CONTEXT_FULL;
if (GetThreadContext(profiled_thread, &context) != 0) { 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 #if V8_HOST_ARCH_X64
sample->pc = reinterpret_cast<Address>(context.Rip); sample->pc = reinterpret_cast<Address>(context.Rip);
sample->sp = reinterpret_cast<Address>(context.Rsp); sample->sp = reinterpret_cast<Address>(context.Rsp);
...@@ -2083,6 +2110,7 @@ class SamplerThread : public Thread { ...@@ -2083,6 +2110,7 @@ class SamplerThread : public Thread {
sample->sp = reinterpret_cast<Address>(context.Esp); sample->sp = reinterpret_cast<Address>(context.Esp);
sample->fp = reinterpret_cast<Address>(context.Ebp); sample->fp = reinterpret_cast<Address>(context.Ebp);
#endif #endif
#endif // USE_SIMULATOR
sampler->SampleStack(sample); sampler->SampleStack(sample);
sampler->Tick(sample); sampler->Tick(sample);
} }
......
...@@ -77,9 +77,6 @@ test-serialize/DeserializeFromSecondSerializationAndRunScript2: SKIP ...@@ -77,9 +77,6 @@ test-serialize/DeserializeFromSecondSerializationAndRunScript2: SKIP
test-serialize/DeserializeAndRunScript2: SKIP test-serialize/DeserializeAndRunScript2: SKIP
test-serialize/DeserializeFromSecondSerialization: SKIP test-serialize/DeserializeFromSecondSerialization: SKIP
# BUG(2621): Stack traversal doesn't work properly on Arm simulator.
test-cpu-profiler/CollectCpuProfile: SKIP
############################################################################## ##############################################################################
[ $arch == android_arm || $arch == android_ia32 ] [ $arch == android_arm || $arch == android_ia32 ]
...@@ -106,9 +103,3 @@ test-log/ProfLazyMode: SKIP ...@@ -106,9 +103,3 @@ test-log/ProfLazyMode: SKIP
test-debug/DebuggerAgent: SKIP test-debug/DebuggerAgent: SKIP
test-debug/DebuggerAgentProtocolOverflowHeader: SKIP test-debug/DebuggerAgentProtocolOverflowHeader: SKIP
test-sockets/Socket: SKIP test-sockets/Socket: SKIP
##############################################################################
[ $arch == mipsel ]
# BUG(2621): Stack traversal doesn't work properly on MIPS simulator.
test-cpu-profiler/CollectCpuProfile: SKIP
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment