Skip to content

[wasm] mono-aot-cross broken on OSX due to System.Threading.AutoreleasePool not found #52718

Closed

Description

@radical

This seems to have broken with 60735c6

NSAutoreleasePool instance should be added to all threads. (#52023)
Add an NSAutoreleasePool to all managed create threads including the Main and Finalizer.

This expands the current support where support was only added to ThreadPool threads. 

New feature switch was created and the ThreadPool one was removed.
 - System.Threading.Thread.EnableAutoreleasePool

Updated AutoReleaseTest for the new scenarios.

Steps to reproduce:

make -C src/mono/sample/wasm/console AOT=1 MSBUILD_ARGS="/fl /flp:v=diag /v:n"

.. fails with:

  Wasm.Console.Sample -> /Users/radical/dev/r4/src/mono/sample/wasm/console/bin/browser-wasm/publish/
  AOT'ing 7 assemblies
  Exit code: 134
/Users/radical/dev/r4/src/mono/wasm/build/WasmApp.targets(145,5): error : Precompiling failed for /Users/radical/dev/r4/src/mono/sample/wasm/console/bin/browser-wasm/publish/System.Console.dll: Error: Process returned non-zero exit code:  [/Users/radical/dev/r4/src/mono/sample/wasm/console/Wasm.Console.Sample.csproj]

Looking at the msbuild.log, mono-aot-cross is failing with:

Runtime critical type System.Threading.AutoreleasePool not found

Activity

  1. added
    arch-wasm
    on May 13, 2021
  2. ghost added
    untriaged
    on May 13, 2021
  3. radical commented on May 13, 2021

    @radical
    MemberAuthor
  4. AaronRobinsonMSFT commented on May 13, 2021

    @AaronRobinsonMSFT
    Member

    @radical Sorry about this. The failing code is at

    #if defined(HOST_DARWIN)
    mono_defaults.autoreleasepool_class = mono_class_load_from_name (
    mono_defaults.corlib, "System.Threading", "AutoreleasePool");
    #else
    mono_defaults.autoreleasepool_class = NULL;
    #endif

    Unsure how we need to deal with this. @marek-safar or @lambdageek can you offer a suggestion here?

  5. lambdageek commented on May 13, 2021

    @lambdageek
    Member

    Can either change the load method to "try load from name" and then deal with NULL at the autoreleasepool callsites, or add a && !defined(MONO_CROSS_COMPILING) to the ifdef (that might be the wrong name - sorry I'm on a phone)

  6. lambdageek commented on May 13, 2021

    @lambdageek
    Member

    "try load from" and check at callsites is probably better. @AaronRobinsonMSFT

  7. removed
    untriaged
    on May 13, 2021
  8. added this to the 6.0.0 milestone on May 13, 2021
  9. AaronRobinsonMSFT commented on May 13, 2021

    @AaronRobinsonMSFT
    Member

    @lambdageek Thanks. You've given me more than enough to try and investigate.

  10. AaronRobinsonMSFT commented on May 13, 2021

    @AaronRobinsonMSFT
    Member

    @vargaz I see your change and it is partially complete. We should also check and branch here:

    void
    mono_thread_init_from_native (void)
    {
    #if defined(HOST_DARWIN)
    MonoInternalThread* thread = mono_thread_internal_current ();
    g_assert (mono_defaults.autoreleasepool_class != NULL);
    ERROR_DECL (error);
    MONO_STATIC_POINTER_INIT (MonoMethod, create_autoreleasepool)
    create_autoreleasepool = mono_class_get_method_from_name_checked (mono_defaults.autoreleasepool_class, "CreateAutoreleasePool", 0, 0, error);
    mono_error_assert_ok (error);
    MONO_STATIC_POINTER_INIT_END (MonoMethod, create_autoreleasepool)
    mono_runtime_invoke_handle_void (create_autoreleasepool, NULL_HANDLE, NULL, error);
    mono_error_cleanup (error);
    thread->flags |= MONO_THREAD_FLAG_CLEANUP_FROM_NATIVE;
    #endif
    }

  11. added a commit that references this issue on May 13, 2021
  12. ghost added
    in-pr
    on May 14, 2021
  13. ghost removed
    in-pr
    on May 14, 2021
  14. added a commit that references this issue on May 14, 2021
  15. ghost locked as resolved and limited conversation to collaborators on Jun 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-wasmarea-System.Threading

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions