change
[IRC.git] / Robust / src / Runtime / runtime.c
1 #include "runtime.h"
2 #include "structdefs.h"
3 #include <signal.h>
4 #include "mem.h"
5 #include <fcntl.h>
6 #include <errno.h>
7 #include <stdio.h>
8 #include "option.h"
9 #include "methodheaders.h"
10 #ifdef DSTM
11 #ifdef RECOVERY
12 #include "DSTM/interface_recovery/dstm.h"
13 #include "DSTM/interface_recovery/prelookup.h"
14
15 #ifdef RECOVERYSTATS
16   extern int numRecovery;
17   extern unsigned int deadMachine[8];
18   extern unsigned int sizeOfRedupedData[8];
19   extern double elapsedTime[8];
20 #endif
21   
22 #else
23 #include "DSTM/interface/dstm.h"
24 #include "DSTM/interface/altprelookup.h"
25 #include "DSTM/interface/prefetch.h"
26 #endif
27 #endif
28 #ifdef STM
29 #include "tm.h"
30 #include <pthread.h>
31 #endif
32 #ifdef STMLOG
33 #define ARRAY_LENGTH 700003
34 __thread int counter;
35 __thread int event[ARRAY_LENGTH];
36 __thread unsigned long long clkticks[ARRAY_LENGTH];
37 unsigned long long beginClock=0;
38 #define FILENAME  "log"
39 #endif
40 #ifdef EVENTMONITOR
41 #include "monitor.h"
42 __thread int objcount=0;
43 #define ASSIGNUID(x) {                                  \
44     int number=((objcount++)<<EVTHREADSHIFT)|threadnum; \
45     x->objuid=number;                                   \
46   }
47 #else
48 #define ASSIGNUID(x)
49 #endif
50
51 #if defined(THREADS)||defined(STM)
52 /* Global barrier for STM */
53 pthread_barrier_t barrier;
54 pthread_barrierattr_t attr;
55 #endif
56
57 #include <string.h>
58
59 extern int classsize[];
60 extern int typearray[];
61 extern int typearray2[];
62 jmp_buf error_handler;
63 int instructioncount;
64
65 char *options;
66 int injectfailures=0;
67 float failurechance=0;
68 int errors=0;
69 int debugtask=0;
70 int injectinstructionfailures;
71 int failurecount;
72 float instfailurechance=0;
73 int numfailures;
74 int instaccum=0;
75 typedef unsigned long long ticks;
76 #ifdef DMALLOC
77 #include "dmalloc.h"
78 #endif
79
80 int instanceof(struct ___Object___ *ptr, int type) {
81   int i=ptr->type;
82   do {
83     if (i==type)
84       return 1;
85     i=typearray[i];
86   } while(i!=-1);
87   i=ptr->type;
88   if (i>NUMCLASSES) {
89     do {
90       if (i==type)
91         return 1;
92       i=typearray2[i-NUMCLASSES];
93     } while(i!=-1);
94   }
95   return 0;
96 }
97
98 void exithandler(int sig, siginfo_t *info, void * uap) {
99   exit(0);
100 }
101
102 void initializeexithandler() {
103   struct sigaction sig;
104   sig.sa_sigaction=&exithandler;
105   sig.sa_flags=SA_SIGINFO;
106   sigemptyset(&sig.sa_mask);
107   sigaction(SIGUSR2, &sig, 0);
108 }
109
110
111 /* This function inject failures */
112
113 void injectinstructionfailure() {
114 #ifdef TASK
115   if (injectinstructionfailures) {
116     if (numfailures==0)
117       return;
118     instructioncount=failurecount;
119     instaccum+=failurecount;
120     if ((((double)random())/RAND_MAX)<instfailurechance) {
121       if (numfailures>0)
122         numfailures--;
123       printf("FAILURE!!! %d\n",numfailures);
124       longjmp(error_handler,11);
125     }
126   }
127 #else
128 #ifdef THREADS
129   if (injectinstructionfailures) {
130     if (numfailures==0)
131       return;
132     instaccum+=failurecount;
133     if ((((double)random())/RAND_MAX)<instfailurechance) {
134       if (numfailures>0)
135         numfailures--;
136       printf("FAILURE!!! %d\n",numfailures);
137       threadexit();
138     }
139   }
140 #endif
141 #endif
142 }
143
144 #ifdef D___Double______nativeparsedouble____L___String___
145 double CALL01(___Double______nativeparsedouble____L___String___,struct ___String___ * ___str___) {
146   int length=VAR(___str___)->___count___;
147   int maxlength=(length>60)?60:length;
148   char str[maxlength+1];
149   struct ArrayObject * chararray=VAR(___str___)->___value___;
150   int i;
151   int offset=VAR(___str___)->___offset___;
152   for(i=0; i<maxlength; i++) {
153     str[i]=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
154   }
155   str[i]=0;
156   double d=atof(str);
157   return d;
158 }
159 #endif
160
161 #ifdef D___Double______nativeparsedouble_____AR_B_I_I 
162 double CALL23(___Double______nativeparsedouble_____AR_B_I_I, int start, int length,int start,int length,struct ArrayObject * ___str___) {
163   int maxlength=(length>60)?60:length;
164   char str[maxlength+1];
165   struct ArrayObject * bytearray=VAR(___str___);
166   int i;
167   for(i=0; i<maxlength; i++) {
168     str[i]=(((char *)&bytearray->___length___)+sizeof(int))[i+start];
169   }
170   str[i]=0;
171   double d=atof(str);
172   return d;
173 }
174 #endif
175
176 #ifdef D___String______convertdoubletochar____D__AR_C
177 int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
178   int length=VAR(___chararray___)->___length___;
179   char str[length];
180   int i;
181   int num=snprintf(str, length, "%f",___val___);
182   if (num>=length)
183     num=length-1;
184   for(i=0; i<length; i++) {
185     ((short *)(((char *)&VAR(___chararray___)->___length___)+sizeof(int)))[i]=(short)str[i];
186   }
187   return num;
188 }
189 #endif
190 #ifdef D___System______deepArrayCopy____L___Object____L___Object___
191 void deepArrayCopy(struct ___Object___ * dst, struct ___Object___ * src) {
192   int dsttype=((int *)dst)[0];
193   int srctype=((int *)src)[0];
194 #ifdef STMARRAY
195   src=src->___objlocation___;
196 #endif
197   if (dsttype<NUMCLASSES||srctype<NUMCLASSES||srctype!=dsttype)
198     return;
199   struct ArrayObject *aodst=(struct ArrayObject *)dst;
200   struct ArrayObject *aosrc=(struct ArrayObject *)src;
201   int dstlength=aodst->___length___;
202   int srclength=aosrc->___length___;
203   if (dstlength!=srclength)
204     return;
205   unsigned INTPTR *pointer=pointerarray[srctype];
206   if (pointer==0) {
207     int elementsize=classsize[srctype];
208     int size=srclength*elementsize;
209     //primitives
210     memcpy(((char *)&aodst->___length___)+sizeof(int) , ((char *)&aosrc->___length___)+sizeof(int), size);
211   } else {
212     //objects
213     int i;
214     for(i=0;i<srclength;i++) {
215       struct ___Object___ * ptr=((struct ___Object___**)(((char*) &aosrc->___length___)+sizeof(int)))[i];
216       int ptrtype=((int *)ptr)[0];
217       if (ptrtype>=NUMCLASSES) {
218         struct ___Object___ * dstptr=((struct ___Object___**)(((char*) &aodst->___length___)+sizeof(int)))[i];
219         deepArrayCopy(dstptr,ptr);
220       } else {
221         //hit an object
222         ((struct ___Object___ **)(((char*) &aodst->___length___)+sizeof(int)))[i]=ptr;
223       }
224     }
225   }
226 }
227
228 void CALL02(___System______deepArrayCopy____L___Object____L___Object___, struct ___Object___ * ___dst___, struct ___Object___ * ___src___) {
229   deepArrayCopy(VAR(___dst___), VAR(___src___));
230 }
231 #endif
232
233 void CALL11(___System______exit____I,int ___status___, int ___status___) {
234 #ifdef RECOVERYSTATS
235   int i=0;
236   for(i=0; i < numRecovery; i++) {
237     printf("Dead Machine = %s\n",midtoIPString(deadMachine[i]));
238     printf("Elapsed Time = %.2f\n",elapsedTime[i]);
239   }
240 #endif
241
242 #ifdef TRANSSTATS
243   printf("numTransCommit = %d\n", numTransCommit);
244   printf("numTransAbort = %d\n", numTransAbort);
245   printf("nSoftAbort = %d\n", nSoftAbort);
246 #ifdef STM
247   printf("nSoftAbortCommit = %d\n", nSoftAbortCommit);
248   printf("nSoftAbortAbort = %d\n", nSoftAbortAbort);
249 #ifdef STMSTATS
250   int i;
251   for(i=0; i<TOTALNUMCLASSANDARRAY; i++) {
252     printf("typesCausingAbort[%2d] numaccess= %5d numabort= %3d\n", i, typesCausingAbort[i].numaccess, typesCausingAbort[i].numabort);
253   }
254 #endif
255 #endif
256 #endif
257 #ifdef EVENTMONITOR
258   dumpdata();
259 #endif
260   exit(___status___);
261 }
262
263 void CALL11(___System______logevent____I,int ___event___, int ___event___) {
264 #ifdef STMLOG
265   event[counter] = ___event___;
266   clkticks[counter] = rdtsc();
267   counter++;
268 #endif
269   return;
270 }
271
272 void CALL00(___System______logevent____) {
273 #ifdef STMLOG
274   beginClock= rdtsc();
275 #endif
276   return;
277 }
278
279 void CALL11(___System______flushToFile____I, int ___threadid___, int ___threadid___) {
280 #ifdef STMLOG
281   FILE *fp;
282   /* Flush to file */
283   char filename[20];
284   memset(filename, 0, 20);
285   sprintf(filename, "%s_%d", FILENAME, ___threadid___);
286   if ((fp = fopen(filename, "w+")) == NULL) {
287     perror("fopen");
288     return;
289   }
290   int i;
291   for (i = 0; i < counter-1; i++) {
292     fprintf(fp, "%d %lld %lld\n", event[i], clkticks[i]-beginClock, clkticks[i+1]-beginClock);
293   }
294   fprintf(fp, "%d %lld\n", event[i], clkticks[i]-beginClock);
295
296   fclose(fp);
297 #endif
298   return;
299 }
300
301 void CALL00(___System______initLog____) {
302 #ifdef STMLOG
303   counter=0;
304   int i;
305   for(i=0; i<ARRAY_LENGTH; i++) {
306     event[i] = 0;
307     clkticks[i] = 0;
308   }
309
310 #endif
311   return;
312 }
313
314 #ifdef D___Vector______removeElement_____AR_L___Object____I_I
315 void CALL23(___Vector______removeElement_____AR_L___Object____I_I, int ___index___, int ___size___, struct ArrayObject * ___array___, int ___index___, int ___size___) {
316   char* offset=((char *)(&VAR(___array___)->___length___))+sizeof(unsigned int)+sizeof(void *)*___index___;
317   memmove(offset, offset+sizeof(void *),(___size___-___index___-1)*sizeof(void *));
318 }
319 #endif
320
321 void CALL11(___System______printI____I,int ___status___, int ___status___) {
322   printf("%d\n",___status___);
323 }
324
325 long long CALL00(___System______currentTimeMillis____) {
326   struct timeval tv; long long retval;
327   gettimeofday(&tv, NULL);
328   retval = tv.tv_sec; /* seconds */
329   retval*=1000; /* milliseconds */
330   retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
331   return retval;
332 }
333
334 long long CALL00(___System______microTimes____) {
335   struct timeval tv; 
336   long long retval;
337   gettimeofday(&tv, NULL);
338   retval = tv.tv_sec; /* seconds */
339   retval*=1000000; /* microsecs */
340   retval+= (tv.tv_usec); /* adjust microseconds & add them in */
341   return retval;
342 }
343
344 long long CALL00(___System______getticks____) {
345   unsigned a, d;
346   asm("cpuid");
347   asm volatile("rdtsc" : "=a" (a), "=d" (d));
348   return (((ticks)a) | (((ticks)d) << 32));
349 }
350
351 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
352   struct ArrayObject * chararray=VAR(___s___)->___value___;
353   int i;
354   int offset=VAR(___s___)->___offset___;
355   for(i=0; i<VAR(___s___)->___count___; i++) {
356     short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
357     putchar(sc);
358   }
359
360 #ifdef RECOVERYSTATS
361   fflush(stdout);
362 #endif
363 }
364
365 #ifdef DSTM
366 void CALL00(___System______clearPrefetchCache____) {
367   prehashClear();
368 }
369
370 #ifdef RANGEPREFETCH
371 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
372   /* Manual Prefetches to be inserted */
373   //printf("DEBUG-> %s() ___Object___ * ___o___ = %x\n", __func__, VAR(___o___));
374   //printf("DEBUG-> %s() ArrayObject * = %x\n", __func__, VAR(___offsets___));
375   int numoffset=VAR(___offsets___)->___length___;
376   int i;
377   short offArry[numoffset+2];
378   offArry[0] = 0;
379   offArry[1] = 0;
380   for(i = 2; i<(numoffset+2); i++) {
381     offArry[i] = *((short *)(((char *)&VAR(___offsets___)->___length___) + sizeof(int) + (i-2) * sizeof(short)));
382     //printf("DEBUG-> offArry[%d] = %d\n", i, offArry[i]);
383   }
384   unsigned int oid;
385   if(((unsigned int)(VAR(___o___)) & 1) != 0) { //odd
386     oid =  (unsigned int) VAR(___o___); //outside transaction therefore just an oid
387   } else { //even
388     oid = (unsigned int) COMPOID(VAR(___o___)); //inside transaction therefore a pointer to oid
389   }
390   rangePrefetch(oid, (short)(numoffset+2), offArry);
391 }
392 #else
393 void CALL02(___System______rangePrefetch____L___Object_____AR_S, struct ___Object___ * ___o___, struct ArrayObject * ___offsets___) {
394   return;
395 }
396 #endif
397
398 #ifdef D___Task______execution____ 
399 extern void* virtualtable[];
400 // associated with Task.execution(). finds proper execute method and call it
401 void CALL01(___Task______execution____,struct ___Task___ * ___this___)
402 {
403   unsigned int oid;
404   oid = (unsigned int) VAR(___this___);   // object id
405   int type = getObjType(oid);             // object type
406
407 #ifdef PRECISE_GC
408   int p[] = {1,0 , oid};
409    
410   ((void(*) (void *))virtualtable[type*MAXCOUNT + EXECUTEMETHOD])(p);
411 #else
412   // call the proper execute method
413   ((void(*) (void *))virtualtable[type*MAXCOUNT + EXECUTEMETHOD])(oid);
414 #endif
415 }
416 #endif
417
418 #endif // DSTM
419
420 /* STM Barrier constructs */
421 #ifdef D___Barrier______setBarrier____I
422 void CALL11(___Barrier______setBarrier____I, int nthreads, int nthreads) {
423   // Barrier initialization
424   int ret;
425   if((ret = pthread_barrier_init(&barrier, NULL, nthreads)) != 0) {
426     printf("%s() Could not create a barrier: numthreads = 0 in %s\n", __func__, __FILE__);
427     exit(-1);
428   }
429 }
430 #endif
431
432 #ifdef D___Barrier______enterBarrier____
433 void CALL00(___Barrier______enterBarrier____) {
434   // Synchronization point
435   int ret;
436 #ifdef EVENTMONITOR
437   EVLOGEVENT(EV_ENTERBARRIER);
438 #endif
439 #ifdef PRECISE_GC
440   stopforgc((struct garbagelist *)___params___);
441 #endif
442   ret = pthread_barrier_wait(&barrier);
443 #ifdef PRECISE_GC
444   restartaftergc();
445 #endif
446   if(ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) {
447     printf("%s() Could not wait on barrier: error %d in %s\n", __func__, errno, __FILE__);
448     exit(-1);
449   }
450 #ifdef EVENTMONITOR
451   EVLOGEVENT(EV_EXITBARRIER);
452 #endif
453 }
454 #endif
455
456 /* Object allocation function */
457
458 #ifdef DSTM
459 __attribute__((malloc)) void * allocate_newglobal(int type) {
460   struct ___Object___ * v=(struct ___Object___ *) transCreateObj(classsize[type]);
461   v->type=type;
462   //printf("DEBUG %s(), type= %x\n", __func__, type);
463 #ifdef THREADS
464   v->tid=0;
465   v->lockentry=0;
466   v->lockcount=0;
467 #endif
468   return v;
469 }
470
471 /* Array allocation function */
472
473 __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, int length) {
474   struct ArrayObject * v=(struct ArrayObject *)transCreateObj(sizeof(struct ArrayObject)+length*classsize[type]);
475   if (length<0) {
476     printf("ERROR: negative array\n");
477     return NULL;
478   }
479   v->type=type;
480   v->___length___=length;
481 #ifdef THREADS
482   v->tid=0;
483   v->lockentry=0;
484   v->lockcount=0;
485 #endif
486   return v;
487 }
488 #endif
489
490
491 #ifdef STM
492 // STM Versions of allocation functions
493
494 /* Object allocation function */
495 __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) {
496 #ifdef STMARRAY
497   struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type], 0);
498 #else
499   struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type]);
500 #endif
501   ASSIGNUID(v);
502   v->type=type;
503   v->___objlocation___=v;
504   return v;
505 }
506
507 /* Array allocation function */
508 __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length) {
509 #ifdef STMARRAY
510   int basesize=length*classsize[type];
511   //round the base size up
512   basesize=(basesize+LOWMASK)&HIGHMASK;
513   int numlocks=basesize>>INDEXSHIFT;
514   int bookkeepsize=numlocks*2*sizeof(int);
515   struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+basesize+bookkeepsize, bookkeepsize);
516   unsigned int *intptr=(unsigned int *)(((char *)v)-sizeof(objheader_t));
517   for(;numlocks>0;numlocks--) {
518     intptr-=2;
519     intptr[0]=1;
520   }
521   v->highindex=-1;
522   v->lowindex=MAXARRAYSIZE;
523 #else
524   struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]);
525 #endif
526   ASSIGNUID(v);
527   if (length<0) {
528     printf("ERROR: negative array\n");
529     return NULL;
530   }
531   v->___objlocation___=(struct ___Object___*)v;
532   v->type=type;
533   v->___length___=length;
534   return v;
535 }
536
537 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
538   objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t));
539   struct ___Object___ * v=(struct ___Object___ *) &tmp[1];
540   ASSIGNUID(v);
541   initdsmlocks(&tmp->lock);
542   tmp->version = 1;
543   v->___objlocation___=v;
544   v->type = type;
545   return v;
546 }
547
548 /* Array allocation function */
549
550 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
551 #ifdef STMARRAY
552   int basesize=length*classsize[type];
553   //round the base size up
554   basesize=(basesize+LOWMASK)&HIGHMASK;
555   int numlocks=basesize>>INDEXSHIFT;
556   int bookkeepsize=(numlocks)*2*sizeof(int);
557   int *tmpint=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+basesize+sizeof(objheader_t)+bookkeepsize);
558   for(;numlocks>0;numlocks--) {
559     tmpint[0]=1;
560     tmpint+=2;
561   }
562   objheader_t *tmp=(objheader_t *)tmpint;
563   struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
564   v->highindex=-1;
565   v->lowindex=MAXARRAYSIZE;
566 #else
567   objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t));
568   struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
569 #endif
570 #ifdef DUALVIEW
571   tmp->lock=RW_LOCK_BIAS;
572 #else
573   initdsmlocks(&tmp->lock);
574 #endif
575   tmp->version=1;
576   ASSIGNUID(v);
577   v->type=type;
578   if (length<0) {
579     printf("ERROR: negative array %d\n", length);
580     return NULL;
581   }
582   v->___objlocation___=(struct ___Object___ *)v;
583   v->___length___=length;
584   return v;
585 }
586 #endif
587
588 #ifndef STM
589 #if defined(PRECISE_GC)
590 __attribute__((malloc)) void * allocate_new(void * ptr, int type) {
591   struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
592   v->type=type;
593 #ifdef THREADS
594   v->tid=0;
595   v->lockentry=0;
596   v->lockcount=0;
597 #endif
598 #ifdef OPTIONAL
599   v->fses=0;
600 #endif
601   return v;
602 }
603
604 /* Array allocation function */
605
606 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
607   struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
608   v->type=type;
609   if (length<0) {
610     printf("ERROR: negative array\n");
611     return NULL;
612   }
613   v->___length___=length;
614 #ifdef THREADS
615   v->tid=0;
616   v->lockentry=0;
617   v->lockcount=0;
618 #endif
619 #ifdef OPTIONAL
620   v->fses=0;
621 #endif
622   return v;
623 }
624
625 #else
626 __attribute__((malloc)) void * allocate_new(int type) {
627   struct ___Object___ * v=FREEMALLOC(classsize[type]);
628   v->type=type;
629 #ifdef OPTIONAL
630   v->fses=0;
631 #endif
632   return v;
633 }
634
635 /* Array allocation function */
636
637 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length) {
638   __attribute__((malloc))  struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
639   v->type=type;
640   v->___length___=length;
641 #ifdef OPTIONAL
642   v->fses=0;
643 #endif
644   return v;
645 }
646 #endif
647 #endif
648
649 /* Converts C character arrays into Java strings */
650 #ifdef PRECISE_GC
651 __attribute__((malloc)) struct ___String___ * NewString(void * ptr, const char *str,int length) {
652 #else
653 __attribute__((malloc)) struct ___String___ * NewString(const char *str,int length) {
654 #endif
655   int i;
656 #ifdef PRECISE_GC
657   struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
658   INTPTR ptrarray[]={1, (INTPTR) ptr, (INTPTR) chararray};
659   struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
660   chararray=(struct ArrayObject *) ptrarray[2];
661 #else
662   struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
663   struct ___String___ * strobj=allocate_new(STRINGTYPE);
664 #endif
665   strobj->___value___=chararray;
666   strobj->___count___=length;
667   strobj->___offset___=0;
668
669   for(i=0; i<length; i++) {
670     ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
671   }
672   return strobj;
673 }
674
675 /* Generated code calls this if we fail a bounds check */
676
677 void failedboundschk() {
678 #ifndef TASK
679   printf("Array out of bounds\n");
680 #ifdef THREADS
681   threadexit();
682 #else
683   exit(-1);
684 #endif
685 #else
686   longjmp(error_handler,2);
687 #endif
688 }
689
690 /* Abort task call */
691 void abort_task() {
692 #ifdef TASK
693   longjmp(error_handler,4);
694 #else
695   printf("Aborting\n");
696   exit(-1);
697 #endif
698 }
699
700 #ifndef SANDBOX
701 #ifdef D___System______Assert____Z
702  void CALL11(___System______Assert____Z, int ___status___, int ___status___) {
703    if (!___status___) {
704      printf("Assertion violation\n");
705      *((int *)(NULL)); //force stack trace error
706    }
707  }
708 #endif
709 #endif