Skip to content

Commit

Permalink
Store current cell in SlotAcceptor
Browse files Browse the repository at this point in the history
Differential Revision: D64713261
  • Loading branch information
lavenzg authored and facebook-github-bot committed Nov 7, 2024
1 parent a973b3e commit e7c2aa4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/hermes/VM/SlotAcceptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,21 @@ class GCCell;
/// pointer. For example, if the pointer is in compressed form.)
/// This is used by a visitor, see \c SlotVisitor.
struct SlotAcceptor {
/// The cell that contains the slot being visited.
const GCCell *currentCell;

virtual ~SlotAcceptor() = default;
virtual void accept(GCPointerBase &ptr) = 0;
virtual void accept(GCHermesValue &hv) = 0;
virtual void accept(GCSmallHermesValue &hv) = 0;
virtual void accept(const GCSymbolID &sym) = 0;

void startCell(const GCCell *cell) {
this->currentCell = cell;
}
void finishCell() {
this->currentCell = nullptr;
}
};

struct RootSectionAcceptor {
Expand Down
6 changes: 6 additions & 0 deletions include/hermes/VM/SlotVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ void visit(
Acceptor &acceptor,
GCCell *cell,
const Metadata::SlotOffsets &offsets) {
acceptor.startCell(cell);
auto *base = reinterpret_cast<char *>(cell);

size_t i = 0;
Expand All @@ -166,6 +167,7 @@ void visit(
if (offsets.array)
detail::visitArray<Acceptor, /* WithNames */ false>(
acceptor, base, *offsets.array);
acceptor.finishCell();
}

/// Like \c visit, but only invokes the acceptor on slots that begin within
Expand All @@ -177,6 +179,7 @@ void visitWithinRange(
const Metadata::SlotOffsets &offsets,
const char *begin,
const char *end) {
acceptor.startCell(cell);
auto *base = reinterpret_cast<char *>(cell);

size_t i = 0;
Expand All @@ -196,6 +199,7 @@ void visitWithinRange(

if (offsets.array)
detail::visitArrayWithinRange(acceptor, base, *offsets.array, begin, end);
acceptor.finishCell();
}

/// Like \c visit, but invokes the acceptor with names.
Expand All @@ -205,6 +209,7 @@ void visitWithNames(
GCCell *cell,
const Metadata::SlotOffsets &offsets,
const Metadata::SlotNames &names) {
acceptor.startCell(cell);
auto *base = reinterpret_cast<char *>(cell);

// Ignore sizes for special fields, since these are known types with known
Expand All @@ -220,6 +225,7 @@ void visitWithNames(
if (offsets.array)
detail::visitArray<Acceptor, /* WithNames */ true>(
acceptor, base, *offsets.array);
acceptor.finishCell();
}

} // namespace SlotVisitor
Expand Down
3 changes: 3 additions & 0 deletions lib/VM/gcs/HadesGC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ class HadesGC::EvacAcceptor final : public RootAndSlotAcceptor,
}

LLVM_NODISCARD GCCell *acceptHeap(GCCell *ptr, void *heapLoc) {
assert(currentCell && "There must be a cell being visited");
if (shouldForward(ptr)) {
assert(
AlignedHeapSegmentBase::getCellMarkBit(ptr) &&
Expand All @@ -423,6 +424,7 @@ class HadesGC::EvacAcceptor final : public RootAndSlotAcceptor,

LLVM_NODISCARD CompressedPointer
acceptHeap(CompressedPointer cptr, void *heapLoc) {
assert(currentCell && "There must be a cell being visited");
if (shouldForward(cptr)) {
GCCell *ptr = cptr.getNonNull(pointerBase_);
assert(
Expand Down Expand Up @@ -643,6 +645,7 @@ class HadesGC::MarkAcceptor final : public RootAndSlotAcceptor {
void acceptHeap(GCCell *cell, const void *heapLoc) {
assert(cell && "Cannot pass null pointer to acceptHeap");
assert(!gc.inYoungGen(heapLoc) && "YG slot found in OG marking");
assert(currentCell && "There must be a cell being visited");
if (gc.compactee_.contains(cell) && !gc.compactee_.contains(heapLoc)) {
// This is a pointer in the heap pointing into the compactee, dirty the
// corresponding card.
Expand Down

0 comments on commit e7c2aa4

Please sign in to comment.