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;
48 int instanceof(struct ___Object___ *ptr, int type) {
60 i=typearray2[i-NUMCLASSES];
66 void exithandler(int sig, siginfo_t *info, void * uap) {
70 void initializeexithandler() {
72 sig.sa_sigaction=&exithandler;
73 sig.sa_flags=SA_SIGINFO;
74 sigemptyset(&sig.sa_mask);
75 sigaction(SIGUSR2, &sig, 0);
79 /* This function inject failures */
81 void injectinstructionfailure() {
83 if (injectinstructionfailures) {
86 instructioncount=failurecount;
87 instaccum+=failurecount;
88 if ((((double)random())/RAND_MAX)<instfailurechance) {
91 printf("FAILURE!!! %d\n",numfailures);
92 longjmp(error_handler,11);
97 if (injectinstructionfailures) {
100 instaccum+=failurecount;
101 if ((((double)random())/RAND_MAX)<instfailurechance) {
104 printf("FAILURE!!! %d\n",numfailures);
112 #ifdef D___Double______nativeparsedouble____L___String___
113 double CALL01(___Double______nativeparsedouble____L___String___,struct ___String___ * ___str___) {
114 int length=VAR(___str___)->___count___;
115 int maxlength=(length>60)?60:length;
116 char str[maxlength+1];
117 struct ArrayObject * chararray=VAR(___str___)->___value___;
119 int offset=VAR(___str___)->___offset___;
120 for(i=0; i<maxlength; i++) {
121 str[i]=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
129 #ifdef D___String______convertdoubletochar____D__AR_C
130 int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
131 int length=VAR(___chararray___)->___length___;
134 int num=snprintf(str, length, "%f",___val___);
137 for(i=0; i<length; i++) {
138 ((short *)(((char *)&VAR(___chararray___)->___length___)+sizeof(int)))[i]=(short)str[i];
144 void CALL11(___System______exit____I,int ___status___, int ___status___) {
146 printf("numTransCommit = %d\n", numTransCommit);
147 printf("numTransAbort = %d\n", numTransAbort);
148 printf("nSoftAbort = %d\n", nSoftAbort);
150 printf("nSoftAbortCommit = %d\n", nSoftAbortCommit);
151 printf("nSoftAbortAbort = %d\n", nSoftAbortAbort);
154 for(i=0; i<TOTALNUMCLASSANDARRAY; i++) {
155 printf("typesCausingAbort[%d]= %d\n", i, typesCausingAbort[i]);
163 #ifdef D___Vector______removeElement_____AR_L___Object____I_I
164 void CALL23(___Vector______removeElement_____AR_L___Object____I_I, int ___index___, int ___size___, struct ArrayObject * ___array___, int ___index___, int ___size___) {
165 char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___;
166 memmove(offset, offset+sizeof(void *),(___size___-___index___-1)*sizeof(void *));
170 void CALL11(___System______printI____I,int ___status___, int ___status___) {
171 printf("%d\n",___status___);
174 long long CALL00(___System______currentTimeMillis____) {
175 struct timeval tv; long long retval;
176 gettimeofday(&tv, NULL);
177 retval = tv.tv_sec; /* seconds */
178 retval*=1000; /* milliseconds */
179 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
183 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
184 struct ArrayObject * chararray=VAR(___s___)->___value___;
186 int offset=VAR(___s___)->___offset___;
187 for(i=0; i<VAR(___s___)->___count___; i++) {
188 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
194 void CALL00(___System______clearPrefetchCache____) {
199 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
200 /* Manual Prefetches to be inserted */
201 //printf("DEBUG-> %s() ___Object___ * ___o___ = %x\n", __func__, VAR(___o___));
202 //printf("DEBUG-> %s() ArrayObject * = %x\n", __func__, VAR(___offsets___));
203 int numoffset=VAR(___offsets___)->___length___;
205 short offArry[numoffset+2];
208 for(i = 2; i<(numoffset+2); i++) {
209 offArry[i] = *((short *)(((char *)&VAR(___offsets___)->___length___) + sizeof(int) + (i-2) * sizeof(short)));
210 //printf("DEBUG-> offArry[%d] = %d\n", i, offArry[i]);
213 if(((unsigned int)(VAR(___o___)) & 1) != 0) { //odd
214 oid = (unsigned int) VAR(___o___); //outside transaction therefore just an oid
216 oid = (unsigned int) COMPOID(VAR(___o___)); //inside transaction therefore a pointer to oid
218 rangePrefetch(oid, (short)(numoffset+2), offArry);
221 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
228 /* STM Barrier constructs */
229 #ifdef D___Barrier______setBarrier____I
230 void CALL11(___Barrier______setBarrier____I, int nthreads, int nthreads) {
231 // Barrier initialization
233 if((ret = pthread_barrier_init(&barrier, NULL, nthreads)) != 0) {
234 printf("%s() Could not create a barrier: numthreads = 0 in %s\n", __func__, __FILE__);
240 #ifdef D___Barrier______enterBarrier____
241 void CALL00(___Barrier______enterBarrier____) {
242 // Synchronization point
245 stopforgc((struct garbagelist *)___params___);
247 ret = pthread_barrier_wait(&barrier);
251 if(ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) {
252 printf("%s() Could not wait on barrier: error %d in %s\n", __func__, errno, __FILE__);
258 /* Object allocation function */
261 __attribute__((malloc)) void * allocate_newglobal(int type) {
262 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(classsize[type]);
272 /* Array allocation function */
274 __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, int length) {
275 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(sizeof(struct ArrayObject)+length*classsize[type]);
277 printf("ERROR: negative array\n");
281 v->___length___=length;
293 // STM Versions of allocation functions
295 /* Object allocation function */
296 __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) {
297 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type]);
299 v->___objlocation___=v;
303 /* Array allocation function */
304 __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length) {
305 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]);
307 printf("ERROR: negative array\n");
310 v->___objlocation___=(struct ___Object___*)v;
312 v->___length___=length;
315 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
316 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t));
317 struct ___Object___ * v=(struct ___Object___ *) &tmp[1];
318 initdsmlocks(&tmp->lock);
320 v->___objlocation___=v;
325 /* Array allocation function */
327 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
328 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t));
329 struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
330 initdsmlocks(&tmp->lock);
334 printf("ERROR: negative array %d\n", length);
337 v->___objlocation___=(struct ___Object___ *)v;
338 v->___length___=length;
344 #if defined(PRECISE_GC)
345 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
346 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
359 /* Array allocation function */
361 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
362 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
365 printf("ERROR: negative array\n");
368 v->___length___=length;
381 __attribute__((malloc)) void * allocate_new(int type) {
382 struct ___Object___ * v=FREEMALLOC(classsize[type]);
390 /* Array allocation function */
392 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length) {
393 __attribute__((malloc)) struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
395 v->___length___=length;
404 /* Converts C character arrays into Java strings */
406 __attribute__((malloc)) struct ___String___ * NewString(void * ptr, const char *str,int length) {
408 __attribute__((malloc)) struct ___String___ * NewString(const char *str,int length) {
412 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
413 INTPTR ptrarray[]={1, (INTPTR) ptr, (INTPTR) chararray};
414 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
415 chararray=(struct ArrayObject *) ptrarray[2];
417 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
418 struct ___String___ * strobj=allocate_new(STRINGTYPE);
420 strobj->___value___=chararray;
421 strobj->___count___=length;
422 strobj->___offset___=0;
424 for(i=0; i<length; i++) {
425 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
430 /* Generated code calls this if we fail a bounds check */
432 void failedboundschk() {
434 printf("Array out of bounds\n");
441 longjmp(error_handler,2);
445 /* Abort task call */
448 longjmp(error_handler,4);
450 printf("Aborting\n");