comparison agent/src/share/classes/sun/jvm/hotspot/memory/Space.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c18cbe5936b8
comparison
equal deleted inserted replaced
-1:000000000000 0:a61af66fc99e
1 /*
2 * Copyright 2000-2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 package sun.jvm.hotspot.memory;
26
27 import java.io.*;
28 import java.util.*;
29 import sun.jvm.hotspot.debugger.*;
30 import sun.jvm.hotspot.types.*;
31 import sun.jvm.hotspot.runtime.*;
32
33 /** <P> A Space describes a heap area. Class Space is an abstract base
34 class. </P>
35
36 <P> Space supports allocation, size computation and GC support is
37 provided. </P>
38
39 <P> Invariant: bottom() and end() are on page_size boundaries and: </P>
40
41 <P> bottom() <= top() <= end() </P>
42
43 <P> top() is inclusive and end() is exclusive. </P> */
44
45 public abstract class Space extends VMObject {
46 private static AddressField bottomField;
47 private static AddressField endField;
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 Type type = db.lookupType("Space");
59
60 bottomField = type.getAddressField("_bottom");
61 endField = type.getAddressField("_end");
62 }
63
64 public Space(Address addr) {
65 super(addr);
66 }
67
68 public Address bottom() { return bottomField.getValue(addr); }
69 public Address end() { return endField.getValue(addr); }
70
71 /** Returns a subregion of the space containing all the objects in
72 the space. */
73 public MemRegion usedRegion() {
74 return new MemRegion(bottom(), end());
75 }
76
77 /** Support for iteration over heap -- not sure how this will
78 interact with GC in reflective system, but necessary for the
79 debugging mechanism */
80 public OopHandle bottomAsOopHandle() {
81 return bottomField.getOopHandle(addr);
82 }
83
84 /** Support for iteration over heap -- not sure how this will
85 interact with GC in reflective system, but necessary for the
86 debugging mechanism */
87 public OopHandle nextOopHandle(OopHandle handle, long size) {
88 return handle.addOffsetToAsOopHandle(size);
89 }
90
91 /** returns all MemRegions where live objects are */
92 public abstract List/*<MemRegion>*/ getLiveRegions();
93
94 /** Returned value is in bytes */
95 public long capacity() { return end().minus(bottom()); }
96 /** Returned value is in bytes */
97 public abstract long used();
98 /** Returned value is in bytes */
99 public abstract long free();
100
101 /** Testers */
102 public boolean contains(Address p) {
103 return (bottom().lessThanOrEqual(p) && end().greaterThan(p));
104 }
105
106 public void print() { printOn(System.out); }
107 public void printOn(PrintStream tty) {
108 tty.print(" space capacity = ");
109 tty.print(capacity());
110 tty.print(", ");
111 tty.print((double) used() * 100.0/ capacity());
112 tty.print(" used");
113 }
114 }