Changeset 248824 in webkit


Ignore:
Timestamp:
Aug 17, 2019 6:47:58 PM (5 years ago)
Author:
ysuzuki@apple.com
Message:

[JSC] WebAssembly BBQ should switch compile mode for size of modules
https://bugs.webkit.org/show_bug.cgi?id=200807

Reviewed by Mark Lam.

Some webpages use very large Wasm module, and it exhausts all executable memory in ARM64 devices since the size of executable memory region is 128MB.
The long term solution should be introducing Wasm interpreter. But as a short term solution, we introduce heuristics switching back to BBQ B3 at
the sacrifice of start-up time, since BBQ Air bloats such lengthy code, and thereby consumes a large amount of executable memory.

Currently, I picked 10MB since the reported website is using 11MB wasm module.

  • runtime/Options.h:
  • wasm/WasmAirIRGenerator.cpp:

(JSC::Wasm::parseAndCompileAir):

  • wasm/WasmB3IRGenerator.cpp:

(JSC::Wasm::parseAndCompile):

  • wasm/WasmBBQPlan.cpp:

(JSC::Wasm::BBQPlan::compileFunctions):

  • wasm/WasmModuleInformation.h:
  • wasm/WasmSectionParser.cpp:

(JSC::Wasm::SectionParser::parseCode):

  • wasm/WasmStreamingParser.cpp:

(JSC::Wasm::StreamingParser::parseCodeSectionSize):

Location:
trunk/Source/JavaScriptCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r248802 r248824  
     12019-08-17  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] WebAssembly BBQ should switch compile mode for size of modules
     4        https://bugs.webkit.org/show_bug.cgi?id=200807
     5
     6        Reviewed by Mark Lam.
     7
     8        Some webpages use very large Wasm module, and it exhausts all executable memory in ARM64 devices since the size of executable memory region is 128MB.
     9        The long term solution should be introducing Wasm interpreter. But as a short term solution, we introduce heuristics switching back to BBQ B3 at
     10        the sacrifice of start-up time, since BBQ Air bloats such lengthy code, and thereby consumes a large amount of executable memory.
     11
     12        Currently, I picked 10MB since the reported website is using 11MB wasm module.
     13
     14        * runtime/Options.h:
     15        * wasm/WasmAirIRGenerator.cpp:
     16        (JSC::Wasm::parseAndCompileAir):
     17        * wasm/WasmB3IRGenerator.cpp:
     18        (JSC::Wasm::parseAndCompile):
     19        * wasm/WasmBBQPlan.cpp:
     20        (JSC::Wasm::BBQPlan::compileFunctions):
     21        * wasm/WasmModuleInformation.h:
     22        * wasm/WasmSectionParser.cpp:
     23        (JSC::Wasm::SectionParser::parseCode):
     24        * wasm/WasmStreamingParser.cpp:
     25        (JSC::Wasm::StreamingParser::parseCodeSectionSize):
     26
    1272019-08-16  Mark Lam  <mark.lam@apple.com>
    228
  • trunk/Source/JavaScriptCore/runtime/Options.h

    r248661 r248824  
    477477    v(bool, failToCompileWebAssemblyCode, false, Normal, "If true, no Wasm::Plan will sucessfully compile a function.") \
    478478    v(size, webAssemblyPartialCompileLimit, 5000, Normal, "Limit on the number of bytes a Wasm::Plan::compile should attempt before checking for other work.") \
    479     v(unsigned, webAssemblyBBQOptimizationLevel, 0, Normal, "B3 Optimization level for BBQ Web Assembly module compilations.") \
     479    v(unsigned, webAssemblyBBQAirOptimizationLevel, 0, Normal, "Air Optimization level for BBQ Web Assembly module compilations.") \
     480    v(unsigned, webAssemblyBBQB3OptimizationLevel, 1, Normal, "B3 Optimization level for BBQ Web Assembly module compilations.") \
    480481    v(unsigned, webAssemblyOMGOptimizationLevel, Options::defaultB3OptLevel(), Normal, "B3 Optimization level for OMG Web Assembly module compilations.") \
    481482    \
     
    492493    v(bool, useFastTLSForWasmContext, true, Normal, "If true, we will store context in fast TLS. If false, we will pin it to a register.") \
    493494    v(bool, wasmBBQUsesAir, true, Normal, nullptr) \
     495    v(size, webAssemblyBBQAirModeThreshold, isIOS() ? (10 * MB) : 0, Normal, "If 0, we always use BBQ Air. If Wasm module code size hits this threshold, we compile Wasm module with B3 BBQ mode.") \
    494496    v(bool, useWebAssemblyStreamingApi, enableWebAssemblyStreamingApi, Normal, "Allow to run WebAssembly's Streaming API") \
    495497    v(bool, useCallICsForWebAssemblyToJSCalls, true, Normal, "If true, we will use CallLinkInfo to inline cache Wasm to JS calls.") \
  • trunk/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp

    r248178 r248824  
    21592159    procedure.setNeedsUsedRegisters(false);
    21602160   
    2161     procedure.setOptLevel(Options::webAssemblyBBQOptimizationLevel());
     2161    procedure.setOptLevel(Options::webAssemblyBBQAirOptimizationLevel());
    21622162
    21632163    AirIRGenerator irGenerator(info, procedure, result.get(), unlinkedWasmToWasmCalls, mode, functionIndex, tierUp, throwWasmException, signature);
  • trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp

    r248178 r248824  
    15711571   
    15721572    procedure.setOptLevel(compilationMode == CompilationMode::BBQMode
    1573         ? Options::webAssemblyBBQOptimizationLevel()
     1573        ? Options::webAssemblyBBQB3OptimizationLevel()
    15741574        : Options::webAssemblyOMGOptimizationLevel());
    15751575
  • trunk/Source/JavaScriptCore/wasm/WasmBBQPlan.cpp

    r248187 r248824  
    270270        TierUpCount* tierUp = Options::useBBQTierUpChecks() ? &m_tierUpCounts[functionIndex] : nullptr;
    271271        Expected<std::unique_ptr<InternalFunction>, String> parseAndCompileResult;
    272         if (Options::wasmBBQUsesAir())
     272
     273        // FIXME: Some webpages use very large Wasm module, and it exhausts all executable memory in ARM64 devices since the size of executable memory region is only limited to 128MB.
     274        // The long term solution should be to introduce a Wasm interpreter. But as a short term solution, we introduce heuristics to switch back to BBQ B3 at the sacrifice of start-up time,
     275        // as BBQ Air bloats such lengthy Wasm code and will consume a large amount of executable memory.
     276        bool forceUsingB3 = false;
     277        if (Options::webAssemblyBBQAirModeThreshold() && m_moduleInformation->codeSectionSize >= Options::webAssemblyBBQAirModeThreshold())
     278            forceUsingB3 = true;
     279
     280        if (!forceUsingB3 && Options::wasmBBQUsesAir())
    273281            parseAndCompileResult = parseAndCompileAir(m_compilationContexts[functionIndex], function.data.data(), function.data.size(), signature, m_unlinkedWasmToWasmCalls[functionIndex], m_moduleInformation.get(), m_mode, functionIndex, tierUp, m_throwWasmException);
    274282        else
  • trunk/Source/JavaScriptCore/wasm/WasmModuleInformation.h

    r246571 r248824  
    8787    Vector<Global> globals;
    8888    unsigned firstInternalGlobal { 0 };
     89    uint32_t codeSectionSize { 0 };
    8990    Vector<CustomSection> customSections;
    9091    Ref<NameSection> nameSection;
  • trunk/Source/JavaScriptCore/wasm/WasmSectionParser.cpp

    r246645 r248824  
    415415auto SectionParser::parseCode() -> PartialResult
    416416{
     417    m_info->codeSectionSize = length();
    417418    uint32_t count;
    418419    WASM_PARSER_FAIL_IF(!parseVarUInt32(count), "can't get Code section's count");
  • trunk/Source/JavaScriptCore/wasm/WasmStreamingParser.cpp

    r243163 r248824  
    111111auto StreamingParser::parseCodeSectionSize(uint32_t functionCount) -> State
    112112{
     113    m_info->codeSectionSize = m_sectionLength;
    113114    m_functionCount = functionCount;
    114115    m_functionIndex = 0;
Note: See TracChangeset for help on using the changeset viewer.