Skip to content

Commit

Permalink
Add a findObject function to CardTable for assertions in writer barri…
Browse files Browse the repository at this point in the history
…ers (facebook#1513)

Summary: Pull Request resolved: facebook#1513

Differential Revision: D62169632
  • Loading branch information
lavenzg authored and facebook-github-bot committed Dec 2, 2024
1 parent e8d567f commit 30c6e3f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/hermes/VM/CardTableNC.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ class CardTable {
///
/// \pre start is card-aligned.
void verifyBoundaries(char *start, char *level) const;

/// Find the object that owns the memory at \p loc.
GCCell *findObjectContaining(const void *loc) const;
#endif // HERMES_SLOW_DEBUG

private:
Expand Down
7 changes: 7 additions & 0 deletions lib/VM/gcs/CardTableNC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ void CardTable::verifyBoundaries(char *start, char *level) const {
"Card object boundary is broken: first obj doesn't extend into card");
}
}

GCCell *CardTable::findObjectContaining(const void *loc) const {
GCCell *obj = firstObjForCard(addressToIndex(loc));
while (obj->nextCell() < loc)
obj = obj->nextCell();
return obj;
}
#endif // HERMES_SLOW_DEBUG

} // namespace vm
Expand Down

0 comments on commit 30c6e3f

Please sign in to comment.