Fix GC_mark_stack_top assertion violation properly in mark_local
authorIvan Maidanski <ivmai@mail.ru>
Sat, 10 Dec 2016 07:37:04 +0000 (10:37 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Sat, 10 Dec 2016 07:37:04 +0000 (10:37 +0300)
(fix commit a563b883)

* mark.c (GC_mark_local): Remove assertion checking that
global_first_nonempty is not greater than GC_mark_stack_top+1 (because
global_first_nonempty could be bigger slightly more at some moments due
to concurrency between the markers); replace n_on_stack==0 with
my_top<my_first_nonempty (the latter is equivalent to
(signed_word)n_on_stack<=0).

mark.c

diff --git a/mark.c b/mark.c
index e6b212e..f631ab5 100644 (file)
--- a/mark.c
+++ b/mark.c
@@ -1093,10 +1093,7 @@ STATIC void GC_mark_local(mse *local_mark_stack, int id)
                   (word)my_first_nonempty <=
                         (word)AO_load((volatile AO_t *)&GC_mark_stack_top)
                         + sizeof(mse));
-        GC_ASSERT((word)global_first_nonempty >= (word)GC_mark_stack &&
-                  (word)global_first_nonempty <=
-                    (word)AO_load_acquire((volatile AO_t *)&GC_mark_stack_top)
-                        + sizeof(mse));
+        GC_ASSERT((word)global_first_nonempty >= (word)GC_mark_stack);
         if ((word)my_first_nonempty < (word)global_first_nonempty) {
             my_first_nonempty = global_first_nonempty;
         } else if ((word)global_first_nonempty < (word)my_first_nonempty) {
@@ -1109,8 +1106,7 @@ STATIC void GC_mark_local(mse *local_mark_stack, int id)
         /* Perhaps we should also update GC_first_nonempty, if it */
         /* is less.  But that would require using atomic updates. */
         my_top = (mse *)AO_load_acquire((volatile AO_t *)(&GC_mark_stack_top));
-        n_on_stack = my_top - my_first_nonempty + 1;
-        if (0 == n_on_stack) {
+        if ((word)my_top < (word)my_first_nonempty) {
             GC_acquire_mark_lock();
             my_top = GC_mark_stack_top;
                 /* Asynchronous modification impossible here,   */
@@ -1157,6 +1153,8 @@ STATIC void GC_mark_local(mse *local_mark_stack, int id)
             } else {
                 GC_release_mark_lock();
             }
+        } else {
+            n_on_stack = my_top - my_first_nonempty + 1;
         }
         n_to_get = ENTRIES_TO_GET;
         if (n_on_stack < 2 * ENTRIES_TO_GET) n_to_get = 1;