src/share/vm/utilities/globalDefinitions_visCPP.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6198
55fb97c4c58d
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_UTILITIES_GLOBALDEFINITIONS_VISCPP_HPP
aoqi@0 26 #define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_VISCPP_HPP
aoqi@0 27
aoqi@0 28 #include "prims/jni.h"
aoqi@0 29
aoqi@0 30 // This file holds compiler-dependent includes,
aoqi@0 31 // globally used constants & types, class (forward)
aoqi@0 32 // declarations and a few frequently used utility functions.
aoqi@0 33
aoqi@0 34 # include <ctype.h>
aoqi@0 35 # include <string.h>
aoqi@0 36 # include <stdarg.h>
aoqi@0 37 # include <stdlib.h>
aoqi@0 38 # include <stddef.h>// for offsetof
aoqi@0 39 # include <io.h> // for stream.cpp
aoqi@0 40 # include <float.h> // for _isnan
aoqi@0 41 # include <stdio.h> // for va_list
aoqi@0 42 # include <time.h>
aoqi@0 43 # include <fcntl.h>
aoqi@0 44 # include <limits.h>
aoqi@0 45 // Need this on windows to get the math constants (e.g., M_PI).
aoqi@0 46 #define _USE_MATH_DEFINES
aoqi@0 47 # include <math.h>
aoqi@0 48
aoqi@0 49 // 4810578: varargs unsafe on 32-bit integer/64-bit pointer architectures
aoqi@0 50 // When __cplusplus is defined, NULL is defined as 0 (32-bit constant) in
aoqi@0 51 // system header files. On 32-bit architectures, there is no problem.
aoqi@0 52 // On 64-bit architectures, defining NULL as a 32-bit constant can cause
aoqi@0 53 // problems with varargs functions: C++ integral promotion rules say for
aoqi@0 54 // varargs, we pass the argument 0 as an int. So, if NULL was passed to a
aoqi@0 55 // varargs function it will remain 32-bits. Depending on the calling
aoqi@0 56 // convention of the machine, if the argument is passed on the stack then
aoqi@0 57 // only 32-bits of the "NULL" pointer may be initialized to zero. The
aoqi@0 58 // other 32-bits will be garbage. If the varargs function is expecting a
aoqi@0 59 // pointer when it extracts the argument, then we may have a problem.
aoqi@0 60 //
aoqi@0 61 // Solution: For 64-bit architectures, redefine NULL as 64-bit constant 0.
aoqi@0 62 #ifdef _LP64
aoqi@0 63 #undef NULL
aoqi@0 64 // 64-bit Windows uses a P64 data model (not LP64, although we define _LP64)
aoqi@0 65 // Since longs are 32-bit we cannot use 0L here. Use the Visual C++ specific
aoqi@0 66 // 64-bit integer-suffix (i64) instead.
aoqi@0 67 #define NULL 0i64
aoqi@0 68 #else
aoqi@0 69 #ifndef NULL
aoqi@0 70 #define NULL 0
aoqi@0 71 #endif
aoqi@0 72 #endif
aoqi@0 73
aoqi@0 74 // NULL vs NULL_WORD:
aoqi@0 75 // On Linux NULL is defined as a special type '__null'. Assigning __null to
aoqi@0 76 // integer variable will cause gcc warning. Use NULL_WORD in places where a
aoqi@0 77 // pointer is stored as integer value.
aoqi@0 78 #define NULL_WORD NULL
aoqi@0 79
aoqi@0 80 // Compiler-specific primitive types
aoqi@0 81 typedef unsigned __int8 uint8_t;
aoqi@0 82 typedef unsigned __int16 uint16_t;
aoqi@0 83 typedef unsigned __int32 uint32_t;
aoqi@0 84 typedef unsigned __int64 uint64_t;
aoqi@0 85
aoqi@0 86 #ifdef _WIN64
aoqi@0 87 typedef unsigned __int64 uintptr_t;
aoqi@0 88 #else
aoqi@0 89 typedef unsigned int uintptr_t;
aoqi@0 90 #endif
aoqi@0 91 typedef signed __int8 int8_t;
aoqi@0 92 typedef signed __int16 int16_t;
aoqi@0 93 typedef signed __int32 int32_t;
aoqi@0 94 typedef signed __int64 int64_t;
aoqi@0 95 #ifdef _WIN64
aoqi@0 96 typedef signed __int64 intptr_t;
aoqi@0 97 typedef signed __int64 ssize_t;
aoqi@0 98 #else
aoqi@0 99 typedef signed int intptr_t;
aoqi@0 100 typedef signed int ssize_t;
aoqi@0 101 #endif
aoqi@0 102
aoqi@0 103 #ifndef UINTPTR_MAX
aoqi@0 104 #ifdef _WIN64
aoqi@0 105 #define UINTPTR_MAX _UI64_MAX
aoqi@0 106 #else
aoqi@0 107 #define UINTPTR_MAX _UI32_MAX
aoqi@0 108 #endif
aoqi@0 109 #endif
aoqi@0 110
aoqi@0 111 //----------------------------------------------------------------------------------------------------
aoqi@0 112 // Additional Java basic types
aoqi@0 113
aoqi@0 114 typedef unsigned char jubyte;
aoqi@0 115 typedef unsigned short jushort;
aoqi@0 116 typedef unsigned int juint;
aoqi@0 117 typedef unsigned __int64 julong;
aoqi@0 118
aoqi@0 119 //----------------------------------------------------------------------------------------------------
aoqi@0 120 // Special (possibly not-portable) casts
aoqi@0 121 // Cast floats into same-size integers and vice-versa w/o changing bit-pattern
aoqi@0 122
aoqi@0 123 inline jint jint_cast (jfloat x) { return *(jint* )&x; }
aoqi@0 124 inline jlong jlong_cast (jdouble x) { return *(jlong* )&x; }
aoqi@0 125
aoqi@0 126 inline jfloat jfloat_cast (jint x) { return *(jfloat* )&x; }
aoqi@0 127 inline jdouble jdouble_cast(jlong x) { return *(jdouble*)&x; }
aoqi@0 128
aoqi@0 129
aoqi@0 130 //----------------------------------------------------------------------------------------------------
aoqi@0 131 // Non-standard stdlib-like stuff:
aoqi@0 132 inline int strcasecmp(const char *s1, const char *s2) { return _stricmp(s1,s2); }
aoqi@0 133 inline int strncasecmp(const char *s1, const char *s2, size_t n) {
aoqi@0 134 return _strnicmp(s1,s2,n);
aoqi@0 135 }
aoqi@0 136
aoqi@0 137
aoqi@0 138 //----------------------------------------------------------------------------------------------------
aoqi@0 139 // Debugging
aoqi@0 140
aoqi@0 141 #if _WIN64
aoqi@0 142 extern "C" void breakpoint();
aoqi@0 143 #define BREAKPOINT ::breakpoint()
aoqi@0 144 #else
aoqi@0 145 #define BREAKPOINT __asm { int 3 }
aoqi@0 146 #endif
aoqi@0 147
aoqi@0 148 //----------------------------------------------------------------------------------------------------
aoqi@0 149 // Checking for nanness
aoqi@0 150
aoqi@0 151 inline int g_isnan(jfloat f) { return _isnan(f); }
aoqi@0 152 inline int g_isnan(jdouble f) { return _isnan(f); }
aoqi@0 153
aoqi@0 154 //----------------------------------------------------------------------------------------------------
aoqi@0 155 // Checking for finiteness
aoqi@0 156
aoqi@0 157 inline int g_isfinite(jfloat f) { return _finite(f); }
aoqi@0 158 inline int g_isfinite(jdouble f) { return _finite(f); }
aoqi@0 159
aoqi@0 160 //----------------------------------------------------------------------------------------------------
aoqi@0 161 // Constant for jlong (specifying an long long constant is C++ compiler specific)
aoqi@0 162
aoqi@0 163 // Build a 64bit integer constant on with Visual C++
aoqi@0 164 #define CONST64(x) (x ## i64)
aoqi@0 165 #define UCONST64(x) ((uint64_t)CONST64(x))
aoqi@0 166
aoqi@0 167 const jlong min_jlong = CONST64(0x8000000000000000);
aoqi@0 168 const jlong max_jlong = CONST64(0x7fffffffffffffff);
aoqi@0 169
aoqi@0 170 //----------------------------------------------------------------------------------------------------
aoqi@0 171 // Miscellaneous
aoqi@0 172
aoqi@0 173 // Visual Studio 2005 deprecates POSIX names - use ISO C++ names instead
aoqi@0 174 #if _MSC_VER >= 1400
aoqi@0 175 #define open _open
aoqi@0 176 #define close _close
aoqi@0 177 #define read _read
aoqi@0 178 #define write _write
aoqi@0 179 #define lseek _lseek
aoqi@0 180 #define unlink _unlink
aoqi@0 181 #define strdup _strdup
aoqi@0 182 #endif
aoqi@0 183
aoqi@0 184 #pragma warning( disable : 4100 ) // unreferenced formal parameter
aoqi@0 185 #pragma warning( disable : 4127 ) // conditional expression is constant
aoqi@0 186 #pragma warning( disable : 4514 ) // unreferenced inline function has been removed
aoqi@0 187 #pragma warning( disable : 4244 ) // possible loss of data
aoqi@0 188 #pragma warning( disable : 4512 ) // assignment operator could not be generated
aoqi@0 189 #pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union (needed in windows.h)
aoqi@0 190 #pragma warning( disable : 4511 ) // copy constructor could not be generated
aoqi@0 191 #pragma warning( disable : 4291 ) // no matching operator delete found; memory will not be freed if initialization thows an exception
aoqi@0 192 #ifdef CHECK_UNHANDLED_OOPS
aoqi@0 193 #pragma warning( disable : 4521 ) // class has multiple copy ctors of a single type
aoqi@0 194 #pragma warning( disable : 4522 ) // class has multiple assignment operators of a single type
aoqi@0 195 #endif // CHECK_UNHANDLED_OOPS
aoqi@0 196 #if _MSC_VER >= 1400
aoqi@0 197 #pragma warning( disable : 4996 ) // unsafe string functions. Same as define _CRT_SECURE_NO_WARNINGS/_CRT_SECURE_NO_DEPRICATE
aoqi@0 198 #endif
aoqi@0 199
aoqi@0 200 inline int vsnprintf(char* buf, size_t count, const char* fmt, va_list argptr) {
aoqi@0 201 // If number of characters written == count, Windows doesn't write a
aoqi@0 202 // terminating NULL, so we do it ourselves.
aoqi@0 203 int ret = _vsnprintf(buf, count, fmt, argptr);
aoqi@0 204 if (count > 0) buf[count-1] = '\0';
aoqi@0 205 return ret;
aoqi@0 206 }
aoqi@0 207
aoqi@0 208 // Portability macros
aoqi@0 209 #define PRAGMA_INTERFACE
aoqi@0 210 #define PRAGMA_IMPLEMENTATION
aoqi@0 211 #define PRAGMA_IMPLEMENTATION_(arg)
aoqi@0 212 #define VALUE_OBJ_CLASS_SPEC : public _ValueObj
aoqi@0 213
aoqi@0 214 // Formatting.
aoqi@0 215 #define FORMAT64_MODIFIER "I64"
aoqi@0 216
aoqi@0 217 // Visual Studio doesn't provide inttypes.h so provide appropriate definitions here.
aoqi@0 218 // The 32 bits ones might need I32 but seem to work ok without it.
aoqi@0 219 #define PRId32 "d"
aoqi@0 220 #define PRIu32 "u"
aoqi@0 221 #define PRIx32 "x"
aoqi@0 222
aoqi@0 223 #define PRId64 "I64d"
aoqi@0 224 #define PRIu64 "I64u"
aoqi@0 225 #define PRIx64 "I64x"
aoqi@0 226
aoqi@0 227 #ifdef _LP64
aoqi@0 228 #define PRIdPTR "I64d"
aoqi@0 229 #define PRIuPTR "I64u"
aoqi@0 230 #define PRIxPTR "I64x"
aoqi@0 231 #else
aoqi@0 232 #define PRIdPTR "d"
aoqi@0 233 #define PRIuPTR "u"
aoqi@0 234 #define PRIxPTR "x"
aoqi@0 235 #endif
aoqi@0 236
aoqi@0 237 #define offset_of(klass,field) offsetof(klass,field)
aoqi@0 238
aoqi@0 239 #endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_VISCPP_HPP

mercurial