Changeset 269950 in webkit


Ignore:
Timestamp:
Nov 18, 2020 2:55:25 AM (3 years ago)
Author:
commit-queue@webkit.org
Message:

Unreviewed, reverting r269940.
https://bugs.webkit.org/show_bug.cgi?id=219076

caused seemingly-infinite build time regression

Reverted changeset:

"[JSC] Implement WebAssembly.Memory with shared"
https://bugs.webkit.org/show_bug.cgi?id=218693
https://trac.webkit.org/changeset/269940

Location:
trunk
Files:
15 deleted
75 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r269940 r269950  
     12020-11-18  Commit Queue  <commit-queue@webkit.org>
     2
     3        Unreviewed, reverting r269940.
     4        https://bugs.webkit.org/show_bug.cgi?id=219076
     5
     6        caused seemingly-infinite build time regression
     7
     8        Reverted changeset:
     9
     10        "[JSC] Implement WebAssembly.Memory with shared"
     11        https://bugs.webkit.org/show_bug.cgi?id=218693
     12        https://trac.webkit.org/changeset/269940
     13
    1142020-11-16  Yusuke Suzuki  <ysuzuki@apple.com>
    215
  • trunk/JSTests/wasm/js-api/test_memory.js

    r269940 r269950  
    125125{
    126126    assert.throws(() => new WebAssembly.Memory(20), TypeError, "WebAssembly.Memory expects its first argument to be an object");
    127     new WebAssembly.Memory({initial:1}, {});
     127    assert.throws(() => new WebAssembly.Memory({}, {}), TypeError,  "WebAssembly.Memory expects exactly one argument");
    128128}
    129129
  • trunk/LayoutTests/ChangeLog

    r269946 r269950  
     12020-11-18  Commit Queue  <commit-queue@webkit.org>
     2
     3        Unreviewed, reverting r269940.
     4        https://bugs.webkit.org/show_bug.cgi?id=219076
     5
     6        caused seemingly-infinite build time regression
     7
     8        Reverted changeset:
     9
     10        "[JSC] Implement WebAssembly.Memory with shared"
     11        https://bugs.webkit.org/show_bug.cgi?id=218693
     12        https://trac.webkit.org/changeset/269940
     13
    1142020-11-18  Carlos Garcia Campos  <cgarcia@igalia.com>
    215
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r269940 r269950  
     12020-11-18  Commit Queue  <commit-queue@webkit.org>
     2
     3        Unreviewed, reverting r269940.
     4        https://bugs.webkit.org/show_bug.cgi?id=219076
     5
     6        caused seemingly-infinite build time regression
     7
     8        Reverted changeset:
     9
     10        "[JSC] Implement WebAssembly.Memory with shared"
     11        https://bugs.webkit.org/show_bug.cgi?id=218693
     12        https://trac.webkit.org/changeset/269940
     13
    1142020-11-16  Yusuke Suzuki  <ysuzuki@apple.com>
    215
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/scripting/processing-model-2/integration-with-the-javascript-agent-formalism/requires-success.any.worker-expected.txt

    r269940 r269950  
    11
    2 PASS [[CanBlock]] in a DedicatedWorkerGlobalScope
     2FAIL [[CanBlock]] in a DedicatedWorkerGlobalScope Typed array for wait/notify must wrap a SharedArrayBuffer.
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor-shared.tentative.any-expected.txt

    r269940 r269950  
    11
    2 PASS Shared memory without maximum
    3 PASS Order of evaluation for descriptor (with shared)
    4 PASS Shared memory
     2FAIL Shared memory without maximum assert_throws_js: function "() => new WebAssembly.Memory({ "initial": 10, "shared": true })" did not throw
     3FAIL Order of evaluation for descriptor (with shared) assert_array_equals: lengths differ, expected array ["initial", "initial valueOf", "maximum", "maximum valueOf", "shared"] length 5, got ["initial", "initial valueOf", "maximum", "maximum valueOf"] length 4
     4FAIL Shared memory assert_equals: undefined: constructor expected true but got false
    55
  • trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor-shared.tentative.any.worker-expected.txt

    r269940 r269950  
    11
    2 PASS Shared memory without maximum
    3 PASS Order of evaluation for descriptor (with shared)
    4 PASS Shared memory
     2FAIL Shared memory without maximum assert_throws_js: function "() => new WebAssembly.Memory({ "initial": 10, "shared": true })" did not throw
     3FAIL Order of evaluation for descriptor (with shared) assert_array_equals: lengths differ, expected array ["initial", "initial valueOf", "maximum", "maximum valueOf", "shared"] length 5, got ["initial", "initial valueOf", "maximum", "maximum valueOf"] length 4
     4FAIL Shared memory assert_equals: undefined: constructor expected true but got false
    55
  • trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any-expected.txt

    r269940 r269950  
    2323PASS Zero initial
    2424PASS Non-zero initial
    25 PASS Stray argument
     25FAIL Stray argument WebAssembly.Memory expects exactly one argument
    2626
  • trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/constructor.any.worker-expected.txt

    r269940 r269950  
    2323PASS Zero initial
    2424PASS Non-zero initial
    25 PASS Stray argument
     25FAIL Stray argument WebAssembly.Memory expects exactly one argument
    2626
  • trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any-expected.txt

    r269940 r269950  
    1818PASS Out-of-range argument: object "[object Object]"
    1919PASS Stray argument
    20 PASS Growing shared memory does not detach old buffer
     20FAIL Growing shared memory does not detach old buffer assert_equals: Buffer before growing: constructor expected true but got false
    2121
  • trunk/LayoutTests/imported/w3c/web-platform-tests/wasm/jsapi/memory/grow.any.worker-expected.txt

    r269940 r269950  
    1818PASS Out-of-range argument: object "[object Object]"
    1919PASS Stray argument
    20 PASS Growing shared memory does not detach old buffer
     20FAIL Growing shared memory does not detach old buffer assert_equals: Buffer before growing: constructor expected true but got false
    2121
  • trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-copy-channel-expected.txt

    r269940 r269950  
    2020PASS   6: buffer.copyFromChannel(x, 0, 16) did not throw an exception.
    2121PASS   7: buffer.copyFromChannel(x, 3) threw IndexSizeError: "Not a valid channelNumber.".
    22 PASS   8: buffer.copyFromChannel(SharedArrayBuffer view, 0) threw TypeError: "Argument 1 ('destination') to AudioBuffer.copyFromChannel must be an instance of Float32Array".
    23 PASS   9: buffer.copyFromChannel(SharedArrayBuffer view, 0, 0) threw TypeError: "Argument 1 ('destination') to AudioBuffer.copyFromChannel must be an instance of Float32Array".
    24 PASS < [copyFrom-exceptions] All assertions passed. (total 11 assertions)
     22FAIL X 8: buffer.copyFromChannel(SharedArrayBuffer view, 0) did not throw an exception. assert_true: expected true got false
     23FAIL X 9: buffer.copyFromChannel(SharedArrayBuffer view, 0, 0) did not throw an exception. assert_true: expected true got false
     24FAIL < [copyFrom-exceptions] 2 out of 11 assertions were failed. assert_true: expected true got false
    2525PASS > [copyTo-exceptions]
    2626PASS   AudioBuffer.prototype.copyToChannel does exist.
     
    3232PASS   5: buffer.copyToChannel(x, 0, 16) did not throw an exception.
    3333PASS   6: buffer.copyToChannel(x, 3) threw IndexSizeError: "Not a valid channelNumber.".
    34 PASS   7: buffer.copyToChannel(SharedArrayBuffer view, 0) threw TypeError: "Argument 1 ('source') to AudioBuffer.copyToChannel must be an instance of Float32Array".
    35 PASS   8: buffer.copyToChannel(SharedArrayBuffer view, 0, 0) threw TypeError: "Argument 1 ('source') to AudioBuffer.copyToChannel must be an instance of Float32Array".
    36 PASS < [copyTo-exceptions] All assertions passed. (total 10 assertions)
     34FAIL X 7: buffer.copyToChannel(SharedArrayBuffer view, 0) did not throw an exception. assert_true: expected true got false
     35FAIL X 8: buffer.copyToChannel(SharedArrayBuffer view, 0, 0) did not throw an exception. assert_true: expected true got false
     36FAIL < [copyTo-exceptions] 2 out of 10 assertions were failed. assert_true: expected true got false
    3737PASS > [copyFrom-validate]
    3838PASS   buffer.copyFromChannel(dst8, 0) is identical to the array [1,2,3,4,5,6,7,8].
     
    6161PASS   buffer.copyToChannel(src10, 2, 5) is identical to the array [-1,-1,-1,-1,-1,1,2,3,4,5,6,7,8,9,10,-1...].
    6262PASS < [copyTo-validate] All assertions passed. (total 10 assertions)
    63 PASS # AUDIT TASK RUNNER FINISHED: 5 tasks ran successfully.
     63FAIL # AUDIT TASK RUNNER FINISHED: 2 out of 5 tasks were failed. assert_true: expected true got false
    6464
  • trunk/LayoutTests/platform/win/TestExpectations

    r269940 r269950  
    46014601webkit.org/b/218346 fast/text/canvas-color-fonts [ Pass ImageOnlyFailure ]
    46024602webkit.org/b/218346 http/tests/canvas/color-fonts [ Pass ImageOnlyFailure ]
    4603 
    4604 # WebAssembly is not enabled
    4605 js/dom/webassembly-memory-shared-basic.html [ Skip ]
    4606 js/dom/webassembly-memory-normal-fail.html [ Skip ]
    4607 js/dom/webassembly-memory-shared-fail.html [ Skip ]
    4608 storage/indexeddb/shared-memory-structured-clone.html [ Skip ]
  • trunk/Source/JavaScriptCore/CMakeLists.txt

    r269940 r269950  
    10901090
    10911091    wasm/js/JSWebAssembly.h
    1092     wasm/js/JSWebAssemblyMemory.h
    10931092    wasm/js/JSWebAssemblyModule.h
    10941093
  • trunk/Source/JavaScriptCore/ChangeLog

    r269940 r269950  
     12020-11-18  Commit Queue  <commit-queue@webkit.org>
     2
     3        Unreviewed, reverting r269940.
     4        https://bugs.webkit.org/show_bug.cgi?id=219076
     5
     6        caused seemingly-infinite build time regression
     7
     8        Reverted changeset:
     9
     10        "[JSC] Implement WebAssembly.Memory with shared"
     11        https://bugs.webkit.org/show_bug.cgi?id=218693
     12        https://trac.webkit.org/changeset/269940
     13
    1142020-11-16  Yusuke Suzuki  <ysuzuki@apple.com>
    215
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r269940 r269950  
    15751575                AD2FCBE31DB58DAD00B3E736 /* JSWebAssemblyCompileError.h in Headers */ = {isa = PBXBuildFile; fileRef = AD2FCBA71DB58DA400B3E736 /* JSWebAssemblyCompileError.h */; };
    15761576                AD2FCBE51DB58DAD00B3E736 /* JSWebAssemblyInstance.h in Headers */ = {isa = PBXBuildFile; fileRef = AD2FCBA91DB58DA400B3E736 /* JSWebAssemblyInstance.h */; };
    1577                 AD2FCBE71DB58DAD00B3E736 /* JSWebAssemblyMemory.h in Headers */ = {isa = PBXBuildFile; fileRef = AD2FCBAB1DB58DA400B3E736 /* JSWebAssemblyMemory.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1577                AD2FCBE71DB58DAD00B3E736 /* JSWebAssemblyMemory.h in Headers */ = {isa = PBXBuildFile; fileRef = AD2FCBAB1DB58DA400B3E736 /* JSWebAssemblyMemory.h */; };
    15781578                AD2FCBE91DB58DAD00B3E736 /* JSWebAssemblyRuntimeError.h in Headers */ = {isa = PBXBuildFile; fileRef = AD2FCBAD1DB58DA400B3E736 /* JSWebAssemblyRuntimeError.h */; };
    15791579                AD2FCBEB1DB58DAD00B3E736 /* JSWebAssemblyTable.h in Headers */ = {isa = PBXBuildFile; fileRef = AD2FCBAF1DB58DA400B3E736 /* JSWebAssemblyTable.h */; };
  • trunk/Source/JavaScriptCore/llint/LLIntPCRanges.h

    r269940 r269950  
    3636    void llintPCRangeStart();
    3737    void llintPCRangeEnd();
    38 #if ENABLE(WEBASSEMBLY)
    39     void wasmLLIntPCRangeStart();
    40     void wasmLLIntPCRangeEnd();
    41 #endif
    4238}
    4339
     
    5147}
    5248
    53 #if ENABLE(WEBASSEMBLY)
    54 ALWAYS_INLINE bool isWasmLLIntPC(void* pc)
    55 {
    56     uintptr_t pcAsInt = bitwise_cast<uintptr_t>(pc);
    57     uintptr_t start = untagCodePtr<uintptr_t, CFunctionPtrTag>(wasmLLIntPCRangeStart);
    58     uintptr_t end = untagCodePtr<uintptr_t, CFunctionPtrTag>(wasmLLIntPCRangeEnd);
    59     RELEASE_ASSERT(start < end);
    60     return start <= pcAsInt && pcAsInt <= end;
    61 }
    62 #endif
    63 
    6449#if !ENABLE(C_LOOP)
    6550static constexpr GPRReg LLIntPC = GPRInfo::regT4;
  • trunk/Source/JavaScriptCore/llint/LowLevelInterpreter.asm

    r269940 r269950  
    24682468    include WebAssembly
    24692469end
    2470 
    2471 global _wasmLLIntPCRangeStart
    2472 _wasmLLIntPCRangeStart:
    24732470wasmScope()
    2474 global _wasmLLIntPCRangeEnd
    2475 _wasmLLIntPCRangeEnd:
    24762471
    24772472else
  • trunk/Source/JavaScriptCore/llint/WebAssembly.asm

    r269940 r269950  
    4646const wasmInstance = csr0
    4747const memoryBase = csr3
    48 const boundsCheckingSize = csr4
     48const memorySize = csr4
    4949
    5050# This must match the definition in LowLevelInterpreter.asm
     
    188188
    189189macro preserveCalleeSavesUsedByWasm()
    190     # NOTE: We intentionally don't save memoryBase and boundsCheckingSize here. See the comment
     190    # NOTE: We intentionally don't save memoryBase and memorySize here. See the comment
    191191    # in restoreCalleeSavesUsedByWasm() below for why.
    192192    subp CalleeSaveSpaceStackAligned, sp
     
    202202
    203203macro restoreCalleeSavesUsedByWasm()
    204     # NOTE: We intentionally don't restore memoryBase and boundsCheckingSize here. These are saved
     204    # NOTE: We intentionally don't restore memoryBase and memorySize here. These are saved
    205205    # and restored when entering Wasm by the JSToWasm wrapper and changes to them are meant
    206206    # to be observable within the same Wasm module.
     
    241241macro reloadMemoryRegistersFromInstance(instance, scratch1, scratch2)
    242242    loadp Wasm::Instance::m_cachedMemory[instance], memoryBase
    243     loadi Wasm::Instance::m_cachedBoundsCheckingSize[instance], boundsCheckingSize
    244     cagedPrimitive(memoryBase, boundsCheckingSize, scratch1, scratch2)
     243    loadi Wasm::Instance::m_cachedMemorySize[instance], memorySize
     244    cagedPrimitive(memoryBase, memorySize, scratch1, scratch2)
    245245end
    246246
     
    857857
    858858wasmOp(current_memory, WasmCurrentMemory, macro(ctx)
    859     loadp Wasm::Instance::m_memory[wasmInstance], t0
    860     loadp Wasm::Memory::m_handle[t0], t0
    861     loadp Wasm::MemoryHandle::m_size[t0], t0
     859    loadp Wasm::Instance::m_cachedMemorySize[wasmInstance], t0
    862860    urshiftq 16, t0
    863861    returnq(ctx, t0)
     
    877875macro emitCheckAndPreparePointer(ctx, pointer, offset, size)
    878876    leap size - 1[pointer, offset], t5
    879     bpb t5, boundsCheckingSize, .continuation
     877    bpb t5, memorySize, .continuation
    880878    throwException(OutOfBoundsMemoryAccess)
    881879.continuation:
  • trunk/Source/JavaScriptCore/runtime/JSArrayBuffer.h

    r269940 r269950  
    5656    // This is the default DOM unwrapping. It calls toUnsharedArrayBuffer().
    5757    static ArrayBuffer* toWrapped(VM&, JSValue);
    58     static ArrayBuffer* toWrappedAllowShared(VM&, JSValue);
    5958   
    6059private:
     
    8887}
    8988
    90 inline ArrayBuffer* JSArrayBuffer::toWrappedAllowShared(VM& vm, JSValue value)
    91 {
    92     return toPossiblySharedArrayBuffer(vm, value);
    93 }
    94 
    9589} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/JSArrayBufferView.h

    r269940 r269950  
    205205   
    206206    static RefPtr<ArrayBufferView> toWrapped(VM&, JSValue);
    207     static RefPtr<ArrayBufferView> toWrappedAllowShared(VM&, JSValue);
    208207
    209208private:
  • trunk/Source/JavaScriptCore/runtime/JSArrayBufferViewInlines.h

    r269940 r269950  
    130130}
    131131
    132 inline RefPtr<ArrayBufferView> JSArrayBufferView::toWrappedAllowShared(VM& vm, JSValue value)
    133 {
    134     if (JSArrayBufferView* view = jsDynamicCast<JSArrayBufferView*>(vm, value))
    135         return view->possiblySharedImpl();
    136     return nullptr;
    137 }
    138 
    139 
    140132} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayView.h

    r269940 r269950  
    288288    // This is the default DOM unwrapping. It calls toUnsharedNativeTypedView().
    289289    static RefPtr<typename Adaptor::ViewType> toWrapped(VM&, JSValue);
    290     // [AllowShared] annotation allows accepting TypedArray originated from SharedArrayBuffer.
    291     static RefPtr<typename Adaptor::ViewType> toWrappedAllowShared(VM&, JSValue);
    292290   
    293291private:
     
    395393}
    396394
    397 template<typename Adaptor>
    398 RefPtr<typename Adaptor::ViewType> JSGenericTypedArrayView<Adaptor>::toWrappedAllowShared(VM& vm, JSValue value)
    399 {
    400     return JSC::toPossiblySharedNativeTypedView<Adaptor>(vm, value);
    401 }
    402 
    403 
    404395} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/Options.cpp

    r269940 r269950  
    366366#endif
    367367
    368 #if !ENABLE(WEBASSEMBLY_SIGNALING_MEMORY)
     368#if !ENABLE(WEBASSEMBLY_FAST_MEMORY)
    369369    Options::useWebAssemblyFastMemory() = false;
    370     Options::useSharedArrayBuffer() = false;
    371370#endif
    372371
     
    660659#endif
    661660
    662 #if ASAN_ENABLED && OS(LINUX) && ENABLE(WEBASSEMBLY_SIGNALING_MEMORY)
    663             if (Options::useWebAssemblyFastMemory() || Options::useSharedArrayBuffer()) {
     661#if ASAN_ENABLED && OS(LINUX) && ENABLE(WEBASSEMBLY_FAST_MEMORY)
     662            if (Options::useWebAssemblyFastMemory()) {
    664663                const char* asanOptions = getenv("ASAN_OPTIONS");
    665664                bool okToUseWebAssemblyFastMemory = asanOptions
    666665                    && (strstr(asanOptions, "allow_user_segv_handler=1") || strstr(asanOptions, "handle_segv=0"));
    667666                if (!okToUseWebAssemblyFastMemory) {
    668                     dataLogLn("WARNING: ASAN interferes with JSC signal handlers; useWebAssemblyFastMemory and useSharedArrayBuffer will be disabled.");
     667                    dataLogLn("WARNING: ASAN interferes with JSC signal handlers; useWebAssemblyFastMemory will be disabled.");
    669668                    Options::useWebAssemblyFastMemory() = false;
    670                     Options::useSharedArrayBuffer() = false;
    671669                }
    672670            }
  • trunk/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp

    r269940 r269950  
    681681    Vector<UnlinkedWasmToWasmCall>& m_unlinkedWasmToWasmCalls; // List each call site and the function index whose address it should be patched with.
    682682    GPRReg m_memoryBaseGPR { InvalidGPRReg };
    683     GPRReg m_boundsCheckingSizeGPR { InvalidGPRReg };
     683    GPRReg m_memorySizeGPR { InvalidGPRReg };
    684684    GPRReg m_wasmContextInstanceGPR { InvalidGPRReg };
    685685    bool m_makesCalls { false };
     
    773773
    774774    if (mode != MemoryMode::Signaling) {
    775         m_boundsCheckingSizeGPR = pinnedRegs.boundsCheckingSizeRegister;
    776         m_code.pinRegister(m_boundsCheckingSizeGPR);
     775        m_memorySizeGPR = pinnedRegs.sizeRegister;
     776        m_code.pinRegister(m_memorySizeGPR);
    777777    }
    778778
     
    919919        RegisterSet clobbers;
    920920        clobbers.set(pinnedRegs->baseMemoryPointer);
    921         clobbers.set(pinnedRegs->boundsCheckingSizeRegister);
     921        clobbers.set(pinnedRegs->sizeRegister);
    922922        if (!isARM64())
    923923            clobbers.set(RegisterSet::macroScratchRegisters());
     
    934934            AllowMacroScratchRegisterUsage allowScratch(jit);
    935935            GPRReg baseMemory = pinnedRegs->baseMemoryPointer;
    936             GPRReg scratchOrBoundsCheckingSize = Gigacage::isEnabled(Gigacage::Primitive) ? params.gpScratch(0) : pinnedRegs->boundsCheckingSizeRegister;
    937 
    938             jit.loadPtr(CCallHelpers::Address(params[0].gpr(), Instance::offsetOfCachedBoundsCheckingSize()), pinnedRegs->boundsCheckingSizeRegister);
     936            GPRReg scratchOrSize = Gigacage::isEnabled(Gigacage::Primitive) ? params.gpScratch(0) : pinnedRegs->sizeRegister;
     937
     938            jit.loadPtr(CCallHelpers::Address(params[0].gpr(), Instance::offsetOfCachedMemorySize()), pinnedRegs->sizeRegister);
    939939            jit.loadPtr(CCallHelpers::Address(params[0].gpr(), Instance::offsetOfCachedMemory()), baseMemory);
    940940
    941             jit.cageConditionally(Gigacage::Primitive, baseMemory, pinnedRegs->boundsCheckingSizeRegister, scratchOrBoundsCheckingSize);
     941            jit.cageConditionally(Gigacage::Primitive, baseMemory, pinnedRegs->sizeRegister, scratchOrSize);
    942942        });
    943943
     
    11691169    auto temp2 = g64();
    11701170
    1171     RELEASE_ASSERT(Arg::isValidAddrForm(Instance::offsetOfMemory(), B3::Width64));
    1172     RELEASE_ASSERT(Arg::isValidAddrForm(Memory::offsetOfHandle(), B3::Width64));
    1173     RELEASE_ASSERT(Arg::isValidAddrForm(MemoryHandle::offsetOfSize(), B3::Width64));
    1174     append(Move, Arg::addr(instanceValue(), Instance::offsetOfMemory()), temp1);
    1175     append(Move, Arg::addr(temp1, Memory::offsetOfHandle()), temp1);
    1176     append(Move, Arg::addr(temp1, MemoryHandle::offsetOfSize()), temp1);
     1171    RELEASE_ASSERT(Arg::isValidAddrForm(Instance::offsetOfCachedMemorySize(), B3::Width64));
     1172    append(Move, Arg::addr(instanceValue(), Instance::offsetOfCachedMemorySize()), temp1);
    11771173    constexpr uint32_t shiftValue = 16;
    11781174    static_assert(PageCount::pageSize == 1ull << shiftValue, "This must hold for the code below to be correct.");
     
    13681364    switch (m_mode) {
    13691365    case MemoryMode::BoundsChecking: {
    1370         // In bound checking mode, while shared wasm memory partially relies on signal handler too, we need to perform bound checking
    1371         // to ensure that no memory access exceeds the current memory size.
    1372         ASSERT(m_boundsCheckingSizeGPR);
     1366        // We're not using signal handling at all, we must therefore check that no memory access exceeds the current memory size.
     1367        ASSERT(m_memorySizeGPR);
    13731368        ASSERT(sizeOfOperation + offset > offset);
    13741369        auto temp = g64();
     
    13771372
    13781373        emitCheck([&] {
    1379             return Inst(Branch64, nullptr, Arg::relCond(MacroAssembler::AboveOrEqual), temp, Tmp(m_boundsCheckingSizeGPR));
     1374            return Inst(Branch64, nullptr, Arg::relCond(MacroAssembler::AboveOrEqual), temp, Tmp(m_memorySizeGPR));
    13801375        }, [=] (CCallHelpers& jit, const B3::StackmapGenerationParams&) {
    13811376            this->emitThrowException(jit, ExceptionType::OutOfBoundsMemoryAccess);
     
    21602155        // We need to clobber the size register since the LLInt always bounds checks
    21612156        if (m_mode == MemoryMode::Signaling)
    2162             patchpoint->clobberLate(RegisterSet { PinnedRegisterInfo::get().boundsCheckingSizeRegister });
     2157            patchpoint->clobberLate(RegisterSet { PinnedRegisterInfo::get().sizeRegister });
    21632158        patchpoint->setGenerator([unlinkedWasmToWasmCalls, functionIndex] (CCallHelpers& jit, const B3::StackmapGenerationParams&) {
    21642159            AllowMacroScratchRegisterUsage allowScratch(jit);
     
    22842279            // FIXME: We should support more than one memory size register
    22852280            //   see: https://bugs.webkit.org/show_bug.cgi?id=162952
    2286             ASSERT(pinnedRegs.boundsCheckingSizeRegister != newContextInstance);
    2287             GPRReg scratchOrBoundsCheckingSize = Gigacage::isEnabled(Gigacage::Primitive) ? params.gpScratch(0) : pinnedRegs.boundsCheckingSizeRegister;
    2288 
    2289             jit.loadPtr(CCallHelpers::Address(newContextInstance, Instance::offsetOfCachedBoundsCheckingSize()), pinnedRegs.boundsCheckingSizeRegister); // Bound checking size.
     2281            ASSERT(pinnedRegs.sizeRegister != newContextInstance);
     2282            GPRReg scratchOrSize = Gigacage::isEnabled(Gigacage::Primitive) ? params.gpScratch(0) : pinnedRegs.sizeRegister;
     2283
     2284            jit.loadPtr(CCallHelpers::Address(newContextInstance, Instance::offsetOfCachedMemorySize()), pinnedRegs.sizeRegister); // Memory size.
    22902285            jit.loadPtr(CCallHelpers::Address(newContextInstance, Instance::offsetOfCachedMemory()), baseMemory); // Memory::void*.
    22912286
    2292             jit.cageConditionally(Gigacage::Primitive, baseMemory, pinnedRegs.boundsCheckingSizeRegister, scratchOrBoundsCheckingSize);
     2287            jit.cageConditionally(Gigacage::Primitive, baseMemory, pinnedRegs.sizeRegister, scratchOrSize);
    22932288        });
    22942289
  • trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp

    r269940 r269950  
    326326    Value* m_framePointer { nullptr };
    327327    GPRReg m_memoryBaseGPR { InvalidGPRReg };
    328     GPRReg m_boundsCheckingSizeGPR { InvalidGPRReg };
     328    GPRReg m_memorySizeGPR { InvalidGPRReg };
    329329    GPRReg m_wasmContextInstanceGPR { InvalidGPRReg };
    330330    bool m_makesCalls { false };
     
    409409
    410410    if (mode != MemoryMode::Signaling) {
    411         m_boundsCheckingSizeGPR = pinnedRegs.boundsCheckingSizeRegister;
    412         m_proc.pinRegister(m_boundsCheckingSizeGPR);
     411        m_memorySizeGPR = pinnedRegs.sizeRegister;
     412        m_proc.pinRegister(m_memorySizeGPR);
    413413    }
    414414
     
    418418            switch (m_mode) {
    419419            case MemoryMode::BoundsChecking:
    420                 ASSERT_UNUSED(pinnedGPR, m_boundsCheckingSizeGPR == pinnedGPR);
     420                ASSERT_UNUSED(pinnedGPR, m_memorySizeGPR == pinnedGPR);
    421421                break;
    422422            case MemoryMode::Signaling:
     
    546546        RegisterSet clobbers;
    547547        clobbers.set(pinnedRegs->baseMemoryPointer);
    548         clobbers.set(pinnedRegs->boundsCheckingSizeRegister);
     548        clobbers.set(pinnedRegs->sizeRegister);
    549549        if (!isARM64())
    550550            clobbers.set(RegisterSet::macroScratchRegisters());
     
    562562            AllowMacroScratchRegisterUsage allowScratch(jit);
    563563            GPRReg baseMemory = pinnedRegs->baseMemoryPointer;
    564             GPRReg scratchOrBoundsCheckingSize = Gigacage::isEnabled(Gigacage::Primitive) ? params.gpScratch(0) : pinnedRegs->boundsCheckingSizeRegister;
    565 
    566             jit.loadPtr(CCallHelpers::Address(params[0].gpr(), Instance::offsetOfCachedBoundsCheckingSize()), pinnedRegs->boundsCheckingSizeRegister);
     564            GPRReg scratchOrSize = Gigacage::isEnabled(Gigacage::Primitive) ? params.gpScratch(0) : pinnedRegs->sizeRegister;
     565
     566            jit.loadPtr(CCallHelpers::Address(params[0].gpr(), Instance::offsetOfCachedMemorySize()), pinnedRegs->sizeRegister);
    567567            jit.loadPtr(CCallHelpers::Address(params[0].gpr(), Instance::offsetOfCachedMemory()), baseMemory);
    568568
    569             jit.cageConditionally(Gigacage::Primitive, baseMemory, pinnedRegs->boundsCheckingSizeRegister, scratchOrBoundsCheckingSize);
     569            jit.cageConditionally(Gigacage::Primitive, baseMemory, pinnedRegs->sizeRegister, scratchOrSize);
    570570        });
    571571    }
     
    794794{
    795795    static_assert(sizeof(decltype(static_cast<Memory*>(nullptr)->size())) == sizeof(uint64_t), "codegen relies on this size");
    796     Value* memory = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Int64, origin(), instanceValue(), safeCast<int32_t>(Instance::offsetOfMemory()));
    797     Value* handle = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Int64, origin(), memory, safeCast<int32_t>(Memory::offsetOfHandle()));
    798     Value* size = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Int64, origin(), handle, safeCast<int32_t>(MemoryHandle::offsetOfSize()));
     796    Value* size = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Int64, origin(), instanceValue(), safeCast<int32_t>(Instance::offsetOfCachedMemorySize()));
    799797
    800798    constexpr uint32_t shiftValue = 16;
     
    957955    case MemoryMode::BoundsChecking: {
    958956        // We're not using signal handling at all, we must therefore check that no memory access exceeds the current memory size.
    959         ASSERT(m_boundsCheckingSizeGPR);
     957        ASSERT(m_memorySizeGPR);
    960958        ASSERT(sizeOfOperation + offset > offset);
    961         m_currentBlock->appendNew<WasmBoundsCheckValue>(m_proc, origin(), m_boundsCheckingSizeGPR, pointer, sizeOfOperation + offset - 1);
     959        m_currentBlock->appendNew<WasmBoundsCheckValue>(m_proc, origin(), m_memorySizeGPR, pointer, sizeOfOperation + offset - 1);
    962960        break;
    963961    }
     
    17131711                // We need to clobber the size register since the LLInt always bounds checks
    17141712                if (m_mode == MemoryMode::Signaling)
    1715                     patchpoint->clobberLate(RegisterSet { PinnedRegisterInfo::get().boundsCheckingSizeRegister });
     1713                    patchpoint->clobberLate(RegisterSet { PinnedRegisterInfo::get().sizeRegister });
    17161714                patchpoint->setGenerator([unlinkedWasmToWasmCalls, functionIndex] (CCallHelpers& jit, const B3::StackmapGenerationParams&) {
    17171715                    AllowMacroScratchRegisterUsage allowScratch(jit);
     
    18341832            jit.storePtr(baseMemory, CCallHelpers::Address(newContextInstance, Instance::offsetOfCachedStackLimit()));
    18351833            jit.storeWasmContextInstance(newContextInstance);
    1836             ASSERT(pinnedRegs.boundsCheckingSizeRegister != baseMemory);
     1834            ASSERT(pinnedRegs.sizeRegister != baseMemory);
    18371835            // FIXME: We should support more than one memory size register
    18381836            //   see: https://bugs.webkit.org/show_bug.cgi?id=162952
    1839             ASSERT(pinnedRegs.boundsCheckingSizeRegister != newContextInstance);
    1840             GPRReg scratchOrBoundsCheckingSize = Gigacage::isEnabled(Gigacage::Primitive) ? params.gpScratch(0) : pinnedRegs.boundsCheckingSizeRegister;
    1841 
    1842             jit.loadPtr(CCallHelpers::Address(newContextInstance, Instance::offsetOfCachedBoundsCheckingSize()), pinnedRegs.boundsCheckingSizeRegister); // Memory size.
     1837            ASSERT(pinnedRegs.sizeRegister != newContextInstance);
     1838            GPRReg scratchOrSize = Gigacage::isEnabled(Gigacage::Primitive) ? params.gpScratch(0) : pinnedRegs.sizeRegister;
     1839
     1840            jit.loadPtr(CCallHelpers::Address(newContextInstance, Instance::offsetOfCachedMemorySize()), pinnedRegs.sizeRegister); // Memory size.
    18431841            jit.loadPtr(CCallHelpers::Address(newContextInstance, Instance::offsetOfCachedMemory()), baseMemory); // Memory::void*.
    18441842
    1845             jit.cageConditionally(Gigacage::Primitive, baseMemory, pinnedRegs.boundsCheckingSizeRegister, scratchOrBoundsCheckingSize);
     1843            jit.cageConditionally(Gigacage::Primitive, baseMemory, pinnedRegs.sizeRegister, scratchOrSize);
    18461844        });
    18471845        doContextSwitch->appendNewControlValue(m_proc, Jump, origin(), continuation);
  • trunk/Source/JavaScriptCore/wasm/WasmBinding.cpp

    r269940 r269950  
    5050    ASSERT(baseMemory != GPRReg::InvalidGPRReg);
    5151    ASSERT(baseMemory != scratch);
    52     ASSERT(pinnedRegs.boundsCheckingSizeRegister != baseMemory);
    53     ASSERT(pinnedRegs.boundsCheckingSizeRegister != scratch);
    54     GPRReg sizeRegAsScratch = pinnedRegs.boundsCheckingSizeRegister;
     52    ASSERT(pinnedRegs.sizeRegister != baseMemory);
     53    ASSERT(pinnedRegs.sizeRegister != scratch);
     54    GPRReg sizeRegAsScratch = pinnedRegs.sizeRegister;
    5555    ASSERT(sizeRegAsScratch != GPRReg::InvalidGPRReg);
    5656
     
    6969    // Set up the callee's baseMemory register as well as the memory size registers.
    7070    {
    71         GPRReg scratchOrBoundsCheckingSize = !Gigacage::isEnabled(Gigacage::Primitive) ? pinnedRegs.boundsCheckingSizeRegister : wasmCallingConvention().prologueScratchGPRs[1];
     71        GPRReg scratchOrSize = !Gigacage::isEnabled(Gigacage::Primitive) ? pinnedRegs.sizeRegister : wasmCallingConvention().prologueScratchGPRs[1];
    7272
    73         jit.loadPtr(JIT::Address(baseMemory, Wasm::Instance::offsetOfCachedBoundsCheckingSize()), pinnedRegs.boundsCheckingSizeRegister); // Bound checking size.
     73        jit.loadPtr(JIT::Address(baseMemory, Wasm::Instance::offsetOfCachedMemorySize()), pinnedRegs.sizeRegister); // Memory size.
    7474        jit.loadPtr(JIT::Address(baseMemory, Wasm::Instance::offsetOfCachedMemory()), baseMemory); // Wasm::Memory::TaggedArrayStoragePtr<void> (void*).
    75         jit.cageConditionally(Gigacage::Primitive, baseMemory, pinnedRegs.boundsCheckingSizeRegister, scratchOrBoundsCheckingSize);
     75        jit.cageConditionally(Gigacage::Primitive, baseMemory, pinnedRegs.sizeRegister, scratchOrSize);
    7676    }
    7777
  • trunk/Source/JavaScriptCore/wasm/WasmFaultSignalHandler.cpp

    r269940 r269950  
    5353static bool fastHandlerInstalled { false };
    5454
    55 #if ENABLE(WEBASSEMBLY_SIGNALING_MEMORY)
     55#if ENABLE(WEBASSEMBLY_FAST_MEMORY)
    5656
    5757static SignalAction trapHandler(Signal, SigInfo& sigInfo, PlatformRegisters& context)
     
    6464
    6565    dataLogLnIf(WasmFaultSignalHandlerInternal::verbose, "JIT memory start: ", RawPointer(startOfFixedExecutableMemoryPool()), " end: ", RawPointer(endOfFixedExecutableMemoryPool()));
    66     dataLogLnIf(WasmFaultSignalHandlerInternal::verbose, "WasmLLInt memory start: ", RawPointer(untagCodePtr<void*, CFunctionPtrTag>(LLInt::wasmLLIntPCRangeStart)), " end: ", RawPointer(untagCodePtr<void*, CFunctionPtrTag>(LLInt::wasmLLIntPCRangeEnd)));
    67     // First we need to make sure we are in JIT code or Wasm LLInt code before we can aquire any locks. Otherwise,
     66    // First we need to make sure we are in JIT code before we can aquire any locks. Otherwise,
    6867    // we might have crashed in code that is already holding one of the locks we want to aquire.
    6968    assertIsNotTagged(faultingInstruction);
    70     if (isJITPC(faultingInstruction) || LLInt::isWasmLLIntPC(faultingInstruction)) {
    71         bool faultedInActiveGrowableMemory = false;
     69    if (isJITPC(faultingInstruction)) {
     70        bool faultedInActiveFastMemory = false;
    7271        {
    7372            void* faultingAddress = sigInfo.faultingAddress;
    7473            dataLogLnIf(WasmFaultSignalHandlerInternal::verbose, "checking faulting address: ", RawPointer(faultingAddress), " is in an active fast memory");
    75             faultedInActiveGrowableMemory = Wasm::Memory::addressIsInGrowableOrFastMemory(faultingAddress);
     74            faultedInActiveFastMemory = Wasm::Memory::addressIsInActiveFastMemory(faultingAddress);
    7675        }
    77         if (faultedInActiveGrowableMemory) {
     76        if (faultedInActiveFastMemory) {
    7877            dataLogLnIf(WasmFaultSignalHandlerInternal::verbose, "found active fast memory for faulting address");
    79 
    80             auto didFaultInWasm = [](void* faultingInstruction) {
    81                 if (LLInt::isWasmLLIntPC(faultingInstruction))
    82                     return true;
    83                 auto& calleeRegistry = CalleeRegistry::singleton();
    84                 auto locker = holdLock(calleeRegistry.getLock());
    85                 for (auto* callee : calleeRegistry.allCallees(locker)) {
    86                     auto [start, end] = callee->range();
    87                     dataLogLnIf(WasmFaultSignalHandlerInternal::verbose, "function start: ", RawPointer(start), " end: ", RawPointer(end));
    88                     if (start <= faultingInstruction && faultingInstruction < end) {
    89                         dataLogLnIf(WasmFaultSignalHandlerInternal::verbose, "found match");
    90                         return true;
    91                     }
     78            auto& calleeRegistry = CalleeRegistry::singleton();
     79            auto locker = holdLock(calleeRegistry.getLock());
     80            for (auto* callee : calleeRegistry.allCallees(locker)) {
     81                auto [start, end] = callee->range();
     82                dataLogLnIf(WasmFaultSignalHandlerInternal::verbose, "function start: ", RawPointer(start), " end: ", RawPointer(end));
     83                if (start <= faultingInstruction && faultingInstruction < end) {
     84                    dataLogLnIf(WasmFaultSignalHandlerInternal::verbose, "found match");
     85                    MachineContext::argumentPointer<1>(context) = reinterpret_cast<void*>(static_cast<uintptr_t>(Wasm::Context::useFastTLS()));
     86                    MachineContext::setInstructionPointer(context, LLInt::getCodePtr<CFunctionPtrTag>(wasm_throw_from_fault_handler_trampoline));
     87                    return SignalAction::Handled;
    9288                }
    93                 return false;
    94             };
    95 
    96             if (didFaultInWasm(faultingInstruction)) {
    97                 MachineContext::argumentPointer<1>(context) = reinterpret_cast<void*>(static_cast<uintptr_t>(Wasm::Context::useFastTLS()));
    98                 MachineContext::setInstructionPointer(context, LLInt::getCodePtr<CFunctionPtrTag>(wasm_throw_from_fault_handler_trampoline));
    99                 return SignalAction::Handled;
    10089            }
    10190        }
     
    10493}
    10594
    106 #endif // ENABLE(WEBASSEMBLY_SIGNALING_MEMORY)
     95#endif // ENABLE(WEBASSEMBLY_FAST_MEMORY)
    10796
    10897bool fastMemoryEnabled()
     
    113102void enableFastMemory()
    114103{
    115 #if ENABLE(WEBASSEMBLY_SIGNALING_MEMORY)
     104#if ENABLE(WEBASSEMBLY_FAST_MEMORY)
    116105    static std::once_flag once;
    117106    std::call_once(once, [] {
     
    119108            return;
    120109
    121         if (!Options::useWebAssemblyFastMemory() && !Options::useSharedArrayBuffer())
     110        if (!Options::useWebAssemblyFastMemory())
    122111            return;
    123112
     
    131120void prepareFastMemory()
    132121{
    133 #if ENABLE(WEBASSEMBLY_SIGNALING_MEMORY)
     122#if ENABLE(WEBASSEMBLY_FAST_MEMORY)
    134123    static std::once_flag once;
    135124    std::call_once(once, [] {
     
    137126            return;
    138127
    139         if (!Options::useWebAssemblyFastMemory() && !Options::useSharedArrayBuffer())
     128        if (!Options::useWebAssemblyFastMemory())
    140129            return;
    141130
     
    144133        });
    145134    });
    146 #endif // ENABLE(WEBASSEMBLY_SIGNALING_MEMORY)
     135#endif // ENABLE(WEBASSEMBLY_FAST_MEMORY)
    147136}
    148137   
  • trunk/Source/JavaScriptCore/wasm/WasmInstance.h

    r269940 r269950  
    7878    void setTable(unsigned, Ref<Table>&&);
    7979
    80     void* cachedMemory() const { return m_cachedMemory.getMayBeNull(cachedBoundsCheckingSize()); }
    81     size_t cachedBoundsCheckingSize() const { return m_cachedBoundsCheckingSize; }
     80    void* cachedMemory() const { return m_cachedMemory.getMayBeNull(cachedMemorySize()); }
     81    size_t cachedMemorySize() const { return m_cachedMemorySize; }
    8282
    8383    void setMemory(Ref<Memory>&& memory)
     
    9090    {
    9191        if (m_memory != nullptr) {
    92             m_cachedMemory = CagedPtr<Gigacage::Primitive, void, tagCagedPtr>(memory()->memory(), memory()->boundsCheckingSize());
    93             m_cachedBoundsCheckingSize = memory()->boundsCheckingSize();
     92            m_cachedMemory = CagedPtr<Gigacage::Primitive, void, tagCagedPtr>(memory()->memory(), memory()->size());
     93            m_cachedMemorySize = memory()->size();
    9494        }
    9595    }
     
    147147    static ptrdiff_t offsetOfGlobals() { return OBJECT_OFFSETOF(Instance, m_globals); }
    148148    static ptrdiff_t offsetOfCachedMemory() { return OBJECT_OFFSETOF(Instance, m_cachedMemory); }
    149     static ptrdiff_t offsetOfCachedBoundsCheckingSize() { return OBJECT_OFFSETOF(Instance, m_cachedBoundsCheckingSize); }
     149    static ptrdiff_t offsetOfCachedMemorySize() { return OBJECT_OFFSETOF(Instance, m_cachedMemorySize); }
    150150    static ptrdiff_t offsetOfPointerToTopEntryFrame() { return OBJECT_OFFSETOF(Instance, m_pointerToTopEntryFrame); }
    151151
     
    202202    Context* m_context { nullptr };
    203203    CagedPtr<Gigacage::Primitive, void, tagCagedPtr> m_cachedMemory;
    204     size_t m_cachedBoundsCheckingSize { 0 };
     204    size_t m_cachedMemorySize { 0 };
    205205    Ref<Module> m_module;
    206206    RefPtr<CodeBlock> m_codeBlock;
  • trunk/Source/JavaScriptCore/wasm/WasmMemory.cpp

    r269940 r269950  
    3737#include <wtf/PrintStream.h>
    3838#include <wtf/RAMSize.h>
    39 #include <wtf/StdSet.h>
    4039#include <wtf/Vector.h>
    4140
     
    135134        dataLogLnIf(Options::logWebAssemblyMemory(), "Freed virtual; state: ", *this);
    136135    }
    137 
    138     MemoryResult tryAllocateGrowableBoundsCheckingMemory(size_t mappedCapacity)
    139     {
    140         MemoryResult result = [&] {
    141             auto holder = holdLock(m_lock);
    142             void* result = Gigacage::tryAllocateZeroedVirtualPages(Gigacage::Primitive, mappedCapacity);
    143             if (!result)
    144                 return MemoryResult(nullptr, MemoryResult::SyncTryToReclaimMemory);
    145 
    146             m_growableBoundsCheckingMemories.insert(std::make_pair(bitwise_cast<uintptr_t>(result), mappedCapacity));
    147 
    148             return MemoryResult(result, MemoryResult::Success);
    149         }();
    150 
    151         dataLogLnIf(Options::logWebAssemblyMemory(), "Allocated virtual: ", result, "; state: ", *this);
    152 
    153         return result;
    154     }
    155 
    156     void freeGrowableBoundsCheckingMemory(void* basePtr, size_t mappedCapacity)
    157     {
    158         {
    159             auto holder = holdLock(m_lock);
    160             Gigacage::freeVirtualPages(Gigacage::Primitive, basePtr, mappedCapacity);
    161             m_growableBoundsCheckingMemories.erase(std::make_pair(bitwise_cast<uintptr_t>(basePtr), mappedCapacity));
    162         }
    163 
    164         dataLogLnIf(Options::logWebAssemblyMemory(), "Freed virtual; state: ", *this);
    165     }
    166 
    167     bool isInGrowableOrFastMemory(void* address)
    168     {
    169         // NOTE: This can be called from a signal handler, but only after we proved that we're in JIT code or WasmLLInt code.
     136   
     137    bool isAddressInFastMemory(void* address)
     138    {
     139        // NOTE: This can be called from a signal handler, but only after we proved that we're in JIT code.
    170140        auto holder = holdLock(m_lock);
    171141        for (void* memory : m_fastMemories) {
     
    174144                return true;
    175145        }
    176         uintptr_t addressValue = bitwise_cast<uintptr_t>(address);
    177         auto iterator = std::upper_bound(m_growableBoundsCheckingMemories.begin(), m_growableBoundsCheckingMemories.end(), std::make_pair(addressValue, 0),
    178             [](std::pair<uintptr_t, size_t> a, std::pair<uintptr_t, size_t> b) {
    179                 return (a.first + a.second) < (b.first + b.second);
    180             });
    181         if (iterator != m_growableBoundsCheckingMemories.end()) {
    182             // Since we never have overlapped range in m_growableBoundsCheckingMemories, just checking one lower-bound range is enough.
    183             if (iterator->first <= addressValue && addressValue < (iterator->first + iterator->second))
    184                 return true;
    185         }
    186146        return false;
    187147    }
     
    233193    unsigned m_maxFastMemoryCount { 0 };
    234194    Vector<void*> m_fastMemories;
    235     StdSet<std::pair<uintptr_t, size_t>> m_growableBoundsCheckingMemories;
    236195    size_t m_physicalBytes { 0 };
    237196};
     
    277236} // anonymous namespace
    278237
    279 
    280 MemoryHandle::MemoryHandle(void* memory, size_t size, size_t mappedCapacity, PageCount initial, PageCount maximum, MemorySharingMode sharingMode, MemoryMode mode)
    281     : m_memory(memory, mappedCapacity)
    282     , m_size(size)
    283     , m_mappedCapacity(mappedCapacity)
     238Memory::Memory()
     239{
     240}
     241
     242Memory::Memory(PageCount initial, PageCount maximum, Function<void(NotifyPressure)>&& notifyMemoryPressure, Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback)
     243    : m_initial(initial)
     244    , m_maximum(maximum)
     245    , m_notifyMemoryPressure(WTFMove(notifyMemoryPressure))
     246    , m_syncTryToReclaimMemory(WTFMove(syncTryToReclaimMemory))
     247    , m_growSuccessCallback(WTFMove(growSuccessCallback))
     248{
     249    ASSERT(!initial.bytes());
     250    ASSERT(m_mode == MemoryMode::BoundsChecking);
     251    dataLogLnIf(verbose, "Memory::Memory allocating ", *this);
     252    ASSERT(!memory());
     253}
     254
     255Memory::Memory(void* memory, PageCount initial, PageCount maximum, size_t mappedCapacity, MemoryMode mode, Function<void(NotifyPressure)>&& notifyMemoryPressure, Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback)
     256    : m_memory(memory, initial.bytes())
     257    , m_size(initial.bytes())
    284258    , m_initial(initial)
    285259    , m_maximum(maximum)
    286     , m_sharingMode(sharingMode)
     260    , m_mappedCapacity(mappedCapacity)
    287261    , m_mode(mode)
    288 {
    289 #if ASSERT_ENABLED
    290     if (sharingMode == MemorySharingMode::Default && mode == MemoryMode::BoundsChecking)
    291         ASSERT(mappedCapacity == size);
    292 #endif
    293 }
    294 
    295 MemoryHandle::~MemoryHandle()
     262    , m_notifyMemoryPressure(WTFMove(notifyMemoryPressure))
     263    , m_syncTryToReclaimMemory(WTFMove(syncTryToReclaimMemory))
     264    , m_growSuccessCallback(WTFMove(growSuccessCallback))
     265{
     266    dataLogLnIf(verbose, "Memory::Memory allocating ", *this);
     267}
     268
     269Ref<Memory> Memory::create()
     270{
     271    return adoptRef(*new Memory());
     272}
     273
     274RefPtr<Memory> Memory::tryCreate(PageCount initial, PageCount maximum, WTF::Function<void(NotifyPressure)>&& notifyMemoryPressure, WTF::Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback)
     275{
     276    ASSERT(initial);
     277    RELEASE_ASSERT(!maximum || maximum >= initial); // This should be guaranteed by our caller.
     278
     279    const size_t initialBytes = initial.bytes();
     280    const size_t maximumBytes = maximum ? maximum.bytes() : 0;
     281
     282    if (initialBytes > MAX_ARRAY_BUFFER_SIZE)
     283        return nullptr; // Client will throw OOMError.
     284
     285    if (maximum && !maximumBytes) {
     286        // User specified a zero maximum, initial size must also be zero.
     287        RELEASE_ASSERT(!initialBytes);
     288        return adoptRef(new Memory(initial, maximum, WTFMove(notifyMemoryPressure), WTFMove(syncTryToReclaimMemory), WTFMove(growSuccessCallback)));
     289    }
     290   
     291    bool done = tryAllocate(
     292        [&] () -> MemoryResult::Kind {
     293            return memoryManager().tryAllocatePhysicalBytes(initialBytes);
     294        }, notifyMemoryPressure, syncTryToReclaimMemory);
     295    if (!done)
     296        return nullptr;
     297       
     298    char* fastMemory = nullptr;
     299    if (Options::useWebAssemblyFastMemory()) {
     300        tryAllocate(
     301            [&] () -> MemoryResult::Kind {
     302                auto result = memoryManager().tryAllocateFastMemory();
     303                fastMemory = bitwise_cast<char*>(result.basePtr);
     304                return result.kind;
     305            }, notifyMemoryPressure, syncTryToReclaimMemory);
     306    }
     307   
     308    if (fastMemory) {
     309       
     310        if (mprotect(fastMemory + initialBytes, Memory::fastMappedBytes() - initialBytes, PROT_NONE)) {
     311            dataLog("mprotect failed: ", strerror(errno), "\n");
     312            RELEASE_ASSERT_NOT_REACHED();
     313        }
     314
     315        return adoptRef(new Memory(fastMemory, initial, maximum, Memory::fastMappedBytes(), MemoryMode::Signaling, WTFMove(notifyMemoryPressure), WTFMove(syncTryToReclaimMemory), WTFMove(growSuccessCallback)));
     316    }
     317   
     318    if (UNLIKELY(Options::crashIfWebAssemblyCantFastMemory()))
     319        webAssemblyCouldntGetFastMemory();
     320
     321    if (!initialBytes)
     322        return adoptRef(new Memory(initial, maximum, WTFMove(notifyMemoryPressure), WTFMove(syncTryToReclaimMemory), WTFMove(growSuccessCallback)));
     323   
     324    void* slowMemory = Gigacage::tryAllocateZeroedVirtualPages(Gigacage::Primitive, initialBytes);
     325    if (!slowMemory) {
     326        memoryManager().freePhysicalBytes(initialBytes);
     327        return nullptr;
     328    }
     329    return adoptRef(new Memory(slowMemory, initial, maximum, initialBytes, MemoryMode::BoundsChecking, WTFMove(notifyMemoryPressure), WTFMove(syncTryToReclaimMemory), WTFMove(growSuccessCallback)));
     330}
     331
     332Memory::~Memory()
    296333{
    297334    if (m_memory) {
     
    305342            memoryManager().freeFastMemory(memory());
    306343            break;
    307         case MemoryMode::BoundsChecking: {
    308             switch (m_sharingMode) {
    309             case MemorySharingMode::Default:
    310                 Gigacage::freeVirtualPages(Gigacage::Primitive, memory(), m_size);
    311                 break;
    312             case MemorySharingMode::Shared: {
    313                 if (mprotect(memory(), m_mappedCapacity, PROT_READ | PROT_WRITE)) {
    314                     dataLog("mprotect failed: ", strerror(errno), "\n");
    315                     RELEASE_ASSERT_NOT_REACHED();
    316                 }
    317                 memoryManager().freeGrowableBoundsCheckingMemory(memory(), m_mappedCapacity);
    318                 break;
    319             }
    320             }
     344        case MemoryMode::BoundsChecking:
     345            Gigacage::freeVirtualPages(Gigacage::Primitive, memory(), m_size);
    321346            break;
    322347        }
    323         }
    324     }
    325 }
    326 
    327 Memory::Memory()
    328     : m_handle(adoptRef(*new MemoryHandle(nullptr, 0, 0, PageCount(0), PageCount(0), MemorySharingMode::Default, MemoryMode::BoundsChecking)))
    329 {
    330 }
    331 
    332 Memory::Memory(PageCount initial, PageCount maximum, MemorySharingMode sharingMode, Function<void(NotifyPressure)>&& notifyMemoryPressure, Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback)
    333     : m_handle(adoptRef(*new MemoryHandle(nullptr, 0, 0, initial, maximum, sharingMode, MemoryMode::BoundsChecking)))
    334     , m_notifyMemoryPressure(WTFMove(notifyMemoryPressure))
    335     , m_syncTryToReclaimMemory(WTFMove(syncTryToReclaimMemory))
    336     , m_growSuccessCallback(WTFMove(growSuccessCallback))
    337 {
    338     ASSERT(!initial.bytes());
    339     ASSERT(mode() == MemoryMode::BoundsChecking);
    340     dataLogLnIf(verbose, "Memory::Memory allocating ", *this);
    341     ASSERT(!memory());
    342 }
    343 
    344 Memory::Memory(Ref<MemoryHandle>&& handle, Function<void(NotifyPressure)>&& notifyMemoryPressure, Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback)
    345     : m_handle(WTFMove(handle))
    346     , m_notifyMemoryPressure(WTFMove(notifyMemoryPressure))
    347     , m_syncTryToReclaimMemory(WTFMove(syncTryToReclaimMemory))
    348     , m_growSuccessCallback(WTFMove(growSuccessCallback))
    349 {
    350     dataLogLnIf(verbose, "Memory::Memory allocating ", *this);
    351 }
    352 
    353 Ref<Memory> Memory::create()
    354 {
    355     return adoptRef(*new Memory());
    356 }
    357 
    358 Ref<Memory> Memory::create(Ref<MemoryHandle>&& handle, WTF::Function<void(NotifyPressure)>&& notifyMemoryPressure, WTF::Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback)
    359 {
    360     return adoptRef(*new Memory(WTFMove(handle), WTFMove(notifyMemoryPressure), WTFMove(syncTryToReclaimMemory), WTFMove(growSuccessCallback)));
    361 }
    362 
    363 RefPtr<Memory> Memory::tryCreate(PageCount initial, PageCount maximum, MemorySharingMode sharingMode, WTF::Function<void(NotifyPressure)>&& notifyMemoryPressure, WTF::Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback)
    364 {
    365     ASSERT(initial);
    366     RELEASE_ASSERT(!maximum || maximum >= initial); // This should be guaranteed by our caller.
    367 
    368     const size_t initialBytes = initial.bytes();
    369     const size_t maximumBytes = maximum ? maximum.bytes() : 0;
    370 
    371     if (initialBytes > MAX_ARRAY_BUFFER_SIZE)
    372         return nullptr; // Client will throw OOMError.
    373 
    374     if (maximum && !maximumBytes) {
    375         // User specified a zero maximum, initial size must also be zero.
    376         RELEASE_ASSERT(!initialBytes);
    377         return adoptRef(new Memory(initial, maximum, sharingMode, WTFMove(notifyMemoryPressure), WTFMove(syncTryToReclaimMemory), WTFMove(growSuccessCallback)));
    378     }
    379    
    380     bool done = tryAllocate(
    381         [&] () -> MemoryResult::Kind {
    382             return memoryManager().tryAllocatePhysicalBytes(initialBytes);
    383         }, notifyMemoryPressure, syncTryToReclaimMemory);
    384     if (!done)
    385         return nullptr;
    386        
    387     char* fastMemory = nullptr;
    388     if (Options::useWebAssemblyFastMemory()) {
    389         tryAllocate(
    390             [&] () -> MemoryResult::Kind {
    391                 auto result = memoryManager().tryAllocateFastMemory();
    392                 fastMemory = bitwise_cast<char*>(result.basePtr);
    393                 return result.kind;
    394             }, notifyMemoryPressure, syncTryToReclaimMemory);
    395     }
    396    
    397     if (fastMemory) {
    398         if (mprotect(fastMemory + initialBytes, Memory::fastMappedBytes() - initialBytes, PROT_NONE)) {
    399             dataLog("mprotect failed: ", strerror(errno), "\n");
    400             RELEASE_ASSERT_NOT_REACHED();
    401         }
    402 
    403         return Memory::create(adoptRef(*new MemoryHandle(fastMemory, initialBytes, Memory::fastMappedBytes(), initial, maximum, sharingMode, MemoryMode::Signaling)), WTFMove(notifyMemoryPressure), WTFMove(syncTryToReclaimMemory), WTFMove(growSuccessCallback));
    404     }
    405    
    406     if (UNLIKELY(Options::crashIfWebAssemblyCantFastMemory()))
    407         webAssemblyCouldntGetFastMemory();
    408 
    409     if (!initialBytes)
    410         return adoptRef(new Memory(initial, maximum, sharingMode, WTFMove(notifyMemoryPressure), WTFMove(syncTryToReclaimMemory), WTFMove(growSuccessCallback)));
    411 
    412     switch (sharingMode) {
    413     case MemorySharingMode::Default: {
    414         void* slowMemory = Gigacage::tryAllocateZeroedVirtualPages(Gigacage::Primitive, initialBytes);
    415         if (!slowMemory) {
    416             memoryManager().freePhysicalBytes(initialBytes);
    417             return nullptr;
    418         }
    419         return Memory::create(adoptRef(*new MemoryHandle(slowMemory, initialBytes, initialBytes, initial, maximum, sharingMode, MemoryMode::BoundsChecking)), WTFMove(notifyMemoryPressure), WTFMove(syncTryToReclaimMemory), WTFMove(growSuccessCallback));
    420     }
    421     case MemorySharingMode::Shared: {
    422         char* slowMemory = nullptr;
    423         tryAllocate(
    424             [&] () -> MemoryResult::Kind {
    425                 auto result = memoryManager().tryAllocateGrowableBoundsCheckingMemory(maximumBytes);
    426                 slowMemory = bitwise_cast<char*>(result.basePtr);
    427                 return result.kind;
    428             }, notifyMemoryPressure, syncTryToReclaimMemory);
    429         if (!slowMemory) {
    430             memoryManager().freePhysicalBytes(initialBytes);
    431             return nullptr;
    432         }
    433 
    434         if (mprotect(slowMemory + initialBytes, maximumBytes - initialBytes, PROT_NONE)) {
    435             dataLog("mprotect failed: ", strerror(errno), "\n");
    436             RELEASE_ASSERT_NOT_REACHED();
    437         }
    438 
    439         return Memory::create(adoptRef(*new MemoryHandle(slowMemory, initialBytes, maximumBytes, initial, maximum, sharingMode, MemoryMode::BoundsChecking)), WTFMove(notifyMemoryPressure), WTFMove(syncTryToReclaimMemory), WTFMove(growSuccessCallback));
    440     }
    441     }
    442     RELEASE_ASSERT_NOT_REACHED();
    443     return nullptr;
    444 }
    445 
    446 Memory::~Memory() = default;
     348    }
     349}
    447350
    448351size_t Memory::fastMappedRedzoneBytes()
     
    457360}
    458361
    459 bool Memory::addressIsInGrowableOrFastMemory(void* address)
    460 {
    461     return memoryManager().isInGrowableOrFastMemory(address);
    462 }
    463 
    464 Expected<PageCount, Memory::GrowFailReason> Memory::growShared(PageCount delta)
    465 {
    466     Wasm::PageCount oldPageCount;
    467     Wasm::PageCount newPageCount;
    468     auto result = ([&]() -> Expected<PageCount, Memory::GrowFailReason> {
    469         auto locker = holdLock(m_handle->lock());
    470 
    471         oldPageCount = sizeInPages();
    472         newPageCount = oldPageCount + delta;
    473         if (!newPageCount || !newPageCount.isValid())
    474             return makeUnexpected(GrowFailReason::InvalidGrowSize);
    475         if (newPageCount.bytes() > MAX_ARRAY_BUFFER_SIZE)
    476             return makeUnexpected(GrowFailReason::OutOfMemory);
    477 
    478         if (!delta.pageCount())
    479             return oldPageCount;
    480 
    481         dataLogLnIf(verbose, "Memory::grow(", delta, ") to ", newPageCount, " from ", *this);
    482         RELEASE_ASSERT(newPageCount > PageCount::fromBytes(size()));
    483 
    484         if (maximum() && newPageCount > maximum())
    485             return makeUnexpected(GrowFailReason::WouldExceedMaximum);
    486 
    487         size_t desiredSize = newPageCount.bytes();
    488         RELEASE_ASSERT(desiredSize <= MAX_ARRAY_BUFFER_SIZE);
    489         RELEASE_ASSERT(desiredSize > size());
    490 
    491         // If the memory is MemorySharingMode::Shared, we already allocated enough virtual address space even if the memory is bound-checking mode. We perform mprotect to extend.
    492         size_t extraBytes = desiredSize - size();
    493         RELEASE_ASSERT(extraBytes);
    494         bool allocationSuccess = tryAllocate(
    495             [&] () -> MemoryResult::Kind {
    496                 return memoryManager().tryAllocatePhysicalBytes(extraBytes);
    497             }, [](Wasm::Memory::NotifyPressure) { }, [](Memory::SyncTryToReclaim) { });
    498         if (!allocationSuccess)
    499             return makeUnexpected(GrowFailReason::OutOfMemory);
    500 
    501         RELEASE_ASSERT(memory());
    502 
    503         // Signaling memory must have been pre-allocated virtually.
    504         uint8_t* startAddress = static_cast<uint8_t*>(memory()) + size();
    505 
    506         dataLogLnIf(verbose, "Marking WebAssembly memory's ", RawPointer(memory()), " as read+write in range [", RawPointer(startAddress), ", ", RawPointer(startAddress + extraBytes), ")");
    507         if (mprotect(startAddress, extraBytes, PROT_READ | PROT_WRITE)) {
    508             dataLog("mprotect failed: ", strerror(errno), "\n");
    509             RELEASE_ASSERT_NOT_REACHED();
    510         }
    511 
    512         m_handle->growToSize(desiredSize);
    513         return oldPageCount;
    514     }());
    515     if (result)
    516         m_growSuccessCallback(GrowSuccessTag, oldPageCount, newPageCount);
    517     return result;
     362bool Memory::addressIsInActiveFastMemory(void* address)
     363{
     364    return memoryManager().isAddressInFastMemory(address);
    518365}
    519366
    520367Expected<PageCount, Memory::GrowFailReason> Memory::grow(PageCount delta)
    521368{
     369    const Wasm::PageCount oldPageCount = sizeInPages();
     370
    522371    if (!delta.isValid())
    523372        return makeUnexpected(GrowFailReason::InvalidDelta);
    524 
    525     if (sharingMode() == MemorySharingMode::Shared)
    526         return growShared(delta);
    527 
    528     const Wasm::PageCount oldPageCount = sizeInPages();
     373   
    529374    const Wasm::PageCount newPageCount = oldPageCount + delta;
    530375    if (!newPageCount || !newPageCount.isValid())
     
    547392
    548393    dataLogLnIf(verbose, "Memory::grow(", delta, ") to ", newPageCount, " from ", *this);
    549     RELEASE_ASSERT(newPageCount > PageCount::fromBytes(size()));
     394    RELEASE_ASSERT(newPageCount > PageCount::fromBytes(m_size));
    550395
    551396    if (maximum() && newPageCount > maximum())
     
    554399    size_t desiredSize = newPageCount.bytes();
    555400    RELEASE_ASSERT(desiredSize <= MAX_ARRAY_BUFFER_SIZE);
    556     RELEASE_ASSERT(desiredSize > size());
     401    RELEASE_ASSERT(desiredSize > m_size);
     402    size_t extraBytes = desiredSize - m_size;
     403    RELEASE_ASSERT(extraBytes);
     404    bool allocationSuccess = tryAllocate(
     405        [&] () -> MemoryResult::Kind {
     406            return memoryManager().tryAllocatePhysicalBytes(extraBytes);
     407        }, m_notifyMemoryPressure, m_syncTryToReclaimMemory);
     408    if (!allocationSuccess)
     409        return makeUnexpected(GrowFailReason::OutOfMemory);
     410
    557411    switch (mode()) {
    558412    case MemoryMode::BoundsChecking: {
    559         bool allocationSuccess = tryAllocate(
    560             [&] () -> MemoryResult::Kind {
    561                 return memoryManager().tryAllocatePhysicalBytes(desiredSize);
    562             }, m_notifyMemoryPressure, m_syncTryToReclaimMemory);
    563         if (!allocationSuccess)
    564             return makeUnexpected(GrowFailReason::OutOfMemory);
    565 
    566413        RELEASE_ASSERT(maximum().bytes() != 0);
    567414
     
    570417            return makeUnexpected(GrowFailReason::OutOfMemory);
    571418
    572         memcpy(newMemory, memory(), size());
    573         auto newHandle = adoptRef(*new MemoryHandle(newMemory, desiredSize, desiredSize, initial(), maximum(), sharingMode(), MemoryMode::BoundsChecking));
    574         m_handle = WTFMove(newHandle);
    575 
     419        memcpy(newMemory, memory(), m_size);
     420        if (m_memory)
     421            Gigacage::freeVirtualPages(Gigacage::Primitive, memory(), m_size);
     422        m_memory = CagedMemory(newMemory, desiredSize);
     423        m_mappedCapacity = desiredSize;
     424        m_size = desiredSize;
    576425        ASSERT(memory() == newMemory);
    577426        return success();
    578427    }
    579428    case MemoryMode::Signaling: {
    580         size_t extraBytes = desiredSize - size();
    581         RELEASE_ASSERT(extraBytes);
    582         bool allocationSuccess = tryAllocate(
    583             [&] () -> MemoryResult::Kind {
    584                 return memoryManager().tryAllocatePhysicalBytes(extraBytes);
    585             }, m_notifyMemoryPressure, m_syncTryToReclaimMemory);
    586         if (!allocationSuccess)
    587             return makeUnexpected(GrowFailReason::OutOfMemory);
    588 
    589429        RELEASE_ASSERT(memory());
    590 
    591430        // Signaling memory must have been pre-allocated virtually.
    592         uint8_t* startAddress = static_cast<uint8_t*>(memory()) + size();
     431        uint8_t* startAddress = static_cast<uint8_t*>(memory()) + m_size;
    593432       
    594433        dataLogLnIf(verbose, "Marking WebAssembly memory's ", RawPointer(memory()), " as read+write in range [", RawPointer(startAddress), ", ", RawPointer(startAddress + extraBytes), ")");
     
    597436            RELEASE_ASSERT_NOT_REACHED();
    598437        }
    599 
    600         m_handle->growToSize(desiredSize);
     438        m_memory.recage(m_size, desiredSize);
     439        m_size = desiredSize;
    601440        return success();
    602441    }
     
    621460void Memory::dump(PrintStream& out) const
    622461{
    623     auto handle = m_handle.copyRef();
    624     out.print("Memory at ", RawPointer(handle->memory()), ", size ", handle->size(), "B capacity ", handle->mappedCapacity(), "B, initial ", handle->initial(), " maximum ", handle->maximum(), " mode ", makeString(handle->mode()), " sharingMode ", makeString(handle->sharingMode()));
     462    out.print("Memory at ", RawPointer(memory()), ", size ", m_size, "B capacity ", m_mappedCapacity, "B, initial ", m_initial, " maximum ", m_maximum, " mode ", makeString(m_mode));
    625463}
    626464
  • trunk/Source/JavaScriptCore/wasm/WasmMemory.h

    r269940 r269950  
    4545namespace JSC {
    4646
    47 class LLIntOffsetsExtractor;
    48 
    4947namespace Wasm {
    5048
    5149class Instance;
    5250
    53 class MemoryHandle final : public ThreadSafeRefCounted<MemoryHandle> {
    54     WTF_MAKE_NONCOPYABLE(MemoryHandle);
    55     WTF_MAKE_FAST_ALLOCATED;
    56     friend LLIntOffsetsExtractor;
    57 public:
    58     MemoryHandle(void*, size_t size, size_t mappedCapacity, PageCount initial, PageCount maximum, MemorySharingMode, MemoryMode);
    59     JS_EXPORT_PRIVATE ~MemoryHandle();
    60 
    61     void* memory() const { ASSERT(m_memory.getMayBeNull(m_mappedCapacity) == m_memory.getUnsafe()); return m_memory.getMayBeNull(m_mappedCapacity); }
    62     size_t size() const { return m_size; }
    63     size_t mappedCapacity() const { return m_mappedCapacity; }
    64     PageCount initial() const { return m_initial; }
    65     PageCount maximum() const { return m_maximum; }
    66     MemorySharingMode sharingMode() const { return m_sharingMode; }
    67     MemoryMode mode() const { return m_mode; }
    68     static ptrdiff_t offsetOfSize() { return OBJECT_OFFSETOF(MemoryHandle, m_size); }
    69     Lock& lock() { return m_lock; }
    70 
    71     void growToSize(size_t size)
    72     {
    73         m_size = size;
    74     }
    75 
    76 private:
    77     using CagedMemory = CagedPtr<Gigacage::Primitive, void, tagCagedPtr>;
    78     CagedMemory m_memory;
    79     size_t m_size { 0 };
    80     size_t m_mappedCapacity { 0 };
    81     PageCount m_initial;
    82     PageCount m_maximum;
    83     MemorySharingMode m_sharingMode { MemorySharingMode::Default };
    84     MemoryMode m_mode { MemoryMode::BoundsChecking };
    85     Lock m_lock;
    86 };
    87 
    88 class Memory final : public RefCounted<Memory> {
     51class Memory : public RefCounted<Memory> {
    8952    WTF_MAKE_NONCOPYABLE(Memory);
    9053    WTF_MAKE_FAST_ALLOCATED;
    91     friend LLIntOffsetsExtractor;
    9254public:
    9355    void dump(WTF::PrintStream&) const;
    9456
    95     explicit operator bool() const { return !!m_handle->memory(); }
     57    explicit operator bool() const { return !!m_memory; }
    9658   
    9759    enum NotifyPressure { NotifyPressureTag };
     
    10062
    10163    static Ref<Memory> create();
    102     JS_EXPORT_PRIVATE static Ref<Memory> create(Ref<MemoryHandle>&&, WTF::Function<void(NotifyPressure)>&& notifyMemoryPressure, WTF::Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback);
    103     static RefPtr<Memory> tryCreate(PageCount initial, PageCount maximum, MemorySharingMode, WTF::Function<void(NotifyPressure)>&& notifyMemoryPressure, WTF::Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback);
     64    static RefPtr<Memory> tryCreate(PageCount initial, PageCount maximum, WTF::Function<void(NotifyPressure)>&& notifyMemoryPressure, WTF::Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback);
    10465
    105     JS_EXPORT_PRIVATE ~Memory();
     66    ~Memory();
    10667
    10768    static size_t fastMappedRedzoneBytes();
    10869    static size_t fastMappedBytes(); // Includes redzone.
    109     static bool addressIsInGrowableOrFastMemory(void*);
     70    static bool addressIsInActiveFastMemory(void*);
    11071
    111     void* memory() const { return m_handle->memory(); }
    112     size_t size() const { return m_handle->size(); }
    113     PageCount sizeInPages() const { return PageCount::fromBytes(size()); }
    114     size_t boundsCheckingSize() const { return m_handle->mappedCapacity(); }
    115     PageCount initial() const { return m_handle->initial(); }
    116     PageCount maximum() const { return m_handle->maximum(); }
    117     MemoryHandle& handle() { return m_handle.get(); }
     72    void* memory() const { ASSERT(m_memory.getMayBeNull(size()) == m_memory.getUnsafe()); return m_memory.getMayBeNull(size()); }
     73    size_t size() const { return m_size; }
     74    PageCount sizeInPages() const { return PageCount::fromBytes(m_size); }
    11875
    119     MemorySharingMode sharingMode() const { return m_handle->sharingMode(); }
    120     MemoryMode mode() const { return m_handle->mode(); }
     76    PageCount initial() const { return m_initial; }
     77    PageCount maximum() const { return m_maximum; }
     78
     79    MemoryMode mode() const { return m_mode; }
    12180
    12281    enum class GrowFailReason {
     
    13190    void check() {  ASSERT(!deletionHasBegun()); }
    13291
    133     static ptrdiff_t offsetOfHandle() { return OBJECT_OFFSETOF(Memory, m_handle); }
     92    static ptrdiff_t offsetOfMemory() { return OBJECT_OFFSETOF(Memory, m_memory); }
     93    static ptrdiff_t offsetOfSize() { return OBJECT_OFFSETOF(Memory, m_size); }
    13494
    13595private:
    13696    Memory();
    137     Memory(Ref<MemoryHandle>&&, WTF::Function<void(NotifyPressure)>&& notifyMemoryPressure, WTF::Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback);
    138     Memory(PageCount initial, PageCount maximum, MemorySharingMode, WTF::Function<void(NotifyPressure)>&& notifyMemoryPressure, WTF::Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback);
     97    Memory(void* memory, PageCount initial, PageCount maximum, size_t mappedCapacity, MemoryMode, WTF::Function<void(NotifyPressure)>&& notifyMemoryPressure, WTF::Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback);
     98    Memory(PageCount initial, PageCount maximum, WTF::Function<void(NotifyPressure)>&& notifyMemoryPressure, WTF::Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback);
    13999
    140     Expected<PageCount, GrowFailReason> growShared(PageCount);
    141 
    142     Ref<MemoryHandle> m_handle;
     100    using CagedMemory = CagedPtr<Gigacage::Primitive, void, tagCagedPtr>;
     101    CagedMemory m_memory;
     102    size_t m_size { 0 };
     103    PageCount m_initial;
     104    PageCount m_maximum;
     105    size_t m_mappedCapacity { 0 };
     106    MemoryMode m_mode { MemoryMode::BoundsChecking };
    143107    WTF::Function<void(NotifyPressure)> m_notifyMemoryPressure;
    144108    WTF::Function<void(SyncTryToReclaim)> m_syncTryToReclaimMemory;
     
    156120public:
    157121    static size_t maxFastMemoryCount() { return 0; }
    158     static bool addressIsInGrowableOrFastMemory(void*) { return false; }
     122    static bool addressIsInActiveFastMemory(void*) { return false; }
    159123};
    160124
  • trunk/Source/JavaScriptCore/wasm/WasmMemoryInformation.cpp

    r269940 r269950  
    4343            ++numberOfPinnedRegisters;
    4444        GPRReg baseMemoryPointer = GPRInfo::regCS3;
    45         GPRReg boundsCheckingSizeRegister = GPRInfo::regCS4;
     45        GPRReg sizeRegister = GPRInfo::regCS4;
    4646        GPRReg wasmContextInstancePointer = InvalidGPRReg;
    4747        if (!Context::useFastTLS())
    4848            wasmContextInstancePointer = GPRInfo::regCS0;
    4949
    50         staticPinnedRegisterInfo.construct(boundsCheckingSizeRegister, baseMemoryPointer, wasmContextInstancePointer);
     50        staticPinnedRegisterInfo.construct(sizeRegister, baseMemoryPointer, wasmContextInstancePointer);
    5151    });
    5252
     
    5454}
    5555
    56 PinnedRegisterInfo::PinnedRegisterInfo(GPRReg boundsCheckingSizeRegister, GPRReg baseMemoryPointer, GPRReg wasmContextInstancePointer)
    57     : boundsCheckingSizeRegister(boundsCheckingSizeRegister)
     56PinnedRegisterInfo::PinnedRegisterInfo(GPRReg sizeRegister, GPRReg baseMemoryPointer, GPRReg wasmContextInstancePointer)
     57    : sizeRegister(sizeRegister)
    5858    , baseMemoryPointer(baseMemoryPointer)
    5959    , wasmContextInstancePointer(wasmContextInstancePointer)
  • trunk/Source/JavaScriptCore/wasm/WasmMemoryInformation.h

    r269940 r269950  
    4040
    4141struct PinnedSizeRegisterInfo {
    42     GPRReg boundsCheckingSizeRegister;
     42    GPRReg sizeRegister;
    4343    unsigned sizeOffset;
    4444};
     
    5757            result.set(wasmContextInstancePointer);
    5858        if (mode != MemoryMode::Signaling)
    59             result.set(boundsCheckingSizeRegister);
     59            result.set(sizeRegister);
    6060        return result;
    6161    }
    6262
    63     GPRReg boundsCheckingSizeRegister;
     63    GPRReg sizeRegister;
    6464    GPRReg baseMemoryPointer;
    6565    GPRReg wasmContextInstancePointer;
  • trunk/Source/JavaScriptCore/wasm/WasmMemoryMode.cpp

    r269940 r269950  
    4343}
    4444
    45 const char* makeString(MemorySharingMode sharingMode)
    46 {
    47     switch (sharingMode) {
    48     case MemorySharingMode::Default: return "Default";
    49     case MemorySharingMode::Shared: return "Shared";
    50     }
    51     RELEASE_ASSERT_NOT_REACHED();
    52     return "";
    53 }
    54 
    5545} } // namespace JSC::Wasm
    5646
  • trunk/Source/JavaScriptCore/wasm/WasmMemoryMode.h

    r269940 r269950  
    4141JS_EXPORT_PRIVATE const char* makeString(MemoryMode);
    4242
    43 enum class MemorySharingMode : uint8_t {
    44     Default,
    45     Shared,
    46 };
    47 
    48 JS_EXPORT_PRIVATE const char* makeString(MemorySharingMode);
    49 
    5043} } // namespace JSC::Wasm
    5144
  • trunk/Source/JavaScriptCore/wasm/js/JSToWasm.cpp

    r269940 r269950  
    222222    if (!!info.memory) {
    223223        GPRReg baseMemory = pinnedRegs.baseMemoryPointer;
    224         GPRReg scratchOrBoundsCheckingSize = wasmCallingConvention().prologueScratchGPRs[0];
     224        GPRReg scratchOrSize = wasmCallingConvention().prologueScratchGPRs[0];
    225225
    226226        if (Context::useFastTLS())
     
    230230        if (isARM64E()) {
    231231            if (mode != Wasm::MemoryMode::Signaling)
    232                 scratchOrBoundsCheckingSize = pinnedRegs.boundsCheckingSizeRegister;
    233             jit.loadPtr(CCallHelpers::Address(currentInstanceGPR, Wasm::Instance::offsetOfCachedBoundsCheckingSize()), scratchOrBoundsCheckingSize);
     232                scratchOrSize = pinnedRegs.sizeRegister;
     233            jit.loadPtr(CCallHelpers::Address(currentInstanceGPR, Wasm::Instance::offsetOfCachedMemorySize()), scratchOrSize);
    234234        } else {
    235235            if (mode != Wasm::MemoryMode::Signaling)
    236                 jit.loadPtr(CCallHelpers::Address(currentInstanceGPR, Wasm::Instance::offsetOfCachedBoundsCheckingSize()), pinnedRegs.boundsCheckingSizeRegister);
     236                jit.loadPtr(CCallHelpers::Address(currentInstanceGPR, Wasm::Instance::offsetOfCachedMemorySize()), pinnedRegs.sizeRegister);
    237237        }
    238238
    239239        jit.loadPtr(CCallHelpers::Address(currentInstanceGPR, Wasm::Instance::offsetOfCachedMemory()), baseMemory);
    240         jit.cageConditionally(Gigacage::Primitive, baseMemory, scratchOrBoundsCheckingSize, scratchOrBoundsCheckingSize);
     240        jit.cageConditionally(Gigacage::Primitive, baseMemory, scratchOrSize, scratchOrSize);
    241241    }
    242242
  • trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp

    r269940 r269950  
    292292            RETURN_IF_EXCEPTION(throwScope, nullptr);
    293293
    294             RefPtr<Wasm::Memory> memory = Wasm::Memory::tryCreate(moduleInformation.memory.initial(), moduleInformation.memory.maximum(), Wasm::MemorySharingMode::Default,
     294            RefPtr<Wasm::Memory> memory = Wasm::Memory::tryCreate(moduleInformation.memory.initial(), moduleInformation.memory.maximum(),
    295295                [&vm] (Wasm::Memory::NotifyPressure) { vm.heap.collectAsync(CollectionScope::Full); },
    296296                [&vm] (Wasm::Memory::SyncTryToReclaim) { vm.heap.collectSync(CollectionScope::Full); },
  • trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.cpp

    r269940 r269950  
    3333#include "ArrayBuffer.h"
    3434#include "JSArrayBuffer.h"
    35 #include "ObjectConstructor.h"
    3635
    3736namespace JSC {
     
    7473}
    7574
    76 JSArrayBuffer* JSWebAssemblyMemory::buffer(JSGlobalObject* globalObject)
     75JSArrayBuffer* JSWebAssemblyMemory::buffer(VM& vm, JSGlobalObject* globalObject)
    7776{
    78     VM& vm = globalObject->vm();
    79     auto throwScope = DECLARE_THROW_SCOPE(vm);
     77    if (m_bufferWrapper)
     78        return m_bufferWrapper.get();
    8079
    81     auto* wrapper = m_bufferWrapper.get();
    82     if (wrapper) {
    83         if (m_memory->sharingMode() == Wasm::MemorySharingMode::Default)
    84             return wrapper;
    85 
    86         ASSERT(m_memory->sharingMode() == Wasm::MemorySharingMode::Shared);
    87         // If SharedArrayBuffer's underlying memory is not grown, we continue using cached wrapper.
    88         if (wrapper->impl()->byteLength() == memory().size())
    89             return wrapper;
    90     }
    91 
    92     Ref<Wasm::MemoryHandle> protectedHandle = m_memory->handle();
    93     auto destructor = createSharedTask<void(void*)>([protectedHandle = WTFMove(protectedHandle)] (void*) { });
     80    // We can't use a ref here since it doesn't have a copy constructor...
     81    Ref<Wasm::Memory> protectedMemory = m_memory.get();
     82    auto destructor = createSharedTask<void(void*)>([protectedMemory = WTFMove(protectedMemory)] (void*) { });
    9483    m_buffer = ArrayBuffer::createFromBytes(memory().memory(), memory().size(), WTFMove(destructor));
    9584    m_buffer->makeWasmMemory();
    96     if (m_memory->sharingMode() == Wasm::MemorySharingMode::Shared)
    97         m_buffer->makeShared();
    98     auto* arrayBuffer = JSArrayBuffer::create(vm, globalObject->arrayBufferStructure(m_buffer->sharingMode()), m_buffer.get());
    99     if (m_memory->sharingMode() == Wasm::MemorySharingMode::Shared) {
    100         objectConstructorFreeze(globalObject, arrayBuffer);
    101         RETURN_IF_EXCEPTION(throwScope, { });
    102     }
    103     m_bufferWrapper.set(vm, this, arrayBuffer);
     85    m_bufferWrapper.set(vm, this, JSArrayBuffer::create(vm, globalObject->arrayBufferStructure(ArrayBufferSharingMode::Default), m_buffer.get()));
    10486    RELEASE_ASSERT(m_bufferWrapper);
    10587    return m_bufferWrapper.get();
     
    136118    // We need to clear out the old array buffer because it might now be pointing to stale memory.
    137119    if (m_buffer) {
    138         if (m_memory->sharingMode() == Wasm::MemorySharingMode::Default)
    139             m_buffer->detach(vm);
     120        m_buffer->detach(vm);
    140121        m_buffer = nullptr;
    141122        m_bufferWrapper.clear();
  • trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h

    r269940 r269950  
    2828#if ENABLE(WEBASSEMBLY)
    2929
    30 #include "JSObject.h"
     30#include "JSDestructibleObject.h"
    3131#include "WasmMemory.h"
    3232#include <wtf/Ref.h>
     
    5050    }
    5151
    52     JS_EXPORT_PRIVATE static JSWebAssemblyMemory* tryCreate(JSGlobalObject*, VM&, Structure*);
     52    static JSWebAssemblyMemory* tryCreate(JSGlobalObject*, VM&, Structure*);
    5353    static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
    5454
    5555    DECLARE_EXPORT_INFO;
    5656
    57     JS_EXPORT_PRIVATE void adopt(Ref<Wasm::Memory>&&);
     57    void adopt(Ref<Wasm::Memory>&&);
    5858    Wasm::Memory& memory() { return m_memory.get(); }
    59     JSArrayBuffer* buffer(JSGlobalObject*);
     59    JSArrayBuffer* buffer(VM& vm, JSGlobalObject*);
    6060    Wasm::PageCount grow(VM&, JSGlobalObject*, uint32_t delta);
    61     JS_EXPORT_PRIVATE void growSuccessCallback(VM&, Wasm::PageCount oldPageCount, Wasm::PageCount newPageCount);
     61    void growSuccessCallback(VM&, Wasm::PageCount oldPageCount, Wasm::PageCount newPageCount);
    6262
    6363private:
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp

    r269940 r269950  
    358358    if (!!moduleInformation.memory) {
    359359        GPRReg baseMemory = pinnedRegs.baseMemoryPointer;
    360         GPRReg scratchOrBoundsCheckingSize = stackLimitGPR;
     360        GPRReg scratchOrSize = stackLimitGPR;
    361361        auto mode = instance()->memoryMode();
    362362
    363363        if (isARM64E()) {
    364364            if (mode != Wasm::MemoryMode::Signaling)
    365                 scratchOrBoundsCheckingSize = pinnedRegs.boundsCheckingSizeRegister;
    366             jit.loadPtr(CCallHelpers::Address(scratchGPR, Wasm::Instance::offsetOfCachedBoundsCheckingSize()), scratchOrBoundsCheckingSize);
     365                scratchOrSize = pinnedRegs.sizeRegister;
     366            jit.loadPtr(CCallHelpers::Address(scratchGPR, Wasm::Instance::offsetOfCachedMemorySize()), scratchOrSize);
    367367        } else {
    368368            if (mode != Wasm::MemoryMode::Signaling)
    369                 jit.loadPtr(CCallHelpers::Address(scratchGPR, Wasm::Instance::offsetOfCachedBoundsCheckingSize()), pinnedRegs.boundsCheckingSizeRegister);
     369                jit.loadPtr(CCallHelpers::Address(scratchGPR, Wasm::Instance::offsetOfCachedMemorySize()), pinnedRegs.sizeRegister);
    370370        }
    371371
    372372        jit.loadPtr(CCallHelpers::Address(scratchGPR, Wasm::Instance::offsetOfCachedMemory()), baseMemory);
    373         jit.cageConditionally(Gigacage::Primitive, baseMemory, scratchOrBoundsCheckingSize, scratchOrBoundsCheckingSize);
     373        jit.cageConditionally(Gigacage::Primitive, baseMemory, scratchOrSize, scratchOrSize);
    374374    }
    375375
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.cpp

    r269940 r269950  
    5757    VM& vm = globalObject->vm();
    5858    auto throwScope = DECLARE_THROW_SCOPE(vm);
     59    if (callFrame->argumentCount() != 1)
     60        return JSValue::encode(throwException(globalObject, throwScope, createTypeError(globalObject, "WebAssembly.Memory expects exactly one argument"_s)));
    5961
    6062    JSObject* memoryDescriptor;
     
    101103    }
    102104
    103     Wasm::MemorySharingMode sharingMode = Wasm::MemorySharingMode::Default;
    104     JSValue sharedValue = memoryDescriptor->get(globalObject, Identifier::fromString(vm, "shared"));
    105     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    106     bool shared = sharedValue.toBoolean(globalObject);
    107     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    108     if (shared) {
    109         if (!maximumPageCount)
    110             return throwVMTypeError(globalObject, throwScope, "'maximum' page count must be defined if 'shared' is true"_s);
    111         if (!Options::useSharedArrayBuffer())
    112             return throwVMTypeError(globalObject, throwScope, "Shared WebAssembly.Memory and SharedArrayBuffer are not enabled"_s);
    113         sharingMode = Wasm::MemorySharingMode::Shared;
    114     }
    115 
    116105    auto* jsMemory = JSWebAssemblyMemory::tryCreate(globalObject, vm, globalObject->webAssemblyMemoryStructure());
    117106    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    118107
    119     RefPtr<Wasm::Memory> memory = Wasm::Memory::tryCreate(initialPageCount, maximumPageCount, sharingMode,
     108    RefPtr<Wasm::Memory> memory = Wasm::Memory::tryCreate(initialPageCount, maximumPageCount,
    120109        [&vm] (Wasm::Memory::NotifyPressure) { vm.heap.collectAsync(CollectionScope::Full); },
    121110        [&vm] (Wasm::Memory::SyncTryToReclaim) { vm.heap.collectSync(CollectionScope::Full); },
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp

    r269940 r269950  
    9494    JSWebAssemblyMemory* memory = getMemory(globalObject, vm, callFrame->thisValue());
    9595    RETURN_IF_EXCEPTION(throwScope, { });
    96     RELEASE_AND_RETURN(throwScope, JSValue::encode(memory->buffer(globalObject)));
     96    return JSValue::encode(memory->buffer(globalObject->vm(), globalObject));
    9797}
    9898
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp

    r269940 r269950  
    567567
    568568    auto forEachSegment = [&] (auto fn) {
    569         auto wasmMemory = m_instance->instance().memory();
    570         uint8_t* memory = reinterpret_cast<uint8_t*>(wasmMemory->memory());
    571         uint64_t sizeInBytes = wasmMemory->size();
     569        uint8_t* memory = reinterpret_cast<uint8_t*>(m_instance->instance().cachedMemory());
     570        uint64_t sizeInBytes = m_instance->instance().cachedMemorySize();
    572571
    573572        for (const Wasm::Segment::Ptr& segment : data) {
  • trunk/Source/WTF/ChangeLog

    r269930 r269950  
     12020-11-18  Commit Queue  <commit-queue@webkit.org>
     2
     3        Unreviewed, reverting r269940.
     4        https://bugs.webkit.org/show_bug.cgi?id=219076
     5
     6        caused seemingly-infinite build time regression
     7
     8        Reverted changeset:
     9
     10        "[JSC] Implement WebAssembly.Memory with shared"
     11        https://bugs.webkit.org/show_bug.cgi?id=218693
     12        https://trac.webkit.org/changeset/269940
     13
    1142020-11-17  Ryan Haddad  <ryanhaddad@apple.com>
    215
  • trunk/Source/WTF/wtf/PlatformEnable.h

    r269940 r269950  
    691691
    692692#if ENABLE(WEBASSEMBLY) && HAVE(MACHINE_CONTEXT)
    693 #define ENABLE_WEBASSEMBLY_SIGNALING_MEMORY 1
     693#define ENABLE_WEBASSEMBLY_FAST_MEMORY 1
    694694#endif
    695695
  • trunk/Source/WebCore/ChangeLog

    r269948 r269950  
     12020-11-18  Commit Queue  <commit-queue@webkit.org>
     2
     3        Unreviewed, reverting r269940.
     4        https://bugs.webkit.org/show_bug.cgi?id=219076
     5
     6        caused seemingly-infinite build time regression
     7
     8        Reverted changeset:
     9
     10        "[JSC] Implement WebAssembly.Memory with shared"
     11        https://bugs.webkit.org/show_bug.cgi?id=218693
     12        https://trac.webkit.org/changeset/269940
     13
    1142020-11-18  Carlos Garcia Campos  <cgarcia@igalia.com>
    215
  • trunk/Source/WebCore/Headers.cmake

    r269940 r269950  
    15771577    workers/WorkerScriptLoaderClient.h
    15781578    workers/WorkerThread.h
    1579     workers/WorkerThreadType.h
    15801579    workers/WorkerType.h
    15811580
  • trunk/Source/WebCore/Modules/indexeddb/server/IDBSerializationContext.cpp

    r269940 r269950  
    8080    m_vm = JSC::VM::create();
    8181    m_vm->heap.acquireAccess();
    82     JSVMClientData::initNormalWorld(m_vm.get(), WorkerThreadType::Worklet);
     82    JSVMClientData::initNormalWorld(m_vm.get());
    8383
    8484    JSC::JSLockHolder locker(m_vm.get());
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r269940 r269950  
    50275027                E3A776671DC85D2800B690D8 /* DOMJITIDLConvert.h in Headers */ = {isa = PBXBuildFile; fileRef = E3A776651DC85D2200B690D8 /* DOMJITIDLConvert.h */; settings = {ATTRIBUTES = (Private, ); }; };
    50285028                E3A776681DC85D2800B690D8 /* DOMJITIDLType.h in Headers */ = {isa = PBXBuildFile; fileRef = E3A776661DC85D2200B690D8 /* DOMJITIDLType.h */; settings = {ATTRIBUTES = (Private, ); }; };
    5029                 E3AFD7AD255F50EB00E5E30E /* WorkerThreadType.h in Headers */ = {isa = PBXBuildFile; fileRef = E3AFD7AB255F50DC00E5E30E /* WorkerThreadType.h */; settings = {ATTRIBUTES = (Private, ); }; };
    50305029                E3B2F0ED1D7F4CA300B0C9D1 /* LoadableScript.h in Headers */ = {isa = PBXBuildFile; fileRef = E3B2F0E71D7F35EC00B0C9D1 /* LoadableScript.h */; settings = {ATTRIBUTES = (Private, ); }; };
    50315030                E3B2F0EE1D7F4CA900B0C9D1 /* LoadableScriptClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E3B2F0E81D7F35EC00B0C9D1 /* LoadableScriptClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    1607316072                E3AE6CD12252F27000C70B50 /* AllDescendantsCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AllDescendantsCollection.cpp; sourceTree = "<group>"; };
    1607416073                E3AFA9641DA6E908002861BD /* JSNodeDOMJIT.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSNodeDOMJIT.cpp; sourceTree = "<group>"; };
    16075                 E3AFD7AB255F50DC00E5E30E /* WorkerThreadType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WorkerThreadType.h; sourceTree = "<group>"; };
    1607616074                E3B2F0E31D7F35EC00B0C9D1 /* LoadableClassicScript.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoadableClassicScript.cpp; sourceTree = "<group>"; };
    1607716075                E3B2F0E41D7F35EC00B0C9D1 /* LoadableClassicScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoadableClassicScript.h; sourceTree = "<group>"; };
     
    1905019048                                2E4346420F546A8200B0F1BA /* WorkerThread.cpp */,
    1905119049                                2E4346430F546A8200B0F1BA /* WorkerThread.h */,
    19052                                 E3AFD7AB255F50DC00E5E30E /* WorkerThreadType.h */,
    1905319050                                51F174FC1F35898800C74950 /* WorkerType.h */,
    1905419051                                51F174FA1F3588D700C74950 /* WorkerType.idl */,
     
    3519935196                                0B9056F90F2685F30095FF6A /* WorkerThreadableLoader.h in Headers */,
    3520035197                                97AABD2D14FA09D5007457AE /* WorkerThreadableWebSocketChannel.h in Headers */,
    35201                                 E3AFD7AD255F50EB00E5E30E /* WorkerThreadType.h in Headers */,
    3520235198                                A54A0C681DB807D90017A90B /* WorkerToPageFrontendChannel.h in Headers */,
    3520335199                                51F174FE1F35899200C74950 /* WorkerType.h in Headers */,
  • trunk/Source/WebCore/bindings/IDLTypes.h

    r269940 r269950  
    152152};
    153153
    154 template<typename T> struct IDLAllowSharedAdaptor : T {
    155     using InnerType = T;
    156 };
    157 
    158154struct IDLObject : IDLType<JSC::Strong<JSC::JSObject>> {
    159155    using NullableType = JSC::Strong<JSC::JSObject>;
     
    328324struct IsIDLTypedArray : public std::integral_constant<bool, WTF::IsBaseOfTemplate<IDLTypedArray, T>::value> { };
    329325
    330 template<typename T>
    331 struct IsIDLArrayBuffer : public std::integral_constant<bool, std::is_base_of<IDLArrayBuffer, T>::value> { };
    332 
    333 template<typename T>
    334 struct IsIDLArrayBufferView : public std::integral_constant<bool, std::is_base_of<IDLArrayBufferView, T>::value> { };
    335 
    336 template<typename T>
    337 struct IsIDLArrayBufferAllowShared : public std::integral_constant<bool, std::is_base_of<IDLAllowSharedAdaptor<IDLArrayBuffer>, T>::value> { };
    338 
    339 template<typename T>
    340 struct IsIDLArrayBufferViewAllowShared : public std::integral_constant<bool, std::is_base_of<IDLAllowSharedAdaptor<IDLArrayBufferView>, T>::value> { };
    341 
    342 
    343326} // namespace WebCore
  • trunk/Source/WebCore/bindings/js/CommonVM.cpp

    r269940 r269950  
    8989    vm.setGlobalConstRedeclarationShouldThrow(globalConstRedeclarationShouldThrow());
    9090
    91     JSVMClientData::initNormalWorld(&vm, WorkerThreadType::Main);
     91    JSVMClientData::initNormalWorld(&vm);
    9292
    9393    return vm;
  • trunk/Source/WebCore/bindings/js/JSDOMConvertBufferSource.h

    r269940 r269950  
    110110namespace Detail {
    111111
    112 enum class BufferSourceConverterAllowSharedMode { Allow, Disallow };
    113 template<typename BufferSourceType, BufferSourceConverterAllowSharedMode mode>
     112template<typename BufferSourceType>
    114113struct BufferSourceConverter {
    115114    using WrapperType = typename Converter<BufferSourceType>::WrapperType;
     
    121120        auto& vm = JSC::getVM(&lexicalGlobalObject);
    122121        auto scope = DECLARE_THROW_SCOPE(vm);
    123         ReturnType object { };
    124         if constexpr (mode == BufferSourceConverterAllowSharedMode::Allow)
    125             object = WrapperType::toWrappedAllowShared(vm, value);
    126         else
    127             object = WrapperType::toWrapped(vm, value);
     122        ReturnType object = WrapperType::toWrapped(vm, value);
    128123        if (UNLIKELY(!object))
    129124            exceptionThrower(lexicalGlobalObject, scope);
     
    141136    static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower())
    142137    {
    143         return Detail::BufferSourceConverter<IDLArrayBuffer, Detail::BufferSourceConverterAllowSharedMode::Disallow>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
     138        return Detail::BufferSourceConverter<IDLArrayBuffer>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
    144139    }
    145140};
     
    163158    static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower())
    164159    {
    165         return Detail::BufferSourceConverter<IDLDataView, Detail::BufferSourceConverterAllowSharedMode::Disallow>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
     160        return Detail::BufferSourceConverter<IDLDataView>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
    166161    }
    167162};
     
    185180    static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower())
    186181    {
    187         return Detail::BufferSourceConverter<IDLInt8Array, Detail::BufferSourceConverterAllowSharedMode::Disallow>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
     182        return Detail::BufferSourceConverter<IDLInt8Array>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
    188183    }
    189184};
     
    207202    static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower())
    208203    {
    209         return Detail::BufferSourceConverter<IDLInt16Array, Detail::BufferSourceConverterAllowSharedMode::Disallow>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
     204        return Detail::BufferSourceConverter<IDLInt16Array>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
    210205    }
    211206};
     
    229224    static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower())
    230225    {
    231         return Detail::BufferSourceConverter<IDLInt32Array, Detail::BufferSourceConverterAllowSharedMode::Disallow>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
     226        return Detail::BufferSourceConverter<IDLInt32Array>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
    232227    }
    233228};
     
    251246    static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower())
    252247    {
    253         return Detail::BufferSourceConverter<IDLUint8Array, Detail::BufferSourceConverterAllowSharedMode::Disallow>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
     248        return Detail::BufferSourceConverter<IDLUint8Array>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
    254249    }
    255250};
     
    279274    static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower())
    280275    {
    281         return Detail::BufferSourceConverter<IDLUint16Array, Detail::BufferSourceConverterAllowSharedMode::Disallow>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
     276        return Detail::BufferSourceConverter<IDLUint16Array>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
    282277    }
    283278};
     
    301296    static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower())
    302297    {
    303         return Detail::BufferSourceConverter<IDLUint32Array, Detail::BufferSourceConverterAllowSharedMode::Disallow>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
     298        return Detail::BufferSourceConverter<IDLUint32Array>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
    304299    }
    305300};
     
    323318    static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower())
    324319    {
    325         return Detail::BufferSourceConverter<IDLUint8ClampedArray, Detail::BufferSourceConverterAllowSharedMode::Disallow>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
     320        return Detail::BufferSourceConverter<IDLUint8ClampedArray>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
    326321    }
    327322};
     
    345340    static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower())
    346341    {
    347         return Detail::BufferSourceConverter<IDLFloat32Array, Detail::BufferSourceConverterAllowSharedMode::Disallow>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
     342        return Detail::BufferSourceConverter<IDLFloat32Array>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
    348343    }
    349344};
     
    367362    static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower())
    368363    {
    369         return Detail::BufferSourceConverter<IDLFloat64Array, Detail::BufferSourceConverterAllowSharedMode::Disallow>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
     364        return Detail::BufferSourceConverter<IDLFloat64Array>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
    370365    }
    371366};
     
    389384    static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower())
    390385    {
    391         return Detail::BufferSourceConverter<IDLArrayBufferView, Detail::BufferSourceConverterAllowSharedMode::Disallow>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
     386        return Detail::BufferSourceConverter<IDLArrayBufferView>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
    392387    }
    393388};
     
    404399};
    405400
    406 template<typename T>
    407 struct Converter<IDLAllowSharedAdaptor<T>> : DefaultConverter<T> {
    408     using ConverterType = Converter<T>;
    409     using WrapperType = typename ConverterType::WrapperType;
    410     using ReturnType = typename ConverterType::ReturnType;
    411 
    412     template<typename ExceptionThrower = DefaultExceptionThrower>
    413     static ReturnType convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value, ExceptionThrower&& exceptionThrower = ExceptionThrower())
    414     {
    415         return Detail::BufferSourceConverter<T, Detail::BufferSourceConverterAllowSharedMode::Allow>::convert(lexicalGlobalObject, value, std::forward<ExceptionThrower>(exceptionThrower));
    416     }
    417 };
    418 
    419401} // namespace WebCore
  • trunk/Source/WebCore/bindings/js/JSDOMConvertUnion.h

    r269940 r269950  
    226226        //     1. If types includes ArrayBuffer, then return the result of converting V to ArrayBuffer.
    227227        //     2. If types includes object, then return the IDL value that is a reference to the object V.
    228         constexpr bool hasArrayBufferType = brigand::any<TypeList, IsIDLArrayBuffer<brigand::_1>>::value;
     228        constexpr bool hasArrayBufferType = brigand::any<TypeList, std::is_same<IDLArrayBuffer, brigand::_1>>::value;
    229229        if (hasArrayBufferType || hasObjectType) {
    230             auto arrayBuffer = (brigand::any<TypeList, IsIDLArrayBufferAllowShared<brigand::_1>>::value) ? JSC::JSArrayBuffer::toWrappedAllowShared(vm, value) : JSC::JSArrayBuffer::toWrapped(vm, value);
     230            auto arrayBuffer = JSC::JSArrayBuffer::toWrapped(vm, value);
    231231            if (arrayBuffer) {
    232232                if (hasArrayBufferType)
     
    236236        }
    237237
    238         constexpr bool hasArrayBufferViewType = brigand::any<TypeList, IsIDLArrayBufferView<brigand::_1>>::value;
     238        constexpr bool hasArrayBufferViewType = brigand::any<TypeList, std::is_same<IDLArrayBufferView, brigand::_1>>::value;
    239239        if (hasArrayBufferViewType || hasObjectType) {
    240             auto arrayBufferView = (brigand::any<TypeList, IsIDLArrayBufferViewAllowShared<brigand::_1>>::value) ? JSC::JSArrayBufferView::toWrappedAllowShared(vm, value) : JSC::JSArrayBufferView::toWrapped(vm, value);
     240            auto arrayBufferView = JSC::JSArrayBufferView::toWrapped(vm, value);
    241241            if (arrayBufferView) {
    242242                if (hasArrayBufferViewType)
     
    406406};
    407407
    408 // BufferSource specialization. In WebKit, BufferSource is defined as IDLUnion<IDLArrayBufferView, IDLArrayBuffer> as a hack, and it is not compatible to
    409 // annotation described in WebIDL.
    410 template<> struct Converter<IDLAllowSharedAdaptor<IDLUnion<IDLArrayBufferView, IDLArrayBuffer>>> : DefaultConverter<IDLUnion<IDLArrayBufferView, IDLArrayBuffer>> {
    411     static auto convert(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue value) -> decltype(auto)
    412     {
    413         return Converter<IDLUnion<IDLAllowSharedAdaptor<IDLArrayBufferView>, IDLAllowSharedAdaptor<IDLArrayBuffer>>>::convert(lexicalGlobalObject, value);
    414     }
    415 };
    416 
    417408} // namespace WebCore
  • trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp

    r269940 r269950  
    7676#include <JavaScriptCore/JSSetIterator.h>
    7777#include <JavaScriptCore/JSTypedArrays.h>
    78 #include <JavaScriptCore/JSWebAssemblyMemory.h>
    7978#include <JavaScriptCore/JSWebAssemblyModule.h>
    8079#include <JavaScriptCore/ObjectConstructor.h>
     
    184183    BigIntTag = 47,
    185184    BigIntObjectTag = 48,
    186 #if ENABLE(WEBASSEMBLY)
    187     WasmMemoryTag = 49,
    188 #endif
    189185    ErrorTag = 255
    190186};
     
    362358 *    | ArrayBuffer
    363359 *    | ArrayBufferViewTag ArrayBufferViewSubtag <byteOffset:uint32_t> <byteLength:uint32_t> (ArrayBuffer | ObjectReference)
     360 *    | ArrayBufferTransferTag <value:uint32_t>
    364361 *    | CryptoKeyTag <wrappedKeyLength:uint32_t> <factor:byte{wrappedKeyLength}>
    365362 *    | DOMPoint
     
    371368 *    | ImageBitmapTag <originClean:uint8_t> <logicalWidth:int32_t> <logicalHeight:int32_t> <resolutionScale:double> <byteLength:uint32_t>(<imageByteData:uint8_t>)
    372369 *    | OffscreenCanvasTransferTag <value:uint32_t>
    373  *    | WasmMemoryTag <value:uint32_t>
    374370 *
    375371 * Inside certificate, data is serialized in this format as per spec:
     
    424420 * ArrayBuffer :-
    425421 *    ArrayBufferTag <length:uint32_t> <contents:byte{length}>
    426  *    ArrayBufferTransferTag <value:uint32_t>
    427  *    SharedArrayBufferTag <value:uint32_t>
    428422 *
    429423 * CryptoKeyHMAC :-
     
    583577#if ENABLE(WEBASSEMBLY)
    584578            WasmModuleArray& wasmModules,
    585             WasmMemoryHandleArray& wasmMemoryHandles,
    586579#endif
    587580        Vector<String>& blobURLs, Vector<uint8_t>& out, SerializationContext context, ArrayBufferContentsArray& sharedBuffers)
     
    593586#if ENABLE(WEBASSEMBLY)
    594587            wasmModules,
    595             wasmMemoryHandles,
    596588#endif
    597589            blobURLs, out, context, sharedBuffers);
     
    624616#if ENABLE(WEBASSEMBLY)
    625617            WasmModuleArray& wasmModules,
    626             WasmMemoryHandleArray& wasmMemoryHandles,
    627618#endif
    628619        Vector<String>& blobURLs, Vector<uint8_t>& out, SerializationContext context, ArrayBufferContentsArray& sharedBuffers)
     
    635626#if ENABLE(WEBASSEMBLY)
    636627        , m_wasmModules(wasmModules)
    637         , m_wasmMemoryHandles(wasmMemoryHandles)
    638628#endif
    639629    {
     
    12411231#if ENABLE(WEBASSEMBLY)
    12421232                WasmModuleArray dummyModules;
    1243                 WasmMemoryHandleArray dummyMemoryHandles;
    12441233#endif
    12451234                ArrayBufferContentsArray dummySharedBuffers;
     
    12501239#if ENABLE(WEBASSEMBLY)
    12511240                    dummyModules,
    1252                     dummyMemoryHandles,
    12531241#endif
    12541242                    dummyBlobURLs, serializedKey, SerializationContext::Default, dummySharedBuffers);
     
    12841272                m_wasmModules.append(makeRef(module->module()));
    12851273                write(WasmModuleTag);
    1286                 write(index);
    1287                 return true;
    1288             }
    1289             if (JSWebAssemblyMemory* memory = jsDynamicCast<JSWebAssemblyMemory*>(vm, obj)) {
    1290                 if (memory->memory().sharingMode() != JSC::Wasm::MemorySharingMode::Shared) {
    1291                     code = SerializationReturnCode::DataCloneError;
    1292                     return true;
    1293                 }
    1294                 if (m_context != SerializationContext::WorkerPostMessage) {
    1295                     code = SerializationReturnCode::DataCloneError;
    1296                     return true;
    1297                 }
    1298                 uint32_t index = m_wasmMemoryHandles.size();
    1299                 m_wasmMemoryHandles.append(makeRef(memory->memory().handle()));
    1300                 write(WasmMemoryTag);
    13011274                write(index);
    13021275                return true;
     
    16861659#if ENABLE(WEBASSEMBLY)
    16871660    WasmModuleArray& m_wasmModules;
    1688     WasmMemoryHandleArray& m_wasmMemoryHandles;
    16891661#endif
    16901662};
     
    19661938#if ENABLE(WEBASSEMBLY)
    19671939        , WasmModuleArray* wasmModules
    1968         , WasmMemoryHandleArray* wasmMemoryHandles
    19691940#endif
    19701941        )
     
    19781949#if ENABLE(WEBASSEMBLY)
    19791950            , wasmModules
    1980             , wasmMemoryHandles
    19811951#endif
    19821952            );
     
    20322002#if ENABLE(WEBASSEMBLY)
    20332003        , WasmModuleArray* wasmModules = nullptr
    2034         , WasmMemoryHandleArray* wasmMemoryHandles = nullptr
    20352004#endif
    20362005        )
     
    20532022#if ENABLE(WEBASSEMBLY)
    20542023        , m_wasmModules(wasmModules)
    2055         , m_wasmMemoryHandles(wasmMemoryHandles)
    20562024#endif
    20572025    {
     
    20662034#if ENABLE(WEBASSEMBLY)
    20672035        , WasmModuleArray* wasmModules
    2068         , WasmMemoryHandleArray* wasmMemoryHandles
    20692036#endif
    20702037        )
     
    20902057#if ENABLE(WEBASSEMBLY)
    20912058        , m_wasmModules(wasmModules)
    2092         , m_wasmMemoryHandles(wasmMemoryHandles)
    20932059#endif
    20942060    {
     
    33343300            return result;
    33353301        }
    3336         case WasmMemoryTag: {
    3337             uint32_t index;
    3338             bool indexSuccessfullyRead = read(index);
    3339             if (!indexSuccessfullyRead || !m_wasmMemoryHandles || index >= m_wasmMemoryHandles->size()) {
    3340                 fail();
    3341                 return JSValue();
    3342             }
    3343             RefPtr<Wasm::MemoryHandle> handle = m_wasmMemoryHandles->at(index);
    3344             if (!handle) {
    3345                 fail();
    3346                 return JSValue();
    3347             }
    3348             auto& vm = m_lexicalGlobalObject->vm();
    3349             auto scope = DECLARE_THROW_SCOPE(vm);
    3350             JSWebAssemblyMemory* result = JSC::JSWebAssemblyMemory::tryCreate(m_lexicalGlobalObject, vm, m_globalObject->webAssemblyMemoryStructure());
    3351             // Since we are cloning a JSWebAssemblyMemory, it's impossible for that
    3352             // module to not have been a valid module. Therefore, createStub should
    3353             // not trow.
    3354             scope.releaseAssertNoException();
    3355             Ref<Wasm::Memory> memory = Wasm::Memory::create(handle.releaseNonNull(),
    3356                 [&vm] (Wasm::Memory::NotifyPressure) { vm.heap.collectAsync(CollectionScope::Full); },
    3357                 [&vm] (Wasm::Memory::SyncTryToReclaim) { vm.heap.collectSync(CollectionScope::Full); },
    3358                 [&vm, result] (Wasm::Memory::GrowSuccess, Wasm::PageCount oldPageCount, Wasm::PageCount newPageCount) { result->growSuccessCallback(vm, oldPageCount, newPageCount); });
    3359             result->adopt(WTFMove(memory));
    3360             m_gcBuffer.appendWithCrashOnOverflow(result);
    3361             return result;
    3362         }
    33633302#endif
    33643303        case ArrayBufferTag: {
     
    35013440#if ENABLE(WEBASSEMBLY)
    35023441    WasmModuleArray* m_wasmModules;
    3503     WasmMemoryHandleArray* m_wasmMemoryHandles;
    35043442#endif
    35053443
     
    37243662#if ENABLE(WEBASSEMBLY)
    37253663        , std::unique_ptr<WasmModuleArray> wasmModulesArray
    3726         , std::unique_ptr<WasmMemoryHandleArray> wasmMemoryHandlesArray
    37273664#endif
    37283665        )
     
    37363673#if ENABLE(WEBASSEMBLY)
    37373674    , m_wasmModulesArray(WTFMove(wasmModulesArray))
    3738     , m_wasmMemoryHandlesArray(WTFMove(wasmMemoryHandlesArray))
    37393675#endif
    37403676{
     
    37753711#if ENABLE(WEBASSEMBLY)
    37763712    // We are not supporting WebAssembly Module memory estimation yet.
    3777     if (m_wasmMemoryHandlesArray) {
    3778         for (auto& content : *m_wasmMemoryHandlesArray)
    3779             cost += content->size();
    3780     }
    37813713#endif
    37823714
     
    38693801#if ENABLE(WEBASSEMBLY)
    38703802    WasmModuleArray dummyModules;
    3871     WasmMemoryHandleArray dummyMemoryHandles;
    38723803#endif
    38733804    ArrayBufferContentsArray dummySharedBuffers;
     
    38783809#if ENABLE(WEBASSEMBLY)
    38793810        dummyModules,
    3880         dummyMemoryHandles,
    38813811#endif
    38823812        blobURLs, buffer, SerializationContext::Default, dummySharedBuffers);
     
    38843814#if ENABLE(WEBASSEMBLY)
    38853815    ASSERT_WITH_MESSAGE(dummyModules.isEmpty(), "Wasm::Module serialization is only allowed in the postMessage context");
    3886     ASSERT_WITH_MESSAGE(dummyMemoryHandles.isEmpty(), "Wasm::Memory serialization is only allowed in the postMessage context");
    38873816#endif
    38883817
     
    39313860    for (auto& transferable : transferList) {
    39323861        if (auto arrayBuffer = toPossiblySharedArrayBuffer(vm, transferable.get())) {
    3933             if (arrayBuffer->isDetached() || arrayBuffer->isShared())
     3862            if (arrayBuffer->isDetached())
    39343863                return Exception { DataCloneError };
    39353864            if (arrayBuffer->isLocked()) {
     
    39763905#if ENABLE(WEBASSEMBLY)
    39773906    WasmModuleArray wasmModules;
    3978     WasmMemoryHandleArray wasmMemoryHandles;
    39793907#endif
    39803908    std::unique_ptr<ArrayBufferContentsArray> sharedBuffers = makeUnique<ArrayBufferContentsArray>();
     
    39843912#endif
    39853913#if ENABLE(WEBASSEMBLY)
    3986         wasmModules,
    3987         wasmMemoryHandles,
     3914        wasmModules,
    39883915#endif
    39893916        blobURLs, buffer, context, *sharedBuffers);
     
    40103937#if ENABLE(WEBASSEMBLY)
    40113938                , makeUnique<WasmModuleArray>(wasmModules)
    4012                 , context == SerializationContext::WorkerPostMessage ? makeUnique<WasmMemoryHandleArray>(wasmMemoryHandles) : nullptr
    40133939#endif
    40143940                ));
     
    40683994#if ENABLE(WEBASSEMBLY)
    40693995        , m_wasmModulesArray.get()
    4070         , m_wasmMemoryHandlesArray.get()
    40713996#endif
    40723997        );
  • trunk/Source/WebCore/bindings/js/SerializedScriptValue.h

    r269940 r269950  
    4242namespace JSC { namespace Wasm {
    4343class Module;
    44 class MemoryHandle;
    4544} }
    4645#endif
     
    6362#if ENABLE(WEBASSEMBLY)
    6463using WasmModuleArray = Vector<RefPtr<JSC::Wasm::Module>>;
    65 using WasmMemoryHandleArray = Vector<RefPtr<JSC::Wasm::MemoryHandle>>;
    6664#endif
    6765
     
    125123#if ENABLE(WEBASSEMBLY)
    126124        , std::unique_ptr<WasmModuleArray> = nullptr
    127         , std::unique_ptr<WasmMemoryHandleArray> = nullptr
    128125#endif
    129126        );
     
    140137#if ENABLE(WEBASSEMBLY)
    141138    std::unique_ptr<WasmModuleArray> m_wasmModulesArray;
    142     std::unique_ptr<WasmMemoryHandleArray> m_wasmMemoryHandlesArray;
    143139#endif
    144140    Vector<String> m_blobURLs;
  • trunk/Source/WebCore/bindings/js/WebCoreJSClientData.cpp

    r269940 r269950  
    137137}
    138138
    139 void JSVMClientData::initNormalWorld(VM* vm, WorkerThreadType type)
     139void JSVMClientData::initNormalWorld(VM* vm)
    140140{
    141141    JSVMClientData* clientData = new JSVMClientData(*vm);
     
    145145
    146146    clientData->m_normalWorld = DOMWrapperWorld::create(*vm, DOMWrapperWorld::Type::Normal);
    147     vm->m_typedArrayController = adoptRef(new WebCoreTypedArrayController(type == WorkerThreadType::DedicatedWorker || type == WorkerThreadType::Worklet));
     147    vm->m_typedArrayController = adoptRef(new WebCoreTypedArrayController());
    148148}
    149149
  • trunk/Source/WebCore/bindings/js/WebCoreJSClientData.h

    r269940 r269950  
    2525#include "WebCoreBuiltinNames.h"
    2626#include "WebCoreJSBuiltins.h"
    27 #include "WorkerThreadType.h"
    2827#include <wtf/HashSet.h>
    2928#include <wtf/RefPtr.h>
     
    4241    virtual ~JSVMClientData();
    4342   
    44     WEBCORE_EXPORT static void initNormalWorld(JSC::VM*, WorkerThreadType);
     43    WEBCORE_EXPORT static void initNormalWorld(JSC::VM*);
    4544
    4645    DOMWrapperWorld& normalWorld() { return *m_normalWorld; }
  • trunk/Source/WebCore/bindings/js/WebCoreTypedArrayController.cpp

    r269940 r269950  
    3535namespace WebCore {
    3636
    37 WebCoreTypedArrayController::WebCoreTypedArrayController(bool allowAtomicsWait)
    38     : m_allowAtomicsWait(allowAtomicsWait)
    39 {
    40 }
     37WebCoreTypedArrayController::WebCoreTypedArrayController() = default;
    4138
    4239WebCoreTypedArrayController::~WebCoreTypedArrayController() = default;
     
    5451bool WebCoreTypedArrayController::isAtomicsWaitAllowedOnCurrentThread()
    5552{
    56     return m_allowAtomicsWait;
     53    return !isMainThread();
    5754}
    5855
  • trunk/Source/WebCore/bindings/js/WebCoreTypedArrayController.h

    r269940 r269950  
    3737class WebCoreTypedArrayController : public JSC::TypedArrayController {
    3838public:
    39     WebCoreTypedArrayController(bool allowAtomicsWait);
     39    WebCoreTypedArrayController();
    4040    virtual ~WebCoreTypedArrayController();
    4141   
     
    5454
    5555    JSArrayBufferOwner m_owner;
    56     bool m_allowAtomicsWait;
    5756};
    5857
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r269940 r269950  
    70007000    return 1 if $type->extendedAttributes->{AtomString};
    70017001    return 1 if $type->extendedAttributes->{RequiresExistingAtomString};
    7002     return 1 if $type->extendedAttributes->{AllowShared};
    70037002}
    70047003
     
    70127011    return "IDLAtomStringAdaptor" if $type->extendedAttributes->{AtomString};
    70137012    return "IDLRequiresExistingAtomStringAdaptor" if $type->extendedAttributes->{RequiresExistingAtomString};
    7014     return "IDLAllowSharedAdaptor" if $type->extendedAttributes->{AllowShared};
    70157013}
    70167014
  • trunk/Source/WebCore/bindings/scripts/IDLAttributes.json

    r269940 r269950  
    2525            "standard": {
    2626                "url": "https://heycam.github.io/webidl/#AllowShared"
    27             }
     27            },
     28            "unsupported": true
    2829        },
    2930        "AppleCopyright": {
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r269940 r269950  
    16031603static JSC_DECLARE_HOST_FUNCTION(jsTestObjPrototypeFunction_double_leading_underscore_function);
    16041604static JSC_DECLARE_HOST_FUNCTION(jsTestObjPrototypeFunction_trailing_underscore_function_);
    1605 static JSC_DECLARE_HOST_FUNCTION(jsTestObjPrototypeFunction_encodeInto);
    16061605static JSC_DECLARE_HOST_FUNCTION(jsTestObjPrototypeFunction_toString);
    16071606
     
    23352334    { "_double_leading_underscore_function", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsTestObjPrototypeFunction_double_leading_underscore_function), (intptr_t) (0) } },
    23362335    { "trailing_underscore_function_", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsTestObjPrototypeFunction_trailing_underscore_function_), (intptr_t) (0) } },
    2337     { "encodeInto", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsTestObjPrototypeFunction_encodeInto), (intptr_t) (1) } },
    23382336    { "toString", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsTestObjPrototypeFunction_toString), (intptr_t) (0) } },
    23392337#if ENABLE(Condition1)
     
    95009498}
    95019499
    9502 static inline JSC::EncodedJSValue jsTestObjPrototypeFunction_encodeIntoBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSTestObj>::ClassParameter castedThis)
    9503 {
    9504     auto& vm = JSC::getVM(lexicalGlobalObject);
    9505     auto throwScope = DECLARE_THROW_SCOPE(vm);
    9506     UNUSED_PARAM(throwScope);
    9507     UNUSED_PARAM(callFrame);
    9508     auto& impl = castedThis->wrapped();
    9509     if (UNLIKELY(callFrame->argumentCount() < 1))
    9510         return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject));
    9511     EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0);
    9512     auto destination = convert<IDLAllowSharedAdaptor<IDLUint8Array>>(*lexicalGlobalObject, argument0.value(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentTypeError(lexicalGlobalObject, scope, 0, "destination", "TestObject", "encodeInto", "Uint8Array"); });
    9513     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    9514     RELEASE_AND_RETURN(throwScope, JSValue::encode(toJS<IDLBoolean>(impl.encodeInto(destination.releaseNonNull()))));
    9515 }
    9516 
    9517 JSC_DEFINE_HOST_FUNCTION(jsTestObjPrototypeFunction_encodeInto, (JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame))
    9518 {
    9519     return IDLOperation<JSTestObj>::call<jsTestObjPrototypeFunction_encodeIntoBody>(*lexicalGlobalObject, *callFrame, "encodeInto");
    9520 }
    9521 
    95229500static inline JSC::EncodedJSValue jsTestObjPrototypeFunction_toStringBody(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame, typename IDLOperation<JSTestObj>::ClassParameter castedThis)
    95239501{
  • trunk/Source/WebCore/bindings/scripts/test/TestObj.idl

    r269940 r269950  
    468468    undefined __double_leading_underscore_function(); // NOTE: WebIDL removes the leading underscore so this is interpreted as "_double_leading_underscore_function"
    469469    undefined trailing_underscore_function_();
    470 
    471     boolean encodeInto([AllowShared] Uint8Array destination);
    472470};
    473471
  • trunk/Source/WebCore/dom/TextDecoder.idl

    r269940 r269950  
    4242    readonly attribute boolean fatal;
    4343    readonly attribute boolean ignoreBOM;
    44     [MayThrowException] USVString decode(optional [AllowShared] BufferSource? input, optional TextDecodeOptions options);
     44    [MayThrowException] USVString decode(optional BufferSource? input, optional TextDecodeOptions options);
    4545};
  • trunk/Source/WebCore/dom/TextDecoderStreamDecoder.idl

    r269940 r269950  
    3333
    3434    [PrivateIdentifier] DOMString encoding();
    35     [PrivateIdentifier, MayThrowException] DOMString decode([AllowShared] BufferSource source);
     35    [PrivateIdentifier, MayThrowException] DOMString decode(BufferSource source);
    3636    [PrivateIdentifier, MayThrowException] DOMString flush();
    3737};
  • trunk/Source/WebCore/dom/TextEncoder.idl

    r269940 r269950  
    4040
    4141    [NewObject] Uint8Array encode(optional USVString input = "");
    42     TextEncoderEncodeIntoResult encodeInto(USVString source, [AllowShared] Uint8Array destination);
     42    TextEncoderEncodeIntoResult encodeInto(USVString source, Uint8Array destination);
    4343};
  • trunk/Source/WebCore/workers/DedicatedWorkerGlobalScope.cpp

    r269940 r269950  
    5858
    5959DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope(const WorkerParameters& params, Ref<SecurityOrigin>&& origin, DedicatedWorkerThread& thread, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider)
    60     : WorkerGlobalScope(WorkerThreadType::DedicatedWorker, params, WTFMove(origin), thread, WTFMove(topOrigin), connectionProxy, socketProvider)
     60    : WorkerGlobalScope(params, WTFMove(origin), thread, WTFMove(topOrigin), connectionProxy, socketProvider)
    6161    , m_name(params.name)
    6262{
  • trunk/Source/WebCore/workers/WorkerGlobalScope.cpp

    r269940 r269950  
    6060WTF_MAKE_ISO_ALLOCATED_IMPL(WorkerGlobalScope);
    6161
    62 WorkerGlobalScope::WorkerGlobalScope(WorkerThreadType type, const WorkerParameters& params, Ref<SecurityOrigin>&& origin, WorkerThread& thread, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider)
    63     : WorkerOrWorkletGlobalScope(type, JSC::VM::create(), &thread)
     62WorkerGlobalScope::WorkerGlobalScope(const WorkerParameters& params, Ref<SecurityOrigin>&& origin, WorkerThread& thread, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider)
     63    : WorkerOrWorkletGlobalScope(JSC::VM::create(), &thread)
    6464    , m_url(params.scriptURL)
    6565    , m_identifier(params.identifier)
  • trunk/Source/WebCore/workers/WorkerGlobalScope.h

    r269940 r269950  
    127127
    128128protected:
    129     WorkerGlobalScope(WorkerThreadType, const WorkerParameters&, Ref<SecurityOrigin>&&, WorkerThread&, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*);
     129    WorkerGlobalScope(const WorkerParameters&, Ref<SecurityOrigin>&&, WorkerThread&, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*);
    130130
    131131    void applyContentSecurityPolicyResponseHeaders(const ContentSecurityPolicyResponseHeaders&);
  • trunk/Source/WebCore/workers/WorkerOrWorkletGlobalScope.cpp

    r269940 r269950  
    3838WTF_MAKE_ISO_ALLOCATED_IMPL(WorkerOrWorkletGlobalScope);
    3939
    40 WorkerOrWorkletGlobalScope::WorkerOrWorkletGlobalScope(WorkerThreadType type, Ref<JSC::VM>&& vm, WorkerOrWorkletThread* thread)
    41     : m_script(makeUnique<WorkerOrWorkletScriptController>(type, WTFMove(vm), this))
     40WorkerOrWorkletGlobalScope::WorkerOrWorkletGlobalScope(Ref<JSC::VM>&& vm, WorkerOrWorkletThread* thread)
     41    : m_script(makeUnique<WorkerOrWorkletScriptController>(WTFMove(vm), this))
    4242    , m_thread(thread)
    4343    , m_inspectorController(makeUnique<WorkerInspectorController>(*this))
  • trunk/Source/WebCore/workers/WorkerOrWorkletGlobalScope.h

    r269940 r269950  
    2828#include "EventTarget.h"
    2929#include "ScriptExecutionContext.h"
    30 #include "WorkerThreadType.h"
    3130
    3231namespace WebCore {
     
    6968
    7069protected:
    71     WorkerOrWorkletGlobalScope(WorkerThreadType, Ref<JSC::VM>&&, WorkerOrWorkletThread*);
     70    WorkerOrWorkletGlobalScope(Ref<JSC::VM>&&, WorkerOrWorkletThread*);
    7271
    7372    // ScriptExecutionContext.
  • trunk/Source/WebCore/workers/WorkerOrWorkletScriptController.cpp

    r269940 r269950  
    5151using namespace JSC;
    5252
    53 WorkerOrWorkletScriptController::WorkerOrWorkletScriptController(WorkerThreadType type, Ref<VM>&& vm, WorkerOrWorkletGlobalScope* globalScope)
     53WorkerOrWorkletScriptController::WorkerOrWorkletScriptController(Ref<VM>&& vm, WorkerOrWorkletGlobalScope* globalScope)
    5454    : m_vm(WTFMove(vm))
    5555    , m_globalScope(globalScope)
     
    5757{
    5858    m_vm->heap.acquireAccess(); // It's not clear that we have good discipline for heap access, so turn it on permanently.
    59     JSVMClientData::initNormalWorld(m_vm.get(), type);
    60 }
    61 
    62 WorkerOrWorkletScriptController::WorkerOrWorkletScriptController(WorkerThreadType type, WorkerOrWorkletGlobalScope* globalScope)
    63     : WorkerOrWorkletScriptController(type, JSC::VM::create(), globalScope)
     59    JSVMClientData::initNormalWorld(m_vm.get());
     60}
     61
     62WorkerOrWorkletScriptController::WorkerOrWorkletScriptController(WorkerOrWorkletGlobalScope* globalScope)
     63    : WorkerOrWorkletScriptController(JSC::VM::create(), globalScope)
    6464{
    6565}
  • trunk/Source/WebCore/workers/WorkerOrWorkletScriptController.h

    r269940 r269950  
    2727#pragma once
    2828
    29 #include "WorkerThreadType.h"
    3029#include <JavaScriptCore/Debugger.h>
    3130#include <JavaScriptCore/JSRunLoopTimer.h>
     
    5352    WTF_MAKE_FAST_ALLOCATED;
    5453public:
    55     WorkerOrWorkletScriptController(WorkerThreadType, Ref<JSC::VM>&&, WorkerOrWorkletGlobalScope*);
    56     explicit WorkerOrWorkletScriptController(WorkerThreadType, WorkerOrWorkletGlobalScope*);
     54    WorkerOrWorkletScriptController(Ref<JSC::VM>&&, WorkerOrWorkletGlobalScope*);
     55    explicit WorkerOrWorkletScriptController(WorkerOrWorkletGlobalScope*);
    5756    ~WorkerOrWorkletScriptController();
    5857
  • trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp

    r269940 r269950  
    5353
    5454ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(const ServiceWorkerContextData& data, const WorkerParameters& params, Ref<SecurityOrigin>&& origin, ServiceWorkerThread& thread, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider)
    55     : WorkerGlobalScope(WorkerThreadType::ServiceWorker, params, WTFMove(origin), thread, WTFMove(topOrigin), connectionProxy, socketProvider)
     55    : WorkerGlobalScope(params, WTFMove(origin), thread, WTFMove(topOrigin), connectionProxy, socketProvider)
    5656    , m_contextData(crossThreadCopy(data))
    5757    , m_registration(ServiceWorkerRegistration::getOrCreate(*this, navigator().serviceWorker(), WTFMove(m_contextData.registration)))
  • trunk/Source/WebCore/worklets/WorkletGlobalScope.cpp

    r269940 r269950  
    5151
    5252WorkletGlobalScope::WorkletGlobalScope(WorkerOrWorkletThread& thread, const WorkletParameters& parameters)
    53     : WorkerOrWorkletGlobalScope(WorkerThreadType::Worklet, JSC::VM::create(), &thread)
     53    : WorkerOrWorkletGlobalScope(JSC::VM::create(), &thread)
    5454    , m_topOrigin(SecurityOrigin::createUnique())
    5555    , m_url(parameters.windowURL)
     
    6363
    6464WorkletGlobalScope::WorkletGlobalScope(Document& document, Ref<JSC::VM>&& vm, ScriptSourceCode&& code)
    65     : WorkerOrWorkletGlobalScope(WorkerThreadType::Worklet, WTFMove(vm), nullptr)
     65    : WorkerOrWorkletGlobalScope(WTFMove(vm), nullptr)
    6666    , m_document(makeWeakPtr(document))
    6767    , m_topOrigin(SecurityOrigin::createUnique())
Note: See TracChangeset for help on using the changeset viewer.