Changeset 101869 in vbox for trunk/src/libs/xpcom18a4/nsprpub/lib
- Timestamp:
- Nov 6, 2023 1:38:17 PM (15 months ago)
- Location:
- trunk/src/libs/xpcom18a4/nsprpub/lib/ds
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/nsprpub/lib/ds/plarena.c
r58734 r101869 53 53 static PLArena *arena_freelist; 54 54 55 #ifdef PL_ARENAMETER 56 static PLArenaStats *arena_stats_list; 57 58 #define COUNT(pool,what) (pool)->stats.what++ 59 #else 60 #define COUNT(pool,what) /* nothing */ 61 #endif 62 55 #define COUNT(pool,what) 63 56 #define PL_ARENA_DEFAULT_ALIGN sizeof(double) 64 57 … … 108 101 PLArenaPool *pool, const char *name, PRUint32 size, PRUint32 align) 109 102 { 110 #if defined(XP_MAC)111 #pragma unused (name)112 #endif113 114 103 if (align == 0) 115 104 align = PL_ARENA_DEFAULT_ALIGN; … … 122 111 (PRUword)PL_ARENA_ALIGN(pool, &pool->first + 1); 123 112 pool->current = &pool->first; 124 pool->arenasize = size; 125 #ifdef PL_ARENAMETER 126 memset(&pool->stats, 0, sizeof pool->stats); 127 pool->stats.name = strdup(name); 128 pool->stats.next = arena_stats_list; 129 arena_stats_list = &pool->stats; 130 #endif 113 pool->arenasize = size; 131 114 } 132 115 … … 322 305 { 323 306 FreeArenaList(pool, &pool->first, PR_TRUE); 324 #ifdef PL_ARENAMETER325 {326 PLArenaStats *stats, **statsp;327 328 if (pool->stats.name)329 PR_DELETE(pool->stats.name);330 for (statsp = &arena_stats_list; (stats = *statsp) != 0;331 statsp = &stats->next) {332 if (stats == &pool->stats) {333 *statsp = stats->next;334 return;335 }336 }337 }338 #endif339 307 } 340 308 341 309 PR_IMPLEMENT(void) PL_CompactArenaPool(PLArenaPool *ap) 342 310 { 343 #if XP_MAC344 #pragma unused (ap)345 #if 0346 PRArena *curr = &(ap->first);347 while (curr) {348 reallocSmaller(curr, curr->avail - (uprword_t)curr);349 curr->limit = curr->avail;350 curr = curr->next;351 }352 #endif353 #endif354 311 } 355 312 … … 370 327 } 371 328 372 #ifdef PL_ARENAMETER373 PR_IMPLEMENT(void) PL_ArenaCountAllocation(PLArenaPool *pool, PRUint32 nb)374 {375 pool->stats.nallocs++;376 pool->stats.nbytes += nb;377 if (nb > pool->stats.maxalloc)378 pool->stats.maxalloc = nb;379 pool->stats.variance += nb * nb;380 }381 382 PR_IMPLEMENT(void) PL_ArenaCountInplaceGrowth(383 PLArenaPool *pool, PRUint32 size, PRUint32 incr)384 {385 pool->stats.ninplace++;386 }387 388 PR_IMPLEMENT(void) PL_ArenaCountGrowth(389 PLArenaPool *pool, PRUint32 size, PRUint32 incr)390 {391 pool->stats.ngrows++;392 pool->stats.nbytes += incr;393 pool->stats.variance -= size * size;394 size += incr;395 if (size > pool->stats.maxalloc)396 pool->stats.maxalloc = size;397 pool->stats.variance += size * size;398 }399 400 PR_IMPLEMENT(void) PL_ArenaCountRelease(PLArenaPool *pool, char *mark)401 {402 pool->stats.nreleases++;403 }404 405 PR_IMPLEMENT(void) PL_ArenaCountRetract(PLArenaPool *pool, char *mark)406 {407 pool->stats.nfastrels++;408 }409 410 #include <math.h>411 #include <stdio.h>412 413 PR_IMPLEMENT(void) PL_DumpArenaStats(FILE *fp)414 {415 PLArenaStats *stats;416 double mean, variance;417 418 for (stats = arena_stats_list; stats; stats = stats->next) {419 if (stats->nallocs != 0) {420 mean = (double)stats->nbytes / stats->nallocs;421 variance = fabs(stats->variance / stats->nallocs - mean * mean);422 } else {423 mean = variance = 0;424 }425 426 fprintf(fp, "\n%s allocation statistics:\n", stats->name);427 fprintf(fp, " number of arenas: %u\n", stats->narenas);428 fprintf(fp, " number of allocations: %u\n", stats->nallocs);429 fprintf(fp, " number of free arena reclaims: %u\n", stats->nreclaims);430 fprintf(fp, " number of malloc calls: %u\n", stats->nmallocs);431 fprintf(fp, " number of deallocations: %u\n", stats->ndeallocs);432 fprintf(fp, " number of allocation growths: %u\n", stats->ngrows);433 fprintf(fp, " number of in-place growths: %u\n", stats->ninplace);434 fprintf(fp, "number of released allocations: %u\n", stats->nreleases);435 fprintf(fp, " number of fast releases: %u\n", stats->nfastrels);436 fprintf(fp, " total bytes allocated: %u\n", stats->nbytes);437 fprintf(fp, " mean allocation size: %g\n", mean);438 fprintf(fp, " standard deviation: %g\n", sqrt(variance));439 fprintf(fp, " maximum allocation size: %u\n", stats->maxalloc);440 }441 }442 #endif /* PL_ARENAMETER */ -
trunk/src/libs/xpcom18a4/nsprpub/lib/ds/plarena.h
r58734 r101869 60 60 }; 61 61 62 #ifdef PL_ARENAMETER63 typedef struct PLArenaStats PLArenaStats;64 65 struct PLArenaStats {66 PLArenaStats *next; /* next in arenaStats list */67 char *name; /* name for debugging */68 PRUint32 narenas; /* number of arenas in pool */69 PRUint32 nallocs; /* number of PL_ARENA_ALLOCATE() calls */70 PRUint32 nreclaims; /* number of reclaims from freeArenas */71 PRUint32 nmallocs; /* number of malloc() calls */72 PRUint32 ndeallocs; /* number of lifetime deallocations */73 PRUint32 ngrows; /* number of PL_ARENA_GROW() calls */74 PRUint32 ninplace; /* number of in-place growths */75 PRUint32 nreleases; /* number of PL_ARENA_RELEASE() calls */76 PRUint32 nfastrels; /* number of "fast path" releases */77 PRUint32 nbytes; /* total bytes allocated */78 PRUint32 maxalloc; /* maximum allocation size in bytes */79 PRFloat64 variance; /* size variance accumulator */80 };81 #endif82 83 62 struct PLArenaPool { 84 63 PLArena first; /* first arena in pool list */ … … 86 65 PRUint32 arenasize; /* net exact size of a new arena */ 87 66 PRUword mask; /* alignment mask (power-of-2 - 1) */ 88 #ifdef PL_ARENAMETER89 PLArenaStats stats;90 #endif91 67 }; 92 68 … … 171 147 PR_END_MACRO 172 148 173 #ifdef PL_ARENAMETER174 #define PL_COUNT_ARENA(pool,op) ((pool)->stats.narenas op)175 #else176 149 #define PL_COUNT_ARENA(pool,op) 177 #endif178 150 179 151 #define PL_ARENA_DESTROY(pool, a, pnext) \ … … 187 159 PR_END_MACRO 188 160 189 #ifdef PL_ARENAMETER190 191 #include <stdio.h>192 193 PR_EXTERN(void) PL_ArenaCountAllocation(PLArenaPool *pool, PRUint32 nb);194 195 PR_EXTERN(void) PL_ArenaCountInplaceGrowth(196 PLArenaPool *pool, PRUint32 size, PRUint32 incr);197 198 PR_EXTERN(void) PL_ArenaCountGrowth(199 PLArenaPool *pool, PRUint32 size, PRUint32 incr);200 201 PR_EXTERN(void) PL_ArenaCountRelease(PLArenaPool *pool, char *mark);202 203 PR_EXTERN(void) PL_ArenaCountRetract(PLArenaPool *pool, char *mark);204 205 PR_EXTERN(void) PL_DumpArenaStats(FILE *fp);206 207 #else /* !PL_ARENAMETER */208 209 161 #define PL_ArenaCountAllocation(ap, nb) /* nothing */ 210 162 #define PL_ArenaCountInplaceGrowth(ap, size, incr) /* nothing */ … … 213 165 #define PL_ArenaCountRetract(ap, mark) /* nothing */ 214 166 215 #endif /* !PL_ARENAMETER */216 217 167 PR_END_EXTERN_C 218 168 -
trunk/src/libs/xpcom18a4/nsprpub/lib/ds/plarenas.h
r11551 r101869 56 56 57 57 /* 58 ** Allocate an arena pool as specified by the parameters.59 **60 ** This is equivelant to allocating the space yourself and then61 ** calling PL_InitArenaPool().62 **63 ** This function may fail (and return a NULL) for a variety of64 ** reasons. The reason for a particular failure can be discovered65 ** by calling PR_GetError().66 */67 #if 0 /* Not implemented */68 PR_EXTERN(PLArenaPool*) PL_AllocArenaPool(69 const char *name, PRUint32 size, PRUint32 align);70 #endif71 72 /*73 ** Destroy an arena pool previously allocated by PL_AllocArenaPool().74 **75 ** This function may fail if the arena is not empty and the caller76 ** wishes to check for empty upon descruction.77 */78 #if 0 /* Not implemented */79 PR_EXTERN(PRStatus) PL_DestroyArenaPool(PLArenaPool *pool, PRBool checkEmpty);80 #endif81 82 83 /*84 58 ** Initialize an arena pool with the given name for debugging and metering, 85 59 ** with a minimum size per arena of size bytes. -
trunk/src/libs/xpcom18a4/nsprpub/lib/ds/plhash.c
r1 r101869 66 66 DefaultAllocTable(void *pool, PRSize size) 67 67 { 68 #if defined(XP_MAC)69 #pragma unused (pool)70 #endif71 72 68 return PR_MALLOC(size); 73 69 } … … 76 72 DefaultFreeTable(void *pool, void *item) 77 73 { 78 #if defined(XP_MAC)79 #pragma unused (pool)80 #endif81 82 74 PR_Free(item); 83 75 } … … 86 78 DefaultAllocEntry(void *pool, const void *key) 87 79 { 88 #if defined(XP_MAC)89 #pragma unused (pool,key)90 #endif91 92 80 return PR_NEW(PLHashEntry); 93 81 } … … 96 84 DefaultFreeEntry(void *pool, PLHashEntry *he, PRUintn flag) 97 85 { 98 #if defined(XP_MAC)99 #pragma unused (pool)100 #endif101 102 86 if (flag == HT_FREE_ENTRY) 103 87 PR_Free(he); … … 133 117 ht->shift = PL_HASH_BITS - n; 134 118 n = 1 << n; 135 #if defined(WIN16) 136 if (n > 16000) { 137 (*allocOps->freeTable)(allocPriv, ht); 138 return 0; 139 } 140 #endif /* WIN16 */ 119 141 120 nb = n * sizeof(PLHashEntry *); 142 121 ht->buckets = (PLHashEntry**)((*allocOps->allocTable)(allocPriv, nb)); … … 191 170 PLHashNumber h; 192 171 193 #ifdef HASHMETER194 ht->nlookups++;195 #endif196 172 h = keyHash * GOLDEN_RATIO; 197 173 h >>= ht->shift; … … 208 184 } 209 185 hep = &he->next; 210 #ifdef HASHMETER211 ht->nsteps++;212 #endif213 186 } 214 187 return hep; … … 225 198 PLHashNumber h; 226 199 227 #ifdef HASHMETER228 ht->nlookups++;229 #endif230 200 h = keyHash * GOLDEN_RATIO; 231 201 h >>= ht->shift; … … 236 206 } 237 207 hep = &he->next; 238 #ifdef HASHMETER239 ht->nsteps++;240 #endif241 208 } 242 209 return hep; … … 255 222 if (ht->nentries >= OVERLOADED(n)) { 256 223 oldbuckets = ht->buckets; 257 #if defined(WIN16) 258 if (2 * n > 16000) 259 return 0; 260 #endif /* WIN16 */ 224 261 225 nb = 2 * n * sizeof(PLHashEntry *); 262 226 ht->buckets = (PLHashEntry**) … … 267 231 } 268 232 memset(ht->buckets, 0, nb); 269 #ifdef HASHMETER270 ht->ngrows++;271 #endif272 233 ht->shift--; 273 234 … … 345 306 } 346 307 memset(ht->buckets, 0, nb); 347 #ifdef HASHMETER348 ht->nshrinks++;349 #endif350 308 ht->shift++; 351 309 … … 455 413 } 456 414 457 #ifdef HASHMETER458 #include <math.h>459 #include <stdio.h>460 461 PR_IMPLEMENT(void)462 PL_HashTableDumpMeter(PLHashTable *ht, PLHashEnumerator dump, FILE *fp)463 {464 double mean, variance;465 PRUint32 nchains, nbuckets;466 PRUint32 i, n, maxChain, maxChainLen;467 PLHashEntry *he;468 469 variance = 0;470 nchains = 0;471 maxChainLen = 0;472 nbuckets = NBUCKETS(ht);473 for (i = 0; i < nbuckets; i++) {474 he = ht->buckets[i];475 if (!he)476 continue;477 nchains++;478 for (n = 0; he; he = he->next)479 n++;480 variance += n * n;481 if (n > maxChainLen) {482 maxChainLen = n;483 maxChain = i;484 }485 }486 mean = (double)ht->nentries / nchains;487 variance = fabs(variance / nchains - mean * mean);488 489 fprintf(fp, "\nHash table statistics:\n");490 fprintf(fp, " number of lookups: %u\n", ht->nlookups);491 fprintf(fp, " number of entries: %u\n", ht->nentries);492 fprintf(fp, " number of grows: %u\n", ht->ngrows);493 fprintf(fp, " number of shrinks: %u\n", ht->nshrinks);494 fprintf(fp, " mean steps per hash: %g\n", (double)ht->nsteps495 / ht->nlookups);496 fprintf(fp, "mean hash chain length: %g\n", mean);497 fprintf(fp, " standard deviation: %g\n", sqrt(variance));498 fprintf(fp, " max hash chain length: %u\n", maxChainLen);499 fprintf(fp, " max hash chain: [%u]\n", maxChain);500 501 for (he = ht->buckets[maxChain], i = 0; he; he = he->next, i++)502 if ((*dump)(he, i, fp) != HT_ENUMERATE_NEXT)503 break;504 }505 #endif /* HASHMETER */506 507 415 PR_IMPLEMENT(int) 508 416 PL_HashTableDump(PLHashTable *ht, PLHashEnumerator dump, FILE *fp) … … 511 419 512 420 count = PL_HashTableEnumerateEntries(ht, dump, fp); 513 #ifdef HASHMETER514 PL_HashTableDumpMeter(ht, dump, fp);515 #endif516 421 return count; 517 422 } -
trunk/src/libs/xpcom18a4/nsprpub/lib/ds/plhash.h
r11551 r101869 70 70 typedef PLHashNumber (PR_CALLBACK *PLHashFunction)(const void *key); 71 71 typedef PRIntn (PR_CALLBACK *PLHashComparator)(const void *v1, const void *v2); 72 73 #if defined(XP_OS2_VACPP) && defined(VACPP_FLIP) /* for nsSpaceManager.cpp */74 PR_END_EXTERN_C /* and nsHTMLDocument.cpp */75 #endif76 72 typedef PRIntn (PR_CALLBACK *PLHashEnumerator)(PLHashEntry *he, PRIntn i, void *arg); 77 78 #if defined(XP_OS2_VACPP) && defined(VACPP_FLIP)79 PR_BEGIN_EXTERN_C80 #endif81 73 82 74 /* Flag bits in PLHashEnumerator's return value */ … … 112 104 const PLHashAllocOps *allocOps; /* allocation operations */ 113 105 void *allocPriv; /* allocation private data */ 114 #ifdef HASHMETER115 PRUint32 nlookups; /* total number of lookups */116 PRUint32 nsteps; /* number of hash chains traversed */117 PRUint32 ngrows; /* number of table expansions */118 PRUint32 nshrinks; /* number of table contractions */119 #endif120 106 }; 121 107
Note:
See TracChangeset
for help on using the changeset viewer.