src/share/vm/libadt/port.hpp

changeset 435
a61af66fc99e
child 948
2328d1d3f8cf
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/libadt/port.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,218 @@
     1.4 +/*
     1.5 + * Copyright 1997-2003 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef _PORT_
    1.29 +#define _PORT_
    1.30 +// Typedefs for portable compiling
    1.31 +
    1.32 +#if defined(__GNUC__)
    1.33 +
    1.34 +#define INTERFACE       #pragma interface
    1.35 +#define IMPLEMENTATION  #pragma implementation
    1.36 +//INTERFACE
    1.37 +#include <stddef.h>
    1.38 +#include <stdlib.h>
    1.39 +#include <string.h>
    1.40 +#undef bzero
    1.41 +inline void bzero(void *b, int len) { memset(b,0,len); }
    1.42 +#undef bcopy
    1.43 +inline void bcopy(const void *s, void *d, size_t len) { memmove(d,s,len); }
    1.44 +#undef bcmp
    1.45 +inline int bcmp(const void *s,const void *t,int len) { return memcmp(s,t,len);}
    1.46 +extern "C" unsigned long strtoul(const char *s, char **end, int base);
    1.47 +
    1.48 +// Definition for sys_errlist varies from Sun 4.1 & Solaris.
    1.49 +// We use the new Solaris definition.
    1.50 +#include <string.h>
    1.51 +
    1.52 +// Access to the C++ class virtual function pointer
    1.53 +// Put the class in the macro
    1.54 +typedef void *VPTR;
    1.55 +// G++ puts it at the end of the base class
    1.56 +#define ACCESS_VPTR(class) VPTR&vptr(){return*(VPTR*)((char*)this+sizeof(class)-sizeof(void*));}
    1.57 +
    1.58 +#elif defined(__TURBOC__)
    1.59 +
    1.60 +#include <mem.h>
    1.61 +#include <string.h>
    1.62 +extern "C" int stricmp(const char *, const char *);
    1.63 +inline void bcopy(const void *s, void *d, int l) { memmove(d,s,l); }
    1.64 +inline void bzero(void *p, int l) { memset(p,0,l); }
    1.65 +inline int bcmp(const void *s, const void *d, int l) { return memcmp(s,d,l); }
    1.66 +inline int min( int a, int b) { return a < b ? a : b; }
    1.67 +inline int max( int a, int b) { return a > b ? a : b; }
    1.68 +//strcasecmp moved to globalDefinitions_visCPP.hpp
    1.69 +//inline int strcasecmp(const char *s1, const char *s2) { return stricmp(s1,s2); }
    1.70 +inline long abs( long x ) { return x < 0 ? -x : x; }
    1.71 +// Access to the C++ class virtual function pointer
    1.72 +// Put the class in the macro
    1.73 +typedef void near *VPTR;
    1.74 +// BorlandC puts it up front
    1.75 +#define ACCESS_VPTR(class) VPTR&vptr(){return*(VPTR*)this;}
    1.76 +
    1.77 +#elif defined(__hpux)
    1.78 +
    1.79 +#define INTERFACE
    1.80 +#define IMPLEMENTATION
    1.81 +#define signed
    1.82 +#include <strings.h>
    1.83 +#include <stdlib.h>
    1.84 +inline long min( long a, long b) { return a < b ? a : b; }
    1.85 +inline long max( long a, long b) { return a > b ? a : b; }
    1.86 +inline int min( int a, int b) { return a < b ? a : b; }
    1.87 +inline int max( int a, int b) { return a > b ? a : b; }
    1.88 +inline long abs( long x ) { return x < 0 ? -x : x; }
    1.89 +
    1.90 +#elif defined(__MOTO__)
    1.91 +// Motorola's mcc
    1.92 +#define INTERFACE
    1.93 +#define IMPLEMENTATION
    1.94 +#include <stdlib.h>
    1.95 +#include <memory.h>
    1.96 +inline int min( int a, int b) { return a < b ? a : b; }
    1.97 +inline int max( int a, int b) { return a > b ? a : b; }
    1.98 +
    1.99 +#elif defined(_AIX)
   1.100 +// IBM's xlC compiler
   1.101 +#define INTERFACE
   1.102 +#define IMPLEMENTATION
   1.103 +#include <stdlib.h>
   1.104 +#include <memory.h>
   1.105 +inline int min( int a, int b) { return a < b ? a : b; }
   1.106 +inline int max( int a, int b) { return a > b ? a : b; }
   1.107 +
   1.108 +#elif defined(_MSC_VER)
   1.109 +// Microsoft Visual C++
   1.110 +//#define INTERFACE
   1.111 +#define IMPLEMENTATION
   1.112 +#include <stdlib.h>
   1.113 +#undef small
   1.114 +//strcasecmp moved to globalDefinitions_visCPP.hpp
   1.115 +//inline int strcasecmp(const char *s1, const char *s2) { return stricmp(s1,s2); }
   1.116 +
   1.117 +
   1.118 +#elif defined(SPARC_WORKS)
   1.119 +
   1.120 +#define INTERFACE
   1.121 +#define IMPLEMENTATION
   1.122 +
   1.123 +#include <stddef.h>
   1.124 +#include <stdlib.h>
   1.125 +#include <string.h>
   1.126 +
   1.127 +#elif defined(SOLARIS)
   1.128 +
   1.129 +#define INTERFACE
   1.130 +#define IMPLEMENTATION
   1.131 +
   1.132 +#include <stddef.h>
   1.133 +#include <stdlib.h>
   1.134 +#include <string.h>
   1.135 +
   1.136 +
   1.137 +#elif defined(__TANDEM)
   1.138 +
   1.139 +// This case is for the Tandem Business Unit of Compaq Computer Corporation.
   1.140 +// The Tandem case must precede the AT&T case,
   1.141 +// because the Tandem c89 compiler also defines __cplusplus.
   1.142 +
   1.143 +#include "port_tandem.hpp"
   1.144 +
   1.145 +#elif defined(__cplusplus)
   1.146 +// AT&Ts cfront
   1.147 +#define INTERFACE
   1.148 +#define IMPLEMENTATION
   1.149 +#include <unistd.h>
   1.150 +#define signed
   1.151 +// #include <bstring.h>
   1.152 +inline int min( int a, int b) { return a < b ? a : b; }
   1.153 +inline int max( int a, int b) { return a > b ? a : b; }
   1.154 +
   1.155 +#else  // All other machines
   1.156 +
   1.157 +#define signed
   1.158 +extern "C" void bcopy(void *b1, void *b2, int len);
   1.159 +inline int min( int a, int b) { return a < b ? a : b; }
   1.160 +inline int max( int a, int b) { return a > b ? a : b; }
   1.161 +
   1.162 +#endif
   1.163 +
   1.164 +//-----------------------------------------------------------------------------
   1.165 +// Safer memory allocations
   1.166 +#ifdef SAFE_MEMORY
   1.167 +#define malloc(size)        safe_malloc(__FILE__,__LINE__,size)
   1.168 +#define free(ptr)           safe_free(__FILE__,__LINE__,ptr)
   1.169 +#define realloc(ptr,size)   safe_realloc(__FILE__,__LINE__,ptr,size)
   1.170 +#define calloc(nitems,size) safe_calloc(__FILE__,__LINE__,nitems,size)
   1.171 +#define strdup(ptr)         safe_strdup(__FILE__,__LINE__,ptr)
   1.172 +extern void *safe_malloc (const char *file, unsigned line, unsigned size);
   1.173 +extern void  safe_free   (const char *file, unsigned line, void *ptr);
   1.174 +extern void *safe_calloc (const char *file, unsigned line, unsigned nitems, unsigned size);
   1.175 +extern void *safe_realloc(const char *file, unsigned line, void *ptr, unsigned size);
   1.176 +extern char *safe_strdup (const char *file, unsigned line, const char *src);
   1.177 +inline void *operator new( size_t size ) { return malloc(size); }
   1.178 +inline void operator delete( void *ptr ) { free(ptr); }
   1.179 +#endif
   1.180 +
   1.181 +//-----------------------------------------------------------------------------
   1.182 +// And now, the bit-size-specified integer sizes
   1.183 +typedef signed char int8;
   1.184 +typedef unsigned char uint8;
   1.185 +typedef unsigned char byte;
   1.186 +
   1.187 +// All uses of *int16 changed to 32-bit to speed up compiler on Intel
   1.188 +//typedef signed short int16;   // Exactly 16bits signed
   1.189 +//typedef unsigned short uint16;        // Exactly 16bits unsigned
   1.190 +//const unsigned int min_uint16 = 0x0000;    // smallest uint16
   1.191 +//const unsigned int max_uint16 = 0xFFFF;    // largest  uint16
   1.192 +
   1.193 +typedef unsigned int uint;      // When you need a fast >=16bit unsigned value
   1.194 +/*typedef int int; */           // When you need a fast >=16bit value
   1.195 +const unsigned int max_uint = (uint)-1;
   1.196 +typedef int32_t int32;   // Exactly 32bits signed
   1.197 +typedef uint32_t uint32; // Exactly 32bits unsigned
   1.198 +
   1.199 +// Bit-sized floating point and long thingies
   1.200 +#ifndef __TANDEM
   1.201 +// Do not define these for Tandem, because they conflict with typedefs in softieee.h.
   1.202 +typedef float float32;          // 32-bit float
   1.203 +typedef double float64;         // 64-bit float
   1.204 +#endif // __TANDEM
   1.205 +
   1.206 +typedef jlong int64;            // Java long for my 64-bit type
   1.207 +typedef julong uint64;          // Java long for my 64-bit type
   1.208 +
   1.209 +//-----------------------------------------------------------------------------
   1.210 +// Nice constants
   1.211 +uint32 gcd( uint32 x, uint32 y );
   1.212 +int ff1( uint32 mask );
   1.213 +int fh1( uint32 mask );
   1.214 +uint32 rotate32( uint32 x, int32 cnt );
   1.215 +
   1.216 +
   1.217 +//-----------------------------------------------------------------------------
   1.218 +extern uint32 heap_totalmem;      // Current total memory allocation
   1.219 +extern uint32 heap_highwater;     // Highwater mark to date for memory usage
   1.220 +
   1.221 +#endif // _PORT_

mercurial