2 #include "structdefs.h"
14 extern int classsize[];
15 jmp_buf error_handler;
20 float failurechance=0;
22 int injectinstructionfailures;
24 float instfailurechance=0;
34 void exithandler(int sig, siginfo_t *info, void * uap) {
38 void initializeexithandler() {
40 sig.sa_sigaction=&exithandler;
41 sig.sa_flags=SA_SIGINFO;
42 sigemptyset(&sig.sa_mask);
43 sigaction(SIGUSR2, &sig, 0);
47 /* This function inject failures */
49 void injectinstructionfailure() {
51 if (injectinstructionfailures) {
54 instructioncount=failurecount;
55 instaccum+=failurecount;
56 if ((((double)random())/RAND_MAX)<instfailurechance) {
59 printf("FAILURE!!! %d\n",numfailures);
60 longjmp(error_handler,11);
65 if (injectinstructionfailures) {
68 instaccum+=failurecount;
69 if ((((double)random())/RAND_MAX)<instfailurechance) {
72 printf("FAILURE!!! %d\n",numfailures);
80 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
81 struct ArrayObject * chararray=VAR(___s___)->___value___;
83 int offset=VAR(___s___)->___offset___;
84 for(i=0;i<VAR(___s___)->___count___;i++) {
85 short sc=((short *)(((char *)& chararray->___length___)+sizeof(int)))[i+offset];
90 /* Object allocation function */
93 void * allocate_newglobal(transrecord_t *trans, int type) {
94 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(trans, classsize[type]);
104 /* Array allocation function */
106 struct ArrayObject * allocate_newarrayglobal(transrecord_t *trans, int type, int length) {
107 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(trans, sizeof(struct ArrayObject)+length*classsize[type]);
109 printf("ERROR: negative array\n");
113 v->___length___=length;
125 void * allocate_new(void * ptr, int type) {
126 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
136 /* Array allocation function */
138 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
139 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
142 printf("ERROR: negative array\n");
145 v->___length___=length;
155 void * allocate_new(int type) {
156 void * v=FREEMALLOC(classsize[type]);
161 /* Array allocation function */
163 struct ArrayObject * allocate_newarray(int type, int length) {
164 struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
166 v->___length___=length;
172 /* Converts C character arrays into Java strings */
174 struct ___String___ * NewString(void * ptr, const char *str,int length) {
176 struct ___String___ * NewString(const char *str,int length) {
180 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
181 int ptrarray[]={1, (int) ptr, (int) chararray};
182 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
183 chararray=(struct ArrayObject *) ptrarray[2];
185 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
186 struct ___String___ * strobj=allocate_new(STRINGTYPE);
188 strobj->___value___=chararray;
189 strobj->___count___=length;
190 strobj->___offset___=0;
192 for(i=0;i<length;i++) {
193 ((short *)(((char *)& chararray->___length___)+sizeof(int)))[i]=(short)str[i]; }
197 /* Generated code calls this if we fail a bounds check */
199 void failedboundschk() {
201 printf("Array out of bounds\n");
208 longjmp(error_handler,2);
212 /* Abort task call */
215 longjmp(error_handler,4);
217 printf("Aborting\n");