2 #include "structdefs.h"
9 #include "methodheaders.h"
12 #include "prelookup.h"
18 /* Global barrier for STM */
19 pthread_barrier_t barrier;
20 pthread_barrierattr_t attr;
24 extern int classsize[];
25 extern int typearray[];
26 extern int typearray2[];
27 jmp_buf error_handler;
32 float failurechance=0;
35 int injectinstructionfailures;
37 float instfailurechance=0;
44 int instanceof(struct ___Object___ *ptr, int type) {
56 i=typearray2[i-NUMCLASSES];
62 void exithandler(int sig, siginfo_t *info, void * uap) {
66 void initializeexithandler() {
68 sig.sa_sigaction=&exithandler;
69 sig.sa_flags=SA_SIGINFO;
70 sigemptyset(&sig.sa_mask);
71 sigaction(SIGUSR2, &sig, 0);
75 /* This function inject failures */
77 void injectinstructionfailure() {
79 if (injectinstructionfailures) {
82 instructioncount=failurecount;
83 instaccum+=failurecount;
84 if ((((double)random())/RAND_MAX)<instfailurechance) {
87 printf("FAILURE!!! %d\n",numfailures);
88 longjmp(error_handler,11);
93 if (injectinstructionfailures) {
96 instaccum+=failurecount;
97 if ((((double)random())/RAND_MAX)<instfailurechance) {
100 printf("FAILURE!!! %d\n",numfailures);
108 void CALL11(___System______exit____I,int ___status___, int ___status___) {
110 printf("numTransCommit = %d\n", numTransCommit);
111 printf("numTransAbort = %d\n", numTransAbort);
112 printf("nSoftAbort = %d\n", nSoftAbort);
114 printf("nSoftAbortCommit = %d\n", nSoftAbortCommit);
115 printf("nSoftAbortAbort = %d\n", nSoftAbortAbort);
121 #ifdef D___Vector______removeElement_____AR_L___Object____I_I
122 void CALL23(___Vector______removeElement_____AR_L___Object____I_I, int ___index___, int ___size___, struct ArrayObject * ___array___, int ___index___, int ___size___) {
123 char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___;
124 memmove(offset, offset+sizeof(void *),(___size___-___index___-1)*sizeof(void *));
128 void CALL11(___System______printI____I,int ___status___, int ___status___) {
129 printf("%d\n",___status___);
132 long long CALL00(___System______currentTimeMillis____) {
133 struct timeval tv; long long retval;
134 gettimeofday(&tv, NULL);
135 retval = tv.tv_sec; /* seconds */
136 retval*=1000; /* milliseconds */
137 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
141 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
142 struct ArrayObject * chararray=VAR(___s___)->___value___;
144 int offset=VAR(___s___)->___offset___;
145 for(i=0; i<VAR(___s___)->___count___; i++) {
146 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
152 void CALL00(___System______clearPrefetchCache____) {
157 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
158 /* Manual Prefetches to be inserted */
159 //printf("DEBUG-> %s() ___Object___ * ___o___ = %x\n", __func__, VAR(___o___));
160 //printf("DEBUG-> %s() ArrayObject * = %x\n", __func__, VAR(___offsets___));
161 int numoffset=VAR(___offsets___)->___length___;
163 short offArry[numoffset+2];
166 for(i = 2; i<(numoffset+2); i++) {
167 offArry[i] = *((short *)(((char *)&VAR(___offsets___)->___length___) + sizeof(int) + (i-2) * sizeof(short)));
168 //printf("DEBUG-> offArry[%d] = %d\n", i, offArry[i]);
171 if(((unsigned int)(VAR(___o___)) & 1) != 0) { //odd
172 oid = (unsigned int) VAR(___o___); //outside transaction therefore just an oid
174 oid = (unsigned int) COMPOID(VAR(___o___)); //inside transaction therefore a pointer to oid
176 rangePrefetch(oid, (short)(numoffset+2), offArry);
179 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
187 /* STM Barrier constructs */
188 #ifdef D___Barrier______setBarrier____I
189 void CALL11(___Barrier______setBarrier____I, int nthreads, int nthreads) {
191 struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
193 // Barrier initialization
195 if((ret = pthread_barrier_init(&barrier, NULL, nthreads)) != 0) {
196 printf("%s() Could not create a barrier: numthreads = 0 in %s\n", __func__, __FILE__);
205 #ifdef D___Barrier______enterBarrier____
206 void CALL00(___Barrier______enterBarrier____) {
207 // Synchronization point
209 ret = pthread_barrier_wait(&barrier);
210 if(ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) {
211 printf("%s() Could not wait on barrier: error %d in %s\n", __func__, errno, __FILE__);
218 /* Object allocation function */
221 __attribute__((malloc)) void * allocate_newglobal(int type) {
222 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(classsize[type]);
232 /* Array allocation function */
234 __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, int length) {
235 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(sizeof(struct ArrayObject)+length*classsize[type]);
237 printf("ERROR: negative array\n");
241 v->___length___=length;
253 // STM Versions of allocation functions
255 /* Object allocation function */
256 __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) {
257 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type]);
259 v->___objlocation___=v;
263 /* Array allocation function */
264 __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length) {
265 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]);
267 printf("ERROR: negative array\n");
270 v->___objlocation___=(struct ___Object___*)v;
272 v->___length___=length;
275 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
276 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t));
277 struct ___Object___ * v=(struct ___Object___ *) &tmp[1];
278 initdsmlocks(&tmp->lock);
280 v->___objlocation___=v;
285 /* Array allocation function */
287 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
288 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t));
289 struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
290 initdsmlocks(&tmp->lock);
294 printf("ERROR: negative array %d\n", length);
297 v->___objlocation___=(struct ___Object___ *)v;
298 v->___length___=length;
304 #if defined(PRECISE_GC)
305 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
306 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
319 /* Array allocation function */
321 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
322 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
325 printf("ERROR: negative array\n");
328 v->___length___=length;
341 __attribute__((malloc)) void * allocate_new(int type) {
342 struct ___Object___ * v=FREEMALLOC(classsize[type]);
350 /* Array allocation function */
352 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length) {
353 __attribute__((malloc)) struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
355 v->___length___=length;
365 /* Converts C character arrays into Java strings */
367 __attribute__((malloc)) struct ___String___ * NewString(void * ptr, const char *str,int length) {
369 __attribute__((malloc)) struct ___String___ * NewString(const char *str,int length) {
373 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
374 INTPTR ptrarray[]={1, (INTPTR) ptr, (INTPTR) chararray};
375 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
376 chararray=(struct ArrayObject *) ptrarray[2];
378 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
379 struct ___String___ * strobj=allocate_new(STRINGTYPE);
381 strobj->___value___=chararray;
382 strobj->___count___=length;
383 strobj->___offset___=0;
385 for(i=0; i<length; i++) {
386 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
391 /* Generated code calls this if we fail a bounds check */
393 void failedboundschk() {
395 printf("Array out of bounds\n");
402 longjmp(error_handler,2);
406 /* Abort task call */
409 longjmp(error_handler,4);
411 printf("Aborting\n");