-
Notifications
You must be signed in to change notification settings - Fork 1
/
gc.h
59 lines (47 loc) · 1.48 KB
/
gc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
typedef unsigned char byte;
typedef struct ClassDescriptor {
char *name;
int size; /* size in bytes of struct */
int num_fields;
/* offset from ptr to object of only fields that are managed ptrs */
int *field_offsets;
} ClassDescriptor;
typedef struct Object {
ClassDescriptor *class;
byte marked;
struct Object *forwarded; // where we've moved this object
} Object;
typedef struct String /* extends Object */ {
ClassDescriptor *class;
byte marked;
Object *forwarded; // where we've moved this object
int length;
char str[];
/* the string starts at the end of fixed fields; this field
* does not take any room in the structure */
} String;
extern ClassDescriptor String_class;
#define MAX_ROOTS 100
extern Object **_roots[MAX_ROOTS];
extern int _rp;
// GC interface
extern void gc_init(int size);
extern void gc();
extern void gc_done();
extern Object *gc_alloc(ClassDescriptor *class);
extern String *gc_alloc_string(int size);
extern char *gc_get_state();
extern int valid_gc_space(int size);
extern int walk_graph(Object* o);
extern int valid_gc_space(int size);
extern void print_roots();
extern void print_debug(char* msg);
extern int gc_num_roots();
extern void compact();
extern void calculate_forwarded();
extern void moveto_forwarded();
extern void reset_mark();
extern int get_string_length(Object* o);
#define gc_save_rp int __rp = _rp;
#define gc_add_root(p) _roots[_rp++] = (Object **)(&(p));
#define gc_restore_roots _rp = __rp;