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 #ifdef D___Vector______removeElement_____AR_L___Object____I
117 void CALL12(___Vector______removeElement_____AR_L___Object____I, int ___index___, struct ArrayObject * ___array___, int ___index___) {
118 int length=VAR(___array___)->___length___;
119 char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___;
120 memmove(offset, offset+sizeof(void *),(length-___index___-1)*sizeof(void *));
124 void CALL11(___System______printI____I,int ___status___, int ___status___) {
125 printf("%d\n",___status___);
128 long CALL00(___System______currentTimeMillis____) {
129 struct timeval tv; long long retval;
130 gettimeofday(&tv, NULL);
131 retval = tv.tv_sec; /* seconds */
132 retval*=1000; /* milliseconds */
133 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
137 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
138 struct ArrayObject * chararray=VAR(___s___)->___value___;
140 int offset=VAR(___s___)->___offset___;
141 for(i=0; i<VAR(___s___)->___count___; i++) {
142 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
148 void CALL00(___System______clearPrefetchCache____) {
153 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
154 /* Manual Prefetches to be inserted */
155 //printf("DEBUG-> %s() ___Object___ * ___o___ = %x\n", __func__, VAR(___o___));
156 //printf("DEBUG-> %s() ArrayObject * = %x\n", __func__, VAR(___offsets___));
157 int numoffset=VAR(___offsets___)->___length___;
159 short offArry[numoffset+2];
162 for(i = 2; i<(numoffset+2); i++) {
163 offArry[i] = *((short *)(((char *)&VAR(___offsets___)->___length___) + sizeof(int) + (i-2) * sizeof(short)));
164 //printf("DEBUG-> offArry[%d] = %d\n", i, offArry[i]);
167 if(((unsigned int)(VAR(___o___)) & 1) != 0) { //odd
168 oid = (unsigned int) VAR(___o___); //outside transaction therefore just an oid
170 oid = (unsigned int) COMPOID(VAR(___o___)); //inside transaction therefore a pointer to oid
172 rangePrefetch(oid, (short)(numoffset+2), offArry);
175 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
182 /* Object allocation function */
185 __attribute__((malloc)) void * allocate_newglobal(int type) {
186 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(classsize[type]);
196 /* Array allocation function */
198 __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, int length) {
199 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(sizeof(struct ArrayObject)+length*classsize[type]);
201 printf("ERROR: negative array\n");
205 v->___length___=length;
217 // STM Versions of allocation functions
219 /* Object allocation function */
220 __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) {
221 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type]);
223 v->___objlocation___=v;
227 /* Array allocation function */
228 __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length) {
229 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]);
231 printf("ERROR: negative array\n");
234 v->___objlocation___=(struct ___Object___*)v;
236 v->___length___=length;
239 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
240 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t));
241 struct ___Object___ * v=(struct ___Object___ *) &tmp[1];
242 initdsmlocks(&tmp->lock);
244 v->___objlocation___=v;
249 /* Array allocation function */
251 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
252 objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t));
253 struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
254 initdsmlocks(&tmp->lock);
258 printf("ERROR: negative array\n");
261 v->___objlocation___=(struct ___Object___ *)v;
262 v->___length___=length;
268 #if defined(PRECISE_GC)
269 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
270 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
283 /* Array allocation function */
285 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
286 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
289 printf("ERROR: negative array\n");
292 v->___length___=length;
305 __attribute__((malloc)) void * allocate_new(int type) {
306 struct ___Object___ * v=FREEMALLOC(classsize[type]);
314 /* Array allocation function */
316 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length) {
317 __attribute__((malloc)) struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
319 v->___length___=length;
329 /* Converts C character arrays into Java strings */
331 __attribute__((malloc)) struct ___String___ * NewString(void * ptr, const char *str,int length) {
333 __attribute__((malloc)) struct ___String___ * NewString(const char *str,int length) {
337 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
338 INTPTR ptrarray[]={1, (INTPTR) ptr, (INTPTR) chararray};
339 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
340 chararray=(struct ArrayObject *) ptrarray[2];
342 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
343 struct ___String___ * strobj=allocate_new(STRINGTYPE);
345 strobj->___value___=chararray;
346 strobj->___count___=length;
347 strobj->___offset___=0;
349 for(i=0; i<length; i++) {
350 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
355 /* Generated code calls this if we fail a bounds check */
357 void failedboundschk() {
359 printf("Array out of bounds\n");
366 longjmp(error_handler,2);
370 /* Abort task call */
373 longjmp(error_handler,4);
375 printf("Aborting\n");