Skip to content

Commit

Permalink
Pass the pointer of owning object in GCPointer::set() part II (#1509)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #1509

Differential Revision: D62227030
  • Loading branch information
lavenzg authored and facebook-github-bot committed Nov 22, 2024
1 parent 5167da4 commit c5040b7
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 c5040b7

Please sign in to comment.