Bug 1395509 - Track malloc memory associated with WeakMap objects r=pbone
authorJon Coppeard <jcoppeard@mozilla.com>
Mon, 10 Jun 2019 16:11:25 +0100
changeset 478501 1a2985fdef253d029033e917aad40cb30a1a5f2f
parent 478500 0943e5feaa8dba351ac8fdd1a9f3b6a66e98c78b
child 478502 82c5c40a88819dadd5d156e1570d8fd90fb4bab8
push id36144
push useraciure@mozilla.com
push dateWed, 12 Jun 2019 21:42:35 +0000
treeherdermozilla-central@848ce760ba38 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbone
bugs1395509
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1395509 - Track malloc memory associated with WeakMap objects r=pbone Use memory tracking APIs to track malloc memory associated with weak maps. Differential Revision: https://phabricator.services.mozilla.com/D34376
js/src/builtin/WeakMapObject-inl.h
js/src/builtin/WeakMapObject.cpp
js/src/gc/GCEnum.h
--- a/js/src/builtin/WeakMapObject-inl.h
+++ b/js/src/builtin/WeakMapObject-inl.h
@@ -32,17 +32,17 @@ static MOZ_ALWAYS_INLINE bool WeakCollec
     HandleValue value) {
   ObjectValueMap* map = obj->getMap();
   if (!map) {
     auto newMap = cx->make_unique<ObjectValueMap>(cx, obj.get());
     if (!newMap) {
       return false;
     }
     map = newMap.release();
-    obj->setPrivate(map);
+    InitObjectPrivate(obj, map, MemoryUse::WeakMapObject);
   }
 
   // Preserve wrapped native keys to prevent wrapper optimization.
   if (!TryPreserveReflector(cx, key)) {
     return false;
   }
 
   RootedObject delegate(cx, UncheckedUnwrapWithoutExpose(key));
--- a/js/src/builtin/WeakMapObject.cpp
+++ b/js/src/builtin/WeakMapObject.cpp
@@ -176,17 +176,17 @@ static void WeakCollection_trace(JSTrace
   if (ObjectValueMap* map = obj->as<WeakCollectionObject>().getMap()) {
     map->trace(trc);
   }
 }
 
 static void WeakCollection_finalize(FreeOp* fop, JSObject* obj) {
   MOZ_ASSERT(fop->maybeOnHelperThread());
   if (ObjectValueMap* map = obj->as<WeakCollectionObject>().getMap()) {
-    fop->delete_(map);
+    fop->delete_(obj, map, MemoryUse::WeakMapObject);
   }
 }
 
 JS_PUBLIC_API JSObject* JS::NewWeakMapObject(JSContext* cx) {
   return NewBuiltinClassInstance<WeakMapObject>(cx);
 }
 
 JS_PUBLIC_API bool JS::IsWeakMapObject(JSObject* obj) {
--- a/js/src/gc/GCEnum.h
+++ b/js/src/gc/GCEnum.h
@@ -95,17 +95,18 @@ enum class ZealMode {
   _(ArrayBufferContents)                   \
   _(StringContents)                        \
   _(ObjectElements)                        \
   _(ObjectSlots)                           \
   _(ScriptPrivateData)                     \
   _(LazyScriptData)                        \
   _(MapObjectTable)                        \
   _(BigIntDigits)                          \
-  _(ScopeData)
+  _(ScopeData)                             \
+  _(WeakMapObject)
 
 #define JS_FOR_EACH_MEMORY_USE(_)  \
   JS_FOR_EACH_PUBLIC_MEMORY_USE(_) \
   JS_FOR_EACH_INTERNAL_MEMORY_USE(_)
 
 enum class MemoryUse : uint8_t {
 #define DEFINE_MEMORY_USE(Name) Name,
   JS_FOR_EACH_MEMORY_USE(DEFINE_MEMORY_USE)