diff --git a/include/hermes/VM/CardTableNC.h b/include/hermes/VM/CardTableNC.h index 7bce327636a..6881873e7b8 100644 --- a/include/hermes/VM/CardTableNC.h +++ b/include/hermes/VM/CardTableNC.h @@ -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: diff --git a/lib/VM/gcs/CardTableNC.cpp b/lib/VM/gcs/CardTableNC.cpp index 10937e15192..018ff2c5a06 100644 --- a/lib/VM/gcs/CardTableNC.cpp +++ b/lib/VM/gcs/CardTableNC.cpp @@ -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