Bug 1612447, part 3 - Fix sizes of XPCMaps. r=bzbarsky

This will make the places we call ctors a little nicer, and the
extra flexibility is never used.

Differential Revision: https://phabricator.services.mozilla.com/D61329

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrew McCreight 2020-02-05 03:29:29 +00:00
Родитель 72a91c0d86
Коммит 3fb9c6fefb
6 изменённых файлов: 44 добавлений и 46 удалений

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

@ -200,7 +200,7 @@ CompartmentPrivate::CompartmentPrivate(
isUAWidgetCompartment(false),
hasExclusiveExpandos(false),
wasShutdown(false),
mWrappedJSMap(new JSObject2WrappedJSMap(XPC_JS_MAP_LENGTH)),
mWrappedJSMap(new JSObject2WrappedJSMap()),
mScope(std::move(scope)) {
MOZ_COUNT_CTOR(xpc::CompartmentPrivate);
}
@ -2913,15 +2913,12 @@ static const JSWrapObjectCallbacks WrapObjectCallbacks = {
XPCJSRuntime::XPCJSRuntime(JSContext* aCx)
: CycleCollectedJSRuntime(aCx),
mWrappedJSMap(new JSObject2WrappedJSMap(XPC_JS_MAP_LENGTH)),
mIID2NativeInterfaceMap(
new IID2NativeInterfaceMap(XPC_NATIVE_INTERFACE_MAP_LENGTH)),
mClassInfo2NativeSetMap(
new ClassInfo2NativeSetMap(XPC_NATIVE_SET_MAP_LENGTH)),
mNativeSetMap(new NativeSetMap(XPC_NATIVE_SET_MAP_LENGTH)),
mWrappedJSMap(new JSObject2WrappedJSMap()),
mIID2NativeInterfaceMap(new IID2NativeInterfaceMap()),
mClassInfo2NativeSetMap(new ClassInfo2NativeSetMap()),
mNativeSetMap(new NativeSetMap()),
mWrappedNativeScopes(),
mDyingWrappedNativeProtoMap(
new XPCWrappedNativeProtoMap(XPC_DYING_NATIVE_PROTO_MAP_LENGTH)),
mDyingWrappedNativeProtoMap(new XPCWrappedNativeProtoMap()),
mGCIsRunning(false),
mNativesToReleaseArray(),
mDoingFinalization(false),

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

@ -97,8 +97,8 @@ size_t JSObject2WrappedJSMap::SizeOfWrappedJS(
/***************************************************************************/
// implement Native2WrappedNativeMap...
Native2WrappedNativeMap::Native2WrappedNativeMap(int length)
: mTable(PLDHashTable::StubOps(), sizeof(Entry), length) {}
Native2WrappedNativeMap::Native2WrappedNativeMap()
: mTable(PLDHashTable::StubOps(), sizeof(Entry), XPC_NATIVE_MAP_LENGTH) {}
size_t Native2WrappedNativeMap::SizeOfIncludingThis(
mozilla::MallocSizeOf mallocSizeOf) const {
@ -118,8 +118,8 @@ const struct PLDHashTableOps IID2NativeInterfaceMap::Entry::sOps = {
HashIIDPtrKey, MatchIIDPtrKey, PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub};
IID2NativeInterfaceMap::IID2NativeInterfaceMap(int length)
: mTable(&Entry::sOps, sizeof(Entry), length) {}
IID2NativeInterfaceMap::IID2NativeInterfaceMap()
: mTable(&Entry::sOps, sizeof(Entry), XPC_NATIVE_INTERFACE_MAP_LENGTH) {}
size_t IID2NativeInterfaceMap::SizeOfIncludingThis(
mozilla::MallocSizeOf mallocSizeOf) const {
@ -155,8 +155,9 @@ const PLDHashTableOps ClassInfo2NativeSetMap::Entry::sOps = {
PLDHashTable::HashVoidPtrKeyStub, Match, PLDHashTable::MoveEntryStub, Clear,
nullptr};
ClassInfo2NativeSetMap::ClassInfo2NativeSetMap(int length)
: mTable(&ClassInfo2NativeSetMap::Entry::sOps, sizeof(Entry), length) {}
ClassInfo2NativeSetMap::ClassInfo2NativeSetMap()
: mTable(&ClassInfo2NativeSetMap::Entry::sOps, sizeof(Entry),
XPC_NATIVE_SET_MAP_LENGTH) {}
size_t ClassInfo2NativeSetMap::ShallowSizeOfIncludingThis(
mozilla::MallocSizeOf mallocSizeOf) {
@ -168,8 +169,9 @@ size_t ClassInfo2NativeSetMap::ShallowSizeOfIncludingThis(
/***************************************************************************/
// implement ClassInfo2WrappedNativeProtoMap...
ClassInfo2WrappedNativeProtoMap::ClassInfo2WrappedNativeProtoMap(int length)
: mTable(PLDHashTable::StubOps(), sizeof(Entry), length) {}
ClassInfo2WrappedNativeProtoMap::ClassInfo2WrappedNativeProtoMap()
: mTable(PLDHashTable::StubOps(), sizeof(Entry),
XPC_NATIVE_PROTO_MAP_LENGTH) {}
size_t ClassInfo2WrappedNativeProtoMap::SizeOfIncludingThis(
mozilla::MallocSizeOf mallocSizeOf) const {
@ -231,8 +233,8 @@ const struct PLDHashTableOps NativeSetMap::Entry::sOps = {
HashNativeKey, Match, PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub};
NativeSetMap::NativeSetMap(int length)
: mTable(&Entry::sOps, sizeof(Entry), length) {}
NativeSetMap::NativeSetMap()
: mTable(&Entry::sOps, sizeof(Entry), XPC_NATIVE_SET_MAP_LENGTH) {}
size_t NativeSetMap::SizeOfIncludingThis(
mozilla::MallocSizeOf mallocSizeOf) const {
@ -248,7 +250,8 @@ size_t NativeSetMap::SizeOfIncludingThis(
/***************************************************************************/
// implement XPCWrappedNativeProtoMap...
XPCWrappedNativeProtoMap::XPCWrappedNativeProtoMap(int length)
: mTable(PLDHashTable::StubOps(), sizeof(PLDHashEntryStub), length) {}
XPCWrappedNativeProtoMap::XPCWrappedNativeProtoMap()
: mTable(PLDHashTable::StubOps(), sizeof(PLDHashEntryStub),
XPC_DYING_NATIVE_PROTO_MAP_LENGTH) {}
/***************************************************************************/

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

@ -23,6 +23,18 @@
// no virtuals in the maps - all the common stuff inlined
// templates could be used to good effect here.
/***************************************************************************/
// default initial sizes for maps (hashtables)
#define XPC_JS_MAP_LENGTH 32
#define XPC_NATIVE_MAP_LENGTH 8
#define XPC_NATIVE_PROTO_MAP_LENGTH 8
#define XPC_DYING_NATIVE_PROTO_MAP_LENGTH 8
#define XPC_NATIVE_INTERFACE_MAP_LENGTH 32
#define XPC_NATIVE_SET_MAP_LENGTH 32
#define XPC_WRAPPER_MAP_LENGTH 8
/*************************/
class JSObject2WrappedJSMap {
@ -31,7 +43,7 @@ class JSObject2WrappedJSMap {
InfallibleAllocPolicy>;
public:
explicit JSObject2WrappedJSMap(size_t length) : mTable(length) {}
JSObject2WrappedJSMap() : mTable(XPC_JS_MAP_LENGTH) {}
inline nsXPCWrappedJS* Find(JSObject* Obj) {
MOZ_ASSERT(Obj, "bad param");
@ -99,7 +111,7 @@ class Native2WrappedNativeMap {
XPCWrappedNative* value;
};
explicit Native2WrappedNativeMap(int size);
Native2WrappedNativeMap();
inline XPCWrappedNative* Find(nsISupports* Obj) const {
MOZ_ASSERT(Obj, "bad param");
@ -146,7 +158,7 @@ class IID2NativeInterfaceMap {
static const struct PLDHashTableOps sOps;
};
explicit IID2NativeInterfaceMap(int size);
IID2NativeInterfaceMap();
inline XPCNativeInterface* Find(REFNSIID iid) const {
auto entry = static_cast<Entry*>(mTable.Search(&iid));
@ -197,7 +209,7 @@ class ClassInfo2NativeSetMap {
static void Clear(PLDHashTable* aTable, PLDHashEntryHdr* aEntry);
};
explicit ClassInfo2NativeSetMap(int size);
ClassInfo2NativeSetMap();
inline XPCNativeSet* Find(nsIClassInfo* info) const {
auto entry = static_cast<Entry*>(mTable.Search(info));
@ -244,7 +256,7 @@ class ClassInfo2WrappedNativeProtoMap {
XPCWrappedNativeProto* value;
};
explicit ClassInfo2WrappedNativeProtoMap(int size);
ClassInfo2WrappedNativeProtoMap();
inline XPCWrappedNativeProto* Find(nsIClassInfo* info) const {
auto entry = static_cast<Entry*>(mTable.Search(info));
@ -290,7 +302,7 @@ class NativeSetMap {
static const struct PLDHashTableOps sOps;
};
explicit NativeSetMap(int size);
NativeSetMap();
inline XPCNativeSet* Find(XPCNativeSetKey* key) const {
auto entry = static_cast<Entry*>(mTable.Search(key));
@ -347,7 +359,7 @@ class XPCWrappedNativeProtoMap {
public:
typedef PLDHashEntryStub Entry;
explicit XPCWrappedNativeProtoMap(int size);
XPCWrappedNativeProtoMap();
inline XPCWrappedNativeProto* Add(XPCWrappedNativeProto* proto) {
MOZ_ASSERT(proto, "bad param");
@ -379,7 +391,7 @@ class JSObject2JSObjectMap {
js::SystemAllocPolicy>;
public:
explicit JSObject2JSObjectMap(size_t length) : mTable(length) {}
JSObject2JSObjectMap() : mTable(XPC_WRAPPER_MAP_LENGTH) {}
inline JSObject* Find(JSObject* key) {
MOZ_ASSERT(key, "bad param");

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

@ -63,9 +63,8 @@ static bool RemoteXULForbidsXBLScope(HandleObject aFirstGlobal) {
XPCWrappedNativeScope::XPCWrappedNativeScope(JS::Compartment* aCompartment,
JS::HandleObject aFirstGlobal)
: mWrappedNativeMap(new Native2WrappedNativeMap(XPC_NATIVE_MAP_LENGTH)),
mWrappedNativeProtoMap(
new ClassInfo2WrappedNativeProtoMap(XPC_NATIVE_PROTO_MAP_LENGTH)),
: mWrappedNativeMap(new Native2WrappedNativeMap()),
mWrappedNativeProtoMap(new ClassInfo2WrappedNativeProtoMap()),
mComponents(nullptr),
mCompartment(aCompartment) {
#ifdef DEBUG

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

@ -165,18 +165,6 @@ class Exception;
} // namespace dom
} // namespace mozilla
/***************************************************************************/
// default initial sizes for maps (hashtables)
#define XPC_JS_MAP_LENGTH 32
#define XPC_NATIVE_MAP_LENGTH 8
#define XPC_NATIVE_PROTO_MAP_LENGTH 8
#define XPC_DYING_NATIVE_PROTO_MAP_LENGTH 8
#define XPC_NATIVE_INTERFACE_MAP_LENGTH 32
#define XPC_NATIVE_SET_MAP_LENGTH 32
#define XPC_WRAPPER_MAP_LENGTH 8
/***************************************************************************/
// data declarations...
extern const char XPC_EXCEPTION_CONTRACTID[];

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

@ -80,8 +80,7 @@ JSObject* WrapperFactory::CreateXrayWaiver(JSContext* cx, HandleObject obj,
// Add the new waiver to the map. It's important that we only ever have
// one waiver for the lifetime of the target object.
if (!scope->mWaiverWrapperMap) {
scope->mWaiverWrapperMap =
mozilla::MakeUnique<JSObject2JSObjectMap>(XPC_WRAPPER_MAP_LENGTH);
scope->mWaiverWrapperMap = mozilla::MakeUnique<JSObject2JSObjectMap>();
}
if (!scope->mWaiverWrapperMap->Add(cx, obj, waiver)) {
return nullptr;