From f9a7abdd9c28656b5ca01c062a9de04637ad2e1f Mon Sep 17 00:00:00 2001 From: "Sunrin SHIMURA (keen)" <3han5chou7@gmail.com> Date: Sun, 19 Jun 2016 10:39:58 +0900 Subject: [PATCH] treat cases where size > UNIT_SIZE in is_`marked_at`, `mark_at` --- extlib/benz/gc/bitmap.c | 42 +++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/extlib/benz/gc/bitmap.c b/extlib/benz/gc/bitmap.c index ea54902d..aca4ff69 100644 --- a/extlib/benz/gc/bitmap.c +++ b/extlib/benz/gc/bitmap.c @@ -204,31 +204,37 @@ PIC_INLINE void mark_at(struct heap_page *page, size_t index, size_t size) { size_t mask = ~(-1 << size); + size_t mark_size; - page->bitmap[index / UNIT_SIZE] |= mask << (index % UNIT_SIZE); - if (numofbits(page->bitmap[index / UNIT_SIZE]) == UNIT_SIZE) { - page->index[index / UNIT_SIZE / UNIT_SIZE] |= 1 << ((index / UNIT_SIZE) % UNIT_SIZE); - } - - if (UNIT_SIZE < index % UNIT_SIZE + size) { - page->bitmap[index / UNIT_SIZE + 1] |= mask >> (UNIT_SIZE - index % UNIT_SIZE); - if (numofbits(page->bitmap[index / UNIT_SIZE + 1]) == UNIT_SIZE) { - page->index[(index / UNIT_SIZE + 1) / UNIT_SIZE] |= 1 << ((index / UNIT_SIZE + 1) % UNIT_SIZE); - } + while (0 < size) { + if (size <= UNIT_SIZE - (index % UNIT_SIZE)) + mark_size = size; + else + mark_size = UNIT_SIZE - (index % UNIT_SIZE); + page->bitmap[index / UNIT_SIZE] |= ~(-1 << mark_size) << (index % UNIT_SIZE); + size -= mark_size; + index += mark_size; } } PIC_INLINE int is_marked_at(uint32_t *bitmap, size_t index, size_t size) { - size_t mask = ~(-1 << size); - size_t map; + size_t test_size; - map = bitmap[index / UNIT_SIZE] >> (index % UNIT_SIZE); - if (UNIT_SIZE < index % UNIT_SIZE + size) - map |= bitmap[index / UNIT_SIZE + 1] << (UNIT_SIZE - index % UNIT_SIZE); + while (0 < size) { + if (size <= UNIT_SIZE - (index % UNIT_SIZE)) + test_size = size; + else + test_size = UNIT_SIZE - (index % UNIT_SIZE); - return mask & map; + if ((bitmap[index / UNIT_SIZE] >> (index % UNIT_SIZE)) & ~(-1 << test_size)) + return 1; + size -= test_size; + index += test_size; + } + + return 0; } @@ -236,10 +242,10 @@ is_marked_at(uint32_t *bitmap, size_t index, size_t size) static void * heap_alloc_heap_page(struct heap_page *page, size_t nunits) { - size_t index; + size_t index, jump; union header *p; - for (index = page->current; index < HEADER_SIZE - (nunits + 1) ; ++index) { + for (index = page->current; index < HEADER_SIZE - (nunits + 1); ++index) { if (index % UNIT_SIZE == 0 && is_marked_at(page->index, index / UNIT_SIZE, 1)) { index += UNIT_SIZE - 1; continue;