31 import sun.jvm.hotspot.runtime.*;
32 import sun.jvm.hotspot.types.*;
33 import sun.jvm.hotspot.utilities.Observable;
34 import sun.jvm.hotspot.utilities.Observer;
35
36 // Oop represents the superclass for all types of
37 // objects in the HotSpot object heap.
38
39 public class Oop {
40 static {
41 VM.registerVMInitializedObserver(new Observer() {
42 public void update(Observable o, Object data) {
43 initialize(VM.getVM().getTypeDataBase());
44 }
45 });
46 }
47
48 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
49 Type type = db.lookupType("oopDesc");
50 mark = new CIntField(type.getCIntegerField("_mark"), 0);
51 klass = new MetadataField(type.getAddressField("_metadata._klass"), 0);
52 compressedKlass = new NarrowKlassField(type.getAddressField("_metadata._compressed_klass"), 0);
53 headerSize = type.getSize();
54 }
55
56 private OopHandle handle;
57 private ObjectHeap heap;
58
59 Oop(OopHandle handle, ObjectHeap heap) {
60 this.handle = handle;
61 this.heap = heap;
62 }
63
64 ObjectHeap getHeap() { return heap; }
65
66 /** Should not be used or needed by most clients outside this
67 package; is needed, however, by {@link
68 sun.jvm.hotspot.utilities.MarkBits}. */
69 public OopHandle getHandle() { return handle; }
70
71 private static long headerSize;
72 public static long getHeaderSize() { return headerSize; } // Header size in bytes.
73
74 private static CIntField mark;
75 private static MetadataField klass;
76 private static NarrowKlassField compressedKlass;
77
78 // Accessors for declared fields
79 public Mark getMark() { return new Mark(getHandle()); }
80 public Klass getKlass() {
81 if (VM.getVM().isCompressedKlassPointersEnabled()) {
82 return (Klass)compressedKlass.getValue(getHandle());
83 } else {
84 return (Klass)klass.getValue(getHandle());
85 }
86 }
87
88 public boolean isA(Klass k) {
89 return getKlass().isSubtypeOf(k);
90 }
91
92 // Returns the byte size of this object
93 public long getObjectSize() {
94 Klass k = getKlass();
95 // All other types should be overriding getObjectSize directly
96 return ((InstanceKlass)k).getObjectSize(this);
97 }
98
99 // Type test operations
100 public boolean isInstance() { return false; }
101 public boolean isInstanceRef() { return false; }
132 return (int) mark.hash();
133 } else {
134 return slowIdentityHash();
135 }
136 }
137
138 public long slowIdentityHash() {
139 return VM.getVM().getObjectSynchronizer().identityHashValueFor(this);
140 }
141
142 public void iterate(OopVisitor visitor, boolean doVMFields) {
143 visitor.setObj(this);
144 visitor.prologue();
145 iterateFields(visitor, doVMFields);
146 visitor.epilogue();
147 }
148
149 void iterateFields(OopVisitor visitor, boolean doVMFields) {
150 if (doVMFields) {
151 visitor.doCInt(mark, true);
152 if (VM.getVM().isCompressedKlassPointersEnabled()) {
153 visitor.doMetadata(compressedKlass, true);
154 } else {
155 visitor.doMetadata(klass, true);
156 }
157 }
158 }
159
160 public void print() { printOn(System.out); }
161 public void printValue() { printValueOn(System.out); }
162 public void printRaw() { printRawOn(System.out); }
163
164 public static void printOopValueOn(Oop obj, PrintStream tty) {
165 if (obj == null) {
166 tty.print("null");
167 } else {
168 obj.printValueOn(tty);
169 tty.print(" @ " + VM.getVM().getUniverse().heap().oopAddressDescription(obj.getHandle()));
170 }
171 }
172
173 public static void printOopAddressOn(Oop obj, PrintStream tty) {
174 if (obj == null) {
175 tty.print("null");
191 }
192 }
193
194 public void printRawOn(PrintStream tty) {
195 tty.print("Dumping raw memory for ");
196 printValueOn(tty);
197 tty.println();
198 long size = getObjectSize() * 4;
199 for (long i = 0; i < size; i += 4) {
200 long memVal = getHandle().getCIntegerAt(i, 4, true);
201 tty.println(Long.toHexString(memVal));
202 }
203 }
204
205 public boolean verify() { return true;}
206
207 public static Klass getKlassForOopHandle(OopHandle handle) {
208 if (handle == null) {
209 return null;
210 }
211 if (VM.getVM().isCompressedKlassPointersEnabled()) {
212 return (Klass)Metadata.instantiateWrapperFor(handle.getCompKlassAddressAt(compressedKlass.getOffset()));
213 } else {
214 return (Klass)Metadata.instantiateWrapperFor(handle.getAddressAt(klass.getOffset()));
215 }
216 }
217 };
|
31 import sun.jvm.hotspot.runtime.*;
32 import sun.jvm.hotspot.types.*;
33 import sun.jvm.hotspot.utilities.Observable;
34 import sun.jvm.hotspot.utilities.Observer;
35
36 // Oop represents the superclass for all types of
37 // objects in the HotSpot object heap.
38
39 public class Oop {
40 static {
41 VM.registerVMInitializedObserver(new Observer() {
42 public void update(Observable o, Object data) {
43 initialize(VM.getVM().getTypeDataBase());
44 }
45 });
46 }
47
48 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
49 Type type = db.lookupType("oopDesc");
50 mark = new CIntField(type.getCIntegerField("_mark"), 0);
51 if (VM.getVM().isCompactObjectHeadersEnabled()) {
52 Type markType = db.lookupType("markWord");
53 headerSize = markType.getSize();
54 } else {
55 headerSize = type.getSize();
56 klass = new MetadataField(type.getAddressField("_metadata._klass"), 0);
57 compressedKlass = new NarrowKlassField(type.getAddressField("_metadata._compressed_klass"), 0);
58 }
59 }
60
61 private OopHandle handle;
62 private ObjectHeap heap;
63
64 Oop(OopHandle handle, ObjectHeap heap) {
65 this.handle = handle;
66 this.heap = heap;
67 }
68
69 ObjectHeap getHeap() { return heap; }
70
71 /** Should not be used or needed by most clients outside this
72 package; is needed, however, by {@link
73 sun.jvm.hotspot.utilities.MarkBits}. */
74 public OopHandle getHandle() { return handle; }
75
76 private static long headerSize;
77 public static long getHeaderSize() { return headerSize; } // Header size in bytes.
78
79 private static CIntField mark;
80 private static MetadataField klass;
81 private static NarrowKlassField compressedKlass;
82
83 // Accessors for declared fields
84 public Mark getMark() { return new Mark(getHandle()); }
85
86 private static Klass getKlass(Mark mark) {
87 assert(VM.getVM().isCompactObjectHeadersEnabled());
88 if (mark.hasMonitor()) {
89 ObjectMonitor mon = mark.monitor();
90 mark = mon.header();
91 }
92 return mark.getKlass();
93 }
94
95 public Klass getKlass() {
96 if (VM.getVM().isCompactObjectHeadersEnabled()) {
97 assert(VM.getVM().isCompressedKlassPointersEnabled());
98 return getKlass(getMark());
99 } else if (VM.getVM().isCompressedKlassPointersEnabled()) {
100 return (Klass)compressedKlass.getValue(getHandle());
101 } else {
102 return (Klass)klass.getValue(getHandle());
103 }
104 }
105
106 public boolean isA(Klass k) {
107 return getKlass().isSubtypeOf(k);
108 }
109
110 // Returns the byte size of this object
111 public long getObjectSize() {
112 Klass k = getKlass();
113 // All other types should be overriding getObjectSize directly
114 return ((InstanceKlass)k).getObjectSize(this);
115 }
116
117 // Type test operations
118 public boolean isInstance() { return false; }
119 public boolean isInstanceRef() { return false; }
150 return (int) mark.hash();
151 } else {
152 return slowIdentityHash();
153 }
154 }
155
156 public long slowIdentityHash() {
157 return VM.getVM().getObjectSynchronizer().identityHashValueFor(this);
158 }
159
160 public void iterate(OopVisitor visitor, boolean doVMFields) {
161 visitor.setObj(this);
162 visitor.prologue();
163 iterateFields(visitor, doVMFields);
164 visitor.epilogue();
165 }
166
167 void iterateFields(OopVisitor visitor, boolean doVMFields) {
168 if (doVMFields) {
169 visitor.doCInt(mark, true);
170 if (!VM.getVM().isCompactObjectHeadersEnabled()) {
171 if (VM.getVM().isCompressedKlassPointersEnabled()) {
172 visitor.doMetadata(compressedKlass, true);
173 } else {
174 visitor.doMetadata(klass, true);
175 }
176 }
177 }
178 }
179
180 public void print() { printOn(System.out); }
181 public void printValue() { printValueOn(System.out); }
182 public void printRaw() { printRawOn(System.out); }
183
184 public static void printOopValueOn(Oop obj, PrintStream tty) {
185 if (obj == null) {
186 tty.print("null");
187 } else {
188 obj.printValueOn(tty);
189 tty.print(" @ " + VM.getVM().getUniverse().heap().oopAddressDescription(obj.getHandle()));
190 }
191 }
192
193 public static void printOopAddressOn(Oop obj, PrintStream tty) {
194 if (obj == null) {
195 tty.print("null");
211 }
212 }
213
214 public void printRawOn(PrintStream tty) {
215 tty.print("Dumping raw memory for ");
216 printValueOn(tty);
217 tty.println();
218 long size = getObjectSize() * 4;
219 for (long i = 0; i < size; i += 4) {
220 long memVal = getHandle().getCIntegerAt(i, 4, true);
221 tty.println(Long.toHexString(memVal));
222 }
223 }
224
225 public boolean verify() { return true;}
226
227 public static Klass getKlassForOopHandle(OopHandle handle) {
228 if (handle == null) {
229 return null;
230 }
231 if (VM.getVM().isCompactObjectHeadersEnabled()) {
232 Mark mark = new Mark(handle);
233 return getKlass(mark);
234 } else if (VM.getVM().isCompressedKlassPointersEnabled()) {
235 return (Klass)Metadata.instantiateWrapperFor(handle.getCompKlassAddressAt(compressedKlass.getOffset()));
236 } else {
237 return (Klass)Metadata.instantiateWrapperFor(handle.getAddressAt(klass.getOffset()));
238 }
239 }
240 };
|