2 #include "structdefs.h"
11 #include "prelookup.h"
14 extern int classsize[];
15 jmp_buf error_handler;
20 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 void CALL11(___System______printI____I,int ___status___, int ___status___) {
83 printf("%d\n",___status___);
86 long CALL00(___System______currentTimeMillis____) {
87 struct timeval tv; long long retval;
88 gettimeofday(&tv, NULL);
89 retval = tv.tv_sec; /* seconds */
90 retval*=1000; /* milliseconds */
91 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
95 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
96 struct ArrayObject * chararray=VAR(___s___)->___value___;
98 int offset=VAR(___s___)->___offset___;
99 for(i=0; i<VAR(___s___)->___count___; i++) {
100 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
106 void CALL00(___System______clearPrefetchCache____) {
111 /* Object allocation function */
114 void * allocate_newglobal(transrecord_t *trans, int type) {
115 struct ___Object___ * v=(struct ___Object___ *) transCreateObj(trans, classsize[type]);
125 /* Array allocation function */
127 struct ArrayObject * allocate_newarrayglobal(transrecord_t *trans, int type, int length) {
128 struct ArrayObject * v=(struct ArrayObject *)transCreateObj(trans, sizeof(struct ArrayObject)+length*classsize[type]);
130 printf("ERROR: negative array\n");
134 v->___length___=length;
146 void * allocate_new(void * ptr, int type) {
147 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
160 /* Array allocation function */
162 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
163 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
166 printf("ERROR: negative array\n");
169 v->___length___=length;
182 void * allocate_new(int type) {
183 struct ___Object___ * v=FREEMALLOC(classsize[type]);
191 /* Array allocation function */
193 struct ArrayObject * allocate_newarray(int type, int length) {
194 struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
196 v->___length___=length;
205 /* Converts C character arrays into Java strings */
207 struct ___String___ * NewString(void * ptr, const char *str,int length) {
209 struct ___String___ * NewString(const char *str,int length) {
213 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
214 int ptrarray[]={1, (int) ptr, (int) chararray};
215 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
216 chararray=(struct ArrayObject *) ptrarray[2];
218 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
219 struct ___String___ * strobj=allocate_new(STRINGTYPE);
221 strobj->___value___=chararray;
222 strobj->___count___=length;
223 strobj->___offset___=0;
225 for(i=0; i<length; i++) {
226 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
231 /* Generated code calls this if we fail a bounds check */
233 void failedboundschk() {
235 printf("Array out of bounds\n");
242 longjmp(error_handler,2);
246 /* Abort task call */
249 longjmp(error_handler,4);
251 printf("Aborting\n");