Bug 1486027 - don't oom on failed ModuleGenerator memory reservations (r=bbouvier)
authorLuke Wagner <luke@mozilla.com>
Fri, 24 Aug 2018 13:41:13 -0500
changeset 491132 b48d2197a9a0b3f5add7032f685177fbb12b21d6
parent 491131 91dc894ac30321311d5c83ecf3ba40525ecfc917
child 491133 11e33b3ad015efb33f8a52e2e8902197f814bef9
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbouvier
bugs1486027
milestone63.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 1486027 - don't oom on failed ModuleGenerator memory reservations (r=bbouvier)
js/src/wasm/WasmGenerator.cpp
--- a/js/src/wasm/WasmGenerator.cpp
+++ b/js/src/wasm/WasmGenerator.cpp
@@ -16,16 +16,17 @@
  * limitations under the License.
  */
 
 #include "wasm/WasmGenerator.h"
 
 #include "mozilla/CheckedInt.h"
 #include "mozilla/EnumeratedRange.h"
 #include "mozilla/SHA1.h"
+#include "mozilla/Unused.h"
 
 #include <algorithm>
 #include <thread>
 
 #include "util/Text.h"
 #include "wasm/WasmBaselineCompile.h"
 #include "wasm/WasmCompile.h"
 #include "wasm/WasmIonCompile.h"
@@ -34,16 +35,17 @@
 #include "jit/MacroAssembler-inl.h"
 
 using namespace js;
 using namespace js::jit;
 using namespace js::wasm;
 
 using mozilla::CheckedInt;
 using mozilla::MakeEnumeratedRange;
+using mozilla::Unused;
 
 bool
 CompiledCode::swap(MacroAssembler& masm)
 {
     MOZ_ASSERT(bytes.empty());
     if (!masm.swapBuffer(bytes))
         return false;
 
@@ -195,34 +197,32 @@ ModuleGenerator::init(Metadata* maybeAsm
     // The funcToCodeRange_ maps function indices to code-range indices and all
     // elements will be initialized by the time module generation is finished.
 
     if (!funcToCodeRange_.appendN(BAD_CODE_RANGE, env_->funcTypes.length()))
         return false;
 
     // Pre-reserve space for large Vectors to avoid the significant cost of the
     // final reallocs. In particular, the MacroAssembler can be enormous, so be
-    // extra conservative. Note, podResizeToFit calls at the end will trim off
-    // unneeded capacity.
+    // extra conservative. Since large over-reservations may fail when the
+    // actual allocations will succeed, ignore OOM failures. Note,
+    // podResizeToFit calls at the end will trim off unneeded capacity.
 
     size_t codeSectionSize = env_->codeSection ? env_->codeSection->size : 0;
+
     size_t estimatedCodeSize = 1.2 * EstimateCompiledCodeSize(tier(), codeSectionSize);
-    if (!masm_.reserve(Min(estimatedCodeSize, MaxCodeBytesPerProcess)))
-        return false;
+    Unused << masm_.reserve(Min(estimatedCodeSize, MaxCodeBytesPerProcess));
 
-    if (!metadataTier_->codeRanges.reserve(2 * env_->numFuncDefs()))
-        return false;
+    Unused << metadataTier_->codeRanges.reserve(2 * env_->numFuncDefs());
 
     const size_t ByteCodesPerCallSite = 50;
-    if (!metadataTier_->callSites.reserve(codeSectionSize / ByteCodesPerCallSite))
-        return false;
+    Unused << metadataTier_->callSites.reserve(codeSectionSize / ByteCodesPerCallSite);
 
     const size_t ByteCodesPerOOBTrap = 10;
-    if (!metadataTier_->trapSites[Trap::OutOfBounds].reserve(codeSectionSize / ByteCodesPerOOBTrap))
-        return false;
+    Unused << metadataTier_->trapSites[Trap::OutOfBounds].reserve(codeSectionSize / ByteCodesPerOOBTrap);
 
     // Allocate space in TlsData for declarations that need it.
 
     MOZ_ASSERT(metadata_->globalDataLength == 0);
 
     for (size_t i = 0; i < env_->funcImportGlobalDataOffsets.length(); i++) {
         uint32_t globalDataOffset;
         if (!allocateGlobalBytes(sizeof(FuncImportTls), sizeof(void*), &globalDataOffset))