1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * This source file is part of SableVM.                            *
3  *                                                                 *
4  * See the file "LICENSE" for the copyright information and for    *
5  * the terms and conditions for copying, distribution and          *
6  * modification of this source file.                               *
7  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
8 
9 #ifndef SVM_SYSTEM_H
10 #define SVM_SYSTEM_H
11 
12 /*
13 IMPORTANT: "ALIGNMENT" should be >= sizeof (void *) and a power of 2
14 
15 This program computes the alignment (assuming a conforming ISO C compiler).
16 
17 #include "jni_system_specific.h"
18 
19 
20 union value
21 {
22   void *p;
23   _svmt_u8 u8;
24   _svmt_s8 s8;
25   _svmt_u16 u16;
26   _svmt_s16 s16;
27   _svmt_u32 u32;
28   _svmt_s32 s32;
29   _svmt_u64 u64;
30   _svmt_s64 s64;
31   _svmt_f32 f32;
32   _svmt_d64 d64;
33 };
34 
35 
36 struct align
37 {
38   char c;
39   union value v;
40 };
41 
42 int main (int argc, char *argv[])
43 {
44   struct align a;
45 
46   printf ("alignment = %u\n", (unsigned int) (((char *) &a.v) - ((char *) &a)));
47 
48   return 0;
49 }
50 
51 */
52 
53 #if (( \
54        defined (__sparc__) || defined (__ia64__) || defined (__alpha__) \
55     || defined (__i386__) || defined (__powerpc__) || defined (__s390__) \
56     || defined (__hppa__) || defined (__arm__) || defined (__m68k__) \
57     || defined (__mc68000__) || defined (__mips__) || defined (__mipsel__) \
58     || defined (__x86_64__) || defined (_POWER)       \
59      ) && defined (__GNUC__))
60 
61 /* "inline" is now an official keyword since the latest C standard (1999).
62    So, it is a reasonable assuption to expect a target compiler to
63    support it.  If your compiler doesn't, then you should define
64    "inline" as nothing.
65 */
66 #define inline __inline__
67 
68 #define SVM_UNUSED __attribute__((unused))
69 #define SVM_CAST_EXTENSION __extension__
70 
71 /* _svmt_word is an unsigned integral type such that:
72  *
73  *   sizeof (void *) == sizeof(_svmt_word).
74  *
75  * I guess that on most architectures, an "unsigned int" is a "word".
76  */
77 
78 #define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
79 
80 #if defined (__alpha__)
81 
82 typedef _svmt_u64 _svmt_word;
83 typedef _svmt_d64 _svmt_float_word;
84 
85 #define SVM_WORD_SIZE 8		/* size in bytes */
86 #define SVM_WORD_BIT_COUNT 64	/* size in bits */
87 
88 /* see comments at the head of this file */
89 #define SVM_ALIGNMENT 8
90 #define SVM_ALIGNMENT_POWER 3	/* 2 ^^ SVM_ALIGNMENT_POWER == SVM_ALIGNMENT */
91 #define SVM_PAGE_SIZE 8192
92 
93 #include <inlined_alpha.h>
94 
95 #elif defined (__arm__)
96 
97 typedef _svmt_u32 _svmt_word;
98 typedef _svmt_f32 _svmt_float_word;
99 
100 #define SVM_WORD_SIZE 4		/* size in bytes */
101 #define SVM_WORD_BIT_COUNT 32	/* size in bits */
102 
103 /* see comments at the head of this file */
104 #define SVM_ALIGNMENT 4
105 #define SVM_ALIGNMENT_POWER 2	/* 2 ^^ SVM_ALIGNMENT_POWER == SVM_ALIGNMENT */
106 #define SVM_PAGE_SIZE 4096
107 
108 #include <inlined_arm.h>
109 
110 #elif defined (__hppa__)
111 
112 typedef _svmt_u32 _svmt_word;
113 typedef _svmt_f32 _svmt_float_word;
114 
115 #define SVM_WORD_SIZE 4		/* size in bytes */
116 #define SVM_WORD_BIT_COUNT 32	/* size in bits */
117 
118 /* see comments at the head of this file */
119 #define SVM_ALIGNMENT 8
120 #define SVM_ALIGNMENT_POWER 3	/* 2 ^^ SVM_ALIGNMENT_POWER == SVM_ALIGNMENT */
121 #define SVM_PAGE_SIZE 4096
122 
123 #include <inlined_hppa.h>
124 
125 #elif defined (__i386__)
126 
127 typedef _svmt_u32 _svmt_word;
128 typedef _svmt_f32 _svmt_float_word;
129 
130 #define SVM_WORD_SIZE 4		/* size in bytes */
131 #define SVM_WORD_BIT_COUNT 32	/* size in bits */
132 
133 /* see comments at the head of this file */
134 #define SVM_ALIGNMENT 4
135 #define SVM_ALIGNMENT_POWER 2	/* 2 ^^ SVM_ALIGNMENT_POWER == SVM_ALIGNMENT */
136 #define SVM_PAGE_SIZE 4096
137 
138 #if   (GCC_VERSION >= 2095) && (GCC_VERSION <3000)
139 #include <inlined_i386-gcc-2.95.h>
140 #else
141 #include <inlined_i386-gcc-3.3.h>
142 #endif /* (GCC_VERSION >= 2095) && (GCC_VERSION <3000) */
143 
144 #elif defined (__ia64__)
145 
146 typedef _svmt_u64 _svmt_word;
147 typedef _svmt_d64 _svmt_float_word;
148 
149 #define SVM_WORD_SIZE 8		/* size in bytes */
150 #define SVM_WORD_BIT_COUNT 64	/* size in bits */
151 
152 /* see comments at the head of this file */
153 #define SVM_ALIGNMENT 8
154 #define SVM_ALIGNMENT_POWER 3	/* 2 ^^ SVM_ALIGNMENT_POWER == SVM_ALIGNMENT */
155 #define SVM_PAGE_SIZE 16384
156 
157 #include <inlined_ia64.h>
158 
159 
160 #elif defined (__m68k__) || defined (__mc68000__)
161 
162 typedef _svmt_u32 _svmt_word;
163 typedef _svmt_f32 _svmt_float_word;
164 
165 #define SVM_WORD_SIZE 4		/* size in bytes */
166 #define SVM_WORD_BIT_COUNT 32	/* size in bits */
167 
168 /* see comments at the head of this file */
169 #define SVM_ALIGNMENT 2
170 #define SVM_ALIGNMENT_POWER 1	/* 2 ^^ SVM_ALIGNMENT_POWER == SVM_ALIGNMENT */
171 #define SVM_PAGE_SIZE 4096
172 
173 #include <inlined_m68k.h>
174 
175 #elif (defined (__mips__) || defined (__mipsel__))
176 
177 typedef _svmt_u32 _svmt_word;
178 typedef _svmt_f32 _svmt_float_word;
179 
180 #define SVM_WORD_SIZE 4		/* size in bytes */
181 #define SVM_WORD_BIT_COUNT 32	/* size in bits */
182 
183 /* see comments at the head of this file */
184 #define SVM_ALIGNMENT 8
185 #define SVM_ALIGNMENT_POWER 3	/* 2 ^^ SVM_ALIGNMENT_POWER == SVM_ALIGNMENT */
186 #define SVM_PAGE_SIZE 4096
187 
188 #elif defined (__powerpc__)
189 
190 typedef _svmt_u32 _svmt_word;
191 typedef _svmt_f32 _svmt_float_word;
192 
193 #define SVM_WORD_SIZE 4		/* size in bytes */
194 #define SVM_WORD_BIT_COUNT 32	/* size in bits */
195 
196 /* see comments at the head of this file */
197 #define SVM_ALIGNMENT 8
198 #define SVM_ALIGNMENT_POWER 3	/* 2 ^^ SVM_ALIGNMENT_POWER == SVM_ALIGNMENT */
199 #define SVM_PAGE_SIZE 4096
200 
201 #include <inlined_powerpc-no-reorder.h>
202 
203 #elif defined (__s390__)
204 /* yes, that's strange, but s390 is 32bit - apparently at least in the userspace */
205 typedef _svmt_u32 _svmt_word;
206 typedef _svmt_f32 _svmt_float_word;
207 
208 #define SVM_WORD_SIZE 4		/* size in bytes */
209 #define SVM_WORD_BIT_COUNT 32	/* size in bits */
210 
211 /* see comments at the head of this file */
212 #define SVM_ALIGNMENT 8
213 #define SVM_ALIGNMENT_POWER 3	/* 2 ^^ SVM_ALIGNMENT_POWER == SVM_ALIGNMENT */
214 #define SVM_PAGE_SIZE 4096
215 
216 #include <inlined_s390.h>
217 
218 #elif defined (__sparc__)
219 
220 typedef _svmt_u32 _svmt_word;
221 typedef _svmt_f32 _svmt_float_word;
222 
223 #define SVM_WORD_SIZE 4		/* size in bytes */
224 #define SVM_WORD_BIT_COUNT 32	/* size in bits */
225 
226 /* see comments at the head of this file */
227 /* http://www.acm.org/crossroads/xrds1-3/free.html says you can have either
228  * processor with 4k page size (old sparc) or 8k page size (ultra sparc).
229  * We should probably choose the bigger value - shouldn't we? (GBP) */
230 #define SVM_ALIGNMENT 8
231 #define SVM_ALIGNMENT_POWER 3	/* 2 ^^ SVM_ALIGNMENT_POWER == SVM_ALIGNMENT */
232 #define SVM_PAGE_SIZE 8192
233 
234 #include <inlined_sparc.h>
235 
236 #elif defined (__x86_64__)
237 
238 typedef _svmt_u64 _svmt_word;
239 typedef _svmt_d64 _svmt_float_word;
240 
241 #define SVM_WORD_SIZE 8		/* size in bytes */
242 #define SVM_WORD_BIT_COUNT 64	/* size in bits */
243 
244 /* see comments at the head of this file */
245 #define SVM_ALIGNMENT 8
246 #define SVM_ALIGNMENT_POWER 3	/* 2 ^^ SVM_ALIGNMENT_POWER == SVM_ALIGNMENT */
247 #define SVM_PAGE_SIZE 4096
248 
249 #include <inlined_x86_64.h>
250 
251 #else
252 #error "unknown system"
253 #endif
254 
255 
256 /* FFI specific types */
257 #define ffi_type_float32 ffi_type_float
258 #define ffi_type_float64 ffi_type_double
259 
260 /* Does ">>" behaves as a "signed" or "unsigned" shift when
261    applied to a signed argument?  I personally think that the C
262    standard should have specified this, unstead of leaving the choice
263    in the hands of each compiler designer.  But what can I do? */
264 
265 #define SVM_SIGNED_SHR 1	/* uncomment when: (-1 >> 1) == -1 */
266 
267 #ifdef COMMENT
268 #define SVM_UNSIGNED_SHR 1	/* uncomment when: (-1 >> 1) != -1 */
269 #endif /* COMMENT */
270 
271 /* Max integer that can be stored in a size_t variable */
272 #ifndef SIZE_T_MAX
273 #define SIZE_T_MAX UINT_MAX
274 #endif /* !SIZE_T_MAX */
275 
276 #if defined (_SABLEVM_NO_GC)
277 
278 #define SVM_HEAP_DEFAULT_SIZE 67108864
279 
280 #elif defined (_SABLEVM_COPY_GC) || (_SABLEVM_GENCOPY_GC)
281 
282 #define SVM_HEAP_DEFAULT_MIN_SIZE 16777216
283 #define SVM_HEAP_DEFAULT_MAX_SIZE 0
284 #define SVM_HEAP_DEFAULT_ALLOCATION_INCREMENT 1048576
285 
286 #if defined (_SABLEVM_GENCOPY_GC)
287 
288 #define SVM_HEAP_DEFAULT_NURSERY_SIZE (1<<20)
289 #define SVM_HEAP_DEFAULT_LARGE_OBJECT_SIZE (1<<11)
290 #define SVM_HEAP_REMSET_BUCKET_NUM (1<<5)
291 #define SVM_HEAP_REMSET_BUCKET_SIZE (1<<5)
292 
293 #endif /* defined (_SABLEVM_GENCOPY_GC) */
294 
295 #endif /* defined (_SABLEVM_NO_GC) */
296 
297 #define SVM_STACK_DEFAULT_MIN_SIZE 65536
298 #define SVM_STACK_DEFAULT_MAX_SIZE 0
299 #define SVM_STACK_DEFAULT_ALLOCATION_INCREMENT 65536
300 
301 #define SVM_CLASS_LOADER_DEFAULT_MIN_SIZE 1048576
302 #define SVM_CLASS_LOADER_DEFAULT_MAX_SIZE 0
303 #define SVM_CLASS_LOADER_DEFAULT_ALLOCATION_INCREMENT 1048576
304 
305 #define SVM_THINLOCK_MAX_RECURSIVE_COUNT 0x01f
306 #define SVM_MAX_FATLOCK_ID 0x07fff
307 #define SVM_MAX_THREAD_ID 0x03ff
308 
309 #define SVM_HASH_NONE 0
310 #define SVM_HASH_NOT_MOVED 1
311 #define SVM_HASH_MOVED 2
312 
313 #if defined (_SABLEVM_BIDIRECTIONAL_OBJECT_LAYOUT)
314 
315 #define SVM_LOCKWORD_START_OVERFLOW 0x03f
316 #define SVM_LOCKWORD_END_OVERFLOW 0x03f
317 
318 #define SVM_LOCKWORD_START_OVERFLOW_OFFSET (SVM_LOCKWORD_START_OVERFLOW * SVM_ALIGNMENT)
319 #define SVM_LOCKWORD_END_OVERFLOW_OFFSET (SVM_LOCKWORD_END_OVERFLOW * SVM_ALIGNMENT + \
320                                           _svmf_aligned_size_t (sizeof (_svmt_object_instance)))
321 
322 #endif
323 
324 #else
325 
326 #error "unknown system"
327 
328 #endif
329 
330 #endif /* not SVM_SYSTEM_H */
331