Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[browser] threads & js cleanup #86278

Merged
merged 10 commits into from
May 25, 2023
Merged

Conversation

pavelsavara
Copy link
Member

@pavelsavara pavelsavara commented May 15, 2023

This is just cleanup. There are no intended functional changes.

TimerQueue

  • renamed SetTimeout to MainThreadScheduleTimer
  • renamed ReplaceNextSetTimeout to ReplaceNextTimer
  • renamed TimeoutCallback to TimerHandler
  • renamed mono_wasm_set_timeout to mono_wasm_main_thread_schedule_timer
  • renamed mono_set_timeout_exec to mono_wasm_execute_timer
  • use [UnmanagedCallersOnly] instead of mono_runtime_try_invoke

ThreadPool

  • renamed QueueCallback to MainThreadScheduleBackgroundJob using mono_main_thread_schedule_background_job
  • renamed Callback to BackgroundJobHandler
  • use [UnmanagedCallersOnly] instead of mono_runtime_try_invoke

JSSynchronizationContext

  • dropped unused RequestPumpCallback
  • renamed ScheduleBackgroundJob to MainThreadScheduleBackgroundJob using mono_main_thread_schedule_background_job

Jobs

  • split mono_threads_schedule_background_job into mono_current_thread_schedule_background_job and mono_main_thread_schedule_background_job
  • made background job queue TLS

MT Debugger

  • I added stricter assert about usage of legacy interop with MT and could make debugger tests fail more explicitly on it because they still use bind_static_method.

Other

  • fixed assert for install_sync_context
  • fixed browser-threads-minimal to pass on Windows
  • added mono_threads_wasm_async_run_in_target_thread
  • added mono_bound_thread_schedule_background_job in preparation for next step
  • more logging in the sample
  • cleanup in legacy interop, more asserts about threads
  • moved conv_string to different file
  • removed unused _get_class_name, _get_type_name, _get_type_aqn methods
  • added named wrapper Function into mono_wasm_bind_cs_function and mono_wasm_bind_js_function only under Debug build of the runtime. It makes debugging easier because names the exported/imported function are visible on the stack trace.
  • fixed how config is applied in the worker via normalizeConfig after it arrived by message.

@pavelsavara pavelsavara added this to the 8.0.0 milestone May 15, 2023
@pavelsavara pavelsavara self-assigned this May 15, 2023
@ghost
Copy link

ghost commented May 15, 2023

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

Issue Details

null

Author: pavelsavara
Assignees: pavelsavara
Labels:

arch-wasm, area-System.Runtime.InteropServices.JavaScript

Milestone: 8.0.0

@pavelsavara
Copy link
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara
Copy link
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara
Copy link
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara
Copy link
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara
Copy link
Member Author

AOT issues are #86621

@pavelsavara pavelsavara changed the title [draft][browser] threads experiment [browser] threads cleanup May 23, 2023
@pavelsavara
Copy link
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara pavelsavara marked this pull request as ready for review May 23, 2023 16:24
@pavelsavara
Copy link
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara
Copy link
Member Author

CI failures are unrelated

Copy link
Member

@ilonatommy ilonatommy left a comment

Choose a reason for hiding this comment

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

After discussing offline: LGTM.

Copy link
Member

@ilonatommy ilonatommy left a comment

Choose a reason for hiding this comment

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

After discussing offline: LGTM.

@pavelsavara
Copy link
Member Author

@lambdageek or @kg please have yet another look and approve. I think the only part which needs your attention is change from invoke via mono reflection to invoke via [UnmanagedCallersOnly] with passing fn pointer. I think it would do the right thing about GC regions ?

@pavelsavara pavelsavara changed the title [browser] threads cleanup [browser] threads & js cleanup May 24, 2023
Copy link
Member

@lambdageek lambdageek left a comment

Choose a reason for hiding this comment

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

Mostly LGTM. A couple of nits.

Two things to consider addressing:

  1. The _DataIsAvailable delegate is there to avoid allocating a new delegate object each time
  2. The 25s delay is testing the threadpool worker timeout doesn't kill a worker that has unsettled promise. Changing to 5s changes the test.

[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void QueueCallback();
internal static extern unsafe void MainThreadScheduleBackgroundJob(void* callback);
Copy link
Member

Choose a reason for hiding this comment

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

nit: It would be nice to collect all of these internal calls that are called inside S.P.C into a single class

added comments
added missing export of _emscripten_main_runtime_thread_id
@pavelsavara
Copy link
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

add asserts and exception handlers
@pavelsavara
Copy link
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@kg
Copy link
Member

kg commented May 24, 2023

@lambdageek or @kg please have yet another look and approve. I think the only part which needs your attention is change from invoke via mono reflection to invoke via [UnmanagedCallersOnly] with passing fn pointer. I think it would do the right thing about GC regions ?

I'm not sure that invoking via UnmanagedCallersOnly will transition from one GC mode to another correctly. @lambdageek do you know?

@lambdageek
Copy link
Member

lambdageek commented May 24, 2023

I'm not sure that invoking via UnmanagedCallersOnly will transition from one GC mode to another correctly. @lambdageek do you know?

It will work correctly (unless you use CallConvSuppressGCTransition)

# Conflicts:
#	src/mono/wasm/wasm.proj
@pavelsavara pavelsavara merged commit df9ad0b into dotnet:main May 25, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jun 24, 2023
@pavelsavara pavelsavara deleted the browser_threads branch September 2, 2024 15:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants