0N/A/*
3362N/A * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_UTILITIES_GLOBALDEFINITIONS_GCC_HPP
1879N/A#define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_GCC_HPP
1879N/A
1879N/A#include "prims/jni.h"
1879N/A
0N/A// This file holds compiler-dependent includes,
0N/A// globally used constants & types, class (forward)
0N/A// declarations and a few frequently used utility functions.
0N/A
0N/A#include <ctype.h>
0N/A#include <string.h>
0N/A#include <stdarg.h>
0N/A#include <stddef.h>
0N/A#include <stdio.h>
0N/A#include <stdlib.h>
0N/A#include <wchar.h>
0N/A
0N/A#ifdef SOLARIS
0N/A#include <ieeefp.h>
0N/A#endif // SOLARIS
0N/A
0N/A#include <math.h>
0N/A#ifndef FP_PZERO
0N/A// Linux doesn't have positive/negative zero
0N/A#define FP_PZERO FP_ZERO
0N/A#endif
0N/A#if (!defined fpclass) && ((!defined SPARC) || (!defined SOLARIS))
0N/A#define fpclass fpclassify
0N/A#endif
0N/A
0N/A#include <time.h>
0N/A#include <fcntl.h>
0N/A#include <dlfcn.h>
0N/A#include <pthread.h>
0N/A
0N/A#ifdef SOLARIS
0N/A#include <thread.h>
0N/A#endif // SOLARIS
0N/A
0N/A#include <limits.h>
0N/A#include <errno.h>
0N/A
0N/A#ifdef SOLARIS
0N/A#include <sys/trap.h>
0N/A#include <sys/regset.h>
0N/A#include <sys/procset.h>
0N/A#include <ucontext.h>
0N/A#include <setjmp.h>
0N/A#endif // SOLARIS
0N/A
0N/A# ifdef SOLARIS_MUTATOR_LIBTHREAD
0N/A# include <sys/procfs.h>
0N/A# endif
0N/A
2796N/A#if defined(LINUX) || defined(_ALLBSD_SOURCE)
2294N/A#ifndef __STDC_LIMIT_MACROS
2154N/A#define __STDC_LIMIT_MACROS
2294N/A#endif // __STDC_LIMIT_MACROS
0N/A#include <inttypes.h>
0N/A#include <signal.h>
2796N/A#ifndef __OpenBSD__
0N/A#include <ucontext.h>
2796N/A#endif
2796N/A#ifdef __APPLE__
2796N/A #include <AvailabilityMacros.h>
3362N/A #include <mach/mach.h>
2796N/A#endif
0N/A#include <sys/time.h>
2796N/A#endif // LINUX || _ALLBSD_SOURCE
0N/A
0N/A// 4810578: varargs unsafe on 32-bit integer/64-bit pointer architectures
0N/A// When __cplusplus is defined, NULL is defined as 0 (32-bit constant) in
0N/A// system header files. On 32-bit architectures, there is no problem.
0N/A// On 64-bit architectures, defining NULL as a 32-bit constant can cause
0N/A// problems with varargs functions: C++ integral promotion rules say for
0N/A// varargs, we pass the argument 0 as an int. So, if NULL was passed to a
0N/A// varargs function it will remain 32-bits. Depending on the calling
0N/A// convention of the machine, if the argument is passed on the stack then
0N/A// only 32-bits of the "NULL" pointer may be initialized to zero. The
0N/A// other 32-bits will be garbage. If the varargs function is expecting a
0N/A// pointer when it extracts the argument, then we have a problem.
0N/A//
0N/A// Solution: For 64-bit architectures, redefine NULL as 64-bit constant 0.
0N/A//
0N/A// Note: this fix doesn't work well on Linux because NULL will be overwritten
0N/A// whenever a system header file is included. Linux handles NULL correctly
0N/A// through a special type '__null'.
0N/A#ifdef SOLARIS
0N/A #ifdef _LP64
0N/A #undef NULL
0N/A #define NULL 0L
0N/A #else
0N/A #ifndef NULL
0N/A #define NULL 0
0N/A #endif
0N/A #endif
0N/A#endif
0N/A
0N/A// NULL vs NULL_WORD:
0N/A// On Linux NULL is defined as a special type '__null'. Assigning __null to
0N/A// integer variable will cause gcc warning. Use NULL_WORD in places where a
0N/A// pointer is stored as integer value. On some platforms, sizeof(intptr_t) >
0N/A// sizeof(void*), so here we want something which is integer type, but has the
0N/A// same size as a pointer.
2796N/A#ifdef __GNUC__
0N/A #ifdef _LP64
0N/A #define NULL_WORD 0L
0N/A #else
512N/A // Cast 0 to intptr_t rather than int32_t since they are not the same type
512N/A // on platforms such as Mac OS X.
512N/A #define NULL_WORD ((intptr_t)0)
0N/A #endif
0N/A#else
0N/A #define NULL_WORD NULL
0N/A#endif
0N/A
2796N/A#if !defined(LINUX) && !defined(_ALLBSD_SOURCE)
0N/A// Compiler-specific primitive types
0N/Atypedef unsigned short uint16_t;
0N/A#ifndef _UINT32_T
0N/A#define _UINT32_T
0N/Atypedef unsigned int uint32_t;
0N/A#endif // _UINT32_T
0N/A
0N/A#if !defined(_SYS_INT_TYPES_H)
0N/A#ifndef _UINT64_T
0N/A#define _UINT64_T
0N/Atypedef unsigned long long uint64_t;
0N/A#endif // _UINT64_T
0N/A// %%%% how to access definition of intptr_t portably in 5.5 onward?
0N/Atypedef int intptr_t;
0N/Atypedef unsigned int uintptr_t;
0N/A// If this gets an error, figure out a symbol XXX that implies the
0N/A// prior definition of intptr_t, and add "&& !defined(XXX)" above.
0N/A#endif // _SYS_INT_TYPES_H
0N/A
2796N/A#endif // !LINUX && !_ALLBSD_SOURCE
0N/A
0N/A// Additional Java basic types
0N/A
0N/Atypedef uint8_t jubyte;
0N/Atypedef uint16_t jushort;
0N/Atypedef uint32_t juint;
0N/Atypedef uint64_t julong;
0N/A
0N/A//----------------------------------------------------------------------------------------------------
0N/A// Special (possibly not-portable) casts
0N/A// Cast floats into same-size integers and vice-versa w/o changing bit-pattern
0N/A// %%%%%% These seem like standard C++ to me--how about factoring them out? - Ungar
0N/A
0N/Ainline jint jint_cast (jfloat x) { return *(jint* )&x; }
0N/Ainline jlong jlong_cast (jdouble x) { return *(jlong* )&x; }
0N/A
0N/Ainline jfloat jfloat_cast (jint x) { return *(jfloat* )&x; }
0N/Ainline jdouble jdouble_cast(jlong x) { return *(jdouble*)&x; }
0N/A
0N/A//----------------------------------------------------------------------------------------------------
0N/A// Constant for jlong (specifying an long long canstant is C++ compiler specific)
0N/A
0N/A// Build a 64bit integer constant
0N/A#define CONST64(x) (x ## LL)
0N/A#define UCONST64(x) (x ## ULL)
0N/A
0N/Aconst jlong min_jlong = CONST64(0x8000000000000000);
0N/Aconst jlong max_jlong = CONST64(0x7fffffffffffffff);
0N/A
0N/A
0N/A#ifdef SOLARIS
0N/A//----------------------------------------------------------------------------------------------------
0N/A// ANSI C++ fixes
0N/A// NOTE:In the ANSI committee's continuing attempt to make each version
0N/A// of C++ incompatible with the previous version, you can no longer cast
0N/A// pointers to functions without specifying linkage unless you want to get
0N/A// warnings.
0N/A//
0N/A// This also means that pointers to functions can no longer be "hidden"
0N/A// in opaque types like void * because at the invokation point warnings
0N/A// will be generated. While this makes perfect sense from a type safety
0N/A// point of view it causes a lot of warnings on old code using C header
0N/A// files. Here are some typedefs to make the job of silencing warnings
0N/A// a bit easier.
0N/A//
0N/A// The final kick in the teeth is that you can only have extern "C" linkage
0N/A// specified at file scope. So these typedefs are here rather than in the
0N/A// .hpp for the class (os:Solaris usually) that needs them.
0N/A
0N/Aextern "C" {
0N/A typedef int (*int_fnP_thread_t_iP_uP_stack_tP_gregset_t)(thread_t, int*, unsigned *, stack_t*, gregset_t);
0N/A typedef int (*int_fnP_thread_t_i_gregset_t)(thread_t, int, gregset_t);
0N/A typedef int (*int_fnP_thread_t_i)(thread_t, int);
0N/A typedef int (*int_fnP_thread_t)(thread_t);
0N/A
0N/A typedef int (*int_fnP_cond_tP_mutex_tP_timestruc_tP)(cond_t *cv, mutex_t *mx, timestruc_t *abst);
0N/A typedef int (*int_fnP_cond_tP_mutex_tP)(cond_t *cv, mutex_t *mx);
0N/A
0N/A // typedef for missing API in libc
0N/A typedef int (*int_fnP_mutex_tP_i_vP)(mutex_t *, int, void *);
0N/A typedef int (*int_fnP_mutex_tP)(mutex_t *);
0N/A typedef int (*int_fnP_cond_tP_i_vP)(cond_t *cv, int scope, void *arg);
0N/A typedef int (*int_fnP_cond_tP)(cond_t *cv);
0N/A};
0N/A#endif // SOLARIS
0N/A
0N/A//----------------------------------------------------------------------------------------------------
0N/A// Debugging
0N/A
0N/A#define DEBUG_EXCEPTION ::abort();
0N/A
1601N/A#ifdef ARM
1601N/A#ifdef SOLARIS
1601N/A#define BREAKPOINT __asm__ volatile (".long 0xe1200070")
1601N/A#else
1601N/A#define BREAKPOINT __asm__ volatile (".long 0xe7f001f0")
1601N/A#endif
1601N/A#else
0N/Aextern "C" void breakpoint();
0N/A#define BREAKPOINT ::breakpoint()
1601N/A#endif
0N/A
0N/A// checking for nanness
0N/A#ifdef SOLARIS
0N/A#ifdef SPARC
0N/Ainline int g_isnan(float f) { return isnanf(f); }
0N/A#else
0N/A// isnanf() broken on Intel Solaris use isnand()
0N/Ainline int g_isnan(float f) { return isnand(f); }
0N/A#endif
0N/Ainline int g_isnan(double f) { return isnand(f); }
2796N/A#elif defined(__APPLE__)
2796N/Ainline int g_isnan(double f) { return isnan(f); }
2796N/A#elif defined(LINUX) || defined(_ALLBSD_SOURCE)
0N/Ainline int g_isnan(float f) { return isnanf(f); }
0N/Ainline int g_isnan(double f) { return isnan(f); }
0N/A#else
0N/A#error "missing platform-specific definition here"
0N/A#endif
0N/A
1601N/A// GCC 4.3 does not allow 0.0/0.0 to produce a NAN value
1601N/A#if (__GNUC__ == 4) && (__GNUC_MINOR__ > 2)
1601N/A#define CAN_USE_NAN_DEFINE 1
1601N/A#endif
1601N/A
1601N/A
0N/A// Checking for finiteness
0N/A
0N/Ainline int g_isfinite(jfloat f) { return finite(f); }
0N/Ainline int g_isfinite(jdouble f) { return finite(f); }
0N/A
0N/A
0N/A// Wide characters
0N/A
0N/Ainline int wcslen(const jchar* x) { return wcslen((const wchar_t*)x); }
0N/A
0N/A
0N/A// Portability macros
0N/A#define PRAGMA_INTERFACE #pragma interface
0N/A#define PRAGMA_IMPLEMENTATION #pragma implementation
0N/A#define VALUE_OBJ_CLASS_SPEC
0N/A
0N/A#if (__GNUC__ == 2) && (__GNUC_MINOR__ < 95)
0N/A#define TEMPLATE_TABLE_BUG
0N/A#endif
0N/A#if (__GNUC__ == 2) && (__GNUC_MINOR__ >= 96)
0N/A#define CONST_SDM_BUG
0N/A#endif
0N/A
0N/A// Formatting.
0N/A#ifdef _LP64
0N/A#define FORMAT64_MODIFIER "l"
0N/A#else // !_LP64
0N/A#define FORMAT64_MODIFIER "ll"
0N/A#endif // _LP64
0N/A
0N/A// HACK: gcc warns about applying offsetof() to non-POD object or calculating
0N/A// offset directly when base address is NULL. Use 16 to get around the
0N/A// warning. gcc-3.4 has an option -Wno-invalid-offsetof to suppress
0N/A// this warning.
0N/A#define offset_of(klass,field) (size_t)((intx)&(((klass*)16)->field) - 16)
0N/A
0N/A#ifdef offsetof
0N/A# undef offsetof
0N/A#endif
0N/A#define offsetof(klass,field) offset_of(klass,field)
1879N/A
1879N/A#endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_GCC_HPP