annotate src/share/vm/libadt/port.cpp @ 4710:41406797186b

7113012: G1: rename not-fully-young GCs as "mixed" Summary: Renamed partially-young GCs as mixed and fully-young GCs as young. Change all external output that includes those terms (GC log and GC ergo log) as well as any comments, fields, methods, etc. The changeset also includes very minor code tidying up (added some curly brackets). Reviewed-by: johnc, brutisso
author tonyp
date Fri, 16 Dec 2011 02:14:27 -0500
parents f95d63e2154a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "libadt/port.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
0
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // Code for portable compiling
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 #ifdef __GNUC__
a61af66fc99e Initial load
duke
parents:
diff changeset
31 #pragma implementation
a61af66fc99e Initial load
duke
parents:
diff changeset
32 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // %%%%% includes not needed with AVM framework - Ungar
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // #include "port.hpp"
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // This is only used if turboc is used and it causes problems with
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // gcc.
a61af66fc99e Initial load
duke
parents:
diff changeset
39 #ifdef __TURBOC__
a61af66fc99e Initial load
duke
parents:
diff changeset
40 #include <iostream.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
41 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 #include <stdio.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 //------------------------------gcd--------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // Greatest common divisor
a61af66fc99e Initial load
duke
parents:
diff changeset
47 uint32 gcd( register uint32 x, register uint32 y )
a61af66fc99e Initial load
duke
parents:
diff changeset
48 {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 register uint32 tmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 while( x ) { // While not zero
a61af66fc99e Initial load
duke
parents:
diff changeset
51 tmp = x; // Hold onto smaller x value
a61af66fc99e Initial load
duke
parents:
diff changeset
52 x = y % x; // Compute modulus; since y>=x, 0 <= mod < x
a61af66fc99e Initial load
duke
parents:
diff changeset
53 y = tmp; // y = old x
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return y;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 //-----------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // Find first 1, or return 32 if empty
a61af66fc99e Initial load
duke
parents:
diff changeset
60 int ff1( uint32 mask )
a61af66fc99e Initial load
duke
parents:
diff changeset
61 {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 unsigned i, n = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 for( i=1, n=0; i; i<<=1, n++)
a61af66fc99e Initial load
duke
parents:
diff changeset
65 if( mask&i ) return n;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 return 32;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 //-----------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // Find highest 1, or return 32 if empty
a61af66fc99e Initial load
duke
parents:
diff changeset
71 int fh1( uint32 mask )
a61af66fc99e Initial load
duke
parents:
diff changeset
72 {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 unsigned i, n = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 for( i=((uint32)1<<31), n=31; i; i>>=1, n--)
a61af66fc99e Initial load
duke
parents:
diff changeset
76 if( mask&i ) return n;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 return 32;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 //------------------------------rotate32---------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // Rotate 32bits. Postive rotates left (bits move toward high-order bit),
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // negative rotates right.
a61af66fc99e Initial load
duke
parents:
diff changeset
83 uint32 rotate32( register uint32 x, register int32 cnt )
a61af66fc99e Initial load
duke
parents:
diff changeset
84 {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 if( cnt >= 0 ) { // Positive rotates left
a61af66fc99e Initial load
duke
parents:
diff changeset
86 cnt &= 31; // Mask off extra shift bits
a61af66fc99e Initial load
duke
parents:
diff changeset
87 } else { // Negative rotates right
a61af66fc99e Initial load
duke
parents:
diff changeset
88 cnt = (-cnt)&31; // Flip sign; mask extra shift bits
a61af66fc99e Initial load
duke
parents:
diff changeset
89 cnt = 32-cnt; // Rotate right by big left rotation
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 return (x << cnt) | (x >> (32-cnt));
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 /* Disabled - we have another log2 in the system.
a61af66fc99e Initial load
duke
parents:
diff changeset
95 This function doesn't work if used as substitute
a61af66fc99e Initial load
duke
parents:
diff changeset
96 for the existing log2. Keep around until we have
a61af66fc99e Initial load
duke
parents:
diff changeset
97 verified all uses of log2 do the correct thing!
a61af66fc99e Initial load
duke
parents:
diff changeset
98 //------------------------------log2-------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // Log base 2. Might also be called 'count leading zeros'. Log2(x) returns
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // an l such that (1L<<l) <= x < (2L<<l). log2(x) returns 32.
a61af66fc99e Initial load
duke
parents:
diff changeset
101 uint log2( uint32 x )
a61af66fc99e Initial load
duke
parents:
diff changeset
102 {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 register uint l = 32; // Log bits
a61af66fc99e Initial load
duke
parents:
diff changeset
104 register int32 sx = x; // Treat as signed number
a61af66fc99e Initial load
duke
parents:
diff changeset
105 while( sx >= 0 ) // While high bit is clear
a61af66fc99e Initial load
duke
parents:
diff changeset
106 sx <<= 1, l--; // Shift bits left, count down log2
a61af66fc99e Initial load
duke
parents:
diff changeset
107 return l;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 */
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 //------------------------------print------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // Print a pointer without modifying the contents
a61af66fc99e Initial load
duke
parents:
diff changeset
113 #ifdef __TURBOC__
a61af66fc99e Initial load
duke
parents:
diff changeset
114 ostream &ostream::operator << (const void *ptr)
a61af66fc99e Initial load
duke
parents:
diff changeset
115 {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 return (*this) << "0x" << hex << (uint)ptr << dec;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
119 /*ostream &operator << (ostream &os, const void *ptr)
a61af66fc99e Initial load
duke
parents:
diff changeset
120 {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return os << "0x" << hex << (uint)ptr << dec;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }*/
a61af66fc99e Initial load
duke
parents:
diff changeset
123 #endif