Bug 721628 (part 3) - Rename several size type-inference-related measurement functions and types. r=bhackett.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 26 Jan 2012 19:09:31 -0800
changeset 88202 19b63ce08d27a2d4fd1db21df1ed9560c2ec728b
parent 88201 c7cc6d203ced99d864dace315e2af078a49444b3
child 88203 829732925bfa6dbac73d7d73011119dac832fcc6
push idunknown
push userunknown
push dateunknown
reviewersbhackett
bugs721628
milestone12.0a1
Bug 721628 (part 3) - Rename several size type-inference-related measurement functions and types. r=bhackett.
js/public/MemoryMetrics.h
js/src/MemoryMetrics.cpp
js/src/jscompartment.cpp
js/src/jscompartment.h
js/src/jsinfer.cpp
js/src/jsinfer.h
js/xpconnect/src/XPCJSRuntime.cpp
--- a/js/public/MemoryMetrics.h
+++ b/js/public/MemoryMetrics.h
@@ -48,17 +48,17 @@
 #include "jspubtd.h"
 
 #include "js/Utility.h"
 #include "js/Vector.h"
 
 namespace JS {
 
 /* Data for tracking analysis/inference memory usage. */
-struct TypeInferenceMemoryStats
+struct TypeInferenceSizes
 {
     int64_t scripts;
     int64_t objects;
     int64_t tables;
     int64_t temporary;
 };
 
 typedef void* (* GetNameCallback)(JSContext *cx, JSCompartment *c);
@@ -108,17 +108,17 @@ struct CompartmentStats
     int64_t shapesExtraTreeShapeKids;
     int64_t shapesCompartmentTables;
     int64_t scriptData;
 
 #ifdef JS_METHODJIT
     int64_t mjitCode;
     int64_t mjitData;
 #endif
-    TypeInferenceMemoryStats typeInferenceMemory;
+    TypeInferenceSizes typeInferenceSizes;
 };
 
 struct IterateData
 {
     IterateData(JSMallocSizeOfFun mallocSizeOf, GetNameCallback getNameCb,
                 DestroyNameCallback destroyNameCb)
       : runtimeObject(0)
       , runtimeAtomsTable(0)
@@ -190,29 +190,16 @@ extern JS_PUBLIC_API(bool)
 CollectCompartmentStatsForRuntime(JSRuntime *rt, IterateData *data);
 
 extern JS_PUBLIC_API(bool)
 GetExplicitNonHeapForRuntime(JSRuntime *rt, int64_t *amount,
                              JSMallocSizeOfFun mallocSizeOf);
 
 #endif /* JS_THREADSAFE */
 
-extern void
-SizeOfCompartmentTypeInferenceData(JSContext *cx, JSCompartment *compartment,
-                                   TypeInferenceMemoryStats *stats,
-                                   JSMallocSizeOfFun mallocSizeOf);
-
-extern void
-SizeOfTypeObjectExcludingThis(/*TypeObject*/ void *object,
-                              TypeInferenceMemoryStats *stats,
-                              JSMallocSizeOfFun mallocSizeOf);
-
-extern size_t
-SizeOfCompartmentShapeTable(JSCompartment *c, JSMallocSizeOfFun mallocSizeOf);
-
 extern JS_PUBLIC_API(size_t)
 SystemCompartmentCount(const JSRuntime *rt);
 
 extern JS_PUBLIC_API(size_t)
 UserCompartmentCount(const JSRuntime *rt);
 
 } // namespace JS
 
--- a/js/src/MemoryMetrics.cpp
+++ b/js/src/MemoryMetrics.cpp
@@ -65,21 +65,18 @@ CompartmentMemoryCallback(JSContext *cx,
     CompartmentStats &curr = data->compartmentStatsVector.back();
     curr.init(data->getNameCb(cx, compartment), data->destroyNameCb);
     data->currCompartmentStats = &curr;
 
     // Get the compartment-level numbers.
 #ifdef JS_METHODJIT
     curr.mjitCode = compartment->sizeOfMjitCode();
 #endif
-    SizeOfCompartmentTypeInferenceData(cx, compartment,
-                                       &curr.typeInferenceMemory,
-                                       data->mallocSizeOf);
-    curr.shapesCompartmentTables =
-        SizeOfCompartmentShapeTable(compartment, data->mallocSizeOf);
+    compartment->sizeOfTypeInferenceData(cx, &curr.typeInferenceSizes, data->mallocSizeOf);
+    curr.shapesCompartmentTables = compartment->sizeOfShapeTable(data->mallocSizeOf);
 }
 
 static void
 ExplicitNonHeapCompartmentCallback(JSContext *cx, void *data, JSCompartment *compartment)
 {
 #ifdef JS_METHODJIT
     size_t *n = static_cast<size_t *>(data);
     *n += compartment->sizeOfMjitCode();
@@ -173,18 +170,17 @@ CellCallback(JSContext *cx, void *vdata,
         curr->mjitData += script->sizeOfJitScripts(data->mallocSizeOf);
 #endif
         break;
     }
     case JSTRACE_TYPE_OBJECT:
     {
         types::TypeObject *obj = static_cast<types::TypeObject *>(thing);
         curr->gcHeapTypeObjects += thingSize;
-        SizeOfTypeObjectExcludingThis(obj, &curr->typeInferenceMemory,
-                                      data->mallocSizeOf);
+        obj->sizeOfExcludingThis(&curr->typeInferenceSizes, data->mallocSizeOf);
         break;
     }
     case JSTRACE_XML:
     {
         curr->gcHeapXML += thingSize;
         break;
     }
     }
@@ -287,20 +283,20 @@ CollectCompartmentStatsForRuntime(JSRunt
                               stats.scriptData;
         data->totalStrings += stats.gcHeapStrings +
                               stats.stringChars;
 #ifdef JS_METHODJIT
         data->totalMjit    += stats.mjitCode +
                               stats.mjitData;
 #endif
         data->totalTypeInference += stats.gcHeapTypeObjects +
-                                    stats.typeInferenceMemory.objects +
-                                    stats.typeInferenceMemory.scripts +
-                                    stats.typeInferenceMemory.tables;
-        data->totalAnalysisTemp  += stats.typeInferenceMemory.temporary;
+                                    stats.typeInferenceSizes.objects +
+                                    stats.typeInferenceSizes.scripts +
+                                    stats.typeInferenceSizes.tables;
+        data->totalAnalysisTemp  += stats.typeInferenceSizes.temporary;
     }
 
     size_t numDirtyChunks = (data->gcHeapChunkTotal -
                              data->gcHeapChunkCleanUnused) /
                             gc::ChunkSize;
     int64_t perChunkAdmin =
         sizeof(gc::Chunk) - (sizeof(gc::Arena) * gc::ArenasPerChunk);
     data->gcHeapChunkAdmin = numDirtyChunks * perChunkAdmin;
--- a/js/src/jscompartment.cpp
+++ b/js/src/jscompartment.cpp
@@ -765,15 +765,15 @@ JSCompartment::sweepBreakpoints(JSContex
 GCMarker *
 JSCompartment::createBarrierTracer()
 {
     JS_ASSERT(!gcIncrementalTracer);
     return NULL;
 }
 
 size_t
-JS::SizeOfCompartmentShapeTable(JSCompartment *c, JSMallocSizeOfFun mallocSizeOf)
+JSCompartment::sizeOfShapeTable(JSMallocSizeOfFun mallocSizeOf)
 {
-    return c->baseShapes.sizeOfExcludingThis(mallocSizeOf)
-         + c->initialShapes.sizeOfExcludingThis(mallocSizeOf)
-         + c->newTypeObjects.sizeOfExcludingThis(mallocSizeOf)
-         + c->lazyTypeObjects.sizeOfExcludingThis(mallocSizeOf);
+    return baseShapes.sizeOfExcludingThis(mallocSizeOf)
+         + initialShapes.sizeOfExcludingThis(mallocSizeOf)
+         + newTypeObjects.sizeOfExcludingThis(mallocSizeOf)
+         + lazyTypeObjects.sizeOfExcludingThis(mallocSizeOf);
 }
--- a/js/src/jscompartment.h
+++ b/js/src/jscompartment.h
@@ -159,16 +159,20 @@ struct ScriptFilenameHasher
 };
 
 typedef HashSet<ScriptFilenameEntry *,
                 ScriptFilenameHasher,
                 SystemAllocPolicy> ScriptFilenameTable;
 
 } /* namespace js */
 
+namespace JS {
+struct TypeInferenceSizes;
+}
+
 struct JSCompartment
 {
     JSRuntime                    *rt;
     JSPrincipals                 *principals;
 
     js::gc::ArenaLists           arenas;
 
     bool                         needsBarrier_;
@@ -235,16 +239,20 @@ struct JSCompartment
         return jaegerCompartment_;
     }
 
     bool ensureJaegerCompartmentExists(JSContext *cx);
 
     size_t sizeOfMjitCode() const;
 #endif
 
+    size_t sizeOfShapeTable(JSMallocSizeOfFun mallocSizeOf);
+    void sizeOfTypeInferenceData(JSContext *cx, JS::TypeInferenceSizes *stats,
+                                 JSMallocSizeOfFun mallocSizeOf);
+
     /*
      * Shared scope property tree, and arena-pool for allocating its nodes.
      */
     js::PropertyTree             propertyTree;
 
 #ifdef DEBUG
     /* Property metering. */
     jsrefcount                   livePropTreeNodes;
--- a/js/src/jsinfer.cpp
+++ b/js/src/jsinfer.cpp
@@ -6253,151 +6253,147 @@ TypeScript::destroy()
 
     if (nesting)
         Foreground::delete_(nesting);
 
     Foreground::free_(this);
 }
 
 inline size_t
-TypeSet::dynamicSize()
+TypeSet::computedSizeOfExcludingThis()
 {
     /*
      * This memory is allocated within the temp pool (but accounted for
      * elsewhere) so we can't use a JSMallocSizeOfFun to measure it.  We must
-     * do it analytically.
+     * compute its size analytically.
      */
     uint32_t count = baseObjectCount();
     if (count >= 2)
         return HashSetCapacity(count) * sizeof(TypeObject *);
     return 0;
 }
 
 inline size_t
-TypeObject::dynamicSize()
+TypeObject::computedSizeOfExcludingThis()
 {
     /*
      * This memory is allocated within the temp pool (but accounted for
      * elsewhere) so we can't use a JSMallocSizeOfFun to measure it.  We must
-     * do it analytically.
+     * compute its size analytically.
      */
     size_t bytes = 0;
 
     uint32_t count = basePropertyCount();
     if (count >= 2)
         bytes += HashSetCapacity(count) * sizeof(TypeObject *);
 
     count = getPropertyCount();
     for (unsigned i = 0; i < count; i++) {
         Property *prop = getProperty(i);
         if (prop)
-            bytes += sizeof(Property) + prop->types.dynamicSize();
+            bytes += sizeof(Property) + prop->types.computedSizeOfExcludingThis();
     }
 
     return bytes;
 }
 
 static void
-GetScriptMemoryStats(JSScript *script, TypeInferenceMemoryStats *stats, JSMallocSizeOfFun mallocSizeOf)
+SizeOfScriptTypeInferenceData(JSScript *script, TypeInferenceSizes *sizes,
+                              JSMallocSizeOfFun mallocSizeOf)
 {
     TypeScript *typeScript = script->types;
     if (!typeScript)
         return;
 
     /* If TI is disabled, a single TypeScript is still present. */
     if (!script->compartment()->types.inferenceEnabled) {
-        stats->scripts += mallocSizeOf(typeScript);
+        sizes->scripts += mallocSizeOf(typeScript);
         return;
     }
 
-    stats->scripts += mallocSizeOf(typeScript->nesting);
+    sizes->scripts += mallocSizeOf(typeScript->nesting);
 
     unsigned count = TypeScript::NumTypeSets(script);
-    stats->scripts += mallocSizeOf(typeScript);
+    sizes->scripts += mallocSizeOf(typeScript);
 
     TypeResult *result = typeScript->dynamicList;
     while (result) {
-        stats->scripts += mallocSizeOf(result);
+        sizes->scripts += mallocSizeOf(result);
         result = result->next;
     }
 
     /*
      * This counts memory that is in the temp pool but gets attributed
      * elsewhere.  See JS::SizeOfCompartmentTypeInferenceData for more details.
      */
     TypeSet *typeArray = typeScript->typeArray();
     for (unsigned i = 0; i < count; i++) {
-        size_t bytes = typeArray[i].dynamicSize();
-        stats->scripts += bytes;
-        stats->temporary -= bytes;
+        size_t bytes = typeArray[i].computedSizeOfExcludingThis();
+        sizes->scripts += bytes;
+        sizes->temporary -= bytes;
     }
 }
 
 void
-JS::SizeOfCompartmentTypeInferenceData(JSContext *cx, JSCompartment *compartment,
-                                       TypeInferenceMemoryStats *stats,
+JSCompartment::sizeOfTypeInferenceData(JSContext *cx, TypeInferenceSizes *sizes,
                                        JSMallocSizeOfFun mallocSizeOf)
 {
     /*
      * Note: not all data in the pool is temporary, and some will survive GCs
      * by being copied to the replacement pool. This memory will be counted
      * elsewhere and deducted from the amount of temporary data.
      */
-    stats->temporary += compartment->typeLifoAlloc.sizeOfExcludingThis(mallocSizeOf);
+    sizes->temporary += typeLifoAlloc.sizeOfExcludingThis(mallocSizeOf);
 
     /* Pending arrays are cleared on GC along with the analysis pool. */
-    stats->temporary +=
-        mallocSizeOf(compartment->types.pendingArray);
+    sizes->temporary += mallocSizeOf(types.pendingArray);
 
     /* TypeCompartment::pendingRecompiles is non-NULL only while inference code is running. */
-    JS_ASSERT(!compartment->types.pendingRecompiles);
-
-    for (gc::CellIter i(cx, compartment, gc::FINALIZE_SCRIPT); !i.done(); i.next())
-        GetScriptMemoryStats(i.get<JSScript>(), stats, mallocSizeOf);
-
-    if (compartment->types.allocationSiteTable)
-        stats->tables += compartment->types.allocationSiteTable->sizeOfIncludingThis(mallocSizeOf);
-
-    if (compartment->types.arrayTypeTable)
-        stats->tables += compartment->types.arrayTypeTable->sizeOfIncludingThis(mallocSizeOf);
-
-    if (compartment->types.objectTypeTable) {
-        stats->tables += compartment->types.objectTypeTable->sizeOfIncludingThis(mallocSizeOf);
-
-        for (ObjectTypeTable::Enum e(*compartment->types.objectTypeTable);
+    JS_ASSERT(!types.pendingRecompiles);
+
+    for (gc::CellIter i(cx, this, gc::FINALIZE_SCRIPT); !i.done(); i.next())
+        SizeOfScriptTypeInferenceData(i.get<JSScript>(), sizes, mallocSizeOf);
+
+    if (types.allocationSiteTable)
+        sizes->tables += types.allocationSiteTable->sizeOfIncludingThis(mallocSizeOf);
+
+    if (types.arrayTypeTable)
+        sizes->tables += types.arrayTypeTable->sizeOfIncludingThis(mallocSizeOf);
+
+    if (types.objectTypeTable) {
+        sizes->tables += types.objectTypeTable->sizeOfIncludingThis(mallocSizeOf);
+
+        for (ObjectTypeTable::Enum e(*types.objectTypeTable);
              !e.empty();
              e.popFront())
         {
             const ObjectTableKey &key = e.front().key;
             const ObjectTableEntry &value = e.front().value;
 
             /* key.ids and values.types have the same length. */
-            stats->tables += mallocSizeOf(key.ids) + mallocSizeOf(value.types);
+            sizes->tables += mallocSizeOf(key.ids) + mallocSizeOf(value.types);
         }
     }
 }
 
 void
-JS::SizeOfTypeObjectExcludingThis(void *object_, TypeInferenceMemoryStats *stats, JSMallocSizeOfFun mallocSizeOf)
-{
-    TypeObject *object = (TypeObject *) object_;
-
-    if (object->singleton) {
+TypeObject::sizeOfExcludingThis(TypeInferenceSizes *sizes, JSMallocSizeOfFun mallocSizeOf)
+{
+    if (singleton) {
         /*
          * Properties and associated type sets for singletons are cleared on
          * every GC. The type object is normally destroyed too, but we don't
          * charge this to 'temporary' as this is not for GC heap values.
          */
-        JS_ASSERT(!object->newScript);
+        JS_ASSERT(!newScript);
         return;
     }
 
-    if (object->newScript)
-        stats->objects += mallocSizeOf(object->newScript);
+    sizes->objects += mallocSizeOf(newScript);
 
     /*
      * This counts memory that is in the temp pool but gets attributed
-     * elsewhere.  See JS_GetTypeInferenceMemoryStats for more details.
+     * elsewhere.  See JSCompartment::sizeOfTypeInferenceData for more details.
      */
-    size_t bytes = object->dynamicSize();
-    stats->objects += bytes;
-    stats->temporary -= bytes;
-}
+    size_t bytes = computedSizeOfExcludingThis();
+    sizes->objects += bytes;
+    sizes->temporary -= bytes;
+}
--- a/js/src/jsinfer.h
+++ b/js/src/jsinfer.h
@@ -46,16 +46,20 @@
 #include "jscell.h"
 #include "jsfriendapi.h"
 #include "jsprvtd.h"
 
 #include "ds/LifoAlloc.h"
 #include "gc/Barrier.h"
 #include "js/HashTable.h"
 
+namespace JS {
+struct TypeInferenceSizes;
+}
+
 namespace js {
 namespace types {
 
 /* Type set entry for either a JSObject with singleton type or a non-singleton TypeObject. */
 struct TypeObjectKey {
     static intptr_t keyBits(TypeObjectKey *obj) { return (intptr_t) obj; }
     static TypeObjectKey *getKey(TypeObjectKey *obj) { return obj; }
 };
@@ -361,17 +365,17 @@ class TypeSet
 
     TypeSet()
         : flags(0), objectSet(NULL), constraintList(NULL)
     {}
 
     void print(JSContext *cx);
 
     inline void sweep(JSContext *cx, JSCompartment *compartment);
-    inline size_t dynamicSize();
+    inline size_t computedSizeOfExcludingThis();
 
     /* Whether this set contains a specific type. */
     inline bool hasType(Type type);
 
     TypeFlags baseFlags() const { return flags & TYPE_FLAG_BASE_MASK; }
     bool unknown() const { return !!(flags & TYPE_FLAG_UNKNOWN); }
     bool unknownObject() const { return !!(flags & (TYPE_FLAG_UNKNOWN | TYPE_FLAG_ANYOBJECT)); }
 
@@ -860,17 +864,19 @@ struct TypeObject : gc::Cell
     void clearNewScript(JSContext *cx);
     void getFromPrototypes(JSContext *cx, jsid id, TypeSet *types, bool force = false);
 
     void print(JSContext *cx);
 
     inline void clearProperties();
     inline void sweep(JSContext *cx);
 
-    inline size_t dynamicSize();
+    inline size_t computedSizeOfExcludingThis();
+
+    void sizeOfExcludingThis(TypeInferenceSizes *sizes, JSMallocSizeOfFun mallocSizeOf);
 
     /*
      * Type objects don't have explicit finalizers. Memory owned by a type
      * object pending deletion is released when weak references are sweeped
      * from all the compartment's type objects.
      */
     void finalize(JSContext *cx, bool background) {}
 
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -1593,40 +1593,40 @@ ReportCompartmentStats(const JS::Compart
                        "Memory used by the method JIT for the compartment's compilation data: "
                        "JITScripts, native maps, and inline cache structs.",
                        callback, closure);
 #endif
 
     ReportMemoryBytes0(MakeMemoryReporterPath(pathPrefix, stats,
                                               "type-inference/script-main"),
                        nsIMemoryReporter::KIND_HEAP,
-                       stats.typeInferenceMemory.scripts,
+                       stats.typeInferenceSizes.scripts,
                        "Memory used during type inference to store type sets of variables "
                        "and dynamically observed types.",
                        callback, closure);
 
     ReportMemoryBytes0(MakeMemoryReporterPath(pathPrefix, stats,
                                               "type-inference/object-main"),
                        nsIMemoryReporter::KIND_HEAP,
-                       stats.typeInferenceMemory.objects,
+                       stats.typeInferenceSizes.objects,
                        "Memory used during type inference to store types and possible "
                        "property types of JS objects.",
                        callback, closure);
 
     ReportMemoryBytes0(MakeMemoryReporterPath(pathPrefix, stats,
                                               "type-inference/tables"),
                        nsIMemoryReporter::KIND_HEAP,
-                       stats.typeInferenceMemory.tables,
+                       stats.typeInferenceSizes.tables,
                        "Memory used during type inference for compartment-wide tables.",
                        callback, closure);
 
     ReportMemoryBytes0(MakeMemoryReporterPath(pathPrefix, stats,
                                               "analysis-temporary"),
                        nsIMemoryReporter::KIND_HEAP,
-                       stats.typeInferenceMemory.temporary,
+                       stats.typeInferenceSizes.temporary,
                        "Memory used during type inference and compilation to hold transient "
                        "analysis information.  Cleared on GC.",
                        callback, closure);
 
     return gcTotal;
 }
 
 void