Bug 1461938 part 10 - Move {maps,sets}WithNurseryMemory from JSCompartment to Nursery. r=jonco

This commit is contained in:
Jan de Mooij 2018-05-22 15:00:53 +02:00
Родитель 578ee6fdf0
Коммит dfa989c141
5 изменённых файлов: 39 добавлений и 41 удалений

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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)

Просмотреть файл

@ -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<NativeObject*, 0, SystemAllocPolicy>;
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<MapObject*, 0, SystemAllocPolicy> mapsWithNurseryMemory_;
Vector<SetObject*, 0, SystemAllocPolicy> 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);

Просмотреть файл

@ -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;

Просмотреть файл

@ -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<js::MapObject*, 0, js::SystemAllocPolicy> mapsWithNurseryMemory;
js::Vector<js::SetObject*, 0, js::SystemAllocPolicy> setsWithNurseryMemory;
};
class JS::Realm : public JSCompartment