2 #include "structdefs.h"
11 extern int classsize[];
12 jmp_buf error_handler;
17 float failurechance=0;
19 int injectinstructionfailures;
21 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 CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
78 struct ArrayObject * chararray=VAR(___s___)->___value___;
80 int offset=VAR(___s___)->___offset___;
81 for(i=0;i<VAR(___s___)->___count___;i++) {
82 short sc=((short *)(((char *)& chararray->___length___)+sizeof(int)))[i+offset];
87 /* Object allocation function */
90 void * allocate_new(void * ptr, int type) {
91 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
101 /* Array allocation function */
103 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
104 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
107 printf("ERROR: negative array\n");
110 v->___length___=length;
120 void * allocate_new(int type) {
121 void * v=FREEMALLOC(classsize[type]);
126 /* Array allocation function */
128 struct ArrayObject * allocate_newarray(int type, int length) {
129 struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
131 v->___length___=length;
137 /* Converts C character arrays into Java strings */
139 struct ___String___ * NewString(void * ptr, const char *str,int length) {
141 struct ___String___ * NewString(const char *str,int length) {
145 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
146 int ptrarray[]={1, (int) ptr, (int) chararray};
147 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
148 chararray=(struct ArrayObject *) ptrarray[2];
150 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
151 struct ___String___ * strobj=allocate_new(STRINGTYPE);
153 strobj->___value___=chararray;
154 strobj->___count___=length;
155 strobj->___offset___=0;
157 for(i=0;i<length;i++) {
158 ((short *)(((char *)& chararray->___length___)+sizeof(int)))[i]=(short)str[i]; }
162 /* Generated code calls this if we fail a bounds check */
164 void failedboundschk() {
166 printf("Array out of bounds\n");
173 longjmp(error_handler,2);
177 /* Abort task call */
180 longjmp(error_handler,4);
182 printf("Aborting\n");