suicmez/libsuicmez/suicmez_gc.h

55 lines
1.2 KiB
C
Raw Normal View History

2025-12-16 22:08:29 +02:00
#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