[nhc-bugs] Counters wrap in error messages

Malcolm Wallace Malcolm.Wallace@cs.york.ac.uk
Mon, 12 Nov 2001 14:32:56 +0000


> GC stats:
>  Used  1541499472 words of heap.  Moved -1466809254 words of heap in 2217 gcs.
>  83 words to next gc.  Max live after gc: 9715784 words.

Ok, I suppose we should use 64-bit counters if they are available.
Here's a patch.

Regards,
    Malcolm


Index: src/runtime/Kernel/collector.c
===================================================================
RCS file: /usr/src/master/nhc/src/runtime/Kernel/collector.c,v
retrieving revision 1.12
diff -u -r1.12 collector.c
--- src/runtime/Kernel/collector.c	2001/06/15 13:21:26	1.12
+++ src/runtime/Kernel/collector.c	2001/11/12 14:29:12
@@ -34,8 +34,8 @@
 extern timer gcTime;
 extern timer totalTime;
 extern timer runTime;
-Int hpTotal;
-Int hpMoved;
+int64_t hpTotal;
+int64_t hpMoved;
 Int hpMaxSurvive;
 int nogc;
 
@@ -72,7 +72,8 @@
   hpBase = hpLowLimit = hpStart;
 
   cafptr = 0;
-  hpMaxSurvive = hpMoved = hpTotal = nogc = 0;
+  hpMoved = hpTotal = 0;
+  hpMaxSurvive = nogc = 0;
 
 
   if(IND_TAG) {
@@ -106,8 +107,8 @@
 void finishGc(NodePtr hp,int verbose)
 {
   if(verbose) {
-    fprintf(stderr,"\n\nUsed  %ld words of heap.\n",hp-hpBase+hpTotal);
-    fprintf(stderr,"Moved %ld words of heap in %d gcs.\n",hpMoved,nogc);
+    fprintf(stderr,"\n\nUsed  %lld words of heap.\n",(int64_t)(hp-hpBase)+hpTotal);
+    fprintf(stderr,"Moved %lld words of heap in %d gcs.\n",hpMoved,nogc);
     fprintf(stderr,"%d words to next gc.\n",hpLimit-hp);
     fprintf(stderr,"Max live after gc: %ld words.\n",hpMaxSurvive);
   }
@@ -565,7 +566,7 @@
   prevLow = hpLowLimit;
   prevHigh = hpLimit;
 
-  hpTotal += hp - hpBase;
+  hpTotal += (int64_t)(hp - hpBase);
 
   clearForeignObjs();
 
@@ -652,7 +653,7 @@
 
   hp = moveHeap(hp);
 
-  hpMoved += hp - &hpLowLimit[GCEXTRA];
+  hpMoved += (int64_t)(hp - &hpLowLimit[GCEXTRA]);
 
   if(hpMaxSurvive < hp-&hpLowLimit[GCEXTRA])
     hpMaxSurvive =  hp-&hpLowLimit[GCEXTRA];
@@ -663,12 +664,12 @@
     fprintf(stderr,"The program ran out of heap memory.");
     fprintf(stderr,"  (Current heapsize is %d bytes.)\n",hpSize*sizeof(int));
     fprintf(stderr,"You can set a bigger size with e.g. +RTS -H4M -RTS");
-    fprintf(stderr," (4M = four megabytes).");
+    fprintf(stderr," (4M = four megabytes).\n");
     fprintf(stderr,"GC stats:\n  ");
     fprintf(stderr,"  Only %d words after gc, need %ld words.\n"
                                                          ,(NodePtr)sp-hp,size);
-    fprintf(stderr,"  Used  %ld words of heap.",hp-hpBase+hpTotal);
-    fprintf(stderr,"  Moved %ld words of heap in %d gcs.\n",hpMoved,nogc);
+    fprintf(stderr,"  Used  %lld words of heap.",(int64_t)(hp-hpBase)+hpTotal);
+    fprintf(stderr,"  Moved %lld words of heap in %d gcs.\n",hpMoved,nogc);
     fprintf(stderr,"  %d words to next gc.",(NodePtr)sp-hp);
     fprintf(stderr,"  Max live after gc: %ld words.\n",hpMaxSurvive);
 #if TRACE
Index: src/runtime/Kernel/mark.h
===================================================================
RCS file: /usr/src/master/nhc/src/runtime/Kernel/mark.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 mark.h
--- src/runtime/Kernel/mark.h	1999/10/11 11:50:26	1.1.1.1
+++ src/runtime/Kernel/mark.h	2001/11/12 14:29:12
@@ -1,6 +1,11 @@
 
 #ifndef _MARK_H
 
+#include <inttypes.h>
+#ifndef int64_t
+#define int64_t	long int
+#endif			/* default down to 32 bits if 64 not available */
+
 /* #define QADDR 1 */
 #define GCEXTRA 2+EXTRA
 
@@ -32,8 +37,8 @@
 extern int bellGc;
 extern timer gcTime;
 extern timer totalTime;
-extern Int hpTotal;
-extern Int hpMoved;
+extern int64_t hpTotal;
+extern int64_t hpMoved;
 extern Int hpMaxSurvive;
 extern int nogc;