From f4e563d391d31101bd3ec65c606b1999058460be Mon Sep 17 00:00:00 2001 From: "yurys@chromium.org" Date: Wed, 17 Apr 2013 07:53:12 +0000 Subject: [PATCH] Move StackTracer to sampler.h Apart from tests Sampler is the only client of StackTracer so it is logical to move it into sampler.h BUG=None Review URL: https://codereview.chromium.org/14208012 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14298 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/frames.h | 1 - src/isolate.h | 2 +- src/log.cc | 30 ------------------------------ src/log.h | 7 ------- src/sampler.cc | 31 ++++++++++++++++++++++++++++++- src/sampler.h | 1 + test/cctest/test-log-stack-tracer.cc | 15 +++++++-------- 7 files changed, 39 insertions(+), 48 deletions(-) diff --git a/src/frames.h b/src/frames.h index 39382db..11e8d28 100644 --- a/src/frames.h +++ b/src/frames.h @@ -593,7 +593,6 @@ class JavaScriptFrame: public StandardFrame { inline Object* function_slot_object() const; friend class StackFrameIterator; - friend class StackTracer; }; diff --git a/src/isolate.h b/src/isolate.h index 078dc50..927ad0e 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -649,7 +649,7 @@ class Isolate { } inline Address* handler_address() { return &thread_local_top_.handler_; } - // Bottom JS entry (see StackTracer::Trace in log.cc). + // Bottom JS entry (see StackTracer::Trace in sampler.cc). static Address js_entry_sp(ThreadLocalTop* thread) { return thread->js_entry_sp_; } diff --git a/src/log.cc b/src/log.cc index 11665c3..1538894 100644 --- a/src/log.cc +++ b/src/log.cc @@ -112,36 +112,6 @@ class Profiler: public Thread { // -// StackTracer implementation -// -DISABLE_ASAN void StackTracer::Trace(Isolate* isolate, TickSample* sample) { - ASSERT(isolate->IsInitialized()); - - // Avoid collecting traces while doing GC. - if (sample->state == GC) return; - - const Address js_entry_sp = - Isolate::js_entry_sp(isolate->thread_local_top()); - if (js_entry_sp == 0) { - // Not executing JS now. - return; - } - - sample->external_callback = isolate->external_callback(); - - SafeStackTraceFrameIterator it(isolate, - sample->fp, sample->sp, - sample->sp, js_entry_sp); - int i = 0; - while (!it.done() && i < TickSample::kMaxFramesCount) { - sample->stack[i++] = it.frame()->pc(); - it.Advance(); - } - sample->frames_count = i; -} - - -// // Ticker used to provide ticks to the profiler and the sliding state // window. // diff --git a/src/log.h b/src/log.h index 9661c63..2683330 100644 --- a/src/log.h +++ b/src/log.h @@ -466,7 +466,6 @@ class Logger { friend class LogMessageBuilder; friend class TimeLog; friend class Profiler; - friend class StackTracer; friend class VMState; friend class LoggerTestHelper; @@ -505,12 +504,6 @@ class Logger { }; -// Class that extracts stack trace, used for profiling. -class StackTracer : public AllStatic { - public: - static void Trace(Isolate* isolate, TickSample* sample); -}; - } } // namespace v8::internal diff --git a/src/sampler.cc b/src/sampler.cc index 79c871b..948b054 100644 --- a/src/sampler.cc +++ b/src/sampler.cc @@ -59,6 +59,7 @@ #include "v8.h" +#include "frames-inl.h" #include "log.h" #include "platform.h" #include "simulator.h" @@ -619,6 +620,34 @@ Mutex* SamplerThread::mutex_ = NULL; SamplerThread* SamplerThread::instance_ = NULL; +// +// StackTracer implementation +// +DISABLE_ASAN void TickSample::Trace(Isolate* isolate) { + ASSERT(isolate->IsInitialized()); + + // Avoid collecting traces while doing GC. + if (state == GC) return; + + const Address js_entry_sp = + Isolate::js_entry_sp(isolate->thread_local_top()); + if (js_entry_sp == 0) { + // Not executing JS now. + return; + } + + external_callback = isolate->external_callback(); + + SafeStackTraceFrameIterator it(isolate, fp, sp, sp, js_entry_sp); + int i = 0; + while (!it.done() && i < TickSample::kMaxFramesCount) { + stack[i++] = it.frame()->pc(); + it.Advance(); + } + frames_count = i; +} + + void Sampler::SetUp() { SamplerThread::SetUp(); } @@ -658,7 +687,7 @@ void Sampler::Stop() { } void Sampler::SampleStack(TickSample* sample) { - StackTracer::Trace(isolate_, sample); + sample->Trace(isolate_); if (++samples_taken_ < 0) samples_taken_ = 0; } diff --git a/src/sampler.h b/src/sampler.h index 2b8b75d..a76d8b9 100644 --- a/src/sampler.h +++ b/src/sampler.h @@ -52,6 +52,7 @@ struct TickSample { fp(NULL), external_callback(NULL), frames_count(0) {} + void Trace(Isolate* isolate); StateTag state; // The state of the VM. Address pc; // Instruction pointer. Address sp; // Stack pointer. diff --git a/test/cctest/test-log-stack-tracer.cc b/test/cctest/test-log-stack-tracer.cc index bd7c801..5bfc1d3 100644 --- a/test/cctest/test-log-stack-tracer.cc +++ b/test/cctest/test-log-stack-tracer.cc @@ -51,7 +51,6 @@ using v8::internal::Address; using v8::internal::Handle; using v8::internal::Isolate; using v8::internal::JSFunction; -using v8::internal::StackTracer; using v8::internal::TickSample; @@ -70,7 +69,7 @@ static void DoTrace(Address fp) { // sp is only used to define stack high bound trace_env.sample->sp = reinterpret_cast
(trace_env.sample) - 10240; - StackTracer::Trace(Isolate::Current(), trace_env.sample); + trace_env.sample->Trace(Isolate::Current()); } @@ -258,7 +257,7 @@ static void CreateTraceCallerFunction(const char* func_name, // This test verifies that stack tracing works when called during // execution of a native function called from JS code. In this case, -// StackTracer uses Isolate::c_entry_fp as a starting point for stack +// TickSample::Trace uses Isolate::c_entry_fp as a starting point for stack // walking. TEST(CFromJSStackTrace) { // BUG(1303) Inlining of JSFuncDoTrace() in JSTrace below breaks this test. @@ -285,7 +284,7 @@ TEST(CFromJSStackTrace) { // JSFuncDoTrace() [JS] [captures EBP value and encodes it as Smi] // trace(EBP) [native (extension)] // DoTrace(EBP) [native] - // StackTracer::Trace + // TickSample::Trace CHECK(sample.external_callback); CHECK_EQ(FUNCTION_ADDR(TraceExtension::Trace), sample.external_callback); @@ -300,9 +299,9 @@ TEST(CFromJSStackTrace) { // This test verifies that stack tracing works when called during -// execution of JS code. However, as calling StackTracer requires +// execution of JS code. However, as calling TickSample::Trace requires // entering native code, we can only emulate pure JS by erasing -// Isolate::c_entry_fp value. In this case, StackTracer uses passed frame +// Isolate::c_entry_fp value. In this case, TickSample::Trace uses passed frame // pointer value as a starting point for stack walking. TEST(PureJSStackTrace) { // This test does not pass with inlining enabled since inlined functions @@ -334,7 +333,7 @@ TEST(PureJSStackTrace) { // JSFuncDoTrace() [JS] // js_trace(EBP) [native (extension)] // DoTraceHideCEntryFPAddress(EBP) [native] - // StackTracer::Trace + // TickSample::Trace // CHECK(sample.external_callback); @@ -374,7 +373,7 @@ static int CFunc(int depth) { // This test verifies that stack tracing doesn't crash when called on -// pure native code. StackTracer only unrolls JS code, so we can't +// pure native code. TickSample::Trace only unrolls JS code, so we can't // get any meaningful info here. TEST(PureCStackTrace) { TickSample sample; -- 2.7.4