Bug 1231224 part 13 - Add OOM checks to Statistics::initialize. r=jonco
authorJan de Mooij <jdemooij@mozilla.com>
Wed, 06 Jan 2016 21:08:58 +0100
changeset 278863 d4dec7c64ebac6e98044c2c55c675cc1c7e1c1d6
parent 278862 6d6334c0964fa13a07070c7eec22d95d09c99756
child 278864 a9b4487febc8b302a4b77412ecf7a8176adde8c1
push id29860
push usercbook@mozilla.com
push dateThu, 07 Jan 2016 10:51:20 +0000
treeherdermozilla-central@e0bcd16e1d4b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1231224
milestone46.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 1231224 part 13 - Add OOM checks to Statistics::initialize. r=jonco
js/src/gc/Statistics.cpp
js/src/gc/Statistics.h
js/src/vm/Initialization.cpp
--- a/js/src/gc/Statistics.cpp
+++ b/js/src/gc/Statistics.cpp
@@ -777,17 +777,17 @@ Statistics::Statistics(JSRuntime* rt)
 }
 
 Statistics::~Statistics()
 {
     if (fp && fp != stdout && fp != stderr)
         fclose(fp);
 }
 
-/* static */ void
+/* static */ bool
 Statistics::initialize()
 {
     for (size_t i = 0; i < PHASE_LIMIT; i++) {
         MOZ_ASSERT(phases[i].index == i);
         for (size_t j = 0; j < PHASE_LIMIT; j++)
             MOZ_ASSERT_IF(i != j, phases[i].telemetryBucket != phases[j].telemetryBucket);
     }
 
@@ -801,39 +801,43 @@ Statistics::initialize()
         Phase parent = dagChildEdges[i].parent;
         if (!phaseExtra[parent].dagSlot)
             phaseExtra[parent].dagSlot = ++dagSlot;
 
         Phase child = dagChildEdges[i].child;
         MOZ_ASSERT(phases[child].parent == PHASE_MULTI_PARENTS);
         int j = child;
         do {
-            dagDescendants[phaseExtra[parent].dagSlot].append(Phase(j));
+            if (!dagDescendants[phaseExtra[parent].dagSlot].append(Phase(j)))
+                return false;
             j++;
         } while (j != PHASE_LIMIT && phases[j].parent != PHASE_MULTI_PARENTS);
     }
     MOZ_ASSERT(dagSlot <= MaxMultiparentPhases - 1);
 
     // Fill in the depth of each node in the tree. Multi-parented nodes
     // have depth 0.
     mozilla::Vector<Phase> stack;
-    stack.append(PHASE_LIMIT); // Dummy entry to avoid special-casing the first node
+    if (!stack.append(PHASE_LIMIT)) // Dummy entry to avoid special-casing the first node
+        return false;
     for (int i = 0; i < PHASE_LIMIT; i++) {
         if (phases[i].parent == PHASE_NO_PARENT ||
             phases[i].parent == PHASE_MULTI_PARENTS)
         {
             stack.clear();
         } else {
             while (stack.back() != phases[i].parent)
                 stack.popBack();
         }
         phaseExtra[i].depth = stack.length();
-        stack.append(Phase(i));
+        if (!stack.append(Phase(i)))
+            return false;
     }
 
+    return true;
 }
 
 JS::GCSliceCallback
 Statistics::setSliceCallback(JS::GCSliceCallback newCallback)
 {
     JS::GCSliceCallback oldCallback = sliceCallback;
     sliceCallback = newCallback;
     return oldCallback;
--- a/js/src/gc/Statistics.h
+++ b/js/src/gc/Statistics.h
@@ -157,17 +157,17 @@ struct Statistics
      * DAGs, this decision should be reconsidered.
      */
     static const size_t MaxMultiparentPhases = 6;
     static const size_t NumTimingArrays = MaxMultiparentPhases + 1;
 
     /* Create a convenient type for referring to tables of phase times. */
     using PhaseTimeTable = int64_t[NumTimingArrays][PHASE_LIMIT];
 
-    static void initialize();
+    static bool initialize();
 
     explicit Statistics(JSRuntime* rt);
     ~Statistics();
 
     void beginPhase(Phase phase);
     void endPhase(Phase phase);
     void endParallelPhase(Phase phase, const GCParallelTask* task);
 
--- a/js/src/vm/Initialization.cpp
+++ b/js/src/vm/Initialization.cpp
@@ -99,17 +99,18 @@ JS_Init(void)
 #endif // EXPOSE_INTL_API
 
     if (!js::CreateHelperThreadsState())
         return false;
 
     if (!FutexRuntime::initialize())
         return false;
 
-    js::gcstats::Statistics::initialize();
+    if (!js::gcstats::Statistics::initialize())
+        return false;
 
     libraryInitState = InitState::Running;
     return true;
 }
 
 JS_PUBLIC_API(void)
 JS_ShutDown(void)
 {