7 extern jmp_buf error_handler;
8 extern int instructioncount;
9 extern int failurecount;
13 #include "DSTM/interface_recovery/dstm.h"
15 #include "DSTM/interface/dstm.h"
34 // The L1 and L2 cache line size for the
35 // AMD Opteron 6168 (dc-10) is 64 bytes. Source:
36 // http://www.cs.virginia.edu/~skadron/cs451/opteron/opteron.ppt
37 #define CACHELINESIZE 64
40 extern void * curr_heapbase;
41 extern void * curr_heaptop;
43 #define likely(x) __builtin_expect((x),1)
44 #define unlikely(x) __builtin_expect((x),0)
47 #define TAGARRAYINTERVAL 10
48 #define OBJECTARRAYINTERVAL 10
50 #define ARRAYSET(array, type, index, value) \
51 ((type *)(&(&array->___length___)[1]))[index]=value
53 #define ARRAYGET(array, type, index) \
54 ((type *)(&(&array->___length___)[1]))[index]
63 __attribute__((malloc)) void * allocate_newglobal(int type);
64 __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, int length);
68 __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type);
69 __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length);
75 __attribute__((malloc)) void * allocate_new_mlp(void *, int type, int oid, int allocsite);
76 __attribute__((malloc)) void * allocate_new(void *, int type);
77 __attribute__((malloc)) struct ArrayObject * allocate_newarray_mlp(void *, int type, int length, int oid, int allocsite);
78 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length);
80 __attribute__((malloc)) void * allocate_new(void *, int type);
81 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void *, int type, int length);
83 __attribute__((malloc)) StringPtr NewString(void *, const char *str,int length);
84 __attribute__((malloc)) StringPtr NewStringShort(void *, const short *str,int length);
85 __attribute__((malloc)) struct ___TagDescriptor___ * allocate_tag(void *ptr, int index);
86 #elif defined MULTICORE_GC
87 __attribute__((malloc)) void * allocate_new(void *, int type);
88 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void *, int type, int length);
89 __attribute__((malloc)) StringPtr NewString(void *, const char *str,int length);
90 __attribute__((malloc)) StringPtr NewStringShort(void *, const short *str,int length);
91 __attribute__((malloc)) struct ___TagDescriptor___ * allocate_tag(void *ptr, int index);
93 __attribute__((malloc)) void * allocate_new(int type);
94 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length);
95 __attribute__((malloc)) StringPtr NewString(const char *str,int length);
96 __attribute__((malloc)) StringPtr NewStringShort(const short *str,int length);
97 __attribute__((malloc)) struct ___TagDescriptor___ * allocate_tag(int index);
102 void initializeexithandler();
103 void failedboundschk(int num, int index, struct ArrayObject * ao);
104 void failednullptr(void * stackptr);
106 void injectinstructionfailure();
108 void createstartupobject(int argc, char ** argv);
110 void createstartupobject();
114 #define VAR(name) ___params___->name
115 #define CALL00(name) name(struct name ## _params * ___params___)
116 #define CALL01(name, alt) name(struct name ## _params * ___params___)
117 #define CALL02(name, alt1, alt2) name(struct name ## _params * ___params___)
118 #define CALL11(name,rest, alt) name(struct name ## _params * ___params___, rest)
119 #define CALL12(name,rest, alt1, alt2) name(struct name ## _params * ___params___, rest)
120 #define CALL22(name, rest, rest2, alt1, alt2) name(struct name ## _params * ___params___, rest, rest2)
121 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(struct name ## _params * ___params___, rest, rest2)
122 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2)
123 #define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2, rest3)
124 #define CALL35(name, rest, rest2, rest3, alt1, alt2, alt3, alt4, alt5) name(struct name ## _params * ___params___, rest, rest2, rest3)
125 #elif defined MULTICORE_GC
126 #define VAR(name) ___params___->name
127 #define CALL00(name) name(struct name ## _params * ___params___)
128 #define CALL01(name, alt) name(struct name ## _params * ___params___)
129 #define CALL02(name, alt1, alt2) name(struct name ## _params * ___params___)
130 #define CALL11(name,rest, alt) name(struct name ## _params * ___params___, rest)
131 #define CALL12(name,rest, alt1, alt2) name(struct name ## _params * ___params___, rest)
132 #define CALL22(name, rest, rest2, alt1, alt2) name(struct name ## _params * ___params___, rest, rest2)
133 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(struct name ## _params * ___params___, rest, rest2)
134 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2)
135 #define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2, rest3)
136 #define CALL35(name, rest, rest2, rest3, alt1, alt2, alt3, alt4, alt5) name(struct name ## _params * ___params___, rest, rest2, rest3)
138 #define VAR(name) name
139 #define CALL00(name) name()
140 #define CALL01(name, alt) name(alt)
141 #define CALL02(name, alt1, alt2) name(alt1, alt2)
142 #define CALL11(name,rest, alt) name(alt)
143 #define CALL12(name,rest, alt1, alt2) name(alt1, alt2)
144 #define CALL22(name, rest, rest2, alt1, alt2) name(alt1, alt2)
145 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(alt1, alt2, alt3)
146 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
147 #define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
148 #define CALL35(name, rest, rest2, rest3, alt1, alt2, alt3, alt4, alt5) name(alt1, alt2, alt3, alt4, alt5)
152 #include "SimpleHash.h"
153 inline void run(int argc, char** argv);
154 int receiveObject_I();
155 void * smemalloc_I(int coren, int size, int * allocsize);
158 #if (defined(THREADS)||defined(MGC))
168 struct lockpair locks[MAXLOCKS];
172 extern __thread struct lockvector lvector;
173 extern __thread int mythreadid;
180 #include "ObjectHash.h"
181 #include "structdefs.h"
185 #include "optionalstruct.h"
190 struct failedtasklist {
191 struct taskdescriptor *task;
195 struct failedtasklist *next;
200 struct transObjInfo {
209 extern ObjectPtr ___fcrevert___;
213 void flagorand(void * ptr, int ormask, int andmask, struct parameterwrapper ** queues, int length);
214 void flagorandinit(void * ptr, int ormask, int andmask);
215 void enqueueObject(void * ptr, struct parameterwrapper ** queues,int length);
217 inline void setTaskExitIndex(int index);
218 inline void addNewObjInfo(void * nobj);
220 int * getAliasLock(void ** ptrs, int length, struct RuntimeHash * tbl);
221 void addAliasLock(void * ptr, int lock);
223 void flagorand(void * ptr, int ormask, int andmask);
224 void flagorandinit(void * ptr, int ormask, int andmask);
225 void enqueueObject(void * ptr);
231 struct tagobjectiterator {
232 int istag; /* 0 if object iterator, 1 if tag iterator */
233 struct ObjectIterator it; /* Object iterator */
234 struct ObjectHash * objectset;
239 int tagobjindex; /* Index for tag or object depending on use */
240 /*if tag we have an object binding */
243 /*if object, we may have one or more tag bindings */
245 int tagbindings[MAXTASKPARAMS-1]; /* list slots */
248 struct parameterwrapper {
249 struct parameterwrapper *next;
250 struct ObjectHash * objectset;
255 struct taskdescriptor * task;
257 struct tagobjectiterator iterators[MAXTASKPARAMS-1];
261 struct taskparamdescriptor {
262 struct taskdescriptor * task;
264 void ** parameterArray;
270 int hashCodetpd(struct taskparamdescriptor *);
271 int comparetpd(struct taskparamdescriptor *, struct taskparamdescriptor *);
273 void toiReset(struct tagobjectiterator * it);
274 int toiHasNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * failed));
275 void toiNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * failed));
276 void processobject(struct parameterwrapper *parameter, int index, struct parameterdescriptor *pd, int *iteratorcount, int * statusarray, int numparams);
277 void processtags(struct parameterdescriptor *pd, int index, struct parameterwrapper *parameter, int * iteratorcount, int *statusarray, int numparams);
278 void builditerators(struct taskdescriptor * task, int index, struct parameterwrapper * parameter);
279 int enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, ObjectPtr ptr, int * enterflags, int numenterflags);
283 #if defined(__i386__)
284 static __inline__ unsigned long long rdtsc(void) {
285 unsigned long long int x;
286 __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
289 #elif defined(__x86_64__)
290 static __inline__ unsigned long long rdtsc(void) {
292 __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
293 return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );