Add GC
TODO: add pointer bitmaps
This commit is contained in:
parent
a32db747e6
commit
447499dede
2 changed files with 271 additions and 0 deletions
55
libsuicmez/suicmez_gc.h
Normal file
55
libsuicmez/suicmez_gc.h
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#ifndef SUICMEZ_GC_H
|
||||
#define SUICMEZ_GC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define YOUNG_SIZE (1024 * 1024 * 2)
|
||||
#define SURVIVOR_SIZE (512 * 1024)
|
||||
#define OLD_SIZE (16 * 1024 * 1024)
|
||||
#define CARD_SIZE 512
|
||||
#define PROMOTION_AGE 2
|
||||
#define MAX_ROOTS 1024
|
||||
#define MARKED 0x1
|
||||
|
||||
/* Forward declare Obj so ObjHeader can reference it */
|
||||
typedef struct Obj Obj;
|
||||
|
||||
/* Header must come first */
|
||||
typedef struct ObjHeader {
|
||||
uint32_t size; // total object size incl header
|
||||
uint16_t age;
|
||||
uint16_t flags;
|
||||
Obj *forwarding; // non-NULL if moved
|
||||
} ObjHeader;
|
||||
|
||||
/* Full object definition */
|
||||
struct Obj {
|
||||
ObjHeader header;
|
||||
void *fields[];
|
||||
};
|
||||
|
||||
// --- API ---
|
||||
// Initialize the GC
|
||||
void gc_init(void);
|
||||
|
||||
// Shutdown GC
|
||||
void gc_shutdown(void);
|
||||
|
||||
// Allocate object in young generation
|
||||
void* gc_alloc_young(size_t size);
|
||||
|
||||
// Root management
|
||||
void gc_add_root(void **ptr);
|
||||
void gc_remove_root(void **ptr);
|
||||
|
||||
// Write barrier for old->young references
|
||||
void gc_write_barrier(void *src, void *dst);
|
||||
|
||||
// Minor GC slice (incremental)
|
||||
void gc_minor_collect_slice(size_t max_objects);
|
||||
|
||||
// Trigger major GC (async background)
|
||||
void gc_major_collect(void);
|
||||
|
||||
#endif // SUICMEZ_GC_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue