Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

.NET Notes #77

Open
Open
@vargaz

Description

@vargaz

I was asked to add some notes based on the needs of Microsoft .NET implementations wrt GC in WebAssembly.

  1. Object layout
    .NET objects in memory usually consist of a header followed by object data. The header contains data
    such as:
  • the vtable/type pointer
  • a sync word for locking on the object
  • a length field for arrays/strings
  • for multi-dimensional arrays, a pointer to a struct describing the dimensions.

The type system of the current proposal doesn't seem to be able to support this layout, i.e. a header followed by array data. Also, .NET supports arrays of structs, i.e. an array of {ref,non-ref} would
look like in memory: [ref, non-ref, ref, non-ref, etc.].

In general, it seems very difficult to model all possible object layouts used by GCd languages.

  1. Interior pointers
    In .NET, its quite common to have pointers into the middle of objects (arrays), and pointers to one past
    the end of an array. anyref doesn't seem to be able to support this.

  2. Interop with C/C++ code
    The .net runtimes are written in C/C++ and assume that object references are normal C pointers which
    point to linear memory, and objects can be accessed from C code as a pointers to C structs. The current
    proposal places allocated objects outside linear memory and adds new accessors to read/write their
    contents. To allow manipulation of these objects from C code would require extensions to the C compilers.

  3. Finalization
    The .net runtime needs to be notified somehow when an object with a finalizer dies.

  4. Weak references
    .net supports multiple kinds of weak references which might not be supported by the underlying JS GC.

  5. Non web runtimes
    Non-web runtimes would need to add a GC implementation, since GC is such a core feature that it
    probably cannot be treated as an optional feature like SIMD.

  6. LLVM support
    The new types/type constructs don't exist in LLVM, not clear how they can be added.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions