- Revision
- 261930
- Author
- [email protected]
- Date
- 2020-05-20 10:48:22 -0700 (Wed, 20 May 2020)
Log Message
[Wasm] Limit the size of Wasm function we optimize in OMG mode
https://bugs.webkit.org/show_bug.cgi?id=212105
Reviewed by Filip Pizlo.
Given that memory grows O(N^2) compiling Wasm code through the OMG path,
we can run out of memory when compiling large Wasm functions. This change adds
a limit option, webAssemblyBBQFallbackSize, When the Wasm function size is
equal to or greater than this limit we always compile using BBQ optimization
parameters.
As part of this change, we still go through the OMG loop entry OSR code
generation path for functions that are at or above the threshold, but we
compile such functions with BBQ compilation optimization levels.
Also for Wasm functions at or above the threashold, we don't tier up to an
OMG compiled normal entry function. Instead we stay with the BBQ compiled version.
* runtime/OptionsList.h:
* wasm/WasmAirIRGenerator.cpp:
(JSC::Wasm::AirIRGenerator::AirIRGenerator):
* wasm/WasmB3IRGenerator.cpp:
(JSC::Wasm::B3IRGenerator::B3IRGenerator):
(JSC::Wasm::parseAndCompile):
* wasm/WasmCompilationMode.cpp:
(JSC::Wasm::wasmFunctionSizeCanBeOMGCompiled):
* wasm/WasmCompilationMode.h:
* wasm/WasmOperations.cpp:
(JSC::Wasm::operationWasmTriggerOSREntryNow):
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (261929 => 261930)
--- trunk/Source/_javascript_Core/ChangeLog 2020-05-20 17:44:50 UTC (rev 261929)
+++ trunk/Source/_javascript_Core/ChangeLog 2020-05-20 17:48:22 UTC (rev 261930)
@@ -1,3 +1,34 @@
+2020-05-20 Michael Saboff <[email protected]>
+
+ [Wasm] Limit the size of Wasm function we optimize in OMG mode
+ https://bugs.webkit.org/show_bug.cgi?id=212105
+
+ Reviewed by Filip Pizlo.
+
+ Given that memory grows O(N^2) compiling Wasm code through the OMG path,
+ we can run out of memory when compiling large Wasm functions. This change adds
+ a limit option, webAssemblyBBQFallbackSize, When the Wasm function size is
+ equal to or greater than this limit we always compile using BBQ optimization
+ parameters.
+
+ As part of this change, we still go through the OMG loop entry OSR code
+ generation path for functions that are at or above the threshold, but we
+ compile such functions with BBQ compilation optimization levels.
+ Also for Wasm functions at or above the threashold, we don't tier up to an
+ OMG compiled normal entry function. Instead we stay with the BBQ compiled version.
+
+ * runtime/OptionsList.h:
+ * wasm/WasmAirIRGenerator.cpp:
+ (JSC::Wasm::AirIRGenerator::AirIRGenerator):
+ * wasm/WasmB3IRGenerator.cpp:
+ (JSC::Wasm::B3IRGenerator::B3IRGenerator):
+ (JSC::Wasm::parseAndCompile):
+ * wasm/WasmCompilationMode.cpp:
+ (JSC::Wasm::wasmFunctionSizeCanBeOMGCompiled):
+ * wasm/WasmCompilationMode.h:
+ * wasm/WasmOperations.cpp:
+ (JSC::Wasm::operationWasmTriggerOSREntryNow):
+
2020-05-19 Ross Kirsling <[email protected]>
REGRESSION(r261755): Win/Linux non-unified builds have hundreds of link failures
Modified: trunk/Source/_javascript_Core/runtime/OptionsList.h (261929 => 261930)
--- trunk/Source/_javascript_Core/runtime/OptionsList.h 2020-05-20 17:44:50 UTC (rev 261929)
+++ trunk/Source/_javascript_Core/runtime/OptionsList.h 2020-05-20 17:48:22 UTC (rev 261930)
@@ -453,6 +453,7 @@
v(Unsigned, webAssemblyBBQAirOptimizationLevel, 0, Normal, "Air Optimization level for BBQ Web Assembly module compilations.") \
v(Unsigned, webAssemblyBBQB3OptimizationLevel, 1, Normal, "B3 Optimization level for BBQ Web Assembly module compilations.") \
v(Unsigned, webAssemblyOMGOptimizationLevel, Options::defaultB3OptLevel(), Normal, "B3 Optimization level for OMG Web Assembly module compilations.") \
+ v(Unsigned, webAssemblyBBQFallbackSize, 50000, Normal, "Limit of Wasm function size above which we fallback to BBQ compilation mode.") \
\
v(Bool, useBBQTierUpChecks, true, Normal, "Enables tier up checks for our BBQ code.") \
v(Bool, useWebAssemblyOSR, true, Normal, nullptr) \
Modified: trunk/Source/_javascript_Core/wasm/WasmAirIRGenerator.cpp (261929 => 261930)
--- trunk/Source/_javascript_Core/wasm/WasmAirIRGenerator.cpp 2020-05-20 17:44:50 UTC (rev 261929)
+++ trunk/Source/_javascript_Core/wasm/WasmAirIRGenerator.cpp 2020-05-20 17:48:22 UTC (rev 261930)
@@ -893,7 +893,8 @@
}
}
- emitEntryTierUpCheck();
+ if (wasmFunctionSizeCanBeOMGCompiled(m_info.functions[m_functionIndex].data.size()))
+ emitEntryTierUpCheck();
}
B3::Type AirIRGenerator::toB3ResultType(BlockSignature returnType)
Modified: trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp (261929 => 261930)
--- trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp 2020-05-20 17:44:50 UTC (rev 261929)
+++ trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp 2020-05-20 17:48:22 UTC (rev 261930)
@@ -537,7 +537,8 @@
});
}
- emitEntryTierUpCheck();
+ if (wasmFunctionSizeCanBeOMGCompiled(m_info.functions[m_functionIndex].data.size()))
+ emitEntryTierUpCheck();
if (m_compilationMode == CompilationMode::OMGForOSREntryMode)
m_currentBlock = m_proc.addBlock();
@@ -1973,7 +1974,7 @@
// optLevel=1.
procedure.setNeedsUsedRegisters(false);
- procedure.setOptLevel(compilationMode == CompilationMode::BBQMode
+ procedure.setOptLevel(compilationMode == CompilationMode::BBQMode || !wasmFunctionSizeCanBeOMGCompiled(function.data.size())
? Options::webAssemblyBBQB3OptimizationLevel()
: Options::webAssemblyOMGOptimizationLevel());
Modified: trunk/Source/_javascript_Core/wasm/WasmCompilationMode.cpp (261929 => 261930)
--- trunk/Source/_javascript_Core/wasm/WasmCompilationMode.cpp 2020-05-20 17:44:50 UTC (rev 261929)
+++ trunk/Source/_javascript_Core/wasm/WasmCompilationMode.cpp 2020-05-20 17:48:22 UTC (rev 261930)
@@ -26,6 +26,7 @@
#include "config.h"
#include "WasmCompilationMode.h"
+#include "Options.h"
#include <wtf/Assertions.h>
namespace JSC { namespace Wasm {
@@ -48,4 +49,9 @@
return "";
}
+bool wasmFunctionSizeCanBeOMGCompiled(size_t size)
+{
+ return size < Options::webAssemblyBBQFallbackSize();
+}
+
} } // namespace JSC::Wasm
Modified: trunk/Source/_javascript_Core/wasm/WasmCompilationMode.h (261929 => 261930)
--- trunk/Source/_javascript_Core/wasm/WasmCompilationMode.h 2020-05-20 17:44:50 UTC (rev 261929)
+++ trunk/Source/_javascript_Core/wasm/WasmCompilationMode.h 2020-05-20 17:48:22 UTC (rev 261930)
@@ -36,5 +36,6 @@
};
const char* makeString(CompilationMode);
+bool wasmFunctionSizeCanBeOMGCompiled(size_t);
} } // namespace JSC::Wasm
Modified: trunk/Source/_javascript_Core/wasm/WasmOperations.cpp (261929 => 261930)
--- trunk/Source/_javascript_Core/wasm/WasmOperations.cpp 2020-05-20 17:44:50 UTC (rev 261929)
+++ trunk/Source/_javascript_Core/wasm/WasmOperations.cpp 2020-05-20 17:48:22 UTC (rev 261930)
@@ -270,6 +270,11 @@
dataLogLnIf(Options::verboseOSR(), "Consider OMGForOSREntryPlan for [", functionIndex, "] loopIndex#", loopIndex, " with executeCounter = ", tierUp, " ", RawPointer(callee.replacement()));
if (!Options::useWebAssemblyOSR()) {
+ if (!wasmFunctionSizeCanBeOMGCompiled(instance->module().moduleInformation().functions[functionIndex].data.size())) {
+ tierUp.deferIndefinitely();
+ return returnWithoutOSREntry();
+ }
+
if (shouldTriggerOMGCompile(tierUp, callee.replacement(), functionIndex))
triggerOMGReplacementCompile(tierUp, callee.replacement(), instance, codeBlock, functionIndex);
@@ -336,6 +341,9 @@
return returnWithoutOSREntry();
if (!triggeredSlowPathToStartCompilation) {
+ if (!wasmFunctionSizeCanBeOMGCompiled(instance->module().moduleInformation().functions[functionIndex].data.size()))
+ return returnWithoutOSREntry();
+
triggerOMGReplacementCompile(tierUp, callee.replacement(), instance, codeBlock, functionIndex);
if (!callee.replacement())