Skip to content

Commit 3632fd1

Browse files
committed
Cache the finalize method on wasm
1 parent 09a7207 commit 3632fd1

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/mono/mono/metadata/gc.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ static gboolean finalizer_thread_exited;
8181
static MonoCoopCond exited_cond;
8282

8383
static MonoInternalThread *gc_thread;
84+
85+
static MonoMethod *finalize_method;
8486
#ifndef HOST_WASM
8587
static RuntimeInvokeFunction finalize_runtime_invoke;
8688
#endif
@@ -289,11 +291,13 @@ mono_gc_run_finalize (void *obj, void *data)
289291
if (mono_log_finalizers)
290292
g_log ("mono-gc-finalizers", G_LOG_LEVEL_MESSAGE, "<%s at %p> Compiling finalizer.", o_name, o);
291293

294+
if (!finalize_method) {
295+
finalize_method = mono_class_get_method_from_name_checked (mono_defaults.object_class, "GuardedFinalize", 0, 0, error);
296+
mono_error_assert_ok (error);
297+
}
298+
292299
#ifndef HOST_WASM
293300
if (!finalize_runtime_invoke) {
294-
MonoMethod *finalize_method = mono_class_get_method_from_name_checked (mono_defaults.object_class, "GuardedFinalize", 0, 0, error);
295-
296-
mono_error_assert_ok (error);
297301
MonoMethod *invoke = mono_marshal_get_runtime_invoke_full (finalize_method, FALSE, TRUE);
298302

299303
finalize_runtime_invoke = (RuntimeInvokeFunction)mono_compile_method_checked (invoke, error);
@@ -317,12 +321,9 @@ mono_gc_run_finalize (void *obj, void *data)
317321
MONO_PROFILER_RAISE (gc_finalizing_object, (o));
318322

319323
#ifdef HOST_WASM
320-
MonoMethod* finalizer = mono_class_get_method_from_name_checked (mono_defaults.object_class, "GuardedFinalize", 0, 0, error);
321-
if (finalizer) { // null finalizers work fine when using the vcall invoke as Object has an empty one
322-
gpointer params [1];
323-
params [0] = NULL;
324-
mono_runtime_try_invoke (finalizer, o, params, &exc, error);
325-
}
324+
gpointer params [1];
325+
params [0] = NULL;
326+
mono_runtime_try_invoke (finalize_method, o, params, &exc, error);
326327
#else
327328
runtime_invoke (o, NULL, &exc, NULL);
328329
#endif

src/tests/issues.targets

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1732,8 +1732,11 @@
17321732
<ExcludeList Include="$(XunitTestBinBase)/JIT/opt/Structs/MemsetMemcpyNullref/*">
17331733
<Issue>https://github.com/dotnet/runtime/issues/98628</Issue>
17341734
</ExcludeList>
1735+
<ExcludeList Include="$(XunitTestBinBase)/baseservices/exceptions/UnhandledExceptionHandler/HandlerThrows/*">
1736+
<Issue>https://github.com/dotnet/runtime/issues/47624</Issue>
1737+
</ExcludeList>
17351738
<ExcludeList Include="$(XunitTestBinBase)/baseservices/exceptions/UnhandledExceptionHandler/NoEffectInMainThread/*">
1736-
<Issue>Test issue. The test relies on overriding the process return code.</Issue>
1739+
<Issue>Test issue. The test relies on overriding the process return code.</Issue>
17371740
</ExcludeList>
17381741
</ItemGroup>
17391742

0 commit comments

Comments
 (0)