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