annotate src/share/vm/utilities/globalDefinitions_gcc.hpp @ 5859:db9bb949e04c

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