22 * |
22 * |
23 */ |
23 */ |
24 |
24 |
25 package sun.jvm.hotspot.gc_implementation.g1; |
25 package sun.jvm.hotspot.gc_implementation.g1; |
26 |
26 |
|
27 import java.util.ArrayList; |
|
28 import java.util.List; |
27 import java.util.Observable; |
29 import java.util.Observable; |
28 import java.util.Observer; |
30 import java.util.Observer; |
29 |
|
30 import sun.jvm.hotspot.debugger.Address; |
31 import sun.jvm.hotspot.debugger.Address; |
31 import sun.jvm.hotspot.memory.ContiguousSpace; |
32 import sun.jvm.hotspot.memory.CompactibleSpace; |
|
33 import sun.jvm.hotspot.memory.MemRegion; |
32 import sun.jvm.hotspot.runtime.VM; |
34 import sun.jvm.hotspot.runtime.VM; |
|
35 import sun.jvm.hotspot.types.AddressField; |
33 import sun.jvm.hotspot.types.CIntegerField; |
36 import sun.jvm.hotspot.types.CIntegerField; |
34 import sun.jvm.hotspot.types.Type; |
37 import sun.jvm.hotspot.types.Type; |
35 import sun.jvm.hotspot.types.TypeDataBase; |
38 import sun.jvm.hotspot.types.TypeDataBase; |
36 |
39 |
37 // Mirror class for HeapRegion. Currently we don't actually include |
40 // Mirror class for HeapRegion. Currently we don't actually include |
38 // any of its fields but only iterate over it (which we get "for free" |
41 // any of its fields but only iterate over it. |
39 // as HeapRegion ultimately inherits from ContiguousSpace). |
|
40 |
42 |
41 public class HeapRegion extends ContiguousSpace { |
43 public class HeapRegion extends CompactibleSpace { |
42 // static int GrainBytes; |
44 // static int GrainBytes; |
43 static private CIntegerField grainBytesField; |
45 static private CIntegerField grainBytesField; |
|
46 static private AddressField topField; |
44 |
47 |
45 static { |
48 static { |
46 VM.registerVMInitializedObserver(new Observer() { |
49 VM.registerVMInitializedObserver(new Observer() { |
47 public void update(Observable o, Object data) { |
50 public void update(Observable o, Object data) { |
48 initialize(VM.getVM().getTypeDataBase()); |
51 initialize(VM.getVM().getTypeDataBase()); |
52 |
55 |
53 static private synchronized void initialize(TypeDataBase db) { |
56 static private synchronized void initialize(TypeDataBase db) { |
54 Type type = db.lookupType("HeapRegion"); |
57 Type type = db.lookupType("HeapRegion"); |
55 |
58 |
56 grainBytesField = type.getCIntegerField("GrainBytes"); |
59 grainBytesField = type.getCIntegerField("GrainBytes"); |
|
60 topField = type.getAddressField("_top"); |
|
61 |
57 } |
62 } |
58 |
63 |
59 static public long grainBytes() { |
64 static public long grainBytes() { |
60 return grainBytesField.getValue(); |
65 return grainBytesField.getValue(); |
61 } |
66 } |
62 |
67 |
63 public HeapRegion(Address addr) { |
68 public HeapRegion(Address addr) { |
64 super(addr); |
69 super(addr); |
65 } |
70 } |
|
71 |
|
72 public Address top() { |
|
73 return topField.getValue(addr); |
|
74 } |
|
75 |
|
76 @Override |
|
77 public List getLiveRegions() { |
|
78 List res = new ArrayList(); |
|
79 res.add(new MemRegion(bottom(), top())); |
|
80 return res; |
|
81 } |
|
82 |
|
83 @Override |
|
84 public long used() { |
|
85 return top().minus(bottom()); |
|
86 } |
|
87 |
|
88 @Override |
|
89 public long free() { |
|
90 return end().minus(top()); |
|
91 } |
66 } |
92 } |