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