Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp
83404 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;159typedef uint64_t julong;160161162//----------------------------------------------------------------------------------------------------163// Constant for jlong (specifying an long long canstant is C++ compiler specific)164165// Build a 64bit integer constant166#define CONST64(x) (x ## LL)167#define UCONST64(x) (x ## ULL)168169const jlong min_jlong = CONST64(0x8000000000000000);170const jlong max_jlong = CONST64(0x7fffffffffffffff);171172173#ifdef SOLARIS174//----------------------------------------------------------------------------------------------------175// ANSI C++ fixes176// NOTE:In the ANSI committee's continuing attempt to make each version177// of C++ incompatible with the previous version, you can no longer cast178// pointers to functions without specifying linkage unless you want to get179// warnings.180//181// This also means that pointers to functions can no longer be "hidden"182// in opaque types like void * because at the invokation point warnings183// will be generated. While this makes perfect sense from a type safety184// point of view it causes a lot of warnings on old code using C header185// files. Here are some typedefs to make the job of silencing warnings186// a bit easier.187//188// The final kick in the teeth is that you can only have extern "C" linkage189// specified at file scope. So these typedefs are here rather than in the190// .hpp for the class (os:Solaris usually) that needs them.191192extern "C" {193typedef int (*int_fnP_thread_t_iP_uP_stack_tP_gregset_t)(thread_t, int*, unsigned *, stack_t*, gregset_t);194typedef int (*int_fnP_thread_t_i_gregset_t)(thread_t, int, gregset_t);195typedef int (*int_fnP_thread_t_i)(thread_t, int);196typedef int (*int_fnP_thread_t)(thread_t);197198typedef int (*int_fnP_cond_tP_mutex_tP_timestruc_tP)(cond_t *cv, mutex_t *mx, timestruc_t *abst);199typedef int (*int_fnP_cond_tP_mutex_tP)(cond_t *cv, mutex_t *mx);200201// typedef for missing API in libc202typedef int (*int_fnP_mutex_tP_i_vP)(mutex_t *, int, void *);203typedef int (*int_fnP_mutex_tP)(mutex_t *);204typedef int (*int_fnP_cond_tP_i_vP)(cond_t *cv, int scope, void *arg);205typedef int (*int_fnP_cond_tP)(cond_t *cv);206};207#endif // SOLARIS208209//----------------------------------------------------------------------------------------------------210// Debugging211212#define DEBUG_EXCEPTION ::abort();213214#ifdef ARM32215#ifdef SOLARIS216#define BREAKPOINT __asm__ volatile (".long 0xe1200070")217#else218#define BREAKPOINT __asm__ volatile (".long 0xe7f001f0")219#endif220#else221extern "C" void breakpoint();222#define BREAKPOINT ::breakpoint()223#endif224225// checking for nanness226#ifdef SOLARIS227#ifdef SPARC228inline int g_isnan(float f) { return isnanf(f); }229#else230// isnanf() broken on Intel Solaris use isnand()231inline int g_isnan(float f) { return isnand(f); }232#endif233inline int g_isnan(double f) { return isnand(f); }234#elif defined(__APPLE__)235inline int g_isnan(double f) { return isnan(f); }236#elif defined(LINUX)237// Linux libc without BSD extensions not required238// to have isnanf, but should have isnan macro239inline int g_isnan(float f) { return isnan(f); }240inline int g_isnan(double f) { return isnan(f); }241#elif defined(_ALLBSD_SOURCE)242inline int g_isnan(float f) { return isnanf(f); }243inline int g_isnan(double f) { return isnan(f); }244#else245#error "missing platform-specific definition here"246#endif247248// GCC 4.3 does not allow 0.0/0.0 to produce a NAN value249#if (__GNUC__ == 4) && (__GNUC_MINOR__ > 2)250#define CAN_USE_NAN_DEFINE 1251#endif252253254// Checking for finiteness255256#if defined(LINUX)257// Linux libc without BSD extensions have no finite, but has isfinite258inline int g_isfinite(jfloat f) { return isfinite(f); }259inline int g_isfinite(jdouble f) { return isfinite(f); }260#else261inline int g_isfinite(jfloat f) { return finite(f); }262inline int g_isfinite(jdouble f) { return finite(f); }263#endif264265266// Wide characters267268inline int wcslen(const jchar* x) { return wcslen((const wchar_t*)x); }269270271// Portability macros272#define PRAGMA_INTERFACE #pragma interface273#define PRAGMA_IMPLEMENTATION #pragma implementation274#define VALUE_OBJ_CLASS_SPEC275276// Diagnostic pragmas like the ones defined below in PRAGMA_FORMAT_NONLITERAL_IGNORED277// were only introduced in GCC 4.2. Because we have no other possibility to ignore278// these warnings for older versions of GCC, we simply don't decorate our printf-style279// functions with __attribute__(format) in that case.280#if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) || (__GNUC__ > 4)281#ifndef ATTRIBUTE_PRINTF282#define ATTRIBUTE_PRINTF(fmt,vargs) __attribute__((format(printf, fmt, vargs)))283#endif284#ifndef ATTRIBUTE_SCANF285#define ATTRIBUTE_SCANF(fmt,vargs) __attribute__((format(scanf, fmt, vargs)))286#endif287#endif // gcc version check288289#define PRAGMA_FORMAT_NONLITERAL_IGNORED _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"") \290_Pragma("GCC diagnostic ignored \"-Wformat-security\"")291#define PRAGMA_FORMAT_IGNORED _Pragma("GCC diagnostic ignored \"-Wformat\"")292293#if defined(__clang_major__) && \294(__clang_major__ >= 4 || \295(__clang_major__ >= 3 && __clang_minor__ >= 1)) || \296((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ > 4)297// Tested to work with clang version 3.1 and better.298#define PRAGMA_DIAG_PUSH _Pragma("GCC diagnostic push")299#define PRAGMA_DIAG_POP _Pragma("GCC diagnostic pop")300#define PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL301#define PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL PRAGMA_FORMAT_NONLITERAL_IGNORED302303// Hack to deal with gcc yammering about non-security format stuff304#else305// Old versions of gcc don't do push/pop, also do not cope with this pragma within a function306// One method does so much varied printing that it is decorated with both internal and external307// versions of the macro-pragma to obtain better checking with newer compilers.308#define PRAGMA_DIAG_PUSH309#define PRAGMA_DIAG_POP310#define PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL PRAGMA_FORMAT_NONLITERAL_IGNORED311#define PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL312#endif313314#ifndef __clang_major__315#define PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC _Pragma("GCC diagnostic ignored \"-Wformat\"") _Pragma("GCC diagnostic error \"-Wformat-nonliteral\"") _Pragma("GCC diagnostic error \"-Wformat-security\"")316#endif317318#if (__GNUC__ == 2) && (__GNUC_MINOR__ < 95)319#define TEMPLATE_TABLE_BUG320#endif321#if (__GNUC__ == 2) && (__GNUC_MINOR__ >= 96)322#define CONST_SDM_BUG323#endif324325// Formatting.326#ifdef _LP64327#define FORMAT64_MODIFIER "l"328#else // !_LP64329#define FORMAT64_MODIFIER "ll"330#endif // _LP64331332// HACK: gcc warns about applying offsetof() to non-POD object or calculating333// offset directly when base address is NULL. Use 16 to get around the334// warning. gcc-3.4 has an option -Wno-invalid-offsetof to suppress335// this warning.336#define offset_of(klass,field) (size_t)((intx)&(((klass*)16)->field) - 16)337338#ifdef offsetof339# undef offsetof340#endif341#define offsetof(klass,field) offset_of(klass,field)342343#if defined(_LP64) && defined(__APPLE__)344#define JLONG_FORMAT "%ld"345#endif // _LP64 && __APPLE__346347// Inlining support348#define NOINLINE __attribute__ ((noinline))349#define ALWAYSINLINE inline __attribute__ ((always_inline))350351#endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_GCC_HPP352353354