Bug 1401099 - Move arena_bin_nonfull_run_get to a method of arena_t. r=njn

--HG--
extra : rebase_source : 808f7ba52a4fc4f99a283ae894296cafac5166da
This commit is contained in:
Mike Hommey 2017-09-15 18:23:33 +09:00
Родитель 003004a71a
Коммит 2c4099f29f
1 изменённых файлов: 48 добавлений и 42 удалений

Просмотреть файл

@ -795,6 +795,10 @@ public:
void* MallocBinHard(arena_bin_t* aBin);
private:
arena_run_t* GetNonFullBinRun(arena_bin_t* aBin);
public:
void Purge(bool aAll);
void HardPurge();
@ -3054,57 +3058,59 @@ arena_t::TrimRunTail(arena_chunk_t* aChunk, arena_run_t* aRun, size_t aOldSize,
DallocRun((arena_run_t*)(uintptr_t(aRun) + aNewSize), aDirty);
}
static arena_run_t *
arena_bin_nonfull_run_get(arena_t *arena, arena_bin_t *bin)
arena_run_t*
arena_t::GetNonFullBinRun(arena_bin_t* aBin)
{
arena_chunk_map_t *mapelm;
arena_run_t *run;
unsigned i, remainder;
arena_chunk_map_t* mapelm;
arena_run_t* run;
unsigned i, remainder;
/* Look for a usable run. */
mapelm = arena_run_tree_first(&bin->runs);
if (mapelm) {
/* run is guaranteed to have available space. */
arena_run_tree_remove(&bin->runs, mapelm);
run = (arena_run_t *)(mapelm->bits & ~pagesize_mask);
return (run);
}
/* No existing runs have any space available. */
/* Look for a usable run. */
mapelm = arena_run_tree_first(&aBin->runs);
if (mapelm) {
/* run is guaranteed to have available space. */
arena_run_tree_remove(&aBin->runs, mapelm);
run = (arena_run_t*)(mapelm->bits & ~pagesize_mask);
return run;
}
/* No existing runs have any space available. */
/* Allocate a new run. */
run = arena->AllocRun(bin, bin->run_size, false, false);
if (!run)
return nullptr;
/*
* Don't initialize if a race in arena_t::AllocRun() allowed an existing
* run to become usable.
*/
if (run == bin->runcur)
return (run);
/* Allocate a new run. */
run = AllocRun(aBin, aBin->run_size, false, false);
if (!run)
return nullptr;
/*
* Don't initialize if a race in arena_t::RunAlloc() allowed an existing
* run to become usable.
*/
if (run == aBin->runcur) {
return run;
}
/* Initialize run internals. */
run->bin = bin;
/* Initialize run internals. */
run->bin = aBin;
for (i = 0; i < bin->regs_mask_nelms - 1; i++)
run->regs_mask[i] = UINT_MAX;
remainder = bin->nregs & ((1U << (SIZEOF_INT_2POW + 3)) - 1);
if (remainder == 0)
run->regs_mask[i] = UINT_MAX;
else {
/* The last element has spare bits that need to be unset. */
run->regs_mask[i] = (UINT_MAX >> ((1U << (SIZEOF_INT_2POW + 3))
- remainder));
}
for (i = 0; i < aBin->regs_mask_nelms - 1; i++) {
run->regs_mask[i] = UINT_MAX;
}
remainder = aBin->nregs & ((1U << (SIZEOF_INT_2POW + 3)) - 1);
if (remainder == 0) {
run->regs_mask[i] = UINT_MAX;
} else {
/* The last element has spare bits that need to be unset. */
run->regs_mask[i] = (UINT_MAX >> ((1U << (SIZEOF_INT_2POW + 3))
- remainder));
}
run->regs_minelm = 0;
run->regs_minelm = 0;
run->nfree = bin->nregs;
run->nfree = aBin->nregs;
#if defined(MOZ_DEBUG) || defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED)
run->magic = ARENA_RUN_MAGIC;
run->magic = ARENA_RUN_MAGIC;
#endif
bin->stats.curruns++;
return (run);
aBin->stats.curruns++;
return run;
}
/* bin->runcur must have space available before this function is called. */
@ -3127,7 +3133,7 @@ arena_t::MallocBinEasy(arena_bin_t* aBin, arena_run_t* aRun)
void*
arena_t::MallocBinHard(arena_bin_t* aBin)
{
aBin->runcur = arena_bin_nonfull_run_get(this, aBin);
aBin->runcur = GetNonFullBinRun(aBin);
if (!aBin->runcur) {
return nullptr;
}