Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/libadt/port.hpp
32285 views
/*1* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_LIBADT_PORT_HPP25#define SHARE_VM_LIBADT_PORT_HPP2627#include "utilities/top.hpp"2829// Typedefs for portable compiling3031#if defined(__GNUC__)3233#define INTERFACE #pragma interface34#define IMPLEMENTATION #pragma implementation35//INTERFACE36#include <stddef.h>37#include <stdlib.h>38#include <string.h>3940// Access to the C++ class virtual function pointer41// Put the class in the macro42typedef void *VPTR;43// G++ puts it at the end of the base class44#define ACCESS_VPTR(class) VPTR&vptr(){return*(VPTR*)((char*)this+sizeof(class)-sizeof(void*));}4546#elif defined(__TURBOC__)4748#include <mem.h>49#include <string.h>50extern "C" int stricmp(const char *, const char *);51inline void bcopy(const void *s, void *d, int l) { memmove(d,s,l); }52inline void bzero(void *p, int l) { memset(p,0,l); }53inline int bcmp(const void *s, const void *d, int l) { return memcmp(s,d,l); }54inline int min( int a, int b) { return a < b ? a : b; }55inline int max( int a, int b) { return a > b ? a : b; }56//strcasecmp moved to globalDefinitions_visCPP.hpp57//inline int strcasecmp(const char *s1, const char *s2) { return stricmp(s1,s2); }58inline long abs( long x ) { return x < 0 ? -x : x; }59// Access to the C++ class virtual function pointer60// Put the class in the macro61typedef void near *VPTR;62// BorlandC puts it up front63#define ACCESS_VPTR(class) VPTR&vptr(){return*(VPTR*)this;}6465#elif defined(__hpux)6667#define INTERFACE68#define IMPLEMENTATION69#define signed70#include <strings.h>71#include <stdlib.h>72inline long min( long a, long b) { return a < b ? a : b; }73inline long max( long a, long b) { return a > b ? a : b; }74inline int min( int a, int b) { return a < b ? a : b; }75inline int max( int a, int b) { return a > b ? a : b; }76inline long abs( long x ) { return x < 0 ? -x : x; }7778#elif defined(__MOTO__)79// Motorola's mcc80#define INTERFACE81#define IMPLEMENTATION82#include <stdlib.h>83#include <memory.h>84inline int min( int a, int b) { return a < b ? a : b; }85inline int max( int a, int b) { return a > b ? a : b; }8687#elif defined(_AIX)88// IBM's xlC compiler89#define INTERFACE90#define IMPLEMENTATION91#include <stdlib.h>92#include <memory.h>9394#elif defined(_MSC_VER)95// Microsoft Visual C++96//#define INTERFACE97#define IMPLEMENTATION98#include <stdlib.h>99#undef small100//strcasecmp moved to globalDefinitions_visCPP.hpp101//inline int strcasecmp(const char *s1, const char *s2) { return stricmp(s1,s2); }102103104#elif defined(SPARC_WORKS)105106#define INTERFACE107#define IMPLEMENTATION108109#include <stddef.h>110#include <stdlib.h>111#include <string.h>112113#elif defined(SOLARIS)114115#define INTERFACE116#define IMPLEMENTATION117118#include <stddef.h>119#include <stdlib.h>120#include <string.h>121122123#elif defined(__TANDEM)124125// This case is for the Tandem Business Unit of Compaq Computer Corporation.126// The Tandem case must precede the AT&T case,127// because the Tandem c89 compiler also defines __cplusplus.128129#include "port_tandem.hpp"130131#elif defined(__cplusplus)132// AT&Ts cfront133#define INTERFACE134#define IMPLEMENTATION135#include <unistd.h>136#define signed137// #include <bstring.h>138inline int min( int a, int b) { return a < b ? a : b; }139inline int max( int a, int b) { return a > b ? a : b; }140141#else // All other machines142143#define signed144extern "C" void bcopy(void *b1, void *b2, int len);145inline int min( int a, int b) { return a < b ? a : b; }146inline int max( int a, int b) { return a > b ? a : b; }147148#endif149150//-----------------------------------------------------------------------------151// Safer memory allocations152#ifdef SAFE_MEMORY153#define malloc(size) safe_malloc(__FILE__,__LINE__,size)154#define free(ptr) safe_free(__FILE__,__LINE__,ptr)155#define realloc(ptr,size) safe_realloc(__FILE__,__LINE__,ptr,size)156#define calloc(nitems,size) safe_calloc(__FILE__,__LINE__,nitems,size)157#define strdup(ptr) safe_strdup(__FILE__,__LINE__,ptr)158extern void *safe_malloc (const char *file, unsigned line, unsigned size);159extern void safe_free (const char *file, unsigned line, void *ptr);160extern void *safe_calloc (const char *file, unsigned line, unsigned nitems, unsigned size);161extern void *safe_realloc(const char *file, unsigned line, void *ptr, unsigned size);162extern char *safe_strdup (const char *file, unsigned line, const char *src);163inline void *operator new( size_t size ) throw() { return malloc(size); }164inline void operator delete( void *ptr ) { free(ptr); }165#endif166167//-----------------------------------------------------------------------------168// And now, the bit-size-specified integer sizes169typedef signed char int8;170typedef unsigned char uint8;171typedef unsigned char byte;172173// All uses of *int16 changed to 32-bit to speed up compiler on Intel174//typedef signed short int16; // Exactly 16bits signed175//typedef unsigned short uint16; // Exactly 16bits unsigned176//const unsigned int min_uint16 = 0x0000; // smallest uint16177//const unsigned int max_uint16 = 0xFFFF; // largest uint16178179typedef unsigned int uint; // When you need a fast >=16bit unsigned value180/*typedef int int; */ // When you need a fast >=16bit value181const unsigned int max_uint = (uint)-1;182typedef int32_t int32; // Exactly 32bits signed183typedef uint32_t uint32; // Exactly 32bits unsigned184185// Bit-sized floating point and long thingies186#ifndef __TANDEM187// Do not define these for Tandem, because they conflict with typedefs in softieee.h.188typedef float float32; // 32-bit float189typedef double float64; // 64-bit float190#endif // __TANDEM191192typedef jlong int64; // Java long for my 64-bit type193typedef julong uint64; // Java long for my 64-bit type194195//-----------------------------------------------------------------------------196// Nice constants197uint32 gcd( uint32 x, uint32 y );198int ff1( uint32 mask );199int fh1( uint32 mask );200uint32 rotate32( uint32 x, int32 cnt );201202203//-----------------------------------------------------------------------------204extern uint32 heap_totalmem; // Current total memory allocation205extern uint32 heap_highwater; // Highwater mark to date for memory usage206207#endif // SHARE_VM_LIBADT_PORT_HPP208209210