[commit: ghc] wip/erikd/remove-nat: rts/ProfHeap.c: Use `size_t` instead of `long`. (def125e)

git at git.haskell.org git at git.haskell.org
Mon May 2 20:31:31 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/erikd/remove-nat
Link       : http://ghc.haskell.org/trac/ghc/changeset/def125e556a4289c1300c496fb5caaf7100571c4/ghc

>---------------------------------------------------------------

commit def125e556a4289c1300c496fb5caaf7100571c4
Author: Erik de Castro Lopo <erikd at mega-nerd.com>
Date:   Mon May 2 20:22:00 2016 +1000

    rts/ProfHeap.c: Use `size_t` instead of `long`.
    
    On x64 Windows `sizeof long` is 4 which could easily overflow
    resulting in incorrect heap profiling results. This change does not
    affect either Linux or OS X where `sizeof long` == `sizeof size_t`
    regardless of machine word size.


>---------------------------------------------------------------

def125e556a4289c1300c496fb5caaf7100571c4
 rts/ProfHeap.c | 44 +++++++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 23 deletions(-)

diff --git a/rts/ProfHeap.c b/rts/ProfHeap.c
index 875cc7e..06d9602 100644
--- a/rts/ProfHeap.c
+++ b/rts/ProfHeap.c
@@ -50,13 +50,13 @@ static uint32_t max_era;
 typedef struct _counter {
     void *identity;
     union {
-        uint32_t resid;
+        size_t resid;
         struct {
-            long prim;     // total size of 'inherently used' closures
-            long not_used; // total size of 'never used' closures
-            long used;     // total size of 'used at least once' closures
-            long void_total;  // current total size of 'destroyed without being used' closures
-            long drag_total;  // current total size of 'used at least once and waiting to die'
+            size_t prim;     // total size of 'inherently used' closures
+            size_t not_used; // total size of 'never used' closures
+            size_t used;     // total size of 'used at least once' closures
+            size_t void_total;  // current total size of 'destroyed without being used' closures
+            size_t drag_total;  // current total size of 'used at least once and waiting to die'
         } ldv;
     } c;
     struct _counter *next;
@@ -79,11 +79,11 @@ typedef struct {
     Arena     * arena;
 
     // for LDV profiling, when just displaying by LDV
-    long       prim;
-    long       not_used;
-    long       used;
-    long       void_total;
-    long       drag_total;
+    size_t     prim;
+    size_t     not_used;
+    size_t     used;
+    size_t     void_total;
+    size_t     drag_total;
 } Census;
 
 static Census *censuses = NULL;
@@ -193,14 +193,14 @@ LDV_recordDead( StgClosure *c, uint32_t size )
             t = (LDVW((c)) & LDV_CREATE_MASK) >> LDV_SHIFT;
             if (t < era) {
                 if (RtsFlags.ProfFlags.bioSelector == NULL) {
-                    censuses[t].void_total   += (long)size;
-                    censuses[era].void_total -= (long)size;
+                    censuses[t].void_total   += size;
+                    censuses[era].void_total -= size;
                     ASSERT(censuses[t].void_total < censuses[t].not_used);
                 } else {
                     id = closureIdentity(c);
                     ctr = lookupHashTable(censuses[t].hash, (StgWord)id);
                     ASSERT( ctr != NULL );
-                    ctr->c.ldv.void_total += (long)size;
+                    ctr->c.ldv.void_total += size;
                     ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
                     if (ctr == NULL) {
                         ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
@@ -210,7 +210,7 @@ LDV_recordDead( StgClosure *c, uint32_t size )
                         ctr->next = censuses[era].ctrs;
                         censuses[era].ctrs = ctr;
                     }
-                    ctr->c.ldv.void_total -= (long)size;
+                    ctr->c.ldv.void_total -= size;
                 }
             }
         } else {
@@ -224,7 +224,7 @@ LDV_recordDead( StgClosure *c, uint32_t size )
                     id = closureIdentity(c);
                     ctr = lookupHashTable(censuses[t+1].hash, (StgWord)id);
                     ASSERT( ctr != NULL );
-                    ctr->c.ldv.drag_total += (long)size;
+                    ctr->c.ldv.drag_total += size;
                     ctr = lookupHashTable(censuses[era].hash, (StgWord)id);
                     if (ctr == NULL) {
                         ctr = arenaAlloc(censuses[era].arena, sizeof(counter));
@@ -234,7 +234,7 @@ LDV_recordDead( StgClosure *c, uint32_t size )
                         ctr->next = censuses[era].ctrs;
                         censuses[era].ctrs = ctr;
                     }
-                    ctr->c.ldv.drag_total -= (long)size;
+                    ctr->c.ldv.drag_total -= size;
                 }
             }
         }
@@ -739,7 +739,7 @@ static void
 dumpCensus( Census *census )
 {
     counter *ctr;
-    long count;
+    size_t count;
 
     printSample(rtsTrue, census->time);
 
@@ -778,8 +778,6 @@ dumpCensus( Census *census )
             count = ctr->c.resid;
         }
 
-        ASSERT( count >= 0 );
-
         if (count == 0) continue;
 
 #if !defined(PROFILING)
@@ -835,7 +833,7 @@ dumpCensus( Census *census )
 }
 
 
-static void heapProfObject(Census *census, StgClosure *p, uint32_t size,
+static void heapProfObject(Census *census, StgClosure *p, size_t size,
                            rtsBool prim
 #ifndef PROFILING
                            STG_UNUSED
@@ -843,7 +841,7 @@ static void heapProfObject(Census *census, StgClosure *p, uint32_t size,
                            )
 {
     void *identity;
-    uint32_t real_size;
+    size_t real_size;
     counter *ctr;
 
             identity = NULL;
@@ -920,7 +918,7 @@ heapCensusChain( Census *census, bdescr *bd )
 {
     StgPtr p;
     StgInfoTable *info;
-    uint32_t size;
+    size_t size;
     rtsBool prim;
 
     for (; bd != NULL; bd = bd->link) {



More information about the ghc-commits mailing list