From: jkummerow@chromium.org Date: Mon, 27 Aug 2012 18:03:38 +0000 (+0000) Subject: Add a new API V8::SetJitCodeEventHandler to push code name and location to users... X-Git-Tag: upstream/4.7.83~16094 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0a6493b5a8274c605e34acb1e66b054fa33c6f59;p=platform%2Fupstream%2Fv8.git Add a new API V8::SetJitCodeEventHandler to push code name and location to users such as profilers. BUG=None TEST=Included in CL. Review URL: https://chromiumcodereview.appspot.com/10795074 Patch from Sigurður Ásgeirsson . git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12389 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/include/v8.h b/include/v8.h index a7b5254..111f9cf 100644 --- a/include/v8.h +++ b/include/v8.h @@ -2945,6 +2945,57 @@ typedef void (*FunctionEntryHook)(uintptr_t function, /** + * A JIT code event is issued each time code is added, moved or removed. + * + * \note removal events are not currently issued. + */ +struct JitCodeEvent { + enum EventType { + CODE_ADDED, + CODE_MOVED, + CODE_REMOVED + }; + + // Type of event. + EventType type; + // Start of the instructions. + void* code_start; + // Size of the instructions. + size_t code_len; + + union { + // Only valid for CODE_ADDED. + struct { + // Name of the object associated with the code, note that the string is + // not zero-terminated. + const char* str; + // Number of chars in str. + size_t len; + } name; + // New location of instructions. Only valid for CODE_MOVED. + void* new_code_start; + }; +}; + +/** + * Option flags passed to the SetJitCodeEventHandler function. + */ +enum JitCodeEventOptions { + kJitCodeEventDefault = 0, + // Generate callbacks for already existent code. + kJitCodeEventEnumExisting = 1 +}; + + +/** + * Callback function passed to SetJitCodeEventHandler. + * + * \param event code add, move or removal event. + */ +typedef void (*JitCodeEventHandler)(const JitCodeEvent* event); + + +/** * Interface for iterating though all external resources in the heap. */ class V8EXPORT ExternalResourceVisitor { // NOLINT @@ -3219,6 +3270,29 @@ class V8EXPORT V8 { static bool SetFunctionEntryHook(FunctionEntryHook entry_hook); /** + * Allows the host application to provide the address of a function that is + * notified each time code is added, moved or removed. + * + * \param options options for the JIT code event handler. + * \param event_handler the JIT code event handler, which will be invoked + * each time code is added, moved or removed. + * \note \p event_handler won't get notified of existent code. + * \note since code removal notifications are not currently issued, the + * \p event_handler may get notifications of code that overlaps earlier + * code notifications. This happens when code areas are reused, and the + * earlier overlapping code areas should therefore be discarded. + * \note the events passed to \p event_handler and the strings they point to + * are not guaranteed to live past each call. The \p event_handler must + * copy strings and other parameters it needs to keep around. + * \note the set of events declared in JitCodeEvent::EventType is expected to + * grow over time, and the JitCodeEvent structure is expected to accrue + * new members. The \p event_handler function must ignore event codes + * it does not recognize to maintain future compatibility. + */ + static void SetJitCodeEventHandler(JitCodeEventOptions options, + JitCodeEventHandler event_handler); + + /** * Adjusts the amount of registered external memory. Used to give * V8 an indication of the amount of externally allocated memory * that is kept alive by JavaScript objects. V8 uses this to decide diff --git a/src/api.cc b/src/api.cc index 0da6ab7..0c92835 100644 --- a/src/api.cc +++ b/src/api.cc @@ -4262,6 +4262,15 @@ bool v8::V8::SetFunctionEntryHook(FunctionEntryHook entry_hook) { } +void v8::V8::SetJitCodeEventHandler( + JitCodeEventOptions options, JitCodeEventHandler event_handler) { + i::Isolate* isolate = i::Isolate::Current(); + // Ensure that logging is initialized for our isolate. + isolate->InitializeLoggingAndCounters(); + isolate->logger()->SetCodeEventHandler(options, event_handler); +} + + bool v8::V8::Dispose() { i::Isolate* isolate = i::Isolate::Current(); if (!ApiCheck(isolate != NULL && isolate->IsDefaultIsolate(), diff --git a/src/compiler.cc b/src/compiler.cc index 88510d5..fac63d5 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -1003,7 +1003,7 @@ void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, // Log the code generation. If source information is available include // script name and line number. Check explicitly whether logging is // enabled as finding the line number is not free. - if (info->isolate()->logger()->is_logging() || + if (info->isolate()->logger()->is_logging_code_events() || CpuProfiler::is_profiling(info->isolate())) { Handle