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 21, 2024
1 parent cf19660 commit 61fb42a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/hermes/VM/AlignedHeapSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,16 @@ class FixedSizeHeapSegment : public AlignedHeapSegment {
static void checkUnwritten(char *start, char *end);
#endif

#ifdef HERMES_SLOW_DEBUG
/// Find the object containing \p loc.
static GCCell *findObjectContaining(const void *loc) {
auto *lowLim = static_cast<char *>(storageStart(loc));
auto *hiLim = lowLim + kSize;
return contents(lowLim)->boundaryTable_.findObjectContaining(
lowLim, hiLim, loc);
}
#endif

private:
FixedSizeHeapSegment(StorageProvider *provider, void *lowLim);
};
Expand Down
6 changes: 6 additions & 0 deletions include/hermes/VM/CardBoundaryTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ class CardBoundaryTable {
///
/// \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 char *lowLim,
const char *hiLim,
const void *loc) const;
#endif // HERMES_SLOW_DEBUG

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

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

} // namespace vm
Expand Down

0 comments on commit 61fb42a

Please sign in to comment.