Skip to content

Commit f258e9b

Browse files
authored
Don't use mono_gc_is_moving for incremental gc (#1229)
1 parent 1a6788a commit f258e9b

File tree

9 files changed

+29
-12
lines changed

9 files changed

+29
-12
lines changed

mono/metadata/boehm-gc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,9 +1576,15 @@ mono_gc_set_desktop_mode (void)
15761576

15771577
gboolean
15781578
mono_gc_is_moving (void)
1579+
{
1580+
return FALSE;
1581+
}
1582+
1583+
gboolean
1584+
mono_gc_needs_write_barriers(void)
15791585
{
15801586
#if HAVE_BDWGC_GC
1581-
return GC_is_incremental_mode ();
1587+
return GC_is_incremental_mode();
15821588
#else
15831589
return FALSE;
15841590
#endif

mono/metadata/domain.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,12 +1252,10 @@ mono_domain_free (MonoDomain *domain, gboolean force)
12521252

12531253
domain->setup = NULL;
12541254

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

12621260
mono_appdomains_lock ();
12631261
appdomains_list [domain->domain_id] = NULL;

mono/metadata/gc-internals.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
} while (0)
5555

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

5959
void mono_object_register_finalizer (MonoObject *obj);
6060
void ves_icall_System_GC_InternalCollect (int generation);
@@ -280,6 +280,11 @@ void mono_gc_set_desktop_mode (void);
280280
*/
281281
gboolean mono_gc_is_moving (void);
282282

283+
/*
284+
* Return whenever this GC needs write barriers
285+
*/
286+
gboolean mono_gc_needs_write_barriers (void);
287+
283288
typedef void* (*MonoGCLockedCallbackFunc) (void *data);
284289

285290
void* mono_gc_invoke_with_gc_lock (MonoGCLockedCallbackFunc func, void *data);

mono/metadata/null-gc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,12 @@ mono_gc_is_moving (void)
430430
return FALSE;
431431
}
432432

433+
gboolean
434+
mono_gc_needs_write_barriers(void)
435+
{
436+
return FALSE;
437+
}
438+
433439
gboolean
434440
mono_gc_is_disabled (void)
435441
{

mono/metadata/object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5703,7 +5703,7 @@ mono_array_full_copy (MonoArray *src, MonoArray *dest)
57035703
static void
57045704
array_full_copy_unchecked_size (MonoArray *src, MonoArray *dest, MonoClass *klass, uintptr_t size)
57055705
{
5706-
if (mono_gc_is_moving ()) {
5706+
if (mono_gc_needs_write_barriers()) {
57075707
if (klass->element_class->valuetype) {
57085708
if (klass->element_class->has_references)
57095709
mono_value_copy_array (dest, 0, mono_array_addr_with_size_fast (src, 0, 0), mono_array_length (src));
@@ -6447,7 +6447,7 @@ mono_value_box_checked (MonoDomain *domain, MonoClass *klass, gpointer value, Mo
64476447

64486448
size = size - sizeof (MonoObject);
64496449

6450-
if (mono_gc_is_moving ()) {
6450+
if (mono_gc_needs_write_barriers()) {
64516451
g_assert (size == mono_class_value_size (klass, NULL));
64526452
mono_gc_wbarrier_value_copy ((char *)res + sizeof (MonoObject), value, 1, klass);
64536453
} else {

mono/metadata/sgen-mono.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2782,6 +2782,12 @@ mono_gc_is_moving (void)
27822782
return TRUE;
27832783
}
27842784

2785+
gboolean
2786+
mono_gc_needs_write_barriers(void)
2787+
{
2788+
return TRUE;
2789+
}
2790+
27852791
gboolean
27862792
mono_gc_is_disabled (void)
27872793
{

mono/metadata/threads.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,12 +566,10 @@ create_internal_thread_object (void)
566566
* Boehm incremental is not actually "moving", it does not need the thread_pinning_ref.
567567
* But having it causes problems when unregistering the root after domain reload.
568568
*/
569-
#if !defined(HAVE_BOEHM_GC)
570569
if (mono_gc_is_moving ()) {
571570
thread->thread_pinning_ref = thread;
572571
MONO_GC_REGISTER_ROOT_PINNING (thread->thread_pinning_ref, MONO_ROOT_SOURCE_THREADING, NULL, "Thread Pinning Reference");
573572
}
574-
#endif
575573

576574
thread->priority = MONO_THREAD_PRIORITY_NORMAL;
577575

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

904900
done:
905901
SET_CURRENT_OBJECT (NULL);

mono/mini/aot-compiler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4111,7 +4111,7 @@ add_wrappers (MonoAotCompile *acfg)
41114111
}
41124112

41134113
/* write barriers */
4114-
if (mono_gc_is_moving ()) {
4114+
if (mono_gc_needs_write_barriers()) {
41154115
add_method (acfg, mono_gc_get_specific_write_barrier (FALSE));
41164116
add_method (acfg, mono_gc_get_specific_write_barrier (TRUE));
41174117
}

mono/mini/mini-gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2627,7 +2627,7 @@ mini_gc_set_slot_type_from_cfa (MonoCompile *cfg, int slot_offset, GCSlotType ty
26272627
void
26282628
mini_gc_init_cfg (MonoCompile *cfg)
26292629
{
2630-
if (mono_gc_is_moving ()) {
2630+
if (mono_gc_needs_write_barriers()) {
26312631
cfg->disable_ref_noref_stack_slot_share = TRUE;
26322632
cfg->gen_write_barriers = TRUE;
26332633
}

0 commit comments

Comments
 (0)