Bug 1461938 part 13 - Move dtoaCache and newProxyCache from JSCompartment to JS::Realm. r=anba

This commit is contained in:
Jan de Mooij 2018-05-22 15:02:37 +02:00
Родитель b4bf5c547f
Коммит 1da2a378bb
7 изменённых файлов: 30 добавлений и 30 удалений

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

@ -4013,8 +4013,8 @@ GCRuntime::purgeRuntime()
{ {
gcstats::AutoPhase ap(stats(), gcstats::PhaseKind::PURGE); gcstats::AutoPhase ap(stats(), gcstats::PhaseKind::PURGE);
for (GCCompartmentsIter comp(rt); !comp.done(); comp.next()) for (GCRealmsIter realm(rt); !realm.done(); realm.next())
comp->purge(); realm->purge();
for (GCZonesIter zone(rt); !zone.done(); zone.next()) { for (GCZonesIter zone(rt); !zone.done(); zone.next()) {
zone->atomCache().clearAndShrink(); zone->atomCache().clearAndShrink();

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

@ -89,7 +89,8 @@ class GCZonesIter
JS::Zone* operator->() const { return get(); } JS::Zone* operator->() const { return get(); }
}; };
typedef CompartmentsIterT<GCZonesIter> GCCompartmentsIter; using GCCompartmentsIter = CompartmentsIterT<GCZonesIter>;
using GCRealmsIter = RealmsIterT<GCZonesIter>;
/* Iterates over all zones in the current sweep group. */ /* Iterates over all zones in the current sweep group. */
class SweepGroupZonesIter { class SweepGroupZonesIter {

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

@ -56,7 +56,7 @@ BEGIN_TEST(testIndexToString)
CHECK(str); CHECK(str);
if (!js::StaticStrings::hasUint(u)) if (!js::StaticStrings::hasUint(u))
CHECK(cx->compartment()->dtoaCache.lookup(10, u) == str); CHECK(cx->realm()->dtoaCache.lookup(10, u) == str);
bool match = false; bool match = false;
CHECK(JS_StringEqualsAscii(cx, str, tests[i].expected, &match)); CHECK(JS_StringEqualsAscii(cx, str, tests[i].expected, &match));

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

@ -568,8 +568,8 @@ MOZ_ALWAYS_INLINE
static JSFlatString* static JSFlatString*
LookupDtoaCache(JSContext* cx, double d) LookupDtoaCache(JSContext* cx, double d)
{ {
if (JSCompartment* comp = cx->compartment()) { if (Realm* realm = cx->realm()) {
if (JSFlatString* str = comp->dtoaCache.lookup(10, d)) if (JSFlatString* str = realm->dtoaCache.lookup(10, d))
return str; return str;
} }
@ -580,8 +580,8 @@ MOZ_ALWAYS_INLINE
static void static void
CacheNumber(JSContext* cx, double d, JSFlatString* str) CacheNumber(JSContext* cx, double d, JSFlatString* str)
{ {
if (JSCompartment* comp = cx->compartment()) if (Realm* realm = cx->realm())
comp->dtoaCache.cache(10, d, str); realm->dtoaCache.cache(10, d, str);
} }
MOZ_ALWAYS_INLINE MOZ_ALWAYS_INLINE
@ -1327,7 +1327,7 @@ NumberToStringWithBase(JSContext* cx, double d, int base)
ToCStringBuf cbuf; ToCStringBuf cbuf;
char* numStr; char* numStr;
JSCompartment* comp = cx->compartment(); Realm* realm = cx->realm();
int32_t i; int32_t i;
bool isBase10Int = false; bool isBase10Int = false;
@ -1343,14 +1343,14 @@ NumberToStringWithBase(JSContext* cx, double d, int base)
return cx->staticStrings().getUnit(c); return cx->staticStrings().getUnit(c);
} }
if (JSFlatString* str = comp->dtoaCache.lookup(base, d)) if (JSFlatString* str = realm->dtoaCache.lookup(base, d))
return str; return str;
size_t len; size_t len;
numStr = Int32ToCString(&cbuf, i, &len, base); numStr = Int32ToCString(&cbuf, i, &len, base);
MOZ_ASSERT(!cbuf.dbuf && numStr >= cbuf.sbuf && numStr < cbuf.sbuf + cbuf.sbufSize); MOZ_ASSERT(!cbuf.dbuf && numStr >= cbuf.sbuf && numStr < cbuf.sbuf + cbuf.sbufSize);
} else { } else {
if (JSFlatString* str = comp->dtoaCache.lookup(base, d)) if (JSFlatString* str = realm->dtoaCache.lookup(base, d))
return str; return str;
numStr = FracNumberToCString(cx, &cbuf, d, base); numStr = FracNumberToCString(cx, &cbuf, d, base);
@ -1371,7 +1371,7 @@ NumberToStringWithBase(JSContext* cx, double d, int base)
if (isBase10Int && i >= 0) if (isBase10Int && i >= 0)
s->maybeInitializeIndex(i); s->maybeInitializeIndex(i);
comp->dtoaCache.cache(base, d, s); realm->dtoaCache.cache(base, d, s);
return s; return s;
} }
@ -1422,8 +1422,8 @@ js::IndexToString(JSContext* cx, uint32_t index)
if (StaticStrings::hasUint(index)) if (StaticStrings::hasUint(index))
return cx->staticStrings().getUint(index); return cx->staticStrings().getUint(index);
JSCompartment* c = cx->compartment(); Realm* realm = cx->realm();
if (JSFlatString* str = c->dtoaCache.lookup(10, index)) if (JSFlatString* str = realm->dtoaCache.lookup(10, index))
return str; return str;
Latin1Char buffer[JSFatInlineString::MAX_LENGTH_LATIN1 + 1]; Latin1Char buffer[JSFatInlineString::MAX_LENGTH_LATIN1 + 1];
@ -1437,7 +1437,7 @@ js::IndexToString(JSContext* cx, uint32_t index)
if (!str) if (!str)
return nullptr; return nullptr;
c->dtoaCache.cache(10, index, str); realm->dtoaCache.cache(10, index, str);
return str; return str;
} }

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

@ -759,7 +759,9 @@ JSCompartment::sweepAfterMinorGC(JSTracer* trc)
table.sweepAfterMinorGC(); table.sweepAfterMinorGC();
crossCompartmentWrappers.sweepAfterMinorGC(trc); crossCompartmentWrappers.sweepAfterMinorGC(trc);
dtoaCache.purge();
Realm* realm = JS::GetRealmForCompartment(this);
realm->dtoaCache.purge();
} }
void void
@ -902,7 +904,7 @@ JSCompartment::fixupAfterMovingGC()
Realm* realm = JS::GetRealmForCompartment(this); Realm* realm = JS::GetRealmForCompartment(this);
purge(); realm->purge();
realm->fixupGlobal(); realm->fixupGlobal();
objectGroups.fixupTablesAfterMovingGC(); objectGroups.fixupTablesAfterMovingGC();
realm->fixupScriptMapsAfterMovingGC(); realm->fixupScriptMapsAfterMovingGC();
@ -994,7 +996,7 @@ Realm::checkScriptMapsAfterMovingGC()
#endif #endif
void void
JSCompartment::purge() Realm::purge()
{ {
dtoaCache.purge(); dtoaCache.purge();
newProxyCache.purge(); newProxyCache.purge();

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

@ -851,8 +851,6 @@ struct JSCompartment
void sweepNativeIterators(); void sweepNativeIterators();
void sweepTemplateObjects(); void sweepTemplateObjects();
void purge();
static void fixupCrossCompartmentWrappersAfterMovingGC(JSTracer* trc); static void fixupCrossCompartmentWrappersAfterMovingGC(JSTracer* trc);
void fixupAfterMovingGC(); void fixupAfterMovingGC();
@ -860,9 +858,6 @@ struct JSCompartment
void findOutgoingEdges(js::gc::ZoneComponentFinder& finder); void findOutgoingEdges(js::gc::ZoneComponentFinder& finder);
js::DtoaCache dtoaCache;
js::NewProxyCache newProxyCache;
// Random number generator for Math.random(). // Random number generator for Math.random().
mozilla::Maybe<mozilla::non_crypto::XorShift128PlusRNG> randomNumberGenerator; mozilla::Maybe<mozilla::non_crypto::XorShift128PlusRNG> randomNumberGenerator;
@ -881,10 +876,6 @@ struct JSCompartment
return offsetof(JSCompartment, regExps); return offsetof(JSCompartment, regExps);
} }
private:
JSCompartment* thisForCtor() { return this; }
public:
// //
// The Debugger observes execution on a frame-by-frame basis. The // The Debugger observes execution on a frame-by-frame basis. The
// invariants of JSCompartment's debug mode bits, JSScript::isDebuggee, // invariants of JSCompartment's debug mode bits, JSScript::isDebuggee,
@ -1071,6 +1062,9 @@ class JS::Realm : public JSCompartment
// WebAssembly state for the realm. // WebAssembly state for the realm.
js::wasm::Realm wasm; js::wasm::Realm wasm;
js::DtoaCache dtoaCache;
js::NewProxyCache newProxyCache;
js::ScriptCountsMap* scriptCountsMap = nullptr; js::ScriptCountsMap* scriptCountsMap = nullptr;
js::ScriptNameMap* scriptNameMap = nullptr; js::ScriptNameMap* scriptNameMap = nullptr;
js::DebugScriptMap* debugScriptMap = nullptr; js::DebugScriptMap* debugScriptMap = nullptr;
@ -1154,6 +1148,8 @@ class JS::Realm : public JSCompartment
void clearScriptCounts(); void clearScriptCounts();
void clearScriptNames(); void clearScriptNames();
void purge();
void fixupScriptMapsAfterMovingGC(); void fixupScriptMapsAfterMovingGC();
#ifdef JSGC_HASH_TABLE_CHECKS #ifdef JSGC_HASH_TABLE_CHECKS

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

@ -160,12 +160,12 @@ ProxyObject::create(JSContext* cx, const Class* clasp, Handle<TaggedProto> proto
{ {
MOZ_ASSERT(clasp->isProxy()); MOZ_ASSERT(clasp->isProxy());
JSCompartment* comp = cx->compartment(); Realm* realm = cx->realm();
RootedObjectGroup group(cx); RootedObjectGroup group(cx);
RootedShape shape(cx); RootedShape shape(cx);
// Try to look up the group and shape in the NewProxyCache. // Try to look up the group and shape in the NewProxyCache.
if (!comp->newProxyCache.lookup(clasp, proto, group.address(), shape.address())) { if (!realm->newProxyCache.lookup(clasp, proto, group.address(), shape.address())) {
group = ObjectGroup::defaultNewGroup(cx, clasp, proto, nullptr); group = ObjectGroup::defaultNewGroup(cx, clasp, proto, nullptr);
if (!group) if (!group)
return cx->alreadyReportedOOM(); return cx->alreadyReportedOOM();
@ -174,7 +174,8 @@ ProxyObject::create(JSContext* cx, const Class* clasp, Handle<TaggedProto> proto
if (!shape) if (!shape)
return cx->alreadyReportedOOM(); return cx->alreadyReportedOOM();
comp->newProxyCache.add(group, shape); MOZ_ASSERT(group->realm() == realm);
realm->newProxyCache.add(group, shape);
} }
gc::InitialHeap heap = GetInitialHeap(newKind, clasp); gc::InitialHeap heap = GetInitialHeap(newKind, clasp);