64 bit support in case we want it...it appears that 64 bit binares are slower
[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 #ifdef RAW
123 struct RuntimeHash * lockRedirectTbl;
124 #endif
125 #endif
126
127 #ifdef FASTCHECK
128 extern struct ___Object___ * ___fcrevert___;
129 #endif
130
131 #ifdef MULTICORE
132 void flagorand(void * ptr, int ormask, int andmask, struct parameterwrapper ** queues, int length);
133 void flagorandinit(void * ptr, int ormask, int andmask);
134 void enqueueObject(void * ptr, struct parameterwrapper ** queues, int length);
135 #ifdef RAW
136 void enqueueObject_I(void * ptr, struct parameterwrapper ** queues, int length);
137 #ifdef RAWPROFILE
138 inline void setTaskExitIndex(int index);
139 inline void addNewObjInfo(void * nobj);
140 #endif
141 #endif
142 int * getAliasLock(void ** ptrs, int length, struct RuntimeHash * tbl);
143 void addAliasLock(void * ptr, int lock);
144 #else
145 void flagorand(void * ptr, int ormask, int andmask);
146 void flagorandinit(void * ptr, int ormask, int andmask);
147 void enqueueObject(void * ptr);
148 #endif
149 void executetasks();
150 void processtasks();
151
152 #ifdef MULTICORE
153 void transferObject(struct transObjInfo * transObj);
154 #endif
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 #ifdef RAW
207 int enqueuetasks_I(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags);
208 #endif
209
210 #endif
211
212 #endif