Mercurial > hg > truffle
annotate src/share/vm/utilities/globalDefinitions_gcc.hpp @ 1162:d749b1813f40
Merge
author | trims |
---|---|
date | Fri, 15 Jan 2010 14:25:44 -0800 |
parents | 0fbdb4381b99 |
children | c18cbe5936b8 |
rev | line source |
---|---|
0 | 1 /* |
579 | 2 * Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 // This file holds compiler-dependent includes, | |
26 // globally used constants & types, class (forward) | |
27 // declarations and a few frequently used utility functions. | |
28 | |
29 #include <ctype.h> | |
30 #include <string.h> | |
31 #include <stdarg.h> | |
32 #include <stddef.h> | |
33 #include <stdio.h> | |
34 #include <stdlib.h> | |
35 #include <wchar.h> | |
36 | |
37 #ifdef SOLARIS | |
38 #include <ieeefp.h> | |
39 #endif // SOLARIS | |
40 | |
41 #include <math.h> | |
42 #ifndef FP_PZERO | |
43 // Linux doesn't have positive/negative zero | |
44 #define FP_PZERO FP_ZERO | |
45 #endif | |
46 #if (!defined fpclass) && ((!defined SPARC) || (!defined SOLARIS)) | |
47 #define fpclass fpclassify | |
48 #endif | |
49 | |
50 #include <time.h> | |
51 #include <fcntl.h> | |
52 #include <dlfcn.h> | |
53 #include <pthread.h> | |
54 | |
55 #ifdef SOLARIS | |
56 #include <thread.h> | |
57 #endif // SOLARIS | |
58 | |
59 #include <limits.h> | |
60 #include <errno.h> | |
61 | |
62 #ifdef SOLARIS | |
63 #include <sys/trap.h> | |
64 #include <sys/regset.h> | |
65 #include <sys/procset.h> | |
66 #include <ucontext.h> | |
67 #include <setjmp.h> | |
68 #endif // SOLARIS | |
69 | |
70 # ifdef SOLARIS_MUTATOR_LIBTHREAD | |
71 # include <sys/procfs.h> | |
72 # endif | |
73 | |
74 #ifdef LINUX | |
75 #include <inttypes.h> | |
76 #include <signal.h> | |
77 #include <ucontext.h> | |
78 #include <sys/time.h> | |
79 #endif // LINUX | |
80 | |
81 // 4810578: varargs unsafe on 32-bit integer/64-bit pointer architectures | |
82 // When __cplusplus is defined, NULL is defined as 0 (32-bit constant) in | |
83 // system header files. On 32-bit architectures, there is no problem. | |
84 // On 64-bit architectures, defining NULL as a 32-bit constant can cause | |
85 // problems with varargs functions: C++ integral promotion rules say for | |
86 // varargs, we pass the argument 0 as an int. So, if NULL was passed to a | |
87 // varargs function it will remain 32-bits. Depending on the calling | |
88 // convention of the machine, if the argument is passed on the stack then | |
89 // only 32-bits of the "NULL" pointer may be initialized to zero. The | |
90 // other 32-bits will be garbage. If the varargs function is expecting a | |
91 // pointer when it extracts the argument, then we have a problem. | |
92 // | |
93 // Solution: For 64-bit architectures, redefine NULL as 64-bit constant 0. | |
94 // | |
95 // Note: this fix doesn't work well on Linux because NULL will be overwritten | |
96 // whenever a system header file is included. Linux handles NULL correctly | |
97 // through a special type '__null'. | |
98 #ifdef SOLARIS | |
99 #ifdef _LP64 | |
100 #undef NULL | |
101 #define NULL 0L | |
102 #else | |
103 #ifndef NULL | |
104 #define NULL 0 | |
105 #endif | |
106 #endif | |
107 #endif | |
108 | |
109 // NULL vs NULL_WORD: | |
110 // On Linux NULL is defined as a special type '__null'. Assigning __null to | |
111 // integer variable will cause gcc warning. Use NULL_WORD in places where a | |
112 // pointer is stored as integer value. On some platforms, sizeof(intptr_t) > | |
113 // sizeof(void*), so here we want something which is integer type, but has the | |
114 // same size as a pointer. | |
115 #ifdef LINUX | |
116 #ifdef _LP64 | |
117 #define NULL_WORD 0L | |
118 #else | |
512
db4caa99ef11
6787106: Hotspot 32 bit build fails on platforms having different definitions for intptr_t & int32_t
xlu
parents:
0
diff
changeset
|
119 // Cast 0 to intptr_t rather than int32_t since they are not the same type |
db4caa99ef11
6787106: Hotspot 32 bit build fails on platforms having different definitions for intptr_t & int32_t
xlu
parents:
0
diff
changeset
|
120 // on platforms such as Mac OS X. |
db4caa99ef11
6787106: Hotspot 32 bit build fails on platforms having different definitions for intptr_t & int32_t
xlu
parents:
0
diff
changeset
|
121 #define NULL_WORD ((intptr_t)0) |
0 | 122 #endif |
123 #else | |
124 #define NULL_WORD NULL | |
125 #endif | |
126 | |
127 #ifndef LINUX | |
128 // Compiler-specific primitive types | |
129 typedef unsigned short uint16_t; | |
130 #ifndef _UINT32_T | |
131 #define _UINT32_T | |
132 typedef unsigned int uint32_t; | |
133 #endif // _UINT32_T | |
134 | |
135 #if !defined(_SYS_INT_TYPES_H) | |
136 #ifndef _UINT64_T | |
137 #define _UINT64_T | |
138 typedef unsigned long long uint64_t; | |
139 #endif // _UINT64_T | |
140 // %%%% how to access definition of intptr_t portably in 5.5 onward? | |
141 typedef int intptr_t; | |
142 typedef unsigned int uintptr_t; | |
143 // If this gets an error, figure out a symbol XXX that implies the | |
144 // prior definition of intptr_t, and add "&& !defined(XXX)" above. | |
145 #endif // _SYS_INT_TYPES_H | |
146 | |
147 #endif // !LINUX | |
148 | |
149 // Additional Java basic types | |
150 | |
151 typedef uint8_t jubyte; | |
152 typedef uint16_t jushort; | |
153 typedef uint32_t juint; | |
154 typedef uint64_t julong; | |
155 | |
156 //---------------------------------------------------------------------------------------------------- | |
157 // Special (possibly not-portable) casts | |
158 // Cast floats into same-size integers and vice-versa w/o changing bit-pattern | |
159 // %%%%%% These seem like standard C++ to me--how about factoring them out? - Ungar | |
160 | |
161 inline jint jint_cast (jfloat x) { return *(jint* )&x; } | |
162 inline jlong jlong_cast (jdouble x) { return *(jlong* )&x; } | |
163 | |
164 inline jfloat jfloat_cast (jint x) { return *(jfloat* )&x; } | |
165 inline jdouble jdouble_cast(jlong x) { return *(jdouble*)&x; } | |
166 | |
167 //---------------------------------------------------------------------------------------------------- | |
168 // Constant for jlong (specifying an long long canstant is C++ compiler specific) | |
169 | |
170 // Build a 64bit integer constant | |
171 #define CONST64(x) (x ## LL) | |
172 #define UCONST64(x) (x ## ULL) | |
173 | |
174 const jlong min_jlong = CONST64(0x8000000000000000); | |
175 const jlong max_jlong = CONST64(0x7fffffffffffffff); | |
176 | |
177 | |
178 #ifdef SOLARIS | |
179 //---------------------------------------------------------------------------------------------------- | |
180 // ANSI C++ fixes | |
181 // NOTE:In the ANSI committee's continuing attempt to make each version | |
182 // of C++ incompatible with the previous version, you can no longer cast | |
183 // pointers to functions without specifying linkage unless you want to get | |
184 // warnings. | |
185 // | |
186 // This also means that pointers to functions can no longer be "hidden" | |
187 // in opaque types like void * because at the invokation point warnings | |
188 // will be generated. While this makes perfect sense from a type safety | |
189 // point of view it causes a lot of warnings on old code using C header | |
190 // files. Here are some typedefs to make the job of silencing warnings | |
191 // a bit easier. | |
192 // | |
193 // The final kick in the teeth is that you can only have extern "C" linkage | |
194 // specified at file scope. So these typedefs are here rather than in the | |
195 // .hpp for the class (os:Solaris usually) that needs them. | |
196 | |
197 extern "C" { | |
198 typedef int (*int_fnP_thread_t_iP_uP_stack_tP_gregset_t)(thread_t, int*, unsigned *, stack_t*, gregset_t); | |
199 typedef int (*int_fnP_thread_t_i_gregset_t)(thread_t, int, gregset_t); | |
200 typedef int (*int_fnP_thread_t_i)(thread_t, int); | |
201 typedef int (*int_fnP_thread_t)(thread_t); | |
202 | |
203 typedef int (*int_fnP_cond_tP_mutex_tP_timestruc_tP)(cond_t *cv, mutex_t *mx, timestruc_t *abst); | |
204 typedef int (*int_fnP_cond_tP_mutex_tP)(cond_t *cv, mutex_t *mx); | |
205 | |
206 // typedef for missing API in libc | |
207 typedef int (*int_fnP_mutex_tP_i_vP)(mutex_t *, int, void *); | |
208 typedef int (*int_fnP_mutex_tP)(mutex_t *); | |
209 typedef int (*int_fnP_cond_tP_i_vP)(cond_t *cv, int scope, void *arg); | |
210 typedef int (*int_fnP_cond_tP)(cond_t *cv); | |
211 }; | |
212 #endif // SOLARIS | |
213 | |
214 //---------------------------------------------------------------------------------------------------- | |
215 // Debugging | |
216 | |
217 #define DEBUG_EXCEPTION ::abort(); | |
218 | |
219 extern "C" void breakpoint(); | |
220 #define BREAKPOINT ::breakpoint() | |
221 | |
222 // checking for nanness | |
223 #ifdef SOLARIS | |
224 #ifdef SPARC | |
225 inline int g_isnan(float f) { return isnanf(f); } | |
226 #else | |
227 // isnanf() broken on Intel Solaris use isnand() | |
228 inline int g_isnan(float f) { return isnand(f); } | |
229 #endif | |
230 inline int g_isnan(double f) { return isnand(f); } | |
231 #elif LINUX | |
232 inline int g_isnan(float f) { return isnanf(f); } | |
233 inline int g_isnan(double f) { return isnan(f); } | |
234 #else | |
235 #error "missing platform-specific definition here" | |
236 #endif | |
237 | |
238 // Checking for finiteness | |
239 | |
240 inline int g_isfinite(jfloat f) { return finite(f); } | |
241 inline int g_isfinite(jdouble f) { return finite(f); } | |
242 | |
243 | |
244 // Wide characters | |
245 | |
246 inline int wcslen(const jchar* x) { return wcslen((const wchar_t*)x); } | |
247 | |
248 | |
249 // Portability macros | |
250 #define PRAGMA_INTERFACE #pragma interface | |
251 #define PRAGMA_IMPLEMENTATION #pragma implementation | |
252 #define VALUE_OBJ_CLASS_SPEC | |
253 | |
254 #if (__GNUC__ == 2) && (__GNUC_MINOR__ < 95) | |
255 #define TEMPLATE_TABLE_BUG | |
256 #endif | |
257 #if (__GNUC__ == 2) && (__GNUC_MINOR__ >= 96) | |
258 #define CONST_SDM_BUG | |
259 #endif | |
260 | |
261 // Formatting. | |
262 #ifdef _LP64 | |
263 #define FORMAT64_MODIFIER "l" | |
264 #else // !_LP64 | |
265 #define FORMAT64_MODIFIER "ll" | |
266 #endif // _LP64 | |
267 | |
268 // HACK: gcc warns about applying offsetof() to non-POD object or calculating | |
269 // offset directly when base address is NULL. Use 16 to get around the | |
270 // warning. gcc-3.4 has an option -Wno-invalid-offsetof to suppress | |
271 // this warning. | |
272 #define offset_of(klass,field) (size_t)((intx)&(((klass*)16)->field) - 16) | |
273 | |
274 #ifdef offsetof | |
275 # undef offsetof | |
276 #endif | |
277 #define offsetof(klass,field) offset_of(klass,field) |