1 /* 2 * Copyright (c) 1997, 2016, 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_VM_UTILITIES_GLOBALDEFINITIONS_SPARCWORKS_HPP 26 #define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_SPARCWORKS_HPP 27 28 #include "prims/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 35 # include <ctype.h> 36 # include <string.h> 37 # include <strings.h> // for bsd'isms 38 # include <stdarg.h> 39 # include <stddef.h> // for offsetof 40 # include <stdio.h> 41 # include <stdlib.h> 42 # include <wchar.h> 43 # include <stdarg.h> 44 #ifdef SOLARIS 45 # include <ieeefp.h> 46 #endif 47 # include <math.h> 48 # include <time.h> 49 # include <fcntl.h> 50 # include <dlfcn.h> 51 # include <pthread.h> 52 #ifdef SOLARIS 53 # include <thread.h> 54 #endif 55 # include <limits.h> 56 # include <errno.h> 57 #ifdef SOLARIS 58 # include <sys/trap.h> 59 # include <sys/regset.h> 60 # include <sys/procset.h> 61 # include <ucontext.h> 62 # include <setjmp.h> 63 #endif 64 # ifdef SOLARIS_MUTATOR_LIBTHREAD 65 # include <sys/procfs.h> 66 # endif 67 68 #include <inttypes.h> 69 70 // Solaris 8 doesn't provide definitions of these 71 #ifdef SOLARIS 72 #ifndef PRIdPTR 73 #if defined(_LP64) 74 #define PRIdPTR "ld" 75 #define PRIuPTR "lu" 76 #define PRIxPTR "lx" 77 #else 78 #define PRIdPTR "d" 79 #define PRIuPTR "u" 80 #define PRIxPTR "x" 81 #endif 82 #endif 83 #endif 84 85 #ifdef LINUX 86 # include <signal.h> 87 # include <ucontext.h> 88 # include <sys/time.h> 89 #endif 90 91 92 // 4810578: varargs unsafe on 32-bit integer/64-bit pointer architectures 93 // When __cplusplus is defined, NULL is defined as 0 (32-bit constant) in 94 // system header files. On 32-bit architectures, there is no problem. 95 // On 64-bit architectures, defining NULL as a 32-bit constant can cause 96 // problems with varargs functions: C++ integral promotion rules say for 97 // varargs, we pass the argument 0 as an int. So, if NULL was passed to a 98 // varargs function it will remain 32-bits. Depending on the calling 99 // convention of the machine, if the argument is passed on the stack then 100 // only 32-bits of the "NULL" pointer may be initialized to zero. The 101 // other 32-bits will be garbage. If the varargs function is expecting a 102 // pointer when it extracts the argument, then we have a problem. 103 // 104 // Solution: For 64-bit architectures, redefine NULL as 64-bit constant 0. 105 // 106 // Note: this fix doesn't work well on Linux because NULL will be overwritten 107 // whenever a system header file is included. Linux handles NULL correctly 108 // through a special type '__null'. 109 #ifdef SOLARIS 110 #ifdef _LP64 111 #undef NULL 112 #define NULL 0L 113 #else 114 #ifndef NULL 115 #define NULL 0 116 #endif 117 #endif 118 #endif 119 120 // NULL vs NULL_WORD: 121 // On Linux NULL is defined as a special type '__null'. Assigning __null to 122 // integer variable will cause gcc warning. Use NULL_WORD in places where a 123 // pointer is stored as integer value. On some platforms, sizeof(intptr_t) > 124 // sizeof(void*), so here we want something which is integer type, but has the 125 // same size as a pointer. 126 #ifdef LINUX 127 #ifdef _LP64 128 #define NULL_WORD 0L 129 #else 130 // Cast 0 to intptr_t rather than int32_t since they are not the same type 131 // on some platforms. 132 #define NULL_WORD ((intptr_t)0) 133 #endif 134 #else 135 #define NULL_WORD NULL 136 #endif 137 138 #ifndef LINUX 139 // Compiler-specific primitive types 140 typedef unsigned short uint16_t; 141 #ifndef _UINT32_T 142 #define _UINT32_T 143 typedef unsigned int uint32_t; 144 #endif 145 #if !defined(_SYS_INT_TYPES_H) 146 #ifndef _UINT64_T 147 #define _UINT64_T 148 typedef unsigned long long uint64_t; 149 #endif 150 // %%%% how to access definition of intptr_t portably in 5.5 onward? 151 typedef int intptr_t; 152 typedef unsigned int uintptr_t; 153 // If this gets an error, figure out a symbol XXX that implies the 154 // prior definition of intptr_t, and add "&& !defined(XXX)" above. 155 #endif 156 #endif 157 158 // On solaris 8, UINTPTR_MAX is defined as empty. 159 // Everywhere else it's an actual value. 160 #if UINTPTR_MAX - 1 == -1 161 #undef UINTPTR_MAX 162 #ifdef _LP64 163 #define UINTPTR_MAX UINT64_MAX 164 #else 165 #define UINTPTR_MAX UINT32_MAX 166 #endif /* ifdef _LP64 */ 167 #endif 168 169 // Additional Java basic types 170 171 typedef unsigned char jubyte; 172 typedef unsigned short jushort; 173 typedef unsigned int juint; 174 typedef unsigned long long julong; 175 176 177 #ifdef SOLARIS 178 //---------------------------------------------------------------------------------------------------- 179 // ANSI C++ fixes 180 // NOTE:In the ANSI committee's continuing attempt to make each version 181 // of C++ incompatible with the previous version, you can no longer cast 182 // pointers to functions without specifying linkage unless you want to get 183 // warnings. 184 // 185 // This also means that pointers to functions can no longer be "hidden" 186 // in opaque types like void * because at the invokation point warnings 187 // will be generated. While this makes perfect sense from a type safety 188 // point of view it causes a lot of warnings on old code using C header 189 // files. Here are some typedefs to make the job of silencing warnings 190 // a bit easier. 191 // 192 // The final kick in the teeth is that you can only have extern "C" linkage 193 // specified at file scope. So these typedefs are here rather than in the 194 // .hpp for the class (os:Solaris usually) that needs them. 195 196 extern "C" { 197 typedef int (*int_fnP_thread_t_iP_uP_stack_tP_gregset_t)(thread_t, int*, unsigned *, stack_t*, gregset_t); 198 typedef int (*int_fnP_thread_t_i_gregset_t)(thread_t, int, gregset_t); 199 typedef int (*int_fnP_thread_t_i)(thread_t, int); 200 typedef int (*int_fnP_thread_t)(thread_t); 201 202 typedef int (*int_fnP_cond_tP_mutex_tP_timestruc_tP)(cond_t *cv, mutex_t *mx, timestruc_t *abst); 203 typedef int (*int_fnP_cond_tP_mutex_tP)(cond_t *cv, mutex_t *mx); 204 205 // typedef for missing API in libc 206 typedef int (*int_fnP_mutex_tP_i_vP)(mutex_t *, int, void *); 207 typedef int (*int_fnP_mutex_tP)(mutex_t *); 208 typedef int (*int_fnP_cond_tP_i_vP)(cond_t *cv, int scope, void *arg); 209 typedef int (*int_fnP_cond_tP)(cond_t *cv); 210 }; 211 #endif 212 213 //---------------------------------------------------------------------------------------------------- 214 // Debugging 215 216 #define DEBUG_EXCEPTION ::abort(); 217 218 extern "C" void breakpoint(); 219 #define BREAKPOINT ::breakpoint() 220 221 // checking for nanness 222 #ifdef SOLARIS 223 #ifdef SPARC 224 inline int g_isnan(float f) { return isnanf(f); } 225 #else 226 // isnanf() broken on Intel Solaris use isnand() 227 inline int g_isnan(float f) { return isnand(f); } 228 #endif 229 230 inline int g_isnan(double f) { return isnand(f); } 231 #elif LINUX 232 inline int g_isnan(float f) { return isnanf(f); } 233 inline int g_isnan(double f) { return isnan(f); } 234 #else 235 #error "missing platform-specific definition here" 236 #endif 237 238 // Checking for finiteness 239 240 inline int g_isfinite(jfloat f) { return finite(f); } 241 inline int g_isfinite(jdouble f) { return finite(f); } 242 243 244 // Wide characters 245 246 inline int wcslen(const jchar* x) { return wcslen((const wchar_t*)x); } 247 248 // Portability macros 249 #define PRAGMA_INTERFACE 250 #define PRAGMA_IMPLEMENTATION 251 #define PRAGMA_IMPLEMENTATION_(arg) 252 #define VALUE_OBJ_CLASS_SPEC : public _ValueObj 253 254 // Formatting. 255 #ifdef _LP64 256 #define FORMAT64_MODIFIER "l" 257 #else // !_LP64 258 #define FORMAT64_MODIFIER "ll" 259 #endif // _LP64 260 261 #define offset_of(klass,field) offsetof(klass,field) 262 263 #ifndef USE_LIBRARY_BASED_TLS_ONLY 264 #define THREAD_LOCAL_DECL __thread 265 #endif 266 267 // Inlining support 268 #define NOINLINE 269 #define ALWAYSINLINE inline __attribute__((always_inline)) 270 271 #endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_SPARCWORKS_HPP