annotate agent/src/share/classes/sun/jvm/hotspot/memory/Generation.java @ 904:ef671fb22f73

6868051: (SA) FreeChunk support for compressed oops is broken Reviewed-by: kvn, dcubed
author never
date Thu, 06 Aug 2009 12:24:41 -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 2000-2005 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.memory;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.types.*;
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 /** <P> The (supported) Generation hierarchy currently looks like this: </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 <ul>
a61af66fc99e Initial load
duke
parents:
diff changeset
36 <li> Generation
a61af66fc99e Initial load
duke
parents:
diff changeset
37 <ul>
a61af66fc99e Initial load
duke
parents:
diff changeset
38 <li> CardGeneration
a61af66fc99e Initial load
duke
parents:
diff changeset
39 <ul>
a61af66fc99e Initial load
duke
parents:
diff changeset
40 <li> OneContigSpaceCardGeneration
a61af66fc99e Initial load
duke
parents:
diff changeset
41 <ul>
a61af66fc99e Initial load
duke
parents:
diff changeset
42 <li> CompactingPermGenGen
a61af66fc99e Initial load
duke
parents:
diff changeset
43 <li> TenuredGeneration
a61af66fc99e Initial load
duke
parents:
diff changeset
44 </ul>
a61af66fc99e Initial load
duke
parents:
diff changeset
45 </ul>
a61af66fc99e Initial load
duke
parents:
diff changeset
46 <li> DefNewGeneration
a61af66fc99e Initial load
duke
parents:
diff changeset
47 </ul>
a61af66fc99e Initial load
duke
parents:
diff changeset
48 </ul>
a61af66fc99e Initial load
duke
parents:
diff changeset
49 */
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 public abstract class Generation extends VMObject {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 private static long reservedFieldOffset;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 private static long virtualSpaceFieldOffset;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 private static CIntegerField levelField;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 protected static final int K = 1024;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // Fields for class StatRecord
a61af66fc99e Initial load
duke
parents:
diff changeset
58 private static Field statRecordField;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 private static CIntegerField invocationField;
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // constants from Name enum
a61af66fc99e Initial load
duke
parents:
diff changeset
62 private static int NAME_DEF_NEW;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 private static int NAME_PAR_NEW;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 private static int NAME_MARK_SWEEP_COMPACT;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 private static int NAME_CONCURRENT_MARK_SWEEP;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 private static int NAME_OTHER;
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 initialize(VM.getVM().getTypeDataBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73 });
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 private static synchronized void initialize(TypeDataBase db) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 Type type = db.lookupType("Generation");
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 reservedFieldOffset = type.getField("_reserved").getOffset();
a61af66fc99e Initial load
duke
parents:
diff changeset
80 virtualSpaceFieldOffset = type.getField("_virtual_space").getOffset();
a61af66fc99e Initial load
duke
parents:
diff changeset
81 levelField = type.getCIntegerField("_level");
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // StatRecord
a61af66fc99e Initial load
duke
parents:
diff changeset
83 statRecordField = type.getField("_stat_record");
a61af66fc99e Initial load
duke
parents:
diff changeset
84 type = db.lookupType("Generation::StatRecord");
a61af66fc99e Initial load
duke
parents:
diff changeset
85 invocationField = type.getCIntegerField("invocations");
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // constants from Generation::Name
a61af66fc99e Initial load
duke
parents:
diff changeset
88 NAME_DEF_NEW = db.lookupIntConstant("Generation::DefNew").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
89 NAME_PAR_NEW = db.lookupIntConstant("Generation::ParNew").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
90 NAME_MARK_SWEEP_COMPACT = db.lookupIntConstant("Generation::MarkSweepCompact").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
91 NAME_CONCURRENT_MARK_SWEEP = db.lookupIntConstant("Generation::ConcurrentMarkSweep").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
92 NAME_OTHER = db.lookupIntConstant("Generation::Other").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 public Generation(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 super(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 public static class Name {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 public static final Name DEF_NEW = new Name("DefNew");
a61af66fc99e Initial load
duke
parents:
diff changeset
101 public static final Name PAR_NEW = new Name("ParNew");
a61af66fc99e Initial load
duke
parents:
diff changeset
102 public static final Name MARK_SWEEP_COMPACT = new Name("MarkSweepCompact");
a61af66fc99e Initial load
duke
parents:
diff changeset
103 public static final Name CONCURRENT_MARK_SWEEP = new Name("ConcurrentMarkSweep");
a61af66fc99e Initial load
duke
parents:
diff changeset
104 public static final Name OTHER = new Name("Other");
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 private Name(String value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 this.value = value;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 private String value;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 public String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return value;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 public Generation.Name kind() {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 return Generation.Name.OTHER;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 static Generation.Name nameForEnum(int value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 if (value == NAME_DEF_NEW) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return Name.DEF_NEW;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 } else if (value == NAME_PAR_NEW) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 return Name.PAR_NEW;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 } else if (value == NAME_MARK_SWEEP_COMPACT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 return Name.MARK_SWEEP_COMPACT;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 } else if (value == NAME_CONCURRENT_MARK_SWEEP) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 return Name.CONCURRENT_MARK_SWEEP;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 } else if (value == NAME_OTHER) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 return Name.OTHER;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 throw new RuntimeException("should not reach here");
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 public GenerationSpec spec() {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 return ((GenCollectedHeap) VM.getVM().getUniverse().heap()).spec(level());
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 public int level() {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 return (int) levelField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 public int invocations() {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 return getStatRecord().getInvocations();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 /** The maximum number of object bytes the generation can currently
a61af66fc99e Initial load
duke
parents:
diff changeset
149 hold. */
a61af66fc99e Initial load
duke
parents:
diff changeset
150 public abstract long capacity();
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 /** The number of used bytes in the gen. */
a61af66fc99e Initial load
duke
parents:
diff changeset
153 public abstract long used();
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 /** The number of free bytes in the gen. */
a61af66fc99e Initial load
duke
parents:
diff changeset
156 public abstract long free();
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 /** The largest number of contiguous free words in the generation,
a61af66fc99e Initial load
duke
parents:
diff changeset
159 including expansion. (VM's version assumes it is called at a
a61af66fc99e Initial load
duke
parents:
diff changeset
160 safepoint.) */
a61af66fc99e Initial load
duke
parents:
diff changeset
161 public abstract long contiguousAvailable();
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 public MemRegion reserved() {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 return new MemRegion(addr.addOffsetTo(reservedFieldOffset));
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 /** Returns a region guaranteed to contain all the objects in the
a61af66fc99e Initial load
duke
parents:
diff changeset
168 generation. */
a61af66fc99e Initial load
duke
parents:
diff changeset
169 public MemRegion usedRegion() {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 return reserved();
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 /* Returns "TRUE" iff "p" points into an allocated object in the
a61af66fc99e Initial load
duke
parents:
diff changeset
174 generation. */
a61af66fc99e Initial load
duke
parents:
diff changeset
175 public boolean isIn(Address p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 GenerationIsInClosure blk = new GenerationIsInClosure(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
177 spaceIterate(blk);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 return (blk.space() != null);
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 /** Returns "TRUE" iff "p" points into the reserved area of the
a61af66fc99e Initial load
duke
parents:
diff changeset
182 generation. */
a61af66fc99e Initial load
duke
parents:
diff changeset
183 public boolean isInReserved(Address p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 return reserved().contains(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 protected VirtualSpace virtualSpace() {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 return (VirtualSpace) VMObjectFactory.newObject(VirtualSpace.class, addr.addOffsetTo(virtualSpaceFieldOffset));
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 public abstract String name();
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 /** Equivalent to spaceIterate(blk, false) */
a61af66fc99e Initial load
duke
parents:
diff changeset
194 public void spaceIterate(SpaceClosure blk) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 spaceIterate(blk, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 /** Iteration - do not use for time critical operations */
a61af66fc99e Initial load
duke
parents:
diff changeset
199 public abstract void spaceIterate(SpaceClosure blk, boolean usedOnly);
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 public void print() { printOn(System.out); }
a61af66fc99e Initial load
duke
parents:
diff changeset
202 public abstract void printOn(PrintStream tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 public static class StatRecord extends VMObject {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 public StatRecord(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 super(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 public int getInvocations() {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 return (int) invocationField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 private StatRecord getStatRecord() {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 return (StatRecord) VMObjectFactory.newObject(Generation.StatRecord.class, addr.addOffsetTo(statRecordField.getOffset()));
a61af66fc99e Initial load
duke
parents:
diff changeset
217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }