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 * 23 */ 24 25 package sun.jvm.hotspot.memory; 26 27 import java.io.*; 28 import java.util.*; 29 30 import sun.jvm.hotspot.debugger.*; 31 import sun.jvm.hotspot.gc_interface.*; 32 import sun.jvm.hotspot.runtime.*; 33 import sun.jvm.hotspot.types.*; 34 import sun.jvm.hotspot.utilities.*; 35 36 public class GenCollectedHeap extends SharedHeap { 37 private static CIntegerField nGensField; 38 private static long gensOffset; 39 private static AddressField genSpecsField; 40 41 private static GenerationFactory genFactory; 42 43 static { 44 VM.registerVMInitializedObserver(new Observer() { 45 public void update(Observable o, Object data) { 46 initialize(VM.getVM().getTypeDataBase()); 47 } 48 }); 49 } 50 51 private static synchronized void initialize(TypeDataBase db) { 52 Type type = db.lookupType("GenCollectedHeap"); 53 54 nGensField = type.getCIntegerField("_n_gens"); 55 gensOffset = type.getField("_gens").getOffset(); 56 genSpecsField = type.getAddressField("_gen_specs"); 57 58 genFactory = new GenerationFactory(); 59 } 60 61 public GenCollectedHeap(Address addr) { 62 super(addr); 63 } 64 65 public int nGens() { 66 return (int) nGensField.getValue(addr); 67 } 68 69 public Generation getGen(int i) { 70 if (Assert.ASSERTS_ENABLED) { 71 Assert.that((i >= 0) && (i < nGens()), "Index " + i + 72 " out of range (should be between 0 and " + nGens() + ")"); 73 } 74 75 if ((i < 0) || (i >= nGens())) { 76 return null; 77 } 78 79 Address genAddr = addr.getAddressAt(gensOffset + 80 (i * VM.getVM().getAddressSize())); 81 return genFactory.newObject(addr.getAddressAt(gensOffset + 82 (i * VM.getVM().getAddressSize()))); 83 } 84 85 public boolean isIn(Address a) { 86 for (int i = 0; i < nGens(); i++) { 87 Generation gen = getGen(i); 88 if (gen.isIn(a)) { 89 return true; 90 } 91 } 92 93 return false; 94 } 95 96 public long capacity() { 97 long capacity = 0; 98 for (int i = 0; i < nGens(); i++) { 99 capacity += getGen(i).capacity(); 100 } 101 return capacity; 102 } | 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 * 23 */ 24 25 package sun.jvm.hotspot.memory; 26 27 import java.io.*; 28 import java.util.*; 29 30 import sun.jvm.hotspot.debugger.*; 31 import sun.jvm.hotspot.gc_interface.*; 32 import sun.jvm.hotspot.runtime.*; 33 import sun.jvm.hotspot.types.*; 34 import sun.jvm.hotspot.utilities.*; 35 36 public class GenCollectedHeap extends SharedHeap { 37 private static CIntegerField nGensField; 38 private static AddressField youngGenField; 39 private static AddressField oldGenField; 40 private static AddressField genSpecsField; 41 42 private static GenerationFactory genFactory; 43 44 static { 45 VM.registerVMInitializedObserver(new Observer() { 46 public void update(Observable o, Object data) { 47 initialize(VM.getVM().getTypeDataBase()); 48 } 49 }); 50 } 51 52 private static synchronized void initialize(TypeDataBase db) { 53 Type type = db.lookupType("GenCollectedHeap"); 54 55 nGensField = type.getCIntegerField("_n_gens"); 56 youngGenField = type.getAddressField("_young_gen"); 57 oldGenField = type.getAddressField("_old_gen"); 58 genSpecsField = type.getAddressField("_gen_specs"); 59 60 genFactory = new GenerationFactory(); 61 } 62 63 public GenCollectedHeap(Address addr) { 64 super(addr); 65 } 66 67 public int nGens() { 68 return (int) nGensField.getValue(addr); 69 } 70 71 public Generation getGen(int i) { 72 if (Assert.ASSERTS_ENABLED) { 73 Assert.that((i >= 0) && (i < nGens()), "Index " + i + 74 " out of range (should be between 0 and " + nGens() + ")"); 75 } 76 77 if ((i < 0) || (i >= nGens())) { 78 return null; 79 } 80 81 if (i == 0) { 82 return genFactory.newObject(youngGenField.getAddress()); 83 } else { 84 return genFactory.newObject(oldGenField.getAddress()); 85 } 86 } 87 88 public boolean isIn(Address a) { 89 for (int i = 0; i < nGens(); i++) { 90 Generation gen = getGen(i); 91 if (gen.isIn(a)) { 92 return true; 93 } 94 } 95 96 return false; 97 } 98 99 public long capacity() { 100 long capacity = 0; 101 for (int i = 0; i < nGens(); i++) { 102 capacity += getGen(i).capacity(); 103 } 104 return capacity; 105 } |