This commit was manufactured by cvs2svn to create tag 'buildscript'.
[IRC.git] /
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 #ifdef DSTM
10 #include "dstm.h"
11 #include "prelookup.h"
12 #endif
13
14 extern int classsize[];
15 jmp_buf error_handler;
16 int instructioncount;
17
18 char *options;
19 int injectfailures=0;
20 float failurechance=0;
21 int errors=0;
22 int debugtask=0;
23 int injectinstructionfailures;
24 int failurecount;
25 float instfailurechance=0;
26 int numfailures;
27 int instaccum=0;
28 #ifdef DMALLOC
29 #include "dmalloc.h"
30 #endif
31
32 void exithandler(int sig, siginfo_t *info, void * uap) {
33   exit(0);
34 }
35
36 void initializeexithandler() {
37   struct sigaction sig;
38   sig.sa_sigaction=&exithandler;
39   sig.sa_flags=SA_SIGINFO;
40   sigemptyset(&sig.sa_mask);
41   sigaction(SIGUSR2, &sig, 0);
42 }
43
44
45 /* This function inject failures */
46
47 void injectinstructionfailure() {
48 #ifdef TASK
49   if (injectinstructionfailures) {
50     if (numfailures==0)
51       return;
52     instructioncount=failurecount;
53     instaccum+=failurecount;
54     if ((((double)random())/RAND_MAX)<instfailurechance) {
55       if (numfailures>0)
56         numfailures--;
57       printf("FAILURE!!! %d\n",numfailures);
58       longjmp(error_handler,11);
59     }
60   }
61 #else
62 #ifdef THREADS
63   if (injectinstructionfailures) {
64     if (numfailures==0)
65       return;
66     instaccum+=failurecount;
67     if ((((double)random())/RAND_MAX)<instfailurechance) {
68       if (numfailures>0)
69         numfailures--;
70       printf("FAILURE!!! %d\n",numfailures);
71       threadexit();
72     }
73   }
74 #endif
75 #endif
76 }
77
78 void CALL11(___System______exit____I,int ___status___, int ___status___) {
79   exit(___status___);
80 }
81
82 void CALL11(___System______printI____I,int ___status___, int ___status___) {
83   printf("%d\n",___status___);
84 }
85
86 long CALL00(___System______currentTimeMillis____) {
87   struct timeval tv; long long retval;
88   gettimeofday(&tv, NULL);
89   retval = tv.tv_sec; /* seconds */
90   retval*=1000; /* milliseconds */
91   retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
92   return retval;
93 }
94
95 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
96   struct ArrayObject * chararray=VAR(___s___)->___value___;
97   int i;
98   int offset=VAR(___s___)->___offset___;
99   for(i=0; i<VAR(___s___)->___count___; i++) {
100     short sc=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
101     putchar(sc);
102   }
103 }
104
105 #ifdef DSTM
106 void CALL00(___System______clearPrefetchCache____) {
107   prehashClear();
108 }
109 #endif
110
111 /* Object allocation function */
112
113 #ifdef DSTM
114 void * allocate_newglobal(transrecord_t *trans, int type) {
115   struct ___Object___ * v=(struct ___Object___ *) transCreateObj(trans, classsize[type]);
116   v->type=type;
117 #ifdef THREADS
118   v->tid=0;
119   v->lockentry=0;
120   v->lockcount=0;
121 #endif
122   return v;
123 }
124
125 /* Array allocation function */
126
127 struct ArrayObject * allocate_newarrayglobal(transrecord_t *trans, int type, int length) {
128   struct ArrayObject * v=(struct ArrayObject *)transCreateObj(trans, sizeof(struct ArrayObject)+length*classsize[type]);
129   if (length<0) {
130     printf("ERROR: negative array\n");
131     return NULL;
132   }
133   v->type=type;
134   v->___length___=length;
135 #ifdef THREADS
136   v->tid=0;
137   v->lockentry=0;
138   v->lockcount=0;
139 #endif
140   return v;
141 }
142 #endif
143
144
145 #ifdef PRECISE_GC
146 void * allocate_new(void * ptr, int type) {
147   struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
148   v->type=type;
149 #ifdef THREADS
150   v->tid=0;
151   v->lockentry=0;
152   v->lockcount=0;
153 #endif
154 #ifdef OPTIONAL
155   v->fses=0;
156 #endif
157   return v;
158 }
159
160 /* Array allocation function */
161
162 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
163   struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
164   v->type=type;
165   if (length<0) {
166     printf("ERROR: negative array\n");
167     return NULL;
168   }
169   v->___length___=length;
170 #ifdef THREADS
171   v->tid=0;
172   v->lockentry=0;
173   v->lockcount=0;
174 #endif
175 #ifdef OPTIONAL
176   v->fses=0;
177 #endif
178   return v;
179 }
180
181 #else
182 void * allocate_new(int type) {
183   struct ___Object___ * v=FREEMALLOC(classsize[type]);
184   v->type=type;
185 #ifdef OPTIONAL
186   v->fses=0;
187 #endif
188   return v;
189 }
190
191 /* Array allocation function */
192
193 struct ArrayObject * allocate_newarray(int type, int length) {
194   struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
195   v->type=type;
196   v->___length___=length;
197 #ifdef OPTIONAL
198   v->fses=0;
199 #endif
200   return v;
201 }
202 #endif
203
204
205 /* Converts C character arrays into Java strings */
206 #ifdef PRECISE_GC
207 struct ___String___ * NewString(void * ptr, const char *str,int length) {
208 #else
209 struct ___String___ * NewString(const char *str,int length) {
210 #endif
211   int i;
212 #ifdef PRECISE_GC
213   struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
214   int ptrarray[]={1, (int) ptr, (int) chararray};
215   struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
216   chararray=(struct ArrayObject *) ptrarray[2];
217 #else
218   struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
219   struct ___String___ * strobj=allocate_new(STRINGTYPE);
220 #endif
221   strobj->___value___=chararray;
222   strobj->___count___=length;
223   strobj->___offset___=0;
224
225   for(i=0; i<length; i++) {
226     ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i]=(short)str[i];
227   }
228   return strobj;
229 }
230
231 /* Generated code calls this if we fail a bounds check */
232
233 void failedboundschk() {
234 #ifndef TASK
235   printf("Array out of bounds\n");
236 #ifdef THREADS
237   threadexit();
238 #else
239   exit(-1);
240 #endif
241 #else
242   longjmp(error_handler,2);
243 #endif
244 }
245
246 /* Abort task call */
247 void abort_task() {
248 #ifdef TASK
249   longjmp(error_handler,4);
250 #else
251   printf("Aborting\n");
252   exit(-1);
253 #endif
254 }