2009-02-25 16:00:21 +00:00
|
|
|
// Copyright 2006-2009 the V8 project authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// Tests of profiler-related functions from log.h
|
|
|
|
|
2009-02-26 14:30:30 +00:00
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-02-26 13:45:11 +00:00
|
|
|
|
2009-02-25 16:00:21 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
2009-05-07 09:24:43 +00:00
|
|
|
#include "codegen.h"
|
2009-02-25 16:00:21 +00:00
|
|
|
#include "log.h"
|
2009-03-20 14:49:12 +00:00
|
|
|
#include "top.h"
|
2009-02-25 16:00:21 +00:00
|
|
|
#include "cctest.h"
|
2009-05-07 09:24:43 +00:00
|
|
|
#include "disassembler.h"
|
2009-05-15 11:09:51 +00:00
|
|
|
#include "register-allocator-inl.h"
|
2009-02-25 16:00:21 +00:00
|
|
|
|
|
|
|
using v8::Function;
|
|
|
|
using v8::Local;
|
|
|
|
using v8::Object;
|
|
|
|
using v8::Script;
|
|
|
|
using v8::String;
|
|
|
|
using v8::Value;
|
|
|
|
|
|
|
|
using v8::internal::byte;
|
2009-05-07 09:24:43 +00:00
|
|
|
using v8::internal::Address;
|
2009-02-25 16:00:21 +00:00
|
|
|
using v8::internal::Handle;
|
|
|
|
using v8::internal::JSFunction;
|
|
|
|
using v8::internal::StackTracer;
|
|
|
|
using v8::internal::TickSample;
|
2009-03-20 14:49:12 +00:00
|
|
|
using v8::internal::Top;
|
2009-02-25 16:00:21 +00:00
|
|
|
|
2009-05-07 09:24:43 +00:00
|
|
|
namespace i = v8::internal;
|
|
|
|
|
2009-02-25 16:00:21 +00:00
|
|
|
|
|
|
|
static v8::Persistent<v8::Context> env;
|
|
|
|
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
TickSample* sample;
|
2009-06-02 09:33:17 +00:00
|
|
|
} trace_env = { NULL };
|
2009-02-25 16:00:21 +00:00
|
|
|
|
|
|
|
|
2009-06-02 09:33:17 +00:00
|
|
|
static void InitTraceEnv(TickSample* sample) {
|
2009-02-25 16:00:21 +00:00
|
|
|
trace_env.sample = sample;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-07 09:24:43 +00:00
|
|
|
static void DoTrace(Address fp) {
|
Fix issue 553: function frame is skipped in profile when compare stub is called.
The problem appeared due to a fact that stubs doesn't create a stack
frame, reusing the stack frame of the caller function. When building
stack traces, the current function is retrieved from PC, and its
callees are retrieved by traversing the stack backwards. Thus, for
stubs, the stub itself was discovered via PC, and then stub's caller's
caller was retrieved from stack.
To fix this problem, a pointer to JSFunction object is now captured
from the topmost stack frame, and is saved into stack trace log
record. Then a simple heuristics is applied whether a referred
function should be added to decoded stack, or not, to avoid reporting
the same function twice (from PC and from the pointer.)
BUG=553
TEST=added to mjsunit/tools/tickprocessor
Review URL: http://codereview.chromium.org/546089
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3673 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2010-01-21 16:42:41 +00:00
|
|
|
trace_env.sample->fp = fp;
|
2009-03-20 14:49:12 +00:00
|
|
|
// sp is only used to define stack high bound
|
|
|
|
trace_env.sample->sp =
|
Fix issue 553: function frame is skipped in profile when compare stub is called.
The problem appeared due to a fact that stubs doesn't create a stack
frame, reusing the stack frame of the caller function. When building
stack traces, the current function is retrieved from PC, and its
callees are retrieved by traversing the stack backwards. Thus, for
stubs, the stub itself was discovered via PC, and then stub's caller's
caller was retrieved from stack.
To fix this problem, a pointer to JSFunction object is now captured
from the topmost stack frame, and is saved into stack trace log
record. Then a simple heuristics is applied whether a referred
function should be added to decoded stack, or not, to avoid reporting
the same function twice (from PC and from the pointer.)
BUG=553
TEST=added to mjsunit/tools/tickprocessor
Review URL: http://codereview.chromium.org/546089
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3673 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2010-01-21 16:42:41 +00:00
|
|
|
reinterpret_cast<Address>(trace_env.sample) - 10240;
|
2009-06-02 09:33:17 +00:00
|
|
|
StackTracer::Trace(trace_env.sample);
|
2009-02-25 16:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-20 14:49:12 +00:00
|
|
|
// Hide c_entry_fp to emulate situation when sampling is done while
|
|
|
|
// pure JS code is being executed
|
2009-05-07 09:24:43 +00:00
|
|
|
static void DoTraceHideCEntryFPAddress(Address fp) {
|
2009-03-20 14:49:12 +00:00
|
|
|
v8::internal::Address saved_c_frame_fp = *(Top::c_entry_fp_address());
|
|
|
|
CHECK(saved_c_frame_fp);
|
|
|
|
*(Top::c_entry_fp_address()) = 0;
|
2009-02-25 16:00:21 +00:00
|
|
|
DoTrace(fp);
|
2009-03-20 14:49:12 +00:00
|
|
|
*(Top::c_entry_fp_address()) = saved_c_frame_fp;
|
2009-02-25 16:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// --- T r a c e E x t e n s i o n ---
|
|
|
|
|
|
|
|
class TraceExtension : public v8::Extension {
|
|
|
|
public:
|
|
|
|
TraceExtension() : v8::Extension("v8/trace", kSource) { }
|
|
|
|
virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
|
2009-03-20 14:49:12 +00:00
|
|
|
v8::Handle<String> name);
|
2009-02-25 16:00:21 +00:00
|
|
|
static v8::Handle<v8::Value> Trace(const v8::Arguments& args);
|
2009-03-20 14:49:12 +00:00
|
|
|
static v8::Handle<v8::Value> JSTrace(const v8::Arguments& args);
|
2009-06-02 09:33:17 +00:00
|
|
|
static v8::Handle<v8::Value> JSEntrySP(const v8::Arguments& args);
|
|
|
|
static v8::Handle<v8::Value> JSEntrySPLevel2(const v8::Arguments& args);
|
2009-02-25 16:00:21 +00:00
|
|
|
private:
|
2009-05-07 09:24:43 +00:00
|
|
|
static Address GetFP(const v8::Arguments& args);
|
2009-02-25 16:00:21 +00:00
|
|
|
static const char* kSource;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-03-20 14:49:12 +00:00
|
|
|
const char* TraceExtension::kSource =
|
|
|
|
"native function trace();"
|
2009-06-02 09:33:17 +00:00
|
|
|
"native function js_trace();"
|
|
|
|
"native function js_entry_sp();"
|
|
|
|
"native function js_entry_sp_level2();";
|
2009-02-25 16:00:21 +00:00
|
|
|
|
|
|
|
v8::Handle<v8::FunctionTemplate> TraceExtension::GetNativeFunction(
|
2009-03-20 14:49:12 +00:00
|
|
|
v8::Handle<String> name) {
|
|
|
|
if (name->Equals(String::New("trace"))) {
|
|
|
|
return v8::FunctionTemplate::New(TraceExtension::Trace);
|
|
|
|
} else if (name->Equals(String::New("js_trace"))) {
|
|
|
|
return v8::FunctionTemplate::New(TraceExtension::JSTrace);
|
2009-06-02 09:33:17 +00:00
|
|
|
} else if (name->Equals(String::New("js_entry_sp"))) {
|
|
|
|
return v8::FunctionTemplate::New(TraceExtension::JSEntrySP);
|
|
|
|
} else if (name->Equals(String::New("js_entry_sp_level2"))) {
|
|
|
|
return v8::FunctionTemplate::New(TraceExtension::JSEntrySPLevel2);
|
2009-03-20 14:49:12 +00:00
|
|
|
} else {
|
|
|
|
CHECK(false);
|
|
|
|
return v8::Handle<v8::FunctionTemplate>();
|
|
|
|
}
|
2009-02-25 16:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-07 09:24:43 +00:00
|
|
|
Address TraceExtension::GetFP(const v8::Arguments& args) {
|
2009-02-25 16:00:21 +00:00
|
|
|
CHECK_EQ(1, args.Length());
|
2009-07-31 11:07:05 +00:00
|
|
|
// CodeGenerator::GenerateGetFramePointer pushes EBP / RBP value
|
|
|
|
// on stack. In 64-bit mode we can't use Smi operations code because
|
|
|
|
// they check that value is within Smi bounds.
|
|
|
|
Address fp = *reinterpret_cast<Address*>(*args[0]);
|
2009-05-07 09:24:43 +00:00
|
|
|
printf("Trace: %p\n", fp);
|
2009-03-20 14:49:12 +00:00
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Handle<v8::Value> TraceExtension::Trace(const v8::Arguments& args) {
|
|
|
|
DoTrace(GetFP(args));
|
|
|
|
return v8::Undefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Handle<v8::Value> TraceExtension::JSTrace(const v8::Arguments& args) {
|
|
|
|
DoTraceHideCEntryFPAddress(GetFP(args));
|
2009-02-25 16:00:21 +00:00
|
|
|
return v8::Undefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-02 09:33:17 +00:00
|
|
|
static Address GetJsEntrySp() {
|
|
|
|
CHECK_NE(NULL, Top::GetCurrentThread());
|
|
|
|
return Top::js_entry_sp(Top::GetCurrentThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Handle<v8::Value> TraceExtension::JSEntrySP(const v8::Arguments& args) {
|
|
|
|
CHECK_NE(0, GetJsEntrySp());
|
|
|
|
return v8::Undefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::Handle<v8::Value> TraceExtension::JSEntrySPLevel2(
|
|
|
|
const v8::Arguments& args) {
|
|
|
|
v8::HandleScope scope;
|
|
|
|
const Address js_entry_sp = GetJsEntrySp();
|
|
|
|
CHECK_NE(0, js_entry_sp);
|
|
|
|
CompileRun("js_entry_sp();");
|
|
|
|
CHECK_EQ(js_entry_sp, GetJsEntrySp());
|
|
|
|
return v8::Undefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-25 16:00:21 +00:00
|
|
|
static TraceExtension kTraceExtension;
|
|
|
|
v8::DeclareExtension kTraceExtensionDeclaration(&kTraceExtension);
|
|
|
|
|
|
|
|
|
2009-05-07 09:24:43 +00:00
|
|
|
static void InitializeVM() {
|
|
|
|
if (env.IsEmpty()) {
|
|
|
|
v8::HandleScope scope;
|
|
|
|
const char* extensions[] = { "v8/trace" };
|
|
|
|
v8::ExtensionConfiguration config(1, extensions);
|
|
|
|
env = v8::Context::New(&config);
|
|
|
|
}
|
|
|
|
v8::HandleScope scope;
|
|
|
|
env->Enter();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 12:42:47 +00:00
|
|
|
static Handle<JSFunction> CompileFunction(const char* source) {
|
|
|
|
Handle<JSFunction> result(JSFunction::cast(
|
|
|
|
*v8::Utils::OpenHandle(*Script::Compile(String::New(source)))));
|
|
|
|
return result;
|
2009-05-07 09:24:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Local<Value> GetGlobalProperty(const char* name) {
|
|
|
|
return env->Global()->Get(String::New(name));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 12:42:47 +00:00
|
|
|
static Handle<JSFunction> GetGlobalJSFunction(const char* name) {
|
|
|
|
Handle<JSFunction> result(JSFunction::cast(
|
|
|
|
*v8::Utils::OpenHandle(*GetGlobalProperty(name))));
|
|
|
|
return result;
|
2009-05-07 09:24:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-18 14:19:33 +00:00
|
|
|
static void CheckObjectIsJSFunction(const char* func_name,
|
|
|
|
Address addr) {
|
|
|
|
i::Object* obj = reinterpret_cast<i::Object*>(addr);
|
|
|
|
CHECK(obj->IsJSFunction());
|
|
|
|
CHECK(JSFunction::cast(obj)->shared()->name()->IsString());
|
|
|
|
i::SmartPointer<char> found_name =
|
|
|
|
i::String::cast(
|
|
|
|
JSFunction::cast(
|
|
|
|
obj)->shared()->name())->ToCString();
|
|
|
|
CHECK_EQ(func_name, *found_name);
|
2009-05-07 09:24:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void SetGlobalProperty(const char* name, Local<Value> value) {
|
|
|
|
env->Global()->Set(String::New(name), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Handle<v8::internal::String> NewString(const char* s) {
|
|
|
|
return i::Factory::NewStringFromAscii(i::CStrVector(s));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2009-05-07 09:24:43 +00:00
|
|
|
|
|
|
|
class CodeGeneratorPatcher {
|
|
|
|
public:
|
|
|
|
CodeGeneratorPatcher() {
|
|
|
|
CodeGenerator::InlineRuntimeLUT genGetFramePointer =
|
2010-03-11 09:27:12 +00:00
|
|
|
{&CodeGenerator::GenerateGetFramePointer, "_GetFramePointer", 0};
|
2010-04-07 08:18:51 +00:00
|
|
|
// _RandomHeapNumber is just used as a dummy function that has zero
|
|
|
|
// arguments, the same as the _GetFramePointer function we actually patch
|
|
|
|
// in.
|
2009-05-07 09:24:43 +00:00
|
|
|
bool result = CodeGenerator::PatchInlineRuntimeEntry(
|
2010-04-07 08:18:51 +00:00
|
|
|
NewString("_RandomHeapNumber"),
|
2009-05-07 09:24:43 +00:00
|
|
|
genGetFramePointer, &oldInlineEntry);
|
|
|
|
CHECK(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
~CodeGeneratorPatcher() {
|
|
|
|
CHECK(CodeGenerator::PatchInlineRuntimeEntry(
|
|
|
|
NewString("_GetFramePointer"),
|
|
|
|
oldInlineEntry, NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CodeGenerator::InlineRuntimeLUT oldInlineEntry;
|
|
|
|
};
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
|
|
|
|
// Creates a global function named 'func_name' that calls the tracing
|
|
|
|
// function 'trace_func_name' with an actual EBP register value,
|
|
|
|
// shifted right to be presented as Smi.
|
|
|
|
static void CreateTraceCallerFunction(const char* func_name,
|
|
|
|
const char* trace_func_name) {
|
|
|
|
i::EmbeddedVector<char, 256> trace_call_buf;
|
|
|
|
i::OS::SNPrintF(trace_call_buf, "%s(%%_GetFramePointer());", trace_func_name);
|
|
|
|
|
|
|
|
// Compile the script.
|
|
|
|
i::CodeGeneratorPatcher patcher;
|
|
|
|
bool allow_natives_syntax = i::FLAG_allow_natives_syntax;
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2010-03-23 12:42:47 +00:00
|
|
|
Handle<JSFunction> func = CompileFunction(trace_call_buf.start());
|
2009-05-07 09:24:43 +00:00
|
|
|
CHECK(!func.is_null());
|
|
|
|
i::FLAG_allow_natives_syntax = allow_natives_syntax;
|
2010-05-18 14:19:33 +00:00
|
|
|
func->shared()->set_name(*NewString(func_name));
|
2009-05-07 09:24:43 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
v8::internal::Code* func_code = func->code();
|
|
|
|
CHECK(func_code->IsCode());
|
|
|
|
func_code->Print();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SetGlobalProperty(func_name, v8::ToApi<Value>(func));
|
2010-03-23 12:42:47 +00:00
|
|
|
CHECK_EQ(*func, *GetGlobalJSFunction(func_name));
|
2009-05-07 09:24:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-24 08:46:17 +00:00
|
|
|
// This test verifies that stack tracing works when called during
|
|
|
|
// execution of a native function called from JS code. In this case,
|
|
|
|
// StackTracer uses Top::c_entry_fp as a starting point for stack
|
|
|
|
// walking.
|
2009-05-07 09:24:43 +00:00
|
|
|
TEST(CFromJSStackTrace) {
|
2010-05-19 09:07:33 +00:00
|
|
|
// TODO(711) The hack of replacing the inline runtime function
|
|
|
|
// RandomHeapNumber with GetFrameNumber does not work with the way the full
|
|
|
|
// compiler generates inline runtime calls.
|
2010-05-25 14:08:17 +00:00
|
|
|
i::FLAG_always_full_compiler = false;
|
2010-05-19 09:07:33 +00:00
|
|
|
|
2009-05-07 09:24:43 +00:00
|
|
|
TickSample sample;
|
2009-06-02 09:33:17 +00:00
|
|
|
InitTraceEnv(&sample);
|
2009-05-07 09:24:43 +00:00
|
|
|
|
|
|
|
InitializeVM();
|
|
|
|
v8::HandleScope scope;
|
2010-03-24 08:46:17 +00:00
|
|
|
// Create global function JSFuncDoTrace which calls
|
|
|
|
// extension function trace() with the current frame pointer value.
|
2009-05-07 09:24:43 +00:00
|
|
|
CreateTraceCallerFunction("JSFuncDoTrace", "trace");
|
2010-03-23 12:42:47 +00:00
|
|
|
Local<Value> result = CompileRun(
|
2009-05-07 09:24:43 +00:00
|
|
|
"function JSTrace() {"
|
|
|
|
" JSFuncDoTrace();"
|
|
|
|
"};\n"
|
2010-03-23 12:42:47 +00:00
|
|
|
"JSTrace();\n"
|
|
|
|
"true;");
|
|
|
|
CHECK(!result.IsEmpty());
|
2010-03-24 08:46:17 +00:00
|
|
|
// When stack tracer is invoked, the stack should look as follows:
|
|
|
|
// script [JS]
|
|
|
|
// JSTrace() [JS]
|
|
|
|
// JSFuncDoTrace() [JS] [captures EBP value and encodes it as Smi]
|
|
|
|
// trace(EBP encoded as Smi) [native (extension)]
|
|
|
|
// DoTrace(EBP) [native]
|
|
|
|
// StackTracer::Trace
|
2009-05-07 09:24:43 +00:00
|
|
|
CHECK_GT(sample.frames_count, 1);
|
2010-03-24 08:46:17 +00:00
|
|
|
// Stack tracing will start from the first JS function, i.e. "JSFuncDoTrace"
|
2010-05-18 14:19:33 +00:00
|
|
|
CheckObjectIsJSFunction("JSFuncDoTrace", sample.stack[0]);
|
|
|
|
CheckObjectIsJSFunction("JSTrace", sample.stack[1]);
|
2009-05-07 09:24:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-24 08:46:17 +00:00
|
|
|
// This test verifies that stack tracing works when called during
|
|
|
|
// execution of JS code. However, as calling StackTracer requires
|
|
|
|
// entering native code, we can only emulate pure JS by erasing
|
|
|
|
// Top::c_entry_fp value. In this case, StackTracer uses passed frame
|
|
|
|
// pointer value as a starting point for stack walking.
|
2009-05-07 09:24:43 +00:00
|
|
|
TEST(PureJSStackTrace) {
|
2010-05-19 09:07:33 +00:00
|
|
|
// TODO(711) The hack of replacing the inline runtime function
|
|
|
|
// RandomHeapNumber with GetFrameNumber does not work with the way the full
|
|
|
|
// compiler generates inline runtime calls.
|
2010-05-25 14:08:17 +00:00
|
|
|
i::FLAG_always_full_compiler = false;
|
2010-05-19 09:07:33 +00:00
|
|
|
|
2009-05-07 09:24:43 +00:00
|
|
|
TickSample sample;
|
2009-06-02 09:33:17 +00:00
|
|
|
InitTraceEnv(&sample);
|
2009-05-07 09:24:43 +00:00
|
|
|
|
|
|
|
InitializeVM();
|
|
|
|
v8::HandleScope scope;
|
2010-03-24 08:46:17 +00:00
|
|
|
// Create global function JSFuncDoTrace which calls
|
|
|
|
// extension function js_trace() with the current frame pointer value.
|
2009-05-07 09:24:43 +00:00
|
|
|
CreateTraceCallerFunction("JSFuncDoTrace", "js_trace");
|
2010-03-23 12:42:47 +00:00
|
|
|
Local<Value> result = CompileRun(
|
2009-05-07 09:24:43 +00:00
|
|
|
"function JSTrace() {"
|
|
|
|
" JSFuncDoTrace();"
|
|
|
|
"};\n"
|
|
|
|
"function OuterJSTrace() {"
|
|
|
|
" JSTrace();"
|
|
|
|
"};\n"
|
2010-03-23 12:42:47 +00:00
|
|
|
"OuterJSTrace();\n"
|
|
|
|
"true;");
|
|
|
|
CHECK(!result.IsEmpty());
|
2010-03-24 08:46:17 +00:00
|
|
|
// When stack tracer is invoked, the stack should look as follows:
|
|
|
|
// script [JS]
|
|
|
|
// OuterJSTrace() [JS]
|
|
|
|
// JSTrace() [JS]
|
|
|
|
// JSFuncDoTrace() [JS] [captures EBP value and encodes it as Smi]
|
|
|
|
// js_trace(EBP encoded as Smi) [native (extension)]
|
|
|
|
// DoTraceHideCEntryFPAddress(EBP) [native]
|
|
|
|
// StackTracer::Trace
|
|
|
|
//
|
|
|
|
// The last JS function called. It is only visible through
|
|
|
|
// sample.function, as its return address is above captured EBP value.
|
2010-01-22 09:42:24 +00:00
|
|
|
CHECK_EQ(GetGlobalJSFunction("JSFuncDoTrace")->address(),
|
|
|
|
sample.function);
|
2009-05-07 09:24:43 +00:00
|
|
|
CHECK_GT(sample.frames_count, 1);
|
|
|
|
// Stack sampling will start from the caller of JSFuncDoTrace, i.e. "JSTrace"
|
2010-05-18 14:19:33 +00:00
|
|
|
CheckObjectIsJSFunction("JSTrace", sample.stack[0]);
|
|
|
|
CheckObjectIsJSFunction("OuterJSTrace", sample.stack[1]);
|
2009-05-07 09:24:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-27 08:50:24 +00:00
|
|
|
static void CFuncDoTrace(byte dummy_parameter) {
|
2009-05-07 09:24:43 +00:00
|
|
|
Address fp;
|
2009-03-20 14:49:12 +00:00
|
|
|
#ifdef __GNUC__
|
2009-05-07 09:24:43 +00:00
|
|
|
fp = reinterpret_cast<Address>(__builtin_frame_address(0));
|
2009-10-27 08:50:24 +00:00
|
|
|
#elif defined _MSC_VER
|
|
|
|
// Approximate a frame pointer address. We compile without base pointers,
|
|
|
|
// so we can't trust ebp/rbp.
|
2009-10-27 13:26:22 +00:00
|
|
|
fp = &dummy_parameter - 2 * sizeof(void*); // NOLINT
|
2009-10-27 08:50:24 +00:00
|
|
|
#else
|
|
|
|
#error Unexpected platform.
|
2009-03-20 14:49:12 +00:00
|
|
|
#endif
|
|
|
|
DoTrace(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int CFunc(int depth) {
|
|
|
|
if (depth <= 0) {
|
2009-10-27 08:50:24 +00:00
|
|
|
CFuncDoTrace(0);
|
2009-03-20 14:49:12 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return CFunc(depth - 1) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-24 08:46:17 +00:00
|
|
|
// This test verifies that stack tracing doesn't crash when called on
|
|
|
|
// pure native code. StackTracer only unrolls JS code, so we can't
|
|
|
|
// get any meaningful info here.
|
2009-03-20 14:49:12 +00:00
|
|
|
TEST(PureCStackTrace) {
|
|
|
|
TickSample sample;
|
2009-06-02 09:33:17 +00:00
|
|
|
InitTraceEnv(&sample);
|
2009-03-20 14:49:12 +00:00
|
|
|
// Check that sampler doesn't crash
|
|
|
|
CHECK_EQ(10, CFunc(10));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-02 09:33:17 +00:00
|
|
|
TEST(JsEntrySp) {
|
|
|
|
InitializeVM();
|
|
|
|
v8::HandleScope scope;
|
|
|
|
CHECK_EQ(0, GetJsEntrySp());
|
|
|
|
CompileRun("a = 1; b = a + 1;");
|
|
|
|
CHECK_EQ(0, GetJsEntrySp());
|
|
|
|
CompileRun("js_entry_sp();");
|
|
|
|
CHECK_EQ(0, GetJsEntrySp());
|
|
|
|
CompileRun("js_entry_sp_level2();");
|
|
|
|
CHECK_EQ(0, GetJsEntrySp());
|
|
|
|
}
|
|
|
|
|
2009-02-26 14:30:30 +00:00
|
|
|
#endif // ENABLE_LOGGING_AND_PROFILING
|