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