src/share/vm/libadt/port.hpp

Wed, 09 Apr 2008 15:10:22 -0700

author
rasbold
date
Wed, 09 Apr 2008 15:10:22 -0700
changeset 544
9f4457a14b58
parent 435
a61af66fc99e
child 948
2328d1d3f8cf
permissions
-rw-r--r--

Merge

duke@435 1 /*
duke@435 2 * Copyright 1997-2003 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 #ifndef _PORT_
duke@435 26 #define _PORT_
duke@435 27 // Typedefs for portable compiling
duke@435 28
duke@435 29 #if defined(__GNUC__)
duke@435 30
duke@435 31 #define INTERFACE #pragma interface
duke@435 32 #define IMPLEMENTATION #pragma implementation
duke@435 33 //INTERFACE
duke@435 34 #include <stddef.h>
duke@435 35 #include <stdlib.h>
duke@435 36 #include <string.h>
duke@435 37 #undef bzero
duke@435 38 inline void bzero(void *b, int len) { memset(b,0,len); }
duke@435 39 #undef bcopy
duke@435 40 inline void bcopy(const void *s, void *d, size_t len) { memmove(d,s,len); }
duke@435 41 #undef bcmp
duke@435 42 inline int bcmp(const void *s,const void *t,int len) { return memcmp(s,t,len);}
duke@435 43 extern "C" unsigned long strtoul(const char *s, char **end, int base);
duke@435 44
duke@435 45 // Definition for sys_errlist varies from Sun 4.1 & Solaris.
duke@435 46 // We use the new Solaris definition.
duke@435 47 #include <string.h>
duke@435 48
duke@435 49 // Access to the C++ class virtual function pointer
duke@435 50 // Put the class in the macro
duke@435 51 typedef void *VPTR;
duke@435 52 // G++ puts it at the end of the base class
duke@435 53 #define ACCESS_VPTR(class) VPTR&vptr(){return*(VPTR*)((char*)this+sizeof(class)-sizeof(void*));}
duke@435 54
duke@435 55 #elif defined(__TURBOC__)
duke@435 56
duke@435 57 #include <mem.h>
duke@435 58 #include <string.h>
duke@435 59 extern "C" int stricmp(const char *, const char *);
duke@435 60 inline void bcopy(const void *s, void *d, int l) { memmove(d,s,l); }
duke@435 61 inline void bzero(void *p, int l) { memset(p,0,l); }
duke@435 62 inline int bcmp(const void *s, const void *d, int l) { return memcmp(s,d,l); }
duke@435 63 inline int min( int a, int b) { return a < b ? a : b; }
duke@435 64 inline int max( int a, int b) { return a > b ? a : b; }
duke@435 65 //strcasecmp moved to globalDefinitions_visCPP.hpp
duke@435 66 //inline int strcasecmp(const char *s1, const char *s2) { return stricmp(s1,s2); }
duke@435 67 inline long abs( long x ) { return x < 0 ? -x : x; }
duke@435 68 // Access to the C++ class virtual function pointer
duke@435 69 // Put the class in the macro
duke@435 70 typedef void near *VPTR;
duke@435 71 // BorlandC puts it up front
duke@435 72 #define ACCESS_VPTR(class) VPTR&vptr(){return*(VPTR*)this;}
duke@435 73
duke@435 74 #elif defined(__hpux)
duke@435 75
duke@435 76 #define INTERFACE
duke@435 77 #define IMPLEMENTATION
duke@435 78 #define signed
duke@435 79 #include <strings.h>
duke@435 80 #include <stdlib.h>
duke@435 81 inline long min( long a, long b) { return a < b ? a : b; }
duke@435 82 inline long max( long a, long b) { return a > b ? a : b; }
duke@435 83 inline int min( int a, int b) { return a < b ? a : b; }
duke@435 84 inline int max( int a, int b) { return a > b ? a : b; }
duke@435 85 inline long abs( long x ) { return x < 0 ? -x : x; }
duke@435 86
duke@435 87 #elif defined(__MOTO__)
duke@435 88 // Motorola's mcc
duke@435 89 #define INTERFACE
duke@435 90 #define IMPLEMENTATION
duke@435 91 #include <stdlib.h>
duke@435 92 #include <memory.h>
duke@435 93 inline int min( int a, int b) { return a < b ? a : b; }
duke@435 94 inline int max( int a, int b) { return a > b ? a : b; }
duke@435 95
duke@435 96 #elif defined(_AIX)
duke@435 97 // IBM's xlC compiler
duke@435 98 #define INTERFACE
duke@435 99 #define IMPLEMENTATION
duke@435 100 #include <stdlib.h>
duke@435 101 #include <memory.h>
duke@435 102 inline int min( int a, int b) { return a < b ? a : b; }
duke@435 103 inline int max( int a, int b) { return a > b ? a : b; }
duke@435 104
duke@435 105 #elif defined(_MSC_VER)
duke@435 106 // Microsoft Visual C++
duke@435 107 //#define INTERFACE
duke@435 108 #define IMPLEMENTATION
duke@435 109 #include <stdlib.h>
duke@435 110 #undef small
duke@435 111 //strcasecmp moved to globalDefinitions_visCPP.hpp
duke@435 112 //inline int strcasecmp(const char *s1, const char *s2) { return stricmp(s1,s2); }
duke@435 113
duke@435 114
duke@435 115 #elif defined(SPARC_WORKS)
duke@435 116
duke@435 117 #define INTERFACE
duke@435 118 #define IMPLEMENTATION
duke@435 119
duke@435 120 #include <stddef.h>
duke@435 121 #include <stdlib.h>
duke@435 122 #include <string.h>
duke@435 123
duke@435 124 #elif defined(SOLARIS)
duke@435 125
duke@435 126 #define INTERFACE
duke@435 127 #define IMPLEMENTATION
duke@435 128
duke@435 129 #include <stddef.h>
duke@435 130 #include <stdlib.h>
duke@435 131 #include <string.h>
duke@435 132
duke@435 133
duke@435 134 #elif defined(__TANDEM)
duke@435 135
duke@435 136 // This case is for the Tandem Business Unit of Compaq Computer Corporation.
duke@435 137 // The Tandem case must precede the AT&T case,
duke@435 138 // because the Tandem c89 compiler also defines __cplusplus.
duke@435 139
duke@435 140 #include "port_tandem.hpp"
duke@435 141
duke@435 142 #elif defined(__cplusplus)
duke@435 143 // AT&Ts cfront
duke@435 144 #define INTERFACE
duke@435 145 #define IMPLEMENTATION
duke@435 146 #include <unistd.h>
duke@435 147 #define signed
duke@435 148 // #include <bstring.h>
duke@435 149 inline int min( int a, int b) { return a < b ? a : b; }
duke@435 150 inline int max( int a, int b) { return a > b ? a : b; }
duke@435 151
duke@435 152 #else // All other machines
duke@435 153
duke@435 154 #define signed
duke@435 155 extern "C" void bcopy(void *b1, void *b2, int len);
duke@435 156 inline int min( int a, int b) { return a < b ? a : b; }
duke@435 157 inline int max( int a, int b) { return a > b ? a : b; }
duke@435 158
duke@435 159 #endif
duke@435 160
duke@435 161 //-----------------------------------------------------------------------------
duke@435 162 // Safer memory allocations
duke@435 163 #ifdef SAFE_MEMORY
duke@435 164 #define malloc(size) safe_malloc(__FILE__,__LINE__,size)
duke@435 165 #define free(ptr) safe_free(__FILE__,__LINE__,ptr)
duke@435 166 #define realloc(ptr,size) safe_realloc(__FILE__,__LINE__,ptr,size)
duke@435 167 #define calloc(nitems,size) safe_calloc(__FILE__,__LINE__,nitems,size)
duke@435 168 #define strdup(ptr) safe_strdup(__FILE__,__LINE__,ptr)
duke@435 169 extern void *safe_malloc (const char *file, unsigned line, unsigned size);
duke@435 170 extern void safe_free (const char *file, unsigned line, void *ptr);
duke@435 171 extern void *safe_calloc (const char *file, unsigned line, unsigned nitems, unsigned size);
duke@435 172 extern void *safe_realloc(const char *file, unsigned line, void *ptr, unsigned size);
duke@435 173 extern char *safe_strdup (const char *file, unsigned line, const char *src);
duke@435 174 inline void *operator new( size_t size ) { return malloc(size); }
duke@435 175 inline void operator delete( void *ptr ) { free(ptr); }
duke@435 176 #endif
duke@435 177
duke@435 178 //-----------------------------------------------------------------------------
duke@435 179 // And now, the bit-size-specified integer sizes
duke@435 180 typedef signed char int8;
duke@435 181 typedef unsigned char uint8;
duke@435 182 typedef unsigned char byte;
duke@435 183
duke@435 184 // All uses of *int16 changed to 32-bit to speed up compiler on Intel
duke@435 185 //typedef signed short int16; // Exactly 16bits signed
duke@435 186 //typedef unsigned short uint16; // Exactly 16bits unsigned
duke@435 187 //const unsigned int min_uint16 = 0x0000; // smallest uint16
duke@435 188 //const unsigned int max_uint16 = 0xFFFF; // largest uint16
duke@435 189
duke@435 190 typedef unsigned int uint; // When you need a fast >=16bit unsigned value
duke@435 191 /*typedef int int; */ // When you need a fast >=16bit value
duke@435 192 const unsigned int max_uint = (uint)-1;
duke@435 193 typedef int32_t int32; // Exactly 32bits signed
duke@435 194 typedef uint32_t uint32; // Exactly 32bits unsigned
duke@435 195
duke@435 196 // Bit-sized floating point and long thingies
duke@435 197 #ifndef __TANDEM
duke@435 198 // Do not define these for Tandem, because they conflict with typedefs in softieee.h.
duke@435 199 typedef float float32; // 32-bit float
duke@435 200 typedef double float64; // 64-bit float
duke@435 201 #endif // __TANDEM
duke@435 202
duke@435 203 typedef jlong int64; // Java long for my 64-bit type
duke@435 204 typedef julong uint64; // Java long for my 64-bit type
duke@435 205
duke@435 206 //-----------------------------------------------------------------------------
duke@435 207 // Nice constants
duke@435 208 uint32 gcd( uint32 x, uint32 y );
duke@435 209 int ff1( uint32 mask );
duke@435 210 int fh1( uint32 mask );
duke@435 211 uint32 rotate32( uint32 x, int32 cnt );
duke@435 212
duke@435 213
duke@435 214 //-----------------------------------------------------------------------------
duke@435 215 extern uint32 heap_totalmem; // Current total memory allocation
duke@435 216 extern uint32 heap_highwater; // Highwater mark to date for memory usage
duke@435 217
duke@435 218 #endif // _PORT_

mercurial