2 #include "structdefs.h"
11 #include "prelookup.h"
15 extern int classsize[];
16 jmp_buf error_handler;
21 float failurechance=0;
24 int injectinstructionfailures;
26 float instfailurechance=0;
33 void exithandler(int sig, siginfo_t *info, void * uap) {
37 void initializeexithandler() {
39 sig.sa_sigaction=&exithandler;
40 sig.sa_flags=SA_SIGINFO;
41 sigemptyset(&sig.sa_mask);
42 sigaction(SIGUSR2, &sig, 0);
46 /* This function inject failures */
48 void injectinstructionfailure() {
50 if (injectinstructionfailures) {
53 instructioncount=failurecount;
54 instaccum+=failurecount;
55 if ((((double)random())/RAND_MAX)<instfailurechance) {
58 printf("FAILURE!!! %d\n",numfailures);
59 longjmp(error_handler,11);
64 if (injectinstructionfailures) {
67 instaccum+=failurecount;
68 if ((((double)random())/RAND_MAX)<instfailurechance) {
71 printf("FAILURE!!! %d\n",numfailures);
79 void CALL11(___System______exit____I,int ___status___, int ___status___) {
83 void CALL11(___System______printI____I,int ___status___, int ___status___) {
84 printf("%d\n",___status___);
87 long CALL00(___System______currentTimeMillis____) {
88 struct timeval tv; long long retval;
89 gettimeofday(&tv, NULL);
90 retval = tv.tv_sec; /* seconds */
91 retval*=1000; /* milliseconds */
92 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
96 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
97 struct ArrayObject * chararray=VAR(___s___)->___value___;
99 int offset=VAR(___s___)->___offset___;
100 for(i=0; i<VAR(___s___)->___count___; i++) {
101 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
107 void CALL00(___System______clearPrefetchCache____) {
111 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
112 /* Manual Prefetches to be inserted */
113 //printf("DEBUG-> %s() ___Object___ * ___o___ = %x\n", __func__, VAR(___o___));
114 //printf("DEBUG-> %s() ArrayObject * = %x\n", __func__, VAR(___offsets___));
115 int numoffset=VAR(___offsets___)->___length___;
117 short offArry[numoffset];
118 for(i = 0; i<numoffset; i++) {
119 offArry[i] = *((short *)(((char *)&VAR(___offsets___)->___length___) + sizeof(int) + i * sizeof(short)));
120 //printf("DEBUG-> offArry[%d] = %d\n", i, offArry[i]);
123 if(((unsigned int)(VAR(___o___)) & 1) != 0) { //odd
124 oid = (unsigned int) VAR(___o___); //outside transaction therefore just an oid
126 oid = (unsigned int) COMPOID(VAR(___o___)); //inside transaction therefore a pointer to oid
128 rangePrefetch(oid, (short)numoffset, offArry);
132 /* Object allocation function */
135 __attribute__((malloc)) void * allocate_newglobal(transrecord_t *trans, int type) {
136 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(trans, classsize[type]);
146 /* Array allocation function */
148 __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(transrecord_t *trans, int type, int length) {
149 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(trans, sizeof(struct ArrayObject)+length*classsize[type]);
151 printf("ERROR: negative array\n");
155 v->___length___=length;
167 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
168 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
181 /* Array allocation function */
183 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
184 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
187 printf("ERROR: negative array\n");
190 v->___length___=length;
203 __attribute__((malloc)) void * allocate_new(int type) {
204 struct ___Object___ * v=FREEMALLOC(classsize[type]);
212 /* Array allocation function */
214 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length) {
215 __attribute__((malloc)) struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
217 v->___length___=length;
226 /* Converts C character arrays into Java strings */
228 __attribute__((malloc)) struct ___String___ * NewString(void * ptr, const char *str,int length) {
230 __attribute__((malloc)) struct ___String___ * NewString(const char *str,int length) {
234 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
235 int ptrarray[]={1, (int) ptr, (int) chararray};
236 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
237 chararray=(struct ArrayObject *) ptrarray[2];
239 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
240 struct ___String___ * strobj=allocate_new(STRINGTYPE);
242 strobj->___value___=chararray;
243 strobj->___count___=length;
244 strobj->___offset___=0;
246 for(i=0; i<length; i++) {
247 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
252 /* Generated code calls this if we fail a bounds check */
254 void failedboundschk() {
256 printf("Array out of bounds\n");
263 longjmp(error_handler,2);
267 /* Abort task call */
270 longjmp(error_handler,4);
272 printf("Aborting\n");