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

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

mercurial