Skip to content

Commit

Permalink
Add pointer of owning object to GCPointer::set II
Browse files Browse the repository at this point in the history
Differential Revision: D62227030
  • Loading branch information
lavenzg authored and facebook-github-bot committed Nov 22, 2024
1 parent 5167da4 commit e7033ed
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
13 changes: 13 additions & 0 deletions include/hermes/VM/GCPointer-inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ inline void GCPointerBase::setNonNull(
setNoBarrier(CompressedPointer::encodeNonNull(ptr, base));
}

inline void GCPointerBase::set(
PointerBase &base,
CompressedPointer ptr,
GC &gc,
const GCCell *owningObj) {
assert(
(!ptr || gc.validPointer(ptr.get(base))) &&
"Cannot set a GCPointer to an invalid pointer");
// Write barrier must happen before the write.
gc.writeBarrierForLargeObj(owningObj, this, ptr.get(base));
setNoBarrier(ptr);
}

inline void GCPointerBase::setNull(GC &gc) {
gc.snapshotWriteBarrier(this);
setNoBarrier(CompressedPointer(nullptr));
Expand Down
18 changes: 17 additions & 1 deletion include/hermes/VM/GCPointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class GCPointerBase : public CompressedPointer {
/// writer barriers.
inline void
set(PointerBase &base, GCCell *ptr, GC &gc, const GCCell *owningObj);
inline void set(
PointerBase &base,
CompressedPointer ptr,
GC &gc,
const GCCell *owningObj);
inline void
setNonNull(PointerBase &base, GCCell *ptr, GC &gc, const GCCell *owningObj);

Expand Down Expand Up @@ -122,10 +127,21 @@ class GCPointer : public GCPointerBase {
GCPointerBase::setNonNull(base, ptr, gc, owningObj);
}

/// Convenience overload of GCPointer::set for other GCPointers.
/// Convenience overload of GCPointer::set for other GCPointers. This must not
/// be used if it lives in an object that supports large allocation.
void set(PointerBase &base, const GCPointer<T> &ptr, GC &gc) {
GCPointerBase::set(base, ptr, gc);
}

/// Convenience overload of GCPointer::set for other GCPointers. \p owningObj
/// is used by the writer barriers.
void set(
PointerBase &base,
const GCPointer<T> &ptr,
GC &gc,
const GCCell *owningObj) {
GCPointerBase::set(base, ptr, gc, owningObj);
}
};

} // namespace vm
Expand Down

0 comments on commit e7033ed

Please sign in to comment.