1 /* 2 * Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_UTILITIES_GLOBALDEFINITIONS_GCC_HPP 26 #define SHARE_UTILITIES_GLOBALDEFINITIONS_GCC_HPP 27 28 #include "jni.h" 29 30 // This file holds compiler-dependent includes, 31 // globally used constants & types, class (forward) 32 // declarations and a few frequently used utility functions. 33 34 #include <ctype.h> 35 #include <string.h> 36 #include <stdarg.h> 37 #include <stddef.h> 38 #include <stdio.h> 39 #include <stdlib.h> 40 #include <wchar.h> 41 42 #include <math.h> 43 #include <time.h> 44 #include <fcntl.h> 45 #include <dlfcn.h> 46 #include <pthread.h> 47 48 #include <limits.h> 49 #include <errno.h> 50 51 #if defined(LINUX) || defined(_ALLBSD_SOURCE) 52 #include <inttypes.h> 53 #include <signal.h> 54 #ifndef __OpenBSD__ 55 #include <ucontext.h> 56 #endif 57 #ifdef __APPLE__ 58 #include <AvailabilityMacros.h> 59 #include <mach/mach.h> 60 #endif 61 #include <sys/time.h> 62 #endif // LINUX || _ALLBSD_SOURCE 63 64 // NULL vs NULL_WORD: 65 // On Linux NULL is defined as a special type '__null'. Assigning __null to 66 // integer variable will cause gcc warning. Use NULL_WORD in places where a 67 // pointer is stored as integer value. On some platforms, sizeof(intptr_t) > 68 // sizeof(void*), so here we want something which is integer type, but has the 69 // same size as a pointer. 70 #ifdef __GNUC__ 71 #ifdef _LP64 72 #define NULL_WORD 0L 73 #else 74 // Cast 0 to intptr_t rather than int32_t since they are not the same type 75 // on platforms such as Mac OS X. 76 #define NULL_WORD ((intptr_t)0) 77 #endif 78 #else 79 #define NULL_WORD NULL 80 #endif 81 82 #if !defined(LINUX) && !defined(_ALLBSD_SOURCE) 83 // Compiler-specific primitive types 84 typedef unsigned short uint16_t; 85 #ifndef _UINT32_T 86 #define _UINT32_T 87 typedef unsigned int uint32_t; 88 #endif // _UINT32_T 89 90 #if !defined(_SYS_INT_TYPES_H) 91 #ifndef _UINT64_T 92 #define _UINT64_T 93 typedef unsigned long long uint64_t; 94 #endif // _UINT64_T 95 // %%%% how to access definition of intptr_t portably in 5.5 onward? 96 typedef int intptr_t; 97 typedef unsigned int uintptr_t; 98 // If this gets an error, figure out a symbol XXX that implies the 99 // prior definition of intptr_t, and add "&& !defined(XXX)" above. 100 #endif // _SYS_INT_TYPES_H 101 102 #endif // !LINUX && !_ALLBSD_SOURCE 103 104 // Additional Java basic types 105 106 typedef uint8_t jubyte; 107 typedef uint16_t jushort; 108 typedef uint32_t juint; 109 typedef uint64_t julong; 110 111 // checking for nanness 112 #if defined(__APPLE__) 113 inline int g_isnan(double f) { return isnan(f); } 114 #elif defined(LINUX) || defined(_ALLBSD_SOURCE) 115 inline int g_isnan(float f) { return isnanf(f); } 116 inline int g_isnan(double f) { return isnan(f); } 117 #else 118 #error "missing platform-specific definition here" 119 #endif 120 121 #define CAN_USE_NAN_DEFINE 1 122 123 124 // Checking for finiteness 125 126 inline int g_isfinite(jfloat f) { return isfinite(f); } 127 inline int g_isfinite(jdouble f) { return isfinite(f); } 128 129 130 // Wide characters 131 132 inline int wcslen(const jchar* x) { return wcslen((const wchar_t*)x); } 133 134 135 // Formatting. 136 #ifdef _LP64 137 # ifdef __APPLE__ 138 # define FORMAT64_MODIFIER "ll" 139 # else 140 # define FORMAT64_MODIFIER "l" 141 # endif 142 #else // !_LP64 143 #define FORMAT64_MODIFIER "ll" 144 #endif // _LP64 145 146 // gcc warns about applying offsetof() to non-POD object or calculating 147 // offset directly when base address is NULL. Use 16 to get around the 148 // warning. The -Wno-invalid-offsetof option could be used to suppress 149 // this warning, but we instead just avoid the use of offsetof(). 150 #define offset_of(klass,field) (size_t)((intx)&(((klass*)16)->field) - 16) 151 152 #if defined(_LP64) && defined(__APPLE__) 153 #define JLONG_FORMAT "%ld" 154 #define JLONG_FORMAT_W(width) "%" #width "ld" 155 #endif // _LP64 && __APPLE__ 156 157 #define THREAD_LOCAL __thread 158 159 // Inlining support 160 #define NOINLINE __attribute__ ((noinline)) 161 #define ALWAYSINLINE inline __attribute__ ((always_inline)) 162 163 // Alignment 164 // 165 #define ATTRIBUTE_ALIGNED(x) __attribute__((aligned(x))) 166 167 #endif // SHARE_UTILITIES_GLOBALDEFINITIONS_GCC_HPP