OMG ADD PROPER PTR BTIMAPOPA AND MEQATADATA
This commit is contained in:
parent
a487c3b763
commit
859e7d7560
2 changed files with 22 additions and 12 deletions
|
|
@ -132,9 +132,7 @@ static void gc_minor_collect(void) {
|
|||
size_t fields =
|
||||
(obj->header.size - sizeof(ObjHeader)) / sizeof(void*);
|
||||
|
||||
for (size_t i = 0; i < fields; i++) {
|
||||
obj->fields[i] = forward((Obj*)obj->fields[i]);
|
||||
}
|
||||
scan_object_fields(obj);
|
||||
p += obj->header.size;
|
||||
}
|
||||
}
|
||||
|
|
@ -146,9 +144,7 @@ static void gc_minor_collect(void) {
|
|||
size_t fields =
|
||||
(obj->header.size - sizeof(ObjHeader)) / sizeof(void*);
|
||||
|
||||
for (size_t i = 0; i < fields; i++) {
|
||||
obj->fields[i] = forward((Obj*)obj->fields[i]);
|
||||
}
|
||||
scan_object_fields(obj);
|
||||
|
||||
scan += obj->header.size;
|
||||
}
|
||||
|
|
@ -168,15 +164,11 @@ static void gc_minor_collect(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void *gc_alloc(size_t payload_size) {
|
||||
size_t size = payload_size + sizeof(ObjHeader);
|
||||
void *gc_alloc(const TypeInfo *type, size_t payload_size) {
|
||||
size_t size = sizeof(ObjHeader) + payload_size;
|
||||
|
||||
if (gc.from_ptr + size > gc.from_space + gc.young_size) {
|
||||
gc_minor_collect();
|
||||
if (gc.from_ptr + size > gc.from_space + gc.young_size) {
|
||||
fprintf(stderr, "GC: out of memory\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
Obj *obj = (Obj*)gc.from_ptr;
|
||||
|
|
@ -184,11 +176,22 @@ void *gc_alloc(size_t payload_size) {
|
|||
obj->header.age = 0;
|
||||
obj->header.flags = 0;
|
||||
obj->header.forwarding = NULL;
|
||||
obj->header.type = type;
|
||||
|
||||
gc.from_ptr += size;
|
||||
return obj;
|
||||
}
|
||||
|
||||
static inline void scan_object_fields(Obj *obj) {
|
||||
const TypeInfo *t = obj->header.type;
|
||||
|
||||
for (uint16_t i = 0; i < t->field_count; i++) {
|
||||
if (t->pointer_bitmap[i]) {
|
||||
obj->fields[i] = forward((Obj*)obj->fields[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void gc_init(void) {
|
||||
gc.young_size = YOUNG_SIZE;
|
||||
gc.old_size = OLD_SIZE;
|
||||
|
|
|
|||
|
|
@ -21,8 +21,15 @@ typedef struct ObjHeader {
|
|||
uint16_t age;
|
||||
uint16_t flags;
|
||||
Obj *forwarding; // non-NULL if moved
|
||||
const TypeInfo *type;
|
||||
} ObjHeader;
|
||||
|
||||
typedef struct TypeInfo {
|
||||
uint16_t field_count;
|
||||
uint16_t pointer_count;
|
||||
const uint8_t *pointer_bitmap;
|
||||
} TypeInfo;
|
||||
|
||||
/* Full object definition */
|
||||
struct Obj {
|
||||
ObjHeader header;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue