Commit f451d6ce authored by Yang Guo's avatar Yang Guo Committed by Commit Bot

[logging] correctly log code events from deserialization.

R=jarin@chromium.org

Bug: v8:8671, v8:8674
Change-Id: I5cdcd49d05f08206aa32426f2fe0560568291f2e
Reviewed-on: https://chromium-review.googlesource.com/c/1405852
Commit-Queue: Yang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58739}
parent 9c9682d0
...@@ -203,6 +203,7 @@ void CodeEventLogger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag, ...@@ -203,6 +203,7 @@ void CodeEventLogger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
SharedFunctionInfo shared, Name name) { SharedFunctionInfo shared, Name name) {
name_buffer_->Init(tag); name_buffer_->Init(tag);
name_buffer_->AppendBytes(ComputeMarker(shared, code)); name_buffer_->AppendBytes(ComputeMarker(shared, code));
name_buffer_->AppendByte(' ');
name_buffer_->AppendName(name); name_buffer_->AppendName(name);
LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size()); LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size());
} }
......
...@@ -276,23 +276,35 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize( ...@@ -276,23 +276,35 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize(
PrintF("[Deserializing from %d bytes took %0.3f ms]\n", length, ms); PrintF("[Deserializing from %d bytes took %0.3f ms]\n", length, ms);
} }
bool log_code_creation = isolate->logger()->is_listening_to_code_events() || bool log_code_creation =
isolate->is_profiling(); isolate->logger()->is_listening_to_code_events() ||
isolate->is_profiling() ||
isolate->code_event_dispatcher()->IsListeningToCodeEvents();
if (log_code_creation || FLAG_log_function_events) { if (log_code_creation || FLAG_log_function_events) {
String name = ReadOnlyRoots(isolate).empty_string(); String name = ReadOnlyRoots(isolate).empty_string();
if (result->script()->IsScript()) { Script script = Script::cast(result->script());
Script script = Script::cast(result->script()); Handle<Script> script_handle(script, isolate);
if (script->name()->IsString()) name = String::cast(script->name()); if (script->name()->IsString()) name = String::cast(script->name());
if (FLAG_log_function_events) { if (FLAG_log_function_events) {
LOG(isolate, FunctionEvent("deserialize", script->id(), LOG(isolate,
timer.Elapsed().InMillisecondsF(), FunctionEvent("deserialize", script->id(),
result->StartPosition(), timer.Elapsed().InMillisecondsF(),
result->EndPosition(), name)); result->StartPosition(), result->EndPosition(), name));
}
} }
if (log_code_creation) { if (log_code_creation) {
PROFILE(isolate, CodeCreateEvent(CodeEventListener::SCRIPT_TAG, Script::InitLineEnds(Handle<Script>(script, isolate));
result->abstract_code(), *result, name)); DisallowHeapAllocation no_gc;
SharedFunctionInfo::ScriptIterator iter(isolate, script);
for (i::SharedFunctionInfo info = iter.Next(); !info.is_null();
info = iter.Next()) {
if (info->is_compiled()) {
int line_num = script->GetLineNumber(info->StartPosition()) + 1;
int column_num = script->GetColumnNumber(info->StartPosition()) + 1;
PROFILE(isolate, CodeCreateEvent(CodeEventListener::SCRIPT_TAG,
info->abstract_code(), info, name,
line_num, column_num));
}
}
} }
} }
......
...@@ -671,7 +671,7 @@ TEST(ExternalCodeEventListener) { ...@@ -671,7 +671,7 @@ TEST(ExternalCodeEventListener) {
v8::HandleScope scope(isolate); v8::HandleScope scope(isolate);
v8::Isolate::Scope isolate_scope(isolate); v8::Isolate::Scope isolate_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate); v8::Local<v8::Context> context = v8::Context::New(isolate);
context->Enter(); v8::Context::Scope context_scope(context);
TestCodeEventHandler code_event_handler(isolate); TestCodeEventHandler code_event_handler(isolate);
...@@ -698,12 +698,68 @@ TEST(ExternalCodeEventListener) { ...@@ -698,12 +698,68 @@ TEST(ExternalCodeEventListener) {
CHECK_GE(code_event_handler.CountLines("LazyCompile", CHECK_GE(code_event_handler.CountLines("LazyCompile",
"testCodeEventListenerAfterStart"), "testCodeEventListenerAfterStart"),
1); 1);
context->Exit();
} }
isolate->Dispose(); isolate->Dispose();
} }
TEST(ExternalCodeEventListenerInnerFunctions) {
i::FLAG_log = false;
i::FLAG_prof = false;
v8::ScriptCompiler::CachedData* cache;
static const char* source_cstring =
"(function f1() { return (function f2() {}); })()";
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate1 = v8::Isolate::New(create_params);
{ // Test that we emit the correct code events from eagerly compiling.
v8::HandleScope scope(isolate1);
v8::Isolate::Scope isolate_scope(isolate1);
v8::Local<v8::Context> context = v8::Context::New(isolate1);
v8::Context::Scope context_scope(context);
TestCodeEventHandler code_event_handler(isolate1);
code_event_handler.Enable();
v8::Local<v8::String> source_string = v8_str(source_cstring);
v8::ScriptOrigin origin(v8_str("test"));
v8::ScriptCompiler::Source source(source_string, origin);
v8::Local<v8::UnboundScript> script =
v8::ScriptCompiler::CompileUnboundScript(isolate1, &source)
.ToLocalChecked();
CHECK_EQ(code_event_handler.CountLines("Script", "f1"), 1);
CHECK_EQ(code_event_handler.CountLines("Script", "f2"), 1);
cache = v8::ScriptCompiler::CreateCodeCache(script);
}
isolate1->Dispose();
v8::Isolate* isolate2 = v8::Isolate::New(create_params);
{ // Test that we emit the correct code events from deserialization.
v8::HandleScope scope(isolate2);
v8::Isolate::Scope isolate_scope(isolate2);
v8::Local<v8::Context> context = v8::Context::New(isolate2);
v8::Context::Scope context_scope(context);
TestCodeEventHandler code_event_handler(isolate2);
code_event_handler.Enable();
v8::Local<v8::String> source_string = v8_str(source_cstring);
v8::ScriptOrigin origin(v8_str("test"));
v8::ScriptCompiler::Source source(source_string, origin, cache);
{
i::DisallowCompilation no_compile_expected(
reinterpret_cast<i::Isolate*>(isolate2));
v8::ScriptCompiler::CompileUnboundScript(
isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache)
.ToLocalChecked();
}
CHECK_EQ(code_event_handler.CountLines("Script", "f1"), 1);
CHECK_EQ(code_event_handler.CountLines("Script", "f2"), 1);
}
isolate2->Dispose();
}
TEST(ExternalCodeEventListenerWithInterpretedFramesNativeStack) { TEST(ExternalCodeEventListenerWithInterpretedFramesNativeStack) {
i::FLAG_log = false; i::FLAG_log = false;
i::FLAG_prof = false; i::FLAG_prof = false;
......
...@@ -2184,8 +2184,8 @@ static bool toplevel_test_code_event_found = false; ...@@ -2184,8 +2184,8 @@ static bool toplevel_test_code_event_found = false;
static void SerializerCodeEventListener(const v8::JitCodeEvent* event) { static void SerializerCodeEventListener(const v8::JitCodeEvent* event) {
if (event->type == v8::JitCodeEvent::CODE_ADDED && if (event->type == v8::JitCodeEvent::CODE_ADDED &&
(memcmp(event->name.str, "Script:~test", 12) == 0 || (memcmp(event->name.str, "Script:~ test", 13) == 0 ||
memcmp(event->name.str, "Script:test", 11) == 0)) { memcmp(event->name.str, "Script: test", 12) == 0)) {
toplevel_test_code_event_found = true; toplevel_test_code_event_found = true;
} }
} }
......
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