2 #include "structdefs.h"
13 #include "runtime_arch.h"
17 extern int classsize[];
19 jmp_buf error_handler;
24 float failurechance=0;
26 int injectinstructionfailures;
28 float instfailurechance=0;
39 void initializeexithandler() {
42 void exithandler(int sig, siginfo_t *info, void * uap) {
44 printf("exit in exithandler\n");
49 void initializeexithandler() {
51 sig.sa_sigaction=&exithandler;
52 sig.sa_flags=SA_SIGINFO;
53 sigemptyset(&sig.sa_mask);
54 sigaction(SIGUSR2, &sig, 0);
58 /* This function inject failures */
60 void injectinstructionfailure() {
62 // not supported in MULTICORE version
66 if (injectinstructionfailures) {
69 instructioncount=failurecount;
70 instaccum+=failurecount;
71 if ((((double)random())/RAND_MAX)<instfailurechance) {
74 printf("FAILURE!!! %d\n",numfailures);
75 longjmp(error_handler,11);
80 if (injectinstructionfailures) {
83 instaccum+=failurecount;
84 if ((((double)random())/RAND_MAX)<instfailurechance) {
87 printf("FAILURE!!! %d\n",numfailures);
96 void CALL11(___System______exit____I,int ___status___, int ___status___) {
98 BAMBOO_EXIT(___status___);
101 printf("exit in CALL11\n");
107 void CALL11(___System______printI____I,int ___status___, int ___status___) {
109 BAMBOO_DEBUGPRINT(0x1111);
110 BAMBOO_DEBUGPRINT_REG(___status___);
113 printf("printI in CALL11\n");
115 printf("%d\n", ___status___);
119 long CALL00(___System______currentTimeMillis____) {
121 // not supported in MULTICORE version
124 struct timeval tv; long long retval;
125 gettimeofday(&tv, NULL);
126 retval = tv.tv_sec; /* seconds */
127 retval*=1000; /* milliseconds */
128 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
133 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
136 struct ArrayObject * chararray=VAR(___s___)->___value___;
138 int offset=VAR(___s___)->___offset___;
139 for(i=0; i<VAR(___s___)->___count___; i++) {
140 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
146 /* Object allocation function */
149 void * allocate_new(void * ptr, int type) {
150 struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
164 /* Array allocation function */
166 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
167 struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
175 printf("ERROR: negative array\n");
179 v->___length___=length;
189 void * allocate_new(int type) {
190 struct ___Object___ * v=FREEMALLOC(classsize[type]);
199 /* Array allocation function */
201 struct ArrayObject * allocate_newarray(int type, int length) {
202 struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
208 v->___length___=length;
214 /* Converts C character arrays into Java strings */
216 struct ___String___ * NewString(void * ptr, const char *str,int length) {
218 struct ___String___ * NewString(const char *str,int length) {
222 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
223 int ptrarray[]={1, (int) ptr, (int) chararray};
224 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
225 chararray=(struct ArrayObject *) ptrarray[2];
227 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
228 struct ___String___ * strobj=allocate_new(STRINGTYPE);
230 strobj->___value___=chararray;
231 strobj->___count___=length;
232 strobj->___offset___=0;
234 for(i=0; i<length; i++) {
235 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
240 /* Generated code calls this if we fail a bounds check */
242 void failedboundschk() {
244 printf("Array out of bounds\n");
252 printf("Array out of bounds\n");
253 longjmp(error_handler,2);
258 /* Abort task call */
262 printf("Aborting\n");
263 longjmp(error_handler,4);
266 printf("Aborting\n");