2 #include "structdefs.h"
11 #include "prelookup.h"
18 extern int classsize[];
19 extern int typearray[];
20 extern int typearray2[];
21 jmp_buf error_handler;
26 float failurechance=0;
29 int injectinstructionfailures;
31 float instfailurechance=0;
38 int instanceof(struct ___Object___ *ptr, int type) {
50 i=typearray2[i-NUMCLASSES];
56 void exithandler(int sig, siginfo_t *info, void * uap) {
60 void initializeexithandler() {
62 sig.sa_sigaction=&exithandler;
63 sig.sa_flags=SA_SIGINFO;
64 sigemptyset(&sig.sa_mask);
65 sigaction(SIGUSR2, &sig, 0);
69 /* This function inject failures */
71 void injectinstructionfailure() {
73 if (injectinstructionfailures) {
76 instructioncount=failurecount;
77 instaccum+=failurecount;
78 if ((((double)random())/RAND_MAX)<instfailurechance) {
81 printf("FAILURE!!! %d\n",numfailures);
82 longjmp(error_handler,11);
87 if (injectinstructionfailures) {
90 instaccum+=failurecount;
91 if ((((double)random())/RAND_MAX)<instfailurechance) {
94 printf("FAILURE!!! %d\n",numfailures);
102 void CALL11(___System______exit____I,int ___status___, int ___status___) {
104 printf("numTransCommit = %d\n", numTransCommit);
105 printf("numTransAbort = %d\n", numTransAbort);
106 printf("nSoftAbort = %d\n", nSoftAbort);
108 printf("nSoftAbortCommit = %d\n", nSoftAbortCommit);
109 printf("nSoftAbortAbort = %d\n", nSoftAbortAbort);
115 void CALL11(___System______printI____I,int ___status___, int ___status___) {
116 printf("%d\n",___status___);
119 long CALL00(___System______currentTimeMillis____) {
120 struct timeval tv; long long retval;
121 gettimeofday(&tv, NULL);
122 retval = tv.tv_sec; /* seconds */
123 retval*=1000; /* milliseconds */
124 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
128 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
129 struct ArrayObject * chararray=VAR(___s___)->___value___;
131 int offset=VAR(___s___)->___offset___;
132 for(i=0; i<VAR(___s___)->___count___; i++) {
133 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
139 void CALL00(___System______clearPrefetchCache____) {
144 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
145 /* Manual Prefetches to be inserted */
146 //printf("DEBUG-> %s() ___Object___ * ___o___ = %x\n", __func__, VAR(___o___));
147 //printf("DEBUG-> %s() ArrayObject * = %x\n", __func__, VAR(___offsets___));
148 int numoffset=VAR(___offsets___)->___length___;
150 short offArry[numoffset+2];
153 for(i = 2; i<(numoffset+2); i++) {
154 offArry[i] = *((short *)(((char *)&VAR(___offsets___)->___length___) + sizeof(int) + (i-2) * sizeof(short)));
155 //printf("DEBUG-> offArry[%d] = %d\n", i, offArry[i]);
158 if(((unsigned int)(VAR(___o___)) & 1) != 0) { //odd
159 oid = (unsigned int) VAR(___o___); //outside transaction therefore just an oid
161 oid = (unsigned int) COMPOID(VAR(___o___)); //inside transaction therefore a pointer to oid
163 rangePrefetch(oid, (short)(numoffset+2), offArry);
166 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
173 /* Object allocation function */
176 __attribute__((malloc)) void * allocate_newglobal(int type) {
177 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(classsize[type]);
187 /* Array allocation function */
189 __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, int length) {
190 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(sizeof(struct ArrayObject)+length*classsize[type]);
192 printf("ERROR: negative array\n");
196 v->___length___=length;
208 // STM Versions of allocation functions
210 /* Object allocation function */
211 __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) {
212 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type]);
214 v->___objlocation___=v;
218 /* Array allocation function */
219 __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length) {
220 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]);
222 printf("ERROR: negative array\n");
225 v->___objlocation___=(struct ___Object___*)v;
227 v->___length___=length;
230 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
231 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t));
232 struct ___Object___ * v=(struct ___Object___ *) &tmp[1];
233 initdsmlocks(&tmp->lock);
235 v->___objlocation___=v;
240 /* Array allocation function */
242 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
243 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t));
244 struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
245 initdsmlocks(&tmp->lock);
249 printf("ERROR: negative array\n");
252 v->___objlocation___=(struct ___Object___ *)v;
253 v->___length___=length;
259 #if defined(PRECISE_GC)
260 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
261 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
274 /* Array allocation function */
276 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
277 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
280 printf("ERROR: negative array\n");
283 v->___length___=length;
296 __attribute__((malloc)) void * allocate_new(int type) {
297 struct ___Object___ * v=FREEMALLOC(classsize[type]);
305 /* Array allocation function */
307 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length) {
308 __attribute__((malloc)) struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
310 v->___length___=length;
320 /* Converts C character arrays into Java strings */
322 __attribute__((malloc)) struct ___String___ * NewString(void * ptr, const char *str,int length) {
324 __attribute__((malloc)) struct ___String___ * NewString(const char *str,int length) {
328 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
329 INTPTR ptrarray[]={1, (INTPTR) ptr, (INTPTR) chararray};
330 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
331 chararray=(struct ArrayObject *) ptrarray[2];
333 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
334 struct ___String___ * strobj=allocate_new(STRINGTYPE);
336 strobj->___value___=chararray;
337 strobj->___count___=length;
338 strobj->___offset___=0;
340 for(i=0; i<length; i++) {
341 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
346 /* Generated code calls this if we fail a bounds check */
348 void failedboundschk() {
350 printf("Array out of bounds\n");
357 longjmp(error_handler,2);
361 /* Abort task call */
364 longjmp(error_handler,4);
366 printf("Aborting\n");