Skip to content

Commit

Permalink
Pass the pointer of owning object in GCPointer::set() part II (facebo…
Browse files Browse the repository at this point in the history
…ok#1509)

Summary: Pull Request resolved: facebook#1509

Differential Revision: D62227030
  • Loading branch information
lavenzg authored and facebook-github-bot committed Nov 8, 2024
1 parent f293120 commit e821749
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 @@ -69,6 +69,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<std::true_type, std::false_type>(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<std::true_type, std::true_type>(base, ptr, gc, owningObj);
Expand Down Expand Up @@ -138,10 +143,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 e821749

Please sign in to comment.