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]);
208 /* 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");
217 v->___length___=length;
220 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
221 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t));
222 struct ___Object___ * v=(struct ___Object___ *) &tmp[1];
228 /* Array allocation function */
230 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
231 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t));
232 struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
236 printf("ERROR: negative array\n");
239 v->___length___=length;
245 #if defined(PRECISE_GC)
246 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
247 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
260 /* Array allocation function */
262 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
263 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
266 printf("ERROR: negative array\n");
269 v->___length___=length;
282 __attribute__((malloc)) void * allocate_new(int type) {
283 struct ___Object___ * v=FREEMALLOC(classsize[type]);
291 /* Array allocation function */
293 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length) {
294 __attribute__((malloc)) struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
296 v->___length___=length;
306 /* Converts C character arrays into Java strings */
308 __attribute__((malloc)) struct ___String___ * NewString(void * ptr, const char *str,int length) {
310 __attribute__((malloc)) struct ___String___ * NewString(const char *str,int length) {
314 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
315 int ptrarray[]={1, (int) ptr, (int) chararray};
316 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
317 chararray=(struct ArrayObject *) ptrarray[2];
319 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
320 struct ___String___ * strobj=allocate_new(STRINGTYPE);
322 strobj->___value___=chararray;
323 strobj->___count___=length;
324 strobj->___offset___=0;
326 for(i=0; i<length; i++) {
327 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
332 /* Generated code calls this if we fail a bounds check */
334 void failedboundschk() {
336 printf("Array out of bounds\n");
343 longjmp(error_handler,2);
347 /* Abort task call */
350 longjmp(error_handler,4);
352 printf("Aborting\n");