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