bug fix in multicore gc
[IRC.git] / Robust / src / Runtime / runtime.h
1 #ifndef RUNTIME
2 #define RUNTIME
3 #ifndef MULTICORE
4 #include <setjmp.h>
5 extern jmp_buf error_handler;
6 extern int instructioncount;
7 extern int failurecount;
8 #endif
9 #ifdef DSTM
10 #include "dstm.h"
11 #endif
12
13 #ifndef INTPTR
14 #ifdef BIT64
15 #define INTPTR long
16 #else
17 #define INTPTR int
18 #endif
19 #endif
20
21 extern void * curr_heapbase;
22 extern void * curr_heaptop;
23
24 #define TAGARRAYINTERVAL 10
25 #define OBJECTARRAYINTERVAL 10
26
27 #define ARRAYSET(array, type, index, value) \
28   ((type *)(& (& array->___length___)[1]))[index]=value
29
30 #define ARRAYGET(array, type, index) \
31   ((type *)(& (& array->___length___)[1]))[index]
32
33 #ifdef OPTIONAL
34 #define OPTARG(x) , x
35 #else
36 #define OPTARG(x)
37 #endif
38
39 #ifdef DSTM
40 __attribute__((malloc)) void * allocate_newglobal(int type);
41 __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, int length);
42 #endif
43
44 #ifdef STM
45 __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type);
46 __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length);
47 #endif
48
49 #ifdef PRECISE_GC
50 #include "garbage.h"
51 __attribute__((malloc)) void * allocate_new(void *, int type);
52 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void *, int type, int length);
53 __attribute__((malloc)) struct ___String___ * NewString(void *, const char *str,int length);
54 __attribute__((malloc)) struct ___TagDescriptor___ * allocate_tag(void *ptr, int index);
55 #elif defined MULTICORE_GC
56 __attribute__((malloc)) void * allocate_new(void *, int type);
57 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void *, int type, int length);
58 __attribute__((malloc)) struct ___String___ * NewString(void *, const char *str,int length);
59 __attribute__((malloc)) struct ___TagDescriptor___ * allocate_tag(void *ptr, int index);
60 #else
61 __attribute__((malloc)) void * allocate_new(int type);
62 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length);
63 __attribute__((malloc)) struct ___String___ * NewString(const char *str,int length);
64 __attribute__((malloc)) struct ___TagDescriptor___ * allocate_tag(int index);
65 #endif
66
67
68
69 void initializeexithandler();
70 void failedboundschk();
71 void failednullptr();
72 void abort_task();
73 void injectinstructionfailure();
74 void createstartupobject();
75
76 #ifdef PRECISE_GC
77 #define VAR(name) ___params___->name
78 #define CALL00(name) name(struct name ## _params * ___params___)
79 #define CALL01(name, alt) name(struct name ## _params * ___params___)
80 #define CALL02(name, alt1, alt2) name(struct name ## _params * ___params___)
81 #define CALL11(name,rest, alt) name(struct name ## _params * ___params___, rest)
82 #define CALL12(name,rest, alt1, alt2) name(struct name ## _params * ___params___, rest)
83 #define CALL22(name, rest, rest2, alt1, alt2) name(struct name ## _params * ___params___, rest, rest2)
84 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(struct name ## _params * ___params___, rest, rest2)
85 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2)
86 #define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2, rest3)
87 #else
88 #define VAR(name) name
89 #define CALL00(name) name()
90 #define CALL01(name, alt) name(alt)
91 #define CALL02(name, alt1, alt2) name(alt1, alt2)
92 #define CALL11(name,rest, alt) name(alt)
93 #define CALL12(name,rest, alt1, alt2) name(alt1, alt2)
94 #define CALL22(name, rest, rest2, alt1, alt2) name(alt1, alt2)
95 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(alt1, alt2, alt3)
96 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
97 #define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
98 #endif
99
100 #ifdef TASK
101 #include "SimpleHash.h"
102 #ifndef MULTICORE
103 #include "chash.h"
104 #include "ObjectHash.h"
105 #include "structdefs.h"
106 #endif
107 #include "task.h"
108 #ifdef OPTIONAL
109 #include "optionalstruct.h"
110 #endif
111
112 #ifdef OPTIONAL
113 struct failedtasklist {
114   struct taskdescriptor *task;
115   int index;
116   int numflags;
117   int *flags;
118   struct failedtasklist *next;
119 };
120 #endif
121
122 #ifdef MULTICORE
123 struct transObjInfo {
124   void * objptr;
125   int targetcore;
126   int * queues;
127   int length;
128 };
129 #endif
130
131 #ifdef FASTCHECK
132 extern struct ___Object___ * ___fcrevert___;
133 #endif
134
135 #ifdef MULTICORE
136 inline void run(void * arg);
137 int receiveObject(void);
138 void flagorand(void * ptr, int ormask, int andmask, struct parameterwrapper ** queues, int length);
139 void flagorandinit(void * ptr, int ormask, int andmask);
140 void enqueueObject(void * ptr, struct parameterwrapper ** queues, int length);
141 #ifdef PROFILE
142 inline void setTaskExitIndex(int index);
143 inline void addNewObjInfo(void * nobj);
144 #endif
145 int * getAliasLock(void ** ptrs, int length, struct RuntimeHash * tbl);
146 void addAliasLock(void * ptr, int lock);
147 void * smemalloc(int size, int * allocsize);
148 #else
149 void flagorand(void * ptr, int ormask, int andmask);
150 void flagorandinit(void * ptr, int ormask, int andmask);
151 void enqueueObject(void * ptr);
152 #endif
153 void executetasks();
154 void processtasks();
155
156 #ifndef MULTICORE
157 struct tagobjectiterator {
158   int istag; /* 0 if object iterator, 1 if tag iterator */
159   struct ObjectIterator it; /* Object iterator */
160   struct ObjectHash * objectset;
161 #ifdef OPTIONAL
162   int failedstate;
163 #endif
164   int slot;
165   int tagobjindex; /* Index for tag or object depending on use */
166   /*if tag we have an object binding */
167   int tagid;
168   int tagobjectslot;
169   /*if object, we may have one or more tag bindings */
170   int numtags;
171   int tagbindings[MAXTASKPARAMS-1]; /* list slots */
172 };
173
174 struct parameterwrapper {
175   struct parameterwrapper *next;
176   struct ObjectHash * objectset;
177   int numberofterms;
178   int * intarray;
179   int numbertags;
180   int * tagarray;
181   struct taskdescriptor * task;
182   int slot;
183   struct tagobjectiterator iterators[MAXTASKPARAMS-1];
184 };
185 #endif
186
187 struct taskparamdescriptor {
188   struct taskdescriptor * task;
189   int numParameters;
190   void ** parameterArray;
191 #ifdef OPTIONAL
192   int * failed;
193 #endif
194 };
195
196 int hashCodetpd(struct taskparamdescriptor *);
197 int comparetpd(struct taskparamdescriptor *, struct taskparamdescriptor *);
198
199 void toiReset(struct tagobjectiterator * it);
200 int toiHasNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * failed));
201 void toiNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * failed));
202 void processobject(struct parameterwrapper *parameter, int index, struct parameterdescriptor *pd, int *iteratorcount, int * statusarray, int numparams);
203 void processtags(struct parameterdescriptor *pd, int index, struct parameterwrapper *parameter, int * iteratorcount, int *statusarray, int numparams);
204 void builditerators(struct taskdescriptor * task, int index, struct parameterwrapper * parameter);
205 int enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags);
206
207 #endif
208
209 #endif