1 /*
   2  * Copyright (c) 1997, 2010, 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_LIBADT_PORT_HPP
  26 #define SHARE_VM_LIBADT_PORT_HPP
  27 
  28 #include "utilities/top.hpp"
  29 
  30 // Typedefs for portable compiling
  31 
  32 #if defined(__GNUC__)
  33 
  34 #define INTERFACE       #pragma interface
  35 #define IMPLEMENTATION  #pragma implementation
  36 //INTERFACE
  37 #include <stddef.h>
  38 #include <stdlib.h>
  39 #include <string.h>
  40 
  41 // Access to the C++ class virtual function pointer
  42 // Put the class in the macro
  43 typedef void *VPTR;
  44 // G++ puts it at the end of the base class
  45 #define ACCESS_VPTR(class) VPTR&vptr(){return*(VPTR*)((char*)this+sizeof(class)-sizeof(void*));}
  46 
  47 #elif defined(__TURBOC__)
  48 
  49 #include <mem.h>
  50 #include <string.h>
  51 extern "C" int stricmp(const char *, const char *);
  52 inline void bcopy(const void *s, void *d, int l) { memmove(d,s,l); }
  53 inline void bzero(void *p, int l) { memset(p,0,l); }
  54 inline int bcmp(const void *s, const void *d, int l) { return memcmp(s,d,l); }
  55 inline int min( int a, int b) { return a < b ? a : b; }
  56 inline int max( int a, int b) { return a > b ? a : b; }
  57 //strcasecmp moved to globalDefinitions_visCPP.hpp
  58 //inline int strcasecmp(const char *s1, const char *s2) { return stricmp(s1,s2); }
  59 inline long abs( long x ) { return x < 0 ? -x : x; }
  60 // Access to the C++ class virtual function pointer
  61 // Put the class in the macro
  62 typedef void near *VPTR;
  63 // BorlandC puts it up front
  64 #define ACCESS_VPTR(class) VPTR&vptr(){return*(VPTR*)this;}
  65 
  66 #elif defined(__hpux)
  67 
  68 #define INTERFACE
  69 #define IMPLEMENTATION
  70 #define signed
  71 #include <strings.h>
  72 #include <stdlib.h>
  73 inline long min( long a, long b) { return a < b ? a : b; }
  74 inline long max( long a, long b) { return a > b ? a : b; }
  75 inline int min( int a, int b) { return a < b ? a : b; }
  76 inline int max( int a, int b) { return a > b ? a : b; }
  77 inline long abs( long x ) { return x < 0 ? -x : x; }
  78 
  79 #elif defined(__MOTO__)
  80 // Motorola's mcc
  81 #define INTERFACE
  82 #define IMPLEMENTATION
  83 #include <stdlib.h>
  84 #include <memory.h>
  85 inline int min( int a, int b) { return a < b ? a : b; }
  86 inline int max( int a, int b) { return a > b ? a : b; }
  87 
  88 #elif defined(_AIX)
  89 // IBM's xlC compiler
  90 #define INTERFACE
  91 #define IMPLEMENTATION
  92 #include <stdlib.h>
  93 #include <memory.h>
  94 inline int min( int a, int b) { return a < b ? a : b; }
  95 inline int max( int a, int b) { return a > b ? a : b; }
  96 
  97 #elif defined(_MSC_VER)
  98 // Microsoft Visual C++
  99 //#define INTERFACE
 100 #define IMPLEMENTATION
 101 #include <stdlib.h>
 102 #undef small
 103 //strcasecmp moved to globalDefinitions_visCPP.hpp
 104 //inline int strcasecmp(const char *s1, const char *s2) { return stricmp(s1,s2); }
 105 
 106 
 107 #elif defined(SPARC_WORKS)
 108 
 109 #define INTERFACE
 110 #define IMPLEMENTATION
 111 
 112 #include <stddef.h>
 113 #include <stdlib.h>
 114 #include <string.h>
 115 
 116 #elif defined(SOLARIS)
 117 
 118 #define INTERFACE
 119 #define IMPLEMENTATION
 120 
 121 #include <stddef.h>
 122 #include <stdlib.h>
 123 #include <string.h>
 124 
 125 
 126 #elif defined(__TANDEM)
 127 
 128 // This case is for the Tandem Business Unit of Compaq Computer Corporation.
 129 // The Tandem case must precede the AT&T case,
 130 // because the Tandem c89 compiler also defines __cplusplus.
 131 
 132 #include "port_tandem.hpp"
 133 
 134 #elif defined(__cplusplus)
 135 // AT&Ts cfront
 136 #define INTERFACE
 137 #define IMPLEMENTATION
 138 #include <unistd.h>
 139 #define signed
 140 // #include <bstring.h>
 141 inline int min( int a, int b) { return a < b ? a : b; }
 142 inline int max( int a, int b) { return a > b ? a : b; }
 143 
 144 #else  // All other machines
 145 
 146 #define signed
 147 extern "C" void bcopy(void *b1, void *b2, int len);
 148 inline int min( int a, int b) { return a < b ? a : b; }
 149 inline int max( int a, int b) { return a > b ? a : b; }
 150 
 151 #endif
 152 
 153 //-----------------------------------------------------------------------------
 154 // Safer memory allocations
 155 #ifdef SAFE_MEMORY
 156 #define malloc(size)        safe_malloc(__FILE__,__LINE__,size)
 157 #define free(ptr)           safe_free(__FILE__,__LINE__,ptr)
 158 #define realloc(ptr,size)   safe_realloc(__FILE__,__LINE__,ptr,size)
 159 #define calloc(nitems,size) safe_calloc(__FILE__,__LINE__,nitems,size)
 160 #define strdup(ptr)         safe_strdup(__FILE__,__LINE__,ptr)
 161 extern void *safe_malloc (const char *file, unsigned line, unsigned size);
 162 extern void  safe_free   (const char *file, unsigned line, void *ptr);
 163 extern void *safe_calloc (const char *file, unsigned line, unsigned nitems, unsigned size);
 164 extern void *safe_realloc(const char *file, unsigned line, void *ptr, unsigned size);
 165 extern char *safe_strdup (const char *file, unsigned line, const char *src);
 166 inline void *operator new( size_t size ) { return malloc(size); }
 167 inline void operator delete( void *ptr ) { free(ptr); }
 168 #endif
 169 
 170 //-----------------------------------------------------------------------------
 171 // And now, the bit-size-specified integer sizes
 172 typedef signed char int8;
 173 typedef unsigned char uint8;
 174 typedef unsigned char byte;
 175 
 176 // All uses of *int16 changed to 32-bit to speed up compiler on Intel
 177 //typedef signed short int16;   // Exactly 16bits signed
 178 //typedef unsigned short uint16;        // Exactly 16bits unsigned
 179 //const unsigned int min_uint16 = 0x0000;    // smallest uint16
 180 //const unsigned int max_uint16 = 0xFFFF;    // largest  uint16
 181 
 182 typedef unsigned int uint;      // When you need a fast >=16bit unsigned value
 183 /*typedef int int; */           // When you need a fast >=16bit value
 184 const unsigned int max_uint = (uint)-1;
 185 typedef int32_t int32;   // Exactly 32bits signed
 186 typedef uint32_t uint32; // Exactly 32bits unsigned
 187 
 188 // Bit-sized floating point and long thingies
 189 #ifndef __TANDEM
 190 // Do not define these for Tandem, because they conflict with typedefs in softieee.h.
 191 typedef float float32;          // 32-bit float
 192 typedef double float64;         // 64-bit float
 193 #endif // __TANDEM
 194 
 195 typedef jlong int64;            // Java long for my 64-bit type
 196 typedef julong uint64;          // Java long for my 64-bit type
 197 
 198 //-----------------------------------------------------------------------------
 199 // Nice constants
 200 uint32 gcd( uint32 x, uint32 y );
 201 int ff1( uint32 mask );
 202 int fh1( uint32 mask );
 203 uint32 rotate32( uint32 x, int32 cnt );
 204 
 205 
 206 //-----------------------------------------------------------------------------
 207 extern uint32 heap_totalmem;      // Current total memory allocation
 208 extern uint32 heap_highwater;     // Highwater mark to date for memory usage
 209 
 210 #endif // SHARE_VM_LIBADT_PORT_HPP