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