diff options
author | siggi@chromium.org <siggi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-05 13:17:40 +0000 |
---|---|---|
committer | siggi@chromium.org <siggi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-05 13:17:40 +0000 |
commit | f80612a33af3e8f3ca17b701513211424f98f4c0 (patch) | |
tree | 764e902ab5d233939af60ee382ea0bff18832b47 /base | |
parent | 6fbdbf5fa62466d43af152debf6fa7d5d9954b81 (diff) | |
download | chromium_src-f80612a33af3e8f3ca17b701513211424f98f4c0.zip chromium_src-f80612a33af3e8f3ca17b701513211424f98f4c0.tar.gz chromium_src-f80612a33af3e8f3ca17b701513211424f98f4c0.tar.bz2 |
Implement glue for V8 JIT code profiling.
This change is dependent on the V8-side change https://codereview.chromium.org/16578008/, which is under review.
BUG=257137
Review URL: https://chromiumcodereview.appspot.com/15914002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210305 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/debug/profiler.cc | 70 | ||||
-rw-r--r-- | base/debug/profiler.h | 33 |
2 files changed, 83 insertions, 20 deletions
diff --git a/base/debug/profiler.cc b/base/debug/profiler.cc index b141204..424dfe2 100644 --- a/base/debug/profiler.cc +++ b/base/debug/profiler.cc @@ -82,6 +82,18 @@ ReturnAddressLocationResolver GetProfilerReturnAddrResolutionFunc() { return NULL; } +DynamicFunctionEntryHook GetProfilerDynamicFunctionEntryHookFunc() { + return NULL; +} + +AddDynamicSymbol GetProfilerAddDynamicSymbolFunc() { + return NULL; +} + +MoveDynamicSymbol GetProfilerMoveDynamicSymbolFunc() { + return NULL; +} + #else // defined(OS_WIN) // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx @@ -118,11 +130,24 @@ bool IsBinaryInstrumented() { return state == INSTRUMENTED_IMAGE; } +namespace { + +struct FunctionSearchContext { + const char* name; + FARPROC function; +}; + // Callback function to PEImage::EnumImportChunks. -static bool FindResolutionFunctionInImports( +bool FindResolutionFunctionInImports( const base::win::PEImage &image, const char* module_name, PIMAGE_THUNK_DATA unused_name_table, PIMAGE_THUNK_DATA import_address_table, PVOID cookie) { + FunctionSearchContext* context = + reinterpret_cast<FunctionSearchContext*>(cookie); + + DCHECK_NE(static_cast<FunctionSearchContext*>(NULL), context); + DCHECK_EQ(static_cast<FARPROC>(NULL), context->function); + // Our import address table contains pointers to the functions we import // at this point. Let's retrieve the first such function and use it to // find the module this import was resolved to by the loader. @@ -139,18 +164,10 @@ static bool FindResolutionFunctionInImports( } // See whether this module exports the function we're looking for. - ReturnAddressLocationResolver exported_func = - reinterpret_cast<ReturnAddressLocationResolver>( - ::GetProcAddress(module, "ResolveReturnAddressLocation")); - + FARPROC exported_func = ::GetProcAddress(module, context->name); if (exported_func != NULL) { - ReturnAddressLocationResolver* resolver_func = - reinterpret_cast<ReturnAddressLocationResolver*>(cookie); - DCHECK(resolver_func != NULL); - DCHECK(*resolver_func == NULL); - // We found it, return the function and terminate the enumeration. - *resolver_func = exported_func; + context->function = exported_func; return false; } @@ -158,17 +175,40 @@ static bool FindResolutionFunctionInImports( return true; } -ReturnAddressLocationResolver GetProfilerReturnAddrResolutionFunc() { +template <typename FunctionType> +FunctionType FindFunctionInImports(const char* function_name) { if (!IsBinaryInstrumented()) return NULL; HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase); base::win::PEImage image(this_module); - ReturnAddressLocationResolver resolver_func = NULL; - image.EnumImportChunks(FindResolutionFunctionInImports, &resolver_func); + FunctionSearchContext ctx = { function_name, NULL }; + image.EnumImportChunks(FindResolutionFunctionInImports, &ctx); + + return reinterpret_cast<FunctionType>(ctx.function); +} + +} // namespace + +ReturnAddressLocationResolver GetProfilerReturnAddrResolutionFunc() { + return FindFunctionInImports<ReturnAddressLocationResolver>( + "ResolveReturnAddressLocation"); +} + +DynamicFunctionEntryHook GetProfilerDynamicFunctionEntryHookFunc() { + return FindFunctionInImports<DynamicFunctionEntryHook>( + "OnDynamicFunctionEntry"); +} + +AddDynamicSymbol GetProfilerAddDynamicSymbolFunc() { + return FindFunctionInImports<AddDynamicSymbol>( + "AddDynamicSymbol"); +} - return resolver_func; +MoveDynamicSymbol GetProfilerMoveDynamicSymbolFunc() { + return FindFunctionInImports<MoveDynamicSymbol>( + "MoveDynamicSymbol"); } #endif // defined(OS_WIN) diff --git a/base/debug/profiler.h b/base/debug/profiler.h index d703876..e1dda89 100644 --- a/base/debug/profiler.h +++ b/base/debug/profiler.h @@ -55,11 +55,34 @@ BASE_EXPORT bool IsBinaryInstrumented(); typedef uintptr_t (*ReturnAddressLocationResolver)( uintptr_t return_addr_location); -// If this binary is instrumented and the instrumentation supplies a return -// address resolution function, finds and returns the address resolution -// function. Otherwise returns NULL. -BASE_EXPORT ReturnAddressLocationResolver - GetProfilerReturnAddrResolutionFunc(); +// This type declaration must match V8's FunctionEntryHook. +typedef void (*DynamicFunctionEntryHook)(uintptr_t function, + uintptr_t return_addr_location); + +// The functions below here are to support profiling V8-generated code. +// V8 has provisions for generating a call to an entry hook for newly generated +// JIT code, and it can push symbol information on code generation and advise +// when the garbage collector moves code. The functions declarations below here +// make glue between V8's facilities and a profiler. + +// This type declaration must match V8's FunctionEntryHook. +typedef void (*DynamicFunctionEntryHook)(uintptr_t function, + uintptr_t return_addr_location); + +typedef void (*AddDynamicSymbol)(const void* address, + size_t length, + const char* name, + size_t name_len); +typedef void (*MoveDynamicSymbol)(const void* address, const void* new_address); + + +// If this binary is instrumented and the instrumentation supplies a function +// for each of those purposes, find and return the function in question. +// Otherwise returns NULL. +BASE_EXPORT ReturnAddressLocationResolver GetProfilerReturnAddrResolutionFunc(); +BASE_EXPORT DynamicFunctionEntryHook GetProfilerDynamicFunctionEntryHookFunc(); +BASE_EXPORT AddDynamicSymbol GetProfilerAddDynamicSymbolFunc(); +BASE_EXPORT MoveDynamicSymbol GetProfilerMoveDynamicSymbolFunc(); } // namespace debug } // namespace base |