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

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c70a245cad3a 790e66e5fbac
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 2003-2007 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.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 public class CompactibleFreeListSpace extends CompactibleSpace {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private static AddressField collectorField;
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 initialize(VM.getVM().getTypeDataBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
42 }
a61af66fc99e Initial load
duke
parents:
diff changeset
43 });
a61af66fc99e Initial load
duke
parents:
diff changeset
44 }
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 private static synchronized void initialize(TypeDataBase db) {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 long sizeofFreeChunk = db.lookupType("FreeChunk").getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
48 VM vm = VM.getVM();
a61af66fc99e Initial load
duke
parents:
diff changeset
49 MinChunkSizeInBytes = numQuanta(sizeofFreeChunk, vm.getMinObjAlignmentInBytes()) *
a61af66fc99e Initial load
duke
parents:
diff changeset
50 vm.getMinObjAlignmentInBytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 Type type = db.lookupType("CompactibleFreeListSpace");
a61af66fc99e Initial load
duke
parents:
diff changeset
53 collectorField = type.getAddressField("_collector");
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 public CompactibleFreeListSpace(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 super(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // Accessing block offset table
a61af66fc99e Initial load
duke
parents:
diff changeset
61 public CMSCollector collector() {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 return (CMSCollector) VMObjectFactory.newObject(
a61af66fc99e Initial load
duke
parents:
diff changeset
63 CMSCollector.class,
a61af66fc99e Initial load
duke
parents:
diff changeset
64 collectorField.getValue(addr));
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 public long used() {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 List regions = getLiveRegions();
a61af66fc99e Initial load
duke
parents:
diff changeset
69 long usedSize = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 for (Iterator itr = regions.iterator(); itr.hasNext();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 MemRegion mr = (MemRegion) itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
72 usedSize += mr.byteSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 return usedSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 public long free() {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 return capacity() - used();
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 public void printOn(PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 tty.print("free-list-space");
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 public Address skipBlockSizeUsingPrintezisBits(Address pos) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 CMSCollector collector = collector();
a61af66fc99e Initial load
duke
parents:
diff changeset
87 long size = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 Address addr = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 if (collector != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 size = collector.blockSizeUsingPrintezisBits(pos);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 if (size >= 3) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 addr = pos.addOffsetTo(adjustObjectSizeInBytes(size));
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return 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 List/*<MemRegion>*/ getLiveRegions() {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 List res = new ArrayList(); // List<MemRegion>
a61af66fc99e Initial load
duke
parents:
diff changeset
101 VM vm = VM.getVM();
a61af66fc99e Initial load
duke
parents:
diff changeset
102 Debugger dbg = vm.getDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
103 ObjectHeap heap = vm.getObjectHeap();
a61af66fc99e Initial load
duke
parents:
diff changeset
104 Address cur = bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
105 Address regionStart = cur;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 Address limit = end();
a61af66fc99e Initial load
duke
parents:
diff changeset
107 final long addressSize = vm.getAddressSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 for (; cur.lessThan(limit);) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 Address klassOop = cur.getAddressAt(addressSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // FIXME: need to do a better job here.
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // can I use bitMap here?
a61af66fc99e Initial load
duke
parents:
diff changeset
113 if (klassOop == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 //Find the object size using Printezis bits and skip over
a61af66fc99e Initial load
duke
parents:
diff changeset
115 System.err.println("Finding object size using Printezis bits and skipping over...");
a61af66fc99e Initial load
duke
parents:
diff changeset
116 long size = collector().blockSizeUsingPrintezisBits(cur);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 if (size == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 System.err.println("Printezis bits not set...");
a61af66fc99e Initial load
duke
parents:
diff changeset
119 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121 cur = cur.addOffsetTo(adjustObjectSizeInBytes(size));
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 if (FreeChunk.secondWordIndicatesFreeChunk(dbg.getAddressValue(klassOop))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 if (! cur.equals(regionStart)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 res.add(new MemRegion(regionStart, cur));
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128 FreeChunk fc = (FreeChunk) VMObjectFactory.newObject(FreeChunk.class, cur);
a61af66fc99e Initial load
duke
parents:
diff changeset
129 long chunkSize = fc.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
130 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 Assert.that(chunkSize > 0, "invalid FreeChunk size");
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // note that fc.size() gives chunk size in heap words
a61af66fc99e Initial load
duke
parents:
diff changeset
134 cur = cur.addOffsetTo(chunkSize * addressSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 System.err.println("Free chunk in CMS heap, size="+chunkSize * addressSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 regionStart = cur;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 } else if (klassOop != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 Oop obj = heap.newOop(cur.addOffsetToAsOopHandle(0));
a61af66fc99e Initial load
duke
parents:
diff changeset
139 long objectSize = obj.getObjectSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 cur = cur.addOffsetTo(adjustObjectSizeInBytes(objectSize));
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 //-- Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // Unlike corresponding VM code, we operate on byte size rather than
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // HeapWord size for convenience.
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 private static long numQuanta(long x, long y) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 return ((x+y-1)/y);
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 public static long adjustObjectSizeInBytes(long sizeInBytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 return Oop.alignObjectSize(Math.max(sizeInBytes, MinChunkSizeInBytes));
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // FIXME: should I read this directly from VM?
a61af66fc99e Initial load
duke
parents:
diff changeset
160 private static long MinChunkSizeInBytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }