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 14, 2024
1 parent f12ade4 commit a268de1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
14 changes: 14 additions & 0 deletions include/hermes/VM/GCPointer-inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ GCPointerBase::set(PointerBase &base, CompressedPointer ptr, GC &gc) {
setNoBarrier(ptr);
}

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.
(void)owningObj;
gc.writeBarrier(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 @@ -57,6 +57,11 @@ class GCPointerBase : public CompressedPointer {
set(PointerBase &base, GCCell *ptr, GC &gc, const GCCell *owningObj) {
setImpl<MaybeLargeObj::Yes, NonNull::No>(base, ptr, gc, 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) {
setImpl<MaybeLargeObj::Yes, NonNull::Yes>(base, ptr, gc, owningObj);
Expand Down Expand Up @@ -140,10 +145,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 a268de1

Please sign in to comment.