Skip to content

Commit

Permalink
[browser] mono_wasm_enable_gc and pump_count cleanup (dotnet#111198)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsavara authored Jan 9, 2025
1 parent 61b7e83 commit 442e882
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 48 deletions.
2 changes: 0 additions & 2 deletions src/mono/browser/runtime/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@
#define EMSCRIPTEN_KEEPALIVE
#endif

int mono_wasm_enable_gc = 1;

/* Missing from public headers */
char *mono_fixup_symbol_name (const char *prefix, const char *key, const char *suffix);
void mono_icall_table_init (void);
Expand Down
2 changes: 0 additions & 2 deletions src/mono/browser/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include <mono/metadata/object.h>
#include <mono/metadata/debug-helpers.h>

extern int mono_wasm_enable_gc;

MonoDomain *mono_wasm_load_runtime_common (int debug_level, MonoLogCallback log_callback, const char *interp_opts);
MonoAssembly *mono_wasm_assembly_load (const char *name);
MonoClass *mono_wasm_assembly_find_class (MonoAssembly *assembly, const char *namespace, const char *name);
Expand Down
21 changes: 9 additions & 12 deletions src/mono/browser/runtime/scheduling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Module, loaderHelpers } from "./globals";
import { forceThreadMemoryViewRefresh } from "./memory";

let spread_timers_maximum = 0;
let pump_count = 0;

export function prevent_timer_throttling (): void {
if (WasmEnableThreads) return;
Expand Down Expand Up @@ -37,7 +36,6 @@ function prevent_timer_throttling_tick () {
}
try {
cwraps.mono_wasm_execute_timer();
pump_count++;
} catch (ex) {
loaderHelpers.mono_exit(1, ex);
}
Expand All @@ -46,24 +44,24 @@ function prevent_timer_throttling_tick () {

function mono_background_exec_until_done () {
if (WasmEnableThreads) return;
lastScheduledBackground = undefined;
Module.maybeExit();
if (!loaderHelpers.is_runtime_running()) {
return;
}
try {
while (pump_count > 0) {
--pump_count;
if (!loaderHelpers.is_runtime_running()) {
return;
}
cwraps.mono_background_exec();
}
cwraps.mono_background_exec();
} catch (ex) {
loaderHelpers.mono_exit(1, ex);
}
}

let lastScheduledBackground: any = undefined;
export function schedule_background_exec (): void {
if (WasmEnableThreads) return;
++pump_count;
Module.safeSetTimeout(mono_background_exec_until_done, 0);
if (!lastScheduledBackground) {
lastScheduledBackground = Module.safeSetTimeout(mono_background_exec_until_done, 0);
}
}

let lastScheduledTimeoutId: any = undefined;
Expand All @@ -86,7 +84,6 @@ function mono_wasm_schedule_timer_tick () {
lastScheduledTimeoutId = undefined;
try {
cwraps.mono_wasm_execute_timer();
pump_count++;
} catch (ex) {
loaderHelpers.mono_exit(1, ex);
}
Expand Down
9 changes: 0 additions & 9 deletions src/mono/mono/metadata/sgen-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -2067,10 +2067,6 @@ pin_handle_stack_interior_ptrs (void **ptr_slot, void *user_data)
sgen_conservatively_pin_objects_from (ptr_slot, ptr_slot+1, ud->start_nursery, ud->end_nursery, PIN_TYPE_STACK);
}

#if defined(HOST_WASM) || defined(HOST_WASI)
extern gboolean mono_wasm_enable_gc;
#endif

/*
* Mark from thread stacks and registers.
*/
Expand All @@ -2079,11 +2075,6 @@ sgen_client_scan_thread_data (void *start_nursery, void *end_nursery, gboolean p
{
scan_area_arg_start = start_nursery;
scan_area_arg_end = end_nursery;
#if defined(HOST_WASM) || defined(HOST_WASI)
//Under WASM we don't scan thread stacks and we can't trust the values we find there either.
if (!mono_wasm_enable_gc)
return;
#endif

SGEN_TV_DECLARE (scan_thread_data_start);
SGEN_TV_DECLARE (scan_thread_data_end);
Expand Down
23 changes: 0 additions & 23 deletions src/mono/mono/sgen/sgen-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2733,32 +2733,9 @@ gc_pump_callback (void)
}
#endif

#if defined(HOST_BROWSER) || defined(HOST_WASI)
extern gboolean mono_wasm_enable_gc;
#endif

void
sgen_perform_collection (size_t requested_size, int generation_to_collect, const char *reason, gboolean forced_serial, gboolean stw)
{
#if defined(HOST_BROWSER) && defined(DISABLE_THREADS)
if (!mono_wasm_enable_gc) {
g_assert (stw); //can't handle non-stw mode (IE, domain unload)
//we ignore forced_serial

//There's a window for racing where we're executing other bg jobs before the GC, they trigger a GC request and it overrides this one.
//I belive this case to be benign as it will, in the worst case, upgrade a minor to a major collection.
if (gc_request.generation_to_collect <= generation_to_collect) {
gc_request.requested_size = requested_size;
gc_request.generation_to_collect = generation_to_collect;
gc_request.reason = reason;
sgen_client_schedule_background_job (gc_pump_callback);
}

sgen_degraded_mode = 1; //enable degraded mode so allocation can continue
return;
}
#endif

sgen_perform_collection_inner (requested_size, generation_to_collect, reason, forced_serial, stw);
}
/*
Expand Down

0 comments on commit 442e882

Please sign in to comment.