Bug 1507721 - Simplify AutoEnterOOMUnsafeRegion by adding an explicit inUnsafeRegion_ flag to the OOM simulator. r=jonco
authorJan de Mooij <jdemooij@mozilla.com>
Fri, 16 Nov 2018 11:23:11 +0100
changeset 503383 7987651658f0c2cdf836eef25ba91ee52e965ec1
parent 503373 7e9cac76980a2a4a10898c721c4a054db831ab4a
child 503384 20c99b0e8e4ecd54197b7d785f94eb60cfbc42e0
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1507721
milestone65.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 1507721 - Simplify AutoEnterOOMUnsafeRegion by adding an explicit inUnsafeRegion_ flag to the OOM simulator. r=jonco Differential Revision: https://phabricator.services.mozilla.com/D12103
js/public/Utility.h
js/src/jit-test/tests/modules/dynamic-import-oom.js
--- a/js/public/Utility.h
+++ b/js/public/Utility.h
@@ -137,32 +137,34 @@ class FailureSimulator
     enum class Kind : uint8_t { Nothing, OOM, StackOOM, Interrupt };
 
   private:
     Kind kind_ = Kind::Nothing;
     uint32_t targetThread_ = 0;
     uint64_t maxChecks_ = UINT64_MAX;
     uint64_t counter_ = 0;
     bool failAlways_ = true;
+    bool inUnsafeRegion_ = false;
 
   public:
     uint64_t maxChecks() const {
         return maxChecks_;
     }
-    void setMaxChecks(uint64_t value) {
-        maxChecks_ = value;
-    }
     uint64_t counter() const {
         return counter_;
     }
+    void setInUnsafeRegion(bool b) {
+        MOZ_ASSERT(inUnsafeRegion_ != b);
+        inUnsafeRegion_ = b;
+    }
     uint32_t targetThread() const {
         return targetThread_;
     }
     bool isThreadSimulatingAny() const {
-        return targetThread_ && targetThread_ == js::oom::GetThreadType();
+        return targetThread_ && targetThread_ == js::oom::GetThreadType() && !inUnsafeRegion_;
     }
     bool isThreadSimulating(Kind kind) const {
         return kind_ == kind && isThreadSimulatingAny();
     }
     bool isSimulatedFailure(Kind kind) const {
         if (!isThreadSimulating(kind)) {
             return false;
         }
@@ -314,45 +316,36 @@ struct MOZ_RAII JS_PUBLIC_DATA(AutoEnter
     using AnnotateOOMAllocationSizeCallback = void(*)(size_t);
     static AnnotateOOMAllocationSizeCallback annotateOOMSizeCallback;
     static void setAnnotateOOMAllocationSizeCallback(AnnotateOOMAllocationSizeCallback callback) {
         annotateOOMSizeCallback = callback;
     }
 
 #if defined(DEBUG) || defined(JS_OOM_BREAKPOINT)
     AutoEnterOOMUnsafeRegion()
-      : oomEnabled_(oom::simulator.isThreadSimulatingAny() &&
-                    oom::simulator.maxChecks() != UINT64_MAX),
-        oomAfter_(0)
+      : oomEnabled_(oom::simulator.isThreadSimulatingAny())
     {
         if (oomEnabled_) {
             MOZ_ALWAYS_TRUE(owner_.compareExchange(nullptr, this));
-            oomAfter_ = (int64_t(oom::simulator.maxChecks()) -
-                         int64_t(oom::simulator.counter()));
-            oom::simulator.setMaxChecks(UINT64_MAX);
+            oom::simulator.setInUnsafeRegion(true);
         }
     }
 
     ~AutoEnterOOMUnsafeRegion() {
         if (oomEnabled_) {
-            MOZ_ASSERT(oom::simulator.maxChecks() == UINT64_MAX);
-            int64_t maxChecks = int64_t(oom::simulator.counter()) + oomAfter_;
-            MOZ_ASSERT(maxChecks >= 0,
-                       "alloc count + oom limit exceeds range, your oom limit is probably too large");
-            oom::simulator.setMaxChecks(maxChecks);
+            oom::simulator.setInUnsafeRegion(false);
             MOZ_ALWAYS_TRUE(owner_.compareExchange(this, nullptr));
         }
     }
 
   private:
     // Used to catch concurrent use from other threads.
     static mozilla::Atomic<AutoEnterOOMUnsafeRegion*> owner_;
 
     bool oomEnabled_;
-    int64_t oomAfter_;
 #endif
 };
 
 } /* namespace js */
 
 // Malloc allocation.
 
 namespace js {
--- a/js/src/jit-test/tests/modules/dynamic-import-oom.js
+++ b/js/src/jit-test/tests/modules/dynamic-import-oom.js
@@ -1,4 +1,7 @@
-// |jit-test| skip-if: !('oomTest' in this)
+// |jit-test| skip-if: !('oomTest' in this); --ion-offthread-compile=off
+//
+// Note: without --ion-offthread-compile=off this test takes a long time and
+// may timeout on some platforms. See bug 1507721.
 
 oomTest(() => import("module1.js"));
 oomTest(() => import("cyclicImport1.js"));