1 /*
2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
28 import java.util.*;
29
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.*;
37
38 public class CompactibleFreeListSpace extends CompactibleSpace {
39 private static AddressField collectorField;
40 private static AddressField indexedFreeListField;
41 private static AddressField dictionaryField;
42 private static long smallLinearAllocBlockFieldOffset;
43
44 private int heapWordSize; // 4 for 32bit, 8 for 64 bits
45 private int IndexSetStart; // for small indexed list
46 private int IndexSetSize;
47 private int IndexSetStride;
48
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");
65 collectorField = type.getAddressField("_collector");
66 dictionaryField = type.getAddressField("_dictionary");
67 indexedFreeListField = type.getAddressField("_indexedFreeList[0]");
68 smallLinearAllocBlockFieldOffset = type.getField("_smallLinearAllocBlock").getOffset();
69 }
70
71 public CompactibleFreeListSpace(Address addr) {
72 super(addr);
73 VM vm = VM.getVM();
74 heapWordSize = vm.getHeapWordSize();
75 IndexSetStart = vm.getMinObjAlignmentInBytes() / heapWordSize;
76 IndexSetStride = IndexSetStart;
77 IndexSetSize = 257;
78 }
79
80 // Accessing block offset table
81 public CMSCollector collector() {
82 return (CMSCollector) VMObjectFactory.newObject(
83 CMSCollector.class,
84 collectorField.getValue(addr));
85 }
86
87 public long free0() {
88 return capacity() - used0();
89 }
90
91 public long used() {
92 return capacity() - free();
93 }
94
95 public long used0() {
96 List regions = getLiveRegions();
97 long usedSize = 0L;
184 cur = cur.addOffsetTo(adjustObjectSizeInBytes(objectSize));
185 } else {
186 // FIXME: need to do a better job here.
187 // can I use bitMap here?
188 //Find the object size using Printezis bits and skip over
189 long size = collector().blockSizeUsingPrintezisBits(cur);
190 if (size == -1) {
191 break;
192 }
193 cur = cur.addOffsetTo(adjustObjectSizeInBytes(size));
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 }
|
1 /*
2 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
28 import java.util.*;
29
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.*;
37
38 public class CompactibleFreeListSpace extends CompactibleSpace {
39 private static AddressField collectorField;
40 private static AddressField indexedFreeListField;
41 private static AddressField dictionaryField;
42 private static long smallLinearAllocBlockFieldOffset;
43
44 private int heapWordSize; // 4 for 32bit, 8 for 64 bits
45 private int IndexSetStart; // for small indexed list
46 private int IndexSetSize;
47 private int IndexSetStride;
48 private static long MinChunkSizeInBytes;
49
50 static {
51 VM.registerVMInitializedObserver(new Observer() {
52 public void update(Observable o, Object data) {
53 initialize(VM.getVM().getTypeDataBase());
54 }
55 });
56 }
57
58 private static synchronized void initialize(TypeDataBase db) {
59 long sizeofFreeChunk = db.lookupType("FreeChunk").getSize();
60 VM vm = VM.getVM();
61
62 Type type = db.lookupType("CompactibleFreeListSpace");
63 collectorField = type.getAddressField("_collector");
64 collectorField = type.getAddressField("_collector");
65 dictionaryField = type.getAddressField("_dictionary");
66 indexedFreeListField = type.getAddressField("_indexedFreeList[0]");
67 smallLinearAllocBlockFieldOffset = type.getField("_smallLinearAllocBlock").getOffset();
68 MinChunkSizeInBytes = (type.getCIntegerField("_min_chunk_size_in_bytes")).getValue();
69 }
70
71 public CompactibleFreeListSpace(Address addr) {
72 super(addr);
73 VM vm = VM.getVM();
74 heapWordSize = vm.getHeapWordSize();
75 IndexSetStart = vm.getMinObjAlignmentInBytes() / heapWordSize;
76 IndexSetStride = IndexSetStart;
77 IndexSetSize = vm.getIndexSetSize();
78 }
79
80 // Accessing block offset table
81 public CMSCollector collector() {
82 return (CMSCollector) VMObjectFactory.newObject(
83 CMSCollector.class,
84 collectorField.getValue(addr));
85 }
86
87 public long free0() {
88 return capacity() - used0();
89 }
90
91 public long used() {
92 return capacity() - free();
93 }
94
95 public long used0() {
96 List regions = getLiveRegions();
97 long usedSize = 0L;
184 cur = cur.addOffsetTo(adjustObjectSizeInBytes(objectSize));
185 } else {
186 // FIXME: need to do a better job here.
187 // can I use bitMap here?
188 //Find the object size using Printezis bits and skip over
189 long size = collector().blockSizeUsingPrintezisBits(cur);
190 if (size == -1) {
191 break;
192 }
193 cur = cur.addOffsetTo(adjustObjectSizeInBytes(size));
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 public static long adjustObjectSizeInBytes(long sizeInBytes) {
205 return Oop.alignObjectSize(Math.max(sizeInBytes, MinChunkSizeInBytes));
206 }
207
208 }
|