Skip to content

Commit a1b76c5

Browse files
Merge pull request #1316 from Unity-Technologies/macos-arm64-finalizer-fix-2
Use mono_runtime_invoke to invoke finalizers.
2 parents 018fee6 + 1ad3768 commit a1b76c5

File tree

1 file changed

+10
-31
lines changed

1 file changed

+10
-31
lines changed

mono/metadata/gc.c

+10-31
Original file line numberDiff line numberDiff line change
@@ -327,25 +327,6 @@ mono_gc_run_finalize (void *obj, void *data)
327327
return;
328328
}
329329

330-
/*
331-
* To avoid the locking plus the other overhead of mono_runtime_invoke_checked (),
332-
* create and precompile a wrapper which calls the finalize method using
333-
* a CALLVIRT.
334-
*/
335-
if (log_finalizers)
336-
g_log ("mono-gc-finalizers", G_LOG_LEVEL_MESSAGE, "<%s at %p> Compiling finalizer.", o->vtable->klass->name, o);
337-
338-
#ifndef HOST_WASM
339-
if (!domain->finalize_runtime_invoke) {
340-
MonoMethod *invoke = mono_marshal_get_runtime_invoke (mono_class_get_method_from_name_flags (mono_defaults.object_class, "Finalize", 0, 0), TRUE);
341-
342-
domain->finalize_runtime_invoke = mono_compile_method_checked (invoke, &error);
343-
mono_error_assert_ok (&error); /* expect this not to fail */
344-
}
345-
346-
RuntimeInvokeFunction runtime_invoke = (RuntimeInvokeFunction)domain->finalize_runtime_invoke;
347-
#endif
348-
349330
mono_runtime_class_init_full (o->vtable, &error);
350331
goto_if_nok (&error, unhandled_error);
351332

@@ -354,22 +335,20 @@ mono_gc_run_finalize (void *obj, void *data)
354335
o->vtable->klass->name_space, o->vtable->klass->name);
355336
}
356337

357-
if (log_finalizers)
358-
g_log ("mono-gc-finalizers", G_LOG_LEVEL_MESSAGE, "<%s at %p> Calling finalizer.", o->vtable->klass->name, o);
338+
if (finalizer) {
339+
if (log_finalizers)
340+
g_log ("mono-gc-finalizers", G_LOG_LEVEL_MESSAGE, "<%s at %p> Calling finalizer.", o->vtable->klass->name, o);
359341

360-
MONO_PROFILER_RAISE (gc_finalizing_object, (o));
342+
MONO_PROFILER_RAISE (gc_finalizing_object, (o));
361343

362-
#ifdef HOST_WASM
363-
gpointer params[] = { NULL };
364-
mono_runtime_try_invoke (finalizer, o, params, &exc, &error);
365-
#else
366-
runtime_invoke (o, NULL, &exc, NULL);
367-
#endif
344+
gpointer params[] = { NULL };
345+
mono_runtime_try_invoke (finalizer, o, params, &exc, &error);
368346

369-
MONO_PROFILER_RAISE (gc_finalized_object, (o));
347+
MONO_PROFILER_RAISE (gc_finalized_object, (o));
370348

371-
if (log_finalizers)
372-
g_log ("mono-gc-finalizers", G_LOG_LEVEL_MESSAGE, "<%s at %p> Returned from finalizer.", o->vtable->klass->name, o);
349+
if (log_finalizers)
350+
g_log ("mono-gc-finalizers", G_LOG_LEVEL_MESSAGE, "<%s at %p> Returned from finalizer.", o->vtable->klass->name, o);
351+
}
373352

374353
unhandled_error:
375354
if (!is_ok (&error))

0 commit comments

Comments
 (0)