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____) {
108 /* Object allocation function */
111 void * allocate_newglobal(transrecord_t *trans, int type) {
112 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(trans, classsize[type]);
122 /* Array allocation function */
124 struct ArrayObject * allocate_newarrayglobal(transrecord_t *trans, int type, int length) {
125 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(trans, sizeof(struct ArrayObject)+length*classsize[type]);
127 printf("ERROR: negative array\n");
131 v->___length___=length;
143 void * allocate_new(void * ptr, int type) {
144 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
157 /* Array allocation function */
159 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
160 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
163 printf("ERROR: negative array\n");
166 v->___length___=length;
179 void * allocate_new(int type) {
180 struct ___Object___ * v=FREEMALLOC(classsize[type]);
188 /* Array allocation function */
190 struct ArrayObject * allocate_newarray(int type, int length) {
191 struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
193 v->___length___=length;
202 /* Converts C character arrays into Java strings */
204 struct ___String___ * NewString(void * ptr, const char *str,int length) {
206 struct ___String___ * NewString(const char *str,int length) {
210 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
211 int ptrarray[]={1, (int) ptr, (int) chararray};
212 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
213 chararray=(struct ArrayObject *) ptrarray[2];
215 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
216 struct ___String___ * strobj=allocate_new(STRINGTYPE);
218 strobj->___value___=chararray;
219 strobj->___count___=length;
220 strobj->___offset___=0;
222 for(i=0;i<length;i++) {
223 ((short *)(((char *)& chararray->___length___)+sizeof(int)))[i]=(short)str[i]; }
227 /* Generated code calls this if we fail a bounds check */
229 void failedboundschk() {
231 printf("Array out of bounds\n");
238 longjmp(error_handler,2);
242 /* Abort task call */
245 longjmp(error_handler,4);
247 printf("Aborting\n");