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