Skip to content

[browser] Turn the >2GB memory test into an interop conformance test#131360

Open
lewing wants to merge 1 commit into
mainfrom
lewing-psychic-robot
Open

[browser] Turn the >2GB memory test into an interop conformance test#131360
lewing wants to merge 1 commit into
mainfrom
lewing-psychic-robot

Conversation

@lewing

@lewing lewing commented Jul 25, 2026

Copy link
Copy Markdown
Member

Rewrites the AllocateLargeHeapThenInterop scenario into an actual conformance test for interop above the 2GB boundary.

Why

The wasm/JS boundary does not preserve signedness. A wasm i32 arrives in JavaScript as a signed number, so every pointer above 2GB shows up negative. The failure modes are mostly silent — a negative subarray start is clamped relative to the end of the heap, a negative HEAPU8 index yields undefined — so a scenario that only checks "a string JSImport still returns the right length" cannot detect them.

What

The scenario now asserts data integrity across the interop surface while every runtime allocation lives above 2GB:

  • strings (short, non-ASCII, and a 1M char one), byte[] / int[] / double[] in both directions
  • Span<byte> and ArraySegment<byte> memory views
  • JSObject properties, exception propagation, Task<int>
  • the JSExport direction (JS calling into managed with byte[]/string payloads)
  • RandomNumberGenerator.Fill and globalization

It also reports the address of a pinned buffer and fails if allocations did not actually land above 2GB, so the test cannot silently stop testing what it is named after. The MemoryTests WBT additionally asserts that the run produced no jiterpreter code generation failed messages, which is how invalid pointer encoding surfaces in the trace compiler.

Validation

Ran the same test app against the shipped runtime packs with EmccMaximumHeapSize=4294901760 and 2.2GB / 3.6GB of heap wasted before startup:

runtime pack result
11.0.0-preview.6 @ 2.2GB and 3.6GB all checks pass, no jiterpreter errors
10.0.9 @ 2.2GB RandomNumberGenerator.Fill silently returns an all-zero buffer; jiterpreter logs code generation failed: CompileError … extra bits in varint

So the new assertions catch the pre-#121221 behaviour rather than just passing everywhere.

Note

This pull request was authored with GitHub Copilot.

The wasm/JS boundary does not preserve signedness: a wasm i32 arrives in
JavaScript as a signed number, so every pointer above 2GB shows up negative.
Missing coercions mostly corrupt data silently (a negative subarray start is
clamped relative to the end of the heap) rather than throwing, so the previous
scenario - which only checked that a string JSImport kept working - could not
detect them.

Exercise the interop surface with data integrity assertions while all runtime
allocations live above the 2GB boundary: strings, byte[]/int[]/double[] in both
directions, memory views, JSObject, exceptions, promises, the JSExport
direction, crypto and globalization. Also assert that the jiterpreter does not
report code generation failures, which is how invalid pointer encoding shows up
in the trace compiler.

Verified against 10.0.9 and 11.0.0-preview.6 runtime packs with 2.2GB and 3.6GB
of heap wasted before startup: 10.0.9 fails the crypto check (the buffer stays
zeroed) and logs jiterpreter code generation failures, 11.0 passes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8b51d9f7-816f-483e-b4cc-ec6e2dc45a6a
Copilot AI review requested due to automatic review settings July 25, 2026 01:24
@lewing
lewing requested review from ilonatommy and maraf as code owners July 25, 2026 01:24
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@lewing
lewing requested a review from pavelsavara July 25, 2026 01:26
@lewing lewing added arch-wasm WebAssembly architecture os-browser Browser variant of arch-wasm labels Jul 25, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

@lewing lewing changed the title [browser] Turn the &gt;2GB memory test into an interop conformance test [browser] Turn the >2GB memory test into an interop conformance test Jul 25, 2026

Copilot AI 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.

Pull request overview

This PR strengthens the existing “>2GB heap” wasm scenario by turning it into a more comprehensive interop conformance test, exercising multiple managed↔JS marshalling paths while allocations are intended to occur above the 2GB boundary.

Changes:

  • Extend the WasmBasicTestApp MemoryTest scenario into an async test suite covering strings, arrays, memory views, JSObject interaction, exceptions, tasks, RNG, and globalization.
  • Add richer JS-side imports/exports in main.js for validating both JSImport and JSExport integrity.
  • Update the build test to assert the scenario actually completed successfully and that no jiterpreter “code generation failed” messages appeared.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/mono/wasm/Wasm.Build.Tests/MemoryTests.cs Validates the scenario ran to completion and checks console output for jiterpreter compilation failures.
src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js Expands module imports and adds JS-driven calls into managed exports for additional coverage.
src/mono/wasm/testassets/WasmBasicTestApp/App/MemoryTest.cs Rewrites the scenario into a multi-check conformance suite (including new JSExport surface for the test).

Comment on lines 139 to 142
try
{
arrayHolder[i] = new int[1024 * 1024 * 25];
}
@lewing
lewing requested a review from radekdoulik July 25, 2026 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-VM-meta-mono os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants