Bug 734976 - Call js_ReportOutOfMemory in jsgcinlines when simulating OOM. Original patch by Brian Hackett. r=luke,bhackett,jdemooij
authorChristian Holler <choller@mozilla.com>
Sat, 14 Apr 2012 11:37:32 -0700
changeset 95005 cc905c76d8d5b37952f087f17b49cb602ec83f2d
parent 95004 46c7419d4bb8404921d1ff371d4cadbb591c33e7
child 95006 4343723f49e1859a3426d6f1bed0c295a4e9953b
push idunknown
push userunknown
push dateunknown
reviewersluke, bhackett, jdemooij
bugs734976
milestone14.0a1
Bug 734976 - Call js_ReportOutOfMemory in jsgcinlines when simulating OOM. Original patch by Brian Hackett. r=luke,bhackett,jdemooij
js/public/Utility.h
js/src/jsgcinlines.h
--- a/js/public/Utility.h
+++ b/js/public/Utility.h
@@ -153,19 +153,30 @@ PrintBacktrace()
     do \
     { \
         if (++OOM_counter > OOM_maxAllocations) { \
             JS_OOM_EMIT_BACKTRACE();\
             return NULL; \
         } \
     } while (0)
 
+#  define JS_OOM_POSSIBLY_FAIL_REPORT(cx) \
+    do \
+    { \
+        if (++OOM_counter > OOM_maxAllocations) { \
+            JS_OOM_EMIT_BACKTRACE();\
+            js_ReportOutOfMemory(cx);\
+            return NULL; \
+        } \
+    } while (0)
+
 # else
 #  define JS_OOM_POSSIBLY_FAIL() do {} while(0)
-# endif
+#  define JS_OOM_POSSIBLY_FAIL_REPORT(cx) do {} while(0)
+# endif /* DEBUG */
 
 /*
  * SpiderMonkey code should not be calling these allocation functions directly.
  * Instead, all calls should go through JSRuntime, JSContext or OffTheBooks.
  * However, js_free() can be called directly.
  */
 static JS_INLINE void* js_malloc(size_t bytes)
 {
--- a/js/src/jsgcinlines.h
+++ b/js/src/jsgcinlines.h
@@ -435,17 +435,17 @@ NewGCThing(JSContext *cx, js::gc::AllocK
 #ifdef JS_THREADSAFE
     JS_ASSERT_IF((cx->compartment == cx->runtime->atomsCompartment),
                  kind == js::gc::FINALIZE_STRING || kind == js::gc::FINALIZE_SHORT_STRING);
 #endif
     JS_ASSERT(!cx->runtime->gcRunning);
     JS_ASSERT(!cx->runtime->noGCOrAllocationCheck);
 
     /* For testing out of memory conditions */
-    JS_OOM_POSSIBLY_FAIL();
+    JS_OOM_POSSIBLY_FAIL_REPORT(cx);
 
 #ifdef JS_GC_ZEAL
     if (cx->runtime->needZealousGC())
         js::gc::RunDebugGC(cx);
 #endif
 
     js::gc::MaybeCheckStackRoots(cx);