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