annotate agent/src/share/classes/sun/jvm/hotspot/utilities/MarkBits.java @ 152:c70a245cad3a

6670684: 4/5 SA command universe did not print out CMS space information Summary: Forward port of Yumin's fix for 6670684 from HSX-11; Yumin verified the port was correct. Reviewed-by: dcubed
author dcubed
date Fri, 09 May 2008 08:55:13 -0700
parents a61af66fc99e
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2001-2003 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.utilities;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.gc_interface.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.memory.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 /** Helper class which covers the reserved area of the heap with an
a61af66fc99e Initial load
duke
parents:
diff changeset
34 (object-external) set of mark bits, used for GC-like scans through
a61af66fc99e Initial load
duke
parents:
diff changeset
35 the heap like liveness analysis. */
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 public class MarkBits {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 public MarkBits(CollectedHeap heap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 MemRegion reserved = heap.reservedRegion();
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // Must cover "reserved" with one bit for each OopHandle
a61af66fc99e Initial load
duke
parents:
diff changeset
41 start = reserved.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
42 end = reserved.end();
a61af66fc99e Initial load
duke
parents:
diff changeset
43 long numOopHandles = end.minus(start) / VM.getVM().getOopSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // FIXME: will have trouble with larger heap sizes
a61af66fc99e Initial load
duke
parents:
diff changeset
45 bits = new BitMap((int) numOopHandles);
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 public void clear() {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 bits.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 /** Returns true if a mark was newly placed for the given Oop, or
a61af66fc99e Initial load
duke
parents:
diff changeset
53 false if the Oop was already marked. If the Oop happens to lie
a61af66fc99e Initial load
duke
parents:
diff changeset
54 outside the heap (should not happen), prints a warning and
a61af66fc99e Initial load
duke
parents:
diff changeset
55 returns false. */
a61af66fc99e Initial load
duke
parents:
diff changeset
56 public boolean mark(Oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 if (obj == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 System.err.println("MarkBits: WARNING: null object, ignoring");
a61af66fc99e Initial load
duke
parents:
diff changeset
59 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 OopHandle handle = obj.getHandle();
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // FIXME: will have trouble with larger heap sizes
a61af66fc99e Initial load
duke
parents:
diff changeset
64 long idx = handle.minus(start) / VM.getVM().getOopSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
65 if ((idx < 0) || (idx >= bits.size())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 System.err.println("MarkBits: WARNING: object " + handle + " outside of heap, ignoring");
a61af66fc99e Initial load
duke
parents:
diff changeset
67 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69 int intIdx = (int) idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 if (bits.at(intIdx)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 return false; // already marked
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73 bits.atPut(intIdx, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
74 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 /** Forces clearing of a given mark bit. */
a61af66fc99e Initial load
duke
parents:
diff changeset
78 public void clear(Oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 OopHandle handle = obj.getHandle();
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // FIXME: will have trouble with larger heap sizes
a61af66fc99e Initial load
duke
parents:
diff changeset
81 long idx = handle.minus(start) / VM.getVM().getOopSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 if ((idx < 0) || (idx >= bits.size())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 System.err.println("MarkBits: WARNING: object " + handle + " outside of heap, ignoring");
a61af66fc99e Initial load
duke
parents:
diff changeset
84 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86 int intIdx = (int) idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 bits.atPut(intIdx, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 private BitMap bits;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 private Address start;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 private Address end;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }