2 #include "structdefs.h"
11 #include "prelookup.h"
19 extern int classsize[];
20 extern int typearray[];
21 extern int typearray2[];
22 jmp_buf error_handler;
27 float failurechance=0;
30 int injectinstructionfailures;
32 float instfailurechance=0;
39 int instanceof(struct ___Object___ *ptr, int type) {
51 i=typearray2[i-NUMCLASSES];
57 void exithandler(int sig, siginfo_t *info, void * uap) {
61 void initializeexithandler() {
63 sig.sa_sigaction=&exithandler;
64 sig.sa_flags=SA_SIGINFO;
65 sigemptyset(&sig.sa_mask);
66 sigaction(SIGUSR2, &sig, 0);
70 /* This function inject failures */
72 void injectinstructionfailure() {
74 if (injectinstructionfailures) {
77 instructioncount=failurecount;
78 instaccum+=failurecount;
79 if ((((double)random())/RAND_MAX)<instfailurechance) {
82 printf("FAILURE!!! %d\n",numfailures);
83 longjmp(error_handler,11);
88 if (injectinstructionfailures) {
91 instaccum+=failurecount;
92 if ((((double)random())/RAND_MAX)<instfailurechance) {
95 printf("FAILURE!!! %d\n",numfailures);
103 void CALL11(___System______exit____I,int ___status___, int ___status___) {
105 printf("numTransCommit = %d\n", numTransCommit);
106 printf("numTransAbort = %d\n", numTransAbort);
107 printf("nSoftAbort = %d\n", nSoftAbort);
109 printf("nSoftAbortCommit = %d\n", nSoftAbortCommit);
110 printf("nSoftAbortAbort = %d\n", nSoftAbortAbort);
116 void CALL12(___Vector______removeElement_____AR_L___Object____I, int ___index___, struct ArrayObject * ___array___, int ___index___) {
117 int length=VAR(___array___)->___length___;
118 char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___;
119 memmove(offset, offset+sizeof(void *),(length-___index___-1)*sizeof(void *));
123 void CALL11(___System______printI____I,int ___status___, int ___status___) {
124 printf("%d\n",___status___);
127 long CALL00(___System______currentTimeMillis____) {
128 struct timeval tv; long long retval;
129 gettimeofday(&tv, NULL);
130 retval = tv.tv_sec; /* seconds */
131 retval*=1000; /* milliseconds */
132 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
136 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
137 struct ArrayObject * chararray=VAR(___s___)->___value___;
139 int offset=VAR(___s___)->___offset___;
140 for(i=0; i<VAR(___s___)->___count___; i++) {
141 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
147 void CALL00(___System______clearPrefetchCache____) {
152 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
153 /* Manual Prefetches to be inserted */
154 //printf("DEBUG-> %s() ___Object___ * ___o___ = %x\n", __func__, VAR(___o___));
155 //printf("DEBUG-> %s() ArrayObject * = %x\n", __func__, VAR(___offsets___));
156 int numoffset=VAR(___offsets___)->___length___;
158 short offArry[numoffset+2];
161 for(i = 2; i<(numoffset+2); i++) {
162 offArry[i] = *((short *)(((char *)&VAR(___offsets___)->___length___) + sizeof(int) + (i-2) * sizeof(short)));
163 //printf("DEBUG-> offArry[%d] = %d\n", i, offArry[i]);
166 if(((unsigned int)(VAR(___o___)) & 1) != 0) { //odd
167 oid = (unsigned int) VAR(___o___); //outside transaction therefore just an oid
169 oid = (unsigned int) COMPOID(VAR(___o___)); //inside transaction therefore a pointer to oid
171 rangePrefetch(oid, (short)(numoffset+2), offArry);
174 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
181 /* Object allocation function */
184 __attribute__((malloc)) void * allocate_newglobal(int type) {
185 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(classsize[type]);
195 /* Array allocation function */
197 __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, int length) {
198 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(sizeof(struct ArrayObject)+length*classsize[type]);
200 printf("ERROR: negative array\n");
204 v->___length___=length;
216 // STM Versions of allocation functions
218 /* Object allocation function */
219 __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) {
220 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type]);
222 v->___objlocation___=v;
226 /* Array allocation function */
227 __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length) {
228 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]);
230 printf("ERROR: negative array\n");
233 v->___objlocation___=(struct ___Object___*)v;
235 v->___length___=length;
238 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
239 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t));
240 struct ___Object___ * v=(struct ___Object___ *) &tmp[1];
241 initdsmlocks(&tmp->lock);
243 v->___objlocation___=v;
248 /* Array allocation function */
250 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
251 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t));
252 struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
253 initdsmlocks(&tmp->lock);
257 printf("ERROR: negative array\n");
260 v->___objlocation___=(struct ___Object___ *)v;
261 v->___length___=length;
267 #if defined(PRECISE_GC)
268 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
269 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
282 /* Array allocation function */
284 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
285 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
288 printf("ERROR: negative array\n");
291 v->___length___=length;
304 __attribute__((malloc)) void * allocate_new(int type) {
305 struct ___Object___ * v=FREEMALLOC(classsize[type]);
313 /* Array allocation function */
315 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length) {
316 __attribute__((malloc)) struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
318 v->___length___=length;
328 /* Converts C character arrays into Java strings */
330 __attribute__((malloc)) struct ___String___ * NewString(void * ptr, const char *str,int length) {
332 __attribute__((malloc)) struct ___String___ * NewString(const char *str,int length) {
336 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
337 INTPTR ptrarray[]={1, (INTPTR) ptr, (INTPTR) chararray};
338 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
339 chararray=(struct ArrayObject *) ptrarray[2];
341 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
342 struct ___String___ * strobj=allocate_new(STRINGTYPE);
344 strobj->___value___=chararray;
345 strobj->___count___=length;
346 strobj->___offset___=0;
348 for(i=0; i<length; i++) {
349 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
354 /* Generated code calls this if we fail a bounds check */
356 void failedboundschk() {
358 printf("Array out of bounds\n");
365 longjmp(error_handler,2);
369 /* Abort task call */
372 longjmp(error_handler,4);
374 printf("Aborting\n");