]> granicus.if.org Git - gc/commitdiff
New macro ALWAYS_SMALL_CLEAR_STACK to avoid clearing large stack sections
authorJonathan Chambers <joncham@gmail.com>
Wed, 31 Jan 2018 08:45:26 +0000 (11:45 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 31 Jan 2018 08:45:26 +0000 (11:45 +0300)
(a cherry-pick of commit 95f5767 from Unity-Technologies/bdwgc)

Issue #173 (bdwgc).

Avoid clearing large sections of the stack.  It was clearing
up to 16k which may not be available in cases of small stacks or stack
overflow situations (for some targets).

* misc.c [ALWAYS_SMALL_CLEAR_STACK] (GC_clear_stack): Do only BZERO for
dummy where dummy is a local array of length SMALL_CLEAR_SIZE.

misc.c

diff --git a/misc.c b/misc.c
index cf15284b5b30655fd1ee86cc8e77ae0e46d90d8d..66f1d97ae63cb7c4dc9bd65c8d21e0f42efcbaaf 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -262,9 +262,13 @@ STATIC void GC_init_size_map(void)
 # define SMALL_CLEAR_SIZE 256   /* Clear this much every time.  */
 #endif
 
-#if defined(STACK_NOT_SCANNED)
+#if defined(ALWAYS_SMALL_CLEAR_STACK) || defined(STACK_NOT_SCANNED)
   GC_API void * GC_CALL GC_clear_stack(void *arg)
   {
+#   ifndef STACK_NOT_SCANNED
+      word volatile dummy[SMALL_CLEAR_SIZE];
+      BZERO((/* no volatile */ void *)dummy, sizeof(dummy));
+#   endif
     return arg;
   }
 #else
@@ -391,7 +395,7 @@ STATIC void GC_init_size_map(void)
     return arg;
   }
 
-#endif /* !STACK_NOT_SCANNED */
+#endif /* !ALWAYS_SMALL_CLEAR_STACK && !STACK_NOT_SCANNED */
 
 /* Return a pointer to the base address of p, given a pointer to a      */
 /* an address within an object.  Return 0 o.w.                          */