Commit 6982eabf authored by Chris Toshok's avatar Chris Toshok

store frequently used values in the Block. also give scanForNext an out from...

store frequently used values in the Block.  also give scanForNext an out from entering the loop at all
parent 88cbdd00
......@@ -130,6 +130,9 @@ static Block* alloc_block(uint64_t size, Block** prev) {
Block* rtn = (Block*)small_arena.doMmap(sizeof(Block));
assert(rtn);
rtn->size = size;
rtn->num_obj = BLOCK_SIZE / size;
rtn->min_obj_index = (BLOCK_HEADER_SIZE + size - 1) / size;
rtn->atoms_per_obj = size / ATOM_SIZE;
rtn->prev = prev;
rtn->next = NULL;
......@@ -371,7 +374,7 @@ GCAllocation* Heap::getAllocationFromInteriorPointer(void* ptr) {
if (obj_idx < b->minObjIndex() || obj_idx >= b->numObjects())
return NULL;
int atom_idx = obj_idx * (size / ATOM_SIZE);
int atom_idx = obj_idx * b->atomsPerObj();
if (b->isfree.isSet(atom_idx))
return NULL;
......
......@@ -87,18 +87,19 @@ public:
void clear(int idx) { data[idx / 64] &= ~(1UL << (idx % 64)); }
int scanForNext(Scanner& sc) {
uint64_t mask = 0;
while (true) {
mask = data[sc.next_to_check];
if (likely(mask != 0L)) {
break;
}
sc.next_to_check++;
if (sc.next_to_check == N / 64) {
sc.next_to_check = 0;
return -1;
uint64_t mask = data[sc.next_to_check];
if (unlikely(mask == 0L)) {
while (true) {
sc.next_to_check++;
if (sc.next_to_check == N / 64) {
sc.next_to_check = 0;
return -1;
}
mask = data[sc.next_to_check];
if (likely(mask != 0L)) {
break;
}
}
}
......@@ -134,7 +135,10 @@ struct Block {
union {
struct {
Block* next, **prev;
uint64_t size;
uint32_t size;
uint16_t num_obj;
uint8_t min_obj_index;
uint8_t atoms_per_obj;
Bitmap<ATOMS_PER_BLOCK> isfree;
Bitmap<ATOMS_PER_BLOCK>::Scanner next_to_check;
void* _header_end[0];
......@@ -142,11 +146,11 @@ struct Block {
Atoms atoms[ATOMS_PER_BLOCK];
};
inline int minObjIndex() { return (BLOCK_HEADER_SIZE + size - 1) / size; }
inline int minObjIndex() const { return min_obj_index; }
inline int numObjects() { return BLOCK_SIZE / size; }
inline int numObjects() const { return num_obj; }
inline int atomsPerObj() { return size / ATOM_SIZE; }
inline int atomsPerObj() const { return atoms_per_obj; }
static Block* forPointer(void* ptr) { return (Block*)((uintptr_t)ptr & ~(BLOCK_SIZE - 1)); }
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment