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 void CALL11(___System______exit____I,int ___status___, int ___status___) {
114 printf("numTransCommit = %d\n", numTransCommit);
115 printf("numTransAbort = %d\n", numTransAbort);
116 printf("nSoftAbort = %d\n", nSoftAbort);
118 printf("nSoftAbortCommit = %d\n", nSoftAbortCommit);
119 printf("nSoftAbortAbort = %d\n", nSoftAbortAbort);
122 for(i=0; i<TOTALNUMCLASSANDARRAY; i++) {
123 printf("typesCausingAbort[%d]= %d\n", i, typesCausingAbort[i]);
131 #ifdef D___Vector______removeElement_____AR_L___Object____I_I
132 void CALL23(___Vector______removeElement_____AR_L___Object____I_I, int ___index___, int ___size___, struct ArrayObject * ___array___, int ___index___, int ___size___) {
133 char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___;
134 memmove(offset, offset+sizeof(void *),(___size___-___index___-1)*sizeof(void *));
138 void CALL11(___System______printI____I,int ___status___, int ___status___) {
139 printf("%d\n",___status___);
142 long long CALL00(___System______currentTimeMillis____) {
143 struct timeval tv; long long retval;
144 gettimeofday(&tv, NULL);
145 retval = tv.tv_sec; /* seconds */
146 retval*=1000; /* milliseconds */
147 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
151 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
152 struct ArrayObject * chararray=VAR(___s___)->___value___;
154 int offset=VAR(___s___)->___offset___;
155 for(i=0; i<VAR(___s___)->___count___; i++) {
156 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
162 void CALL00(___System______clearPrefetchCache____) {
167 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
168 /* Manual Prefetches to be inserted */
169 //printf("DEBUG-> %s() ___Object___ * ___o___ = %x\n", __func__, VAR(___o___));
170 //printf("DEBUG-> %s() ArrayObject * = %x\n", __func__, VAR(___offsets___));
171 int numoffset=VAR(___offsets___)->___length___;
173 short offArry[numoffset+2];
176 for(i = 2; i<(numoffset+2); i++) {
177 offArry[i] = *((short *)(((char *)&VAR(___offsets___)->___length___) + sizeof(int) + (i-2) * sizeof(short)));
178 //printf("DEBUG-> offArry[%d] = %d\n", i, offArry[i]);
181 if(((unsigned int)(VAR(___o___)) & 1) != 0) { //odd
182 oid = (unsigned int) VAR(___o___); //outside transaction therefore just an oid
184 oid = (unsigned int) COMPOID(VAR(___o___)); //inside transaction therefore a pointer to oid
186 rangePrefetch(oid, (short)(numoffset+2), offArry);
189 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
196 /* STM Barrier constructs */
197 #ifdef D___Barrier______setBarrier____I
198 void CALL11(___Barrier______setBarrier____I, int nthreads, int nthreads) {
199 // Barrier initialization
201 if((ret = pthread_barrier_init(&barrier, NULL, nthreads)) != 0) {
202 printf("%s() Could not create a barrier: numthreads = 0 in %s\n", __func__, __FILE__);
208 #ifdef D___Barrier______enterBarrier____
209 void CALL00(___Barrier______enterBarrier____) {
210 // Synchronization point
213 stopforgc((struct garbagelist *)___params___);
215 ret = pthread_barrier_wait(&barrier);
219 if(ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) {
220 printf("%s() Could not wait on barrier: error %d in %s\n", __func__, errno, __FILE__);
226 /* Object allocation function */
229 __attribute__((malloc)) void * allocate_newglobal(int type) {
230 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(classsize[type]);
240 /* Array allocation function */
242 __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, int length) {
243 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(sizeof(struct ArrayObject)+length*classsize[type]);
245 printf("ERROR: negative array\n");
249 v->___length___=length;
261 // STM Versions of allocation functions
263 /* Object allocation function */
264 __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) {
265 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type]);
267 v->___objlocation___=v;
271 /* Array allocation function */
272 __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length) {
273 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]);
275 printf("ERROR: negative array\n");
278 v->___objlocation___=(struct ___Object___*)v;
280 v->___length___=length;
283 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
284 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t));
285 struct ___Object___ * v=(struct ___Object___ *) &tmp[1];
286 initdsmlocks(&tmp->lock);
288 v->___objlocation___=v;
293 /* Array allocation function */
295 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
296 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t));
297 struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
298 initdsmlocks(&tmp->lock);
302 printf("ERROR: negative array %d\n", length);
305 v->___objlocation___=(struct ___Object___ *)v;
306 v->___length___=length;
312 #if defined(PRECISE_GC)
313 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
314 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
327 /* Array allocation function */
329 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
330 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
333 printf("ERROR: negative array\n");
336 v->___length___=length;
349 __attribute__((malloc)) void * allocate_new(int type) {
350 struct ___Object___ * v=FREEMALLOC(classsize[type]);
358 /* Array allocation function */
360 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length) {
361 __attribute__((malloc)) struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
363 v->___length___=length;
373 /* Converts C character arrays into Java strings */
375 __attribute__((malloc)) struct ___String___ * NewString(void * ptr, const char *str,int length) {
377 __attribute__((malloc)) struct ___String___ * NewString(const char *str,int length) {
381 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
382 INTPTR ptrarray[]={1, (INTPTR) ptr, (INTPTR) chararray};
383 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
384 chararray=(struct ArrayObject *) ptrarray[2];
386 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
387 struct ___String___ * strobj=allocate_new(STRINGTYPE);
389 strobj->___value___=chararray;
390 strobj->___count___=length;
391 strobj->___offset___=0;
393 for(i=0; i<length; i++) {
394 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
399 /* Generated code calls this if we fail a bounds check */
401 void failedboundschk() {
403 printf("Array out of bounds\n");
410 longjmp(error_handler,2);
414 /* Abort task call */
417 longjmp(error_handler,4);
419 printf("Aborting\n");