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
122 void CALL12(___Vector______removeElement_____AR_L___Object____I, int ___index___, struct ArrayObject * ___array___, int ___index___) {
123 int length=VAR(___array___)->___length___;
124 char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___;
125 memmove(offset, offset+sizeof(void *),(length-___index___-1)*sizeof(void *));
129 void CALL11(___System______printI____I,int ___status___, int ___status___) {
130 printf("%d\n",___status___);
133 long long CALL00(___System______currentTimeMillis____) {
134 struct timeval tv; long long retval;
135 gettimeofday(&tv, NULL);
136 retval = tv.tv_sec; /* seconds */
137 retval*=1000; /* milliseconds */
138 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
142 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
143 struct ArrayObject * chararray=VAR(___s___)->___value___;
145 int offset=VAR(___s___)->___offset___;
146 for(i=0; i<VAR(___s___)->___count___; i++) {
147 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
153 void CALL00(___System______clearPrefetchCache____) {
158 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
159 /* Manual Prefetches to be inserted */
160 //printf("DEBUG-> %s() ___Object___ * ___o___ = %x\n", __func__, VAR(___o___));
161 //printf("DEBUG-> %s() ArrayObject * = %x\n", __func__, VAR(___offsets___));
162 int numoffset=VAR(___offsets___)->___length___;
164 short offArry[numoffset+2];
167 for(i = 2; i<(numoffset+2); i++) {
168 offArry[i] = *((short *)(((char *)&VAR(___offsets___)->___length___) + sizeof(int) + (i-2) * sizeof(short)));
169 //printf("DEBUG-> offArry[%d] = %d\n", i, offArry[i]);
172 if(((unsigned int)(VAR(___o___)) & 1) != 0) { //odd
173 oid = (unsigned int) VAR(___o___); //outside transaction therefore just an oid
175 oid = (unsigned int) COMPOID(VAR(___o___)); //inside transaction therefore a pointer to oid
177 rangePrefetch(oid, (short)(numoffset+2), offArry);
180 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
188 /* STM Barrier constructs */
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: error %d\n", __func__, errno);
205 void CALL00(___Barrier______enterBarrier____) {
206 // Synchronization point
208 ret = pthread_barrier_wait(&barrier);
210 printf("%s() Could not wait on barrier: error %d\n", __func__, errno);
217 /* Object allocation function */
220 __attribute__((malloc)) void * allocate_newglobal(int type) {
221 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(classsize[type]);
231 /* Array allocation function */
233 __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, int length) {
234 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(sizeof(struct ArrayObject)+length*classsize[type]);
236 printf("ERROR: negative array\n");
240 v->___length___=length;
252 // STM Versions of allocation functions
254 /* Object allocation function */
255 __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) {
256 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type]);
258 v->___objlocation___=v;
262 /* Array allocation function */
263 __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length) {
264 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]);
266 printf("ERROR: negative array\n");
269 v->___objlocation___=(struct ___Object___*)v;
271 v->___length___=length;
274 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
275 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t));
276 struct ___Object___ * v=(struct ___Object___ *) &tmp[1];
277 initdsmlocks(&tmp->lock);
279 v->___objlocation___=v;
284 /* Array allocation function */
286 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
287 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t));
288 struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
289 initdsmlocks(&tmp->lock);
293 printf("ERROR: negative array\n");
296 v->___objlocation___=(struct ___Object___ *)v;
297 v->___length___=length;
303 #if defined(PRECISE_GC)
304 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
305 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
318 /* Array allocation function */
320 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
321 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
324 printf("ERROR: negative array\n");
327 v->___length___=length;
340 __attribute__((malloc)) void * allocate_new(int type) {
341 struct ___Object___ * v=FREEMALLOC(classsize[type]);
349 /* Array allocation function */
351 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length) {
352 __attribute__((malloc)) struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
354 v->___length___=length;
364 /* Converts C character arrays into Java strings */
366 __attribute__((malloc)) struct ___String___ * NewString(void * ptr, const char *str,int length) {
368 __attribute__((malloc)) struct ___String___ * NewString(const char *str,int length) {
372 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
373 INTPTR ptrarray[]={1, (INTPTR) ptr, (INTPTR) chararray};
374 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
375 chararray=(struct ArrayObject *) ptrarray[2];
377 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
378 struct ___String___ * strobj=allocate_new(STRINGTYPE);
380 strobj->___value___=chararray;
381 strobj->___count___=length;
382 strobj->___offset___=0;
384 for(i=0; i<length; i++) {
385 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
390 /* Generated code calls this if we fail a bounds check */
392 void failedboundschk() {
394 printf("Array out of bounds\n");
401 longjmp(error_handler,2);
405 /* Abort task call */
408 longjmp(error_handler,4);
410 printf("Aborting\n");