Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp
32285 views
/*1* Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_UTILITIES_GLOBALDEFINITIONS_GCC_HPP25#define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_GCC_HPP2627#include "prims/jni.h"2829// This file holds compiler-dependent includes,30// globally used constants & types, class (forward)31// declarations and a few frequently used utility functions.3233#include <ctype.h>34#include <string.h>35#include <stdarg.h>36#include <stddef.h>37#include <stdio.h>38#include <stdlib.h>39#include <wchar.h>4041#ifdef SOLARIS42#include <ieeefp.h>43#endif // SOLARIS4445#include <math.h>46#include <time.h>47#include <fcntl.h>48#include <dlfcn.h>49#include <pthread.h>5051#ifdef SOLARIS52#include <thread.h>53#endif // SOLARIS5455#include <limits.h>56#include <errno.h>5758#ifdef SOLARIS59#include <sys/trap.h>60#include <sys/regset.h>61#include <sys/procset.h>62#include <ucontext.h>63#include <setjmp.h>64#endif // SOLARIS6566# ifdef SOLARIS_MUTATOR_LIBTHREAD67# include <sys/procfs.h>68# endif6970#if defined(LINUX) || defined(_ALLBSD_SOURCE)71#ifndef __STDC_LIMIT_MACROS72#define __STDC_LIMIT_MACROS73#endif // __STDC_LIMIT_MACROS74#include <inttypes.h>75#include <signal.h>76#ifndef __OpenBSD__77#include <ucontext.h>78#endif79#ifdef __APPLE__80#include <AvailabilityMacros.h>81#include <mach/mach.h>82#endif83#include <sys/time.h>84#endif // LINUX || _ALLBSD_SOURCE8586// 4810578: varargs unsafe on 32-bit integer/64-bit pointer architectures87// When __cplusplus is defined, NULL is defined as 0 (32-bit constant) in88// system header files. On 32-bit architectures, there is no problem.89// On 64-bit architectures, defining NULL as a 32-bit constant can cause90// problems with varargs functions: C++ integral promotion rules say for91// varargs, we pass the argument 0 as an int. So, if NULL was passed to a92// varargs function it will remain 32-bits. Depending on the calling93// convention of the machine, if the argument is passed on the stack then94// only 32-bits of the "NULL" pointer may be initialized to zero. The95// other 32-bits will be garbage. If the varargs function is expecting a96// pointer when it extracts the argument, then we have a problem.97//98// Solution: For 64-bit architectures, redefine NULL as 64-bit constant 0.99//100// Note: this fix doesn't work well on Linux because NULL will be overwritten101// whenever a system header file is included. Linux handles NULL correctly102// through a special type '__null'.103#ifdef SOLARIS104#ifdef _LP64105#undef NULL106#define NULL 0L107#else108#ifndef NULL109#define NULL 0110#endif111#endif112#endif113114// NULL vs NULL_WORD:115// On Linux NULL is defined as a special type '__null'. Assigning __null to116// integer variable will cause gcc warning. Use NULL_WORD in places where a117// pointer is stored as integer value. On some platforms, sizeof(intptr_t) >118// sizeof(void*), so here we want something which is integer type, but has the119// same size as a pointer.120#ifdef __GNUC__121#ifdef _LP64122#define NULL_WORD 0L123#else124// Cast 0 to intptr_t rather than int32_t since they are not the same type125// on platforms such as Mac OS X.126#define NULL_WORD ((intptr_t)0)127#endif128#else129#define NULL_WORD NULL130#endif131132#if !defined(LINUX) && !defined(_ALLBSD_SOURCE)133// Compiler-specific primitive types134typedef unsigned short uint16_t;135#ifndef _UINT32_T136#define _UINT32_T137typedef unsigned int uint32_t;138#endif // _UINT32_T139140#if !defined(_SYS_INT_TYPES_H)141#ifndef _UINT64_T142#define _UINT64_T143typedef unsigned long long uint64_t;144#endif // _UINT64_T145// %%%% how to access definition of intptr_t portably in 5.5 onward?146typedef int intptr_t;147typedef unsigned int uintptr_t;148// If this gets an error, figure out a symbol XXX that implies the149// prior definition of intptr_t, and add "&& !defined(XXX)" above.150#endif // _SYS_INT_TYPES_H151152#endif // !LINUX && !_ALLBSD_SOURCE153154// Additional Java basic types155156typedef uint8_t jubyte;157typedef uint16_t jushort;158typedef uint32_t juint;159// --- iOS aarch64 port ---160// Darwin `uint64_t` type is `unsigned long long` instead of `unsigned long`,161// which will cause compile errors. Therefore, we should switch back to old162// type `unsigned long`. On 64-bit, `long` is 8-byte long, which is same as163// `long long`, so just change it.164#if !defined(__APPLE__) || !defined(AARCH64)165typedef uint64_t julong;166#else167typedef unsigned long julong;168#endif169170171//----------------------------------------------------------------------------------------------------172// Constant for jlong (specifying an long long canstant is C++ compiler specific)173174// Build a 64bit integer constant175#define CONST64(x) (x ## LL)176#define UCONST64(x) (x ## ULL)177178const jlong min_jlong = CONST64(0x8000000000000000);179const jlong max_jlong = CONST64(0x7fffffffffffffff);180181182#ifdef SOLARIS183//----------------------------------------------------------------------------------------------------184// ANSI C++ fixes185// NOTE:In the ANSI committee's continuing attempt to make each version186// of C++ incompatible with the previous version, you can no longer cast187// pointers to functions without specifying linkage unless you want to get188// warnings.189//190// This also means that pointers to functions can no longer be "hidden"191// in opaque types like void * because at the invokation point warnings192// will be generated. While this makes perfect sense from a type safety193// point of view it causes a lot of warnings on old code using C header194// files. Here are some typedefs to make the job of silencing warnings195// a bit easier.196//197// The final kick in the teeth is that you can only have extern "C" linkage198// specified at file scope. So these typedefs are here rather than in the199// .hpp for the class (os:Solaris usually) that needs them.200201extern "C" {202typedef int (*int_fnP_thread_t_iP_uP_stack_tP_gregset_t)(thread_t, int*, unsigned *, stack_t*, gregset_t);203typedef int (*int_fnP_thread_t_i_gregset_t)(thread_t, int, gregset_t);204typedef int (*int_fnP_thread_t_i)(thread_t, int);205typedef int (*int_fnP_thread_t)(thread_t);206207typedef int (*int_fnP_cond_tP_mutex_tP_timestruc_tP)(cond_t *cv, mutex_t *mx, timestruc_t *abst);208typedef int (*int_fnP_cond_tP_mutex_tP)(cond_t *cv, mutex_t *mx);209210// typedef for missing API in libc211typedef int (*int_fnP_mutex_tP_i_vP)(mutex_t *, int, void *);212typedef int (*int_fnP_mutex_tP)(mutex_t *);213typedef int (*int_fnP_cond_tP_i_vP)(cond_t *cv, int scope, void *arg);214typedef int (*int_fnP_cond_tP)(cond_t *cv);215};216#endif // SOLARIS217218//----------------------------------------------------------------------------------------------------219// Debugging220221#define DEBUG_EXCEPTION ::abort();222223#ifdef ARM32224#ifdef SOLARIS225#define BREAKPOINT __asm__ volatile (".long 0xe1200070")226#else227#define BREAKPOINT __asm__ volatile (".long 0xe7f001f0")228#endif229#else230extern "C" void breakpoint();231#define BREAKPOINT ::breakpoint()232#endif233234// checking for nanness235#ifdef SOLARIS236#ifdef SPARC237inline int g_isnan(float f) { return isnanf(f); }238#else239// isnanf() broken on Intel Solaris use isnand()240inline int g_isnan(float f) { return isnand(f); }241#endif242inline int g_isnan(double f) { return isnand(f); }243#elif defined(__APPLE__)244inline int g_isnan(double f) { return isnan(f); }245#elif defined(LINUX) || defined(_ALLBSD_SOURCE)246inline int g_isnan(float f) { return isnanf(f); }247inline int g_isnan(double f) { return isnan(f); }248#else249#error "missing platform-specific definition here"250#endif251252// GCC 4.3 does not allow 0.0/0.0 to produce a NAN value253#if (__GNUC__ == 4) && (__GNUC_MINOR__ > 2)254#define CAN_USE_NAN_DEFINE 1255#endif256257258// Checking for finiteness259260inline int g_isfinite(jfloat f) { return finite(f); }261inline int g_isfinite(jdouble f) { return finite(f); }262263264// Wide characters265266inline int wcslen(const jchar* x) { return wcslen((const wchar_t*)x); }267268269// Portability macros270#define PRAGMA_INTERFACE #pragma interface271#define PRAGMA_IMPLEMENTATION #pragma implementation272#define VALUE_OBJ_CLASS_SPEC273274// Diagnostic pragmas like the ones defined below in PRAGMA_FORMAT_NONLITERAL_IGNORED275// were only introduced in GCC 4.2. Because we have no other possibility to ignore276// these warnings for older versions of GCC, we simply don't decorate our printf-style277// functions with __attribute__(format) in that case.278#if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) || (__GNUC__ > 4)279#ifndef ATTRIBUTE_PRINTF280#define ATTRIBUTE_PRINTF(fmt,vargs) __attribute__((format(printf, fmt, vargs)))281#endif282#ifndef ATTRIBUTE_SCANF283#define ATTRIBUTE_SCANF(fmt,vargs) __attribute__((format(scanf, fmt, vargs)))284#endif285#endif // gcc version check286287#define PRAGMA_FORMAT_NONLITERAL_IGNORED _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"") \288_Pragma("GCC diagnostic ignored \"-Wformat-security\"")289#define PRAGMA_FORMAT_IGNORED _Pragma("GCC diagnostic ignored \"-Wformat\"")290291#if defined(__clang_major__) && \292(__clang_major__ >= 4 || \293(__clang_major__ >= 3 && __clang_minor__ >= 1)) || \294((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ > 4)295// Tested to work with clang version 3.1 and better.296#define PRAGMA_DIAG_PUSH _Pragma("GCC diagnostic push")297#define PRAGMA_DIAG_POP _Pragma("GCC diagnostic pop")298#define PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL299#define PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL PRAGMA_FORMAT_NONLITERAL_IGNORED300301// Hack to deal with gcc yammering about non-security format stuff302#else303// Old versions of gcc don't do push/pop, also do not cope with this pragma within a function304// One method does so much varied printing that it is decorated with both internal and external305// versions of the macro-pragma to obtain better checking with newer compilers.306#define PRAGMA_DIAG_PUSH307#define PRAGMA_DIAG_POP308#define PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL PRAGMA_FORMAT_NONLITERAL_IGNORED309#define PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL310#endif311312#ifndef __clang_major__313#define PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC _Pragma("GCC diagnostic ignored \"-Wformat\"") _Pragma("GCC diagnostic error \"-Wformat-nonliteral\"") _Pragma("GCC diagnostic error \"-Wformat-security\"")314#endif315316#if (__GNUC__ == 2) && (__GNUC_MINOR__ < 95)317#define TEMPLATE_TABLE_BUG318#endif319#if (__GNUC__ == 2) && (__GNUC_MINOR__ >= 96)320#define CONST_SDM_BUG321#endif322323// Formatting.324#ifdef _LP64325#define FORMAT64_MODIFIER "l"326#else // !_LP64327#define FORMAT64_MODIFIER "ll"328#endif // _LP64329330// HACK: gcc warns about applying offsetof() to non-POD object or calculating331// offset directly when base address is NULL. Use 16 to get around the332// warning. gcc-3.4 has an option -Wno-invalid-offsetof to suppress333// this warning.334#define offset_of(klass,field) (size_t)((intx)&(((klass*)16)->field) - 16)335336#ifdef offsetof337# undef offsetof338#endif339#define offsetof(klass,field) offset_of(klass,field)340341#if defined(_LP64) && defined(__APPLE__)342#define JLONG_FORMAT "%ld"343#endif // _LP64 && __APPLE__344345// Inlining support346#define NOINLINE __attribute__ ((noinline))347#define ALWAYSINLINE inline __attribute__ ((always_inline))348349#endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_GCC_HPP350351352