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