#include <stdlib.h>
#include <setjmp.h>
-//typedef struct {
-// uint64_t objmap;
-// uint8_t data[];
-//} obj_t;
-
typedef struct root_t {
struct root_t* next;
uintptr_t* address;
void* gc_object(uint64_t objmap, size_t num_slots)
{
- (void)objmap;
- (void)num_slots;
- return NULL;
-// obj_t* obj = heap_allocate(Heap, num_slots+1);
-// obj->objmap = objmap;
-// obj++;
-// return obj;
+ return heap_allocate(Heap, objmap, num_slots);
}
void* gc_allocate(size_t size)
{
size_t slot_sz = sizeof(uintptr_t);
size_t num_slots = (size + slot_sz - 1) / slot_sz;
- return heap_allocate(Heap, UINT16_MAX, num_slots + 1);
+ return heap_allocate(Heap, UINT16_MAX, num_slots);
}
static void gc_scan_object(void* object) {
void* heap_allocate(heap_t* heap, uint64_t ptrmap, uintptr_t num_slots)
{
void* obj = NULL;
- if (num_slots <= MAX_NUM_SLOTS) {
- obj = allocate_small_block(heap, ptrmap, num_slots);
+ if (num_slots+1 <= MAX_NUM_SLOTS) {
+ obj = allocate_small_block(heap, ptrmap, num_slots+1);
} else {
obj = allocate_large_block(heap, ptrmap, num_slots);
}
TEST(Verify_Allocate_should_allocate_a_new_segment_if_the_subheap_is_empty) {
heap_t* heap = heap_create();
CHECK(NULL != heap_allocate(heap, 0, 1));
- CHECK(heap->heaps[0].available != NULL);
+ CHECK(heap->heaps[1].available != NULL);
heap_destroy(heap);
}
TEST(Verify_Allocate_should_allocate_a_new_segment_if_the_current_segment_is_full) {
heap_t* heap = heap_create();
CHECK(NULL != heap_allocate(heap, 0, 1));
- heap->heaps[0].available->blockmap[0] = 1 << ((sizeof(uint16_t) * 8) - 1);
- heap->heaps[0].available->blockmap[16] = 1 << ((sizeof(uint16_t) * 8) - 1);
+ heap->heaps[1].available->blockmap[0] = 1 << ((sizeof(uint16_t) * 8) - 1);
+ heap->heaps[1].available->blockmap[16] = 1 << ((sizeof(uint16_t) * 8) - 1);
CHECK(NULL != heap_allocate(heap, 0, 1));
- CHECK(heap->heaps[0].available == NULL);
- CHECK(heap->heaps[0].full != NULL);
- CHECK(heap->heaps[0].full->next == NULL);
+ CHECK(heap->heaps[1].available == NULL);
+ CHECK(heap->heaps[1].full != NULL);
+ CHECK(heap->heaps[1].full->next == NULL);
heap_destroy(heap);
}