Commit 32ec3c1c authored by Dominik Inführ's avatar Dominik Inführ Committed by Commit Bot

[heap-profiler] Generate location for generators

Add source code location for generators into heap snapshot file.

Bug: chromium:854097
Change-Id: I726b245a707515502976476703e57b7f58c92782
Reviewed-on: https://chromium-review.googlesource.com/1174433
Commit-Queue: Dominik Inführ <dinfuehr@google.com>
Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55254}
parent acf09252
...@@ -615,9 +615,17 @@ HeapEntry* V8HeapExplorer::AllocateEntry(HeapThing ptr) { ...@@ -615,9 +615,17 @@ HeapEntry* V8HeapExplorer::AllocateEntry(HeapThing ptr) {
} }
void V8HeapExplorer::ExtractLocation(int entry, HeapObject* object) { void V8HeapExplorer::ExtractLocation(int entry, HeapObject* object) {
if (!object->IsJSFunction()) return; if (object->IsJSFunction()) {
JSFunction* func = JSFunction::cast(object);
ExtractLocationForJSFunction(entry, func);
} else if (object->IsJSGeneratorObject()) {
JSGeneratorObject* gen = JSGeneratorObject::cast(object);
ExtractLocationForJSFunction(entry, gen->function());
}
}
JSFunction* func = JSFunction::cast(object); void V8HeapExplorer::ExtractLocationForJSFunction(int entry, JSFunction* func) {
if (!func->shared()->script()->IsScript()) return; if (!func->shared()->script()->IsScript()) return;
Script* script = Script::cast(func->shared()->script()); Script* script = Script::cast(func->shared()->script());
int scriptId = script->id(); int scriptId = script->id();
......
...@@ -377,6 +377,7 @@ class V8HeapExplorer : public HeapEntriesAllocator { ...@@ -377,6 +377,7 @@ class V8HeapExplorer : public HeapEntriesAllocator {
const char* GetSystemEntryName(HeapObject* object); const char* GetSystemEntryName(HeapObject* object);
void ExtractLocation(int entry, HeapObject* object); void ExtractLocation(int entry, HeapObject* object);
void ExtractLocationForJSFunction(int entry, JSFunction* func);
void ExtractReferences(int entry, HeapObject* obj); void ExtractReferences(int entry, HeapObject* obj);
void ExtractJSGlobalProxyReferences(int entry, JSGlobalProxy* proxy); void ExtractJSGlobalProxyReferences(int entry, JSGlobalProxy* proxy);
void ExtractJSObjectReferences(int entry, JSObject* js_obj); void ExtractJSObjectReferences(int entry, JSObject* js_obj);
......
...@@ -284,7 +284,9 @@ TEST(HeapSnapshotLocations) { ...@@ -284,7 +284,9 @@ TEST(HeapSnapshotLocations) {
CompileRun( CompileRun(
"function X(a) { return function() { return a; } }\n" "function X(a) { return function() { return a; } }\n"
"var x = X(1);"); "function* getid() { yield 1; }\n"
"var x = X(1);\n"
"var g = getid();");
const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot();
CHECK(ValidateSnapshot(snapshot)); CHECK(ValidateSnapshot(snapshot));
...@@ -293,10 +295,19 @@ TEST(HeapSnapshotLocations) { ...@@ -293,10 +295,19 @@ TEST(HeapSnapshotLocations) {
GetProperty(env->GetIsolate(), global, v8::HeapGraphEdge::kProperty, "x"); GetProperty(env->GetIsolate(), global, v8::HeapGraphEdge::kProperty, "x");
CHECK(x); CHECK(x);
Optional<SourceLocation> location = GetLocation(snapshot, x); Optional<SourceLocation> x_loc = GetLocation(snapshot, x);
CHECK(location); CHECK(x_loc);
CHECK_EQ(0, location->line); CHECK_EQ(0, x_loc->line);
CHECK_EQ(31, location->col); CHECK_EQ(31, x_loc->col);
const v8::HeapGraphNode* g =
GetProperty(env->GetIsolate(), global, v8::HeapGraphEdge::kProperty, "g");
CHECK(x);
Optional<SourceLocation> g_loc = GetLocation(snapshot, g);
CHECK(g_loc);
CHECK_EQ(1, g_loc->line);
CHECK_EQ(15, g_loc->col);
} }
TEST(HeapSnapshotObjectSizes) { TEST(HeapSnapshotObjectSizes) {
......
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