Bug 995657 - Check new capacity is large enough when growing the mark stack r=terrence
authorJon Coppeard <jcoppeard@mozilla.com>
Wed, 16 Apr 2014 09:48:24 +0100
changeset 198368 a668d68c3592a14581b69bea1433b1680da38c7f
parent 198367 ce496597e5eb7a546ec60a0d43611c100ad3f25f
child 198369 5bb0b8d757f4f7cb2571ece0c342c2ba7070da11
push id486
push userasasaki@mozilla.com
push dateMon, 14 Jul 2014 18:39:42 +0000
treeherdermozilla-release@d33428174ff1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs995657
milestone31.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 995657 - Check new capacity is large enough when growing the mark stack r=terrence
js/src/jsgc.h
--- a/js/src/jsgc.h
+++ b/js/src/jsgc.h
@@ -1003,28 +1003,28 @@ struct MarkStack {
         if (baseCapacity_ > maxCapacity_)
             baseCapacity_ = maxCapacity_;
 
         reset();
     }
 
     bool push(T item) {
         if (tos_ == end_) {
-            if (!enlarge())
+            if (!enlarge(1))
                 return false;
         }
         JS_ASSERT(tos_ < end_);
         *tos_++ = item;
         return true;
     }
 
     bool push(T item1, T item2, T item3) {
         T *nextTos = tos_ + 3;
         if (nextTos > end_) {
-            if (!enlarge())
+            if (!enlarge(3))
                 return false;
             nextTos = tos_ + 3;
         }
         JS_ASSERT(nextTos <= end_);
         tos_[0] = item1;
         tos_[1] = item2;
         tos_[2] = item3;
         tos_ = nextTos;
@@ -1052,24 +1052,22 @@ struct MarkStack {
             // If the realloc fails, just keep using the existing stack; it's
             // not ideal but better than failing.
             newStack = stack_;
             baseCapacity_ = capacity();
         }
         setStack(newStack, 0, baseCapacity_);
     }
 
-    bool enlarge() {
-        if (capacity() == maxCapacity_)
+    /* Grow the stack, ensuring there is space for at least count elements. */
+    bool enlarge(unsigned count) {
+        size_t newCapacity = Min(maxCapacity_, capacity() * 2);
+        if (newCapacity < capacity() + count)
             return false;
 
-        size_t newCapacity = capacity() * 2;
-        if (newCapacity > maxCapacity_)
-            newCapacity = maxCapacity_;
-
         size_t tosIndex = position();
 
         T *newStack = (T *)js_realloc(stack_, sizeof(T) * newCapacity);
         if (!newStack)
             return false;
 
         setStack(newStack, tosIndex, newCapacity);
         return true;