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) {
62 BAMBOO_DEBUGPRINT(0xa001);
66 void initializeexithandler() {
68 sig.sa_sigaction=&exithandler;
69 sig.sa_flags=SA_SIGINFO;
70 sigemptyset(&sig.sa_mask);
71 sigaction(SIGUSR2, &sig, 0);
75 /* This function inject failures */
77 void injectinstructionfailure() {
79 // not supported in MULTICORE version
83 if (injectinstructionfailures) {
86 instructioncount=failurecount;
87 instaccum+=failurecount;
88 if ((((double)random())/RAND_MAX)<instfailurechance) {
91 printf("FAILURE!!! %d\n",numfailures);
92 longjmp(error_handler,11);
97 if (injectinstructionfailures) {
100 instaccum+=failurecount;
101 if ((((double)random())/RAND_MAX)<instfailurechance) {
104 printf("FAILURE!!! %d\n",numfailures);
113 #ifdef D___Double______nativeparsedouble____L___String___
114 double CALL01(___Double______nativeparsedouble____L___String___,struct ___String___ * ___str___) {
115 int length=VAR(___str___)->___count___;
116 int maxlength=(length>60) ? 60 : length;
117 char str[maxlength+1];
118 struct ArrayObject * chararray=VAR(___str___)->___value___;
120 int offset=VAR(___str___)->___offset___;
121 for(i=0; i<maxlength; i++) {
122 str[i]=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
130 #ifdef D___String______convertdoubletochar____D__AR_C
131 int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
132 int length=VAR(___chararray___)->___length___;
135 int num=snprintf(str, length, "%f",___val___);
138 for(i=0; i<length; i++) {
139 ((short *)(((char *)&VAR(___chararray___)->___length___)+sizeof(int)))[i]=(short)str[i];
144 int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
149 void CALL11(___System______exit____I,int ___status___, int ___status___) {
151 BAMBOO_EXIT(___status___);
154 printf("exit in CALL11\n");
160 void CALL23(___Vector______removeElement_____AR_L___Object____I_I, int ___index___, int ___size___, struct ArrayObject * ___array___, int ___index___, int ___size___) {
161 char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___;
162 memmove(offset, offset+sizeof(void *),(___size___-___index___-1)*sizeof(void *));
165 void CALL11(___System______printI____I,int ___status___, int ___status___) {
167 BAMBOO_DEBUGPRINT(0x1111);
168 BAMBOO_DEBUGPRINT_REG(___status___);
171 printf("printI in CALL11\n");
173 printf("%d\n", ___status___);
177 long CALL00(___System______currentTimeMillis____) {
179 // not supported in MULTICORE version
182 struct timeval tv; long long retval;
183 gettimeofday(&tv, NULL);
184 retval = tv.tv_sec; /* seconds */
185 retval*=1000; /* milliseconds */
186 retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
191 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
194 struct ArrayObject * chararray=VAR(___s___)->___value___;
196 int offset=VAR(___s___)->___offset___;
197 for(i=0; i<VAR(___s___)->___count___; i++) {
198 short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
204 /* Object allocation function */
207 void * allocate_new(void * ptr, int type) {
208 struct ___Object___ * v=(struct ___Object___ *)FREEMALLOC((struct garbagelist *) ptr, classsize[type]);
215 extern unsigned int gc_num_obj;
221 /* Array allocation function */
223 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
224 struct ArrayObject * v=(struct ArrayObject *)FREEMALLOC((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
231 v->___length___=length;
234 extern unsigned int gc_num_obj;
241 void * allocate_new(int type) {
242 struct ___Object___ * v=FREEMALLOC(classsize[type]);
250 /* Array allocation function */
252 struct ArrayObject * allocate_newarray(int type, int length) {
253 struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
257 v->___length___=length;
264 /* Converts C character arrays into Java strings */
266 struct ___String___ * NewString(void * ptr, const char *str,int length) {
268 struct ___String___ * NewString(const char *str,int length) {
272 struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
273 int ptrarray[]={1, (int) ptr, (int) chararray};
274 struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
275 chararray=(struct ArrayObject *) ptrarray[2];
277 struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
278 struct ___String___ * strobj=allocate_new(STRINGTYPE);
280 strobj->___value___=chararray;
281 strobj->___count___=length;
282 strobj->___offset___=0;
284 for(i=0; i<length; i++) {
285 ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
290 /* Generated code calls this if we fail a bounds check */
292 void failedboundschk() {
294 printf("Array out of bounds\n");
302 printf("Array out of bounds\n");
303 longjmp(error_handler,2);
310 /* Abort task call */
314 printf("Aborting\n");
315 longjmp(error_handler,4);
318 printf("Aborting\n");