|
@@ -147,6 +147,11 @@ static gc_pheader *gc_allocator_new_page( int pid, int block, int size, int kind
|
|
gc_allocator_page_data *p = &ph->alloc;
|
|
gc_allocator_page_data *p = &ph->alloc;
|
|
|
|
|
|
p->block_size = block;
|
|
p->block_size = block;
|
|
|
|
+ p->size_bits = 0;
|
|
|
|
+ while( block < (1<<p->size_bits) )
|
|
|
|
+ p->size_bits++;
|
|
|
|
+ if( block != (1<<p->size_bits) )
|
|
|
|
+ p->size_bits = 0;
|
|
p->max_blocks = max_blocks;
|
|
p->max_blocks = max_blocks;
|
|
p->sizes = NULL;
|
|
p->sizes = NULL;
|
|
if( p->max_blocks > GC_PAGE_SIZE )
|
|
if( p->max_blocks > GC_PAGE_SIZE )
|
|
@@ -521,10 +526,18 @@ static void gc_allocator_init() {
|
|
|
|
|
|
static int gc_allocator_get_block_id( gc_pheader *page, void *block ) {
|
|
static int gc_allocator_get_block_id( gc_pheader *page, void *block ) {
|
|
int offset = (int)((unsigned char*)block - page->base);
|
|
int offset = (int)((unsigned char*)block - page->base);
|
|
- if( offset%page->alloc.block_size != 0 )
|
|
|
|
|
|
+ int bid;
|
|
|
|
+ if( page->alloc.size_bits ) {
|
|
|
|
+ bid = offset >> page->alloc.size_bits;
|
|
|
|
+ if( bid << page->alloc.size_bits != offset )
|
|
|
|
+ return -1;
|
|
|
|
+ } else {
|
|
|
|
+ bid = offset / page->alloc.block_size;
|
|
|
|
+ if( bid * page->alloc.block_size != offset )
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ if( page->alloc.sizes && page->alloc.sizes[bid] == 0 )
|
|
return -1;
|
|
return -1;
|
|
- int bid = offset / page->alloc.block_size;
|
|
|
|
- if( page->alloc.sizes && page->alloc.sizes[bid] == 0 ) return -1;
|
|
|
|
return bid;
|
|
return bid;
|
|
}
|
|
}
|
|
|
|
|