From 8dd16259287f58f9273002717ec4d27e97127719 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:43:14 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- js/src/gc/WeakMap-inl.h | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'js/src/gc/WeakMap-inl.h') diff --git a/js/src/gc/WeakMap-inl.h b/js/src/gc/WeakMap-inl.h index d7b5feb5a6..b1e52aacc8 100644 --- a/js/src/gc/WeakMap-inl.h +++ b/js/src/gc/WeakMap-inl.h @@ -22,6 +22,7 @@ #include "js/TraceKind.h" #include "vm/JSContext.h" +#include "gc/Marking-inl.h" #include "gc/StableCellHasher-inl.h" namespace js { @@ -184,23 +185,24 @@ bool WeakMap::markEntry(GCMarker* marker, gc::CellColor mapColor, K& key, } if (populateWeakKeysTable) { + MOZ_ASSERT(trc->weakMapAction() == JS::WeakMapTraceAction::Expand); + // Note that delegateColor >= keyColor because marking a key marks its // delegate, so we only need to check whether keyColor < mapColor to tell // this. - if (keyColor < mapColor) { - MOZ_ASSERT(trc->weakMapAction() == JS::WeakMapTraceAction::Expand); - // The final color of the key is not yet known. Record this weakmap and - // the lookup key in the list of weak keys. If the key has a delegate, - // then the lookup key is the delegate (because marking the key will end - // up marking the delegate and thereby mark the entry.) + // The final color of the key is not yet known. Add an edge to the + // relevant ephemerons table to ensure that the value will be marked if + // the key is marked. If the key has a delegate, also add an edge to + // ensure the key is marked if the delegate is marked. + gc::TenuredCell* tenuredValue = nullptr; if (cellValue && cellValue->isTenured()) { tenuredValue = &cellValue->asTenured(); } - if (!this->addImplicitEdges(AsMarkColor(mapColor), keyCell, delegate, - tenuredValue)) { + if (!this->addEphemeronEdgesForEntry(AsMarkColor(mapColor), keyCell, + delegate, tenuredValue)) { marker->abortLinearWeakMarking(); } } @@ -392,6 +394,24 @@ bool WeakMap::checkMarking() const { } #endif +#ifdef JSGC_HASH_TABLE_CHECKS +template +void WeakMap::checkAfterMovingGC() const { + for (Range r = all(); !r.empty(); r.popFront()) { + gc::Cell* key = gc::ToMarkable(r.front().key()); + gc::Cell* value = gc::ToMarkable(r.front().value()); + CheckGCThingAfterMovingGC(key); + if (!allowKeysInOtherZones()) { + Zone* keyZone = key->zoneFromAnyThread(); + MOZ_RELEASE_ASSERT(keyZone == zone() || keyZone->isAtomsZone()); + } + CheckGCThingAfterMovingGC(value, zone()); + auto ptr = lookupUnbarriered(r.front().key()); + MOZ_RELEASE_ASSERT(ptr.found() && &*ptr == &r.front()); + } +} +#endif // JSGC_HASH_TABLE_CHECKS + inline HashNumber GetHash(JS::Symbol* sym) { return sym->hash(); } inline bool HashMatch(JS::Symbol* key, JS::Symbol* lookup) { -- cgit v1.2.3