src/share/vm/libadt/port.hpp

Thu, 27 Jan 2011 16:11:27 -0800

author
coleenp
date
Thu, 27 Jan 2011 16:11:27 -0800
changeset 2497
3582bf76420e
parent 2314
f95d63e2154a
child 5614
9758d9f36299
child 6461
bdd155477289
permissions
-rw-r--r--

6990754: Use native memory and reference counting to implement SymbolTable
Summary: move symbols from permgen into C heap and reference count them
Reviewed-by: never, acorn, jmasa, stefank

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

mercurial