author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 35217 | hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/cms/CompactibleFreeListSpace.java@ce4b5303a813 |
child 47816 | ac0af7750da9 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
30769 | 2 |
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3795
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3795
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3795
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
30769 | 25 |
package sun.jvm.hotspot.gc.cms; |
1 | 26 |
|
30769 | 27 |
import java.io.*; |
28 |
import java.util.*; |
|
22886
e8b17e1f03ac
8033440: jmap reports unexpected used/free size of concurrent mark-sweep generation
sjohanss
parents:
15735
diff
changeset
|
29 |
|
30769 | 30 |
import sun.jvm.hotspot.debugger.*; |
31 |
import sun.jvm.hotspot.gc.shared.*; |
|
32 |
import sun.jvm.hotspot.memory.*; |
|
33 |
import sun.jvm.hotspot.oops.*; |
|
34 |
import sun.jvm.hotspot.runtime.*; |
|
35 |
import sun.jvm.hotspot.types.*; |
|
36 |
import sun.jvm.hotspot.utilities.*; |
|
1 | 37 |
|
38 |
public class CompactibleFreeListSpace extends CompactibleSpace { |
|
39 |
private static AddressField collectorField; |
|
578
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
40 |
private static AddressField indexedFreeListField; |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
41 |
private static AddressField dictionaryField; |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
42 |
private static long smallLinearAllocBlockFieldOffset; |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
43 |
|
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
44 |
private int heapWordSize; // 4 for 32bit, 8 for 64 bits |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
45 |
private int IndexSetStart; // for small indexed list |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
46 |
private int IndexSetSize; |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
47 |
private int IndexSetStride; |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
48 |
|
1 | 49 |
static { |
50 |
VM.registerVMInitializedObserver(new Observer() { |
|
51 |
public void update(Observable o, Object data) { |
|
52 |
initialize(VM.getVM().getTypeDataBase()); |
|
53 |
} |
|
54 |
}); |
|
55 |
} |
|
56 |
||
57 |
private static synchronized void initialize(TypeDataBase db) { |
|
58 |
long sizeofFreeChunk = db.lookupType("FreeChunk").getSize(); |
|
59 |
VM vm = VM.getVM(); |
|
60 |
MinChunkSizeInBytes = numQuanta(sizeofFreeChunk, vm.getMinObjAlignmentInBytes()) * |
|
61 |
vm.getMinObjAlignmentInBytes(); |
|
62 |
||
63 |
Type type = db.lookupType("CompactibleFreeListSpace"); |
|
64 |
collectorField = type.getAddressField("_collector"); |
|
578
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
65 |
collectorField = type.getAddressField("_collector"); |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
66 |
dictionaryField = type.getAddressField("_dictionary"); |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
67 |
indexedFreeListField = type.getAddressField("_indexedFreeList[0]"); |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
68 |
smallLinearAllocBlockFieldOffset = type.getField("_smallLinearAllocBlock").getOffset(); |
1 | 69 |
} |
70 |
||
71 |
public CompactibleFreeListSpace(Address addr) { |
|
72 |
super(addr); |
|
5694
1e0532a6abff
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
3795
diff
changeset
|
73 |
VM vm = VM.getVM(); |
1e0532a6abff
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
3795
diff
changeset
|
74 |
heapWordSize = vm.getHeapWordSize(); |
1e0532a6abff
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
3795
diff
changeset
|
75 |
IndexSetStart = vm.getMinObjAlignmentInBytes() / heapWordSize; |
1e0532a6abff
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
3795
diff
changeset
|
76 |
IndexSetStride = IndexSetStart; |
1e0532a6abff
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
3795
diff
changeset
|
77 |
IndexSetSize = 257; |
1 | 78 |
} |
79 |
||
80 |
// Accessing block offset table |
|
81 |
public CMSCollector collector() { |
|
82 |
return (CMSCollector) VMObjectFactory.newObject( |
|
83 |
CMSCollector.class, |
|
84 |
collectorField.getValue(addr)); |
|
578
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
85 |
} |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
86 |
|
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
87 |
public long free0() { |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
88 |
return capacity() - used0(); |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
89 |
} |
1 | 90 |
|
91 |
public long used() { |
|
578
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
92 |
return capacity() - free(); |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
93 |
} |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
94 |
|
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
95 |
public long used0() { |
1 | 96 |
List regions = getLiveRegions(); |
97 |
long usedSize = 0L; |
|
98 |
for (Iterator itr = regions.iterator(); itr.hasNext();) { |
|
99 |
MemRegion mr = (MemRegion) itr.next(); |
|
100 |
usedSize += mr.byteSize(); |
|
101 |
} |
|
102 |
return usedSize; |
|
103 |
} |
|
104 |
||
105 |
public long free() { |
|
578
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
106 |
// small chunks |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
107 |
long size = 0; |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
108 |
Address cur = addr.addOffsetTo( indexedFreeListField.getOffset() ); |
22886
e8b17e1f03ac
8033440: jmap reports unexpected used/free size of concurrent mark-sweep generation
sjohanss
parents:
15735
diff
changeset
|
109 |
cur = cur.addOffsetTo(IndexSetStart*AdaptiveFreeList.sizeOf()); |
578
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
110 |
for (int i=IndexSetStart; i<IndexSetSize; i += IndexSetStride) { |
22886
e8b17e1f03ac
8033440: jmap reports unexpected used/free size of concurrent mark-sweep generation
sjohanss
parents:
15735
diff
changeset
|
111 |
AdaptiveFreeList freeList = (AdaptiveFreeList) VMObjectFactory.newObject(AdaptiveFreeList.class, cur); |
578
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
112 |
size += i*freeList.count(); |
22886
e8b17e1f03ac
8033440: jmap reports unexpected used/free size of concurrent mark-sweep generation
sjohanss
parents:
15735
diff
changeset
|
113 |
cur= cur.addOffsetTo(IndexSetStride*AdaptiveFreeList.sizeOf()); |
578
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
114 |
} |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
115 |
|
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
116 |
// large block |
15431
570c5062ab8a
8005278: Serviceability Agent: jmap -heap and jstack -m fail
minqi
parents:
13728
diff
changeset
|
117 |
AFLBinaryTreeDictionary aflbd = (AFLBinaryTreeDictionary) VMObjectFactory.newObject(AFLBinaryTreeDictionary.class, |
578
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
118 |
dictionaryField.getValue(addr)); |
15431
570c5062ab8a
8005278: Serviceability Agent: jmap -heap and jstack -m fail
minqi
parents:
13728
diff
changeset
|
119 |
size += aflbd.size(); |
578
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
120 |
|
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
121 |
|
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
122 |
// linear block in TLAB |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
123 |
LinearAllocBlock lab = (LinearAllocBlock) VMObjectFactory.newObject(LinearAllocBlock.class, |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
124 |
addr.addOffsetTo(smallLinearAllocBlockFieldOffset)); |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
125 |
size += lab.word_size(); |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
126 |
|
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
127 |
return size*heapWordSize; |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
128 |
} |
1 | 129 |
|
130 |
public void printOn(PrintStream tty) { |
|
131 |
tty.print("free-list-space"); |
|
578
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
132 |
tty.print("[ " + bottom() + " , " + end() + " ) "); |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
133 |
long cap = capacity(); |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
134 |
long used_size = used(); |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
135 |
long free_size = free(); |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
136 |
int used_perc = (int)((double)used_size/cap*100); |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
137 |
tty.print("space capacity = " + cap + " used(" + used_perc + "%)= " + used_size + " "); |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
138 |
tty.print("free= " + free_size ); |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
139 |
tty.print("\n"); |
862a85ed20db
6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents:
1
diff
changeset
|
140 |
|
1 | 141 |
} |
142 |
||
143 |
public Address skipBlockSizeUsingPrintezisBits(Address pos) { |
|
144 |
CMSCollector collector = collector(); |
|
145 |
long size = 0; |
|
146 |
Address addr = null; |
|
147 |
||
148 |
if (collector != null) { |
|
149 |
size = collector.blockSizeUsingPrintezisBits(pos); |
|
150 |
if (size >= 3) { |
|
151 |
addr = pos.addOffsetTo(adjustObjectSizeInBytes(size)); |
|
152 |
} |
|
153 |
} |
|
154 |
return addr; |
|
155 |
} |
|
156 |
||
157 |
public List/*<MemRegion>*/ getLiveRegions() { |
|
158 |
List res = new ArrayList(); // List<MemRegion> |
|
159 |
VM vm = VM.getVM(); |
|
160 |
Debugger dbg = vm.getDebugger(); |
|
161 |
ObjectHeap heap = vm.getObjectHeap(); |
|
162 |
Address cur = bottom(); |
|
163 |
Address regionStart = cur; |
|
164 |
Address limit = end(); |
|
165 |
final long addressSize = vm.getAddressSize(); |
|
166 |
||
167 |
for (; cur.lessThan(limit);) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7662
diff
changeset
|
168 |
Address k = cur.getAddressAt(addressSize); |
613 | 169 |
if (FreeChunk.indicatesFreeChunk(cur)) { |
1 | 170 |
if (! cur.equals(regionStart)) { |
171 |
res.add(new MemRegion(regionStart, cur)); |
|
172 |
} |
|
173 |
FreeChunk fc = (FreeChunk) VMObjectFactory.newObject(FreeChunk.class, cur); |
|
174 |
long chunkSize = fc.size(); |
|
175 |
if (Assert.ASSERTS_ENABLED) { |
|
176 |
Assert.that(chunkSize > 0, "invalid FreeChunk size"); |
|
177 |
} |
|
178 |
// note that fc.size() gives chunk size in heap words |
|
179 |
cur = cur.addOffsetTo(chunkSize * addressSize); |
|
180 |
regionStart = cur; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7662
diff
changeset
|
181 |
} else if (k != null) { |
1 | 182 |
Oop obj = heap.newOop(cur.addOffsetToAsOopHandle(0)); |
183 |
long objectSize = obj.getObjectSize(); |
|
184 |
cur = cur.addOffsetTo(adjustObjectSizeInBytes(objectSize)); |
|
3604
30fbd94d4963
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
670
diff
changeset
|
185 |
} else { |
30fbd94d4963
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
670
diff
changeset
|
186 |
// FIXME: need to do a better job here. |
30fbd94d4963
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
670
diff
changeset
|
187 |
// can I use bitMap here? |
30fbd94d4963
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
670
diff
changeset
|
188 |
//Find the object size using Printezis bits and skip over |
30fbd94d4963
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
670
diff
changeset
|
189 |
long size = collector().blockSizeUsingPrintezisBits(cur); |
30fbd94d4963
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
670
diff
changeset
|
190 |
if (size == -1) { |
30fbd94d4963
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
670
diff
changeset
|
191 |
break; |
30fbd94d4963
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
670
diff
changeset
|
192 |
} |
30fbd94d4963
6868051: (SA) FreeChunk support for compressed oops is broken
never
parents:
670
diff
changeset
|
193 |
cur = cur.addOffsetTo(adjustObjectSizeInBytes(size)); |
1 | 194 |
} |
195 |
} |
|
196 |
return res; |
|
197 |
} |
|
198 |
||
199 |
//-- Internals only below this point |
|
200 |
||
201 |
// Unlike corresponding VM code, we operate on byte size rather than |
|
202 |
// HeapWord size for convenience. |
|
203 |
||
204 |
private static long numQuanta(long x, long y) { |
|
205 |
return ((x+y-1)/y); |
|
206 |
} |
|
207 |
||
208 |
public static long adjustObjectSizeInBytes(long sizeInBytes) { |
|
209 |
return Oop.alignObjectSize(Math.max(sizeInBytes, MinChunkSizeInBytes)); |
|
210 |
} |
|
211 |
||
212 |
// FIXME: should I read this directly from VM? |
|
213 |
private static long MinChunkSizeInBytes; |
|
214 |
} |