Skip to content

Conversation

@AaronRobinsonMSFT
Copy link
Member

@AaronRobinsonMSFT AaronRobinsonMSFT commented Sep 8, 2025

Implement array allocators for WASM.

Calling empty Main() works for corerun. Steps:

  1. Build coreclr and libs for browser
    • ./build.sh -os browser -c Debug -subset clr.runtime+libs
    • It is okay if the "libs" build fails. We just need System.Runtime.dll to build.
  2. Copy over System.Runtime.dll to the IL location containing System.Private.CoreLib.dll
  3. Build a simple C# application:
    public static class Program
    {
        public static void Main() { }
    }
  4. Copy the simple C# application to the IL location. It should now have System.Private.CoreLib.dll, System.Runtime.dll and <app>.dll.

Additional changes to get to where we need to execute
an unmanaged FCall implementation.
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

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 implements essential array allocation functionality for WebAssembly (WASM) to enable empty Main() method execution in corerun. The implementation provides basic memory allocation, method invocation infrastructure, and interpreter support necessary for minimal CLR functionality on WASM.

Key changes include:

  • Implementation of array allocation helpers (RhpNewArrayFast, RhNewString) to support basic object creation
  • Addition of managed method invocation support through portable entry points and call stubs
  • Updates to method compilation and invocation infrastructure for WASM interpreter compatibility

Reviewed Changes

Copilot reviewed 22 out of 23 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/coreclr/vm/wasm/helpers.cpp Implements calli stubs and managed method invocation for WASM interpreter
src/coreclr/vm/threads.cpp Fixes preprocessor directive placement for portable helpers
src/coreclr/vm/runtimehandles.cpp Adds null check assertion for type handle validation
src/coreclr/vm/prestub.cpp Enhances FCall handling with portable entry point support and managed implementation detection
src/coreclr/vm/precode_portable.hpp Adds method for creating portable entry points from native code
src/coreclr/vm/precode_portable.cpp Implements portable entry point creation and code address management
src/coreclr/vm/portable/AllocSlow.cpp Adds allocation failure handler stub
src/coreclr/vm/object.h Adds SetNumComponents method and removes unused friend declarations
src/coreclr/vm/method.cpp Refactors code entry point setting logic for portable entry points
src/coreclr/vm/jitinterface.cpp Optimizes helper function entry point creation and caching
src/coreclr/vm/gchelpers.cpp Updates array allocation to use new SetNumComponents method
src/coreclr/vm/gcheaputilities.h Refactors allocation context methods for better encapsulation
src/coreclr/vm/finalizerthread.h Moves RaiseShutdownEvents implementation to source file
src/coreclr/vm/finalizerthread.cpp Implements RaiseShutdownEvents with WASM-specific handling
src/coreclr/vm/ecall.h Adds optional output parameter for managed implementation detection
src/coreclr/vm/ecall.cpp Enhances FCall implementation detection and managed constructor handling
src/coreclr/vm/callstubgenerator.cpp Fixes variable shadowing in call stub generation
src/coreclr/runtime/portable/AllocFast.cpp Implements fast array and string allocation with allocation context management
src/coreclr/nativeaot/Runtime/portable.cpp Updates NativeAOT allocation helpers to use consistent method names
src/coreclr/nativeaot/Runtime/ObjectLayout.h Standardizes method naming for array initialization
src/coreclr/nativeaot/Runtime/ObjectLayout.cpp Updates method implementation to match new naming convention
src/coreclr/nativeaot/Runtime/GCHelpers.cpp Updates allocation helper to use SetMethodTable naming

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thank you!

pavelsavara and others added 3 commits September 9, 2025 09:50
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@pavelsavara
Copy link
Member

I tested it and it works 🎉

@jkotas
Copy link
Member

jkotas commented Sep 9, 2025

Revert "Update src/coreclr/vm/jitinterface.cpp"

This hit a buggy path discussed in #119355 (comment) . I have reapplied the feedback with additional fix.

Copy link
Member

@radekdoulik radekdoulik left a comment

Choose a reason for hiding this comment

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

LGTM, I will address the remaining feedback on caching cookie in another PR

@AaronRobinsonMSFT
Copy link
Member Author

Revert "Update src/coreclr/vm/jitinterface.cpp"

This hit a buggy path discussed in #119355 (comment) . I have reapplied the feedback with additional fix.

FYI @kotlarmilos

@AaronRobinsonMSFT AaronRobinsonMSFT enabled auto-merge (squash) September 9, 2025 15:12
@AaronRobinsonMSFT AaronRobinsonMSFT merged commit 51ff53f into dotnet:main Sep 9, 2025
99 checks passed
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the array_alloc branch September 9, 2025 15:28
@github-actions github-actions bot locked and limited conversation to collaborators Oct 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasm WebAssembly architecture area-VM-coreclr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants