2 #include "structdefs.h"
11 #include "prelookup.h"
14 extern int classsize[];
15 jmp_buf error_handler;
20 float failurechance=0;
22 int injectinstructionfailures;
24 float instfailurechance=0;
31 void exithandler(int sig, siginfo_t *info, void * uap) {
35 void initializeexithandler() {
37 sig.sa_sigaction=&exithandler;
38 sig.sa_flags=SA_SIGINFO;
39 sigemptyset(&sig.sa_mask);
40 sigaction(SIGUSR2, &sig, 0);
44 /* This function inject failures */
46 void injectinstructionfailure() {
48 if (injectinstructionfailures) {
51 instructioncount=failurecount;
52 instaccum+=failurecount;
53 if ((((double)random())/RAND_MAX)<instfailurechance) {
56 printf("FAILURE!!! %d\n",numfailures);
57 longjmp(error_handler,11);
62 if (injectinstructionfailures) {
65 instaccum+=failurecount;
66 if ((((double)random())/RAND_MAX)<instfailurechance) {
69 printf("FAILURE!!! %d\n",numfailures);
77 void CALL11(___System______exit____I,int ___status___, int ___status___) {
81 void CALL11(___System______printI____I,int ___status___, int ___status___) {
82 printf("%d\n",___status___);
85 long CALL00(___System______currentTimeMillis____) {
86 struct timeval tv; long long retval;
87 gettimeofday(&tv, NULL);
88 retval = tv.tv_sec; /* seconds */
89 retval*=1000; /* milliseconds */
90 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
94 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
95 struct ArrayObject * chararray=VAR(___s___)->___value___;
97 int offset=VAR(___s___)->___offset___;
98 for(i=0; i<VAR(___s___)->___count___; i++) {
99 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
105 void CALL00(___System______clearPrefetchCache____) {
110 /* Object allocation function */
113 void * allocate_newglobal(transrecord_t *trans, int type) {
114 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(trans, classsize[type]);
124 /* Array allocation function */
126 struct ArrayObject * allocate_newarrayglobal(transrecord_t *trans, int type, int length) {
127 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(trans, sizeof(struct ArrayObject)+length*classsize[type]);
129 printf("ERROR: negative array\n");
133 v->___length___=length;
145 void * allocate_new(void * ptr, int type) {
146 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
159 /* Array allocation function */
161 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
162 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
165 printf("ERROR: negative array\n");
168 v->___length___=length;
181 void * allocate_new(int type) {
182 struct ___Object___ * v=FREEMALLOC(classsize[type]);
190 /* Array allocation function */
192 struct ArrayObject * allocate_newarray(int type, int length) {
193 struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
195 v->___length___=length;
204 /* Converts C character arrays into Java strings */
206 struct ___String___ * NewString(void * ptr, const char *str,int length) {
208 struct ___String___ * NewString(const char *str,int length) {
212 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
213 int ptrarray[]={1, (int) ptr, (int) chararray};
214 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
215 chararray=(struct ArrayObject *) ptrarray[2];
217 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
218 struct ___String___ * strobj=allocate_new(STRINGTYPE);
220 strobj->___value___=chararray;
221 strobj->___count___=length;
222 strobj->___offset___=0;
224 for(i=0; i<length; i++) {
225 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
230 /* Generated code calls this if we fail a bounds check */
232 void failedboundschk() {
234 printf("Array out of bounds\n");
241 longjmp(error_handler,2);
245 /* Abort task call */
248 longjmp(error_handler,4);
250 printf("Aborting\n");