Skip to content

Commit

Permalink
Add JSFunction -> CodeBlock edge in heap snapshot
Browse files Browse the repository at this point in the history
Summary: Adds a "shortcut" edge ( = internal, non-retaining, named) from each `JSFunction` to its `CodeBlock`.

Reviewed By: dulinriley

Differential Revision: D26583520

fbshipit-source-id: 81220f6d24ac9828abee348c12e3416a9876f121
  • Loading branch information
motiz88 authored and facebook-github-bot committed Feb 23, 2021
1 parent 2f5e764 commit 7bf7eba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/hermes/VM/Callable.h
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ class JSFunction : public Callable {
static std::string _snapshotNameImpl(GCCell *cell, GC *gc);
static void
_snapshotAddLocationsImpl(GCCell *cell, GC *gc, HeapSnapshot &snap);
static void _snapshotAddEdgesImpl(GCCell *cell, GC *gc, HeapSnapshot &snap);
};

/// A function which interprets code and returns a Async Function when called.
Expand Down
15 changes: 15 additions & 0 deletions lib/VM/Callable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,21 @@ std::string JSFunction::_snapshotNameImpl(GCCell *cell, GC *gc) {
return self->codeBlock_->getNameString(gc->getCallbacks());
}

void JSFunction::_snapshotAddEdgesImpl(
GCCell *cell,
GC *gc,
HeapSnapshot &snap) {
auto *const self = vmcast<JSFunction>(cell);
// Add the super type's edges too.
Callable::_snapshotAddEdgesImpl(self, gc, snap);

// A node for the code block will be added as part of the RuntimeModule.
snap.addNamedEdge(
HeapSnapshot::EdgeType::Shortcut,
"codeBlock",
gc->getIDTracker().getNativeID(self->codeBlock_));
}

void JSFunction::_snapshotAddLocationsImpl(
GCCell *cell,
GC *gc,
Expand Down
6 changes: 3 additions & 3 deletions unittests/VMRuntime/HeapSnapshotTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ TEST_F(HeapSnapshotRuntimeTest, FunctionLocationForLazyCode) {
"myGlobal",
funcID,
func->getAllocatedSize(),
6};
7};
EXPECT_EQ(node, expected);
// Edges aren't tested in this test.

Expand Down Expand Up @@ -814,7 +814,7 @@ TEST_F(HeapSnapshotRuntimeTest, FunctionLocationAndNameTest) {
"foo",
funcID,
func->getAllocatedSize(),
6};
7};
EXPECT_EQ(node, expected);
// Edges aren't tested in this test.

Expand Down Expand Up @@ -858,7 +858,7 @@ TEST_F(HeapSnapshotRuntimeTest, FunctionDisplayNameTest) {
"bar",
funcID,
func->getAllocatedSize(),
11};
12};
EXPECT_EQ(node, expected);
}

Expand Down

0 comments on commit 7bf7eba

Please sign in to comment.