71 lines
No EOL
1.5 KiB
C
71 lines
No EOL
1.5 KiB
C
#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;
|
|
|
|
/* Forward declare TypeInfo */
|
|
typedef struct TypeInfo TypeInfo;
|
|
|
|
/* 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
|
|
const TypeInfo *type;
|
|
} ObjHeader;
|
|
|
|
struct TypeInfo {
|
|
uint16_t field_count;
|
|
uint16_t pointer_count;
|
|
const uint8_t *pointer_bitmap;
|
|
};
|
|
|
|
/* 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(const TypeInfo *type, size_t payload_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
|
|
void gc_major_collect(void);
|
|
|
|
static inline void scan_object_fields(Obj *obj);
|
|
|
|
static void mark_obj(Obj *obj);
|
|
|
|
void gc_collect_old(void);
|
|
|
|
#endif // SUICMEZ_GC_H
|