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
This commit is contained in:
yurys@chromium.org 2013-04-17 07:53:12 +00:00
parent 99a0dabbaf
commit f4e563d391
7 changed files with 39 additions and 48 deletions

View File

@ -593,7 +593,6 @@ class JavaScriptFrame: public StandardFrame {
inline Object* function_slot_object() const;
friend class StackFrameIterator;
friend class StackTracer;
};

View File

@ -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_;
}

View File

@ -111,36 +111,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.

View File

@ -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

View File

@ -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;
}

View File

@ -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.

View File

@ -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<Address>(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;