Allocation of thread objects usese the mono_object_new_mature API. These objects are allocated before the thread is finished attaching to the runtime. This means that a collection can happen on an unattached thread as well as all its callbacks, which is a counter-intuitive behavior.
On android this is problematic because at the end of the SGen collection we need to call the java collection, which needs to have the thread attached. This could probably be fixed instead from the Xamarin.Android side, but this approach seems simpler and saner.
Fixes https://github.com/mono/mono/issues/17878
Commit migrated from https://github.com/mono/mono/commit/
640ffa7a62a861b048fb311c0bdcb0a500336ad2
return p;
}
+/*
+ * Used to allocate thread objects during attach. Doesn't trigger collections since
+ * the thread is not yet attached.
+ */
GCObject*
sgen_alloc_obj_mature (GCVTable vtable, size_t size)
{
size = ALIGN_UP (size);
LOCK_GC;
- res = alloc_degraded (vtable, size, TRUE);
+ res = sgen_major_collector.alloc_degraded (vtable, size);
UNLOCK_GC;
if (res) {