Skip to content

Add support for Memory64 in WebAssembly in IPInt Tier - #52155

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
colelao:eng/Add-support-for-Memory64-in-WebAssembly-in-IPInt-Tier
Dec 7, 2025
Merged

webkit-commit-queue merged 1 commit into
WebKit:mainfrom
colelao:eng/Add-support-for-Memory64-in-WebAssembly-in-IPInt-Tier

Conversation

@colelao

@colelao colelao commented Oct 11, 2025 •

Copy link
Copy Markdown
Contributor

26868df

Add support for Memory64 in WebAssembly in IPInt Tier
https://bugs.webkit.org/show_bug.cgi?id=300539
rdar://162406385

Reviewed by Keith Miller.

This patch allows the WasmFunctionParser to accept 64 bit pointers while performing
memory operations. This includes all the load and store operations, the bulk memory
operations, and the size and grow operations.

Test: JSTests/wasm/stress/load-and-store-with-64-bit-address.js

* JSTests/wasm/stress/memory64-bulk-memory.js: Added.
(async test):
* JSTests/wasm/stress/memory64-grow-and-size.js: Added.
(async test):
(async testGrowByZero):
(async testNoMaximum):
(async testLargeGrowValue):
* JSTests/wasm/stress/memory64-load-and-store.js: Added.
(getWasmTypeWidth):
(let.wat.module):
(join):
(async test):
* Source/JavaScriptCore/llint/InPlaceInterpreter64.asm:
* Source/JavaScriptCore/runtime/OptionsList.h:
* Source/JavaScriptCore/wasm/WasmFunctionIPIntMetadataGenerator.cpp:
(JSC::Wasm::FunctionIPIntMetadataGenerator::addLEB128ConstantInt64AndLength):
* Source/JavaScriptCore/wasm/WasmFunctionIPIntMetadataGenerator.h:
* Source/JavaScriptCore/wasm/WasmFunctionParser.h:
(JSC::Wasm::FunctionParser<Context>::load):
(JSC::Wasm::FunctionParser<Context>::store):
(JSC::Wasm::FunctionParser<Context>::parseExpression):
(JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression):
* Source/JavaScriptCore/wasm/WasmIPIntGenerator.cpp:
(JSC::Wasm::IPIntGenerator::load):
(JSC::Wasm::IPIntGenerator::store):
* Source/JavaScriptCore/wasm/WasmIPIntSlowPaths.cpp:
(JSC::IPInt::WASM_IPINT_EXTERN_CPP_DECL):
* Source/JavaScriptCore/wasm/WasmIPIntSlowPaths.h:
* Source/JavaScriptCore/wasm/WasmMemory.cpp:
(JSC::Wasm::Memory::init):
* Source/JavaScriptCore/wasm/WasmMemory.h:
* Source/JavaScriptCore/wasm/WasmMemoryInformation.cpp:
(JSC::Wasm::MemoryInformation::MemoryInformation):
* Source/JavaScriptCore/wasm/WasmMemoryInformation.h:
(JSC::Wasm::MemoryInformation::isMemory64 const):
* Source/JavaScriptCore/wasm/WasmOperationsInlines.h:
(JSC::Wasm::memoryInit):
* Source/JavaScriptCore/wasm/WasmSectionParser.cpp:
(JSC::Wasm::limitsFlagIsValid):
(JSC::Wasm::SectionParser::parseResizableLimits):
(JSC::Wasm::SectionParser::parseTableHelper):
(JSC::Wasm::SectionParser::parseMemoryHelper):
* Source/JavaScriptCore/wasm/WasmSectionParser.h:
* Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp:
(JSC::JSWebAssemblyInstance::memoryInit):
* Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h:

Canonical link: https://commits.webkit.org/304075@main

7041740

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ⏳ 🛠 ios-apple
✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ✅ 🧪 win-tests ⏳ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe ⏳ 🛠 vision-apple
✅ 🧪 ios-wk2-wpt ✅ 🧪 api-mac-debug loading 🛠 wpe-cairo-libwebrtc
✅ 🛠 🧪 jsc ✅ 🧪 api-ios ✅ 🧪 mac-wk1 ✅ 🛠 gtk
✅ 🛠 🧪 jsc-arm64 ✅ 🛠 vision ✅ 🧪 mac-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-wk2-stress ✅ 🛠 playstation
✅ 🛠 tv ✅ 🧪 mac-intel-wk2 ✅ 🛠 jsc-armv7
✅ 🛠 tv-sim ✅ 🛠 mac-safer-cpp ✅ 🧪 jsc-armv7-tests
✅ 🛠 watch
✅ 🛠 watch-sim

@colelao
colelao requested a review from a team as a code owner October 11, 2025 01:08
@colelao colelao self-assigned this Oct 11, 2025
@colelao colelao added the WebAssembly For bugs in JavaScript WebAssembly label Oct 11, 2025
@colelao
colelao marked this pull request as draft October 11, 2025 01:09
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Oct 11, 2025

@Constellation Constellation left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that memory64 requires a lot of compiler work.

  1. You need to make wasm bound checking compiler code work for memory64
  2. Bound checking code has various optimizations in B3 compiler as well. So you need to update and/or add new optimizations to allow B3 compiler to remove these checks when possible.
  3. You need to ensure that fast memory is not used for memory64 since page fault based handling does not work
  4. You need to change wasm address calculation code for memory64 in all tiers since they have strong assumption that input is 32bit

@colelao colelao removed the merging-blocked Applied to prevent a change from being merged label Oct 29, 2025
@colelao
colelao force-pushed the eng/Add-support-for-Memory64-in-WebAssembly-in-IPInt-Tier branch from 5673b2b to ddf4911 Compare October 29, 2025 18:54
@colelao
colelao force-pushed the eng/Add-support-for-Memory64-in-WebAssembly-in-IPInt-Tier branch from ddf4911 to 68a4577 Compare October 29, 2025 19:07
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Oct 29, 2025
@colelao colelao added skip-ews Applied to prevent a change from being run on EWS and removed merging-blocked Applied to prevent a change from being merged skip-ews Applied to prevent a change from being run on EWS labels Oct 31, 2025
@colelao
colelao force-pushed the eng/Add-support-for-Memory64-in-WebAssembly-in-IPInt-Tier branch from 68a4577 to 10b4aa5 Compare November 3, 2025 19:41
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Nov 3, 2025
@colelao colelao removed the merging-blocked Applied to prevent a change from being merged label Nov 12, 2025
@colelao
colelao force-pushed the eng/Add-support-for-Memory64-in-WebAssembly-in-IPInt-Tier branch from 10b4aa5 to b0b7f9e Compare November 12, 2025 00:11
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Nov 12, 2025
@colelao colelao removed the merging-blocked Applied to prevent a change from being merged label Dec 3, 2025
@colelao
colelao force-pushed the eng/Add-support-for-Memory64-in-WebAssembly-in-IPInt-Tier branch from b0b7f9e to 3712a5c Compare December 3, 2025 02:00
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Dec 3, 2025
@colelao colelao removed the merging-blocked Applied to prevent a change from being merged label Dec 3, 2025
@colelao
colelao force-pushed the eng/Add-support-for-Memory64-in-WebAssembly-in-IPInt-Tier branch from 3712a5c to 5497b4e Compare December 3, 2025 19:59
@colelao
colelao force-pushed the eng/Add-support-for-Memory64-in-WebAssembly-in-IPInt-Tier branch from 5497b4e to 92c2f24 Compare December 3, 2025 20:21
@colelao
colelao marked this pull request as ready for review December 3, 2025 21:03

@Constellation Constellation left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to disable this via Options since it is not having BBQ and OMG.

@colelao
colelao force-pushed the eng/Add-support-for-Memory64-in-WebAssembly-in-IPInt-Tier branch from 92c2f24 to b78edc8 Compare December 4, 2025 02:45
@colelao
colelao requested a review from Constellation December 4, 2025 02:46
ipintOp(_i32_load_mem, macro()
# i32.load
# pop index
popMemoryIndex(t0, t2)
loadi IPInt::Const32Metadata::value[MC], t2
loadMemoryOffsetAndAdvanceMC(t2, t3, t4)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation looks wonky; maybe tabs vs. spaces IDE thing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks

@colelao
colelao force-pushed the eng/Add-support-for-Memory64-in-WebAssembly-in-IPInt-Tier branch from b78edc8 to e726370 Compare December 4, 2025 02:54
@@ -658,6 +658,7 @@ bool hasCapacityToUseLargeGigacage();
v(Bool, useWasmSIMD, true, Normal, "Allow the new simd instructions and types from the wasm simd spec."_s) \
v(Bool, useWasmRelaxedSIMD, false, Normal, "Allow the relaxed simd instructions and types from the wasm relaxed simd spec."_s) \
v(Bool, useWasmTailCalls, true, Normal, "Allow the new instructions from the wasm tail calls spec."_s) \
v(Bool, useWasmMemory64, false, Normal, "Allow the Memory64 proposal for WebAssembly. This feature is currently only supported in the IPInt tier."_s) \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by comment: let's keep these sorted alphabetically for ease of future maintenance.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 'n done!

{
WASM_RETURN_TWO(reinterpret_cast<void*>(Wasm::growMemory(instance, delta)), 0);
}

WASM_IPINT_EXTERN_CPP_DECL(memory_init, int32_t dataIndex, IPIntStackEntry* sp)
WASM_IPINT_EXTERN_CPP_DECL(memory_init, int64_t dataIndex, IPIntStackEntry* sp)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does dataIndex need to be widened to int64_t? The proposal maintains dataidx as a u32, and downstream logic in Wasm::memoryInit() is unchanged.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I updated it!

@colelao
colelao force-pushed the eng/Add-support-for-Memory64-in-WebAssembly-in-IPInt-Tier branch from e726370 to 6cf5981 Compare December 4, 2025 20:03
@colelao
colelao force-pushed the eng/Add-support-for-Memory64-in-WebAssembly-in-IPInt-Tier branch from 6cf5981 to aba3343 Compare December 4, 2025 20:05
@colelao
colelao force-pushed the eng/Add-support-for-Memory64-in-WebAssembly-in-IPInt-Tier branch from aba3343 to 23b2bd5 Compare December 4, 2025 21:08

@kmiller68 kmiller68 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me with some comments.

loadb JSWebAssemblyInstance::m_cachedIsMemory64[wasmInstance], tmpReg
btiz tmpReg, .memory32
loadq IPInt::Const64Metadata::value[MC], dstReg
loadb IPInt::Const64Metadata::instructionLength[MC], instrLenReg

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing seems off on this line?

jmp .done
.memory32:
loadi IPInt::Const32Metadata::value[MC], dstReg
loadb IPInt::Const32Metadata::instructionLength[MC], instrLenReg

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

bool isShared = false;
PartialResult limits = parseResizableLimits(initial, maximum, isShared, LimitsType::Table);
bool isTable64;
PartialResult limits = parseResizableLimits<LimitsType::Table>(initial, maximum, isShared, isTable64);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an ASSERT(!isShared);

if (!limits) [[unlikely]]
return makeUnexpected(WTFMove(limits.error()));
WASM_PARSER_FAIL_IF(isShared && !maximum, "shared memory must have a maximum size"_s);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep this in parseResizableLimits since when wasm inevitably adds shared tables this requirement will be required there too.

Comment thread JSTests/wasm/memory64/bulk-memory.js Outdated
@@ -0,0 +1,63 @@
//@ skip if $addressBits <= 32
//@ runDefaultWasm("-m", "--useJIT=0", "--useWasmMemory64=1")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: These could be --useBBQJIT=0 for slightly more coverage.

@colelao
colelao force-pushed the eng/Add-support-for-Memory64-in-WebAssembly-in-IPInt-Tier branch from 23b2bd5 to 7041740 Compare December 5, 2025 19:36
@colelao colelao added safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks merge-queue Applied to send a pull request to merge-queue and removed safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks labels Dec 5, 2025
https://bugs.webkit.org/show_bug.cgi?id=300539
rdar://162406385

Reviewed by Keith Miller.

This patch allows the WasmFunctionParser to accept 64 bit pointers while performing
memory operations. This includes all the load and store operations, the bulk memory
operations, and the size and grow operations.

Test: JSTests/wasm/stress/load-and-store-with-64-bit-address.js

* JSTests/wasm/stress/memory64-bulk-memory.js: Added.
(async test):
* JSTests/wasm/stress/memory64-grow-and-size.js: Added.
(async test):
(async testGrowByZero):
(async testNoMaximum):
(async testLargeGrowValue):
* JSTests/wasm/stress/memory64-load-and-store.js: Added.
(getWasmTypeWidth):
(let.wat.module):
(join):
(async test):
* Source/JavaScriptCore/llint/InPlaceInterpreter64.asm:
* Source/JavaScriptCore/runtime/OptionsList.h:
* Source/JavaScriptCore/wasm/WasmFunctionIPIntMetadataGenerator.cpp:
(JSC::Wasm::FunctionIPIntMetadataGenerator::addLEB128ConstantInt64AndLength):
* Source/JavaScriptCore/wasm/WasmFunctionIPIntMetadataGenerator.h:
* Source/JavaScriptCore/wasm/WasmFunctionParser.h:
(JSC::Wasm::FunctionParser<Context>::load):
(JSC::Wasm::FunctionParser<Context>::store):
(JSC::Wasm::FunctionParser<Context>::parseExpression):
(JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression):
* Source/JavaScriptCore/wasm/WasmIPIntGenerator.cpp:
(JSC::Wasm::IPIntGenerator::load):
(JSC::Wasm::IPIntGenerator::store):
* Source/JavaScriptCore/wasm/WasmIPIntSlowPaths.cpp:
(JSC::IPInt::WASM_IPINT_EXTERN_CPP_DECL):
* Source/JavaScriptCore/wasm/WasmIPIntSlowPaths.h:
* Source/JavaScriptCore/wasm/WasmMemory.cpp:
(JSC::Wasm::Memory::init):
* Source/JavaScriptCore/wasm/WasmMemory.h:
* Source/JavaScriptCore/wasm/WasmMemoryInformation.cpp:
(JSC::Wasm::MemoryInformation::MemoryInformation):
* Source/JavaScriptCore/wasm/WasmMemoryInformation.h:
(JSC::Wasm::MemoryInformation::isMemory64 const):
* Source/JavaScriptCore/wasm/WasmOperationsInlines.h:
(JSC::Wasm::memoryInit):
* Source/JavaScriptCore/wasm/WasmSectionParser.cpp:
(JSC::Wasm::limitsFlagIsValid):
(JSC::Wasm::SectionParser::parseResizableLimits):
(JSC::Wasm::SectionParser::parseTableHelper):
(JSC::Wasm::SectionParser::parseMemoryHelper):
* Source/JavaScriptCore/wasm/WasmSectionParser.h:
* Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp:
(JSC::JSWebAssemblyInstance::memoryInit):
* Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h:

Canonical link: https://commits.webkit.org/304075@main
@webkit-commit-queue
webkit-commit-queue force-pushed the eng/Add-support-for-Memory64-in-WebAssembly-in-IPInt-Tier branch from 7041740 to 26868df Compare December 7, 2025 17:27
@webkit-commit-queue

Copy link
Copy Markdown
Collaborator

Committed 304075@main (26868df): https://commits.webkit.org/304075@main

Reviewed commits have been landed. Closing PR #52155 and removing active labels.

@webkit-commit-queue
webkit-commit-queue merged commit 26868df into WebKit:main Dec 7, 2025
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WebAssembly For bugs in JavaScript WebAssembly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants