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___) {
106 void CALL11(___System______printI____I,int ___status___, int ___status___) {
107 printf("%d\n",___status___);
110 long CALL00(___System______currentTimeMillis____) {
111 struct timeval tv; long long retval;
112 gettimeofday(&tv, NULL);
113 retval = tv.tv_sec; /* seconds */
114 retval*=1000; /* milliseconds */
115 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
119 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
120 struct ArrayObject * chararray=VAR(___s___)->___value___;
122 int offset=VAR(___s___)->___offset___;
123 for(i=0; i<VAR(___s___)->___count___; i++) {
124 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
130 void CALL00(___System______clearPrefetchCache____) {
135 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
136 /* Manual Prefetches to be inserted */
137 //printf("DEBUG-> %s() ___Object___ * ___o___ = %x\n", __func__, VAR(___o___));
138 //printf("DEBUG-> %s() ArrayObject * = %x\n", __func__, VAR(___offsets___));
139 int numoffset=VAR(___offsets___)->___length___;
141 short offArry[numoffset+2];
144 for(i = 2; i<(numoffset+2); i++) {
145 offArry[i] = *((short *)(((char *)&VAR(___offsets___)->___length___) + sizeof(int) + (i-2) * sizeof(short)));
146 //printf("DEBUG-> offArry[%d] = %d\n", i, offArry[i]);
149 if(((unsigned int)(VAR(___o___)) & 1) != 0) { //odd
150 oid = (unsigned int) VAR(___o___); //outside transaction therefore just an oid
152 oid = (unsigned int) COMPOID(VAR(___o___)); //inside transaction therefore a pointer to oid
154 rangePrefetch(oid, (short)(numoffset+2), offArry);
157 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
164 /* Object allocation function */
167 __attribute__((malloc)) void * allocate_newglobal(int type) {
168 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(classsize[type]);
178 /* Array allocation function */
180 __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, int length) {
181 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(sizeof(struct ArrayObject)+length*classsize[type]);
183 printf("ERROR: negative array\n");
187 v->___length___=length;
199 // STM Versions of allocation functions
201 /* Object allocation function */
202 __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) {
203 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type]);
205 v->___objlocation___=v;
209 /* Array allocation function */
210 __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length) {
211 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]);
213 printf("ERROR: negative array\n");
216 v->___objlocation___=(struct ___Object___*)v;
218 v->___length___=length;
221 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
222 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t));
223 struct ___Object___ * v=(struct ___Object___ *) &tmp[1];
224 initdsmlocks(&tmp->lock);
226 v->___objlocation___=v;
231 /* Array allocation function */
233 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
234 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t));
235 struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
236 initdsmlocks(&tmp->lock);
240 printf("ERROR: negative array\n");
243 v->___objlocation___=(struct ___Object___ *)v;
244 v->___length___=length;
250 #if defined(PRECISE_GC)
251 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
252 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
265 /* Array allocation function */
267 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
268 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
271 printf("ERROR: negative array\n");
274 v->___length___=length;
287 __attribute__((malloc)) void * allocate_new(int type) {
288 struct ___Object___ * v=FREEMALLOC(classsize[type]);
296 /* Array allocation function */
298 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length) {
299 __attribute__((malloc)) struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
301 v->___length___=length;
311 /* Converts C character arrays into Java strings */
313 __attribute__((malloc)) struct ___String___ * NewString(void * ptr, const char *str,int length) {
315 __attribute__((malloc)) struct ___String___ * NewString(const char *str,int length) {
319 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
320 int ptrarray[]={1, (int) ptr, (int) chararray};
321 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
322 chararray=(struct ArrayObject *) ptrarray[2];
324 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
325 struct ___String___ * strobj=allocate_new(STRINGTYPE);
327 strobj->___value___=chararray;
328 strobj->___count___=length;
329 strobj->___offset___=0;
331 for(i=0; i<length; i++) {
332 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
337 /* Generated code calls this if we fail a bounds check */
339 void failedboundschk() {
341 printf("Array out of bounds\n");
348 longjmp(error_handler,2);
352 /* Abort task call */
355 longjmp(error_handler,4);
357 printf("Aborting\n");