From dfa989c141468050538e8775d6cf406aba5b1d14 Mon Sep 17 00:00:00 2001 From: Jan de Mooij Date: Tue, 22 May 2018 15:00:53 +0200 Subject: [PATCH] Bug 1461938 part 10 - Move {maps,sets}WithNurseryMemory from JSCompartment to Nursery. r=jonco --- js/src/builtin/MapObject.cpp | 8 ++++---- js/src/gc/Nursery.cpp | 14 ++++++++++++++ js/src/gc/Nursery.h | 21 +++++++++++++++++++++ js/src/vm/JSCompartment.cpp | 15 --------------- js/src/vm/JSCompartment.h | 22 ---------------------- 5 files changed, 39 insertions(+), 41 deletions(-) diff --git a/js/src/builtin/MapObject.cpp b/js/src/builtin/MapObject.cpp index 4facbe6e98ae..160785259165 100644 --- a/js/src/builtin/MapObject.cpp +++ b/js/src/builtin/MapObject.cpp @@ -246,7 +246,7 @@ MapIteratorObject::create(JSContext* cx, HandleObject obj, ValueMap* data, bool insideNursery = IsInsideNursery(iterobj); MOZ_ASSERT(insideNursery == nursery.isInside(buffer)); if (insideNursery && !HasNurseryMemory(mapobj.get())) { - if (!cx->compartment()->addMapWithNurseryMemory(mapobj)) { + if (!cx->nursery().addMapWithNurseryMemory(mapobj)) { ReportOutOfMemory(cx); return nullptr; } @@ -644,7 +644,7 @@ MapObject::create(JSContext* cx, HandleObject proto /* = nullptr */) return nullptr; bool insideNursery = IsInsideNursery(mapObj); - if (insideNursery && !cx->compartment()->addMapWithNurseryMemory(mapObj)) { + if (insideNursery && !cx->nursery().addMapWithNurseryMemory(mapObj)) { ReportOutOfMemory(cx); return nullptr; } @@ -1097,7 +1097,7 @@ SetIteratorObject::create(JSContext* cx, HandleObject obj, ValueSet* data, bool insideNursery = IsInsideNursery(iterobj); MOZ_ASSERT(insideNursery == nursery.isInside(buffer)); if (insideNursery && !HasNurseryMemory(setobj.get())) { - if (!cx->compartment()->addSetWithNurseryMemory(setobj)) { + if (!cx->nursery().addSetWithNurseryMemory(setobj)) { ReportOutOfMemory(cx); return nullptr; } @@ -1327,7 +1327,7 @@ SetObject::create(JSContext* cx, HandleObject proto /* = nullptr */) return nullptr; bool insideNursery = IsInsideNursery(obj); - if (insideNursery && !cx->compartment()->addSetWithNurseryMemory(obj)) { + if (insideNursery && !cx->nursery().addSetWithNurseryMemory(obj)) { ReportOutOfMemory(cx); return nullptr; } diff --git a/js/src/gc/Nursery.cpp b/js/src/gc/Nursery.cpp index 8be82db6867e..f122fa6700c5 100644 --- a/js/src/gc/Nursery.cpp +++ b/js/src/gc/Nursery.cpp @@ -1033,6 +1033,7 @@ js::Nursery::sweep(JSTracer* trc) c->sweepAfterMinorGC(trc); sweepDictionaryModeObjects(); + sweepMapAndSetObjects(); } void @@ -1246,6 +1247,19 @@ js::Nursery::sweepDictionaryModeObjects() dictionaryModeObjects_.clear(); } +void +js::Nursery::sweepMapAndSetObjects() +{ + auto fop = runtime_->defaultFreeOp(); + + for (auto mapobj : mapsWithNurseryMemory_) + MapObject::sweepAfterMinorGC(fop, mapobj); + mapsWithNurseryMemory_.clearAndFree(); + + for (auto setobj : setsWithNurseryMemory_) + SetObject::sweepAfterMinorGC(fop, setobj); + setsWithNurseryMemory_.clearAndFree(); +} JS_PUBLIC_API(void) JS::EnableNurseryStrings(JSContext* cx) diff --git a/js/src/gc/Nursery.h b/js/src/gc/Nursery.h index f0036da55d2b..772cd43e9fd2 100644 --- a/js/src/gc/Nursery.h +++ b/js/src/gc/Nursery.h @@ -51,6 +51,8 @@ class Nursery; struct NurseryChunk; class HeapSlot; class JSONPrinter; +class MapObject; +class SetObject; void SetGCZeal(JSRuntime*, uint8_t, uint32_t); @@ -337,6 +339,17 @@ class Nursery bool enableProfiling() const { return enableProfiling_; } + bool addMapWithNurseryMemory(MapObject* obj) { + MOZ_ASSERT_IF(!mapsWithNurseryMemory_.empty(), + mapsWithNurseryMemory_.back() != obj); + return mapsWithNurseryMemory_.append(obj); + } + bool addSetWithNurseryMemory(SetObject* obj) { + MOZ_ASSERT_IF(!setsWithNurseryMemory_.empty(), + setsWithNurseryMemory_.back() != obj); + return setsWithNurseryMemory_.append(obj); + } + /* The amount of space in the mapped nursery available to allocations. */ static const size_t NurseryChunkUsableSize = gc::ChunkSize - gc::ChunkTrailerSize; @@ -483,6 +496,13 @@ class Nursery using NativeObjectVector = Vector; NativeObjectVector dictionaryModeObjects_; + /* + * Lists of map and set objects allocated in the nursery or with iterators + * allocated there. Such objects need to be swept after minor GC. + */ + Vector mapsWithNurseryMemory_; + Vector setsWithNurseryMemory_; + #ifdef JS_GC_ZEAL struct Canary; Canary* lastCanary_; @@ -545,6 +565,7 @@ class Nursery void clear(); void sweepDictionaryModeObjects(); + void sweepMapAndSetObjects(); /* Change the allocable space provided by the nursery. */ void maybeResizeNursery(JS::gcreason::Reason reason); diff --git a/js/src/vm/JSCompartment.cpp b/js/src/vm/JSCompartment.cpp index c3b30d31415c..aa7412b81cd4 100644 --- a/js/src/vm/JSCompartment.cpp +++ b/js/src/vm/JSCompartment.cpp @@ -760,7 +760,6 @@ JSCompartment::sweepAfterMinorGC(JSTracer* trc) crossCompartmentWrappers.sweepAfterMinorGC(trc); dtoaCache.purge(); - sweepMapAndSetObjectsAfterMinorGC(); } void @@ -842,20 +841,6 @@ Realm::sweepVarNames() varNames_.sweep(); } -void -JSCompartment::sweepMapAndSetObjectsAfterMinorGC() -{ - auto fop = runtime_->defaultFreeOp(); - - for (auto mapobj : mapsWithNurseryMemory) - MapObject::sweepAfterMinorGC(fop, mapobj); - mapsWithNurseryMemory.clearAndFree(); - - for (auto setobj : setsWithNurseryMemory) - SetObject::sweepAfterMinorGC(fop, setobj); - setsWithNurseryMemory.clearAndFree(); -} - namespace { struct TraceRootFunctor { JSTracer* trc; diff --git a/js/src/vm/JSCompartment.h b/js/src/vm/JSCompartment.h index 3c4ddd6d6bbe..2f3bc11719e3 100644 --- a/js/src/vm/JSCompartment.h +++ b/js/src/vm/JSCompartment.h @@ -842,7 +842,6 @@ struct JSCompartment static void traceIncomingCrossCompartmentEdgesForZoneGC(JSTracer* trc); void sweepAfterMinorGC(JSTracer* trc); - void sweepMapAndSetObjectsAfterMinorGC(); void sweepCrossCompartmentWrappers(); void sweepSavedStacks(); @@ -1069,27 +1068,6 @@ struct JSCompartment // Aggregated output used to collect JSScript hit counts when code coverage // is enabled. js::coverage::LCovCompartment lcovOutput; - - bool addMapWithNurseryMemory(js::MapObject* obj) { - MOZ_ASSERT_IF(!mapsWithNurseryMemory.empty(), - mapsWithNurseryMemory.back() != obj); - return mapsWithNurseryMemory.append(obj); - } - - bool addSetWithNurseryMemory(js::SetObject* obj) { - MOZ_ASSERT_IF(!setsWithNurseryMemory.empty(), - setsWithNurseryMemory.back() != obj); - return setsWithNurseryMemory.append(obj); - } - - private: - - /* - * Lists of map and set objects allocated in the nursery or with iterators - * allocated there. Such objects need to be swept after minor GC. - */ - js::Vector mapsWithNurseryMemory; - js::Vector setsWithNurseryMemory; }; class JS::Realm : public JSCompartment