comparison agent/src/share/classes/sun/jvm/hotspot/memory/CodeHeap.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c18cbe5936b8
comparison
equal deleted inserted replaced
-1:000000000000 0:a61af66fc99e
1 /*
2 * Copyright 2000-2004 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.util.*;
28 import sun.jvm.hotspot.debugger.*;
29 import sun.jvm.hotspot.runtime.*;
30 import sun.jvm.hotspot.types.*;
31
32 public class CodeHeap extends VMObject {
33 private static Field memoryField;
34 private static Field segmapField;
35 // private static CIntegerField numberOfCommittedSegmentsField;
36 // private static CIntegerField numberOfReservedSegmentsField;
37 // private static CIntegerField segmentSizeField;
38 private static CIntegerField log2SegmentSizeField;
39 // private static CIntegerField nextSegmentField;
40 // private static AddressField freelistField;
41 // private static CIntegerField freeSegmentsField;
42
43 private VirtualSpace memory;
44 private VirtualSpace segmentMap;
45 private int log2SegmentSize;
46
47 static {
48 VM.registerVMInitializedObserver(new Observer() {
49 public void update(Observable o, Object data) {
50 initialize(VM.getVM().getTypeDataBase());
51 }
52 });
53 }
54
55 private static void initialize(TypeDataBase db) {
56 Type type = db.lookupType("CodeHeap");
57
58 memoryField = type.getField("_memory");
59 segmapField = type.getField("_segmap");
60 log2SegmentSizeField = type.getCIntegerField("_log2_segment_size");
61
62 }
63
64 public CodeHeap(Address addr) {
65 super(addr);
66 log2SegmentSize = (int) log2SegmentSizeField.getValue(addr);
67 segmentMap = new VirtualSpace(addr.addOffsetTo(segmapField.getOffset()));
68 memory = new VirtualSpace(addr.addOffsetTo(memoryField.getOffset()));
69 }
70
71 public Address begin() {
72 return getMemory().low();
73 }
74
75 public Address end() {
76 return getMemory().high();
77 }
78
79 public boolean contains(Address p) {
80 return (begin().lessThanOrEqual(p) && end().greaterThan(p));
81 }
82
83 /** Returns the start of the block containing p or null */
84 public Address findStart(Address p) {
85 if (!contains(p)) return null;
86 HeapBlock h = blockStart(p);
87 if (h == null || h.isFree()) {
88 return null;
89 }
90 return h.getAllocatedSpace();
91 }
92
93 public Address nextBlock(Address ptr) {
94 Address base = blockBase(ptr);
95 if (base == null) {
96 return null;
97 }
98 HeapBlock block = getBlockAt(base);
99 return base.addOffsetTo(block.getLength() * (1 << getLog2SegmentSize()));
100 }
101
102 //--------------------------------------------------------------------------------
103 // Internals only below this point
104 //
105
106 private VirtualSpace getMemory() {
107 return memory;
108 }
109
110 private VirtualSpace getSegmentMap() {
111 return segmentMap;
112 }
113
114 private long segmentFor(Address p) {
115 return p.minus(getMemory().low()) >> getLog2SegmentSize();
116 }
117
118 private int getLog2SegmentSize() {
119 return log2SegmentSize;
120 }
121
122 private HeapBlock getBlockAt(Address addr) {
123 return (HeapBlock) VMObjectFactory.newObject(HeapBlock.class, addr);
124 }
125
126
127 private HeapBlock blockStart(Address p) {
128 Address base = blockBase(p);
129 if (base == null) return null;
130 return getBlockAt(base);
131 }
132
133 private Address blockBase(Address p) {
134 long i = segmentFor(p);
135 Address b = getSegmentMap().low();
136 if (b.getCIntegerAt(i, 1, true) == 0xFF) {
137 return null;
138 }
139 while (b.getCIntegerAt(i, 1, true) > 0) {
140 i -= b.getCIntegerAt(i, 1, true);
141 }
142 return getMemory().low().addOffsetTo(i << getLog2SegmentSize());
143 }
144
145 }