duke@435: /* mikael@6198: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_UTILITIES_GLOBALDEFINITIONS_VISCPP_HPP stefank@2314: #define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_VISCPP_HPP stefank@2314: stefank@2314: #include "prims/jni.h" stefank@2314: duke@435: // This file holds compiler-dependent includes, duke@435: // globally used constants & types, class (forward) duke@435: // declarations and a few frequently used utility functions. duke@435: duke@435: # include duke@435: # include duke@435: # include duke@435: # include duke@435: # include // for offsetof duke@435: # include // for stream.cpp duke@435: # include // for _isnan duke@435: # include // for va_list duke@435: # include duke@435: # include kamg@2589: # include duke@435: // Need this on windows to get the math constants (e.g., M_PI). duke@435: #define _USE_MATH_DEFINES duke@435: # include duke@435: duke@435: // 4810578: varargs unsafe on 32-bit integer/64-bit pointer architectures duke@435: // When __cplusplus is defined, NULL is defined as 0 (32-bit constant) in duke@435: // system header files. On 32-bit architectures, there is no problem. duke@435: // On 64-bit architectures, defining NULL as a 32-bit constant can cause duke@435: // problems with varargs functions: C++ integral promotion rules say for duke@435: // varargs, we pass the argument 0 as an int. So, if NULL was passed to a duke@435: // varargs function it will remain 32-bits. Depending on the calling duke@435: // convention of the machine, if the argument is passed on the stack then duke@435: // only 32-bits of the "NULL" pointer may be initialized to zero. The duke@435: // other 32-bits will be garbage. If the varargs function is expecting a duke@435: // pointer when it extracts the argument, then we may have a problem. duke@435: // duke@435: // Solution: For 64-bit architectures, redefine NULL as 64-bit constant 0. duke@435: #ifdef _LP64 duke@435: #undef NULL duke@435: // 64-bit Windows uses a P64 data model (not LP64, although we define _LP64) duke@435: // Since longs are 32-bit we cannot use 0L here. Use the Visual C++ specific duke@435: // 64-bit integer-suffix (i64) instead. duke@435: #define NULL 0i64 duke@435: #else duke@435: #ifndef NULL duke@435: #define NULL 0 duke@435: #endif duke@435: #endif duke@435: duke@435: // NULL vs NULL_WORD: duke@435: // On Linux NULL is defined as a special type '__null'. Assigning __null to duke@435: // integer variable will cause gcc warning. Use NULL_WORD in places where a duke@435: // pointer is stored as integer value. duke@435: #define NULL_WORD NULL duke@435: duke@435: // Compiler-specific primitive types duke@435: typedef unsigned __int8 uint8_t; duke@435: typedef unsigned __int16 uint16_t; duke@435: typedef unsigned __int32 uint32_t; duke@435: typedef unsigned __int64 uint64_t; duke@435: duke@435: #ifdef _WIN64 duke@435: typedef unsigned __int64 uintptr_t; duke@435: #else duke@435: typedef unsigned int uintptr_t; duke@435: #endif duke@435: typedef signed __int8 int8_t; duke@435: typedef signed __int16 int16_t; duke@435: typedef signed __int32 int32_t; duke@435: typedef signed __int64 int64_t; duke@435: #ifdef _WIN64 duke@435: typedef signed __int64 intptr_t; duke@435: typedef signed __int64 ssize_t; duke@435: #else duke@435: typedef signed int intptr_t; duke@435: typedef signed int ssize_t; duke@435: #endif duke@435: kamg@2589: #ifndef UINTPTR_MAX kamg@2589: #ifdef _WIN64 kamg@2589: #define UINTPTR_MAX _UI64_MAX kamg@2589: #else kamg@2589: #define UINTPTR_MAX _UI32_MAX kamg@2589: #endif kamg@2589: #endif kamg@2589: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Additional Java basic types duke@435: duke@435: typedef unsigned char jubyte; duke@435: typedef unsigned short jushort; duke@435: typedef unsigned int juint; duke@435: typedef unsigned __int64 julong; duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Non-standard stdlib-like stuff: duke@435: inline int strcasecmp(const char *s1, const char *s2) { return _stricmp(s1,s2); } fparain@3476: inline int strncasecmp(const char *s1, const char *s2, size_t n) { fparain@3476: return _strnicmp(s1,s2,n); fparain@3476: } duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Debugging duke@435: duke@435: #if _WIN64 duke@435: extern "C" void breakpoint(); duke@435: #define BREAKPOINT ::breakpoint() duke@435: #else duke@435: #define BREAKPOINT __asm { int 3 } duke@435: #endif duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Checking for nanness duke@435: duke@435: inline int g_isnan(jfloat f) { return _isnan(f); } duke@435: inline int g_isnan(jdouble f) { return _isnan(f); } duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Checking for finiteness duke@435: duke@435: inline int g_isfinite(jfloat f) { return _finite(f); } duke@435: inline int g_isfinite(jdouble f) { return _finite(f); } duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Constant for jlong (specifying an long long constant is C++ compiler specific) duke@435: duke@435: // Build a 64bit integer constant on with Visual C++ duke@435: #define CONST64(x) (x ## i64) duke@435: #define UCONST64(x) ((uint64_t)CONST64(x)) duke@435: duke@435: const jlong min_jlong = CONST64(0x8000000000000000); duke@435: const jlong max_jlong = CONST64(0x7fffffffffffffff); duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Miscellaneous duke@435: duke@435: // Visual Studio 2005 deprecates POSIX names - use ISO C++ names instead kvn@1080: #if _MSC_VER >= 1400 duke@435: #define open _open duke@435: #define close _close duke@435: #define read _read duke@435: #define write _write duke@435: #define lseek _lseek duke@435: #define unlink _unlink duke@435: #define strdup _strdup duke@435: #endif duke@435: duke@435: #pragma warning( disable : 4100 ) // unreferenced formal parameter duke@435: #pragma warning( disable : 4127 ) // conditional expression is constant duke@435: #pragma warning( disable : 4514 ) // unreferenced inline function has been removed duke@435: #pragma warning( disable : 4244 ) // possible loss of data duke@435: #pragma warning( disable : 4512 ) // assignment operator could not be generated duke@435: #pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union (needed in windows.h) duke@435: #pragma warning( disable : 4511 ) // copy constructor could not be generated duke@435: #pragma warning( disable : 4291 ) // no matching operator delete found; memory will not be freed if initialization thows an exception hseigel@5784: #ifdef CHECK_UNHANDLED_OOPS hseigel@5784: #pragma warning( disable : 4521 ) // class has multiple copy ctors of a single type hseigel@5784: #pragma warning( disable : 4522 ) // class has multiple assignment operators of a single type hseigel@5784: #endif // CHECK_UNHANDLED_OOPS ikrylov@1094: #if _MSC_VER >= 1400 ikrylov@1094: #pragma warning( disable : 4996 ) // unsafe string functions. Same as define _CRT_SECURE_NO_WARNINGS/_CRT_SECURE_NO_DEPRICATE ikrylov@1094: #endif ikrylov@1094: ikrylov@1094: inline int vsnprintf(char* buf, size_t count, const char* fmt, va_list argptr) { ikrylov@1094: // If number of characters written == count, Windows doesn't write a ikrylov@1094: // terminating NULL, so we do it ourselves. ikrylov@1094: int ret = _vsnprintf(buf, count, fmt, argptr); ikrylov@1094: if (count > 0) buf[count-1] = '\0'; ikrylov@1094: return ret; ikrylov@1094: } duke@435: duke@435: // Portability macros duke@435: #define PRAGMA_INTERFACE duke@435: #define PRAGMA_IMPLEMENTATION duke@435: #define PRAGMA_IMPLEMENTATION_(arg) duke@435: #define VALUE_OBJ_CLASS_SPEC : public _ValueObj duke@435: duke@435: // Formatting. duke@435: #define FORMAT64_MODIFIER "I64" duke@435: never@3156: // Visual Studio doesn't provide inttypes.h so provide appropriate definitions here. never@3156: // The 32 bits ones might need I32 but seem to work ok without it. never@3156: #define PRId32 "d" never@3156: #define PRIu32 "u" never@3156: #define PRIx32 "x" never@3156: never@3156: #define PRId64 "I64d" never@3156: #define PRIu64 "I64u" never@3156: #define PRIx64 "I64x" never@3156: dholmes@3830: #ifdef _LP64 dholmes@3830: #define PRIdPTR "I64d" dholmes@3830: #define PRIuPTR "I64u" dholmes@3830: #define PRIxPTR "I64x" dholmes@3830: #else never@3156: #define PRIdPTR "d" never@3156: #define PRIuPTR "u" never@3156: #define PRIxPTR "x" dholmes@3830: #endif never@3156: duke@435: #define offset_of(klass,field) offsetof(klass,field) stefank@2314: stefank@2314: #endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_VISCPP_HPP