2 #include "structdefs.h"
9 #include "methodheaders.h"
12 #include "prelookup.h"
20 #if defined(THREADS)||defined(STM)
21 /* Global barrier for STM */
22 pthread_barrier_t barrier;
23 pthread_barrierattr_t attr;
28 extern int classsize[];
29 extern int typearray[];
30 extern int typearray2[];
31 jmp_buf error_handler;
36 float failurechance=0;
39 int injectinstructionfailures;
41 float instfailurechance=0;
44 typedef unsigned long long ticks;
49 int instanceof(struct ___Object___ *ptr, int type) {
61 i=typearray2[i-NUMCLASSES];
67 void exithandler(int sig, siginfo_t *info, void * uap) {
71 void initializeexithandler() {
73 sig.sa_sigaction=&exithandler;
74 sig.sa_flags=SA_SIGINFO;
75 sigemptyset(&sig.sa_mask);
76 sigaction(SIGUSR2, &sig, 0);
80 /* This function inject failures */
82 void injectinstructionfailure() {
84 if (injectinstructionfailures) {
87 instructioncount=failurecount;
88 instaccum+=failurecount;
89 if ((((double)random())/RAND_MAX)<instfailurechance) {
92 printf("FAILURE!!! %d\n",numfailures);
93 longjmp(error_handler,11);
98 if (injectinstructionfailures) {
101 instaccum+=failurecount;
102 if ((((double)random())/RAND_MAX)<instfailurechance) {
105 printf("FAILURE!!! %d\n",numfailures);
113 #ifdef D___Double______nativeparsedouble____L___String___
114 double CALL01(___Double______nativeparsedouble____L___String___,struct ___String___ * ___str___) {
115 int length=VAR(___str___)->___count___;
116 int maxlength=(length>60)?60:length;
117 char str[maxlength+1];
118 struct ArrayObject * chararray=VAR(___str___)->___value___;
120 int offset=VAR(___str___)->___offset___;
121 for(i=0; i<maxlength; i++) {
122 str[i]=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
130 #ifdef D___String______convertdoubletochar____D__AR_C
131 int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
132 int length=VAR(___chararray___)->___length___;
135 int num=snprintf(str, length, "%f",___val___);
138 for(i=0; i<length; i++) {
139 ((short *)(((char *)&VAR(___chararray___)->___length___)+sizeof(int)))[i]=(short)str[i];
144 #ifdef D___System______deepArrayCopy____L___Object____L___Object___
145 void deepArrayCopy(struct ___Object___ * dst, struct ___Object___ * src) {
146 int dsttype=((int *)dst)[0];
147 int srctype=((int *)src)[0];
148 if (dsttype<NUMCLASSES||srctype<NUMCLASSES||srctype!=dsttype)
150 struct ArrayObject *aodst=(struct ArrayObject *)dst;
151 struct ArrayObject *aosrc=(struct ArrayObject *)src;
152 int dstlength=aodst->___length___;
153 int srclength=aosrc->___length___;
154 if (dstlength!=srclength)
156 unsigned INTPTR *pointer=pointerarray[srctype];
158 int elementsize=classsize[srctype];
159 int size=srclength*elementsize;
161 memcpy(((char *)&aodst->___length___)+sizeof(int) , ((char *)&aosrc->___length___)+sizeof(int), size);
165 for(i=0;i<srclength;i++) {
166 struct ___Object___ * ptr=((struct ___Object___**)(((char*) &aosrc->___length___)+sizeof(int)))[i];
167 int ptrtype=((int *)ptr)[0];
168 if (ptrtype>=NUMCLASSES) {
169 struct ___Object___ * dstptr=((struct ___Object___**)(((char*) &aodst->___length___)+sizeof(int)))[i];
170 deepArrayCopy(dstptr,ptr);
173 ((struct ___Object___ **)(((char*) &aodst->___length___)+sizeof(int)))[i]=ptr;
179 void CALL02(___System______deepArrayCopy____L___Object____L___Object___, struct ___Object___ * ___dst___, struct ___Object___ * ___src___) {
180 deepArrayCopy(VAR(___dst___), VAR(___src___));
184 void CALL11(___System______exit____I,int ___status___, int ___status___) {
186 printf("numTransCommit = %d\n", numTransCommit);
187 printf("numTransAbort = %d\n", numTransAbort);
188 printf("nSoftAbort = %d\n", nSoftAbort);
190 printf("nSoftAbortCommit = %d\n", nSoftAbortCommit);
191 printf("nSoftAbortAbort = %d\n", nSoftAbortAbort);
194 for(i=0; i<TOTALNUMCLASSANDARRAY; i++) {
195 printf("typesCausingAbort[%2d] numaccess= %5d numabort= %3d\n", i, typesCausingAbort[i].numaccess, typesCausingAbort[i].numabort);
203 #ifdef D___Vector______removeElement_____AR_L___Object____I_I
204 void CALL23(___Vector______removeElement_____AR_L___Object____I_I, int ___index___, int ___size___, struct ArrayObject * ___array___, int ___index___, int ___size___) {
205 char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___;
206 memmove(offset, offset+sizeof(void *),(___size___-___index___-1)*sizeof(void *));
210 void CALL11(___System______printI____I,int ___status___, int ___status___) {
211 printf("%d\n",___status___);
214 long long CALL00(___System______currentTimeMillis____) {
215 struct timeval tv; long long retval;
216 gettimeofday(&tv, NULL);
217 retval = tv.tv_sec; /* seconds */
218 retval*=1000; /* milliseconds */
219 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
223 long long CALL00(___System______microTimes____) {
226 gettimeofday(&tv, NULL);
227 retval = tv.tv_sec; /* seconds */
228 retval*=1000000; /* microsecs */
229 retval+= (tv.tv_usec); /* adjust microseconds & add them in */
233 long long CALL00(___System______getticks____) {
236 asm volatile("rdtsc" : "=a" (a), "=d" (d));
237 return (((ticks)a) | (((ticks)d) << 32));
240 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
241 struct ArrayObject * chararray=VAR(___s___)->___value___;
243 int offset=VAR(___s___)->___offset___;
244 for(i=0; i<VAR(___s___)->___count___; i++) {
245 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
251 void CALL00(___System______clearPrefetchCache____) {
256 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
257 /* Manual Prefetches to be inserted */
258 //printf("DEBUG-> %s() ___Object___ * ___o___ = %x\n", __func__, VAR(___o___));
259 //printf("DEBUG-> %s() ArrayObject * = %x\n", __func__, VAR(___offsets___));
260 int numoffset=VAR(___offsets___)->___length___;
262 short offArry[numoffset+2];
265 for(i = 2; i<(numoffset+2); i++) {
266 offArry[i] = *((short *)(((char *)&VAR(___offsets___)->___length___) + sizeof(int) + (i-2) * sizeof(short)));
267 //printf("DEBUG-> offArry[%d] = %d\n", i, offArry[i]);
270 if(((unsigned int)(VAR(___o___)) & 1) != 0) { //odd
271 oid = (unsigned int) VAR(___o___); //outside transaction therefore just an oid
273 oid = (unsigned int) COMPOID(VAR(___o___)); //inside transaction therefore a pointer to oid
275 rangePrefetch(oid, (short)(numoffset+2), offArry);
278 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
285 /* STM Barrier constructs */
286 #ifdef D___Barrier______setBarrier____I
287 void CALL11(___Barrier______setBarrier____I, int nthreads, int nthreads) {
288 // Barrier initialization
290 if((ret = pthread_barrier_init(&barrier, NULL, nthreads)) != 0) {
291 printf("%s() Could not create a barrier: numthreads = 0 in %s\n", __func__, __FILE__);
297 #ifdef D___Barrier______enterBarrier____
298 void CALL00(___Barrier______enterBarrier____) {
299 // Synchronization point
302 stopforgc((struct garbagelist *)___params___);
304 ret = pthread_barrier_wait(&barrier);
308 if(ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) {
309 printf("%s() Could not wait on barrier: error %d in %s\n", __func__, errno, __FILE__);
315 /* Object allocation function */
318 __attribute__((malloc)) void * allocate_newglobal(int type) {
319 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(classsize[type]);
329 /* Array allocation function */
331 __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, int length) {
332 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(sizeof(struct ArrayObject)+length*classsize[type]);
334 printf("ERROR: negative array\n");
338 v->___length___=length;
350 // STM Versions of allocation functions
352 /* Object allocation function */
353 __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) {
354 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type]);
356 v->___objlocation___=v;
360 /* Array allocation function */
361 __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length) {
362 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]);
364 printf("ERROR: negative array\n");
367 v->___objlocation___=(struct ___Object___*)v;
369 v->___length___=length;
372 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
373 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t));
374 struct ___Object___ * v=(struct ___Object___ *) &tmp[1];
375 initdsmlocks(&tmp->lock);
377 v->___objlocation___=v;
382 /* Array allocation function */
384 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
385 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t));
386 struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
387 initdsmlocks(&tmp->lock);
391 printf("ERROR: negative array %d\n", length);
394 v->___objlocation___=(struct ___Object___ *)v;
395 v->___length___=length;
401 #if defined(PRECISE_GC)
402 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
403 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
416 /* Array allocation function */
418 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
419 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
422 printf("ERROR: negative array\n");
425 v->___length___=length;
438 __attribute__((malloc)) void * allocate_new(int type) {
439 struct ___Object___ * v=FREEMALLOC(classsize[type]);
447 /* Array allocation function */
449 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length) {
450 __attribute__((malloc)) struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
452 v->___length___=length;
461 /* Converts C character arrays into Java strings */
463 __attribute__((malloc)) struct ___String___ * NewString(void * ptr, const char *str,int length) {
465 __attribute__((malloc)) struct ___String___ * NewString(const char *str,int length) {
469 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
470 INTPTR ptrarray[]={1, (INTPTR) ptr, (INTPTR) chararray};
471 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
472 chararray=(struct ArrayObject *) ptrarray[2];
474 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
475 struct ___String___ * strobj=allocate_new(STRINGTYPE);
477 strobj->___value___=chararray;
478 strobj->___count___=length;
479 strobj->___offset___=0;
481 for(i=0; i<length; i++) {
482 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
487 /* Generated code calls this if we fail a bounds check */
489 void failedboundschk() {
491 printf("Array out of bounds\n");
498 longjmp(error_handler,2);
502 /* Abort task call */
505 longjmp(error_handler,4);
507 printf("Aborting\n");