소스 검색

minor gc mark optim

Nicolas Cannasse 2 년 전
부모
커밋
45b92d6a1f
3개의 변경된 파일20개의 추가작업 그리고 5개의 파일을 삭제
  1. 16 3
      src/allocator.c
  2. 3 2
      src/allocator.h
  3. 1 0
      src/gc.c

+ 16 - 3
src/allocator.c

@@ -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;
 
 	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->sizes = NULL;
 	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 ) {
 	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;
-	int bid = offset / page->alloc.block_size;
-	if( page->alloc.sizes && page->alloc.sizes[bid] == 0 ) return -1;
 	return bid;
 }
 

+ 3 - 2
src/allocator.h

@@ -15,9 +15,10 @@ typedef struct _gc_freelist {
 
 typedef struct {
 	int block_size;
+	unsigned char size_bits;
+	unsigned char need_flush;
+	short first_block;
 	int max_blocks;
-	int first_block;
-	bool need_flush;
 	// mutable
 	gc_freelist free;
 	unsigned char *sizes;

+ 1 - 0
src/gc.c

@@ -630,6 +630,7 @@ static void gc_flush_mark() {
 			}
 			p = *block++;
 			pos++;
+			if( !p ) continue;
 			page = GC_GET_PAGE(p);
 			if( !page || !INPAGE(p,page) ) continue;
 			int bid = gc_allocator_get_block_id(page,p);