Wed, 03 Jul 2019 20:42:37 +0800
Merge
aoqi@0 | 1 | /* |
dlong@7598 | 2 | * Copyright (c) 1998, 2015, 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_GCC_HPP |
aoqi@0 | 26 | #define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_GCC_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 <stddef.h> |
aoqi@0 | 38 | #include <stdio.h> |
aoqi@0 | 39 | #include <stdlib.h> |
aoqi@0 | 40 | #include <wchar.h> |
aoqi@0 | 41 | |
aoqi@0 | 42 | #ifdef SOLARIS |
aoqi@0 | 43 | #include <ieeefp.h> |
aoqi@0 | 44 | #endif // SOLARIS |
aoqi@0 | 45 | |
aoqi@0 | 46 | #include <math.h> |
aoqi@0 | 47 | #include <time.h> |
aoqi@0 | 48 | #include <fcntl.h> |
aoqi@0 | 49 | #include <dlfcn.h> |
aoqi@0 | 50 | #include <pthread.h> |
aoqi@0 | 51 | |
aoqi@0 | 52 | #ifdef SOLARIS |
aoqi@0 | 53 | #include <thread.h> |
aoqi@0 | 54 | #endif // SOLARIS |
aoqi@0 | 55 | |
aoqi@0 | 56 | #include <limits.h> |
aoqi@0 | 57 | #include <errno.h> |
aoqi@0 | 58 | |
aoqi@0 | 59 | #ifdef SOLARIS |
aoqi@0 | 60 | #include <sys/trap.h> |
aoqi@0 | 61 | #include <sys/regset.h> |
aoqi@0 | 62 | #include <sys/procset.h> |
aoqi@0 | 63 | #include <ucontext.h> |
aoqi@0 | 64 | #include <setjmp.h> |
aoqi@0 | 65 | #endif // SOLARIS |
aoqi@0 | 66 | |
aoqi@0 | 67 | # ifdef SOLARIS_MUTATOR_LIBTHREAD |
aoqi@0 | 68 | # include <sys/procfs.h> |
aoqi@0 | 69 | # endif |
aoqi@0 | 70 | |
aoqi@0 | 71 | #if defined(LINUX) || defined(_ALLBSD_SOURCE) |
aoqi@0 | 72 | #ifndef __STDC_LIMIT_MACROS |
aoqi@0 | 73 | #define __STDC_LIMIT_MACROS |
aoqi@0 | 74 | #endif // __STDC_LIMIT_MACROS |
aoqi@0 | 75 | #include <inttypes.h> |
aoqi@0 | 76 | #include <signal.h> |
aoqi@0 | 77 | #ifndef __OpenBSD__ |
aoqi@0 | 78 | #include <ucontext.h> |
aoqi@0 | 79 | #endif |
aoqi@0 | 80 | #ifdef __APPLE__ |
aoqi@0 | 81 | #include <AvailabilityMacros.h> |
aoqi@0 | 82 | #include <mach/mach.h> |
aoqi@0 | 83 | #endif |
aoqi@0 | 84 | #include <sys/time.h> |
aoqi@0 | 85 | #endif // LINUX || _ALLBSD_SOURCE |
aoqi@0 | 86 | |
aoqi@0 | 87 | // 4810578: varargs unsafe on 32-bit integer/64-bit pointer architectures |
aoqi@0 | 88 | // When __cplusplus is defined, NULL is defined as 0 (32-bit constant) in |
aoqi@0 | 89 | // system header files. On 32-bit architectures, there is no problem. |
aoqi@0 | 90 | // On 64-bit architectures, defining NULL as a 32-bit constant can cause |
aoqi@0 | 91 | // problems with varargs functions: C++ integral promotion rules say for |
aoqi@0 | 92 | // varargs, we pass the argument 0 as an int. So, if NULL was passed to a |
aoqi@0 | 93 | // varargs function it will remain 32-bits. Depending on the calling |
aoqi@0 | 94 | // convention of the machine, if the argument is passed on the stack then |
aoqi@0 | 95 | // only 32-bits of the "NULL" pointer may be initialized to zero. The |
aoqi@0 | 96 | // other 32-bits will be garbage. If the varargs function is expecting a |
aoqi@0 | 97 | // pointer when it extracts the argument, then we have a problem. |
aoqi@0 | 98 | // |
aoqi@0 | 99 | // Solution: For 64-bit architectures, redefine NULL as 64-bit constant 0. |
aoqi@0 | 100 | // |
aoqi@0 | 101 | // Note: this fix doesn't work well on Linux because NULL will be overwritten |
aoqi@0 | 102 | // whenever a system header file is included. Linux handles NULL correctly |
aoqi@0 | 103 | // through a special type '__null'. |
aoqi@0 | 104 | #ifdef SOLARIS |
aoqi@0 | 105 | #ifdef _LP64 |
aoqi@0 | 106 | #undef NULL |
aoqi@0 | 107 | #define NULL 0L |
aoqi@0 | 108 | #else |
aoqi@0 | 109 | #ifndef NULL |
aoqi@0 | 110 | #define NULL 0 |
aoqi@0 | 111 | #endif |
aoqi@0 | 112 | #endif |
aoqi@0 | 113 | #endif |
aoqi@0 | 114 | |
aoqi@0 | 115 | // NULL vs NULL_WORD: |
aoqi@0 | 116 | // On Linux NULL is defined as a special type '__null'. Assigning __null to |
aoqi@0 | 117 | // integer variable will cause gcc warning. Use NULL_WORD in places where a |
aoqi@0 | 118 | // pointer is stored as integer value. On some platforms, sizeof(intptr_t) > |
aoqi@0 | 119 | // sizeof(void*), so here we want something which is integer type, but has the |
aoqi@0 | 120 | // same size as a pointer. |
aoqi@0 | 121 | #ifdef __GNUC__ |
aoqi@0 | 122 | #ifdef _LP64 |
aoqi@0 | 123 | #define NULL_WORD 0L |
aoqi@0 | 124 | #else |
aoqi@0 | 125 | // Cast 0 to intptr_t rather than int32_t since they are not the same type |
aoqi@0 | 126 | // on platforms such as Mac OS X. |
aoqi@0 | 127 | #define NULL_WORD ((intptr_t)0) |
aoqi@0 | 128 | #endif |
aoqi@0 | 129 | #else |
aoqi@0 | 130 | #define NULL_WORD NULL |
aoqi@0 | 131 | #endif |
aoqi@0 | 132 | |
aoqi@0 | 133 | #if !defined(LINUX) && !defined(_ALLBSD_SOURCE) |
aoqi@0 | 134 | // Compiler-specific primitive types |
aoqi@0 | 135 | typedef unsigned short uint16_t; |
aoqi@0 | 136 | #ifndef _UINT32_T |
aoqi@0 | 137 | #define _UINT32_T |
aoqi@0 | 138 | typedef unsigned int uint32_t; |
aoqi@0 | 139 | #endif // _UINT32_T |
aoqi@0 | 140 | |
aoqi@0 | 141 | #if !defined(_SYS_INT_TYPES_H) |
aoqi@0 | 142 | #ifndef _UINT64_T |
aoqi@0 | 143 | #define _UINT64_T |
aoqi@0 | 144 | typedef unsigned long long uint64_t; |
aoqi@0 | 145 | #endif // _UINT64_T |
aoqi@0 | 146 | // %%%% how to access definition of intptr_t portably in 5.5 onward? |
aoqi@0 | 147 | typedef int intptr_t; |
aoqi@0 | 148 | typedef unsigned int uintptr_t; |
aoqi@0 | 149 | // If this gets an error, figure out a symbol XXX that implies the |
aoqi@0 | 150 | // prior definition of intptr_t, and add "&& !defined(XXX)" above. |
aoqi@0 | 151 | #endif // _SYS_INT_TYPES_H |
aoqi@0 | 152 | |
aoqi@0 | 153 | #endif // !LINUX && !_ALLBSD_SOURCE |
aoqi@0 | 154 | |
aoqi@0 | 155 | // Additional Java basic types |
aoqi@0 | 156 | |
aoqi@0 | 157 | typedef uint8_t jubyte; |
aoqi@0 | 158 | typedef uint16_t jushort; |
aoqi@0 | 159 | typedef uint32_t juint; |
aoqi@0 | 160 | typedef uint64_t julong; |
aoqi@0 | 161 | |
aoqi@0 | 162 | |
aoqi@0 | 163 | //---------------------------------------------------------------------------------------------------- |
aoqi@0 | 164 | // Constant for jlong (specifying an long long canstant is C++ compiler specific) |
aoqi@0 | 165 | |
aoqi@0 | 166 | // Build a 64bit integer constant |
aoqi@0 | 167 | #define CONST64(x) (x ## LL) |
aoqi@0 | 168 | #define UCONST64(x) (x ## ULL) |
aoqi@0 | 169 | |
aoqi@0 | 170 | const jlong min_jlong = CONST64(0x8000000000000000); |
aoqi@0 | 171 | const jlong max_jlong = CONST64(0x7fffffffffffffff); |
aoqi@0 | 172 | |
aoqi@0 | 173 | |
aoqi@0 | 174 | #ifdef SOLARIS |
aoqi@0 | 175 | //---------------------------------------------------------------------------------------------------- |
aoqi@0 | 176 | // ANSI C++ fixes |
aoqi@0 | 177 | // NOTE:In the ANSI committee's continuing attempt to make each version |
aoqi@0 | 178 | // of C++ incompatible with the previous version, you can no longer cast |
aoqi@0 | 179 | // pointers to functions without specifying linkage unless you want to get |
aoqi@0 | 180 | // warnings. |
aoqi@0 | 181 | // |
aoqi@0 | 182 | // This also means that pointers to functions can no longer be "hidden" |
aoqi@0 | 183 | // in opaque types like void * because at the invokation point warnings |
aoqi@0 | 184 | // will be generated. While this makes perfect sense from a type safety |
aoqi@0 | 185 | // point of view it causes a lot of warnings on old code using C header |
aoqi@0 | 186 | // files. Here are some typedefs to make the job of silencing warnings |
aoqi@0 | 187 | // a bit easier. |
aoqi@0 | 188 | // |
aoqi@0 | 189 | // The final kick in the teeth is that you can only have extern "C" linkage |
aoqi@0 | 190 | // specified at file scope. So these typedefs are here rather than in the |
aoqi@0 | 191 | // .hpp for the class (os:Solaris usually) that needs them. |
aoqi@0 | 192 | |
aoqi@0 | 193 | extern "C" { |
aoqi@0 | 194 | typedef int (*int_fnP_thread_t_iP_uP_stack_tP_gregset_t)(thread_t, int*, unsigned *, stack_t*, gregset_t); |
aoqi@0 | 195 | typedef int (*int_fnP_thread_t_i_gregset_t)(thread_t, int, gregset_t); |
aoqi@0 | 196 | typedef int (*int_fnP_thread_t_i)(thread_t, int); |
aoqi@0 | 197 | typedef int (*int_fnP_thread_t)(thread_t); |
aoqi@0 | 198 | |
aoqi@0 | 199 | typedef int (*int_fnP_cond_tP_mutex_tP_timestruc_tP)(cond_t *cv, mutex_t *mx, timestruc_t *abst); |
aoqi@0 | 200 | typedef int (*int_fnP_cond_tP_mutex_tP)(cond_t *cv, mutex_t *mx); |
aoqi@0 | 201 | |
aoqi@0 | 202 | // typedef for missing API in libc |
aoqi@0 | 203 | typedef int (*int_fnP_mutex_tP_i_vP)(mutex_t *, int, void *); |
aoqi@0 | 204 | typedef int (*int_fnP_mutex_tP)(mutex_t *); |
aoqi@0 | 205 | typedef int (*int_fnP_cond_tP_i_vP)(cond_t *cv, int scope, void *arg); |
aoqi@0 | 206 | typedef int (*int_fnP_cond_tP)(cond_t *cv); |
aoqi@0 | 207 | }; |
aoqi@0 | 208 | #endif // SOLARIS |
aoqi@0 | 209 | |
aoqi@0 | 210 | //---------------------------------------------------------------------------------------------------- |
aoqi@0 | 211 | // Debugging |
aoqi@0 | 212 | |
aoqi@0 | 213 | #define DEBUG_EXCEPTION ::abort(); |
aoqi@0 | 214 | |
dlong@7598 | 215 | #ifdef ARM32 |
aoqi@0 | 216 | #ifdef SOLARIS |
aoqi@0 | 217 | #define BREAKPOINT __asm__ volatile (".long 0xe1200070") |
aoqi@0 | 218 | #else |
aoqi@0 | 219 | #define BREAKPOINT __asm__ volatile (".long 0xe7f001f0") |
aoqi@0 | 220 | #endif |
aoqi@0 | 221 | #else |
aoqi@0 | 222 | extern "C" void breakpoint(); |
aoqi@0 | 223 | #define BREAKPOINT ::breakpoint() |
aoqi@0 | 224 | #endif |
aoqi@0 | 225 | |
aoqi@0 | 226 | // checking for nanness |
aoqi@0 | 227 | #ifdef SOLARIS |
aoqi@0 | 228 | #ifdef SPARC |
aoqi@0 | 229 | inline int g_isnan(float f) { return isnanf(f); } |
aoqi@0 | 230 | #else |
aoqi@0 | 231 | // isnanf() broken on Intel Solaris use isnand() |
aoqi@0 | 232 | inline int g_isnan(float f) { return isnand(f); } |
aoqi@0 | 233 | #endif |
aoqi@0 | 234 | inline int g_isnan(double f) { return isnand(f); } |
aoqi@0 | 235 | #elif defined(__APPLE__) |
aoqi@0 | 236 | inline int g_isnan(double f) { return isnan(f); } |
aoqi@0 | 237 | #elif defined(LINUX) || defined(_ALLBSD_SOURCE) |
aoqi@0 | 238 | inline int g_isnan(float f) { return isnanf(f); } |
aoqi@0 | 239 | inline int g_isnan(double f) { return isnan(f); } |
aoqi@0 | 240 | #else |
aoqi@0 | 241 | #error "missing platform-specific definition here" |
aoqi@0 | 242 | #endif |
aoqi@0 | 243 | |
aoqi@0 | 244 | // GCC 4.3 does not allow 0.0/0.0 to produce a NAN value |
aoqi@0 | 245 | #if (__GNUC__ == 4) && (__GNUC_MINOR__ > 2) |
aoqi@0 | 246 | #define CAN_USE_NAN_DEFINE 1 |
aoqi@0 | 247 | #endif |
aoqi@0 | 248 | |
aoqi@0 | 249 | |
aoqi@0 | 250 | // Checking for finiteness |
aoqi@0 | 251 | |
aoqi@0 | 252 | inline int g_isfinite(jfloat f) { return finite(f); } |
aoqi@0 | 253 | inline int g_isfinite(jdouble f) { return finite(f); } |
aoqi@0 | 254 | |
aoqi@0 | 255 | |
aoqi@0 | 256 | // Wide characters |
aoqi@0 | 257 | |
aoqi@0 | 258 | inline int wcslen(const jchar* x) { return wcslen((const wchar_t*)x); } |
aoqi@0 | 259 | |
aoqi@0 | 260 | |
aoqi@0 | 261 | // Portability macros |
aoqi@0 | 262 | #define PRAGMA_INTERFACE #pragma interface |
aoqi@0 | 263 | #define PRAGMA_IMPLEMENTATION #pragma implementation |
aoqi@0 | 264 | #define VALUE_OBJ_CLASS_SPEC |
aoqi@0 | 265 | |
aoqi@0 | 266 | #ifndef ATTRIBUTE_PRINTF |
aoqi@0 | 267 | // Diagnostic pragmas like the ones defined below in PRAGMA_FORMAT_NONLITERAL_IGNORED |
aoqi@0 | 268 | // were only introduced in GCC 4.2. Because we have no other possibility to ignore |
aoqi@0 | 269 | // these warnings for older versions of GCC, we simply don't decorate our printf-style |
aoqi@0 | 270 | // functions with __attribute__(format) in that case. |
aoqi@0 | 271 | #if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) || (__GNUC__ > 4) |
aoqi@0 | 272 | #define ATTRIBUTE_PRINTF(fmt,vargs) __attribute__((format(printf, fmt, vargs))) |
aoqi@0 | 273 | #else |
aoqi@0 | 274 | #define ATTRIBUTE_PRINTF(fmt,vargs) |
aoqi@0 | 275 | #endif |
aoqi@0 | 276 | #endif |
aoqi@0 | 277 | |
aoqi@0 | 278 | #define PRAGMA_FORMAT_NONLITERAL_IGNORED _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"") \ |
aoqi@0 | 279 | _Pragma("GCC diagnostic ignored \"-Wformat-security\"") |
aoqi@0 | 280 | #define PRAGMA_FORMAT_IGNORED _Pragma("GCC diagnostic ignored \"-Wformat\"") |
aoqi@0 | 281 | |
aoqi@0 | 282 | #if defined(__clang_major__) && \ |
aoqi@0 | 283 | (__clang_major__ >= 4 || \ |
aoqi@0 | 284 | (__clang_major__ >= 3 && __clang_minor__ >= 1)) || \ |
aoqi@0 | 285 | ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ > 4) |
aoqi@0 | 286 | // Tested to work with clang version 3.1 and better. |
aoqi@0 | 287 | #define PRAGMA_DIAG_PUSH _Pragma("GCC diagnostic push") |
aoqi@0 | 288 | #define PRAGMA_DIAG_POP _Pragma("GCC diagnostic pop") |
aoqi@0 | 289 | #define PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL |
aoqi@0 | 290 | #define PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL PRAGMA_FORMAT_NONLITERAL_IGNORED |
aoqi@0 | 291 | |
aoqi@0 | 292 | // Hack to deal with gcc yammering about non-security format stuff |
aoqi@0 | 293 | #else |
aoqi@0 | 294 | // Old versions of gcc don't do push/pop, also do not cope with this pragma within a function |
aoqi@0 | 295 | // One method does so much varied printing that it is decorated with both internal and external |
aoqi@0 | 296 | // versions of the macro-pragma to obtain better checking with newer compilers. |
aoqi@0 | 297 | #define PRAGMA_DIAG_PUSH |
aoqi@0 | 298 | #define PRAGMA_DIAG_POP |
aoqi@0 | 299 | #define PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL PRAGMA_FORMAT_NONLITERAL_IGNORED |
aoqi@0 | 300 | #define PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL |
aoqi@0 | 301 | #endif |
aoqi@0 | 302 | |
aoqi@0 | 303 | #ifndef __clang_major__ |
aoqi@0 | 304 | #define PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC _Pragma("GCC diagnostic ignored \"-Wformat\"") _Pragma("GCC diagnostic error \"-Wformat-nonliteral\"") _Pragma("GCC diagnostic error \"-Wformat-security\"") |
aoqi@0 | 305 | #endif |
aoqi@0 | 306 | |
aoqi@0 | 307 | #if (__GNUC__ == 2) && (__GNUC_MINOR__ < 95) |
aoqi@0 | 308 | #define TEMPLATE_TABLE_BUG |
aoqi@0 | 309 | #endif |
aoqi@0 | 310 | #if (__GNUC__ == 2) && (__GNUC_MINOR__ >= 96) |
aoqi@0 | 311 | #define CONST_SDM_BUG |
aoqi@0 | 312 | #endif |
aoqi@0 | 313 | |
aoqi@0 | 314 | // Formatting. |
aoqi@0 | 315 | #ifdef _LP64 |
aoqi@0 | 316 | #define FORMAT64_MODIFIER "l" |
aoqi@0 | 317 | #else // !_LP64 |
aoqi@0 | 318 | #define FORMAT64_MODIFIER "ll" |
aoqi@0 | 319 | #endif // _LP64 |
aoqi@0 | 320 | |
aoqi@0 | 321 | // HACK: gcc warns about applying offsetof() to non-POD object or calculating |
aoqi@0 | 322 | // offset directly when base address is NULL. Use 16 to get around the |
aoqi@0 | 323 | // warning. gcc-3.4 has an option -Wno-invalid-offsetof to suppress |
aoqi@0 | 324 | // this warning. |
aoqi@0 | 325 | #define offset_of(klass,field) (size_t)((intx)&(((klass*)16)->field) - 16) |
aoqi@0 | 326 | |
aoqi@0 | 327 | #ifdef offsetof |
aoqi@0 | 328 | # undef offsetof |
aoqi@0 | 329 | #endif |
aoqi@0 | 330 | #define offsetof(klass,field) offset_of(klass,field) |
aoqi@0 | 331 | |
aoqi@0 | 332 | #if defined(_LP64) && defined(__APPLE__) |
aoqi@0 | 333 | #define JLONG_FORMAT "%ld" |
aoqi@0 | 334 | #endif // _LP64 && __APPLE__ |
aoqi@0 | 335 | |
aoqi@0 | 336 | #endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_GCC_HPP |