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<signal.h>
8 #include<stdio.h>
9 #include "option.h"
10 #ifdef DSTM
11 #include "dstm.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 long CALL00(___System______currentTimeMillis____) {
82   struct timeval tv; long long retval;
83   gettimeofday(&tv, NULL);
84   retval = tv.tv_sec; /* seconds */
85   retval*=1000; /* milliseconds */
86   retval+= (tv.tv_usec/1000); /* adjust milliseconds & add them in */
87   return retval;
88 }
89
90 void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
91     struct ArrayObject * chararray=VAR(___s___)->___value___;
92     int i;
93     int offset=VAR(___s___)->___offset___;
94     for(i=0;i<VAR(___s___)->___count___;i++) {
95         short sc=((short *)(((char *)& chararray->___length___)+sizeof(int)))[i+offset];
96         putchar(sc);
97     }
98 }
99
100 /* Object allocation function */
101
102 #ifdef DSTM
103 void * allocate_newglobal(transrecord_t *trans, int type) {
104   struct ___Object___ * v=(struct ___Object___ *) transCreateObj(trans, classsize[type]);
105   v->type=type;
106 #ifdef THREADS
107   v->tid=0;
108   v->lockentry=0;
109   v->lockcount=0;
110 #endif
111   return v;
112 }
113
114 /* Array allocation function */
115
116 struct ArrayObject * allocate_newarrayglobal(transrecord_t *trans, int type, int length) {
117   struct ArrayObject * v=(struct ArrayObject *)transCreateObj(trans, sizeof(struct ArrayObject)+length*classsize[type]);
118   if (length<0) {
119     printf("ERROR: negative array\n");
120     return NULL;
121   }
122   v->type=type;
123   v->___length___=length;
124 #ifdef THREADS
125   v->tid=0;
126   v->lockentry=0;
127   v->lockcount=0;
128 #endif
129   return v;
130 }
131 #endif
132
133
134 #ifdef PRECISE_GC
135 void * allocate_new(void * ptr, int type) {
136   struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
137   v->type=type;
138 #ifdef THREADS
139   v->tid=0;
140   v->lockentry=0;
141   v->lockcount=0;
142 #endif
143 #ifdef OPTIONAL
144   v->fses=0;
145 #endif
146   return v;
147 }
148
149 /* Array allocation function */
150
151 struct ArrayObject * allocate_newarray(void * ptr, int type, int length) {
152   struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
153   v->type=type;
154   if (length<0) {
155     printf("ERROR: negative array\n");
156     return NULL;
157   }
158   v->___length___=length;
159 #ifdef THREADS
160   v->tid=0;
161   v->lockentry=0;
162   v->lockcount=0;
163 #endif
164 #ifdef OPTIONAL
165   v->fses=0;
166 #endif
167   return v;
168 }
169
170 #else
171 void * allocate_new(int type) {
172   struct ___Object___ * v=FREEMALLOC(classsize[type]);
173   v->type=type;
174 #ifdef OPTIONAL
175   v->fses=0;
176 #endif
177   return v;
178 }
179
180 /* Array allocation function */
181
182 struct ArrayObject * allocate_newarray(int type, int length) {
183   struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
184   v->type=type;
185   v->___length___=length;
186 #ifdef OPTIONAL
187   v->fses=0;
188 #endif
189   return v;
190 }
191 #endif
192
193
194 /* Converts C character arrays into Java strings */
195 #ifdef PRECISE_GC
196 struct ___String___ * NewString(void * ptr, const char *str,int length) {
197 #else
198 struct ___String___ * NewString(const char *str,int length) {
199 #endif
200   int i;
201 #ifdef PRECISE_GC
202   struct ArrayObject * chararray=allocate_newarray((struct garbagelist *)ptr, CHARARRAYTYPE, length);
203   int ptrarray[]={1, (int) ptr, (int) chararray};
204   struct ___String___ * strobj=allocate_new((struct garbagelist *) &ptrarray, STRINGTYPE);
205   chararray=(struct ArrayObject *) ptrarray[2];
206 #else
207   struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
208   struct ___String___ * strobj=allocate_new(STRINGTYPE);
209 #endif
210   strobj->___value___=chararray;
211   strobj->___count___=length;
212   strobj->___offset___=0;
213
214   for(i=0;i<length;i++) {
215     ((short *)(((char *)& chararray->___length___)+sizeof(int)))[i]=(short)str[i];  }
216   return strobj;
217 }
218
219 /* Generated code calls this if we fail a bounds check */
220
221 void failedboundschk() {
222 #ifndef TASK
223   printf("Array out of bounds\n");
224 #ifdef THREADS
225   threadexit();
226 #else
227   exit(-1);
228 #endif
229 #else
230   longjmp(error_handler,2);
231 #endif
232 }
233
234 /* Abort task call */
235 void abort_task() {
236 #ifdef TASK
237   longjmp(error_handler,4);
238 #else
239   printf("Aborting\n");
240   exit(-1);
241 #endif
242 }