src/share/vm/libadt/port.cpp

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 6876
710a3c8b516e
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 #include "precompiled.hpp"
stefank@2314 26 #include "libadt/port.hpp"
stefank@2314 27
duke@435 28 // Code for portable compiling
duke@435 29
duke@435 30 #ifdef __GNUC__
duke@435 31 #pragma implementation
duke@435 32 #endif
duke@435 33
duke@435 34 // %%%%% includes not needed with AVM framework - Ungar
duke@435 35 // #include "port.hpp"
duke@435 36
duke@435 37 // This is only used if turboc is used and it causes problems with
duke@435 38 // gcc.
duke@435 39 #ifdef __TURBOC__
duke@435 40 #include <iostream.h>
duke@435 41 #endif
duke@435 42
duke@435 43 #include <stdio.h>
duke@435 44
duke@435 45 //------------------------------gcd--------------------------------------------
duke@435 46 // Greatest common divisor
duke@435 47 uint32 gcd( register uint32 x, register uint32 y )
duke@435 48 {
duke@435 49 register uint32 tmp;
duke@435 50 while( x ) { // While not zero
duke@435 51 tmp = x; // Hold onto smaller x value
duke@435 52 x = y % x; // Compute modulus; since y>=x, 0 <= mod < x
duke@435 53 y = tmp; // y = old x
duke@435 54 }
duke@435 55 return y;
duke@435 56 }
duke@435 57
duke@435 58 //-----------------------------------------------------------------------------
duke@435 59 // Find first 1, or return 32 if empty
duke@435 60 int ff1( uint32 mask )
duke@435 61 {
duke@435 62 unsigned i, n = 0;
duke@435 63
duke@435 64 for( i=1, n=0; i; i<<=1, n++)
duke@435 65 if( mask&i ) return n;
duke@435 66 return 32;
duke@435 67 }
duke@435 68
duke@435 69 //-----------------------------------------------------------------------------
duke@435 70 // Find highest 1, or return 32 if empty
duke@435 71 int fh1( uint32 mask )
duke@435 72 {
duke@435 73 unsigned i, n = 0;
duke@435 74
duke@435 75 for( i=((uint32)1<<31), n=31; i; i>>=1, n--)
duke@435 76 if( mask&i ) return n;
duke@435 77 return 32;
duke@435 78 }
duke@435 79
duke@435 80 //------------------------------rotate32---------------------------------------
duke@435 81 // Rotate 32bits. Postive rotates left (bits move toward high-order bit),
duke@435 82 // negative rotates right.
duke@435 83 uint32 rotate32( register uint32 x, register int32 cnt )
duke@435 84 {
duke@435 85 if( cnt >= 0 ) { // Positive rotates left
duke@435 86 cnt &= 31; // Mask off extra shift bits
duke@435 87 } else { // Negative rotates right
duke@435 88 cnt = (-cnt)&31; // Flip sign; mask extra shift bits
duke@435 89 cnt = 32-cnt; // Rotate right by big left rotation
duke@435 90 }
duke@435 91 return (x << cnt) | (x >> (32-cnt));
duke@435 92 }
duke@435 93
duke@435 94 /* Disabled - we have another log2 in the system.
duke@435 95 This function doesn't work if used as substitute
duke@435 96 for the existing log2. Keep around until we have
duke@435 97 verified all uses of log2 do the correct thing!
duke@435 98 //------------------------------log2-------------------------------------------
duke@435 99 // Log base 2. Might also be called 'count leading zeros'. Log2(x) returns
duke@435 100 // an l such that (1L<<l) <= x < (2L<<l). log2(x) returns 32.
duke@435 101 uint log2( uint32 x )
duke@435 102 {
duke@435 103 register uint l = 32; // Log bits
duke@435 104 register int32 sx = x; // Treat as signed number
duke@435 105 while( sx >= 0 ) // While high bit is clear
duke@435 106 sx <<= 1, l--; // Shift bits left, count down log2
duke@435 107 return l;
duke@435 108 }
duke@435 109 */
duke@435 110
duke@435 111 //------------------------------print------------------------------------------
duke@435 112 // Print a pointer without modifying the contents
duke@435 113 #ifdef __TURBOC__
duke@435 114 ostream &ostream::operator << (const void *ptr)
duke@435 115 {
duke@435 116 return (*this) << "0x" << hex << (uint)ptr << dec;
duke@435 117 }
duke@435 118 #else
duke@435 119 /*ostream &operator << (ostream &os, const void *ptr)
duke@435 120 {
duke@435 121 return os << "0x" << hex << (uint)ptr << dec;
duke@435 122 }*/
duke@435 123 #endif

mercurial