gc: superficial cleaning
[nit.git] / clib / gc.h
1 /* This file is part of NIT ( http://www.nitlanguage.org ).
2 *
3 * Copyright 2009 Julien Chevalier <chevjulien@gmail.com>
4 *
5 * This file is free software, which comes along with NIT. This software is
6 * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
8 * PARTICULAR PURPOSE. You can modify it is you want, provided this header
9 * is kept unaltered, and a notification of the changes is added.
10 * You are allowed to redistribute it and sell it, alone or is a part of
11 * another product.
12 */
13
14 #ifndef GC
15 #define GC
16
17 #include <stdlib.h>
18 #include <stdio.h>
19 #include <errno.h>
20 #include "nit_common.h"
21 #include "gc_static_objects_list.h"
22
23 /* Markbit manipulations */
24 #define GET_MARKBIT(x) (((val_t)((x)[0].vft)) & 1)
25 #define SET_MARKBIT(x) ((x)->vft = (void*)(((bigint)((x)->vft)) | 1))
26 #define REMOVE_MARKBIT(x) ((x) ^ 1)
27
28 #define HEAP_ACTIVE_SIZE_MIN 3000
29
30 typedef struct heap {
31 char *heapPointer;
32 unsigned long size;
33 } heap;
34
35 typedef struct TBOX_struct {
36 const classtable_elt_t *vft;
37 char *val;
38 bigint object_id;
39 } *BOX_struct;
40
41 heap *heapActive;
42 heap *heapInactive;
43 char *allocationPointer;
44 char *evacuationPointer;
45 char *scavengingPointer;
46
47 unsigned long heapActiveUsedSize;
48
49 GC_List staticObjects;
50
51 void Nit_gc_init(void);
52
53 val_t GC_evacuation(obj_t object);
54
55 void GC_scavenging(void);
56
57 void* Nit_gc_malloc(size_t size);
58
59 void GC_add_static_object(val_t *pointer);
60
61 #endif