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