Skip to content

Commit

Permalink
deps: cherry-pick b20faff from upstream V8
Browse files Browse the repository at this point in the history
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.

    [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}

Refs: v8/v8@b20faff

Backport-PR-URL: #21668
PR-URL: #21126
Refs: v8/v8@aa6ce3e
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Matheus Marchini authored and rvagg committed Aug 15, 2018
1 parent 6df5feb commit be569f8
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 20 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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

# Enable disassembler for `--print-code` v8 options
'v8_enable_disassembler': 1,
Expand Down
44 changes: 26 additions & 18 deletions deps/v8/src/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2012,18 +2012,18 @@ FILE* Logger::TearDown() {
}

void ExistingCodeLogger::LogCodeObject(Object* object) {
AbstractCode* code_object = AbstractCode::cast(object);
AbstractCode* abstract_code = AbstractCode::cast(object);
CodeEventListener::LogEventsAndTags tag = CodeEventListener::STUB_TAG;
const char* description = "Unknown code from before profiling";
switch (code_object->kind()) {
switch (abstract_code->kind()) {
case AbstractCode::INTERPRETED_FUNCTION:
case AbstractCode::OPTIMIZED_FUNCTION:
return; // We log this later using LogCompiledFunctions.
case AbstractCode::BYTECODE_HANDLER:
return; // We log it later by walking the dispatch table.
case AbstractCode::STUB:
description =
CodeStub::MajorName(CodeStub::GetMajorKey(code_object->GetCode()));
CodeStub::MajorName(CodeStub::GetMajorKey(abstract_code->GetCode()));
if (description == nullptr) description = "A stub from before profiling";
tag = CodeEventListener::STUB_TAG;
break;
Expand All @@ -2032,8 +2032,13 @@ void ExistingCodeLogger::LogCodeObject(Object* object) {
tag = CodeEventListener::REG_EXP_TAG;
break;
case AbstractCode::BUILTIN:
if (Code::cast(object)->is_interpreter_trampoline_builtin() &&
Code::cast(object) ==
*BUILTIN_CODE(isolate_, InterpreterEntryTrampoline)) {
return;
}
description =
isolate_->builtins()->name(code_object->GetCode()->builtin_index());
isolate_->builtins()->name(abstract_code->GetCode()->builtin_index());
tag = CodeEventListener::BUILTIN_TAG;
break;
case AbstractCode::WASM_FUNCTION:
Expand All @@ -2059,7 +2064,7 @@ void ExistingCodeLogger::LogCodeObject(Object* object) {
case AbstractCode::NUMBER_OF_KINDS:
UNIMPLEMENTED();
}
CALL_CODE_EVENT_HANDLER(CodeCreateEvent(tag, code_object, description))
CALL_CODE_EVENT_HANDLER(CodeCreateEvent(tag, abstract_code, description))
}

void ExistingCodeLogger::LogCodeObjects() {
Expand All @@ -2085,6 +2090,12 @@ void ExistingCodeLogger::LogCompiledFunctions() {
// During iteration, there can be heap allocation due to
// GetScriptLineNumber call.
for (int i = 0; i < compiled_funcs_count; ++i) {
if (sfis[i]->function_data()->IsInterpreterData()) {
LogExistingFunction(sfis[i],
Handle<AbstractCode>(AbstractCode::cast(
sfis[i]->InterpreterTrampoline())),
CodeEventListener::INTERPRETED_FUNCTION_TAG);
}
if (code_objects[i].is_identical_to(BUILTIN_CODE(isolate_, CompileLazy)))
continue;
LogExistingFunction(sfis[i], code_objects[i]);
Expand Down Expand Up @@ -2129,8 +2140,9 @@ void ExistingCodeLogger::LogBytecodeHandlers() {
}
}

void ExistingCodeLogger::LogExistingFunction(Handle<SharedFunctionInfo> shared,
Handle<AbstractCode> code) {
void ExistingCodeLogger::LogExistingFunction(
Handle<SharedFunctionInfo> shared, Handle<AbstractCode> code,
CodeEventListener::LogEventsAndTags tag) {
if (shared->script()->IsScript()) {
Handle<Script> script(Script::cast(shared->script()));
int line_num = Script::GetLineNumber(script, shared->StartPosition()) + 1;
Expand All @@ -2140,21 +2152,18 @@ void ExistingCodeLogger::LogExistingFunction(Handle<SharedFunctionInfo> shared,
Handle<String> script_name(String::cast(script->name()));
if (line_num > 0) {
CALL_CODE_EVENT_HANDLER(
CodeCreateEvent(Logger::ToNativeByScript(
CodeEventListener::LAZY_COMPILE_TAG, *script),
*code, *shared, *script_name, line_num, column_num))
CodeCreateEvent(Logger::ToNativeByScript(tag, *script), *code,
*shared, *script_name, line_num, column_num))
} else {
// Can't distinguish eval and script here, so always use Script.
CALL_CODE_EVENT_HANDLER(CodeCreateEvent(
Logger::ToNativeByScript(CodeEventListener::SCRIPT_TAG, *script),
*code, *shared, *script_name))
}
} else {
CALL_CODE_EVENT_HANDLER(
CodeCreateEvent(Logger::ToNativeByScript(
CodeEventListener::LAZY_COMPILE_TAG, *script),
*code, *shared, isolate_->heap()->empty_string(),
line_num, column_num))
CALL_CODE_EVENT_HANDLER(CodeCreateEvent(
Logger::ToNativeByScript(tag, *script), *code, *shared,
isolate_->heap()->empty_string(), line_num, column_num))
}
} else if (shared->IsApiFunction()) {
// API function.
Expand All @@ -2170,9 +2179,8 @@ void ExistingCodeLogger::LogExistingFunction(Handle<SharedFunctionInfo> shared,
CALL_CODE_EVENT_HANDLER(CallbackEvent(shared->DebugName(), entry_point))
}
} else {
CALL_CODE_EVENT_HANDLER(CodeCreateEvent(CodeEventListener::LAZY_COMPILE_TAG,
*code, *shared,
isolate_->heap()->empty_string()))
CALL_CODE_EVENT_HANDLER(
CodeCreateEvent(tag, *code, *shared, isolate_->heap()->empty_string()))
}
}

Expand Down
4 changes: 3 additions & 1 deletion deps/v8/src/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ class ExistingCodeLogger {

void LogCompiledFunctions();
void LogExistingFunction(Handle<SharedFunctionInfo> shared,
Handle<AbstractCode> code);
Handle<AbstractCode> code,
CodeEventListener::LogEventsAndTags tag =
CodeEventListener::LAZY_COMPILE_TAG);
void LogCodeObject(Object* object);
void LogBytecodeHandler(interpreter::Bytecode bytecode,
interpreter::OperandScale operand_scale, Code* code);
Expand Down
43 changes: 43 additions & 0 deletions deps/v8/test/cctest/test-log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,49 @@ TEST(ExternalCodeEventListener) {
isolate->Dispose();
}

TEST(ExternalCodeEventListenerWithInterpretedFramesNativeStack) {
i::FLAG_log = false;
i::FLAG_prof = false;
i::FLAG_interpreted_frames_native_stack = true;

v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);

{
v8::HandleScope scope(isolate);
v8::Isolate::Scope isolate_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
context->Enter();

TestCodeEventHandler code_event_handler(isolate);

const char* source_text_before_start =
"function testCodeEventListenerBeforeStart(a,b) { return a + b };"
"testCodeEventListenerBeforeStart('1', 1);";
CompileRun(source_text_before_start);

CHECK_NULL(code_event_handler.FindLine("InterpretedFunction",
"testCodeEventListenerBeforeStart"));

code_event_handler.Enable();

CHECK_NOT_NULL(code_event_handler.FindLine(
"InterpretedFunction", "testCodeEventListenerBeforeStart"));

const char* source_text_after_start =
"function testCodeEventListenerAfterStart(a,b) { return a + b };"
"testCodeEventListenerAfterStart('1', 1);";
CompileRun(source_text_after_start);

CHECK_NOT_NULL(code_event_handler.FindLine(
"InterpretedFunction", "testCodeEventListenerAfterStart"));

context->Exit();
}
isolate->Dispose();
}

TEST(TraceMaps) {
SETUP_FLAGS();
i::FLAG_trace_maps = true;
Expand Down

0 comments on commit be569f8

Please sign in to comment.