Mercurial > hg > truffle
comparison src/share/vm/utilities/globalDefinitions_visCPP.hpp @ 0:a61af66fc99e jdk7-b24
Initial load
author | duke |
---|---|
date | Sat, 01 Dec 2007 00:00:00 +0000 |
parents | |
children | c3a720eefe82 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a61af66fc99e |
---|---|
1 /* | |
2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. | |
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 <stdlib.h> | |
33 # include <stddef.h>// for offsetof | |
34 # include <io.h> // for stream.cpp | |
35 # include <float.h> // for _isnan | |
36 # include <stdio.h> // for va_list | |
37 # include <time.h> | |
38 # include <fcntl.h> | |
39 // Need this on windows to get the math constants (e.g., M_PI). | |
40 #define _USE_MATH_DEFINES | |
41 # include <math.h> | |
42 | |
43 // 4810578: varargs unsafe on 32-bit integer/64-bit pointer architectures | |
44 // When __cplusplus is defined, NULL is defined as 0 (32-bit constant) in | |
45 // system header files. On 32-bit architectures, there is no problem. | |
46 // On 64-bit architectures, defining NULL as a 32-bit constant can cause | |
47 // problems with varargs functions: C++ integral promotion rules say for | |
48 // varargs, we pass the argument 0 as an int. So, if NULL was passed to a | |
49 // varargs function it will remain 32-bits. Depending on the calling | |
50 // convention of the machine, if the argument is passed on the stack then | |
51 // only 32-bits of the "NULL" pointer may be initialized to zero. The | |
52 // other 32-bits will be garbage. If the varargs function is expecting a | |
53 // pointer when it extracts the argument, then we may have a problem. | |
54 // | |
55 // Solution: For 64-bit architectures, redefine NULL as 64-bit constant 0. | |
56 #ifdef _LP64 | |
57 #undef NULL | |
58 // 64-bit Windows uses a P64 data model (not LP64, although we define _LP64) | |
59 // Since longs are 32-bit we cannot use 0L here. Use the Visual C++ specific | |
60 // 64-bit integer-suffix (i64) instead. | |
61 #define NULL 0i64 | |
62 #else | |
63 #ifndef NULL | |
64 #define NULL 0 | |
65 #endif | |
66 #endif | |
67 | |
68 // NULL vs NULL_WORD: | |
69 // On Linux NULL is defined as a special type '__null'. Assigning __null to | |
70 // integer variable will cause gcc warning. Use NULL_WORD in places where a | |
71 // pointer is stored as integer value. | |
72 #define NULL_WORD NULL | |
73 | |
74 // Compiler-specific primitive types | |
75 typedef unsigned __int8 uint8_t; | |
76 typedef unsigned __int16 uint16_t; | |
77 typedef unsigned __int32 uint32_t; | |
78 typedef unsigned __int64 uint64_t; | |
79 | |
80 #ifdef _WIN64 | |
81 typedef unsigned __int64 uintptr_t; | |
82 #else | |
83 typedef unsigned int uintptr_t; | |
84 #endif | |
85 typedef signed __int8 int8_t; | |
86 typedef signed __int16 int16_t; | |
87 typedef signed __int32 int32_t; | |
88 typedef signed __int64 int64_t; | |
89 #ifdef _WIN64 | |
90 typedef signed __int64 intptr_t; | |
91 typedef signed __int64 ssize_t; | |
92 #else | |
93 typedef signed int intptr_t; | |
94 typedef signed int ssize_t; | |
95 #endif | |
96 | |
97 //---------------------------------------------------------------------------------------------------- | |
98 // Additional Java basic types | |
99 | |
100 typedef unsigned char jubyte; | |
101 typedef unsigned short jushort; | |
102 typedef unsigned int juint; | |
103 typedef unsigned __int64 julong; | |
104 | |
105 //---------------------------------------------------------------------------------------------------- | |
106 // Special (possibly not-portable) casts | |
107 // Cast floats into same-size integers and vice-versa w/o changing bit-pattern | |
108 | |
109 inline jint jint_cast (jfloat x) { return *(jint* )&x; } | |
110 inline jlong jlong_cast (jdouble x) { return *(jlong* )&x; } | |
111 | |
112 inline jfloat jfloat_cast (jint x) { return *(jfloat* )&x; } | |
113 inline jdouble jdouble_cast(jlong x) { return *(jdouble*)&x; } | |
114 | |
115 | |
116 //---------------------------------------------------------------------------------------------------- | |
117 // Non-standard stdlib-like stuff: | |
118 inline int strcasecmp(const char *s1, const char *s2) { return _stricmp(s1,s2); } | |
119 | |
120 | |
121 //---------------------------------------------------------------------------------------------------- | |
122 // Debugging | |
123 | |
124 #if _WIN64 | |
125 extern "C" void breakpoint(); | |
126 #define BREAKPOINT ::breakpoint() | |
127 #else | |
128 #define BREAKPOINT __asm { int 3 } | |
129 #endif | |
130 | |
131 //---------------------------------------------------------------------------------------------------- | |
132 // Checking for nanness | |
133 | |
134 inline int g_isnan(jfloat f) { return _isnan(f); } | |
135 inline int g_isnan(jdouble f) { return _isnan(f); } | |
136 | |
137 //---------------------------------------------------------------------------------------------------- | |
138 // Checking for finiteness | |
139 | |
140 inline int g_isfinite(jfloat f) { return _finite(f); } | |
141 inline int g_isfinite(jdouble f) { return _finite(f); } | |
142 | |
143 //---------------------------------------------------------------------------------------------------- | |
144 // Constant for jlong (specifying an long long constant is C++ compiler specific) | |
145 | |
146 // Build a 64bit integer constant on with Visual C++ | |
147 #define CONST64(x) (x ## i64) | |
148 #define UCONST64(x) ((uint64_t)CONST64(x)) | |
149 | |
150 const jlong min_jlong = CONST64(0x8000000000000000); | |
151 const jlong max_jlong = CONST64(0x7fffffffffffffff); | |
152 | |
153 //---------------------------------------------------------------------------------------------------- | |
154 // Miscellaneous | |
155 | |
156 inline int vsnprintf(char* buf, size_t count, const char* fmt, va_list argptr) { | |
157 // If number of characters written == count, Windows doesn't write a | |
158 // terminating NULL, so we do it ourselves. | |
159 int ret = _vsnprintf(buf, count, fmt, argptr); | |
160 if (count > 0) buf[count-1] = '\0'; | |
161 return ret; | |
162 } | |
163 | |
164 // Visual Studio 2005 deprecates POSIX names - use ISO C++ names instead | |
165 #if _MSC_VER >= 1400 && !defined(_WIN64) | |
166 #define open _open | |
167 #define close _close | |
168 #define read _read | |
169 #define write _write | |
170 #define lseek _lseek | |
171 #define unlink _unlink | |
172 #define strdup _strdup | |
173 #endif | |
174 | |
175 #pragma warning( disable : 4100 ) // unreferenced formal parameter | |
176 #pragma warning( disable : 4127 ) // conditional expression is constant | |
177 #pragma warning( disable : 4514 ) // unreferenced inline function has been removed | |
178 #pragma warning( disable : 4244 ) // possible loss of data | |
179 #pragma warning( disable : 4512 ) // assignment operator could not be generated | |
180 #pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union (needed in windows.h) | |
181 #pragma warning( disable : 4511 ) // copy constructor could not be generated | |
182 #pragma warning( disable : 4291 ) // no matching operator delete found; memory will not be freed if initialization thows an exception | |
183 | |
184 // Portability macros | |
185 #define PRAGMA_INTERFACE | |
186 #define PRAGMA_IMPLEMENTATION | |
187 #define PRAGMA_IMPLEMENTATION_(arg) | |
188 #define VALUE_OBJ_CLASS_SPEC : public _ValueObj | |
189 | |
190 // Formatting. | |
191 #define FORMAT64_MODIFIER "I64" | |
192 | |
193 #define offset_of(klass,field) offsetof(klass,field) |