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