Commit ee21e390 authored by Matheus Marchini's avatar Matheus Marchini Committed by Commit Bot

[log] report code relocation through CodeEventHandler

Also report code relocation events through the public CodeEventHandler
API, so that embedders can expose this information to external
profilers, allowing those profilers to correctly translate function
names even after they were relocated.

R=bmeurer@chromium.org, jgruber@chromium.org, yangguo@chromium.org

Change-Id: I8795186f5f5c58ede9054e4b83e2d290d92b6e00
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1802657Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63943}
parent ae764cc3
......@@ -125,6 +125,7 @@ Marcin Cieślak <saper@marcincieslak.com>
Marcin Wiącek <marcin@mwiacek.com>
Mateusz Czeladka <mateusz.szczap@gmail.com>
Matheus Marchini <mat@mmarchini.me>
Matheus Marchini <mmarchini@netflix.com>
Mathias Bynens <mathias@qiwi.be>
Matt Hanselman <mjhanselman@gmail.com>
Matthew Sporleder <msporleder@gmail.com>
......
......@@ -976,7 +976,8 @@ struct HeapStatsUpdate {
V(LazyCompile) \
V(RegExp) \
V(Script) \
V(Stub)
V(Stub) \
V(Relocation)
/**
* Note that this enum may be extended in the future. Please include a default
......@@ -1009,10 +1010,12 @@ class V8_EXPORT CodeEvent {
const char* GetComment();
static const char* GetCodeEventTypeName(CodeEventType code_event_type);
uintptr_t GetPreviousCodeStartAddress();
};
/**
* Interface to listen to code creation events.
* Interface to listen to code creation and code relocation events.
*/
class V8_EXPORT CodeEventHandler {
public:
......@@ -1024,9 +1027,26 @@ class V8_EXPORT CodeEventHandler {
explicit CodeEventHandler(Isolate* isolate);
virtual ~CodeEventHandler();
/**
* Handle is called every time a code object is created or moved. Information
* about each code event will be available through the `code_event`
* parameter.
*
* When the CodeEventType is kRelocationType, the code for this CodeEvent has
* moved from `GetPreviousCodeStartAddress()` to `GetCodeStartAddress()`.
*/
virtual void Handle(CodeEvent* code_event) = 0;
/**
* Call `Enable()` to starts listening to code creation and code relocation
* events. These events will be handled by `Handle()`.
*/
void Enable();
/**
* Call `Disable()` to stop listening to code creation and code relocation
* events.
*/
void Disable();
private:
......
......@@ -10216,6 +10216,10 @@ const char* CodeEvent::GetComment() {
return reinterpret_cast<i::CodeEvent*>(this)->comment;
}
uintptr_t CodeEvent::GetPreviousCodeStartAddress() {
return reinterpret_cast<i::CodeEvent*>(this)->previous_code_start_address;
}
const char* CodeEvent::GetCodeEventTypeName(CodeEventType code_event_type) {
switch (code_event_type) {
case kUnknownType:
......
......@@ -477,6 +477,23 @@ void ExternalCodeEventListener::RegExpCodeCreateEvent(AbstractCode code,
code_event_handler_->Handle(reinterpret_cast<v8::CodeEvent*>(&code_event));
}
void ExternalCodeEventListener::CodeMoveEvent(AbstractCode from,
AbstractCode to) {
CodeEvent code_event;
code_event.previous_code_start_address =
static_cast<uintptr_t>(from.InstructionStart());
code_event.code_start_address = static_cast<uintptr_t>(to.InstructionStart());
code_event.code_size = static_cast<size_t>(to.InstructionSize());
code_event.function_name = isolate_->factory()->empty_string();
code_event.script_name = isolate_->factory()->empty_string();
code_event.script_line = 0;
code_event.script_column = 0;
code_event.code_type = v8::CodeEventType::kRelocationType;
code_event.comment = "";
code_event_handler_->Handle(reinterpret_cast<v8::CodeEvent*>(&code_event));
}
// Low-level logging support.
class LowLevelLogger : public CodeEventLogger {
public:
......
......@@ -423,6 +423,7 @@ struct CodeEvent {
int script_column;
CodeEventType code_type;
const char* comment;
uintptr_t previous_code_start_address;
};
class ExternalCodeEventListener : public CodeEventListener {
......@@ -448,7 +449,7 @@ class ExternalCodeEventListener : public CodeEventListener {
void SetterCallbackEvent(Name name, Address entry_point) override {}
void SharedFunctionInfoMoveEvent(Address from, Address to) override {}
void NativeContextMoveEvent(Address from, Address to) override {}
void CodeMoveEvent(AbstractCode from, AbstractCode to) override {}
void CodeMoveEvent(AbstractCode from, AbstractCode to) override;
void CodeDisableOptEvent(AbstractCode code,
SharedFunctionInfo shared) override {}
void CodeMovingGCEvent() override {}
......
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