Bug 1507721 - Simplify AutoEnterOOMUnsafeRegion by adding an explicit inUnsafeRegion_ flag to the OOM simulator. r=jonco
☠☠ backed out by dad98317fee0 ☠ ☠
authorJan de Mooij <jdemooij@mozilla.com>
Fri, 16 Nov 2018 17:12:44 +0000
changeset 503231 1d50d21da50d91de52719decd7bf3e942a9ac89f
parent 503230 e97253b0e95c20792e31a72a435be3f1c50195f4
child 503232 3ab98d066db05f049c52d634bc5d6c3b66763810
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
--- 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 {