annotate src/share/vm/utilities/globalDefinitions_visCPP.hpp @ 4834:74d14a44c398

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