From 4fafc74344456be993b42c7270f840bc23ea1d2c Mon Sep 17 00:00:00 2001
From: Matt Birkholz <puck@birchwood-abbey.net>
Date: Tue, 26 Aug 2014 22:27:38 -0700
Subject: [PATCH] microcode/unix: fix continue_from_trap to freak out (force
 GC) less

The classify_pc function returns pcl_unknown for traps in shared
libraries, e.g. in feraiseexcept (in the raise-float-exceptions
primitive) or any callout (in the c-call primitive).  This new
continue_from_trap function is less conservative, ignoring the
pcl_unknown result from classify_pc when the stack_pointer, Free and
PRIMITIVE registers all look good.  This eliminated all complaints
during `make check' about "resetting bogus Free" (not the actual
problem), representing 14 unnecessarily forced GCs.

Also, fix the murmur about "resetting bogus Free".  Correct it for
accuracy and so that it must be turned on with the
((make-primitive-procedure 'SET-DEBUG-FLAGS! 2) 9 #t)
---
 src/microcode/uxtrap.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/microcode/uxtrap.c b/src/microcode/uxtrap.c
index 511f112e2..6e7db83ba 100644
--- a/src/microcode/uxtrap.c
+++ b/src/microcode/uxtrap.c
@@ -391,6 +391,23 @@ continue_from_trap (int signo, SIGINFO_T info, SIGCONTEXT_T * scp)
 #endif
 
     case pcl_unknown:
+      if (((OBJECT_TYPE (primitive)) == TC_PRIMITIVE)
+	  && (ADDRESS_IN_STACK_P (stack_pointer)) && (ALIGNED_P (stack_pointer))
+	  && (ADDRESS_IN_HEAP_P (Free)) && (ALIGNED_P (Free)))
+	{
+#ifdef ENABLE_DEBUGGING_TOOLS
+	  if (GC_Debug == true)
+	    {
+	      /* Note where this presumption is employed. */
+	      outf_error (";Warning: trap at 0x%lx assumed a primitive\n", pc);
+	      outf_flush_error ();
+	    }
+#endif
+	  new_sp = stack_pointer;
+	  SET_RECOVERY_INFO
+	    (STATE_PRIMITIVE, primitive, (ULONG_TO_FIXNUM (GET_LEXPR_ACTUALS)));
+	  break;
+	}
       new_sp = 0;
       SET_RECOVERY_INFO
 	(STATE_UNKNOWN,
@@ -409,8 +426,13 @@ continue_from_trap (int signo, SIGINFO_T info, SIGCONTEXT_T * scp)
 	&& (ALIGNED_P (Free))))
     {
 #ifdef ENABLE_DEBUGGING_TOOLS
-      outf_error ("Resetting bogus Free in continue_from_trap.\n");
-      outf_flush_error ();
+      if (GC_Debug == true)
+	{
+	  outf_error ((new_sp == 0)
+		      ? ";Warning: bogus stack_pointer in continue_from_trap\n"
+		      : ";Warning: bogus Free in continue_from_trap\n");
+	  outf_flush_error ();
+	}
 #endif
       Free = heap_alloc_limit;
     }
-- 
2.25.1