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

Unified Diff: src/sampler.cc

Issue 578163002: Implemented GetSample. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Including win32-headers.h in v8.h for testing on trybots. Created 6 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 side-by-side diff with in-line comments
Download patch
Index: src/sampler.cc
diff --git a/src/sampler.cc b/src/sampler.cc
index 394efeb7640764870b6f768a9d11a1b879955416..6ffaf1c7668c054c28f5529ad1a742e188759dd8 100644
--- a/src/sampler.cc
+++ b/src/sampler.cc
@@ -232,7 +232,7 @@ class SimulatorHelper {
return simulator_ != NULL;
}
- inline void FillRegisters(RegisterState* state) {
+ inline void FillRegisters(v8::RegisterState* state) {
#if V8_TARGET_ARCH_ARM
state->pc = reinterpret_cast<Address>(simulator_->get_pc());
state->sp = reinterpret_cast<Address>(simulator_->get_register(
@@ -353,9 +353,9 @@ void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info,
Sampler* sampler = isolate->logger()->sampler();
if (sampler == NULL) return;
- RegisterState state;
#if defined(USE_SIMULATOR)
+ v8::RegisterState state;
SimulatorHelper helper;
if (!helper.Init(sampler, isolate)) return;
helper.FillRegisters(&state);
@@ -365,119 +365,8 @@ void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info,
// Bailout if sp/fp doesn't contain the new value.
if (state.sp == 0 || state.fp == 0) return;
#else
- // Extracting the sample from the context is extremely machine dependent.
ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
-#if !V8_OS_OPENBSD
- mcontext_t& mcontext = ucontext->uc_mcontext;
-#endif
-#if V8_OS_LINUX
-#if V8_HOST_ARCH_IA32
- state.pc = reinterpret_cast<Address>(mcontext.gregs[REG_EIP]);
- state.sp = reinterpret_cast<Address>(mcontext.gregs[REG_ESP]);
- state.fp = reinterpret_cast<Address>(mcontext.gregs[REG_EBP]);
-#elif V8_HOST_ARCH_X64
- state.pc = reinterpret_cast<Address>(mcontext.gregs[REG_RIP]);
- state.sp = reinterpret_cast<Address>(mcontext.gregs[REG_RSP]);
- state.fp = reinterpret_cast<Address>(mcontext.gregs[REG_RBP]);
-#elif V8_HOST_ARCH_ARM
-#if defined(__GLIBC__) && !defined(__UCLIBC__) && \
- (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3))
- // Old GLibc ARM versions used a gregs[] array to access the register
- // values from mcontext_t.
- state.pc = reinterpret_cast<Address>(mcontext.gregs[R15]);
- state.sp = reinterpret_cast<Address>(mcontext.gregs[R13]);
- state.fp = reinterpret_cast<Address>(mcontext.gregs[R11]);
-#else
- state.pc = reinterpret_cast<Address>(mcontext.arm_pc);
- state.sp = reinterpret_cast<Address>(mcontext.arm_sp);
- state.fp = reinterpret_cast<Address>(mcontext.arm_fp);
-#endif // defined(__GLIBC__) && !defined(__UCLIBC__) &&
- // (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3))
-#elif V8_HOST_ARCH_ARM64
- state.pc = reinterpret_cast<Address>(mcontext.pc);
- state.sp = reinterpret_cast<Address>(mcontext.sp);
- // FP is an alias for x29.
- state.fp = reinterpret_cast<Address>(mcontext.regs[29]);
-#elif V8_HOST_ARCH_MIPS
- state.pc = reinterpret_cast<Address>(mcontext.pc);
- state.sp = reinterpret_cast<Address>(mcontext.gregs[29]);
- state.fp = reinterpret_cast<Address>(mcontext.gregs[30]);
-#elif V8_HOST_ARCH_MIPS64
- state.pc = reinterpret_cast<Address>(mcontext.pc);
- state.sp = reinterpret_cast<Address>(mcontext.gregs[29]);
- state.fp = reinterpret_cast<Address>(mcontext.gregs[30]);
-#endif // V8_HOST_ARCH_*
-#elif V8_OS_MACOSX
-#if V8_HOST_ARCH_X64
-#if __DARWIN_UNIX03
- state.pc = reinterpret_cast<Address>(mcontext->__ss.__rip);
- state.sp = reinterpret_cast<Address>(mcontext->__ss.__rsp);
- state.fp = reinterpret_cast<Address>(mcontext->__ss.__rbp);
-#else // !__DARWIN_UNIX03
- state.pc = reinterpret_cast<Address>(mcontext->ss.rip);
- state.sp = reinterpret_cast<Address>(mcontext->ss.rsp);
- state.fp = reinterpret_cast<Address>(mcontext->ss.rbp);
-#endif // __DARWIN_UNIX03
-#elif V8_HOST_ARCH_IA32
-#if __DARWIN_UNIX03
- state.pc = reinterpret_cast<Address>(mcontext->__ss.__eip);
- state.sp = reinterpret_cast<Address>(mcontext->__ss.__esp);
- state.fp = reinterpret_cast<Address>(mcontext->__ss.__ebp);
-#else // !__DARWIN_UNIX03
- state.pc = reinterpret_cast<Address>(mcontext->ss.eip);
- state.sp = reinterpret_cast<Address>(mcontext->ss.esp);
- state.fp = reinterpret_cast<Address>(mcontext->ss.ebp);
-#endif // __DARWIN_UNIX03
-#endif // V8_HOST_ARCH_IA32
-#elif V8_OS_FREEBSD
-#if V8_HOST_ARCH_IA32
- state.pc = reinterpret_cast<Address>(mcontext.mc_eip);
- state.sp = reinterpret_cast<Address>(mcontext.mc_esp);
- state.fp = reinterpret_cast<Address>(mcontext.mc_ebp);
-#elif V8_HOST_ARCH_X64
- state.pc = reinterpret_cast<Address>(mcontext.mc_rip);
- state.sp = reinterpret_cast<Address>(mcontext.mc_rsp);
- state.fp = reinterpret_cast<Address>(mcontext.mc_rbp);
-#elif V8_HOST_ARCH_ARM
- state.pc = reinterpret_cast<Address>(mcontext.mc_r15);
- state.sp = reinterpret_cast<Address>(mcontext.mc_r13);
- state.fp = reinterpret_cast<Address>(mcontext.mc_r11);
-#endif // V8_HOST_ARCH_*
-#elif V8_OS_NETBSD
-#if V8_HOST_ARCH_IA32
- state.pc = reinterpret_cast<Address>(mcontext.__gregs[_REG_EIP]);
- state.sp = reinterpret_cast<Address>(mcontext.__gregs[_REG_ESP]);
- state.fp = reinterpret_cast<Address>(mcontext.__gregs[_REG_EBP]);
-#elif V8_HOST_ARCH_X64
- state.pc = reinterpret_cast<Address>(mcontext.__gregs[_REG_RIP]);
- state.sp = reinterpret_cast<Address>(mcontext.__gregs[_REG_RSP]);
- state.fp = reinterpret_cast<Address>(mcontext.__gregs[_REG_RBP]);
-#endif // V8_HOST_ARCH_*
-#elif V8_OS_OPENBSD
-#if V8_HOST_ARCH_IA32
- state.pc = reinterpret_cast<Address>(ucontext->sc_eip);
- state.sp = reinterpret_cast<Address>(ucontext->sc_esp);
- state.fp = reinterpret_cast<Address>(ucontext->sc_ebp);
-#elif V8_HOST_ARCH_X64
- state.pc = reinterpret_cast<Address>(ucontext->sc_rip);
- state.sp = reinterpret_cast<Address>(ucontext->sc_rsp);
- state.fp = reinterpret_cast<Address>(ucontext->sc_rbp);
-#endif // V8_HOST_ARCH_*
-#elif V8_OS_SOLARIS
- state.pc = reinterpret_cast<Address>(mcontext.gregs[REG_PC]);
- state.sp = reinterpret_cast<Address>(mcontext.gregs[REG_SP]);
- state.fp = reinterpret_cast<Address>(mcontext.gregs[REG_FP]);
-#elif V8_OS_QNX
-#if V8_HOST_ARCH_IA32
- state.pc = reinterpret_cast<Address>(mcontext.cpu.eip);
- state.sp = reinterpret_cast<Address>(mcontext.cpu.esp);
- state.fp = reinterpret_cast<Address>(mcontext.cpu.ebp);
-#elif V8_HOST_ARCH_ARM
- state.pc = reinterpret_cast<Address>(mcontext.cpu.gpr[ARM_REG_PC]);
- state.sp = reinterpret_cast<Address>(mcontext.cpu.gpr[ARM_REG_SP]);
- state.fp = reinterpret_cast<Address>(mcontext.cpu.gpr[ARM_REG_FP]);
-#endif // V8_HOST_ARCH_*
-#endif // V8_OS_QNX
+ v8::RegisterState state(*ucontext);
#endif // USE_SIMULATOR
sampler->SampleStack(state);
}
@@ -577,10 +466,10 @@ SamplerThread* SamplerThread::instance_ = NULL;
// StackTracer implementation
//
DISABLE_ASAN void TickSample::Init(Isolate* isolate,
- const RegisterState& regs) {
+ const v8::RegisterState& regs) {
DCHECK(isolate->IsInitialized());
timestamp = base::TimeTicks::HighResolutionNow();
- pc = regs.pc;
+ pc = reinterpret_cast<Address>(regs.pc);
state = isolate->current_vm_state();
// Avoid collecting traces while doing GC.
@@ -603,11 +492,12 @@ DISABLE_ASAN void TickSample::Init(Isolate* isolate,
} else {
// Sample potential return address value for frameless invocation of
// stubs (we'll figure out later, if this value makes sense).
- tos = Memory::Address_at(regs.sp);
+ tos = Memory::Address_at(reinterpret_cast<Address>(regs.sp));
has_external_callback = false;
}
- SafeStackFrameIterator it(isolate, regs.fp, regs.sp, js_entry_sp);
+ SafeStackFrameIterator it(isolate, reinterpret_cast<Address>(regs.fp),
+ reinterpret_cast<Address>(regs.sp), js_entry_sp);
top_frame_type = it.top_frame_type();
unsigned i = 0;
while (!it.done() && i < TickSample::kMaxFramesCount) {
@@ -682,7 +572,7 @@ void Sampler::DecreaseProfilingDepth() {
}
-void Sampler::SampleStack(const RegisterState& state) {
+void Sampler::SampleStack(const v8::RegisterState& state) {
TickSample* sample = isolate_->cpu_profiler()->StartTickSample();
TickSample sample_obj;
if (sample == NULL) sample = &sample_obj;
@@ -725,20 +615,12 @@ void Sampler::DoSample() {
memset(&context, 0, sizeof(context));
context.ContextFlags = CONTEXT_FULL;
if (GetThreadContext(profiled_thread, &context) != 0) {
- RegisterState state;
#if defined(USE_SIMULATOR)
+ v8::RegisterState state;
helper.FillRegisters(&state);
#else
-#if V8_HOST_ARCH_X64
- state.pc = reinterpret_cast<Address>(context.Rip);
- state.sp = reinterpret_cast<Address>(context.Rsp);
- state.fp = reinterpret_cast<Address>(context.Rbp);
-#else
- state.pc = reinterpret_cast<Address>(context.Eip);
- state.sp = reinterpret_cast<Address>(context.Esp);
- state.fp = reinterpret_cast<Address>(context.Ebp);
+ v8::RegisterState state(context);
#endif
-#endif // USE_SIMULATOR
SampleStack(state);
}
ResumeThread(profiled_thread);

Powered by Google App Engine
This is Rietveld 408576698