Bug 1084280 - Use a local RegExpStack when running the RegExp interpreter. r=jandem, a=dveditz
authorBrian Hackett <bhackett1024@gmail.com>
Fri, 31 Oct 2014 08:04:26 -0700
changeset 225895 631a73cdbc91
parent 225894 3c329a6fd0cb
child 225896 5238acab8176
push id4059
push userryanvm@gmail.com
push date2014-10-31 21:13 +0000
treeherdermozilla-beta@631a73cdbc91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem, dveditz
bugs1084280
milestone34.0
Bug 1084280 - Use a local RegExpStack when running the RegExp interpreter. r=jandem, a=dveditz
js/src/irregexp/RegExpInterpreter.cpp
--- a/js/src/irregexp/RegExpInterpreter.cpp
+++ b/js/src/irregexp/RegExpInterpreter.cpp
@@ -39,24 +39,33 @@ using namespace js::irregexp;
 
 static const size_t kBitsPerByte = 8;
 static const size_t kBitsPerByteLog2 = 3;
 
 class MOZ_STACK_CLASS RegExpStackCursor
 {
   public:
     explicit RegExpStackCursor(JSContext *cx)
-      : cx(cx), cursor(base())
+      : cx(cx), cursor(nullptr)
     {}
 
+    bool init() {
+        if (!stack.init()) {
+            js_ReportOutOfMemory(cx);
+            return false;
+        }
+        cursor = base();
+        return true;
+    }
+
     bool push(int32_t value) {
         *cursor++ = value;
-        if (cursor >= stack().limit()) {
+        if (cursor >= stack.limit()) {
             int32_t pos = position();
-            if (!stack().grow()) {
+            if (!stack.grow()) {
                 js_ReportOverRecursed(cx);
                 return false;
             }
             setPosition(pos);
         }
         return true;
     }
 
@@ -66,31 +75,32 @@ class MOZ_STACK_CLASS RegExpStackCursor
     }
 
     int32_t peek() {
         JS_ASSERT(cursor > base());
         return *(cursor - 1);
     }
 
     int32_t position() {
+        JS_ASSERT(cursor >= base());
         return cursor - base();
     }
 
     void setPosition(int32_t position) {
         cursor = base() + position;
-        JS_ASSERT(cursor < stack().limit());
+        JS_ASSERT(cursor < stack.limit());
     }
 
   private:
     JSContext *cx;
+    RegExpStack stack;
 
     int32_t *cursor;
 
-    RegExpStack &stack() { return cx->runtime()->mainThread.regexpStack; }
-    int32_t *base() { return (int32_t *) stack().base(); }
+    int32_t *base() { return (int32_t *) stack.base(); }
 };
 
 static int32_t
 Load32Aligned(const uint8_t* pc)
 {
     JS_ASSERT((reinterpret_cast<uintptr_t>(pc) & 3) == 0);
     return *reinterpret_cast<const int32_t *>(pc);
 }
@@ -110,16 +120,19 @@ irregexp::InterpretCode(JSContext *cx, c
                         size_t length, MatchPairs *matches)
 {
     const uint8_t* pc = byteCode;
 
     uint32_t current_char = current ? chars[current - 1] : '\n';
 
     RegExpStackCursor stack(cx);
 
+    if (!stack.init())
+        return RegExpRunStatus_Error;
+
     int32_t numRegisters = Load32Aligned(pc);
     pc += 4;
 
     Vector<int32_t, 0, SystemAllocPolicy> registers;
     if (!registers.growByUninitialized(numRegisters))
         return RegExpRunStatus_Error;
     for (size_t i = 0; i < matches->length() * 2; i++)
         registers[i] = -1;