0
|
1 /*
|
|
2 * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 *
|
|
5 * This code is free software; you can redistribute it and/or modify it
|
|
6 * under the terms of the GNU General Public License version 2 only, as
|
|
7 * published by the Free Software Foundation.
|
|
8 *
|
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
|
13 * accompanied this code).
|
|
14 *
|
|
15 * You should have received a copy of the GNU General Public License version
|
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 *
|
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 package sun.jvm.hotspot.memory;
|
|
26
|
|
27 import java.io.*;
|
|
28 import java.util.*;
|
|
29 import sun.jvm.hotspot.debugger.*;
|
|
30 import sun.jvm.hotspot.runtime.*;
|
|
31 import sun.jvm.hotspot.types.*;
|
|
32 import sun.jvm.hotspot.utilities.*;
|
|
33
|
|
34 public class CMSBitMap extends VMObject {
|
|
35 private static AddressField bmStartWordField;
|
|
36 private static CIntegerField bmWordSizeField;
|
|
37 private static CIntegerField shifterField;
|
|
38 //private static AddressField bmField;
|
|
39 private static long virtualSpaceFieldOffset;
|
|
40
|
|
41 public CMSBitMap(Address addr) {
|
|
42 super(addr);
|
|
43 }
|
|
44
|
|
45 static {
|
|
46 VM.registerVMInitializedObserver(new Observer() {
|
|
47 public void update(Observable o, Object data) {
|
|
48 initialize(VM.getVM().getTypeDataBase());
|
|
49 }
|
|
50 });
|
|
51 }
|
|
52
|
|
53 private static synchronized void initialize(TypeDataBase db) {
|
|
54 Type type = db.lookupType("CMSBitMap");
|
|
55 bmStartWordField = type.getAddressField("_bmStartWord");
|
|
56 bmWordSizeField = type.getCIntegerField("_bmWordSize");
|
|
57 shifterField = type.getCIntegerField("_shifter");
|
|
58 //bmField = type.getAddressField("_bm");
|
|
59 virtualSpaceFieldOffset = type.getField("_virtual_space").getOffset();
|
|
60 }
|
|
61 public void printAll() {
|
|
62 System.out.println("bmStartWord(): "+bmStartWord());
|
|
63 System.out.println("bmWordSize(): "+bmWordSize());
|
|
64 System.out.println("shifter(): "+shifter());
|
|
65 }
|
|
66
|
|
67 public Address bmStartWord() {
|
|
68 return bmStartWordField.getValue(addr);
|
|
69 }
|
|
70 public long bmWordSize() {
|
|
71 return bmWordSizeField.getValue(addr);
|
|
72 }
|
|
73 public long shifter() {
|
|
74 return shifterField.getValue(addr);
|
|
75 }
|
|
76 public VirtualSpace virtualSpace() {
|
|
77 return (VirtualSpace) VMObjectFactory.newObject(VirtualSpace.class, addr.addOffsetTo(virtualSpaceFieldOffset));
|
|
78 }
|
|
79
|
|
80 public BitMap bm() {
|
|
81 BitMap bitMap = new BitMap((int) (bmWordSize() >> (shifter() + 3) ));
|
|
82 VirtualSpace vs = virtualSpace();
|
|
83 //bitMap.set_size((int)vs.committedSize());
|
|
84 bitMap.set_map(vs.low());
|
|
85 return bitMap;
|
|
86 }
|
|
87
|
|
88 public Address getNextMarkedWordAddress(Address addr) {
|
|
89 Address endWord = bmStartWord().addOffsetTo(bmWordSize());
|
|
90 int nextOffset = bm().getNextOneOffset(heapWordToOffset(addr), heapWordToOffset(endWord) );
|
|
91 Address nextAddr = offsetToHeapWord(nextOffset);
|
|
92 return nextAddr;
|
|
93 }
|
|
94
|
|
95 int heapWordToOffset(Address addr) {
|
|
96 int temp = (int)addr.minus(bmStartWord()) / (int) VM.getVM().getAddressSize();
|
|
97 int ret_val = temp >> shifter();
|
|
98 return ret_val;
|
|
99 }
|
|
100
|
|
101 Address offsetToHeapWord(int offset) {
|
|
102 int temp = offset << shifter();
|
|
103 return bmStartWord().addOffsetTo(temp*VM.getVM().getAddressSize());
|
|
104 }
|
|
105
|
|
106 boolean isMarked(Address addr) {
|
|
107 BitMap bm = bm();
|
|
108 return bm.at(heapWordToOffset(addr));
|
|
109 }
|
|
110 }
|