2 #include "structdefs.h"
13 #include "runtime_arch.h"
16 extern int classsize[];
17 extern int typearray[];
18 extern int typearray2[];
20 jmp_buf error_handler;
25 float failurechance=0;
27 int injectinstructionfailures;
29 float instfailurechance=0;
39 int instanceof(struct ___Object___ *ptr, int type) {
51 i=typearray2[i-NUMCLASSES];
58 void initializeexithandler() {
61 void exithandler(int sig, siginfo_t *info, void * uap) {
63 printf("exit in exithandler\n");
68 void initializeexithandler() {
70 sig.sa_sigaction=&exithandler;
71 sig.sa_flags=SA_SIGINFO;
72 sigemptyset(&sig.sa_mask);
73 sigaction(SIGUSR2, &sig, 0);
77 /* This function inject failures */
79 void injectinstructionfailure() {
81 // not supported in MULTICORE version
85 if (injectinstructionfailures) {
88 instructioncount=failurecount;
89 instaccum+=failurecount;
90 if ((((double)random())/RAND_MAX)<instfailurechance) {
93 printf("FAILURE!!! %d\n",numfailures);
94 longjmp(error_handler,11);
99 if (injectinstructionfailures) {
102 instaccum+=failurecount;
103 if ((((double)random())/RAND_MAX)<instfailurechance) {
106 printf("FAILURE!!! %d\n",numfailures);
115 #ifdef D___Double______nativeparsedouble____L___String___
116 double CALL01(___Double______nativeparsedouble____L___String___,struct ___String___ * ___str___) {
117 int length=VAR(___str___)->___count___;
118 int maxlength=(length>60) ? 60 : length;
119 char str[maxlength+1];
120 struct ArrayObject * chararray=VAR(___str___)->___value___;
122 int offset=VAR(___str___)->___offset___;
123 for(i=0; i<maxlength; i++) {
124 str[i]=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
132 #ifdef D___String______convertdoubletochar____D__AR_C
133 int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
134 int length=VAR(___chararray___)->___length___;
137 int num=snprintf(str, length, "%f",___val___);
140 for(i=0; i<length; i++) {
141 ((short *)(((char *)&VAR(___chararray___)->___length___)+sizeof(int)))[i]=(short)str[i];
146 int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
151 void CALL11(___System______exit____I,int ___status___, int ___status___) {
153 BAMBOO_EXIT(___status___);
156 printf("exit in CALL11\n");
162 void CALL23(___Vector______removeElement_____AR_L___Object____I_I, int ___index___, int ___size___, struct ArrayObject * ___array___, int ___index___, int ___size___) {
163 char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___;
164 memmove(offset, offset+sizeof(void *),(___size___-___index___-1)*sizeof(void *));
167 void CALL11(___System______printI____I,int ___status___, int ___status___) {
169 BAMBOO_DEBUGPRINT(0x1111);
170 BAMBOO_DEBUGPRINT_REG(___status___);
173 printf("printI in CALL11\n");
175 printf("%d\n", ___status___);
179 long CALL00(___System______currentTimeMillis____) {
181 // not supported in MULTICORE version
184 struct timeval tv; long long retval;
185 gettimeofday(&tv, NULL);
186 retval = tv.tv_sec; /* seconds */
187 retval*=1000; /* milliseconds */
188 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
193 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
196 struct ArrayObject * chararray=VAR(___s___)->___value___;
198 int offset=VAR(___s___)->___offset___;
199 for(i=0; i<VAR(___s___)->___count___; i++) {
200 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
206 /* Object allocation function */
209 void * allocate_new(void * ptr, int type) {
210 struct ___Object___ * v=(struct ___Object___ *)FREEMALLOC((struct garbagelist *) ptr, classsize[type]);
212 printf("(%x,%x): new object: %x (%d, %x) \n", udn_tile_coord_x(),
213 udn_tile_coord_y(), (int)v, type, classsize[type]);
221 extern unsigned int gc_num_obj;
227 /* Array allocation function */
229 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
230 struct ArrayObject * v=(struct ArrayObject *)FREEMALLOC((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
232 printf("(%x,%x): new array object: %x (%d, %x)\n", udn_tile_coord_x(),
233 udn_tile_coord_y(), (int)v, type,
234 sizeof(struct ArrayObject)+length*classsize[type]);
242 v->___length___=length;
245 extern unsigned int gc_num_obj;
252 void * allocate_new(int type) {
253 struct ___Object___ * v=FREEMALLOC(classsize[type]);
261 /* Array allocation function */
263 struct ArrayObject * allocate_newarray(int type, int length) {
264 struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
268 v->___length___=length;
275 /* Converts C character arrays into Java strings */
277 struct ___String___ * NewString(void * ptr, const char *str,int length) {
279 struct ___String___ * NewString(const char *str,int length) {
283 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
284 int ptrarray[]={1, (int) ptr, (int) chararray};
285 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
286 chararray=(struct ArrayObject *) ptrarray[2];
288 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
289 struct ___String___ * strobj=allocate_new(STRINGTYPE);
291 strobj->___value___=chararray;
292 strobj->___count___=length;
293 strobj->___offset___=0;
295 for(i=0; i<length; i++) {
296 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
301 /* Generated code calls this if we fail a bounds check */
303 void failedboundschk() {
305 printf("Array out of bounds\n");
313 printf("Array out of bounds\n");
314 longjmp(error_handler,2);
321 /* Abort task call */
325 printf("Aborting\n");
326 longjmp(error_handler,4);
329 printf("Aborting\n");