diff --git a/include/hermes/VM/HadesGC.h b/include/hermes/VM/HadesGC.h index a95848b372a..97f3b86ab9a 100644 --- a/include/hermes/VM/HadesGC.h +++ b/include/hermes/VM/HadesGC.h @@ -743,6 +743,10 @@ class HadesGC final : public GCBase { /// If true, turn off promoteYGToOG_ as soon as the first OG GC occurs. bool revertToYGAtTTI_; + /// If true, overwrite the allocation region in the YG with kInvalidHeapValue + /// at the end of each YG collection. + bool overwriteDeadYGObjects_; + /// Target OG occupancy ratio at the end of an OG collection. const double occupancyTarget_; diff --git a/lib/VM/gcs/HadesGC.cpp b/lib/VM/gcs/HadesGC.cpp index 7a327c74a7c..6f0e6c8d2d7 100644 --- a/lib/VM/gcs/HadesGC.cpp +++ b/lib/VM/gcs/HadesGC.cpp @@ -1296,6 +1296,7 @@ HadesGC::HadesGC( kConcurrentGC ? std::make_unique() : nullptr}, promoteYGToOG_{!gcConfig.getAllocInYoung()}, revertToYGAtTTI_{gcConfig.getRevertToYGAtTTI()}, + overwriteDeadYGObjects_{gcConfig.getOverwriteDeadYGObjects()}, occupancyTarget_(gcConfig.getOccupancyTarget()), ygAverageSurvivalBytes_{ /*weight*/ 0.5, @@ -2503,6 +2504,10 @@ void HadesGC::youngGenCollection( // This was modified by debitExternalMemoryFromFinalizer, called by // finalizers. The difference in the value before to now was the swept bytes externalBytes.after = getYoungGenExternalBytes(); + + if (overwriteDeadYGObjects_) + memset(yg.start(), kInvalidHeapValue, yg.used()); + // Now the copy list is drained, and all references point to the old // gen. Clear the level of the young gen. yg.resetLevel(); diff --git a/public/hermes/Public/GCConfig.h b/public/hermes/Public/GCConfig.h index e81359dff53..8d2553d918f 100644 --- a/public/hermes/Public/GCConfig.h +++ b/public/hermes/Public/GCConfig.h @@ -184,6 +184,9 @@ enum class GCEventKind { /* old gen (false). */ \ F(constexpr, bool, AllocInYoung, true) \ \ + /* Whether to fill the YG with invalid data after each collection. */ \ + F(constexpr, bool, OverwriteDeadYGObjects, false) \ + \ /* Whether to revert, if necessary, to young-gen allocation at TTI. */ \ F(constexpr, bool, RevertToYGAtTTI, false) \ \