2 #include "structdefs.h"
13 #include "runtime_arch.h"
17 extern int classsize[];
18 extern int typearray[];
19 extern int typearray2[];
21 jmp_buf error_handler;
26 float failurechance=0;
28 int injectinstructionfailures;
30 float instfailurechance=0;
40 int instanceof(struct ___Object___ *ptr, int type) {
52 i=typearray2[i-NUMCLASSES];
59 void initializeexithandler() {
62 void exithandler(int sig, siginfo_t *info, void * uap) {
64 printf("exit in exithandler\n");
69 void initializeexithandler() {
71 sig.sa_sigaction=&exithandler;
72 sig.sa_flags=SA_SIGINFO;
73 sigemptyset(&sig.sa_mask);
74 sigaction(SIGUSR2, &sig, 0);
78 /* This function inject failures */
80 void injectinstructionfailure() {
82 // not supported in MULTICORE version
86 if (injectinstructionfailures) {
89 instructioncount=failurecount;
90 instaccum+=failurecount;
91 if ((((double)random())/RAND_MAX)<instfailurechance) {
94 printf("FAILURE!!! %d\n",numfailures);
95 longjmp(error_handler,11);
100 if (injectinstructionfailures) {
103 instaccum+=failurecount;
104 if ((((double)random())/RAND_MAX)<instfailurechance) {
107 printf("FAILURE!!! %d\n",numfailures);
116 #ifdef D___Double______nativeparsedouble____L___String___
117 double CALL01(___Double______nativeparsedouble____L___String___,struct ___String___ * ___str___) {
118 int length=VAR(___str___)->___count___;
119 int maxlength=(length>60) ? 60 : length;
120 char str[maxlength+1];
121 struct ArrayObject * chararray=VAR(___str___)->___value___;
123 int offset=VAR(___str___)->___offset___;
124 for(i=0; i<maxlength; i++) {
125 str[i]=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
133 #ifdef D___String______convertdoubletochar____D__AR_C
134 int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
135 int length=VAR(___chararray___)->___length___;
138 int num=snprintf(str, length, "%f",___val___);
141 for(i=0; i<length; i++) {
142 ((short *)(((char *)&VAR(___chararray___)->___length___)+sizeof(int)))[i]=(short)str[i];
147 int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
152 void CALL11(___System______exit____I,int ___status___, int ___status___) {
154 BAMBOO_EXIT(___status___);
157 printf("exit in CALL11\n");
163 //#ifdef D___Vector______removeElement_____AR_L___Object____I_I
164 void CALL23(___Vector______removeElement_____AR_L___Object____I_I, int ___index___, int ___size___, struct ArrayObject * ___array___, int ___index___, int ___size___) {
165 char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___;
166 memmove(offset, offset+sizeof(void *),(___size___-___index___-1)*sizeof(void *));
170 void CALL11(___System______printI____I,int ___status___, int ___status___) {
172 BAMBOO_DEBUGPRINT(0x1111);
173 BAMBOO_DEBUGPRINT_REG(___status___);
176 printf("printI in CALL11\n");
178 printf("%d\n", ___status___);
182 long CALL00(___System______currentTimeMillis____) {
184 // not supported in MULTICORE version
187 struct timeval tv; long long retval;
188 gettimeofday(&tv, NULL);
189 retval = tv.tv_sec; /* seconds */
190 retval*=1000; /* milliseconds */
191 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
196 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
199 struct ArrayObject * chararray=VAR(___s___)->___value___;
201 int offset=VAR(___s___)->___offset___;
202 for(i=0; i<VAR(___s___)->___count___; i++) {
203 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
209 /* Object allocation function */
212 void * allocate_new(void * ptr, int type) {
213 struct ___Object___ * v=(struct ___Object___ *)FREEMALLOC((struct garbagelist *) ptr, classsize[type]);
215 printf("(%x,%x): new object: %x \n", udn_tile_coord_x(),
216 udn_tile_coord_y(), v);
224 extern unsigned int gc_num_obj;
230 /* Array allocation function */
232 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
233 struct ArrayObject * v=(struct ArrayObject *)FREEMALLOC((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
235 printf("(%x,%x): new array object: %x \n", udn_tile_coord_x(),
236 udn_tile_coord_y(), v);
244 v->___length___=length;
247 extern unsigned int gc_num_obj;
254 void * allocate_new(int type) {
255 struct ___Object___ * v=FREEMALLOC(classsize[type]);
264 /* Array allocation function */
266 struct ArrayObject * allocate_newarray(int type, int length) {
267 struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
272 v->___length___=length;
279 /* Converts C character arrays into Java strings */
281 struct ___String___ * NewString(void * ptr, const char *str,int length) {
283 struct ___String___ * NewString(const char *str,int length) {
287 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
288 int ptrarray[]={1, (int) ptr, (int) chararray};
289 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
290 chararray=(struct ArrayObject *) ptrarray[2];
292 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
293 struct ___String___ * strobj=allocate_new(STRINGTYPE);
295 strobj->___value___=chararray;
296 strobj->___count___=length;
297 strobj->___offset___=0;
299 for(i=0; i<length; i++) {
300 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
305 /* Generated code calls this if we fail a bounds check */
307 void failedboundschk() {
309 printf("Array out of bounds\n");
317 printf("Array out of bounds\n");
318 longjmp(error_handler,2);
323 /* Abort task call */
327 printf("Aborting\n");
328 longjmp(error_handler,4);
331 printf("Aborting\n");