Skip to content

Commit

Permalink
[sgen] Don't trigger collections during allocation of thread objects (m…
Browse files Browse the repository at this point in the history
…ono/mono#17970)

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 mono/mono#17878

Commit migrated from mono/mono@640ffa7
  • Loading branch information
BrzVlad authored and lambdageek committed Dec 2, 2019
1 parent 2e13b1c commit 8d985be
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/mono/mono/sgen/sgen-alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ sgen_alloc_obj_pinned (GCVTable vtable, size_t size)
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)
{
Expand All @@ -499,7 +503,7 @@ 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) {
Expand Down

0 comments on commit 8d985be

Please sign in to comment.