X64: enable stack sampling in profiler.

Added necessary code to initialize Top::js_entry_sp value.
Renamed 'test-log-ia32' test to 'test-log-stack-tracer' and enabled it in 64-bit version.

Review URL: http://codereview.chromium.org/160446


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2597 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 3a472fad
......@@ -5154,11 +5154,10 @@ void CodeGenerator::GenerateObjectEquals(ZoneList<Expression*>* args) {
void CodeGenerator::GenerateGetFramePointer(ZoneList<Expression*>* args) {
ASSERT(args->length() == 0);
ASSERT(kSmiTagSize == 1 && kSmiTag == 0); // shifting code depends on this
ASSERT(kSmiTag == 0); // EBP value is aligned, so it should look like Smi.
Result ebp_as_smi = allocator_->Allocate();
ASSERT(ebp_as_smi.is_valid());
__ mov(ebp_as_smi.reg(), Operand(ebp));
__ shr(ebp_as_smi.reg(), kSmiTagSize);
frame_->Push(&ebp_as_smi);
}
......@@ -7786,7 +7785,7 @@ void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) {
// If this is the outermost JS call, set js_entry_sp value.
ExternalReference js_entry_sp(Top::k_js_entry_sp_address);
__ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0));
__ j(NegateCondition(equal), &not_outermost_js);
__ j(not_equal, &not_outermost_js);
__ mov(Operand::StaticVariable(js_entry_sp), ebp);
__ bind(&not_outermost_js);
#endif
......@@ -7837,7 +7836,7 @@ void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) {
// If current EBP value is the same as js_entry_sp value, it means that
// the current function is the outermost.
__ cmp(ebp, Operand::StaticVariable(js_entry_sp));
__ j(NegateCondition(equal), &not_outermost_js_2);
__ j(not_equal, &not_outermost_js_2);
__ mov(Operand::StaticVariable(js_entry_sp), Immediate(0));
__ bind(&not_outermost_js_2);
#endif
......
......@@ -603,7 +603,7 @@ class CodeGenerator: public AstVisitor {
friend class Reference;
friend class Result;
friend class CodeGeneratorPatcher; // Used in test-log-ia32.cc
friend class CodeGeneratorPatcher; // Used in test-log-stack-tracer.cc
DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
};
......
......@@ -3421,6 +3421,16 @@ void CodeGenerator::GenerateObjectEquals(ZoneList<Expression*>* args) {
}
void CodeGenerator::GenerateGetFramePointer(ZoneList<Expression*>* args) {
ASSERT(args->length() == 0);
ASSERT(kSmiTag == 0); // RBP value is aligned, so it should look like Smi.
Result rbp_as_smi = allocator_->Allocate();
ASSERT(rbp_as_smi.is_valid());
__ movq(rbp_as_smi.reg(), rbp);
frame_->Push(&rbp_as_smi);
}
void CodeGenerator::GenerateRandomPositiveSmi(ZoneList<Expression*>* args) {
ASSERT(args->length() == 0);
frame_->SpillAll();
......@@ -6573,6 +6583,9 @@ void CEntryStub::GenerateBody(MacroAssembler* masm, bool is_debug_break) {
void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) {
Label invoke, exit;
#ifdef ENABLE_LOGGING_AND_PROFILING
Label not_outermost_js, not_outermost_js_2;
#endif
// Setup frame.
__ push(rbp);
......@@ -6598,6 +6611,17 @@ void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) {
__ load_rax(c_entry_fp);
__ push(rax);
#ifdef ENABLE_LOGGING_AND_PROFILING
// If this is the outermost JS call, set js_entry_sp value.
ExternalReference js_entry_sp(Top::k_js_entry_sp_address);
__ load_rax(js_entry_sp);
__ testq(rax, rax);
__ j(not_zero, &not_outermost_js);
__ movq(rax, rbp);
__ store_rax(js_entry_sp);
__ bind(&not_outermost_js);
#endif
// Call a faked try-block that does the invoke.
__ call(&invoke);
......@@ -6640,6 +6664,16 @@ void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) {
// Pop next_sp.
__ addq(rsp, Immediate(StackHandlerConstants::kSize - kPointerSize));
#ifdef ENABLE_LOGGING_AND_PROFILING
// If current EBP value is the same as js_entry_sp value, it means that
// the current function is the outermost.
__ movq(kScratchRegister, js_entry_sp);
__ cmpq(rbp, Operand(kScratchRegister, 0));
__ j(not_equal, &not_outermost_js_2);
__ movq(Operand(kScratchRegister, 0), Immediate(0));
__ bind(&not_outermost_js_2);
#endif
// Restore the top frame descriptor from the stack.
__ bind(&exit);
__ movq(kScratchRegister, ExternalReference(Top::k_c_entry_fp_address));
......
......@@ -534,6 +534,8 @@ class CodeGenerator: public AstVisitor {
void GenerateLog(ZoneList<Expression*>* args);
void GenerateGetFramePointer(ZoneList<Expression*>* args);
// Fast support for Math.random().
void GenerateRandomPositiveSmi(ZoneList<Expression*>* args);
......@@ -593,6 +595,8 @@ class CodeGenerator: public AstVisitor {
friend class Reference;
friend class Result;
friend class CodeGeneratorPatcher; // Used in test-log-stack-tracer.cc
DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
};
......
......@@ -63,9 +63,9 @@ SOURCES = {
'arch:ia32': [
'test-assembler-ia32.cc',
'test-disasm-ia32.cc',
'test-log-ia32.cc'
'test-log-stack-tracer.cc'
],
'arch:x64': ['test-assembler-x64.cc'],
'arch:x64': ['test-assembler-x64.cc', 'test-log-stack-tracer.cc'],
'os:linux': ['test-platform-linux.cc'],
'os:macos': ['test-platform-macos.cc'],
'os:nullos': ['test-platform-nullos.cc'],
......
......@@ -50,7 +50,7 @@ static void DoTrace(Address fp) {
trace_env.sample->fp = reinterpret_cast<uintptr_t>(fp);
// sp is only used to define stack high bound
trace_env.sample->sp =
reinterpret_cast<unsigned int>(trace_env.sample) - 10240;
reinterpret_cast<uintptr_t>(trace_env.sample) - 10240;
StackTracer::Trace(trace_env.sample);
}
......@@ -130,7 +130,10 @@ v8::Handle<v8::FunctionTemplate> TraceExtension::GetNativeFunction(
Address TraceExtension::GetFP(const v8::Arguments& args) {
CHECK_EQ(1, args.Length());
Address fp = reinterpret_cast<Address>(args[0]->Int32Value() << 2);
// 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]);
printf("Trace: %p\n", fp);
return fp;
}
......@@ -330,8 +333,11 @@ static void CFuncDoTrace() {
Address fp;
#ifdef __GNUC__
fp = reinterpret_cast<Address>(__builtin_frame_address(0));
#elif defined _MSC_VER
#elif defined _MSC_VER && defined V8_TARGET_ARCH_IA32
__asm mov [fp], ebp // NOLINT
#elif defined _MSC_VER && defined V8_TARGET_ARCH_X64
// FIXME: I haven't really tried to compile it.
__asm movq [fp], rbp // NOLINT
#endif
DoTrace(fp);
}
......
......@@ -210,7 +210,7 @@
>
</File>
<File
RelativePath="..\..\test\cctest\test-log-ia32.cc"
RelativePath="..\..\test\cctest\test-log-stack-tracer.cc"
>
</File>
<File
......
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