globalDefinitions_sparcWorks.hpp revision 11743:ae67f85487cb
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
140typedef unsigned short     uint16_t;
141#ifndef _UINT32_T
142#define _UINT32_T
143typedef unsigned int       uint32_t;
144#endif
145#if !defined(_SYS_INT_TYPES_H)
146#ifndef _UINT64_T
147#define _UINT64_T
148typedef unsigned long long uint64_t;
149#endif
150// %%%% how to access definition of intptr_t portably in 5.5 onward?
151typedef int                     intptr_t;
152typedef 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
171typedef unsigned char      jubyte;
172typedef unsigned short     jushort;
173typedef unsigned int       juint;
174typedef unsigned long long julong;
175
176
177//----------------------------------------------------------------------------------------------------
178// Constant for jlong (specifying a long long constant is C++ compiler specific)
179
180// Build a 64bit integer constant
181#define CONST64(x)  (x ## LL)
182#define UCONST64(x) (x ## ULL)
183
184const jlong min_jlong = CONST64(0x8000000000000000);
185const jlong max_jlong = CONST64(0x7fffffffffffffff);
186
187#ifdef SOLARIS
188//----------------------------------------------------------------------------------------------------
189// ANSI C++ fixes
190// NOTE:In the ANSI committee's continuing attempt to make each version
191// of C++ incompatible with the previous version, you can no longer cast
192// pointers to functions without specifying linkage unless you want to get
193// warnings.
194//
195// This also means that pointers to functions can no longer be "hidden"
196// in opaque types like void * because at the invokation point warnings
197// will be generated. While this makes perfect sense from a type safety
198// point of view it causes a lot of warnings on old code using C header
199// files. Here are some typedefs to make the job of silencing warnings
200// a bit easier.
201//
202// The final kick in the teeth is that you can only have extern "C" linkage
203// specified at file scope. So these typedefs are here rather than in the
204// .hpp for the class (os:Solaris usually) that needs them.
205
206extern "C" {
207   typedef int (*int_fnP_thread_t_iP_uP_stack_tP_gregset_t)(thread_t, int*, unsigned *, stack_t*, gregset_t);
208   typedef int (*int_fnP_thread_t_i_gregset_t)(thread_t, int, gregset_t);
209   typedef int (*int_fnP_thread_t_i)(thread_t, int);
210   typedef int (*int_fnP_thread_t)(thread_t);
211
212   typedef int (*int_fnP_cond_tP_mutex_tP_timestruc_tP)(cond_t *cv, mutex_t *mx, timestruc_t *abst);
213   typedef int (*int_fnP_cond_tP_mutex_tP)(cond_t *cv, mutex_t *mx);
214
215   // typedef for missing API in libc
216   typedef int (*int_fnP_mutex_tP_i_vP)(mutex_t *, int, void *);
217   typedef int (*int_fnP_mutex_tP)(mutex_t *);
218   typedef int (*int_fnP_cond_tP_i_vP)(cond_t *cv, int scope, void *arg);
219   typedef int (*int_fnP_cond_tP)(cond_t *cv);
220};
221#endif
222
223//----------------------------------------------------------------------------------------------------
224// Debugging
225
226#define DEBUG_EXCEPTION ::abort();
227
228extern "C" void breakpoint();
229#define BREAKPOINT ::breakpoint()
230
231// checking for nanness
232#ifdef SOLARIS
233#ifdef SPARC
234inline int g_isnan(float  f) { return isnanf(f); }
235#else
236// isnanf() broken on Intel Solaris use isnand()
237inline int g_isnan(float  f) { return isnand(f); }
238#endif
239
240inline int g_isnan(double f) { return isnand(f); }
241#elif LINUX
242inline int g_isnan(float  f) { return isnanf(f); }
243inline int g_isnan(double f) { return isnan(f); }
244#else
245#error "missing platform-specific definition here"
246#endif
247
248// Checking for finiteness
249
250inline int g_isfinite(jfloat  f)                 { return finite(f); }
251inline int g_isfinite(jdouble f)                 { return finite(f); }
252
253
254// Wide characters
255
256inline int wcslen(const jchar* x) { return wcslen((const wchar_t*)x); }
257
258// Portability macros
259#define PRAGMA_INTERFACE
260#define PRAGMA_IMPLEMENTATION
261#define PRAGMA_IMPLEMENTATION_(arg)
262#define VALUE_OBJ_CLASS_SPEC    : public _ValueObj
263
264// Formatting.
265#ifdef _LP64
266#define FORMAT64_MODIFIER "l"
267#else // !_LP64
268#define FORMAT64_MODIFIER "ll"
269#endif // _LP64
270
271#define offset_of(klass,field) offsetof(klass,field)
272
273#ifndef USE_LIBRARY_BASED_TLS_ONLY
274#define THREAD_LOCAL_DECL __thread
275#endif
276
277// Inlining support
278#define NOINLINE
279#define ALWAYSINLINE inline __attribute__((always_inline))
280
281#endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_SPARCWORKS_HPP
282