1 /*
   2  * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2012, 2019 SAP SE. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #ifndef SHARE_UTILITIES_GLOBALDEFINITIONS_XLC_HPP
  27 #define SHARE_UTILITIES_GLOBALDEFINITIONS_XLC_HPP
  28 
  29 #include "jni.h"
  30 
  31 // This file holds compiler-dependent includes,
  32 // globally used constants & types, class (forward)
  33 // declarations and a few frequently used utility functions.
  34 
  35 #include <ctype.h>
  36 #include <string.h>
  37 #include <stdarg.h>
  38 #include <stddef.h>
  39 #include <stdio.h>
  40 #include <stdlib.h>
  41 #include <wchar.h>
  42 
  43 #include <math.h>
  44 #include <time.h>
  45 #include <fcntl.h>
  46 #include <dlfcn.h>
  47 #include <pthread.h>
  48 
  49 #include <limits.h>
  50 #include <errno.h>
  51 
  52 #include <stdint.h>
  53 
  54 // __IBMCPP__ is not defined any more with xlclang++
  55 #ifdef __IBMCPP__ 
  56 #if __IBMCPP__ < 1200
  57 #error "xlc < 12 not supported"
  58 #endif
  59 #endif
  60 
  61 #ifndef _AIX
  62 #error "missing AIX-specific definition _AIX"
  63 #endif
  64 
  65 // Use XLC compiler builtins instead of inline assembler
  66 #define USE_XLC_BUILTINS
  67 
  68 #ifdef USE_XLC_BUILTINS
  69 #include <builtins.h>
  70 // XLC V10 and higher provide the prototype for __dcbtst (void *);
  71 #endif // USE_XLC_BUILTINS
  72 
  73 // NULL vs NULL_WORD:
  74 // Some platform/tool-chain combinations can't assign NULL to an integer
  75 // type so we define NULL_WORD to use in those contexts. For xlc they are the same.
  76 #define NULL_WORD  NULL
  77 
  78 // AIX also needs a 64 bit NULL to work as a null address pointer.
  79 // Most system includes on AIX would define it as an int 0 if not already defined with one
  80 // exception: /usr/include/dirent.h will unconditionally redefine NULL to int 0 again.
  81 // In this case you need to copy the following defines to a position after #include <dirent.h>
  82 #include <dirent.h>
  83 #ifdef _LP64
  84   #undef NULL
  85   #define NULL 0L
  86 #else
  87   #ifndef NULL
  88     #define NULL 0
  89   #endif
  90 #endif
  91 
  92 // Compiler-specific primitive types
  93 // All defs of int (uint16_6 etc) are defined in AIX' /usr/include/stdint.h
  94 
  95 // Additional Java basic types
  96 
  97 typedef uint8_t  jubyte;
  98 typedef uint16_t jushort;
  99 typedef uint32_t juint;
 100 typedef uint64_t julong;
 101 
 102 // checking for nanness
 103 inline int g_isnan(float  f) { return isnan(f); }
 104 inline int g_isnan(double f) { return isnan(f); }
 105 
 106 // Checking for finiteness
 107 inline int g_isfinite(jfloat  f)                 { return finite(f); }
 108 inline int g_isfinite(jdouble f)                 { return finite(f); }
 109 
 110 // Wide characters
 111 inline int wcslen(const jchar* x) { return wcslen((const wchar_t*)x); }
 112 
 113 
 114 // Formatting.
 115 #ifdef _LP64
 116 #define FORMAT64_MODIFIER "l"
 117 #else // !_LP64
 118 #define FORMAT64_MODIFIER "ll"
 119 #endif // _LP64
 120 
 121 // Cannot use xlc's offsetof as implementation of hotspot's
 122 // offset_of(), because xlc warns about applying offsetof() to non-POD
 123 // object and xlc cannot compile the expression offsetof(DataLayout,
 124 // _cells[index]) in DataLayout::cell_offset() .  Therefore we define
 125 // offset_of as it is defined for gcc.
 126 #define offset_of(klass,field) (size_t)((intx)&(((klass*)16)->field) - 16)
 127 
 128 // AIX 5.3 has buggy __thread support. (see JDK-8176442).
 129 #define USE_LIBRARY_BASED_TLS_ONLY 1
 130 
 131 #ifndef USE_LIBRARY_BASED_TLS_ONLY
 132 #define THREAD_LOCAL_DECL __thread
 133 #endif
 134 
 135 // Inlining support
 136 //
 137 // Be aware that for function/method declarations, xlC only supports the following
 138 // syntax (i.e. the attribute must be placed AFTER the function/method declarator):
 139 //
 140 //   void* operator new(size_t size) throw() NOINLINE;
 141 //
 142 // For function/method defintions, the more common placement BEFORE the
 143 // function/method declarator seems to be supported as well:
 144 //
 145 //   NOINLINE void* CHeapObj<F>::operator new(size_t size) throw() {...}
 146 
 147 #define NOINLINE     __attribute__((__noinline__))
 148 #define ALWAYSINLINE inline __attribute__((__always_inline__))
 149 
 150 #endif // SHARE_UTILITIES_GLOBALDEFINITIONS_XLC_HPP