1 /*
2 * Copyright 2000-2007 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 *
30 import sun.jvm.hotspot.debugger.*;
31 import sun.jvm.hotspot.runtime.*;
32 import sun.jvm.hotspot.types.*;
33 import sun.jvm.hotspot.memory.CompactingPermGenGen;
34
35 // Oop represents the superclass for all types of
36 // objects in the HotSpot object heap.
37
38 public class Oop {
39 static {
40 VM.registerVMInitializedObserver(new Observer() {
41 public void update(Observable o, Object data) {
42 initialize(VM.getVM().getTypeDataBase());
43 }
44 });
45 }
46
47 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
48 Type type = db.lookupType("oopDesc");
49 mark = new CIntField(type.getCIntegerField("_mark"), 0);
50 klass = new OopField(type.getOopField("_klass"), 0);
51 headerSize = type.getSize();
52 }
53
54 private OopHandle handle;
55 private ObjectHeap heap;
56
57 Oop(OopHandle handle, ObjectHeap heap) {
58 this.handle = handle;
59 this.heap = heap;
60 }
61
62 ObjectHeap getHeap() { return heap; }
63
64 /** Should not be used or needed by most clients outside this
65 package; is needed, however, by {@link
66 sun.jvm.hotspot.utilities.MarkBits}. */
67 public OopHandle getHandle() { return handle; }
68
69 private static long headerSize;
70 public static long getHeaderSize() { return headerSize; }
71
72 private static CIntField mark;
73 private static OopField klass;
74
75 public boolean isShared() {
76 return CompactingPermGenGen.isShared(handle);
77 }
78
79 public boolean isSharedReadOnly() {
80 return CompactingPermGenGen.isSharedReadOnly(handle);
81 }
82
83 public boolean isSharedReadWrite() {
84 return CompactingPermGenGen.isSharedReadWrite(handle);
85 }
86
87 // Accessors for declared fields
88 public Mark getMark() { return new Mark(getHandle()); }
89 public Klass getKlass() { return (Klass) klass.getValue(this); }
90
91 public boolean isA(Klass k) {
92 return getKlass().isSubtypeOf(k);
93 }
94
95 // Returns the byte size of this object
96 public long getObjectSize() {
97 Klass k = getKlass();
98 if (k instanceof InstanceKlass) {
99 return ((InstanceKlass)k).getSizeHelper()
100 * VM.getVM().getAddressSize();
101 }
102 // If it is not an instance, this method should be replaced.
103 return getHeaderSize();
104 }
105
106 // Type test operations
107 public boolean isInstance() { return false; }
108 public boolean isInstanceRef() { return false; }
109 public boolean isArray() { return false; }
110 public boolean isObjArray() { return false; }
111 public boolean isTypeArray() { return false; }
112 public boolean isSymbol() { return false; }
113 public boolean isKlass() { return false; }
114 public boolean isThread() { return false; }
115 public boolean isMethod() { return false; }
116 public boolean isMethodData() { return false; }
117 public boolean isConstantPool() { return false; }
118 public boolean isConstantPoolCache() { return false; }
119 public boolean isCompiledICHolder() { return false; }
120
121 // Align the object size.
122 public static long alignObjectSize(long size) {
123 return VM.getVM().alignUp(size, VM.getVM().getMinObjAlignmentInBytes());
124 }
125
126 // All vm's align longs, so pad out certain offsets.
127 public static long alignObjectOffset(long offset) {
128 return VM.getVM().alignUp(offset, VM.getVM().getBytesPerLong());
129 }
130
131 public boolean equals(Object obj) {
132 if (obj != null && (obj instanceof Oop)) {
133 return getHandle().equals(((Oop) obj).getHandle());
134 }
135 return false;
136 }
137
138 public int hashCode() { return getHandle().hashCode(); }
139
140 /** Identity hash in the target VM */
141 public long identityHash() {
142 Mark mark = getMark();
143 if (mark.isUnlocked() && (!mark.hasNoHash())) {
146 return (int) mark.hash();
147 } else {
148 return slowIdentityHash();
149 }
150 }
151
152 public long slowIdentityHash() {
153 return VM.getVM().getObjectSynchronizer().identityHashValueFor(this);
154 }
155
156 public void iterate(OopVisitor visitor, boolean doVMFields) {
157 visitor.setObj(this);
158 visitor.prologue();
159 iterateFields(visitor, doVMFields);
160 visitor.epilogue();
161 }
162
163 void iterateFields(OopVisitor visitor, boolean doVMFields) {
164 if (doVMFields) {
165 visitor.doCInt(mark, true);
166 visitor.doOop(klass, true);
167 }
168 }
169
170 public void print() { printOn(System.out); }
171 public void printValue() { printValueOn(System.out); }
172 public void printRaw() { printRawOn(System.out); }
173
174 public static void printOopValueOn(Oop obj, PrintStream tty) {
175 if (obj == null) {
176 tty.print("null");
177 } else {
178 obj.printValueOn(tty);
179 tty.print(" @ " + obj.getHandle());
180 }
181 }
182
183 public static void printOopAddressOn(Oop obj, PrintStream tty) {
184 if (obj == null) {
185 tty.print("null");
186 } else {
187 tty.print(obj.getHandle().toString());
188 }
202 }
203
204 public void printRawOn(PrintStream tty) {
205 tty.print("Dumping raw memory for ");
206 printValueOn(tty);
207 tty.println();
208 long size = getObjectSize() * 4;
209 for (long i = 0; i < size; i += 4) {
210 long memVal = getHandle().getCIntegerAt(i, 4, true);
211 tty.println(Long.toHexString(memVal));
212 }
213 }
214
215 public boolean verify() { return true;}
216
217 // Package-private routine to speed up ObjectHeap.newOop
218 static OopHandle getKlassForOopHandle(OopHandle handle) {
219 if (handle == null) {
220 return null;
221 }
222 return handle.getOopHandleAt(klass.getOffset());
223 }
224 };
|
1 /*
2 * Copyright 2000-2008 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 *
30 import sun.jvm.hotspot.debugger.*;
31 import sun.jvm.hotspot.runtime.*;
32 import sun.jvm.hotspot.types.*;
33 import sun.jvm.hotspot.memory.CompactingPermGenGen;
34
35 // Oop represents the superclass for all types of
36 // objects in the HotSpot object heap.
37
38 public class Oop {
39 static {
40 VM.registerVMInitializedObserver(new Observer() {
41 public void update(Observable o, Object data) {
42 initialize(VM.getVM().getTypeDataBase());
43 }
44 });
45 }
46
47 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
48 Type type = db.lookupType("oopDesc");
49 mark = new CIntField(type.getCIntegerField("_mark"), 0);
50 klass = new OopField(type.getOopField("_metadata._klass"), 0);
51 compressedKlass = new NarrowOopField(type.getOopField("_metadata._compressed_klass"), 0);
52 headerSize = type.getSize();
53 }
54
55 private OopHandle handle;
56 private ObjectHeap heap;
57
58 Oop(OopHandle handle, ObjectHeap heap) {
59 this.handle = handle;
60 this.heap = heap;
61 }
62
63 ObjectHeap getHeap() { return heap; }
64
65 /** Should not be used or needed by most clients outside this
66 package; is needed, however, by {@link
67 sun.jvm.hotspot.utilities.MarkBits}. */
68 public OopHandle getHandle() { return handle; }
69
70 private static long headerSize;
71 public static long getHeaderSize() { return headerSize; } // Header size in bytes.
72
73 private static CIntField mark;
74 private static OopField klass;
75 private static NarrowOopField compressedKlass;
76
77 public boolean isShared() {
78 return CompactingPermGenGen.isShared(handle);
79 }
80
81 public boolean isSharedReadOnly() {
82 return CompactingPermGenGen.isSharedReadOnly(handle);
83 }
84
85 public boolean isSharedReadWrite() {
86 return CompactingPermGenGen.isSharedReadWrite(handle);
87 }
88
89 // Accessors for declared fields
90 public Mark getMark() { return new Mark(getHandle()); }
91 public Klass getKlass() {
92 if (VM.getVM().isCompressedOopsEnabled()) {
93 return (Klass) compressedKlass.getValue(this);
94 } else {
95 return (Klass) klass.getValue(this);
96 }
97 }
98
99 public boolean isA(Klass k) {
100 return getKlass().isSubtypeOf(k);
101 }
102
103 // Returns the byte size of this object
104 public long getObjectSize() {
105 Klass k = getKlass();
106 if (k instanceof InstanceKlass) {
107 return ((InstanceKlass)k).getSizeHelper()
108 * VM.getVM().getAddressSize();
109 }
110 // If it is not an instance, this method should be replaced.
111 return getHeaderSize();
112 }
113
114 // Type test operations
115 public boolean isInstance() { return false; }
116 public boolean isInstanceRef() { return false; }
117 public boolean isArray() { return false; }
118 public boolean isObjArray() { return false; }
119 public boolean isTypeArray() { return false; }
120 public boolean isSymbol() { return false; }
121 public boolean isKlass() { return false; }
122 public boolean isThread() { return false; }
123 public boolean isMethod() { return false; }
124 public boolean isMethodData() { return false; }
125 public boolean isConstantPool() { return false; }
126 public boolean isConstantPoolCache() { return false; }
127 public boolean isCompiledICHolder() { return false; }
128
129 // Align the object size.
130 public static long alignObjectSize(long size) {
131 return VM.getVM().alignUp(size, VM.getVM().getMinObjAlignment());
132 }
133
134 // All vm's align longs, so pad out certain offsets.
135 public static long alignObjectOffset(long offset) {
136 return VM.getVM().alignUp(offset, VM.getVM().getBytesPerLong());
137 }
138
139 public boolean equals(Object obj) {
140 if (obj != null && (obj instanceof Oop)) {
141 return getHandle().equals(((Oop) obj).getHandle());
142 }
143 return false;
144 }
145
146 public int hashCode() { return getHandle().hashCode(); }
147
148 /** Identity hash in the target VM */
149 public long identityHash() {
150 Mark mark = getMark();
151 if (mark.isUnlocked() && (!mark.hasNoHash())) {
154 return (int) mark.hash();
155 } else {
156 return slowIdentityHash();
157 }
158 }
159
160 public long slowIdentityHash() {
161 return VM.getVM().getObjectSynchronizer().identityHashValueFor(this);
162 }
163
164 public void iterate(OopVisitor visitor, boolean doVMFields) {
165 visitor.setObj(this);
166 visitor.prologue();
167 iterateFields(visitor, doVMFields);
168 visitor.epilogue();
169 }
170
171 void iterateFields(OopVisitor visitor, boolean doVMFields) {
172 if (doVMFields) {
173 visitor.doCInt(mark, true);
174 if (VM.getVM().isCompressedOopsEnabled()) {
175 visitor.doOop(compressedKlass, true);
176 } else {
177 visitor.doOop(klass, true);
178 }
179 }
180 }
181
182 public void print() { printOn(System.out); }
183 public void printValue() { printValueOn(System.out); }
184 public void printRaw() { printRawOn(System.out); }
185
186 public static void printOopValueOn(Oop obj, PrintStream tty) {
187 if (obj == null) {
188 tty.print("null");
189 } else {
190 obj.printValueOn(tty);
191 tty.print(" @ " + obj.getHandle());
192 }
193 }
194
195 public static void printOopAddressOn(Oop obj, PrintStream tty) {
196 if (obj == null) {
197 tty.print("null");
198 } else {
199 tty.print(obj.getHandle().toString());
200 }
214 }
215
216 public void printRawOn(PrintStream tty) {
217 tty.print("Dumping raw memory for ");
218 printValueOn(tty);
219 tty.println();
220 long size = getObjectSize() * 4;
221 for (long i = 0; i < size; i += 4) {
222 long memVal = getHandle().getCIntegerAt(i, 4, true);
223 tty.println(Long.toHexString(memVal));
224 }
225 }
226
227 public boolean verify() { return true;}
228
229 // Package-private routine to speed up ObjectHeap.newOop
230 static OopHandle getKlassForOopHandle(OopHandle handle) {
231 if (handle == null) {
232 return null;
233 }
234 if (VM.getVM().isCompressedOopsEnabled()) {
235 return handle.getCompOopHandleAt(compressedKlass.getOffset());
236 } else {
237 return handle.getOopHandleAt(klass.getOffset());
238 }
239 }
240 };
|