From 6eb2ff7db0604e40e0994ca933f01da8628380b0 Mon Sep 17 00:00:00 2001 From: Gang Zhao Date: Thu, 21 Nov 2024 10:53:54 -0800 Subject: [PATCH] Add pointer of owning object to GCPointer::set II Differential Revision: D62227030 --- include/hermes/VM/GCPointer-inline.h | 14 ++++++++++++++ include/hermes/VM/GCPointer.h | 18 +++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/include/hermes/VM/GCPointer-inline.h b/include/hermes/VM/GCPointer-inline.h index b5b94f3fc1f..250fc0c3581 100644 --- a/include/hermes/VM/GCPointer-inline.h +++ b/include/hermes/VM/GCPointer-inline.h @@ -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)); diff --git a/include/hermes/VM/GCPointer.h b/include/hermes/VM/GCPointer.h index b288cc9112e..eb51e29631d 100644 --- a/include/hermes/VM/GCPointer.h +++ b/include/hermes/VM/GCPointer.h @@ -57,6 +57,11 @@ class GCPointerBase : public CompressedPointer { set(PointerBase &base, GCCell *ptr, GC &gc, const GCCell *owningObj) { setImpl(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(base, ptr, gc, owningObj); @@ -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 &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 &ptr, + GC &gc, + const GCCell *owningObj) { + GCPointerBase::set(base, ptr, gc, owningObj); + } }; } // namespace vm