3b4dd34cefad5b012ad163a529066013ed1e281a
[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 #ifndef INTPTR
12 #ifdef BIT64
13 #define INTPTR long
14 #else
15 #define INTPTR int
16 #endif
17 #endif
18
19 extern void * curr_heapbase;
20 extern void * curr_heaptop;
21
22 #define TAGARRAYINTERVAL 10
23 #define OBJECTARRAYINTERVAL 10
24
25 #define ARRAYSET(array, type, index, value) \
26   ((type *)(& (& array->___length___)[1]))[index]=value
27
28 #define ARRAYGET(array, type, index) \
29   ((type *)(& (& array->___length___)[1]))[index]
30
31 #ifdef OPTIONAL
32 #define OPTARG(x) , x
33 #else
34 #define OPTARG(x)
35 #endif
36
37 #ifdef DSTM
38 __attribute__((malloc)) void * allocate_newglobal(int type);
39 __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, int length);
40 #endif
41
42 #ifdef STM
43 __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type);
44 __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length);
45 #endif
46
47 #ifdef PRECISE_GC
48 #include "garbage.h"
49 __attribute__((malloc)) void * allocate_new(void *, int type);
50 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void *, int type, int length);
51 __attribute__((malloc)) struct ___String___ * NewString(void *, const char *str,int length);
52 __attribute__((malloc)) struct ___TagDescriptor___ * allocate_tag(void *ptr, int index);
53 #else
54 __attribute__((malloc)) void * allocate_new(int type);
55 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length);
56 __attribute__((malloc)) struct ___String___ * NewString(const char *str,int length);
57 __attribute__((malloc)) struct ___TagDescriptor___ * allocate_tag(int index);
58 #endif
59
60
61
62 void initializeexithandler();
63 void failedboundschk();
64 void failednullptr();
65 void abort_task();
66 void injectinstructionfailure();
67 void createstartupobject();
68
69 #ifdef PRECISE_GC
70 #define VAR(name) ___params___->name
71 #define CALL00(name) name(struct name ## _params * ___params___)
72 #define CALL01(name, alt) name(struct name ## _params * ___params___)
73 #define CALL02(name, alt1, alt2) name(struct name ## _params * ___params___)
74 #define CALL11(name,rest, alt) name(struct name ## _params * ___params___, rest)
75 #define CALL12(name,rest, alt1, alt2) name(struct name ## _params * ___params___, rest)
76 #define CALL22(name, rest, rest2, alt1, alt2) name(struct name ## _params * ___params___, rest, rest2)
77 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(struct name ## _params * ___params___, rest, rest2)
78 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2)
79 #define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2, rest3)
80 #else
81 #define VAR(name) name
82 #define CALL00(name) name()
83 #define CALL01(name, alt) name(alt)
84 #define CALL02(name, alt1, alt2) name(alt1, alt2)
85 #define CALL11(name,rest, alt) name(alt)
86 #define CALL12(name,rest, alt1, alt2) name(alt1, alt2)
87 #define CALL22(name, rest, rest2, alt1, alt2) name(alt1, alt2)
88 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(alt1, alt2, alt3)
89 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
90 #define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
91 #endif
92
93 #ifdef TASK
94 #include "SimpleHash.h"
95 #include "chash.h"
96 #ifndef MULTICORE
97 #include "ObjectHash.h"
98 #include "structdefs.h"
99 #endif
100 #include "task.h"
101 #ifdef OPTIONAL
102 #include "optionalstruct.h"
103 #endif
104
105 #ifdef OPTIONAL
106 struct failedtasklist {
107   struct taskdescriptor *task;
108   int index;
109   int numflags;
110   int *flags;
111   struct failedtasklist *next;
112 };
113 #endif
114
115 #ifdef MULTICORE
116 struct transObjInfo {
117   void * objptr;
118   int targetcore;
119   int * queues;
120   int length;
121 };
122 struct RuntimeHash * lockRedirectTbl;
123 #endif
124
125 #ifdef FASTCHECK
126 extern struct ___Object___ * ___fcrevert___;
127 #endif
128
129 #ifdef MULTICORE
130 inline int receiveObject(void);
131 void flagorand(void * ptr, int ormask, int andmask, struct parameterwrapper ** queues, int length);
132 void flagorandinit(void * ptr, int ormask, int andmask);
133 void enqueueObject(void * ptr, struct parameterwrapper ** queues, int length);
134 #ifdef PROFILE
135 inline void setTaskExitIndex(int index);
136 inline void addNewObjInfo(void * nobj);
137 #endif
138 int * getAliasLock(void ** ptrs, int length, struct RuntimeHash * tbl);
139 void addAliasLock(void * ptr, int lock);
140 #else
141 void flagorand(void * ptr, int ormask, int andmask);
142 void flagorandinit(void * ptr, int ormask, int andmask);
143 void enqueueObject(void * ptr);
144 #endif
145 void executetasks();
146 void processtasks();
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
199 #endif
200
201 #endif