Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/memory/CompactibleFreeListSpace.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 | d1605aabd0a1 |
children | 89e0543e1737 |
rev | line source |
---|---|
0 | 1 /* |
196 | 2 * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. |
0 | 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.oops.*; | |
31 import sun.jvm.hotspot.runtime.*; | |
32 import sun.jvm.hotspot.types.*; | |
33 import sun.jvm.hotspot.utilities.*; | |
34 | |
35 public class CompactibleFreeListSpace extends CompactibleSpace { | |
36 private static AddressField collectorField; | |
37 | |
152
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
38 // for free size, three fields |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
39 // FreeBlockDictionary* _dictionary; // ptr to dictionary for large size blocks |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
40 // FreeList _indexedFreeList[IndexSetSize]; // indexed array for small size blocks |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
41 // LinearAllocBlock _smallLinearAllocBlock; // small linear alloc in TLAB |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
42 private static AddressField indexedFreeListField; |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
43 private static AddressField dictionaryField; |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
44 private static long smallLinearAllocBlockFieldOffset; |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
45 private static long indexedFreeListSizeOf; |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
46 |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
47 private int heapWordSize; // 4 for 32bit, 8 for 64 bits |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
48 private int IndexSetStart; // for small indexed list |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
49 private int IndexSetSize; |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
50 private int IndexSetStride; |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
51 |
0 | 52 static { |
53 VM.registerVMInitializedObserver(new Observer() { | |
54 public void update(Observable o, Object data) { | |
55 initialize(VM.getVM().getTypeDataBase()); | |
56 } | |
57 }); | |
58 } | |
59 | |
60 private static synchronized void initialize(TypeDataBase db) { | |
61 long sizeofFreeChunk = db.lookupType("FreeChunk").getSize(); | |
62 VM vm = VM.getVM(); | |
63 MinChunkSizeInBytes = numQuanta(sizeofFreeChunk, vm.getMinObjAlignmentInBytes()) * | |
64 vm.getMinObjAlignmentInBytes(); | |
65 | |
66 Type type = db.lookupType("CompactibleFreeListSpace"); | |
67 collectorField = type.getAddressField("_collector"); | |
152
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
68 collectorField = type.getAddressField("_collector"); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
69 dictionaryField = type.getAddressField("_dictionary"); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
70 indexedFreeListField = type.getAddressField("_indexedFreeList[0]"); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
71 smallLinearAllocBlockFieldOffset = type.getField("_smallLinearAllocBlock").getOffset(); |
0 | 72 } |
73 | |
74 public CompactibleFreeListSpace(Address addr) { | |
75 super(addr); | |
152
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
76 if ( VM.getVM().isLP64() ) { |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
77 heapWordSize = 8; |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
78 IndexSetStart = 1; |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
79 IndexSetStride = 1; |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
80 } |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
81 else { |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
82 heapWordSize = 4; |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
83 IndexSetStart = 2; |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
84 IndexSetStride = 2; |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
85 } |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
86 |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
87 IndexSetSize = 257; |
0 | 88 } |
89 | |
90 // Accessing block offset table | |
91 public CMSCollector collector() { | |
92 return (CMSCollector) VMObjectFactory.newObject( | |
93 CMSCollector.class, | |
94 collectorField.getValue(addr)); | |
152
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
95 } |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
96 |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
97 public long free0() { |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
98 return capacity() - used0(); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
99 } |
0 | 100 |
101 public long used() { | |
152
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
102 return capacity() - free(); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
103 } |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
104 |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
105 public long used0() { |
0 | 106 List regions = getLiveRegions(); |
107 long usedSize = 0L; | |
108 for (Iterator itr = regions.iterator(); itr.hasNext();) { | |
109 MemRegion mr = (MemRegion) itr.next(); | |
110 usedSize += mr.byteSize(); | |
111 } | |
112 return usedSize; | |
113 } | |
114 | |
115 public long free() { | |
152
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
116 // small chunks |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
117 long size = 0; |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
118 Address cur = addr.addOffsetTo( indexedFreeListField.getOffset() ); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
119 cur = cur.addOffsetTo(IndexSetStart*FreeList.sizeOf()); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
120 for (int i=IndexSetStart; i<IndexSetSize; i += IndexSetStride) { |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
121 FreeList freeList = (FreeList) VMObjectFactory.newObject(FreeList.class, cur); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
122 size += i*freeList.count(); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
123 cur= cur.addOffsetTo(IndexSetStride*FreeList.sizeOf()); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
124 } |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
125 |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
126 // large block |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
127 BinaryTreeDictionary bfbd = (BinaryTreeDictionary) VMObjectFactory.newObject(BinaryTreeDictionary.class, |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
128 dictionaryField.getValue(addr)); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
129 size += bfbd.size(); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
130 |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
131 |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
132 // linear block in TLAB |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
133 LinearAllocBlock lab = (LinearAllocBlock) VMObjectFactory.newObject(LinearAllocBlock.class, |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
134 addr.addOffsetTo(smallLinearAllocBlockFieldOffset)); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
135 size += lab.word_size(); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
136 |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
137 return size*heapWordSize; |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
138 } |
0 | 139 |
140 public void printOn(PrintStream tty) { | |
141 tty.print("free-list-space"); | |
152
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
142 tty.print("[ " + bottom() + " , " + end() + " ) "); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
143 long cap = capacity(); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
144 long used_size = used(); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
145 long free_size = free(); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
146 int used_perc = (int)((double)used_size/cap*100); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
147 tty.print("space capacity = " + cap + " used(" + used_perc + "%)= " + used_size + " "); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
148 tty.print("free= " + free_size ); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
149 tty.print("\n"); |
c70a245cad3a
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
0
diff
changeset
|
150 |
0 | 151 } |
152 | |
153 public Address skipBlockSizeUsingPrintezisBits(Address pos) { | |
154 CMSCollector collector = collector(); | |
155 long size = 0; | |
156 Address addr = null; | |
157 | |
158 if (collector != null) { | |
159 size = collector.blockSizeUsingPrintezisBits(pos); | |
160 if (size >= 3) { | |
161 addr = pos.addOffsetTo(adjustObjectSizeInBytes(size)); | |
162 } | |
163 } | |
164 return addr; | |
165 } | |
166 | |
167 public List/*<MemRegion>*/ getLiveRegions() { | |
168 List res = new ArrayList(); // List<MemRegion> | |
169 VM vm = VM.getVM(); | |
170 Debugger dbg = vm.getDebugger(); | |
171 ObjectHeap heap = vm.getObjectHeap(); | |
172 Address cur = bottom(); | |
173 Address regionStart = cur; | |
174 Address limit = end(); | |
175 final long addressSize = vm.getAddressSize(); | |
176 | |
177 for (; cur.lessThan(limit);) { | |
178 Address klassOop = cur.getAddressAt(addressSize); | |
187 | 179 if (FreeChunk.indicatesFreeChunk(cur)) { |
0 | 180 if (! cur.equals(regionStart)) { |
181 res.add(new MemRegion(regionStart, cur)); | |
182 } | |
183 FreeChunk fc = (FreeChunk) VMObjectFactory.newObject(FreeChunk.class, cur); | |
184 long chunkSize = fc.size(); | |
185 if (Assert.ASSERTS_ENABLED) { | |
186 Assert.that(chunkSize > 0, "invalid FreeChunk size"); | |
187 } | |
188 // note that fc.size() gives chunk size in heap words | |
189 cur = cur.addOffsetTo(chunkSize * addressSize); | |
190 regionStart = cur; | |
191 } else if (klassOop != null) { | |
192 Oop obj = heap.newOop(cur.addOffsetToAsOopHandle(0)); | |
193 long objectSize = obj.getObjectSize(); | |
194 cur = cur.addOffsetTo(adjustObjectSizeInBytes(objectSize)); | |
904
ef671fb22f73
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
196
diff
changeset
|
195 } else { |
ef671fb22f73
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
196
diff
changeset
|
196 // FIXME: need to do a better job here. |
ef671fb22f73
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
196
diff
changeset
|
197 // can I use bitMap here? |
ef671fb22f73
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
196
diff
changeset
|
198 //Find the object size using Printezis bits and skip over |
ef671fb22f73
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
196
diff
changeset
|
199 long size = collector().blockSizeUsingPrintezisBits(cur); |
ef671fb22f73
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
196
diff
changeset
|
200 if (size == -1) { |
ef671fb22f73
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
196
diff
changeset
|
201 System.err.println("Printezis bits not set..."); |
ef671fb22f73
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
196
diff
changeset
|
202 break; |
ef671fb22f73
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
196
diff
changeset
|
203 } |
ef671fb22f73
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
196
diff
changeset
|
204 cur = cur.addOffsetTo(adjustObjectSizeInBytes(size)); |
0 | 205 } |
206 } | |
207 return res; | |
208 } | |
209 | |
210 //-- Internals only below this point | |
211 | |
212 // Unlike corresponding VM code, we operate on byte size rather than | |
213 // HeapWord size for convenience. | |
214 | |
215 private static long numQuanta(long x, long y) { | |
216 return ((x+y-1)/y); | |
217 } | |
218 | |
219 public static long adjustObjectSizeInBytes(long sizeInBytes) { | |
220 return Oop.alignObjectSize(Math.max(sizeInBytes, MinChunkSizeInBytes)); | |
221 } | |
222 | |
223 // FIXME: should I read this directly from VM? | |
224 private static long MinChunkSizeInBytes; | |
225 } |