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 #ifdef D___Double______nativeparsedouble____L___String___
97 double CALL01(___Double______nativeparsedouble____L___String___,struct ___String___ * ___str___) {
98 int length=VAR(___str___)->___count___;
99 int maxlength=(length>60)?60:length;
100 char str[maxlength+1];
101 struct ArrayObject * chararray=VAR(___str___)->___value___;
103 int offset=VAR(___str___)->___offset___;
104 for(i=0; i<maxlength; i++) {
105 str[i]=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
113 #ifdef D___String______convertdoubletochar____D__AR_C
114 int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
115 int length=VAR(___chararray___)->___length___;
118 int num=snprintf(str, length, "%f",___val___);
121 for(i=0; i<length; i++) {
122 ((short *)(((char *)&VAR(___chararray___)->___length___)+sizeof(int)))[i]=(short)str[i];
127 int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
132 void CALL11(___System______exit____I,int ___status___, int ___status___) {
134 BAMBOO_EXIT(___status___);
137 printf("exit in CALL11\n");
143 //#ifdef D___Vector______removeElement_____AR_L___Object____I_I
144 void CALL23(___Vector______removeElement_____AR_L___Object____I_I, int ___index___, int ___size___, struct ArrayObject * ___array___, int ___index___, int ___size___) {
145 char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___;
146 memmove(offset, offset+sizeof(void *),(___size___-___index___-1)*sizeof(void *));
150 void CALL11(___System______printI____I,int ___status___, int ___status___) {
152 BAMBOO_DEBUGPRINT(0x1111);
153 BAMBOO_DEBUGPRINT_REG(___status___);
156 printf("printI in CALL11\n");
158 printf("%d\n", ___status___);
162 long CALL00(___System______currentTimeMillis____) {
164 // not supported in MULTICORE version
167 struct timeval tv; long long retval;
168 gettimeofday(&tv, NULL);
169 retval = tv.tv_sec; /* seconds */
170 retval*=1000; /* milliseconds */
171 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
176 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
179 struct ArrayObject * chararray=VAR(___s___)->___value___;
181 int offset=VAR(___s___)->___offset___;
182 for(i=0; i<VAR(___s___)->___count___; i++) {
183 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
189 /* Object allocation function */
192 void * allocate_new(void * ptr, int type) {
193 struct ___Object___ * v=(struct ___Object___ *)FREEMALLOC((struct garbagelist *) ptr, classsize[type]);
195 tprintf("new object: %x \n", v);
204 /* Array allocation function */
206 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
207 struct ArrayObject * v=(struct ArrayObject *)FREEMALLOC((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
209 tprintf("new array object: %x \n", v);
217 v->___length___=length;
223 void * allocate_new(int type) {
224 struct ___Object___ * v=FREEMALLOC(classsize[type]);
233 /* Array allocation function */
235 struct ArrayObject * allocate_newarray(int type, int length) {
236 struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
241 v->___length___=length;
248 /* Converts C character arrays into Java strings */
250 struct ___String___ * NewString(void * ptr, const char *str,int length) {
252 struct ___String___ * NewString(const char *str,int length) {
256 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
257 int ptrarray[]={1, (int) ptr, (int) chararray};
258 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
259 chararray=(struct ArrayObject *) ptrarray[2];
261 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
262 struct ___String___ * strobj=allocate_new(STRINGTYPE);
264 strobj->___value___=chararray;
265 strobj->___count___=length;
266 strobj->___offset___=0;
268 for(i=0; i<length; i++) {
269 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
274 /* Generated code calls this if we fail a bounds check */
276 void failedboundschk() {
278 printf("Array out of bounds\n");
286 printf("Array out of bounds\n");
287 longjmp(error_handler,2);
292 /* Abort task call */
296 printf("Aborting\n");
297 longjmp(error_handler,4);
300 printf("Aborting\n");