Skip to content

Don't use mono_gc_is_moving for incremental gc #1228

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 3 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion mono/metadata/boehm-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1576,9 +1576,15 @@ mono_gc_set_desktop_mode (void)

gboolean
mono_gc_is_moving (void)
{
return FALSE;
}

gboolean
mono_gc_needs_write_barriers(void)
{
#if HAVE_BDWGC_GC
return GC_is_incremental_mode ();
return GC_is_incremental_mode();
#else
return FALSE;
#endif
Expand Down
2 changes: 0 additions & 2 deletions mono/metadata/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1252,12 +1252,10 @@ mono_domain_free (MonoDomain *domain, gboolean force)

domain->setup = NULL;

#if !HAVE_BDWGC_GC
// This crashes in bdwgc because we never register such a root.
// Not sure why/how it works in sgen, or if it is needed?
if (mono_gc_is_moving ())
mono_gc_deregister_root ((char*)&(domain->MONO_DOMAIN_FIRST_GC_TRACKED));
#endif

mono_appdomains_lock ();
appdomains_list [domain->domain_id] = NULL;
Expand Down
7 changes: 6 additions & 1 deletion mono/metadata/gc-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
} while (0)

/* useful until we keep track of gc-references in corlib etc. */
#define IS_GC_REFERENCE(class,t) (mono_gc_is_moving () ? FALSE : ((t)->type == MONO_TYPE_U && (class)->image == mono_defaults.corlib))
#define IS_GC_REFERENCE(class,t) (mono_gc_needs_write_barriers() ? FALSE : ((t)->type == MONO_TYPE_U && (class)->image == mono_defaults.corlib))

void mono_object_register_finalizer (MonoObject *obj);
void ves_icall_System_GC_InternalCollect (int generation);
Expand Down Expand Up @@ -280,6 +280,11 @@ void mono_gc_set_desktop_mode (void);
*/
gboolean mono_gc_is_moving (void);

/*
* Return whenever this GC needs write barriers
*/
gboolean mono_gc_needs_write_barriers (void);

typedef void* (*MonoGCLockedCallbackFunc) (void *data);

void* mono_gc_invoke_with_gc_lock (MonoGCLockedCallbackFunc func, void *data);
Expand Down
6 changes: 6 additions & 0 deletions mono/metadata/null-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ mono_gc_is_moving (void)
return FALSE;
}

gboolean
mono_gc_needs_write_barriers(void)
{
return FALSE;
}

gboolean
mono_gc_is_disabled (void)
{
Expand Down
4 changes: 2 additions & 2 deletions mono/metadata/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -5703,7 +5703,7 @@ mono_array_full_copy (MonoArray *src, MonoArray *dest)
static void
array_full_copy_unchecked_size (MonoArray *src, MonoArray *dest, MonoClass *klass, uintptr_t size)
{
if (mono_gc_is_moving ()) {
if (mono_gc_needs_write_barriers()) {
if (klass->element_class->valuetype) {
if (klass->element_class->has_references)
mono_value_copy_array (dest, 0, mono_array_addr_with_size_fast (src, 0, 0), mono_array_length (src));
Expand Down Expand Up @@ -6447,7 +6447,7 @@ mono_value_box_checked (MonoDomain *domain, MonoClass *klass, gpointer value, Mo

size = size - sizeof (MonoObject);

if (mono_gc_is_moving ()) {
if (mono_gc_needs_write_barriers()) {
g_assert (size == mono_class_value_size (klass, NULL));
mono_gc_wbarrier_value_copy ((char *)res + sizeof (MonoObject), value, 1, klass);
} else {
Expand Down
6 changes: 6 additions & 0 deletions mono/metadata/sgen-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -2782,6 +2782,12 @@ mono_gc_is_moving (void)
return TRUE;
}

gboolean
mono_gc_needs_write_barriers(void)
{
return TRUE;
}

gboolean
mono_gc_is_disabled (void)
{
Expand Down
4 changes: 0 additions & 4 deletions mono/metadata/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,12 +566,10 @@ create_internal_thread_object (void)
* Boehm incremental is not actually "moving", it does not need the thread_pinning_ref.
* But having it causes problems when unregistering the root after domain reload.
*/
#if !defined(HAVE_BOEHM_GC)
if (mono_gc_is_moving ()) {
thread->thread_pinning_ref = thread;
MONO_GC_REGISTER_ROOT_PINNING (thread->thread_pinning_ref, MONO_ROOT_SOURCE_THREADING, NULL, "Thread Pinning Reference");
}
#endif

thread->priority = MONO_THREAD_PRIORITY_NORMAL;

Expand Down Expand Up @@ -894,12 +892,10 @@ mono_thread_detach_internal (MonoInternalThread *thread)
* Boehm incremental is not actually "moving", it does not need the thread_pinning_ref.
* But having it causes problems when unregistering the root after domain reload.
*/
#if !defined(HAVE_BOEHM_GC)
if (mono_gc_is_moving ()) {
MONO_GC_UNREGISTER_ROOT (thread->thread_pinning_ref);
thread->thread_pinning_ref = NULL;
}
#endif

done:
SET_CURRENT_OBJECT (NULL);
Expand Down
2 changes: 1 addition & 1 deletion mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -4111,7 +4111,7 @@ add_wrappers (MonoAotCompile *acfg)
}

/* write barriers */
if (mono_gc_is_moving ()) {
if (mono_gc_needs_write_barriers()) {
add_method (acfg, mono_gc_get_specific_write_barrier (FALSE));
add_method (acfg, mono_gc_get_specific_write_barrier (TRUE));
}
Expand Down
2 changes: 1 addition & 1 deletion mono/mini/mini-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2627,7 +2627,7 @@ mini_gc_set_slot_type_from_cfa (MonoCompile *cfg, int slot_offset, GCSlotType ty
void
mini_gc_init_cfg (MonoCompile *cfg)
{
if (mono_gc_is_moving ()) {
if (mono_gc_needs_write_barriers()) {
cfg->disable_ref_noref_stack_slot_share = TRUE;
cfg->gen_write_barriers = TRUE;
}
Expand Down