Changeset 261930 in webkit


Ignore:
Timestamp:
May 20, 2020 10:48:22 AM (4 years ago)
Author:
msaboff@apple.com
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(N2) 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):

Location:
trunk/Source/JavaScriptCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r261895 r261930  
     12020-05-20  Michael Saboff  <msaboff@apple.com>
     2
     3        [Wasm] Limit the size of Wasm function we optimize in OMG mode
     4        https://bugs.webkit.org/show_bug.cgi?id=212105
     5
     6        Reviewed by Filip Pizlo.
     7
     8        Given that memory grows O(N^2) compiling Wasm code through the OMG path,
     9        we can run out of memory when compiling large Wasm functions.  This change adds
     10        a limit option, webAssemblyBBQFallbackSize,  When the Wasm function size is
     11        equal to or greater than this limit we always compile using BBQ optimization
     12        parameters.
     13
     14        As part of this change, we still go through the OMG loop entry OSR code
     15        generation path for functions that are at or above the threshold, but we
     16        compile such functions with BBQ compilation optimization levels.
     17        Also for Wasm functions at or above  the threashold, we don't tier up to an
     18        OMG compiled normal entry function.  Instead we stay with the BBQ compiled version.
     19
     20        * runtime/OptionsList.h:
     21        * wasm/WasmAirIRGenerator.cpp:
     22        (JSC::Wasm::AirIRGenerator::AirIRGenerator):
     23        * wasm/WasmB3IRGenerator.cpp:
     24        (JSC::Wasm::B3IRGenerator::B3IRGenerator):
     25        (JSC::Wasm::parseAndCompile):
     26        * wasm/WasmCompilationMode.cpp:
     27        (JSC::Wasm::wasmFunctionSizeCanBeOMGCompiled):
     28        * wasm/WasmCompilationMode.h:
     29        * wasm/WasmOperations.cpp:
     30        (JSC::Wasm::operationWasmTriggerOSREntryNow):
     31
    1322020-05-19  Ross Kirsling  <ross.kirsling@sony.com>
    233
  • trunk/Source/JavaScriptCore/runtime/OptionsList.h

    r261728 r261930  
    454454    v(Unsigned, webAssemblyBBQB3OptimizationLevel, 1, Normal, "B3 Optimization level for BBQ Web Assembly module compilations.") \
    455455    v(Unsigned, webAssemblyOMGOptimizationLevel, Options::defaultB3OptLevel(), Normal, "B3 Optimization level for OMG Web Assembly module compilations.") \
     456    v(Unsigned, webAssemblyBBQFallbackSize, 50000, Normal, "Limit of Wasm function size above which we fallback to BBQ compilation mode.") \
    456457    \
    457458    v(Bool, useBBQTierUpChecks, true, Normal, "Enables tier up checks for our BBQ code.") \
  • trunk/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp

    r261755 r261930  
    894894    }
    895895
    896     emitEntryTierUpCheck();
     896    if (wasmFunctionSizeCanBeOMGCompiled(m_info.functions[m_functionIndex].data.size()))
     897        emitEntryTierUpCheck();
    897898}
    898899
  • trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp

    r261755 r261930  
    538538    }
    539539
    540     emitEntryTierUpCheck();
     540    if (wasmFunctionSizeCanBeOMGCompiled(m_info.functions[m_functionIndex].data.size()))
     541        emitEntryTierUpCheck();
    541542
    542543    if (m_compilationMode == CompilationMode::OMGForOSREntryMode)
     
    19741975    procedure.setNeedsUsedRegisters(false);
    19751976   
    1976     procedure.setOptLevel(compilationMode == CompilationMode::BBQMode
     1977    procedure.setOptLevel(compilationMode == CompilationMode::BBQMode || !wasmFunctionSizeCanBeOMGCompiled(function.data.size())
    19771978        ? Options::webAssemblyBBQB3OptimizationLevel()
    19781979        : Options::webAssemblyOMGOptimizationLevel());
  • trunk/Source/JavaScriptCore/wasm/WasmCompilationMode.cpp

    r251886 r261930  
    2727#include "WasmCompilationMode.h"
    2828
     29#include "Options.h"
    2930#include <wtf/Assertions.h>
    3031
     
    4950}
    5051
     52bool wasmFunctionSizeCanBeOMGCompiled(size_t size)
     53{
     54    return size < Options::webAssemblyBBQFallbackSize();
     55}
     56
    5157} } // namespace JSC::Wasm
  • trunk/Source/JavaScriptCore/wasm/WasmCompilationMode.h

    r251886 r261930  
    3737
    3838const char* makeString(CompilationMode);
     39bool wasmFunctionSizeCanBeOMGCompiled(size_t);
    3940
    4041} } // namespace JSC::Wasm
  • trunk/Source/JavaScriptCore/wasm/WasmOperations.cpp

    r261755 r261930  
    271271
    272272    if (!Options::useWebAssemblyOSR()) {
     273        if (!wasmFunctionSizeCanBeOMGCompiled(instance->module().moduleInformation().functions[functionIndex].data.size())) {
     274            tierUp.deferIndefinitely();
     275            return returnWithoutOSREntry();
     276        }
     277
    273278        if (shouldTriggerOMGCompile(tierUp, callee.replacement(), functionIndex))
    274279            triggerOMGReplacementCompile(tierUp, callee.replacement(), instance, codeBlock, functionIndex);
     
    337342
    338343    if (!triggeredSlowPathToStartCompilation) {
     344        if (!wasmFunctionSizeCanBeOMGCompiled(instance->module().moduleInformation().functions[functionIndex].data.size()))
     345            return returnWithoutOSREntry();
     346
    339347        triggerOMGReplacementCompile(tierUp, callee.replacement(), instance, codeBlock, functionIndex);
    340348
Note: See TracChangeset for help on using the changeset viewer.