Skip to content

Commit

Permalink
Handle primitive values in WeakMap when taking snapshot
Browse files Browse the repository at this point in the history
Summary:
Scan WeakMapEntrySlots to visit (possible) primitive values with
PrimitiveNodeAcceptor, so that we can successfully add edges to them in
WeakMap.

Reviewed By: neildhar

Differential Revision: D55450685

fbshipit-source-id: 67bb29484ee94e5789fbd955f94867a1ec783e82
  • Loading branch information
lavenzg authored and facebook-github-bot committed Apr 11, 2024
1 parent d77f1b6 commit d00fe80
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
5 changes: 5 additions & 0 deletions lib/VM/GCBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,11 @@ void GCBase::createSnapshot(GC &gc, llvh::raw_ostream &os) {
stackTracesTreeNode ? stackTracesTreeNode->id : 0);
};
gc.forAllObjs(snapshotForObject);
// Scan all WeakMapEntrySlot so that PrimitiveNodeAcceptor won't miss
// primitives stored as WeakMap values.
weakMapEntrySlots_.forEach([&primitiveAcceptor](WeakMapEntrySlot &slot) {
primitiveAcceptor.accept(slot.mappedValue);
});
// Write the singleton number nodes into the snapshot.
primitiveAcceptor.writeAllNodes();
snap.endSection(HeapSnapshot::Section::Nodes);
Expand Down
8 changes: 0 additions & 8 deletions lib/VM/JSWeakMapImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,6 @@ void JSWeakMapImplBase::_snapshotAddEdgesImpl(
gc.getObjectID(key.getKeyNonNull(gc.getPointerBase(), gc)));

auto mappedValue = key.getMappedValue(gc);
// TODO(T175014649): nodes for numbers may not exist since they are not seen
// by PrimitiveNodeAcceptor. We can't simply add them in
// _snapshotAddNodesImpl() either, because PrimitiveNodeAcceptor may see the
// same number in a heap object and the assertion of not writing duplicate
// node will fail.
if (mappedValue.isNumber()) {
continue;
}
if (auto id = gc.getSnapshotID(mappedValue)) {
snap.addNamedEdge(
HeapSnapshot::EdgeType::Internal,
Expand Down

0 comments on commit d00fe80

Please sign in to comment.