annotate agent/src/share/classes/sun/jvm/hotspot/oops/Oop.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children ba764ed4b6f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.oops;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.memory.CompactingPermGenGen;
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // Oop represents the superclass for all types of
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // objects in the HotSpot object heap.
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 public class Oop {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 initialize(VM.getVM().getTypeDataBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
43 }
a61af66fc99e Initial load
duke
parents:
diff changeset
44 });
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 Type type = db.lookupType("oopDesc");
a61af66fc99e Initial load
duke
parents:
diff changeset
49 mark = new CIntField(type.getCIntegerField("_mark"), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
50 klass = new OopField(type.getOopField("_klass"), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
51 headerSize = type.getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
52 }
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 private OopHandle handle;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 private ObjectHeap heap;
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 Oop(OopHandle handle, ObjectHeap heap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 this.handle = handle;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 this.heap = heap;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 ObjectHeap getHeap() { return heap; }
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 /** Should not be used or needed by most clients outside this
a61af66fc99e Initial load
duke
parents:
diff changeset
65 package; is needed, however, by {@link
a61af66fc99e Initial load
duke
parents:
diff changeset
66 sun.jvm.hotspot.utilities.MarkBits}. */
a61af66fc99e Initial load
duke
parents:
diff changeset
67 public OopHandle getHandle() { return handle; }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 private static long headerSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 public static long getHeaderSize() { return headerSize; }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 private static CIntField mark;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 private static OopField klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 public boolean isShared() {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 return CompactingPermGenGen.isShared(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 public boolean isSharedReadOnly() {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 return CompactingPermGenGen.isSharedReadOnly(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 public boolean isSharedReadWrite() {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 return CompactingPermGenGen.isSharedReadWrite(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // Accessors for declared fields
a61af66fc99e Initial load
duke
parents:
diff changeset
88 public Mark getMark() { return new Mark(getHandle()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 public Klass getKlass() { return (Klass) klass.getValue(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 public boolean isA(Klass k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return getKlass().isSubtypeOf(k);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // Returns the byte size of this object
a61af66fc99e Initial load
duke
parents:
diff changeset
96 public long getObjectSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 Klass k = getKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
98 if (k instanceof InstanceKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 return ((InstanceKlass)k).getSizeHelper()
a61af66fc99e Initial load
duke
parents:
diff changeset
100 * VM.getVM().getAddressSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // If it is not an instance, this method should be replaced.
a61af66fc99e Initial load
duke
parents:
diff changeset
103 return getHeaderSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // Type test operations
a61af66fc99e Initial load
duke
parents:
diff changeset
107 public boolean isInstance() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 public boolean isInstanceRef() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 public boolean isArray() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 public boolean isObjArray() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 public boolean isTypeArray() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 public boolean isSymbol() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 public boolean isKlass() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
114 public boolean isThread() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 public boolean isMethod() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 public boolean isMethodData() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 public boolean isConstantPool() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 public boolean isConstantPoolCache() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 public boolean isCompiledICHolder() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // Align the object size.
a61af66fc99e Initial load
duke
parents:
diff changeset
122 public static long alignObjectSize(long size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 return VM.getVM().alignUp(size, VM.getVM().getMinObjAlignmentInBytes());
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // All vm's align longs, so pad out certain offsets.
a61af66fc99e Initial load
duke
parents:
diff changeset
127 public static long alignObjectOffset(long offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 return VM.getVM().alignUp(offset, VM.getVM().getBytesPerLong());
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 public boolean equals(Object obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 if (obj != null && (obj instanceof Oop)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 return getHandle().equals(((Oop) obj).getHandle());
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 public int hashCode() { return getHandle().hashCode(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 /** Identity hash in the target VM */
a61af66fc99e Initial load
duke
parents:
diff changeset
141 public long identityHash() {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 Mark mark = getMark();
a61af66fc99e Initial load
duke
parents:
diff changeset
143 if (mark.isUnlocked() && (!mark.hasNoHash())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 return (int) mark.hash();
a61af66fc99e Initial load
duke
parents:
diff changeset
145 } else if (mark.isMarked()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 return (int) mark.hash();
a61af66fc99e Initial load
duke
parents:
diff changeset
147 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 return slowIdentityHash();
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 public long slowIdentityHash() {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 return VM.getVM().getObjectSynchronizer().identityHashValueFor(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 public void iterate(OopVisitor visitor, boolean doVMFields) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 visitor.setObj(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
158 visitor.prologue();
a61af66fc99e Initial load
duke
parents:
diff changeset
159 iterateFields(visitor, doVMFields);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 visitor.epilogue();
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 void iterateFields(OopVisitor visitor, boolean doVMFields) {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 if (doVMFields) {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 visitor.doCInt(mark, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
166 visitor.doOop(klass, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 public void print() { printOn(System.out); }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 public void printValue() { printValueOn(System.out); }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 public void printRaw() { printRawOn(System.out); }
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 public static void printOopValueOn(Oop obj, PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 if (obj == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 tty.print("null");
a61af66fc99e Initial load
duke
parents:
diff changeset
177 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 obj.printValueOn(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
179 tty.print(" @ " + obj.getHandle());
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 public static void printOopAddressOn(Oop obj, PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 if (obj == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 tty.print("null");
a61af66fc99e Initial load
duke
parents:
diff changeset
186 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 tty.print(obj.getHandle().toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 public void printOn(PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 OopPrinter printer = new OopPrinter(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
193 iterate(printer, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 public void printValueOn(PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 tty.print("Oop for " + getKlass().getName().asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
199 } catch (java.lang.NullPointerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 tty.print("Oop");
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 public void printRawOn(PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 tty.print("Dumping raw memory for ");
a61af66fc99e Initial load
duke
parents:
diff changeset
206 printValueOn(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 tty.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
208 long size = getObjectSize() * 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
209 for (long i = 0; i < size; i += 4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 long memVal = getHandle().getCIntegerAt(i, 4, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
211 tty.println(Long.toHexString(memVal));
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 public boolean verify() { return true;}
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // Package-private routine to speed up ObjectHeap.newOop
a61af66fc99e Initial load
duke
parents:
diff changeset
218 static OopHandle getKlassForOopHandle(OopHandle handle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 if (handle == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222 return handle.getOopHandleAt(klass.getOffset());
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 };