X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2FRetainerSet.c;h=bfa0bc8acfa947e3c5d8d4868856e872804b7255;hb=d700953c29ffe78d6530f734f2820c796e5ec6e0;hp=709555a82eea6beb651bba72d4678d21728c8412;hpb=db61851c5472bf565cd1da900b33d6e033fd743d;p=ghc-hetmet.git diff --git a/ghc/rts/RetainerSet.c b/ghc/rts/RetainerSet.c index 709555a..bfa0bc8 100644 --- a/ghc/rts/RetainerSet.c +++ b/ghc/rts/RetainerSet.c @@ -1,5 +1,4 @@ /* ----------------------------------------------------------------------------- - * $Id: RetainerSet.c,v 1.1 2001/11/22 14:25:12 simonmar Exp $ * * (c) The GHC Team, 2001 * Author: Sungwoo Park @@ -11,12 +10,14 @@ #ifdef PROFILING #include "Rts.h" +#include "RtsFlags.h" #include "Stats.h" #include "RtsUtils.h" #include "RetainerSet.h" #include "Arena.h" #include "Profiling.h" +#include #include #define HASH_TABLE_SIZE 255 @@ -40,19 +41,16 @@ static int nextId; // id of next retainer set * -------------------------------------------------------------------------- */ RetainerSet rs_MANY = { num : 0, - cost : 0, hashKey : 0, link : NULL, id : 1, element : {} }; -nat maxRetainerSetSize = 16; - /* ----------------------------------------------------------------------------- * calculate the size of a RetainerSet structure * -------------------------------------------------------------------------- */ -static inline size_t +STATIC_INLINE size_t sizeofRetainerSet( int elems ) { return (sizeof(RetainerSet) + elems * sizeof(retainer)); @@ -80,11 +78,9 @@ initializeAllRetainerSet(void) void refreshAllRetainerSet(void) { +#ifdef FIRST_APPROACH int i; - // Choose one of the following two approaches. - -#ifdef FIRST_APPROACH // first approach: completely refresh arenaFree(arena); arena = newArena(); @@ -92,20 +88,7 @@ refreshAllRetainerSet(void) for (i = 0; i < HASH_TABLE_SIZE; i++) hashTable[i] = NULL; nextId = 2; -#endif // FIRST_APPROACH - -#ifdef SECOND_APPROACH - // second approach: leave all the retainer sets for reuse - RetainerSet *rs; - for (i = 0;i < HASH_TABLE_SIZE; i++) { - rs = hashTable[i]; - while (rs != NULL) { - rs->cost = 0; - rs = rs->link; - } - } - rs_MANY.cost = 0; -#endif // SECOND_APPROACH +#endif /* FIRST_APPROACH */ } /* ----------------------------------------------------------------------------- @@ -133,7 +116,6 @@ singleton(retainer r) // create it rs = arenaAlloc( arena, sizeofRetainerSet(1) ); rs->num = 1; - rs->cost = 0; rs->hashKey = hk; rs->link = hashTable[hash(hk)]; rs->id = nextId++; @@ -164,13 +146,13 @@ addElement(retainer r, RetainerSet *rs) StgWord hk; // Hash Key #ifdef DEBUG_RETAINER - // fprintf(stderr, "addElement(%p, %p) = ", r, rs); + // debugBelch("addElement(%p, %p) = ", r, rs); #endif ASSERT(rs != NULL); - ASSERT(rs->num <= maxRetainerSetSize); + ASSERT(rs->num <= RtsFlags.ProfFlags.maxRetainerSetSize); - if (rs == &rs_MANY || rs->num == maxRetainerSetSize) { + if (rs == &rs_MANY || rs->num == RtsFlags.ProfFlags.maxRetainerSetSize) { return &rs_MANY; } @@ -204,7 +186,7 @@ addElement(retainer r, RetainerSet *rs) if (i < rs->num) continue; #ifdef DEBUG_RETAINER - // fprintf(stderr, "%p\n", nrs); + // debugBelch("%p\n", nrs); #endif // The set we are seeking already exists! return nrs; @@ -213,7 +195,6 @@ addElement(retainer r, RetainerSet *rs) // create a new retainer set nrs = arenaAlloc( arena, sizeofRetainerSet(rs->num + 1) ); nrs->num = rs->num + 1; - nrs->cost = 0; nrs->hashKey = hk; nrs->link = hashTable[hash(hk)]; nrs->id = nextId++; @@ -228,7 +209,7 @@ addElement(retainer r, RetainerSet *rs) hashTable[hash(hk)] = nrs; #ifdef DEBUG_RETAINER - // fprintf(stderr, "%p\n", nrs); + // debugBelch("%p\n", nrs); #endif return nrs; } @@ -447,80 +428,10 @@ printRetainerSetShort(FILE *f, retainerSet *rs) #endif /* SECOND_APPROACH */ /* ----------------------------------------------------------------------------- - * Print the statistics. This function is called after each - * retainer profiling. *allCost is set the sum of all costs retained - * by any retainer sets. *numSet is set to the number of all - * retainer sets (including those with 0 cost). - * -------------------------------------------------------------------------- */ -void -outputRetainerSet( FILE *hp_file, nat *allCost, nat *numSet ) -{ - nat i; -#ifdef FIRST_APPROACH - nat j; -#endif - RetainerSet *rs; - double duration; - - *allCost = 0; - *numSet = 0; - duration = mut_user_time_during_RP(); - - fprintf(hp_file, "MARK %f\n", duration); - fprintf(hp_file, "BEGIN_SAMPLE %f\n", duration); - - if (rs_MANY.cost > 0) { - fprintf(hp_file, "MANY\t%u\n", rs_MANY.cost * sizeof(StgWord)); - } - - for (i = 0; i < HASH_TABLE_SIZE; i++) { - for (rs = hashTable[i]; rs != NULL; rs = rs->link) { - (*numSet)++; - /* - Note: If rs->cost is 0, it means that there exists at - least one object which is retained by this retainer set - *rs temporarily. Since its new retainer set of this - object (replacing *rs) is at least larger than *rs, if - the cost of every object was a positive quantity, the - following invariants would hold: If rs->cost == 0, there - exists a retainer set rs' such that rs'->cost > 0 and - rs'->num > rs->num. However, static objects cost zero, - this does not hold. If we set the cost of each static - object to a positive quantity, it should hold, which is - actually the case. - */ - if (rs->cost == 0) - continue; - - *allCost += rs->cost; - -#ifdef SECOND_APPROACH - if (rs->id > 0) // if having a positive cost for the first time? - rs->id = -(rs->id); // mark as having a positive cost - // Now, this retainer set has a permanent negative id. - - // report in the unit of bytes: * sizeof(StgWord) - printRetainerSetShort(hp_file, rs); - fprintf(hp_file, "\t%u\n", rs->cost * sizeof(StgWord)); -#endif - -#ifdef FIRST_APPROACH - fprintf(hp_file, "{"); - for (j = 0; j < rs->num - 1; j++) { - printRetainer(hp_file, rs->element[j]); - fprintf(hp_file, ","); - } - printRetainer(hp_file, rs->element[j]); - fprintf(hp_file, "}\t%u\n", rs->cost * sizeof(StgWord)); -#endif - } - } - fprintf(hp_file, "END_SAMPLE %f\n", duration); -} - -/* - This function is called at the exit of the program. - */ + * Dump the contents of each retainer set into the log file at the end + * of the run, so the user can find out for a given retainer set ID + * the full contents of that set. + * --------------------------------------------------------------------------- */ #ifdef SECOND_APPROACH void outputAllRetainerSet(FILE *prof_file) @@ -580,8 +491,8 @@ outputAllRetainerSet(FILE *prof_file) fprintf(prof_file, "}\n"); } - free(rsArray); + stgFree(rsArray); } -#endif // SECOND_APPROACH +#endif /* SECOND_APPROACH */ #endif /* PROFILING */