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