1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/utilities/globalDefinitions_gcc.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,275 @@ 1.4 +/* 1.5 + * Copyright 1998-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// This file holds compiler-dependent includes, 1.29 +// globally used constants & types, class (forward) 1.30 +// declarations and a few frequently used utility functions. 1.31 + 1.32 +#include <ctype.h> 1.33 +#include <string.h> 1.34 +#include <stdarg.h> 1.35 +#include <stddef.h> 1.36 +#include <stdio.h> 1.37 +#include <stdlib.h> 1.38 +#include <wchar.h> 1.39 + 1.40 +#ifdef SOLARIS 1.41 +#include <ieeefp.h> 1.42 +#endif // SOLARIS 1.43 + 1.44 +#include <math.h> 1.45 +#ifndef FP_PZERO 1.46 +// Linux doesn't have positive/negative zero 1.47 +#define FP_PZERO FP_ZERO 1.48 +#endif 1.49 +#if (!defined fpclass) && ((!defined SPARC) || (!defined SOLARIS)) 1.50 +#define fpclass fpclassify 1.51 +#endif 1.52 + 1.53 +#include <time.h> 1.54 +#include <fcntl.h> 1.55 +#include <dlfcn.h> 1.56 +#include <pthread.h> 1.57 + 1.58 +#ifdef SOLARIS 1.59 +#include <thread.h> 1.60 +#endif // SOLARIS 1.61 + 1.62 +#include <limits.h> 1.63 +#include <errno.h> 1.64 + 1.65 +#ifdef SOLARIS 1.66 +#include <sys/trap.h> 1.67 +#include <sys/regset.h> 1.68 +#include <sys/procset.h> 1.69 +#include <ucontext.h> 1.70 +#include <setjmp.h> 1.71 +#endif // SOLARIS 1.72 + 1.73 +# ifdef SOLARIS_MUTATOR_LIBTHREAD 1.74 +# include <sys/procfs.h> 1.75 +# endif 1.76 + 1.77 +#ifdef LINUX 1.78 +#include <inttypes.h> 1.79 +#include <signal.h> 1.80 +#include <ucontext.h> 1.81 +#include <sys/time.h> 1.82 +#endif // LINUX 1.83 + 1.84 +// 4810578: varargs unsafe on 32-bit integer/64-bit pointer architectures 1.85 +// When __cplusplus is defined, NULL is defined as 0 (32-bit constant) in 1.86 +// system header files. On 32-bit architectures, there is no problem. 1.87 +// On 64-bit architectures, defining NULL as a 32-bit constant can cause 1.88 +// problems with varargs functions: C++ integral promotion rules say for 1.89 +// varargs, we pass the argument 0 as an int. So, if NULL was passed to a 1.90 +// varargs function it will remain 32-bits. Depending on the calling 1.91 +// convention of the machine, if the argument is passed on the stack then 1.92 +// only 32-bits of the "NULL" pointer may be initialized to zero. The 1.93 +// other 32-bits will be garbage. If the varargs function is expecting a 1.94 +// pointer when it extracts the argument, then we have a problem. 1.95 +// 1.96 +// Solution: For 64-bit architectures, redefine NULL as 64-bit constant 0. 1.97 +// 1.98 +// Note: this fix doesn't work well on Linux because NULL will be overwritten 1.99 +// whenever a system header file is included. Linux handles NULL correctly 1.100 +// through a special type '__null'. 1.101 +#ifdef SOLARIS 1.102 + #ifdef _LP64 1.103 + #undef NULL 1.104 + #define NULL 0L 1.105 + #else 1.106 + #ifndef NULL 1.107 + #define NULL 0 1.108 + #endif 1.109 + #endif 1.110 +#endif 1.111 + 1.112 +// NULL vs NULL_WORD: 1.113 +// On Linux NULL is defined as a special type '__null'. Assigning __null to 1.114 +// integer variable will cause gcc warning. Use NULL_WORD in places where a 1.115 +// pointer is stored as integer value. On some platforms, sizeof(intptr_t) > 1.116 +// sizeof(void*), so here we want something which is integer type, but has the 1.117 +// same size as a pointer. 1.118 +#ifdef LINUX 1.119 + #ifdef _LP64 1.120 + #define NULL_WORD 0L 1.121 + #else 1.122 + #define NULL_WORD 0 1.123 + #endif 1.124 +#else 1.125 + #define NULL_WORD NULL 1.126 +#endif 1.127 + 1.128 +#ifndef LINUX 1.129 +// Compiler-specific primitive types 1.130 +typedef unsigned short uint16_t; 1.131 +#ifndef _UINT32_T 1.132 +#define _UINT32_T 1.133 +typedef unsigned int uint32_t; 1.134 +#endif // _UINT32_T 1.135 + 1.136 +#if !defined(_SYS_INT_TYPES_H) 1.137 +#ifndef _UINT64_T 1.138 +#define _UINT64_T 1.139 +typedef unsigned long long uint64_t; 1.140 +#endif // _UINT64_T 1.141 +// %%%% how to access definition of intptr_t portably in 5.5 onward? 1.142 +typedef int intptr_t; 1.143 +typedef unsigned int uintptr_t; 1.144 +// If this gets an error, figure out a symbol XXX that implies the 1.145 +// prior definition of intptr_t, and add "&& !defined(XXX)" above. 1.146 +#endif // _SYS_INT_TYPES_H 1.147 + 1.148 +#endif // !LINUX 1.149 + 1.150 +// Additional Java basic types 1.151 + 1.152 +typedef uint8_t jubyte; 1.153 +typedef uint16_t jushort; 1.154 +typedef uint32_t juint; 1.155 +typedef uint64_t julong; 1.156 + 1.157 +//---------------------------------------------------------------------------------------------------- 1.158 +// Special (possibly not-portable) casts 1.159 +// Cast floats into same-size integers and vice-versa w/o changing bit-pattern 1.160 +// %%%%%% These seem like standard C++ to me--how about factoring them out? - Ungar 1.161 + 1.162 +inline jint jint_cast (jfloat x) { return *(jint* )&x; } 1.163 +inline jlong jlong_cast (jdouble x) { return *(jlong* )&x; } 1.164 + 1.165 +inline jfloat jfloat_cast (jint x) { return *(jfloat* )&x; } 1.166 +inline jdouble jdouble_cast(jlong x) { return *(jdouble*)&x; } 1.167 + 1.168 +//---------------------------------------------------------------------------------------------------- 1.169 +// Constant for jlong (specifying an long long canstant is C++ compiler specific) 1.170 + 1.171 +// Build a 64bit integer constant 1.172 +#define CONST64(x) (x ## LL) 1.173 +#define UCONST64(x) (x ## ULL) 1.174 + 1.175 +const jlong min_jlong = CONST64(0x8000000000000000); 1.176 +const jlong max_jlong = CONST64(0x7fffffffffffffff); 1.177 + 1.178 + 1.179 +#ifdef SOLARIS 1.180 +//---------------------------------------------------------------------------------------------------- 1.181 +// ANSI C++ fixes 1.182 +// NOTE:In the ANSI committee's continuing attempt to make each version 1.183 +// of C++ incompatible with the previous version, you can no longer cast 1.184 +// pointers to functions without specifying linkage unless you want to get 1.185 +// warnings. 1.186 +// 1.187 +// This also means that pointers to functions can no longer be "hidden" 1.188 +// in opaque types like void * because at the invokation point warnings 1.189 +// will be generated. While this makes perfect sense from a type safety 1.190 +// point of view it causes a lot of warnings on old code using C header 1.191 +// files. Here are some typedefs to make the job of silencing warnings 1.192 +// a bit easier. 1.193 +// 1.194 +// The final kick in the teeth is that you can only have extern "C" linkage 1.195 +// specified at file scope. So these typedefs are here rather than in the 1.196 +// .hpp for the class (os:Solaris usually) that needs them. 1.197 + 1.198 +extern "C" { 1.199 + typedef int (*int_fnP_thread_t_iP_uP_stack_tP_gregset_t)(thread_t, int*, unsigned *, stack_t*, gregset_t); 1.200 + typedef int (*int_fnP_thread_t_i_gregset_t)(thread_t, int, gregset_t); 1.201 + typedef int (*int_fnP_thread_t_i)(thread_t, int); 1.202 + typedef int (*int_fnP_thread_t)(thread_t); 1.203 + 1.204 + typedef int (*int_fnP_cond_tP_mutex_tP_timestruc_tP)(cond_t *cv, mutex_t *mx, timestruc_t *abst); 1.205 + typedef int (*int_fnP_cond_tP_mutex_tP)(cond_t *cv, mutex_t *mx); 1.206 + 1.207 + // typedef for missing API in libc 1.208 + typedef int (*int_fnP_mutex_tP_i_vP)(mutex_t *, int, void *); 1.209 + typedef int (*int_fnP_mutex_tP)(mutex_t *); 1.210 + typedef int (*int_fnP_cond_tP_i_vP)(cond_t *cv, int scope, void *arg); 1.211 + typedef int (*int_fnP_cond_tP)(cond_t *cv); 1.212 +}; 1.213 +#endif // SOLARIS 1.214 + 1.215 +//---------------------------------------------------------------------------------------------------- 1.216 +// Debugging 1.217 + 1.218 +#define DEBUG_EXCEPTION ::abort(); 1.219 + 1.220 +extern "C" void breakpoint(); 1.221 +#define BREAKPOINT ::breakpoint() 1.222 + 1.223 +// checking for nanness 1.224 +#ifdef SOLARIS 1.225 +#ifdef SPARC 1.226 +inline int g_isnan(float f) { return isnanf(f); } 1.227 +#else 1.228 +// isnanf() broken on Intel Solaris use isnand() 1.229 +inline int g_isnan(float f) { return isnand(f); } 1.230 +#endif 1.231 +inline int g_isnan(double f) { return isnand(f); } 1.232 +#elif LINUX 1.233 +inline int g_isnan(float f) { return isnanf(f); } 1.234 +inline int g_isnan(double f) { return isnan(f); } 1.235 +#else 1.236 +#error "missing platform-specific definition here" 1.237 +#endif 1.238 + 1.239 +// Checking for finiteness 1.240 + 1.241 +inline int g_isfinite(jfloat f) { return finite(f); } 1.242 +inline int g_isfinite(jdouble f) { return finite(f); } 1.243 + 1.244 + 1.245 +// Wide characters 1.246 + 1.247 +inline int wcslen(const jchar* x) { return wcslen((const wchar_t*)x); } 1.248 + 1.249 + 1.250 +// Portability macros 1.251 +#define PRAGMA_INTERFACE #pragma interface 1.252 +#define PRAGMA_IMPLEMENTATION #pragma implementation 1.253 +#define VALUE_OBJ_CLASS_SPEC 1.254 + 1.255 +#if (__GNUC__ == 2) && (__GNUC_MINOR__ < 95) 1.256 +#define TEMPLATE_TABLE_BUG 1.257 +#endif 1.258 +#if (__GNUC__ == 2) && (__GNUC_MINOR__ >= 96) 1.259 +#define CONST_SDM_BUG 1.260 +#endif 1.261 + 1.262 +// Formatting. 1.263 +#ifdef _LP64 1.264 +#define FORMAT64_MODIFIER "l" 1.265 +#else // !_LP64 1.266 +#define FORMAT64_MODIFIER "ll" 1.267 +#endif // _LP64 1.268 + 1.269 +// HACK: gcc warns about applying offsetof() to non-POD object or calculating 1.270 +// offset directly when base address is NULL. Use 16 to get around the 1.271 +// warning. gcc-3.4 has an option -Wno-invalid-offsetof to suppress 1.272 +// this warning. 1.273 +#define offset_of(klass,field) (size_t)((intx)&(((klass*)16)->field) - 16) 1.274 + 1.275 +#ifdef offsetof 1.276 +# undef offsetof 1.277 +#endif 1.278 +#define offsetof(klass,field) offset_of(klass,field)