Skip to content

Use mono_runtime_invoke to invoke finalizers. #1316

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

Merged
merged 2 commits into from
Jul 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 10 additions & 31 deletions mono/metadata/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,25 +327,6 @@ mono_gc_run_finalize (void *obj, void *data)
return;
}

/*
* To avoid the locking plus the other overhead of mono_runtime_invoke_checked (),
* create and precompile a wrapper which calls the finalize method using
* a CALLVIRT.
*/
if (log_finalizers)
g_log ("mono-gc-finalizers", G_LOG_LEVEL_MESSAGE, "<%s at %p> Compiling finalizer.", o->vtable->klass->name, o);

#ifndef HOST_WASM
if (!domain->finalize_runtime_invoke) {
MonoMethod *invoke = mono_marshal_get_runtime_invoke (mono_class_get_method_from_name_flags (mono_defaults.object_class, "Finalize", 0, 0), TRUE);

domain->finalize_runtime_invoke = mono_compile_method_checked (invoke, &error);
mono_error_assert_ok (&error); /* expect this not to fail */
}

RuntimeInvokeFunction runtime_invoke = (RuntimeInvokeFunction)domain->finalize_runtime_invoke;
#endif

mono_runtime_class_init_full (o->vtable, &error);
goto_if_nok (&error, unhandled_error);

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

if (log_finalizers)
g_log ("mono-gc-finalizers", G_LOG_LEVEL_MESSAGE, "<%s at %p> Calling finalizer.", o->vtable->klass->name, o);
if (finalizer) {
if (log_finalizers)
g_log ("mono-gc-finalizers", G_LOG_LEVEL_MESSAGE, "<%s at %p> Calling finalizer.", o->vtable->klass->name, o);

MONO_PROFILER_RAISE (gc_finalizing_object, (o));
MONO_PROFILER_RAISE (gc_finalizing_object, (o));

#ifdef HOST_WASM
gpointer params[] = { NULL };
mono_runtime_try_invoke (finalizer, o, params, &exc, &error);
#else
runtime_invoke (o, NULL, &exc, NULL);
#endif
gpointer params[] = { NULL };
mono_runtime_try_invoke (finalizer, o, params, &exc, &error);

MONO_PROFILER_RAISE (gc_finalized_object, (o));
MONO_PROFILER_RAISE (gc_finalized_object, (o));

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

unhandled_error:
if (!is_ok (&error))
Expand Down