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) {
}
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;
Script* script = Script::cast(func->shared()->script());
int scriptId = script->id();
......
......@@ -377,6 +377,7 @@ class V8HeapExplorer : public HeapEntriesAllocator {
const char* GetSystemEntryName(HeapObject* object);
void ExtractLocation(int entry, HeapObject* object);
void ExtractLocationForJSFunction(int entry, JSFunction* func);
void ExtractReferences(int entry, HeapObject* obj);
void ExtractJSGlobalProxyReferences(int entry, JSGlobalProxy* proxy);
void ExtractJSObjectReferences(int entry, JSObject* js_obj);
......
......@@ -284,7 +284,9 @@ TEST(HeapSnapshotLocations) {
CompileRun(
"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();
CHECK(ValidateSnapshot(snapshot));
......@@ -293,10 +295,19 @@ TEST(HeapSnapshotLocations) {
GetProperty(env->GetIsolate(), global, v8::HeapGraphEdge::kProperty, "x");
CHECK(x);
Optional<SourceLocation> location = GetLocation(snapshot, x);
CHECK(location);
CHECK_EQ(0, location->line);
CHECK_EQ(31, location->col);
Optional<SourceLocation> x_loc = GetLocation(snapshot, x);
CHECK(x_loc);
CHECK_EQ(0, x_loc->line);
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) {
......
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