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);
118 for(i=0; i<TOTALNUMCLASSANDARRAY; i++) {
119 printf("typesCausingAbort[%d]= %d\n", i, typesCausingAbort[i]);
127 #ifdef D___Vector______removeElement_____AR_L___Object____I_I
128 void CALL23(___Vector______removeElement_____AR_L___Object____I_I, int ___index___, int ___size___, struct ArrayObject * ___array___, int ___index___, int ___size___) {
129 char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___;
130 memmove(offset, offset+sizeof(void *),(___size___-___index___-1)*sizeof(void *));
134 void CALL11(___System______printI____I,int ___status___, int ___status___) {
135 printf("%d\n",___status___);
138 long long CALL00(___System______currentTimeMillis____) {
139 struct timeval tv; long long retval;
140 gettimeofday(&tv, NULL);
141 retval = tv.tv_sec; /* seconds */
142 retval*=1000; /* milliseconds */
143 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
147 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
148 struct ArrayObject * chararray=VAR(___s___)->___value___;
150 int offset=VAR(___s___)->___offset___;
151 for(i=0; i<VAR(___s___)->___count___; i++) {
152 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
158 void CALL00(___System______clearPrefetchCache____) {
163 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
164 /* Manual Prefetches to be inserted */
165 //printf("DEBUG-> %s() ___Object___ * ___o___ = %x\n", __func__, VAR(___o___));
166 //printf("DEBUG-> %s() ArrayObject * = %x\n", __func__, VAR(___offsets___));
167 int numoffset=VAR(___offsets___)->___length___;
169 short offArry[numoffset+2];
172 for(i = 2; i<(numoffset+2); i++) {
173 offArry[i] = *((short *)(((char *)&VAR(___offsets___)->___length___) + sizeof(int) + (i-2) * sizeof(short)));
174 //printf("DEBUG-> offArry[%d] = %d\n", i, offArry[i]);
177 if(((unsigned int)(VAR(___o___)) & 1) != 0) { //odd
178 oid = (unsigned int) VAR(___o___); //outside transaction therefore just an oid
180 oid = (unsigned int) COMPOID(VAR(___o___)); //inside transaction therefore a pointer to oid
182 rangePrefetch(oid, (short)(numoffset+2), offArry);
185 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
193 /* STM Barrier constructs */
194 #ifdef D___Barrier______setBarrier____I
195 void CALL11(___Barrier______setBarrier____I, int nthreads, int nthreads) {
197 struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
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__);
211 #ifdef D___Barrier______enterBarrier____
212 void CALL00(___Barrier______enterBarrier____) {
213 // Synchronization point
215 ret = pthread_barrier_wait(&barrier);
216 if(ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) {
217 printf("%s() Could not wait on barrier: error %d in %s\n", __func__, errno, __FILE__);
224 /* Object allocation function */
227 __attribute__((malloc)) void * allocate_newglobal(int type) {
228 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(classsize[type]);
238 /* Array allocation function */
240 __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, int length) {
241 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(sizeof(struct ArrayObject)+length*classsize[type]);
243 printf("ERROR: negative array\n");
247 v->___length___=length;
259 // STM Versions of allocation functions
261 /* Object allocation function */
262 __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) {
263 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type]);
265 v->___objlocation___=v;
269 /* Array allocation function */
270 __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length) {
271 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]);
273 printf("ERROR: negative array\n");
276 v->___objlocation___=(struct ___Object___*)v;
278 v->___length___=length;
281 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
282 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t));
283 struct ___Object___ * v=(struct ___Object___ *) &tmp[1];
284 initdsmlocks(&tmp->lock);
286 v->___objlocation___=v;
291 /* Array allocation function */
293 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
294 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t));
295 struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
296 initdsmlocks(&tmp->lock);
300 printf("ERROR: negative array %d\n", length);
303 v->___objlocation___=(struct ___Object___ *)v;
304 v->___length___=length;
310 #if defined(PRECISE_GC)
311 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
312 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
325 /* Array allocation function */
327 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
328 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
331 printf("ERROR: negative array\n");
334 v->___length___=length;
347 __attribute__((malloc)) void * allocate_new(int type) {
348 struct ___Object___ * v=FREEMALLOC(classsize[type]);
356 /* Array allocation function */
358 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length) {
359 __attribute__((malloc)) struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
361 v->___length___=length;
371 /* Converts C character arrays into Java strings */
373 __attribute__((malloc)) struct ___String___ * NewString(void * ptr, const char *str,int length) {
375 __attribute__((malloc)) struct ___String___ * NewString(const char *str,int length) {
379 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
380 INTPTR ptrarray[]={1, (INTPTR) ptr, (INTPTR) chararray};
381 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
382 chararray=(struct ArrayObject *) ptrarray[2];
384 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
385 struct ___String___ * strobj=allocate_new(STRINGTYPE);
387 strobj->___value___=chararray;
388 strobj->___count___=length;
389 strobj->___offset___=0;
391 for(i=0; i<length; i++) {
392 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
397 /* Generated code calls this if we fail a bounds check */
399 void failedboundschk() {
401 printf("Array out of bounds\n");
408 longjmp(error_handler,2);
412 /* Abort task call */
415 longjmp(error_handler,4);
417 printf("Aborting\n");