src/share/vm/utilities/globalDefinitions_gcc.hpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7001
b6a8cc1e0d92
parent 6876
710a3c8b516e
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

merge

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

mercurial