[sgen] Add an explanatory comment about OOM.
authorMark Probst <mark.probst@gmail.com>
Thu, 30 Oct 2014 23:28:03 +0000 (16:28 -0700)
committerMark Probst <mark.probst@gmail.com>
Thu, 30 Oct 2014 23:28:03 +0000 (16:28 -0700)
mono/metadata/sgen-alloc.c

index ed28184ae4b631f6d57b05f7301153c8b7efd1ac..368388a5dab2fe5bf006844ac910be56d92811bc 100644 (file)
@@ -293,6 +293,21 @@ mono_gc_alloc_obj_nolock (MonoVTable *vtable, size_t size)
                                /* Allocate directly from the nursery */
                                p = sgen_nursery_alloc (size);
                                if (!p) {
+                                       /*
+                                        * We couldn't allocate from the nursery, so we try
+                                        * collecting.  Even after the collection, we might
+                                        * still not have enough memory to allocate the
+                                        * object.  The reason will most likely be that we've
+                                        * run out of memory, but there is the theoretical
+                                        * possibility that other threads might have consumed
+                                        * the freed up memory ahead of us, so doing another
+                                        * collection and trying again might actually help.
+                                        * Of course the same thing might happen again.
+                                        *
+                                        * Ideally we'd like to detect that case and loop (if
+                                        * we always loop we will loop endlessly in the case of
+                                        * OOM).  What we do here is give up right away.
+                                        */
                                        sgen_ensure_free_space (real_size);
                                        if (degraded_mode)
                                                return alloc_degraded (vtable, size, FALSE);
@@ -310,6 +325,7 @@ mono_gc_alloc_obj_nolock (MonoVTable *vtable, size_t size)
 
                                p = sgen_nursery_alloc_range (tlab_size, size, &alloc_size);
                                if (!p) {
+                                       /* See comment above in similar case. */
                                        sgen_ensure_free_space (tlab_size);
                                        if (degraded_mode)
                                                return alloc_degraded (vtable, size, FALSE);