Bug 1227914: TraceLogger - Limit the memory tracelogger can take, r=bbouvier
authorHannes Verschore <hv1989@gmail.com>
Mon, 30 Nov 2015 20:45:14 +0100
changeset 308882 541a97a551cb7bdd2791e937b3cb2a087b0eab6f
parent 308881 101b505e73f3042584f13fb745d64eb04dee9a97
child 308883 7683aae0caff682c97e21bbe0e6e40c0c958f7eb
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbouvier
bugs1227914
milestone45.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 1227914: TraceLogger - Limit the memory tracelogger can take, r=bbouvier
js/src/vm/TraceLoggingTypes.h
--- a/js/src/vm/TraceLoggingTypes.h
+++ b/js/src/vm/TraceLoggingTypes.h
@@ -125,16 +125,19 @@ inline bool
 TLTextIdIsTreeEvent(uint32_t id)
 {
     // Everything between TraceLogger_Error and TraceLogger_LastTreeItem are tree events and
     // atm also every custom event.
     return (id > TraceLogger_Error && id < TraceLogger_LastTreeItem) ||
            id >= TraceLogger_Last;
 }
 
+// The maximum amount of ram memory a continuous space structure can take (in bytes).
+static const uint32_t CONTINUOUSSPACE_LIMIT = 200 * 1024 * 1024;
+
 template <class T>
 class ContinuousSpace {
     T* data_;
     uint32_t size_;
     uint32_t capacity_;
 
   public:
     ContinuousSpace ()
@@ -189,20 +192,25 @@ class ContinuousSpace {
     }
 
     bool ensureSpaceBeforeAdd(uint32_t count = 1) {
         MOZ_ASSERT(data_);
         if (hasSpaceForAdd(count))
             return true;
 
         uint32_t nCapacity = capacity_ * 2;
-        if (size_ + count > nCapacity)
+        if (size_ + count > nCapacity || nCapacity * sizeof(T) > CONTINUOUSSPACE_LIMIT) {
             nCapacity = size_ + count;
+
+            // Limit the size of a continuous buffer.
+            if (nCapacity * sizeof(T) > CONTINUOUSSPACE_LIMIT)
+                return false;
+        }
+
         T* entries = (T*) js_realloc(data_, nCapacity * sizeof(T));
-
         if (!entries)
             return false;
 
         data_ = entries;
         capacity_ = nCapacity;
 
         return true;
     }