Skip to content

Commit b20faff

Browse files
Matheus MarchiniCommit Bot
authored andcommitted
[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. [email protected] Change-Id: I3ee4be03800122d28d53b51b20c60dcf6263e4c1 Reviewed-on: https://chromium-review.googlesource.com/1087813 Reviewed-by: Yang Guo <[email protected]> Commit-Queue: Yang Guo <[email protected]> Cr-Commit-Position: refs/heads/master@{#53624}
1 parent 41b2d78 commit b20faff

File tree

3 files changed

+72
-19
lines changed

3 files changed

+72
-19
lines changed

src/log.cc

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,18 +2011,18 @@ FILE* Logger::TearDown() {
20112011
}
20122012

20132013
void ExistingCodeLogger::LogCodeObject(Object* object) {
2014-
AbstractCode* code_object = AbstractCode::cast(object);
2014+
AbstractCode* abstract_code = AbstractCode::cast(object);
20152015
CodeEventListener::LogEventsAndTags tag = CodeEventListener::STUB_TAG;
20162016
const char* description = "Unknown code from before profiling";
2017-
switch (code_object->kind()) {
2017+
switch (abstract_code->kind()) {
20182018
case AbstractCode::INTERPRETED_FUNCTION:
20192019
case AbstractCode::OPTIMIZED_FUNCTION:
20202020
return; // We log this later using LogCompiledFunctions.
20212021
case AbstractCode::BYTECODE_HANDLER:
20222022
return; // We log it later by walking the dispatch table.
20232023
case AbstractCode::STUB:
20242024
description =
2025-
CodeStub::MajorName(CodeStub::GetMajorKey(code_object->GetCode()));
2025+
CodeStub::MajorName(CodeStub::GetMajorKey(abstract_code->GetCode()));
20262026
if (description == nullptr) description = "A stub from before profiling";
20272027
tag = CodeEventListener::STUB_TAG;
20282028
break;
@@ -2031,8 +2031,13 @@ void ExistingCodeLogger::LogCodeObject(Object* object) {
20312031
tag = CodeEventListener::REG_EXP_TAG;
20322032
break;
20332033
case AbstractCode::BUILTIN:
2034+
if (Code::cast(object)->is_interpreter_trampoline_builtin() &&
2035+
Code::cast(object) ==
2036+
*BUILTIN_CODE(isolate_, InterpreterEntryTrampoline)) {
2037+
return;
2038+
}
20342039
description =
2035-
isolate_->builtins()->name(code_object->GetCode()->builtin_index());
2040+
isolate_->builtins()->name(abstract_code->GetCode()->builtin_index());
20362041
tag = CodeEventListener::BUILTIN_TAG;
20372042
break;
20382043
case AbstractCode::WASM_FUNCTION:
@@ -2058,7 +2063,7 @@ void ExistingCodeLogger::LogCodeObject(Object* object) {
20582063
case AbstractCode::NUMBER_OF_KINDS:
20592064
UNIMPLEMENTED();
20602065
}
2061-
CALL_CODE_EVENT_HANDLER(CodeCreateEvent(tag, code_object, description))
2066+
CALL_CODE_EVENT_HANDLER(CodeCreateEvent(tag, abstract_code, description))
20622067
}
20632068

20642069
void ExistingCodeLogger::LogCodeObjects() {
@@ -2084,6 +2089,12 @@ void ExistingCodeLogger::LogCompiledFunctions() {
20842089
// During iteration, there can be heap allocation due to
20852090
// GetScriptLineNumber call.
20862091
for (int i = 0; i < compiled_funcs_count; ++i) {
2092+
if (sfis[i]->function_data()->IsInterpreterData()) {
2093+
LogExistingFunction(sfis[i],
2094+
Handle<AbstractCode>(AbstractCode::cast(
2095+
sfis[i]->InterpreterTrampoline())),
2096+
CodeEventListener::INTERPRETED_FUNCTION_TAG);
2097+
}
20872098
if (code_objects[i].is_identical_to(BUILTIN_CODE(isolate_, CompileLazy)))
20882099
continue;
20892100
LogExistingFunction(sfis[i], code_objects[i]);
@@ -2128,8 +2139,9 @@ void ExistingCodeLogger::LogBytecodeHandlers() {
21282139
}
21292140
}
21302141

2131-
void ExistingCodeLogger::LogExistingFunction(Handle<SharedFunctionInfo> shared,
2132-
Handle<AbstractCode> code) {
2142+
void ExistingCodeLogger::LogExistingFunction(
2143+
Handle<SharedFunctionInfo> shared, Handle<AbstractCode> code,
2144+
CodeEventListener::LogEventsAndTags tag) {
21332145
if (shared->script()->IsScript()) {
21342146
Handle<Script> script(Script::cast(shared->script()));
21352147
int line_num = Script::GetLineNumber(script, shared->StartPosition()) + 1;
@@ -2139,21 +2151,18 @@ void ExistingCodeLogger::LogExistingFunction(Handle<SharedFunctionInfo> shared,
21392151
Handle<String> script_name(String::cast(script->name()));
21402152
if (line_num > 0) {
21412153
CALL_CODE_EVENT_HANDLER(
2142-
CodeCreateEvent(Logger::ToNativeByScript(
2143-
CodeEventListener::LAZY_COMPILE_TAG, *script),
2144-
*code, *shared, *script_name, line_num, column_num))
2154+
CodeCreateEvent(Logger::ToNativeByScript(tag, *script), *code,
2155+
*shared, *script_name, line_num, column_num))
21452156
} else {
21462157
// Can't distinguish eval and script here, so always use Script.
21472158
CALL_CODE_EVENT_HANDLER(CodeCreateEvent(
21482159
Logger::ToNativeByScript(CodeEventListener::SCRIPT_TAG, *script),
21492160
*code, *shared, *script_name))
21502161
}
21512162
} else {
2152-
CALL_CODE_EVENT_HANDLER(
2153-
CodeCreateEvent(Logger::ToNativeByScript(
2154-
CodeEventListener::LAZY_COMPILE_TAG, *script),
2155-
*code, *shared, isolate_->heap()->empty_string(),
2156-
line_num, column_num))
2163+
CALL_CODE_EVENT_HANDLER(CodeCreateEvent(
2164+
Logger::ToNativeByScript(tag, *script), *code, *shared,
2165+
isolate_->heap()->empty_string(), line_num, column_num))
21572166
}
21582167
} else if (shared->IsApiFunction()) {
21592168
// API function.
@@ -2169,9 +2178,8 @@ void ExistingCodeLogger::LogExistingFunction(Handle<SharedFunctionInfo> shared,
21692178
CALL_CODE_EVENT_HANDLER(CallbackEvent(shared->DebugName(), entry_point))
21702179
}
21712180
} else {
2172-
CALL_CODE_EVENT_HANDLER(CodeCreateEvent(CodeEventListener::LAZY_COMPILE_TAG,
2173-
*code, *shared,
2174-
isolate_->heap()->empty_string()))
2181+
CALL_CODE_EVENT_HANDLER(
2182+
CodeCreateEvent(tag, *code, *shared, isolate_->heap()->empty_string()))
21752183
}
21762184
}
21772185

src/log.h

Lines changed: 3 additions & 1 deletion
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);

test/cctest/test-log.cc

Lines changed: 43 additions & 0 deletions
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)