Skip to content

Commit be569f8

Browse files
Matheus Marchinirvagg
Matheus Marchini
authored andcommitted
deps: cherry-pick b20faff from upstream V8
Original commit message: [log] fix ExistingCodeLogger behavior on edge case ExistingCodeLogger was behaving incorrectly when the CodeEventHandler API was used in combination with --interpreted-frames-native-stack. Instead of collecting copied trampolines as InterpretedFunction:functionName, they were being collected as Builtin:IntepreterEntryTrampolines. This patch adds special handling for copied trampolines when using ExistingCodeLogger. R=yangguo@google.com Change-Id: I3ee4be03800122d28d53b51b20c60dcf6263e4c1 Reviewed-on: https://chromium-review.googlesource.com/1087813 Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Yang Guo <yangguo@chromium.org> Cr-Commit-Position: refs/heads/master@{#53624} Refs: v8/v8@b20faff Backport-PR-URL: #21668 PR-URL: #21126 Refs: v8/v8@aa6ce3e Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 6df5feb commit be569f8

File tree

4 files changed

+73
-20
lines changed

4 files changed

+73
-20
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# Reset this number to 0 on major V8 upgrades.
3131
# Increment by one for each non-official patch applied to deps/v8.
32-
'v8_embedder_string': '-node.3',
32+
'v8_embedder_string': '-node.4',
3333

3434
# Enable disassembler for `--print-code` v8 options
3535
'v8_enable_disassembler': 1,

deps/v8/src/log.cc

+26-18
Original file line numberDiff line numberDiff line change
@@ -2012,18 +2012,18 @@ FILE* Logger::TearDown() {
20122012
}
20132013

20142014
void ExistingCodeLogger::LogCodeObject(Object* object) {
2015-
AbstractCode* code_object = AbstractCode::cast(object);
2015+
AbstractCode* abstract_code = AbstractCode::cast(object);
20162016
CodeEventListener::LogEventsAndTags tag = CodeEventListener::STUB_TAG;
20172017
const char* description = "Unknown code from before profiling";
2018-
switch (code_object->kind()) {
2018+
switch (abstract_code->kind()) {
20192019
case AbstractCode::INTERPRETED_FUNCTION:
20202020
case AbstractCode::OPTIMIZED_FUNCTION:
20212021
return; // We log this later using LogCompiledFunctions.
20222022
case AbstractCode::BYTECODE_HANDLER:
20232023
return; // We log it later by walking the dispatch table.
20242024
case AbstractCode::STUB:
20252025
description =
2026-
CodeStub::MajorName(CodeStub::GetMajorKey(code_object->GetCode()));
2026+
CodeStub::MajorName(CodeStub::GetMajorKey(abstract_code->GetCode()));
20272027
if (description == nullptr) description = "A stub from before profiling";
20282028
tag = CodeEventListener::STUB_TAG;
20292029
break;
@@ -2032,8 +2032,13 @@ void ExistingCodeLogger::LogCodeObject(Object* object) {
20322032
tag = CodeEventListener::REG_EXP_TAG;
20332033
break;
20342034
case AbstractCode::BUILTIN:
2035+
if (Code::cast(object)->is_interpreter_trampoline_builtin() &&
2036+
Code::cast(object) ==
2037+
*BUILTIN_CODE(isolate_, InterpreterEntryTrampoline)) {
2038+
return;
2039+
}
20352040
description =
2036-
isolate_->builtins()->name(code_object->GetCode()->builtin_index());
2041+
isolate_->builtins()->name(abstract_code->GetCode()->builtin_index());
20372042
tag = CodeEventListener::BUILTIN_TAG;
20382043
break;
20392044
case AbstractCode::WASM_FUNCTION:
@@ -2059,7 +2064,7 @@ void ExistingCodeLogger::LogCodeObject(Object* object) {
20592064
case AbstractCode::NUMBER_OF_KINDS:
20602065
UNIMPLEMENTED();
20612066
}
2062-
CALL_CODE_EVENT_HANDLER(CodeCreateEvent(tag, code_object, description))
2067+
CALL_CODE_EVENT_HANDLER(CodeCreateEvent(tag, abstract_code, description))
20632068
}
20642069

20652070
void ExistingCodeLogger::LogCodeObjects() {
@@ -2085,6 +2090,12 @@ void ExistingCodeLogger::LogCompiledFunctions() {
20852090
// During iteration, there can be heap allocation due to
20862091
// GetScriptLineNumber call.
20872092
for (int i = 0; i < compiled_funcs_count; ++i) {
2093+
if (sfis[i]->function_data()->IsInterpreterData()) {
2094+
LogExistingFunction(sfis[i],
2095+
Handle<AbstractCode>(AbstractCode::cast(
2096+
sfis[i]->InterpreterTrampoline())),
2097+
CodeEventListener::INTERPRETED_FUNCTION_TAG);
2098+
}
20882099
if (code_objects[i].is_identical_to(BUILTIN_CODE(isolate_, CompileLazy)))
20892100
continue;
20902101
LogExistingFunction(sfis[i], code_objects[i]);
@@ -2129,8 +2140,9 @@ void ExistingCodeLogger::LogBytecodeHandlers() {
21292140
}
21302141
}
21312142

2132-
void ExistingCodeLogger::LogExistingFunction(Handle<SharedFunctionInfo> shared,
2133-
Handle<AbstractCode> code) {
2143+
void ExistingCodeLogger::LogExistingFunction(
2144+
Handle<SharedFunctionInfo> shared, Handle<AbstractCode> code,
2145+
CodeEventListener::LogEventsAndTags tag) {
21342146
if (shared->script()->IsScript()) {
21352147
Handle<Script> script(Script::cast(shared->script()));
21362148
int line_num = Script::GetLineNumber(script, shared->StartPosition()) + 1;
@@ -2140,21 +2152,18 @@ void ExistingCodeLogger::LogExistingFunction(Handle<SharedFunctionInfo> shared,
21402152
Handle<String> script_name(String::cast(script->name()));
21412153
if (line_num > 0) {
21422154
CALL_CODE_EVENT_HANDLER(
2143-
CodeCreateEvent(Logger::ToNativeByScript(
2144-
CodeEventListener::LAZY_COMPILE_TAG, *script),
2145-
*code, *shared, *script_name, line_num, column_num))
2155+
CodeCreateEvent(Logger::ToNativeByScript(tag, *script), *code,
2156+
*shared, *script_name, line_num, column_num))
21462157
} else {
21472158
// Can't distinguish eval and script here, so always use Script.
21482159
CALL_CODE_EVENT_HANDLER(CodeCreateEvent(
21492160
Logger::ToNativeByScript(CodeEventListener::SCRIPT_TAG, *script),
21502161
*code, *shared, *script_name))
21512162
}
21522163
} else {
2153-
CALL_CODE_EVENT_HANDLER(
2154-
CodeCreateEvent(Logger::ToNativeByScript(
2155-
CodeEventListener::LAZY_COMPILE_TAG, *script),
2156-
*code, *shared, isolate_->heap()->empty_string(),
2157-
line_num, column_num))
2164+
CALL_CODE_EVENT_HANDLER(CodeCreateEvent(
2165+
Logger::ToNativeByScript(tag, *script), *code, *shared,
2166+
isolate_->heap()->empty_string(), line_num, column_num))
21582167
}
21592168
} else if (shared->IsApiFunction()) {
21602169
// API function.
@@ -2170,9 +2179,8 @@ void ExistingCodeLogger::LogExistingFunction(Handle<SharedFunctionInfo> shared,
21702179
CALL_CODE_EVENT_HANDLER(CallbackEvent(shared->DebugName(), entry_point))
21712180
}
21722181
} else {
2173-
CALL_CODE_EVENT_HANDLER(CodeCreateEvent(CodeEventListener::LAZY_COMPILE_TAG,
2174-
*code, *shared,
2175-
isolate_->heap()->empty_string()))
2182+
CALL_CODE_EVENT_HANDLER(
2183+
CodeCreateEvent(tag, *code, *shared, isolate_->heap()->empty_string()))
21762184
}
21772185
}
21782186

deps/v8/src/log.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ class ExistingCodeLogger {
109109

110110
void LogCompiledFunctions();
111111
void LogExistingFunction(Handle<SharedFunctionInfo> shared,
112-
Handle<AbstractCode> code);
112+
Handle<AbstractCode> code,
113+
CodeEventListener::LogEventsAndTags tag =
114+
CodeEventListener::LAZY_COMPILE_TAG);
113115
void LogCodeObject(Object* object);
114116
void LogBytecodeHandler(interpreter::Bytecode bytecode,
115117
interpreter::OperandScale operand_scale, Code* code);

deps/v8/test/cctest/test-log.cc

+43
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,49 @@ TEST(ExternalCodeEventListener) {
875875
isolate->Dispose();
876876
}
877877

878+
TEST(ExternalCodeEventListenerWithInterpretedFramesNativeStack) {
879+
i::FLAG_log = false;
880+
i::FLAG_prof = false;
881+
i::FLAG_interpreted_frames_native_stack = true;
882+
883+
v8::Isolate::CreateParams create_params;
884+
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
885+
v8::Isolate* isolate = v8::Isolate::New(create_params);
886+
887+
{
888+
v8::HandleScope scope(isolate);
889+
v8::Isolate::Scope isolate_scope(isolate);
890+
v8::Local<v8::Context> context = v8::Context::New(isolate);
891+
context->Enter();
892+
893+
TestCodeEventHandler code_event_handler(isolate);
894+
895+
const char* source_text_before_start =
896+
"function testCodeEventListenerBeforeStart(a,b) { return a + b };"
897+
"testCodeEventListenerBeforeStart('1', 1);";
898+
CompileRun(source_text_before_start);
899+
900+
CHECK_NULL(code_event_handler.FindLine("InterpretedFunction",
901+
"testCodeEventListenerBeforeStart"));
902+
903+
code_event_handler.Enable();
904+
905+
CHECK_NOT_NULL(code_event_handler.FindLine(
906+
"InterpretedFunction", "testCodeEventListenerBeforeStart"));
907+
908+
const char* source_text_after_start =
909+
"function testCodeEventListenerAfterStart(a,b) { return a + b };"
910+
"testCodeEventListenerAfterStart('1', 1);";
911+
CompileRun(source_text_after_start);
912+
913+
CHECK_NOT_NULL(code_event_handler.FindLine(
914+
"InterpretedFunction", "testCodeEventListenerAfterStart"));
915+
916+
context->Exit();
917+
}
918+
isolate->Dispose();
919+
}
920+
878921
TEST(TraceMaps) {
879922
SETUP_FLAGS();
880923
i::FLAG_trace_maps = true;

0 commit comments

Comments
 (0)