2 #include "structdefs.h"
12 #include "prelookup.h"
15 extern int classsize[];
16 jmp_buf error_handler;
21 float failurechance=0;
23 int injectinstructionfailures;
25 float instfailurechance=0;
32 void exithandler(int sig, siginfo_t *info, void * uap) {
36 void initializeexithandler() {
38 sig.sa_sigaction=&exithandler;
39 sig.sa_flags=SA_SIGINFO;
40 sigemptyset(&sig.sa_mask);
41 sigaction(SIGUSR2, &sig, 0);
45 /* This function inject failures */
47 void injectinstructionfailure() {
49 if (injectinstructionfailures) {
52 instructioncount=failurecount;
53 instaccum+=failurecount;
54 if ((((double)random())/RAND_MAX)<instfailurechance) {
57 printf("FAILURE!!! %d\n",numfailures);
58 longjmp(error_handler,11);
63 if (injectinstructionfailures) {
66 instaccum+=failurecount;
67 if ((((double)random())/RAND_MAX)<instfailurechance) {
70 printf("FAILURE!!! %d\n",numfailures);
78 void CALL11(___System______exit____I,int ___status___, int ___status___) {
82 long CALL00(___System______currentTimeMillis____) {
83 struct timeval tv; long long retval;
84 gettimeofday(&tv, NULL);
85 retval = tv.tv_sec; /* seconds */
86 retval*=1000; /* milliseconds */
87 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
91 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
92 struct ArrayObject * chararray=VAR(___s___)->___value___;
94 int offset=VAR(___s___)->___offset___;
95 for(i=0;i<VAR(___s___)->___count___;i++) {
96 short sc=((short *)(((char *)& chararray->___length___)+sizeof(int)))[i+offset];
102 void CALL00(___System______clearPrefetchCache____) {
107 /* Object allocation function */
110 void * allocate_newglobal(transrecord_t *trans, int type) {
111 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(trans, classsize[type]);
121 /* Array allocation function */
123 struct ArrayObject * allocate_newarrayglobal(transrecord_t *trans, int type, int length) {
124 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(trans, sizeof(struct ArrayObject)+length*classsize[type]);
126 printf("ERROR: negative array\n");
130 v->___length___=length;
142 void * allocate_new(void * ptr, int type) {
143 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
156 /* Array allocation function */
158 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
159 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
162 printf("ERROR: negative array\n");
165 v->___length___=length;
178 void * allocate_new(int type) {
179 struct ___Object___ * v=FREEMALLOC(classsize[type]);
187 /* Array allocation function */
189 struct ArrayObject * allocate_newarray(int type, int length) {
190 struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
192 v->___length___=length;
201 /* Converts C character arrays into Java strings */
203 struct ___String___ * NewString(void * ptr, const char *str,int length) {
205 struct ___String___ * NewString(const char *str,int length) {
209 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
210 int ptrarray[]={1, (int) ptr, (int) chararray};
211 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
212 chararray=(struct ArrayObject *) ptrarray[2];
214 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
215 struct ___String___ * strobj=allocate_new(STRINGTYPE);
217 strobj->___value___=chararray;
218 strobj->___count___=length;
219 strobj->___offset___=0;
221 for(i=0;i<length;i++) {
222 ((short *)(((char *)& chararray->___length___)+sizeof(int)))[i]=(short)str[i]; }
226 /* Generated code calls this if we fail a bounds check */
228 void failedboundschk() {
230 printf("Array out of bounds\n");
237 longjmp(error_handler,2);
241 /* Abort task call */
244 longjmp(error_handler,4);
246 printf("Aborting\n");