]> git.proxmox.com Git - rustc.git/blobdiff - src/jemalloc/src/ckh.c
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / jemalloc / src / ckh.c
index 3a545966abbf3c03e50bf8bf63f896ba34696d0c..3b423aa22a3e56e7b00a8a02dfb90c829c3dec5d 100644 (file)
@@ -99,7 +99,7 @@ ckh_try_bucket_insert(ckh_t *ckh, size_t bucket, const void *key,
         * Cycle through the cells in the bucket, starting at a random position.
         * The randomness avoids worst-case search overhead as buckets fill up.
         */
-       prng32(offset, LG_CKH_BUCKET_CELLS, ckh->prng_state, CKH_A, CKH_C);
+       offset = (unsigned)prng_lg_range(&ckh->prng_state, LG_CKH_BUCKET_CELLS);
        for (i = 0; i < (ZU(1) << LG_CKH_BUCKET_CELLS); i++) {
                cell = &ckh->tab[(bucket << LG_CKH_BUCKET_CELLS) +
                    ((i + offset) & ((ZU(1) << LG_CKH_BUCKET_CELLS) - 1))];
@@ -141,7 +141,8 @@ ckh_evict_reloc_insert(ckh_t *ckh, size_t argbucket, void const **argkey,
                 * were an item for which both hashes indicated the same
                 * bucket.
                 */
-               prng32(i, LG_CKH_BUCKET_CELLS, ckh->prng_state, CKH_A, CKH_C);
+               i = (unsigned)prng_lg_range(&ckh->prng_state,
+                   LG_CKH_BUCKET_CELLS);
                cell = &ckh->tab[(bucket << LG_CKH_BUCKET_CELLS) + i];
                assert(cell->key != NULL);
 
@@ -247,8 +248,7 @@ ckh_grow(tsd_t *tsd, ckh_t *ckh)
 {
        bool ret;
        ckhc_t *tab, *ttab;
-       size_t lg_curcells;
-       unsigned lg_prevbuckets;
+       unsigned lg_prevbuckets, lg_curcells;
 
 #ifdef CKH_COUNT
        ckh->ngrows++;
@@ -266,11 +266,12 @@ ckh_grow(tsd_t *tsd, ckh_t *ckh)
 
                lg_curcells++;
                usize = sa2u(sizeof(ckhc_t) << lg_curcells, CACHELINE);
-               if (usize == 0) {
+               if (unlikely(usize == 0 || usize > HUGE_MAXCLASS)) {
                        ret = true;
                        goto label_return;
                }
-               tab = (ckhc_t *)ipalloc(tsd, usize, CACHELINE, true);
+               tab = (ckhc_t *)ipallocztm(tsd, usize, CACHELINE, true, NULL,
+                   true, NULL);
                if (tab == NULL) {
                        ret = true;
                        goto label_return;
@@ -282,12 +283,12 @@ ckh_grow(tsd_t *tsd, ckh_t *ckh)
                ckh->lg_curbuckets = lg_curcells - LG_CKH_BUCKET_CELLS;
 
                if (!ckh_rebuild(ckh, tab)) {
-                       idalloc(tsd, tab);
+                       idalloctm(tsd, tab, tcache_get(tsd, false), true, true);
                        break;
                }
 
                /* Rebuilding failed, so back out partially rebuilt table. */
-               idalloc(tsd, ckh->tab);
+               idalloctm(tsd, ckh->tab, tcache_get(tsd, false), true, true);
                ckh->tab = tab;
                ckh->lg_curbuckets = lg_prevbuckets;
        }
@@ -301,8 +302,8 @@ static void
 ckh_shrink(tsd_t *tsd, ckh_t *ckh)
 {
        ckhc_t *tab, *ttab;
-       size_t lg_curcells, usize;
-       unsigned lg_prevbuckets;
+       size_t usize;
+       unsigned lg_prevbuckets, lg_curcells;
 
        /*
         * It is possible (though unlikely, given well behaved hashes) that the
@@ -311,9 +312,10 @@ ckh_shrink(tsd_t *tsd, ckh_t *ckh)
        lg_prevbuckets = ckh->lg_curbuckets;
        lg_curcells = ckh->lg_curbuckets + LG_CKH_BUCKET_CELLS - 1;
        usize = sa2u(sizeof(ckhc_t) << lg_curcells, CACHELINE);
-       if (usize == 0)
+       if (unlikely(usize == 0 || usize > HUGE_MAXCLASS))
                return;
-       tab = (ckhc_t *)ipalloc(tsd, usize, CACHELINE, true);
+       tab = (ckhc_t *)ipallocztm(tsd, usize, CACHELINE, true, NULL, true,
+           NULL);
        if (tab == NULL) {
                /*
                 * An OOM error isn't worth propagating, since it doesn't
@@ -328,7 +330,7 @@ ckh_shrink(tsd_t *tsd, ckh_t *ckh)
        ckh->lg_curbuckets = lg_curcells - LG_CKH_BUCKET_CELLS;
 
        if (!ckh_rebuild(ckh, tab)) {
-               idalloc(tsd, tab);
+               idalloctm(tsd, tab, tcache_get(tsd, false), true, true);
 #ifdef CKH_COUNT
                ckh->nshrinks++;
 #endif
@@ -336,7 +338,7 @@ ckh_shrink(tsd_t *tsd, ckh_t *ckh)
        }
 
        /* Rebuilding failed, so back out partially rebuilt table. */
-       idalloc(tsd, ckh->tab);
+       idalloctm(tsd, ckh->tab, tcache_get(tsd, false), true, true);
        ckh->tab = tab;
        ckh->lg_curbuckets = lg_prevbuckets;
 #ifdef CKH_COUNT
@@ -367,10 +369,10 @@ ckh_new(tsd_t *tsd, ckh_t *ckh, size_t minitems, ckh_hash_t *hash,
        ckh->count = 0;
 
        /*
-        * Find the minimum power of 2 that is large enough to fit aBaseCount
+        * Find the minimum power of 2 that is large enough to fit minitems
         * entries.  We are using (2+,2) cuckoo hashing, which has an expected
         * maximum load factor of at least ~0.86, so 0.75 is a conservative load
-        * factor that will typically allow 2^aLgMinItems to fit without ever
+        * factor that will typically allow mincells items to fit without ever
         * growing the table.
         */
        assert(LG_CKH_BUCKET_CELLS > 0);
@@ -385,11 +387,12 @@ ckh_new(tsd_t *tsd, ckh_t *ckh, size_t minitems, ckh_hash_t *hash,
        ckh->keycomp = keycomp;
 
        usize = sa2u(sizeof(ckhc_t) << lg_mincells, CACHELINE);
-       if (usize == 0) {
+       if (unlikely(usize == 0 || usize > HUGE_MAXCLASS)) {
                ret = true;
                goto label_return;
        }
-       ckh->tab = (ckhc_t *)ipalloc(tsd, usize, CACHELINE, true);
+       ckh->tab = (ckhc_t *)ipallocztm(tsd, usize, CACHELINE, true, NULL, true,
+           NULL);
        if (ckh->tab == NULL) {
                ret = true;
                goto label_return;
@@ -408,9 +411,9 @@ ckh_delete(tsd_t *tsd, ckh_t *ckh)
 
 #ifdef CKH_VERBOSE
        malloc_printf(
-           "%s(%p): ngrows: %"PRIu64", nshrinks: %"PRIu64","
-           " nshrinkfails: %"PRIu64", ninserts: %"PRIu64","
-           " nrelocs: %"PRIu64"\n", __func__, ckh,
+           "%s(%p): ngrows: %"FMTu64", nshrinks: %"FMTu64","
+           " nshrinkfails: %"FMTu64", ninserts: %"FMTu64","
+           " nrelocs: %"FMTu64"\n", __func__, ckh,
            (unsigned long long)ckh->ngrows,
            (unsigned long long)ckh->nshrinks,
            (unsigned long long)ckh->nshrinkfails,
@@ -418,7 +421,7 @@ ckh_delete(tsd_t *tsd, ckh_t *ckh)
            (unsigned long long)ckh->nrelocs);
 #endif
 
-       idalloc(tsd, ckh->tab);
+       idalloctm(tsd, ckh->tab, tcache_get(tsd, false), true, true);
        if (config_debug)
                memset(ckh, 0x5a, sizeof(ckh_t));
 }