From e7033ed988715fecd7328cd0b0eb5400139e400b Mon Sep 17 00:00:00 2001 From: Gang Zhao Date: Fri, 22 Nov 2024 15:53:24 -0800 Subject: [PATCH] Add pointer of owning object to GCPointer::set II Differential Revision: D62227030 --- include/hermes/VM/GCPointer-inline.h | 13 +++++++++++++ include/hermes/VM/GCPointer.h | 18 +++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/include/hermes/VM/GCPointer-inline.h b/include/hermes/VM/GCPointer-inline.h index 0cfbbb0fc01..4db995331fe 100644 --- a/include/hermes/VM/GCPointer-inline.h +++ b/include/hermes/VM/GCPointer-inline.h @@ -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)); diff --git a/include/hermes/VM/GCPointer.h b/include/hermes/VM/GCPointer.h index 1336c7c5a30..cff5dc5b86e 100644 --- a/include/hermes/VM/GCPointer.h +++ b/include/hermes/VM/GCPointer.h @@ -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); @@ -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 &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