add Tilera version stuff in buildscript and removes some redundant codes to avoid...
[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 #ifndef MULTICORE
96 #include "chash.h"
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 void run(void * arg);
131 int receiveObject(void);
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 PROFILE
136 inline void setTaskExitIndex(int index);
137 inline void addNewObjInfo(void * nobj);
138 #endif
139 int * getAliasLock(void ** ptrs, int length, struct RuntimeHash * tbl);
140 void addAliasLock(void * ptr, int lock);
141 #else
142 void flagorand(void * ptr, int ormask, int andmask);
143 void flagorandinit(void * ptr, int ormask, int andmask);
144 void enqueueObject(void * ptr);
145 #endif
146 void executetasks();
147 void processtasks();
148
149 #ifndef MULTICORE
150 struct tagobjectiterator {
151   int istag; /* 0 if object iterator, 1 if tag iterator */
152   struct ObjectIterator it; /* Object iterator */
153   struct ObjectHash * objectset;
154 #ifdef OPTIONAL
155   int failedstate;
156 #endif
157   int slot;
158   int tagobjindex; /* Index for tag or object depending on use */
159   /*if tag we have an object binding */
160   int tagid;
161   int tagobjectslot;
162   /*if object, we may have one or more tag bindings */
163   int numtags;
164   int tagbindings[MAXTASKPARAMS-1]; /* list slots */
165 };
166
167 struct parameterwrapper {
168   struct parameterwrapper *next;
169   struct ObjectHash * objectset;
170   int numberofterms;
171   int * intarray;
172   int numbertags;
173   int * tagarray;
174   struct taskdescriptor * task;
175   int slot;
176   struct tagobjectiterator iterators[MAXTASKPARAMS-1];
177 };
178 #endif
179
180 struct taskparamdescriptor {
181   struct taskdescriptor * task;
182   int numParameters;
183   void ** parameterArray;
184 #ifdef OPTIONAL
185   int * failed;
186 #endif
187 };
188
189 int hashCodetpd(struct taskparamdescriptor *);
190 int comparetpd(struct taskparamdescriptor *, struct taskparamdescriptor *);
191
192 void toiReset(struct tagobjectiterator * it);
193 int toiHasNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * failed));
194 void toiNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * failed));
195 void processobject(struct parameterwrapper *parameter, int index, struct parameterdescriptor *pd, int *iteratorcount, int * statusarray, int numparams);
196 void processtags(struct parameterdescriptor *pd, int index, struct parameterwrapper *parameter, int * iteratorcount, int *statusarray, int numparams);
197 void builditerators(struct taskdescriptor * task, int index, struct parameterwrapper * parameter);
198 int enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags);
199
200 #endif
201
202 #endif