From: danno@chromium.org Date: Wed, 25 Jul 2012 14:36:38 +0000 (+0000) Subject: MIPS: Implements a new API to set a function entry hook for profiling. X-Git-Tag: upstream/4.7.83~16250 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=816128578697e4777cfbc3da25720e78f3da415d;p=platform%2Fupstream%2Fv8.git MIPS: Implements a new API to set a function entry hook for profiling. Port r12107 (59ee5c88) Original commit message: Exposes a new API; V8::SetFunctionEntryHook. If a non-NULL function entry hook is set, the code generator(s) will invoke on the entry hook at the very start of each generated function. Committed: https://code.google.com/p/v8/source/detail?r=12069 Committed: https://code.google.com/p/v8/source/detail?r=12083 BUG= TEST= Review URL: https://chromiumcodereview.appspot.com/10795021 Patch from Akos Palfi . git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12188 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/mips/code-stubs-mips.cc b/src/mips/code-stubs-mips.cc index 0eea32c..63e3b44 100644 --- a/src/mips/code-stubs-mips.cc +++ b/src/mips/code-stubs-mips.cc @@ -7766,6 +7766,66 @@ void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { } +void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { + if (entry_hook_ != NULL) { + ProfileEntryHookStub stub; + __ push(ra); + __ CallStub(&stub); + __ pop(ra); + } +} + + +void ProfileEntryHookStub::Generate(MacroAssembler* masm) { + // The entry hook is a "push ra" instruction, followed by a call. + // Note: on MIPS "push" is 2 instruction + const int32_t kReturnAddressDistanceFromFunctionStart = + Assembler::kCallTargetAddressOffset + (2 * Assembler::kInstrSize); + + // Save live volatile registers. + __ Push(ra, t1, a1); + const int32_t kNumSavedRegs = 3; + + // Compute the function's address for the first argument. + __ Subu(a0, ra, Operand(kReturnAddressDistanceFromFunctionStart)); + + // The caller's return address is above the saved temporaries. + // Grab that for the second argument to the hook. + __ Addu(a1, sp, Operand(kNumSavedRegs * kPointerSize)); + + // Align the stack if necessary. + int frame_alignment = masm->ActivationFrameAlignment(); + if (frame_alignment > kPointerSize) { + __ mov(t1, sp); + ASSERT(IsPowerOf2(frame_alignment)); + __ And(sp, sp, Operand(-frame_alignment)); + } + +#if defined(V8_HOST_ARCH_MIPS) + __ li(at, Operand(reinterpret_cast(&entry_hook_))); + __ lw(at, MemOperand(at)); +#else + // Under the simulator we need to indirect the entry hook through a + // trampoline function at a known address. + Address trampoline_address = reinterpret_cast
( + reinterpret_cast(EntryHookTrampoline)); + ApiFunction dispatcher(trampoline_address); + __ li(at, Operand(ExternalReference(&dispatcher, + ExternalReference::BUILTIN_CALL, + masm->isolate()))); +#endif + __ Call(at); + + // Restore the stack pointer if needed. + if (frame_alignment > kPointerSize) { + __ mov(sp, t1); + } + + __ Pop(ra, t1, a1); + __ Ret(); +} + + #undef __ } } // namespace v8::internal diff --git a/src/mips/full-codegen-mips.cc b/src/mips/full-codegen-mips.cc index dd4b70e..4a19d6c 100644 --- a/src/mips/full-codegen-mips.cc +++ b/src/mips/full-codegen-mips.cc @@ -143,6 +143,8 @@ void FullCodeGenerator::Generate() { SetFunctionPosition(function()); Comment cmnt(masm_, "[ function compiled by full code generator"); + ProfileEntryHookStub::MaybeCallEntryHook(masm_); + #ifdef DEBUG if (strlen(FLAG_stop_at) > 0 && info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { diff --git a/src/mips/lithium-codegen-mips.cc b/src/mips/lithium-codegen-mips.cc index e924159..9fbb2da 100644 --- a/src/mips/lithium-codegen-mips.cc +++ b/src/mips/lithium-codegen-mips.cc @@ -125,6 +125,8 @@ void LCodeGen::Comment(const char* format, ...) { bool LCodeGen::GeneratePrologue() { ASSERT(is_generating()); + ProfileEntryHookStub::MaybeCallEntryHook(masm_); + #ifdef DEBUG if (strlen(FLAG_stop_at) > 0 && info_->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) {