src/share/vm/utilities/globalDefinitions_gcc.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/utilities/globalDefinitions_gcc.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,355 @@
     1.4 +/*
     1.5 + * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_UTILITIES_GLOBALDEFINITIONS_GCC_HPP
    1.29 +#define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_GCC_HPP
    1.30 +
    1.31 +#include "prims/jni.h"
    1.32 +
    1.33 +// This file holds compiler-dependent includes,
    1.34 +// globally used constants & types, class (forward)
    1.35 +// declarations and a few frequently used utility functions.
    1.36 +
    1.37 +#include <ctype.h>
    1.38 +#include <string.h>
    1.39 +#include <stdarg.h>
    1.40 +#include <stddef.h>
    1.41 +#include <stdio.h>
    1.42 +#include <stdlib.h>
    1.43 +#include <wchar.h>
    1.44 +
    1.45 +#ifdef SOLARIS
    1.46 +#include <ieeefp.h>
    1.47 +#endif // SOLARIS
    1.48 +
    1.49 +#include <math.h>
    1.50 +#ifndef FP_PZERO
    1.51 +// Linux doesn't have positive/negative zero
    1.52 +#define FP_PZERO FP_ZERO
    1.53 +#endif
    1.54 +#if (!defined fpclass) && ((!defined SPARC) || (!defined SOLARIS))
    1.55 +#define fpclass fpclassify
    1.56 +#endif
    1.57 +
    1.58 +#include <time.h>
    1.59 +#include <fcntl.h>
    1.60 +#include <dlfcn.h>
    1.61 +#include <pthread.h>
    1.62 +
    1.63 +#ifdef SOLARIS
    1.64 +#include <thread.h>
    1.65 +#endif // SOLARIS
    1.66 +
    1.67 +#include <limits.h>
    1.68 +#include <errno.h>
    1.69 +
    1.70 +#ifdef SOLARIS
    1.71 +#include <sys/trap.h>
    1.72 +#include <sys/regset.h>
    1.73 +#include <sys/procset.h>
    1.74 +#include <ucontext.h>
    1.75 +#include <setjmp.h>
    1.76 +#endif // SOLARIS
    1.77 +
    1.78 +# ifdef SOLARIS_MUTATOR_LIBTHREAD
    1.79 +# include <sys/procfs.h>
    1.80 +# endif
    1.81 +
    1.82 +#if defined(LINUX) || defined(_ALLBSD_SOURCE)
    1.83 +#ifndef __STDC_LIMIT_MACROS
    1.84 +#define __STDC_LIMIT_MACROS
    1.85 +#endif // __STDC_LIMIT_MACROS
    1.86 +#include <inttypes.h>
    1.87 +#include <signal.h>
    1.88 +#ifndef __OpenBSD__
    1.89 +#include <ucontext.h>
    1.90 +#endif
    1.91 +#ifdef __APPLE__
    1.92 +  #include <AvailabilityMacros.h>
    1.93 +  #include <mach/mach.h>
    1.94 +#endif
    1.95 +#include <sys/time.h>
    1.96 +#endif // LINUX || _ALLBSD_SOURCE
    1.97 +
    1.98 +// 4810578: varargs unsafe on 32-bit integer/64-bit pointer architectures
    1.99 +// When __cplusplus is defined, NULL is defined as 0 (32-bit constant) in
   1.100 +// system header files.  On 32-bit architectures, there is no problem.
   1.101 +// On 64-bit architectures, defining NULL as a 32-bit constant can cause
   1.102 +// problems with varargs functions: C++ integral promotion rules say for
   1.103 +// varargs, we pass the argument 0 as an int.  So, if NULL was passed to a
   1.104 +// varargs function it will remain 32-bits.  Depending on the calling
   1.105 +// convention of the machine, if the argument is passed on the stack then
   1.106 +// only 32-bits of the "NULL" pointer may be initialized to zero.  The
   1.107 +// other 32-bits will be garbage.  If the varargs function is expecting a
   1.108 +// pointer when it extracts the argument, then we have a problem.
   1.109 +//
   1.110 +// Solution: For 64-bit architectures, redefine NULL as 64-bit constant 0.
   1.111 +//
   1.112 +// Note: this fix doesn't work well on Linux because NULL will be overwritten
   1.113 +// whenever a system header file is included. Linux handles NULL correctly
   1.114 +// through a special type '__null'.
   1.115 +#ifdef SOLARIS
   1.116 +  #ifdef _LP64
   1.117 +    #undef NULL
   1.118 +    #define NULL 0L
   1.119 +  #else
   1.120 +    #ifndef NULL
   1.121 +      #define NULL 0
   1.122 +    #endif
   1.123 +  #endif
   1.124 +#endif
   1.125 +
   1.126 +// NULL vs NULL_WORD:
   1.127 +// On Linux NULL is defined as a special type '__null'. Assigning __null to
   1.128 +// integer variable will cause gcc warning. Use NULL_WORD in places where a
   1.129 +// pointer is stored as integer value.  On some platforms, sizeof(intptr_t) >
   1.130 +// sizeof(void*), so here we want something which is integer type, but has the
   1.131 +// same size as a pointer.
   1.132 +#ifdef __GNUC__
   1.133 +  #ifdef _LP64
   1.134 +    #define NULL_WORD  0L
   1.135 +  #else
   1.136 +    // Cast 0 to intptr_t rather than int32_t since they are not the same type
   1.137 +    // on platforms such as Mac OS X.
   1.138 +    #define NULL_WORD  ((intptr_t)0)
   1.139 +  #endif
   1.140 +#else
   1.141 +  #define NULL_WORD  NULL
   1.142 +#endif
   1.143 +
   1.144 +#if !defined(LINUX) && !defined(_ALLBSD_SOURCE)
   1.145 +// Compiler-specific primitive types
   1.146 +typedef unsigned short     uint16_t;
   1.147 +#ifndef _UINT32_T
   1.148 +#define _UINT32_T
   1.149 +typedef unsigned int       uint32_t;
   1.150 +#endif // _UINT32_T
   1.151 +
   1.152 +#if !defined(_SYS_INT_TYPES_H)
   1.153 +#ifndef _UINT64_T
   1.154 +#define _UINT64_T
   1.155 +typedef unsigned long long uint64_t;
   1.156 +#endif // _UINT64_T
   1.157 +// %%%% how to access definition of intptr_t portably in 5.5 onward?
   1.158 +typedef int                     intptr_t;
   1.159 +typedef unsigned int            uintptr_t;
   1.160 +// If this gets an error, figure out a symbol XXX that implies the
   1.161 +// prior definition of intptr_t, and add "&& !defined(XXX)" above.
   1.162 +#endif // _SYS_INT_TYPES_H
   1.163 +
   1.164 +#endif // !LINUX && !_ALLBSD_SOURCE
   1.165 +
   1.166 +// Additional Java basic types
   1.167 +
   1.168 +typedef uint8_t  jubyte;
   1.169 +typedef uint16_t jushort;
   1.170 +typedef uint32_t juint;
   1.171 +typedef uint64_t julong;
   1.172 +
   1.173 +//----------------------------------------------------------------------------------------------------
   1.174 +// Special (possibly not-portable) casts
   1.175 +// Cast floats into same-size integers and vice-versa w/o changing bit-pattern
   1.176 +// %%%%%% These seem like standard C++ to me--how about factoring them out? - Ungar
   1.177 +
   1.178 +inline jint    jint_cast   (jfloat  x)           { return *(jint*   )&x; }
   1.179 +inline jlong   jlong_cast  (jdouble x)           { return *(jlong*  )&x; }
   1.180 +inline julong  julong_cast (jdouble x)           { return *(julong* )&x; }
   1.181 +
   1.182 +inline jfloat  jfloat_cast (jint    x)           { return *(jfloat* )&x; }
   1.183 +inline jdouble jdouble_cast(jlong   x)           { return *(jdouble*)&x; }
   1.184 +
   1.185 +//----------------------------------------------------------------------------------------------------
   1.186 +// Constant for jlong (specifying an long long canstant is C++ compiler specific)
   1.187 +
   1.188 +// Build a 64bit integer constant
   1.189 +#define CONST64(x)  (x ## LL)
   1.190 +#define UCONST64(x) (x ## ULL)
   1.191 +
   1.192 +const jlong min_jlong = CONST64(0x8000000000000000);
   1.193 +const jlong max_jlong = CONST64(0x7fffffffffffffff);
   1.194 +
   1.195 +
   1.196 +#ifdef SOLARIS
   1.197 +//----------------------------------------------------------------------------------------------------
   1.198 +// ANSI C++ fixes
   1.199 +// NOTE:In the ANSI committee's continuing attempt to make each version
   1.200 +// of C++ incompatible with the previous version, you can no longer cast
   1.201 +// pointers to functions without specifying linkage unless you want to get
   1.202 +// warnings.
   1.203 +//
   1.204 +// This also means that pointers to functions can no longer be "hidden"
   1.205 +// in opaque types like void * because at the invokation point warnings
   1.206 +// will be generated. While this makes perfect sense from a type safety
   1.207 +// point of view it causes a lot of warnings on old code using C header
   1.208 +// files. Here are some typedefs to make the job of silencing warnings
   1.209 +// a bit easier.
   1.210 +//
   1.211 +// The final kick in the teeth is that you can only have extern "C" linkage
   1.212 +// specified at file scope. So these typedefs are here rather than in the
   1.213 +// .hpp for the class (os:Solaris usually) that needs them.
   1.214 +
   1.215 +extern "C" {
   1.216 +   typedef int (*int_fnP_thread_t_iP_uP_stack_tP_gregset_t)(thread_t, int*, unsigned *, stack_t*, gregset_t);
   1.217 +   typedef int (*int_fnP_thread_t_i_gregset_t)(thread_t, int, gregset_t);
   1.218 +   typedef int (*int_fnP_thread_t_i)(thread_t, int);
   1.219 +   typedef int (*int_fnP_thread_t)(thread_t);
   1.220 +
   1.221 +   typedef int (*int_fnP_cond_tP_mutex_tP_timestruc_tP)(cond_t *cv, mutex_t *mx, timestruc_t *abst);
   1.222 +   typedef int (*int_fnP_cond_tP_mutex_tP)(cond_t *cv, mutex_t *mx);
   1.223 +
   1.224 +   // typedef for missing API in libc
   1.225 +   typedef int (*int_fnP_mutex_tP_i_vP)(mutex_t *, int, void *);
   1.226 +   typedef int (*int_fnP_mutex_tP)(mutex_t *);
   1.227 +   typedef int (*int_fnP_cond_tP_i_vP)(cond_t *cv, int scope, void *arg);
   1.228 +   typedef int (*int_fnP_cond_tP)(cond_t *cv);
   1.229 +};
   1.230 +#endif // SOLARIS
   1.231 +
   1.232 +//----------------------------------------------------------------------------------------------------
   1.233 +// Debugging
   1.234 +
   1.235 +#define DEBUG_EXCEPTION ::abort();
   1.236 +
   1.237 +#ifdef ARM
   1.238 +#ifdef SOLARIS
   1.239 +#define BREAKPOINT __asm__ volatile (".long 0xe1200070")
   1.240 +#else
   1.241 +#define BREAKPOINT __asm__ volatile (".long 0xe7f001f0")
   1.242 +#endif
   1.243 +#else
   1.244 +extern "C" void breakpoint();
   1.245 +#define BREAKPOINT ::breakpoint()
   1.246 +#endif
   1.247 +
   1.248 +// checking for nanness
   1.249 +#ifdef SOLARIS
   1.250 +#ifdef SPARC
   1.251 +inline int g_isnan(float  f) { return isnanf(f); }
   1.252 +#else
   1.253 +// isnanf() broken on Intel Solaris use isnand()
   1.254 +inline int g_isnan(float  f) { return isnand(f); }
   1.255 +#endif
   1.256 +inline int g_isnan(double f) { return isnand(f); }
   1.257 +#elif defined(__APPLE__)
   1.258 +inline int g_isnan(double f) { return isnan(f); }
   1.259 +#elif defined(LINUX) || defined(_ALLBSD_SOURCE)
   1.260 +inline int g_isnan(float  f) { return isnanf(f); }
   1.261 +inline int g_isnan(double f) { return isnan(f); }
   1.262 +#else
   1.263 +#error "missing platform-specific definition here"
   1.264 +#endif
   1.265 +
   1.266 +// GCC 4.3 does not allow 0.0/0.0 to produce a NAN value
   1.267 +#if (__GNUC__ == 4) && (__GNUC_MINOR__ > 2)
   1.268 +#define CAN_USE_NAN_DEFINE 1
   1.269 +#endif
   1.270 +
   1.271 +
   1.272 +// Checking for finiteness
   1.273 +
   1.274 +inline int g_isfinite(jfloat  f)                 { return finite(f); }
   1.275 +inline int g_isfinite(jdouble f)                 { return finite(f); }
   1.276 +
   1.277 +
   1.278 +// Wide characters
   1.279 +
   1.280 +inline int wcslen(const jchar* x) { return wcslen((const wchar_t*)x); }
   1.281 +
   1.282 +
   1.283 +// Portability macros
   1.284 +#define PRAGMA_INTERFACE             #pragma interface
   1.285 +#define PRAGMA_IMPLEMENTATION        #pragma implementation
   1.286 +#define VALUE_OBJ_CLASS_SPEC
   1.287 +
   1.288 +#ifndef ATTRIBUTE_PRINTF
   1.289 +// Diagnostic pragmas like the ones defined below in PRAGMA_FORMAT_NONLITERAL_IGNORED
   1.290 +// were only introduced in GCC 4.2. Because we have no other possibility to ignore
   1.291 +// these warnings for older versions of GCC, we simply don't decorate our printf-style
   1.292 +// functions with __attribute__(format) in that case.
   1.293 +#if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) || (__GNUC__ > 4)
   1.294 +#define ATTRIBUTE_PRINTF(fmt,vargs)  __attribute__((format(printf, fmt, vargs)))
   1.295 +#else
   1.296 +#define ATTRIBUTE_PRINTF(fmt,vargs)
   1.297 +#endif
   1.298 +#endif
   1.299 +
   1.300 +#define PRAGMA_FORMAT_NONLITERAL_IGNORED _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"") \
   1.301 +                                         _Pragma("GCC diagnostic ignored \"-Wformat-security\"")
   1.302 +#define PRAGMA_FORMAT_IGNORED _Pragma("GCC diagnostic ignored \"-Wformat\"")
   1.303 +
   1.304 +#if defined(__clang_major__) && \
   1.305 +      (__clang_major__ >= 4 || \
   1.306 +      (__clang_major__ >= 3 && __clang_minor__ >= 1)) || \
   1.307 +    ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ > 4)
   1.308 +// Tested to work with clang version 3.1 and better.
   1.309 +#define PRAGMA_DIAG_PUSH             _Pragma("GCC diagnostic push")
   1.310 +#define PRAGMA_DIAG_POP              _Pragma("GCC diagnostic pop")
   1.311 +#define PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL
   1.312 +#define PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL PRAGMA_FORMAT_NONLITERAL_IGNORED
   1.313 +
   1.314 +// Hack to deal with gcc yammering about non-security format stuff
   1.315 +#else
   1.316 +// Old versions of gcc don't do push/pop, also do not cope with this pragma within a function
   1.317 +// One method does so much varied printing that it is decorated with both internal and external
   1.318 +// versions of the macro-pragma to obtain better checking with newer compilers.
   1.319 +#define PRAGMA_DIAG_PUSH
   1.320 +#define PRAGMA_DIAG_POP
   1.321 +#define PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL PRAGMA_FORMAT_NONLITERAL_IGNORED
   1.322 +#define PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL
   1.323 +#endif
   1.324 +
   1.325 +#ifndef __clang_major__
   1.326 +#define PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC _Pragma("GCC diagnostic ignored \"-Wformat\"") _Pragma("GCC diagnostic error \"-Wformat-nonliteral\"") _Pragma("GCC diagnostic error \"-Wformat-security\"")
   1.327 +#endif
   1.328 +
   1.329 +#if (__GNUC__ == 2) && (__GNUC_MINOR__ < 95)
   1.330 +#define TEMPLATE_TABLE_BUG
   1.331 +#endif
   1.332 +#if (__GNUC__ == 2) && (__GNUC_MINOR__ >= 96)
   1.333 +#define CONST_SDM_BUG
   1.334 +#endif
   1.335 +
   1.336 +// Formatting.
   1.337 +#ifdef _LP64
   1.338 +#define FORMAT64_MODIFIER "l"
   1.339 +#else // !_LP64
   1.340 +#define FORMAT64_MODIFIER "ll"
   1.341 +#endif // _LP64
   1.342 +
   1.343 +// HACK: gcc warns about applying offsetof() to non-POD object or calculating
   1.344 +//       offset directly when base address is NULL. Use 16 to get around the
   1.345 +//       warning. gcc-3.4 has an option -Wno-invalid-offsetof to suppress
   1.346 +//       this warning.
   1.347 +#define offset_of(klass,field) (size_t)((intx)&(((klass*)16)->field) - 16)
   1.348 +
   1.349 +#ifdef offsetof
   1.350 +# undef offsetof
   1.351 +#endif
   1.352 +#define offsetof(klass,field) offset_of(klass,field)
   1.353 +
   1.354 +#if defined(_LP64) && defined(__APPLE__)
   1.355 +#define JLONG_FORMAT           "%ld"
   1.356 +#endif // _LP64 && __APPLE__
   1.357 +
   1.358 +#endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_GCC_HPP

mercurial