#include "runtime.h"
#include "structdefs.h"
-#include <string.h>
#include <signal.h>
#include "mem.h"
-#include<fcntl.h>
-#include<sys/types.h>
-#include<sys/mman.h>
-#include<errno.h>
-#include<signal.h>
-#include<stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdio.h>
#include "option.h"
+#include "methodheaders.h"
+
+#if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP)
+#include "thread.h"
+#endif
+
+#ifdef DSTM
+#ifdef RECOVERY
+#include "DSTM/interface_recovery/dstm.h"
+#include "DSTM/interface_recovery/altprelookup.h"
+
+#ifdef RECOVERYSTATS
+extern int numRecovery;
+extern unsigned int deadMachine[8];
+extern unsigned int sizeOfRedupedData[8];
+extern double elapsedTime[8];
+#endif
+
+#else
+#include "DSTM/interface/dstm.h"
+#include "DSTM/interface/altprelookup.h"
+#include "DSTM/interface/prefetch.h"
+#endif
+#endif
+#ifdef STM
+#include "tm.h"
+#include <pthread.h>
+#endif
+#ifdef STMLOG
+#define ARRAY_LENGTH 700003
+__thread int counter;
+__thread int event[ARRAY_LENGTH];
+__thread unsigned long long clkticks[ARRAY_LENGTH];
+unsigned long long beginClock=0;
+#define FILENAME "log"
+#endif
+#ifdef EVENTMONITOR
+#include "monitor.h"
+__thread int objcount=0;
+#define ASSIGNUID(x) { \
+ int number=((objcount++)<<EVTHREADSHIFT)|threadnum; \
+ x->objuid=number; \
+}
+#else
+#define ASSIGNUID(x)
+#endif
+
+#if defined(THREADS)||defined(STM)
+#ifndef MAC
+/* Global barrier for STM */
+pthread_barrier_t barrier;
+pthread_barrierattr_t attr;
+#endif
+#endif
+
+#include <string.h>
+
+#ifndef bool
+#define bool int
+#endif
+#define GCPOINT(x) ((INTPTR)((x)*0.99))
+
extern int classsize[];
+extern int typearray[];
+extern int typearray2[];
jmp_buf error_handler;
int instructioncount;
char *options;
int injectfailures=0;
float failurechance=0;
+int errors=0;
int debugtask=0;
int injectinstructionfailures;
int failurecount;
float instfailurechance=0;
int numfailures;
int instaccum=0;
+typedef unsigned long long ticks;
#ifdef DMALLOC
#include "dmalloc.h"
#endif
+int instanceof(ObjectPtr ptr, int type) {
+ int i=ptr->type;
+ do {
+ if (i==type)
+ return 1;
+ i=typearray[i];
+ } while(i!=-1);
+ i=ptr->type;
+ if (i>NUMCLASSES) {
+ do {
+ if (i==type)
+ return 1;
+ i=typearray2[i-NUMCLASSES];
+ } while(i!=-1);
+ }
+ return 0;
+}
-#ifdef TASK
-#include "checkpoint.h"
-#include "Queue.h"
-#include "SimpleHash.h"
-#include "GenericHashtable.h"
-#include <sys/select.h>
+void exithandler(int sig, siginfo_t *info, void * uap) {
+ exit(0);
+}
-#ifdef CONSCHECK
-#include "instrument.h"
-#endif
+void initializeexithandler() {
+ struct sigaction sig;
+ sig.sa_sigaction=&exithandler;
+ sig.sa_flags=SA_SIGINFO;
+ sigemptyset(&sig.sa_mask);
+ sigaction(SIGUSR2, &sig, 0);
+}
-struct genhashtable * activetasks;
-struct parameterwrapper * objectqueues[NUMCLASSES];
-struct genhashtable * failedtasks;
-struct taskparamdescriptor * currtpd;
-struct RuntimeHash * forward;
-struct RuntimeHash * reverse;
+/* This function inject failures */
-int main(int argc, char **argv) {
-#ifdef BOEHM_GC
- GC_init(); // Initialize the garbage collector
+void injectinstructionfailure() {
+#ifdef TASK
+ if (injectinstructionfailures) {
+ if (numfailures==0)
+ return;
+ instructioncount=failurecount;
+ instaccum+=failurecount;
+ if ((((double)random())/RAND_MAX)<instfailurechance) {
+ if (numfailures>0)
+ numfailures--;
+ printf("FAILURE!!! %d\n",numfailures);
+ longjmp(error_handler,11);
+ }
+ }
+#else
+#ifdef THREADS
+ if (injectinstructionfailures) {
+ if (numfailures==0)
+ return;
+ instaccum+=failurecount;
+ if ((((double)random())/RAND_MAX)<instfailurechance) {
+ if (numfailures>0)
+ numfailures--;
+ printf("FAILURE!!! %d\n",numfailures);
+ threadexit();
+ }
+ }
#endif
-#ifdef CONSCHECK
- initializemmap();
#endif
- processOptions();
- initializeexithandler();
- /* Create table for failed tasks */
- failedtasks=genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd,
- (int (*)(void *,void *)) &comparetpd);
- /* Create queue of active tasks */
- activetasks=genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd,
- (int (*)(void *,void *)) &comparetpd);
-
-
- /* Process task information */
- processtasks();
-
- /* Create startup object */
- createstartupobject(argc, argv);
-
- /* Start executing the tasks */
- executetasks();
}
-void createstartupobject(int argc, char ** argv) {
+#ifdef D___Double______nativeparsedouble____L___String___
+double CALL01(___Double______nativeparsedouble____L___String___,struct ___String___ * ___str___) {
+ int length=VAR(___str___)->___count___;
+ int maxlength=(length>60) ? 60 : length;
+ char str[maxlength+1];
+ struct ArrayObject * chararray=VAR(___str___)->___value___;
int i;
-
- /* Allocate startup object */
-#ifdef PRECISE_GC
- struct ___StartupObject___ *startupobject=(struct ___StartupObject___*) allocate_new(NULL, STARTUPTYPE);
- struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-1);
-#else
- struct ___StartupObject___ *startupobject=(struct ___StartupObject___*) allocate_new(STARTUPTYPE);
- struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);
-#endif
- /* Build array of strings */
- startupobject->___parameters___=stringarray;
- for(i=1;i<argc;i++) {
- int length=strlen(argv[i]);
-#ifdef PRECISE_GC
- struct ___String___ *newstring=NewString(NULL, argv[i],length);
-#else
- struct ___String___ *newstring=NewString(argv[i],length);
-#endif
- ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-1]=newstring;
+ int offset=VAR(___str___)->___offset___;
+ for(i=0; i<maxlength; i++) {
+ str[i]=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
}
-
- /* Set initialized flag for startup object */
- flagorand(startupobject,1,0xFFFFFFFF);
+ str[i]=0;
+ double d=atof(str);
+ return d;
}
+#endif
-int hashCodetpd(struct taskparamdescriptor *ftd) {
- int hash=(int)ftd->task;
+#ifdef D___Double______nativeparsedouble_____AR_B_I_I
+double CALL23(___Double______nativeparsedouble_____AR_B_I_I, int start, int length,int start,int length,struct ArrayObject * ___str___) {
+ int maxlength=(length>60) ? 60 : length;
+ char str[maxlength+1];
+ struct ArrayObject * bytearray=VAR(___str___);
int i;
- for(i=0;i<ftd->numParameters;i++) {
- hash^=(int)ftd->parameterArray[i];
+ for(i=0; i<maxlength; i++) {
+ str[i]=(((char *)&bytearray->___length___)+sizeof(int))[i+start];
}
- return hash;
+ str[i]=0;
+ double d=atof(str);
+ return d;
}
+#endif
-int comparetpd(struct taskparamdescriptor *ftd1, struct taskparamdescriptor *ftd2) {
+#ifdef D___Double______doubleToRawLongBits____D
+typedef union jvalue {
+ bool z;
+ char c;
+ short s;
int i;
- if (ftd1->task!=ftd2->task)
- return 0;
- for(i=0;i<ftd1->numParameters;i++)
- if (ftd1->parameterArray[i]!=ftd2->parameterArray[i])
- return 0;
- return 1;
+ long long j;
+ float f;
+ double d;
+} jvalue;
+
+long long CALL11(___Double______doubleToRawLongBits____D, double dval, double dval) {
+ jvalue val;
+ val.d = dval;
+
+#if defined(__IEEE_BYTES_LITTLE_ENDIAN)
+ /* On little endian ARM processors when using FPA, word order of
+ doubles is still big endian. So take that into account here. When
+ using VFP, word order of doubles follows byte order. */
+
+#define SWAP_DOUBLE(a) (((a) << 32) | (((a) >> 32) & 0x00000000ffffffff))
+
+ val.j = SWAP_DOUBLE(val.j);
+#endif
+
+ return val.j;
}
+#endif
+#ifdef D___Double______longBitsToDouble____J
+double CALL11(___Double______longBitsToDouble____J, long long lval, long long lval) {
+ jvalue val;
+ val.j = lval;
-/* This function sets a tag. */
-#ifdef PRECISE_GC
-void tagset(void *ptr, struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
-#else
-void tagset(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
+#if defined(__IEEE_BYTES_LITTLE_ENDIAN)
+#ifndef SWAP_DOUBLE
+#define SWAP_DOUBLE(a) (((a) << 32) | (((a) >> 32) & 0x00000000ffffffff))
#endif
- struct ___Object___ * tagptr=obj->___tags___;
- if (tagptr==NULL) {
- obj->___tags___=(struct ___Object___ *)tagd;
- } else {
- /* Have to check if it is already set */
- if (tagptr->type==TAGTYPE) {
- struct ___TagDescriptor___ * td=(struct ___TagDescriptor___ *) tagptr;
- if (td==tagd)
- return;
-#ifdef PRECISE_GC
- int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
- struct ArrayObject * ao=allocate_newarray(&ptrarray,TAGARRAYTYPE,TAGARRAYINTERVAL);
- obj=(struct ___Object___ *)ptrarray[2];
- tagd=(struct ___TagDescriptor___ *)ptrarray[3];
- td=(struct ___TagDescriptor___ *) obj->___tags___;
-#else
- struct ArrayObject * ao=allocate_newarray(TAGARRAYTYPE,TAGARRAYINTERVAL);
-#endif
- ARRAYSET(ao, struct ___TagDescriptor___ *, 0, td);
- ARRAYSET(ao, struct ___TagDescriptor___ *, 1, tagd);
- obj->___tags___=(struct ___Object___ *) ao;
- ao->___cachedCode___=2;
- } else {
- /* Array Case */
- int i;
- struct ArrayObject *ao=(struct ArrayObject *) tagptr;
- for(i=0;i<ao->___cachedCode___;i++) {
- struct ___TagDescriptor___ * td=ARRAYGET(ao, struct ___TagDescriptor___*, i);
- if (td==tagd)
- return;
- }
- if (ao->___cachedCode___<ao->___length___) {
- ARRAYSET(ao, struct ___TagDescriptor___ *, ao->___cachedCode___, tagd);
- ao->___cachedCode___++;
- } else {
-#ifdef PRECISE_GC
- int ptrarray[]={2,(int) ptr, (int) obj, (int) tagd};
- struct ArrayObject * aonew=allocate_newarray(&ptrarray,TAGARRAYTYPE,TAGARRAYINTERVAL+ao->___length___);
- obj=(struct ___Object___ *)ptrarray[2];
- tagd=(struct ___TagDescriptor___ *) ptrarray[3];
- ao=(struct ArrayObject *)obj->___tags___;
-#else
- struct ArrayObject * aonew=allocate_newarray(TAGARRAYTYPE,TAGARRAYINTERVAL+ao->___length___);
+ val.j = SWAP_DOUBLE(val.j);
#endif
- aonew->___cachedCode___=ao->___length___+1;
- for(i=0;i<ao->___length___;i++) {
- ARRAYSET(aonew, struct ___TagDescriptor___*, i, ARRAYGET(ao, struct ___TagDescriptor___*, i));
- }
- ARRAYSET(aonew, struct ___TagDescriptor___ *, ao->___length___, tagd);
- }
- }
- }
- {
- struct ___Object___ * tagset=tagd->flagptr;
-
- if(tagset==NULL) {
- tagd->flagptr=obj;
- } else if (tagset->type!=OBJECTARRAYTYPE) {
-#ifdef PRECISE_GC
- int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
- struct ArrayObject * ao=allocate_newarray(&ptrarray,OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
- obj=(struct ___Object___ *)ptrarray[2];
- tagd=(struct ___TagDescriptor___ *)ptrarray[3];
-#else
- struct ArrayObject * ao=allocate_newarray(OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
-#endif
- ARRAYSET(ao, struct ___Object___ *, 0, tagd->flagptr);
- ARRAYSET(ao, struct ___Object___ *, 1, obj);
- ao->___cachedCode___=2;
- tagd->flagptr=(struct ___Object___ *)ao;
- } else {
- struct ArrayObject *ao=(struct ArrayObject *) tagset;
- if (ao->___cachedCode___<ao->___length___) {
- ARRAYSET(ao, struct ___Object___*, ao->___cachedCode___++, obj);
- } else {
- int i;
-#ifdef PRECISE_GC
- int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
- struct ArrayObject * aonew=allocate_newarray(&ptrarray,OBJECTARRAYTYPE,OBJECTARRAYINTERVAL+ao->___length___);
- obj=(struct ___Object___ *)ptrarray[2];
- tagd=(struct ___TagDescriptor___ *)ptrarray[3];
- ao=(struct ArrayObject *)tagd->flagptr;
-#else
- struct ArrayObject * aonew=allocate_newarray(OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
-#endif
- aonew->___cachedCode___=ao->___cachedCode___+1;
- for(i=0;i<ao->___length___;i++) {
- ARRAYSET(aonew, struct ___Object___*, i, ARRAYGET(ao, struct ___Object___*, i));
- }
- ARRAYSET(aonew, struct ___Object___ *, ao->___cachedCode___, obj);
- tagd->flagptr=(struct ___Object___ *) ao;
- }
- }
- }
+ return val.d;
}
-
-/* This function clears a tag. */
-#ifdef PRECISE_GC
-void tagclear(void *ptr, struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
-#else
-void tagclear(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
#endif
- /* We'll assume that tag is alway there.
- Need to statically check for this of course. */
- struct ___Object___ * tagptr=obj->___tags___;
- if (tagptr->type==TAGTYPE) {
- if ((struct ___TagDescriptor___ *)tagptr==tagd)
- obj->___tags___=NULL;
- else
- printf("ERROR 1 in tagclear\n");
+#ifdef D___String______convertdoubletochar____D__AR_C
+int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
+ int length=VAR(___chararray___)->___length___;
+ char str[length];
+ int i;
+ int num=snprintf(str, length, "%f",___val___);
+ if (num>=length)
+ num=length-1;
+ for(i=0; i<length; i++) {
+ ((short *)(((char *)&VAR(___chararray___)->___length___)+sizeof(int)))[i]=(short)str[i];
+ }
+ return num;
+}
+#endif
+#ifdef D___System______deepArrayCopy____L___Object____L___Object___
+void deepArrayCopy(struct ___Object___ * dst, struct ___Object___ * src) {
+ int dsttype=((int *)dst)[0];
+ int srctype=((int *)src)[0];
+#ifdef STMARRAY
+ src=src->___objlocation___;
+#endif
+ if (dsttype<NUMCLASSES||srctype<NUMCLASSES||srctype!=dsttype)
+ return;
+ struct ArrayObject *aodst=(struct ArrayObject *)dst;
+ struct ArrayObject *aosrc=(struct ArrayObject *)src;
+ int dstlength=aodst->___length___;
+ int srclength=aosrc->___length___;
+ if (dstlength!=srclength)
+ return;
+ unsigned INTPTR *pointer=pointerarray[srctype];
+ if (pointer==0) {
+ int elementsize=classsize[srctype];
+ int size=srclength*elementsize;
+ //primitives
+ memcpy(((char *)&aodst->___length___)+sizeof(int), ((char *)&aosrc->___length___)+sizeof(int), size);
} else {
- struct ArrayObject *ao=(struct ArrayObject *) tagptr;
+ //objects
int i;
- for(i=0;i<ao->___cachedCode___;i++) {
- struct ___TagDescriptor___ * td=ARRAYGET(ao, struct ___TagDescriptor___ *, i);
- if (td==tagd) {
- ao->___cachedCode___--;
- if (i<ao->___cachedCode___)
- ARRAYSET(ao, struct ___TagDescriptor___ *, i, ARRAYGET(ao, struct ___TagDescriptor___ *, ao->___cachedCode___));
- ARRAYSET(ao, struct ___TagDescriptor___ *, ao->___cachedCode___, NULL);
- if (ao->___cachedCode___==0)
- obj->___tags___=NULL;
- goto PROCESSCLEAR;
- }
- }
- printf("ERROR 2 in tagclear\n");
- }
- PROCESSCLEAR:
- {
- struct ___Object___ *tagset=tagd->flagptr;
- if (tagset->type!=OBJECTARRAYTYPE) {
- if (tagset==obj)
- tagd->flagptr=NULL;
- else
- printf("ERROR 3 in tagclear\n");
- } else {
- struct ArrayObject *ao=(struct ArrayObject *) tagset;
- int i;
- for(i=0;i<ao->___cachedCode___;i++) {
- struct ___Object___ * tobj=ARRAYGET(ao, struct ___Object___ *, i);
- if (tobj==obj) {
- ao->___cachedCode___--;
- if (i<ao->___cachedCode___)
- ARRAYSET(ao, struct ___Object___ *, i, ARRAYGET(ao, struct ___Object___ *, ao->___cachedCode___));
- ARRAYSET(ao, struct ___Object___ *, ao->___cachedCode___, NULL);
- if (ao->___cachedCode___==0)
- tagd->flagptr=NULL;
- goto ENDCLEAR;
- }
+ for(i=0; i<srclength; i++) {
+ struct ___Object___ * ptr=((struct ___Object___**)(((char*) &aosrc->___length___)+sizeof(int)))[i];
+ int ptrtype=((int *)ptr)[0];
+ if (ptrtype>=NUMCLASSES) {
+ struct ___Object___ * dstptr=((struct ___Object___**)(((char*) &aodst->___length___)+sizeof(int)))[i];
+ deepArrayCopy(dstptr,ptr);
+ } else {
+ //hit an object
+ ((struct ___Object___ **)(((char*) &aodst->___length___)+sizeof(int)))[i]=ptr;
}
- printf("ERROR 4 in tagclear\n");
}
}
- ENDCLEAR:
- return;
-
}
-
-/* This function allocates a new tag. */
-#ifdef PRECISE_GC
-struct ___TagDescriptor___ * allocate_tag(void *ptr, int index) {
- struct ___TagDescriptor___ * v=(struct ___TagDescriptor___ *) mygcmalloc((struct garbagelist *) ptr, classsize[STARTUPTYPE]);
-#else
-struct ___TagDescriptor___ * allocate_tag(int index) {
- struct ___TagDescriptor___ * v=FREEMALLOC(classsize[STARTUPTYPE]);
+
+void CALL02(___System______deepArrayCopy____L___Object____L___Object___, struct ___Object___ * ___dst___, struct ___Object___ * ___src___) {
+ deepArrayCopy(VAR(___dst___), VAR(___src___));
+}
#endif
- v->type=STARTUPTYPE;
- v->flag=index;
- return v;
-}
+#ifdef D___System______arraycopy____L___Object____I_L___Object____I_I
+void arraycopy(struct ___Object___ *src, int srcPos, struct ___Object___ *dst, int destPos, int length) {
+ int dsttype=((int *)dst)[0];
+ int srctype=((int *)src)[0];
+ //not an array or type mismatch
+ if (dsttype<NUMCLASSES||srctype<NUMCLASSES)
+ return;
+ if (srctype!=dsttype)
+ printf("Potential type mismatch in arraycopy\n");
-/* This function updates the flag for object ptr. It or's the flag
- with the or mask and and's it with the andmask. */
+ struct ArrayObject *aodst=(struct ArrayObject *)dst;
+ struct ArrayObject *aosrc=(struct ArrayObject *)src;
+ int dstlength=aodst->___length___;
+ int srclength=aosrc->___length___;
-void flagbody(struct ___Object___ *ptr, int flag);
+ if (length<=0)
+ return;
+ if (srcPos+length>srclength)
+ return;
+ if (destPos+length>dstlength)
+ return;
-void flagorand(void * ptr, int ormask, int andmask) {
- int oldflag=((int *)ptr)[1];
- int flag=ormask|oldflag;
- flag&=andmask;
- // Not sure why this was necessary
- // if (flag==oldflag) /* Don't do anything */
- // return;
- //else
- flagbody(ptr, flag);
+ unsigned INTPTR *pointer=pointerarray[srctype];
+ if (pointer==0) {
+ int elementsize=classsize[srctype];
+ int size=length*elementsize;
+ //primitives
+ memcpy(((char *)&aodst->___length___)+sizeof(int)+destPos*elementsize, ((char *)&aosrc->___length___)+sizeof(int)+srcPos*elementsize, size);
+ } else {
+ //objects
+ int i;
+ for(i=0; i<length; i++) {
+ struct ___Object___ * ptr=((struct ___Object___**)(((char*) &aosrc->___length___)+sizeof(int)))[i+srcPos];
+ //hit an object
+ ((struct ___Object___ **)(((char*) &aodst->___length___)+sizeof(int)))[i+destPos]=ptr;
+ }
+ }
}
-void intflagorand(void * ptr, int ormask, int andmask) {
- int oldflag=((int *)ptr)[1];
- int flag=ormask|oldflag;
- flag&=andmask;
- if (flag==oldflag) /* Don't do anything */
- return;
- else flagbody(ptr, flag);
+void CALL35(___System______arraycopy____L___Object____I_L___Object____I_I, int ___srcPos___, int ___destPos___, int ___length___, struct ___Object___ * ___src___, int ___srcPos___, struct ___Object___ * ___dst___, int ___destPos___, int ___length___) {
+ arraycopy(VAR(___src___), ___srcPos___, VAR(___dst___), ___destPos___, ___length___);
}
+#endif
-void flagorandinit(void * ptr, int ormask, int andmask) {
- int oldflag=((int *)ptr)[1];
- int flag=ormask|oldflag;
- flag&=andmask;
- flagbody(ptr,flag);
+#ifdef D___Runtime______availableProcessors____
+int CALL01(___Runtime______availableProcessors____, struct ___Runtime___ * ___this___) {
+ printf("Unimplemented Runtime.availableProcessors\n");
+ return 24;
}
+#endif
-void flagbody(struct ___Object___ *ptr, int flag) {
- struct parameterwrapper *flagptr=(struct parameterwrapper *)ptr->flagptr;
- ptr->flag=flag;
-
- /*Remove object from all queues */
- while(flagptr!=NULL) {
- struct parameterwrapper *next;
- struct ___Object___ * tag=ptr->___tags___;
- RuntimeHashget(flagptr->objectset, (int) ptr, (int *) &next);
- RuntimeHashremove(flagptr->objectset, (int)ptr, (int) next);
- flagptr=next;
- }
-
- {
- struct QueueItem *tmpptr;
- struct parameterwrapper * parameter=objectqueues[ptr->type];
- int i;
- struct parameterwrapper * prevptr=NULL;
- struct ___Object___ *tagptr=ptr->___tags___;
-
- /* Outer loop iterates through all parameter queues an object of
- this type could be in. */
-
- while(parameter!=NULL) {
- /* Check tags */
- if (parameter->numbertags>0) {
- if (tagptr==NULL)
- goto nextloop;
- else if(tagptr->type==TAGTYPE) {
- struct ___TagDescriptor___ * tag=(struct ___TagDescriptor___*) tagptr;
- for(i=0;i<parameter->numbertags;i++) {
- //slotid is parameter->tagarray[2*i];
- int tagid=parameter->tagarray[2*i+1];
- if (tagid!=tagptr->flag)
- goto nextloop; /*We don't have this tag */
- }
- } else {
- struct ArrayObject * ao=(struct ArrayObject *) tagptr;
- for(i=0;i<parameter->numbertags;i++) {
- //slotid is parameter->tagarray[2*i];
- int tagid=parameter->tagarray[2*i+1];
- int j;
- for(j=0;j<ao->___cachedCode___;j++) {
- if (tagid==ARRAYGET(ao, struct ___TagDescriptor___*, i)->flag)
- goto foundtag;
- }
- goto nextloop;
- foundtag:
- ;
- }
- }
- }
+#ifdef D___Runtime______freeMemory____
+long long CALL01(___Runtime______freeMemory____, struct ___Runtime___ * ___this___) {
+ printf("Unimplemented Runtime.freeMemory\n");
+ return 1024*1024*1024;
+}
+#endif
- /* Check flags */
- for(i=0;i<parameter->numberofterms;i++) {
- int andmask=parameter->intarray[i*2];
- int checkmask=parameter->intarray[i*2+1];
- if ((flag&andmask)==checkmask) {
- enqueuetasks(parameter, prevptr, ptr);
- prevptr=parameter;
- break;
- }
- }
- nextloop:
- parameter=parameter->next;
- }
- ptr->flagptr=prevptr;
- }
+#ifdef D___Runtime______totalMemory____
+long long CALL01(___Runtime______totalMemory____, struct ___Runtime___ * ___this___) {
+ printf("Unimplemented Runtime.totalMemory\n");
+ return 1024*1024*1024;
}
-
-void enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr) {
- void * taskpointerarray[MAXTASKPARAMS];
- int j;
- int numparams=parameter->task->numParameters;
- int numiterators=parameter->task->numTotal-1;
-
- struct taskdescriptor * task=parameter->task;
-
- RuntimeHashadd(parameter->objectset, (int) ptr, (int) prevptr);
-
- /* Add enqueued object to parameter vector */
- taskpointerarray[parameter->slot]=ptr;
-
- /* Reset iterators */
- for(j=0;j<numiterators;j++) {
- toiReset(¶meter->iterators[j]);
- }
+#endif
- /* Find initial state */
- for(j=0;j<numiterators;j++) {
- backtrackinit:
- if(toiHasNext(¶meter->iterators[j], taskpointerarray))
- toiNext(¶meter->iterators[j], taskpointerarray);
- else if (j>0) {
- /* Need to backtrack */
- toiReset(¶meter->iterators[j]);
- j--;
- goto backtrackinit;
- } else {
- /* Nothing to enqueue */
- return;
- }
+#ifdef D___Runtime______maxMemory____
+long long CALL01(___Runtime______maxMemory____, struct ___Runtime___ * ___this___) {
+ printf("Unimplemented Runtime.maxMemory\n");
+ return 1024*1024*1024;
+}
+#endif
+#ifdef D___System______exit____I
+void CALL11(___System______exit____I,int ___status___, int ___status___) {
+#ifdef TRANSSTATS
+#ifndef RECOVERY
+ printf("numTransCommit = %d\n", numTransCommit);
+ printf("numTransAbort = %d\n", numTransAbort);
+ printf("nSoftAbort = %d\n", nSoftAbort);
+#endif
+#ifdef STM
+ printf("nSoftAbortCommit = %d\n", nSoftAbortCommit);
+ printf("nSoftAbortAbort = %d\n", nSoftAbortAbort);
+#ifdef STMSTATS
+ int i;
+ for(i=0; i<TOTALNUMCLASSANDARRAY; i++) {
+ printf("typesCausingAbort[%2d] numaccess= %5d numabort= %3d\n", i, typesCausingAbort[i].numaccess, typesCausingAbort[i].numabort);
}
+#endif
+#endif
+#endif
+#ifdef EVENTMONITOR
+ dumpdata();
+#endif
+ exit(___status___);
+}
+#endif
-
- while(1) {
- /* Enqueue current state */
- struct taskparamdescriptor *tpd=RUNMALLOC(sizeof(struct taskparamdescriptor));
- tpd->task=task;
- tpd->numParameters=numiterators+1;
- tpd->parameterArray=RUNMALLOC(sizeof(void *)*(numiterators+1));
- for(j=0;j<=numiterators;j++)
- tpd->parameterArray[j]=taskpointerarray[j];
-
- /* Enqueue task */
- if (!gencontains(failedtasks, tpd)&&!gencontains(activetasks,tpd)) {
- genputtable(activetasks, tpd, tpd);
- } else {
- RUNFREE(tpd->parameterArray);
- RUNFREE(tpd);
- }
-
- /* This loop iterates to the next parameter combination */
- if (numiterators==0)
- return;
-
- for(j=numiterators-1; j<numiterators;j++) {
- backtrackinc:
- if(toiHasNext(¶meter->iterators[j], taskpointerarray))
- toiNext(¶meter->iterators[j], taskpointerarray);
- else if (j>0) {
- /* Need to backtrack */
- toiReset(¶meter->iterators[j]);
- j--;
- goto backtrackinc;
- } else {
- /* Nothing more to enqueue */
- return;
- }
- }
- }
+#ifdef D___System______logevent____I
+void CALL11(___System______logevent____I,int ___event___, int ___event___) {
+#ifdef STMLOG
+ event[counter] = ___event___;
+ clkticks[counter] = rdtsc();
+ counter++;
+#endif
+ return;
}
-
-/* Handler for signals. The signals catch null pointer errors and
- arithmatic errors. */
+#endif
-void myhandler(int sig, siginfo_t *info, void *uap) {
-#ifdef DEBUG
- printf("sig=%d\n",sig);
- printf("signal\n");
+#ifdef ___System______logevent____
+void CALL00(___System______logevent____) {
+#ifdef STMLOG
+ beginClock= rdtsc();
#endif
- longjmp(error_handler,1);
+ return;
}
+#endif
-fd_set readfds;
-int maxreadfd;
-struct RuntimeHash *fdtoobject;
+#ifdef ___System______flushToFile____I
+void CALL11(___System______flushToFile____I, int ___threadid___, int ___threadid___) {
+#ifdef STMLOG
+ FILE *fp;
+ /* Flush to file */
+ char filename[20];
+ memset(filename, 0, 20);
+ sprintf(filename, "%s_%d", FILENAME, ___threadid___);
+ if ((fp = fopen(filename, "w+")) == NULL) {
+ perror("fopen");
+ return;
+ }
+ int i;
+ for (i = 0; i < counter-1; i++) {
+ fprintf(fp, "%d %lld %lld\n", event[i], clkticks[i]-beginClock, clkticks[i+1]-beginClock);
+ }
+ fprintf(fp, "%d %lld\n", event[i], clkticks[i]-beginClock);
-void addreadfd(int fd) {
- if (fd>=maxreadfd)
- maxreadfd=fd+1;
- FD_SET(fd, &readfds);
+ fclose(fp);
+#endif
+ return;
}
+#endif
-void removereadfd(int fd) {
- FD_CLR(fd, &readfds);
- if (maxreadfd==(fd+1)) {
- maxreadfd--;
- while(maxreadfd>0&&!FD_ISSET(maxreadfd-1, &readfds))
- maxreadfd--;
+#ifdef D___System______initLog____
+void CALL00(___System______initLog____) {
+#ifdef STMLOG
+ counter=0;
+ int i;
+ for(i=0; i<ARRAY_LENGTH; i++) {
+ event[i] = 0;
+ clkticks[i] = 0;
}
-}
-#ifdef PRECISE_GC
-#define OFFSET 2
-#else
-#define OFFSET 0
+#endif
+ return;
+}
#endif
-void executetasks() {
- void * taskpointerarray[MAXTASKPARAMS+OFFSET];
+#ifdef D___Vector______removeElement_____AR_L___Object____I_I
+void CALL23(___Vector______removeElement_____AR_L___Object____I_I, int ___index___, int ___size___, struct ArrayObject * ___array___, int ___index___, int ___size___) {
+ char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___;
+ memmove(offset, offset+sizeof(void *),(___size___-___index___-1)*sizeof(void *));
+}
+#endif
- /* Set up signal handlers */
- struct sigaction sig;
- sig.sa_sigaction=&myhandler;
- sig.sa_flags=SA_SIGINFO;
- sigemptyset(&sig.sa_mask);
+#ifdef D___System______printI____I
+void CALL11(___System______printI____I,int ___status___, int ___status___) {
+ printf("%d\n",___status___);
+}
+#endif
- /* Catch bus errors, segmentation faults, and floating point exceptions*/
- sigaction(SIGBUS,&sig,0);
- sigaction(SIGSEGV,&sig,0);
- sigaction(SIGFPE,&sig,0);
- sigaction(SIGPIPE,&sig,0);
-
- /* Zero fd set */
- FD_ZERO(&readfds);
- maxreadfd=0;
- fdtoobject=allocateRuntimeHash(100);
-
- /* Map first block of memory to protected, anonymous page */
- mmap(0, 0x1000, 0, MAP_SHARED|MAP_FIXED|MAP_ANON, -1, 0);
-
- newtask:
- while((hashsize(activetasks)>0)||(maxreadfd>0)) {
-
- /* Check if any filedescriptors have IO pending */
- if (maxreadfd>0) {
- int i;
- struct timeval timeout={0,0};
- fd_set tmpreadfds;
- int numselect;
- tmpreadfds=readfds;
- numselect=select(maxreadfd, &tmpreadfds, NULL, NULL, &timeout);
- if (numselect>0) {
- /* Process ready fd's */
- int fd;
- for(fd=0;fd<maxreadfd;fd++) {
- if (FD_ISSET(fd, &tmpreadfds)) {
- /* Set ready flag on object */
- void * objptr;
- // printf("Setting fd %d\n",fd);
- if (RuntimeHashget(fdtoobject, fd,(int *) &objptr)) {
- intflagorand(objptr,1,0xFFFFFFFF); /* Set the first flag to 1 */
- }
- }
- }
- }
- }
+#ifdef D___System______currentTimeMillis____
+long long CALL00(___System______currentTimeMillis____) {
+ struct timeval tv; long long retval;
+ gettimeofday(&tv, NULL);
+ retval = tv.tv_sec; /* seconds */
+ retval*=1000; /* milliseconds */
+ retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
+ return retval;
+}
+#endif
- /* See if there are any active tasks */
- if (hashsize(activetasks)>0) {
- int i;
- currtpd=(struct taskparamdescriptor *) getfirstkey(activetasks);
- genfreekey(activetasks, currtpd);
-
- /* Check if this task has failed */
- if (gencontains(failedtasks, currtpd)) {
- // Free up task parameter descriptor
- RUNFREE(currtpd->parameterArray);
- RUNFREE(currtpd);
- goto newtask;
- }
- int numparams=currtpd->task->numParameters;
- int numtotal=currtpd->task->numTotal;
-
- /* Make sure that the parameters are still in the queues */
- for(i=0;i<numparams;i++) {
- void * parameter=currtpd->parameterArray[i];
- struct parameterdescriptor * pd=currtpd->task->descriptorarray[i];
- struct parameterwrapper *pw=(struct parameterwrapper *) pd->queue;
- int j;
- /* Check that object is still in queue */
- if (!RuntimeHashcontainskey(pw->objectset, (int) parameter)) {
- RUNFREE(currtpd->parameterArray);
- RUNFREE(currtpd);
- goto newtask;
- }
- /* Check that object still has necessary tags */
- for(j=0;j<pd->numbertags;j++) {
- int slotid=pd->tagarray[2*i]+numparams;
- struct ___TagDescriptor___ *tagd=currtpd->parameterArray[slotid];
- if (!containstag(parameter, tagd)) {
- RUNFREE(currtpd->parameterArray);
- RUNFREE(currtpd);
- goto newtask;
- }
- }
-
- taskpointerarray[i+OFFSET]=parameter;
- }
- /* Copy the tags */
- for(;i<numtotal;i++) {
- taskpointerarray[i+OFFSET]=currtpd->parameterArray[i];
- }
+#ifdef D___System______gc____
+void CALL00(___System______gc____) {
+#if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP)
+ while (pthread_mutex_trylock(&gclock)!=0) {
+ stopforgc((struct garbagelist *)___params___);
+ restartaftergc();
+ }
+#endif
- {
- /* Checkpoint the state */
- forward=allocateRuntimeHash(100);
- reverse=allocateRuntimeHash(100);
- void ** checkpoint=makecheckpoint(currtpd->task->numParameters, currtpd->parameterArray, forward, reverse);
- int x;
- if (x=setjmp(error_handler)) {
- /* Recover */
- int h;
-#ifdef DEBUG
- printf("Fatal Error=%d, Recovering!\n",x);
-#endif
- genputtable(failedtasks,currtpd,currtpd);
- restorecheckpoint(currtpd->task->numParameters, currtpd->parameterArray, checkpoint, forward, reverse);
- freeRuntimeHash(forward);
- freeRuntimeHash(reverse);
- freemalloc();
- forward=NULL;
- reverse=NULL;
- } else {
- if (injectfailures) {
- if ((((double)random())/RAND_MAX)<failurechance) {
- printf("\nINJECTING TASK FAILURE to %s\n", currtpd->task->name);
- longjmp(error_handler,10);
- }
- }
- /* Actually call task */
-#ifdef PRECISE_GC
- ((int *)taskpointerarray)[0]=currtpd->task->numParameters;
- taskpointerarray[1]=NULL;
-#endif
-
- if (debugtask) {
- printf("ENTER %s count=%d\n",currtpd->task->name, (instaccum-instructioncount));
- ((void (*) (void **)) currtpd->task->taskptr)(taskpointerarray);
- printf("EXIT %s count=%d\n",currtpd->task->name, (instaccum-instructioncount));
- } else
- ((void (*) (void **)) currtpd->task->taskptr)(taskpointerarray);
- freeRuntimeHash(forward);
- freeRuntimeHash(reverse);
- freemalloc();
- // Free up task parameter descriptor
- RUNFREE(currtpd->parameterArray);
- RUNFREE(currtpd);
- forward=NULL;
- reverse=NULL;
- }
+ /* Grow the to heap if necessary */
+ {
+ INTPTR curr_heapsize=curr_heaptop-curr_heapbase;
+ INTPTR to_heapsize=to_heaptop-to_heapbase;
+
+ if (curr_heapsize>to_heapsize) {
+ free(to_heapbase);
+ to_heapbase=malloc(curr_heapsize);
+ if (to_heapbase==NULL) {
+ printf("Error Allocating enough memory\n");
+ exit(-1);
}
+ to_heaptop=to_heapbase+curr_heapsize;
+ to_heapptr=to_heapbase;
}
}
-}
-/* This function processes an objects tags */
-void processtags(struct parameterdescriptor *pd, int index, struct parameterwrapper *parameter, int * iteratorcount, int *statusarray, int numparams) {
- int i;
- for(i=0;i<pd->numbertags;i++) {
- int slotid=pd->tagarray[2*i];
- int tagid=pd->tagarray[2*i+1];
-
- if (statusarray[slotid+numparams]==0) {
- parameter->iterators[*iteratorcount].istag=1;
- parameter->iterators[*iteratorcount].tagid=tagid;
- parameter->iterators[*iteratorcount].slot=slotid+numparams;
- parameter->iterators[*iteratorcount].tagobjectslot=index;
- statusarray[slotid+numparams]=1;
- (*iteratorcount)++;
- }
+ collect((struct garbagelist *)___params___);
+
+ {
+ void * tmp=to_heapbase;
+ to_heapbase=curr_heapbase;
+ curr_heapbase=tmp;
+
+ tmp=to_heaptop;
+ to_heaptop=curr_heaptop;
+ curr_heaptop=tmp;
+
+ tmp=to_heapptr;
+ curr_heapptr=to_heapptr;
+ curr_heapgcpoint=((char *) curr_heapbase)+GCPOINT(curr_heaptop-curr_heapbase);
+ to_heapptr=to_heapbase;
+ bzero(tmp, curr_heaptop-tmp);
+
}
+
+#if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP)
+ pthread_mutex_unlock(&gclock);
+#endif
+}
+#endif
+
+#ifdef D___System______microTimes____
+long long CALL00(___System______microTimes____) {
+ struct timeval tv;
+ long long retval;
+ gettimeofday(&tv, NULL);
+ retval = tv.tv_sec; /* seconds */
+ retval*=1000000; /* microsecs */
+ retval+= (tv.tv_usec); /* adjust microseconds & add them in */
+ return retval;
}
+#endif
+#ifdef D___System______getticks____
+long long CALL00(___System______getticks____) {
+ unsigned a, d;
+ asm ("cpuid");
+ asm volatile ("rdtsc" : "=a" (a), "=d" (d));
+ return (((ticks)a) | (((ticks)d) << 32));
+}
+#endif
-void processobject(struct parameterwrapper *parameter, int index, struct parameterdescriptor *pd, int *iteratorcount, int * statusarray, int numparams) {
+#ifdef D___System______printString____L___String___
+void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
+ struct ArrayObject * chararray=VAR(___s___)->___value___;
int i;
- int tagcount=0;
- struct RuntimeHash * objectset=((struct parameterwrapper *)pd->queue)->objectset;
-
- parameter->iterators[*iteratorcount].istag=0;
- parameter->iterators[*iteratorcount].slot=index;
- parameter->iterators[*iteratorcount].objectset=objectset;
- statusarray[index]=1;
-
- for(i=0;i<pd->numbertags;i++) {
- int slotid=pd->tagarray[2*i];
- int tagid=pd->tagarray[2*i+1];
- if (statusarray[slotid+numparams]!=0) {
- /* This tag has already been enqueued, use it to narrow search */
- parameter->iterators[*iteratorcount].tagbindings[tagcount]=slotid+numparams;
- tagcount++;
- }
+ int offset=VAR(___s___)->___offset___;
+ for(i=0; i<VAR(___s___)->___count___; i++) {
+ short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
+ putchar(sc);
}
- parameter->iterators[*iteratorcount].numtags=tagcount;
+#ifdef RECOVERYSTATS
+ fflush(stdout);
+ fflush(stdout);
+#endif
+}
+#endif
- (*iteratorcount)++;
+#ifdef D___RecoveryStat______printRecoveryStat____
+#ifdef RECOVERYSTATS
+void CALL00(___RecoveryStat______printRecoveryStat____) {
+ printRecoveryStat();
}
+#else
+void CALL00(___RecoveryStat______printRecoveryStat____) {
+ printf("No Stat\n");
+ fflush(stdout);
+}
+#endif
+#endif
-/* This function builds the iterators for a task & parameter */
+#ifdef DSTM
+#ifdef D___System______clearPrefetchCache____
+void CALL00(___System______clearPrefetchCache____) {
+ prehashClear();
+}
+#endif
-void builditerators(struct taskdescriptor * task, int index, struct parameterwrapper * parameter) {
- int statusarray[MAXTASKPARAMS];
+#ifdef RANGEPREFETCH
+#ifdef D___System______rangePrefetch____L___Object_____AR_S
+void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
+ /* Manual Prefetches to be inserted */
+ //printf("DEBUG-> %s() ___Object___ * ___o___ = %x\n", __func__, VAR(___o___));
+ //printf("DEBUG-> %s() ArrayObject * = %x\n", __func__, VAR(___offsets___));
+ int numoffset=VAR(___offsets___)->___length___;
int i;
- int numparams=task->numParameters;
- int iteratorcount=0;
- for(i=0;i<MAXTASKPARAMS;i++) statusarray[i]=0;
-
- statusarray[index]=1; /* Initial parameter */
- /* Process tags for initial iterator */
-
- processtags(task->descriptorarray[index], index, parameter, & iteratorcount, statusarray, numparams);
-
- while(1) {
- loopstart:
- /* Check for objects with existing tags */
- for(i=0;i<numparams;i++) {
- if (statusarray[i]==0) {
- struct parameterdescriptor *pd=task->descriptorarray[i];
- int j;
- for(j=0;j<pd->numbertags;j++) {
- int slotid=pd->tagarray[2*j];
- if(statusarray[slotid+numparams]!=0) {
- processobject(parameter, i, pd, &iteratorcount, statusarray, numparams);
- processtags(pd, i, parameter, &iteratorcount, statusarray, numparams);
- goto loopstart;
- }
- }
- }
- }
- /* Nothing with a tag enqueued */
-
- for(i=0;i<numparams;i++) {
- if (statusarray[i]==0) {
- struct parameterdescriptor *pd=task->descriptorarray[i];
- processobject(parameter, i, pd, &iteratorcount, statusarray, numparams);
- processtags(pd, i, parameter, &iteratorcount, statusarray, numparams);
- goto loopstart;
- }
- }
-
- /* Nothing left */
- return;
+ short offArry[numoffset+2];
+ offArry[0] = 0;
+ offArry[1] = 0;
+ for(i = 2; i<(numoffset+2); i++) {
+ offArry[i] = *((short *)(((char *)&VAR(___offsets___)->___length___) + sizeof(int) + (i-2) * sizeof(short)));
+ //printf("DEBUG-> offArry[%d] = %d\n", i, offArry[i]);
+ }
+ unsigned int oid;
+ if(((unsigned int)(VAR(___o___)) & 1) != 0) { //odd
+ oid = (unsigned int) VAR(___o___); //outside transaction therefore just an oid
+ } else { //even
+ oid = (unsigned int) COMPOID(VAR(___o___)); //inside transaction therefore a pointer to oid
}
+ rangePrefetch(oid, (short)(numoffset+2), offArry);
}
+#else
+void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
+ return;
+}
+#endif
+#endif
+#ifdef D___Task______execution____
+extern void* virtualtable[];
+// associated with Task.execution(). finds proper execute method and call it
+void CALL01(___Task______execution____,struct ___Task___ * ___this___) {
+ unsigned int oid;
+ oid = (unsigned int) VAR(___this___); // object id
+ int type = getObjType(oid); // object type
-
+#ifdef PRECISE_GC
+ int p[] = {1,0, oid};
+ ((void (*)(void *))virtualtable[type*MAXCOUNT + EXECUTEMETHOD])(p);
+#else
+ // call the proper execute method
+ ((void (*)(void *))virtualtable[type*MAXCOUNT + EXECUTEMETHOD])(oid);
+#endif
+}
+#endif
-/* This function processes the task information to create queues for
- each parameter type. */
+#endif // DSTM
-void processtasks() {
- int i;
- for(i=0;i<numtasks;i++) {
- struct taskdescriptor * task=taskarray[i];
- int j;
-
- for(j=0;j<task->numParameters;j++) {
- struct parameterdescriptor *param=task->descriptorarray[j];
- struct parameterwrapper * parameter=RUNMALLOC(sizeof(struct parameterwrapper));
- struct parameterwrapper ** ptr=&objectqueues[param->type];
-
- param->queue=parameter;
- parameter->objectset=allocateRuntimeHash(10);
- parameter->numberofterms=param->numberterms;
- parameter->intarray=param->intarray;
- parameter->numbertags=param->numbertags;
- parameter->tagarray=param->tagarray;
- parameter->task=task;
- /* Link new queue in */
- while((*ptr)!=NULL)
- ptr=&((*ptr)->next);
- (*ptr)=parameter;
- }
-
- /* Build iterators for parameters */
- for(j=0;j<task->numParameters;j++) {
- struct parameterdescriptor *param=task->descriptorarray[j];
- struct parameterwrapper *parameter=param->queue;
- parameter->slot=j;
- builditerators(task, j, parameter);
- }
+/* STM Barrier constructs */
+#ifdef D___Barrier______setBarrier____I
+void CALL11(___Barrier______setBarrier____I, int nthreads, int nthreads) {
+ // Barrier initialization
+ int ret;
+ if((ret = pthread_barrier_init(&barrier, NULL, nthreads)) != 0) {
+ printf("%s() Could not create a barrier: numthreads = 0 in %s\n", __func__, __FILE__);
+ exit(-1);
}
}
+#endif
-void toiReset(struct tagobjectiterator * it) {
- if (it->istag) {
- it->tagobjindex=0;
- } else if (it->numtags>0) {
- it->tagobjindex=0;
- } else {
- RuntimeHashiterator(it->objectset, &it->it);
+#ifdef D___Barrier______enterBarrier____
+void CALL00(___Barrier______enterBarrier____) {
+ // Synchronization point
+ int ret;
+#ifdef EVENTMONITOR
+ EVLOGEVENT(EV_ENTERBARRIER);
+#endif
+#ifdef PRECISE_GC
+ stopforgc((struct garbagelist *)___params___);
+#endif
+ ret = pthread_barrier_wait(&barrier);
+#ifdef PRECISE_GC
+ restartaftergc();
+#endif
+ if(ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) {
+ printf("%s() Could not wait on barrier: error %d in %s\n", __func__, errno, __FILE__);
+ exit(-1);
}
+#ifdef EVENTMONITOR
+ EVLOGEVENT(EV_EXITBARRIER);
+#endif
}
+#endif
-int toiHasNext(struct tagobjectiterator *it, void ** objectarray) {
- if (it->istag) {
- /* Iterate tag */
- /* Get object with tags */
- struct ___Object___ *obj=objectarray[it->tagobjectslot];
- struct ___Object___ *tagptr=obj->___tags___;
- if (tagptr->type==TAGTYPE) {
- if ((it->tagobjindex==0)&& /* First object */
- (it->tagid==((struct ___TagDescriptor___ *)tagptr)->flag)) /* Right tag type */
- return 1;
- else
- return 0;
- } else {
- struct ArrayObject *ao=(struct ArrayObject *) tagptr;
- int tagindex=it->tagobjindex;
- for(;tagindex<ao->___cachedCode___;tagindex++) {
- struct ___TagDescriptor___ *td=ARRAYGET(ao, struct ___TagDescriptor___ *, tagindex);
- if (td->flag==it->tagid) {
- it->tagobjindex=tagindex; /* Found right type of tag */
- return 1;
- }
- }
- return 0;
- }
- } else if (it->numtags>0) {
- /* Use tags to locate appropriate objects */
- struct ___TagDescriptor___ *tag=objectarray[it->tagbindings[0]];
- struct ___Object___ *objptr=tag->flagptr;
- int i;
- if (objptr->type!=OBJECTARRAYTYPE) {
- if (it->tagobjindex>0)
- return 0;
- if (!RuntimeHashcontainskey(it->objectset, (int) objptr))
- return 0;
- for(i=1;i<it->numtags;i++) {
- struct ___TagDescriptor___ *tag2=objectarray[it->tagbindings[i]];
- if (!containstag(objptr,tag2))
- return 0;
- }
- return 1;
- } else {
- struct ArrayObject *ao=(struct ArrayObject *) objptr;
- int tagindex;
- int i;
- for(tagindex=it->tagobjindex;tagindex<ao->___cachedCode___;tagindex++) {
- struct ___Object___ *objptr=ARRAYGET(ao, struct ___Object___*, tagindex);
- if (!RuntimeHashcontainskey(it->objectset, (int) objptr))
- continue;
- for(i=1;i<it->numtags;i++) {
- struct ___TagDescriptor___ *tag2=objectarray[it->tagbindings[i]];
- if (!containstag(objptr,tag2))
- goto nexttag;
- }
- return 1;
- nexttag:
- ;
- }
- it->tagobjindex=tagindex;
- return 0;
- }
- } else {
- return RunhasNext(&it->it);
- }
-}
+/* Object allocation function */
-int containstag(struct ___Object___ *ptr, struct ___TagDescriptor___ *tag) {
- int j;
- struct ___Object___ * objptr=tag->flagptr;
- if (objptr->type==OBJECTARRAYTYPE) {
- struct ArrayObject *ao=(struct ArrayObject *)objptr;
- for(j=0;j<ao->___cachedCode___;j++) {
- if (ptr==ARRAYGET(ao, struct ___Object___*, j))
- return 1;
- }
- return 0;
- } else
- return objptr==ptr;
+#ifdef DSTM
+__attribute__((malloc)) void * allocate_newglobal(int type) {
+ struct ___Object___ * v=(struct ___Object___ *) transCreateObj(classsize[type]);
+ v->type=type;
+ v->hashcode=(int)(INTPTR)v;
+ //printf("DEBUG %s(), type= %x\n", __func__, type);
+#ifdef THREADS
+ v->tid=0;
+#endif
+ return v;
}
-void toiNext(struct tagobjectiterator *it , void ** objectarray) {
- /* hasNext has all of the intelligence */
- if(it->istag) {
- /* Iterate tag */
- /* Get object with tags */
- struct ___Object___ *obj=objectarray[it->tagobjectslot];
- struct ___Object___ *tagptr=obj->___tags___;
- if (tagptr->type==TAGTYPE) {
- it->tagobjindex++;
- objectarray[it->slot]=tagptr;
- } else {
- struct ArrayObject *ao=(struct ArrayObject *) tagptr;
- objectarray[it->slot]=ARRAYGET(ao, struct ___TagDescriptor___ *, it->tagobjindex++);
- }
- } else if (it->numtags>0) {
- /* Use tags to locate appropriate objects */
- struct ___TagDescriptor___ *tag=objectarray[it->tagbindings[0]];
- struct ___Object___ *objptr=tag->flagptr;
- if (objptr->type!=OBJECTARRAYTYPE) {
- it->tagobjindex++;
- objectarray[it->slot]=objptr;
- } else {
- struct ArrayObject *ao=(struct ArrayObject *) objptr;
- objectarray[it->slot]=ARRAYGET(ao, struct ___Object___ *, it->tagobjindex++);
- }
- } else {
- /* Iterate object */
- objectarray[it->slot]=(void *)Runkey(&it->it);
- Runnext(&it->it);
+/* Array allocation function */
+
+__attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, int length) {
+ struct ArrayObject * v=(struct ArrayObject *)transCreateObj(sizeof(struct ArrayObject)+length*classsize[type]);
+ if (length<0) {
+ printf("ERROR: negative array\n");
+ return NULL;
}
+ v->type=type;
+ v->hashcode=(int)(INTPTR)v;
+ v->___length___=length;
+#ifdef THREADS
+ v->tid=0;
+#endif
+ return v;
}
+#endif
-#endif
+#ifdef STM
+// STM Versions of allocation functions
-void exithandler(int sig, siginfo_t *info, void * uap) {
- exit(0);
+/* Object allocation function */
+__attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) {
+#ifdef STMARRAY
+ struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type], 0);
+#else
+ struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type]);
+#endif
+ ASSIGNUID(v);
+ v->type=type;
+ v->hashcode=(int)(INTPTR)v;
+ v->___objlocation___=v;
+ return v;
}
-void initializeexithandler() {
- struct sigaction sig;
- sig.sa_sigaction=&exithandler;
- sig.sa_flags=SA_SIGINFO;
- sigemptyset(&sig.sa_mask);
- sigaction(SIGUSR2, &sig, 0);
+/* Array allocation function */
+__attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length) {
+#ifdef STMARRAY
+ int basesize=length*classsize[type];
+ //round the base size up
+ basesize=(basesize+LOWMASK)&HIGHMASK;
+ int numlocks=basesize>>INDEXSHIFT;
+ int bookkeepsize=numlocks*2*sizeof(int);
+ struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+basesize+bookkeepsize, bookkeepsize);
+ unsigned int *intptr=(unsigned int *)(((char *)v)-sizeof(objheader_t));
+ for(; numlocks>0; numlocks--) {
+ intptr-=2;
+ intptr[0]=1;
+ }
+ v->highindex=-1;
+ v->lowindex=MAXARRAYSIZE;
+#else
+ struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]);
+#endif
+ ASSIGNUID(v);
+ if (length<0) {
+ printf("ERROR: negative array\n");
+ return NULL;
+ }
+ v->___objlocation___=(struct ___Object___*)v;
+ v->type=type;
+ v->hashcode=(int)(INTPTR)v;
+ v->___length___=length;
+ return v;
}
+__attribute__((malloc)) void * allocate_new(void * ptr, int type) {
+ objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t));
+ struct ___Object___ * v=(struct ___Object___ *) &tmp[1];
+ ASSIGNUID(v);
+ initdsmlocks(&tmp->lock);
+ tmp->version = 1;
+ v->___objlocation___=v;
+ v->type = type;
+ v->hashcode=(int)(INTPTR)v;
+ return v;
+}
-/* This function inject failures */
+/* Array allocation function */
-void injectinstructionfailure() {
-#ifdef TASK
- if (injectinstructionfailures) {
- if (numfailures==0)
- return;
- instructioncount=failurecount;
- instaccum+=failurecount;
- if ((((double)random())/RAND_MAX)<instfailurechance) {
- if (numfailures>0)
- numfailures--;
- printf("FAILURE!!! %d\n",numfailures);
- longjmp(error_handler,11);
- }
+__attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
+#ifdef STMARRAY
+ int basesize=length*classsize[type];
+ //round the base size up
+ basesize=(basesize+LOWMASK)&HIGHMASK;
+ int numlocks=basesize>>INDEXSHIFT;
+ int bookkeepsize=(numlocks)*2*sizeof(int);
+ int *tmpint=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+basesize+sizeof(objheader_t)+bookkeepsize);
+ for(; numlocks>0; numlocks--) {
+ tmpint[0]=1;
+ tmpint+=2;
}
+ objheader_t *tmp=(objheader_t *)tmpint;
+ struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
+ v->highindex=-1;
+ v->lowindex=MAXARRAYSIZE;
#else
-#ifdef THREADS
- if (injectinstructionfailures) {
- if (numfailures==0)
- return;
- instaccum+=failurecount;
- if ((((double)random())/RAND_MAX)<instfailurechance) {
- if (numfailures>0)
- numfailures--;
- printf("FAILURE!!! %d\n",numfailures);
- threadexit();
- }
- }
+ objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t));
+ struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
#endif
+#ifdef DUALVIEW
+ tmp->lock=RW_LOCK_BIAS;
+#else
+ initdsmlocks(&tmp->lock);
#endif
+ tmp->version=1;
+ ASSIGNUID(v);
+ v->type=type;
+ v->hashcode=(int)(INTPTR)v;
+ if (length<0) {
+ printf("ERROR: negative array %d\n", length);
+ return NULL;
+ }
+ v->___objlocation___=(struct ___Object___ *)v;
+ v->___length___=length;
+ return v;
}
+#endif
-void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
- struct ArrayObject * chararray=VAR(___s___)->___value___;
- int i;
- int offset=VAR(___s___)->___offset___;
- for(i=0;i<VAR(___s___)->___count___;i++) {
- short sc=((short *)(((char *)& chararray->___length___)+sizeof(int)))[i+offset];
- putchar(sc);
- }
+#ifndef STM
+#if defined(PRECISE_GC)
+#ifdef MLP
+__attribute__((malloc)) void * allocate_new(void * ptr, int type) {
+ return allocate_new_mlp(ptr, type, 0, 0);
}
-
-/* Object allocation function */
-
-#ifdef PRECISE_GC
-void * allocate_new(void * ptr, int type) {
- struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
+__attribute__((malloc)) void * allocate_new_mlp(void * ptr, int type, int oid, int allocsite) {
+#else
+__attribute__((malloc)) void * allocate_new(void * ptr, int type) {
+#endif
+ ObjectPtr v=(ObjectPtr) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
v->type=type;
+ v->hashcode=(int)(INTPTR)v;
#ifdef THREADS
v->tid=0;
- v->lockentry=0;
- v->lockcount=0;
+#endif
+#ifdef OPTIONAL
+ v->fses=0;
+#endif
+#ifdef MLP
+ v->oid=oid;
+ v->allocsite=allocsite;
#endif
return v;
}
/* Array allocation function */
-
-struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
+#ifdef MLP
+__attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
+ return allocate_newarray_mlp(ptr, type, length, 0, 0);
+}
+__attribute__((malloc)) struct ArrayObject * allocate_newarray_mlp(void * ptr, int type, int length, int oid, int allocsite) {
+#else
+__attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
+#endif
struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
v->type=type;
+ v->hashcode=(int)(INTPTR)v;
if (length<0) {
printf("ERROR: negative array\n");
return NULL;
v->___length___=length;
#ifdef THREADS
v->tid=0;
- v->lockentry=0;
- v->lockcount=0;
+#endif
+#ifdef OPTIONAL
+ v->fses=0;
+#endif
+#ifdef MLP
+ v->oid=oid;
+ v->allocsite=allocsite;
#endif
return v;
}
#else
-void * allocate_new(int type) {
- void * v=FREEMALLOC(classsize[type]);
- *((int *)v)=type;
+__attribute__((malloc)) void * allocate_new(int type) {
+ ObjectPtr v=FREEMALLOC(classsize[type]);
+ v->type=type;
+ v->hashcode=(int)(INTPTR)v;
+#ifdef OPTIONAL
+ v->fses=0;
+#endif
return v;
}
/* Array allocation function */
-struct ArrayObject * allocate_newarray(int type, int length) {
- struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
+__attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length) {
+ __attribute__((malloc)) struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
v->type=type;
+ v->hashcode=(int)(INTPTR)v;
v->___length___=length;
+#ifdef OPTIONAL
+ v->fses=0;
+#endif
return v;
}
#endif
+#endif
+/* Converts C character arrays into Java strings */
+#ifdef PRECISE_GC
+__attribute__((malloc)) StringPtr NewStringShort(void * ptr, const short *str,int length) {
+#else
+__attribute__((malloc)) StringPtr NewStringShort(const short *str,int length) {
+#endif
+ int i;
+#ifdef PRECISE_GC
+ struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
+ INTPTR ptrarray[]={1, (INTPTR) ptr, (INTPTR) chararray};
+ StringPtr strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
+ chararray=(struct ArrayObject *) ptrarray[2];
+#else
+ struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
+ StringPtr strobj=allocate_new(STRINGTYPE);
+#endif
+ strobj->___value___=chararray;
+ strobj->___count___=length;
+ strobj->___offset___=0;
+
+ for(i=0; i<length; i++) {
+ ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=str[i];
+ }
+ return strobj;
+}
/* Converts C character arrays into Java strings */
#ifdef PRECISE_GC
-struct ___String___ * NewString(void * ptr, const char *str,int length) {
+__attribute__((malloc)) StringPtr NewString(void * ptr, const char *str,int length) {
#else
-struct ___String___ * NewString(const char *str,int length) {
+__attribute__((malloc)) StringPtr NewString(const char *str,int length) {
#endif
int i;
#ifdef PRECISE_GC
struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
- int ptrarray[]={1, (int) ptr, (int) chararray};
- struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
+ INTPTR ptrarray[]={1, (INTPTR) ptr, (INTPTR) chararray};
+ StringPtr strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
chararray=(struct ArrayObject *) ptrarray[2];
#else
struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
- struct ___String___ * strobj=allocate_new(STRINGTYPE);
+ StringPtr strobj=allocate_new(STRINGTYPE);
#endif
strobj->___value___=chararray;
strobj->___count___=length;
strobj->___offset___=0;
- for(i=0;i<length;i++) {
- ((short *)(((char *)& chararray->___length___)+sizeof(int)))[i]=(short)str[i]; }
+ for(i=0; i<length; i++) {
+ ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
+ }
return strobj;
}
/* Generated code calls this if we fail a bounds check */
-void failedboundschk() {
+ void failedboundschk(int num, int index, struct ArrayObject * ao ) {
#ifndef TASK
- printf("Array out of bounds\n");
+ printf("Array out of bounds at line %u with index %u of object %x with length %u\n", num, index, ao, ao->___length___);
#ifdef THREADS
threadexit();
#else
exit(-1);
#endif
}
+
+#ifndef SANDBOX
+#ifdef D___System______Assert____Z
+void CALL11(___System______Assert____Z, int ___status___, int ___status___) {
+ if (!___status___) {
+ printf("Assertion violation\n");
+ *((int *)(NULL)); //force stack trace error
+ }
+}
+#endif
+#endif