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