Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/oops/Oop.java @ 3945:8ed53447f690
Merge
author | iveresov |
---|---|
date | Thu, 15 Sep 2011 12:44:09 -0700 |
parents | 63997f575155 |
children | da91efe96a93 |
rev | line source |
---|---|
0 | 1 /* |
2411
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2042
diff
changeset
|
2 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
196
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
196
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
196
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.oops; | |
26 | |
27 import java.io.*; | |
28 import java.util.*; | |
29 import sun.jvm.hotspot.utilities.*; | |
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); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
50 klass = new OopField(type.getOopField("_metadata._klass"), 0); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
51 compressedKlass = new NarrowOopField(type.getOopField("_metadata._compressed_klass"), 0); |
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; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
71 public static long getHeaderSize() { return headerSize; } // Header size in bytes. |
0 | 72 |
73 private static CIntField mark; | |
74 private static OopField klass; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
75 private static NarrowOopField compressedKlass; |
0 | 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()); } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
91 public Klass getKlass() { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
92 if (VM.getVM().isCompressedOopsEnabled()) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
93 return (Klass) compressedKlass.getValue(this); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
94 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
95 return (Klass) klass.getValue(this); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
96 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
97 } |
0 | 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(); | |
2411
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2042
diff
changeset
|
106 // All other types should be overriding getObjectSize directly |
63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
2042
diff
changeset
|
107 return ((InstanceKlass)k).getObjectSize(this); |
0 | 108 } |
109 | |
110 // Type test operations | |
111 public boolean isInstance() { return false; } | |
112 public boolean isInstanceRef() { return false; } | |
113 public boolean isArray() { return false; } | |
114 public boolean isObjArray() { return false; } | |
115 public boolean isTypeArray() { return false; } | |
116 public boolean isSymbol() { return false; } | |
117 public boolean isKlass() { return false; } | |
118 public boolean isThread() { return false; } | |
119 public boolean isMethod() { return false; } | |
120 public boolean isMethodData() { return false; } | |
121 public boolean isConstantPool() { return false; } | |
122 public boolean isConstantPoolCache() { return false; } | |
123 public boolean isCompiledICHolder() { return false; } | |
124 | |
125 // Align the object size. | |
126 public static long alignObjectSize(long size) { | |
1571
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
196
diff
changeset
|
127 return VM.getVM().alignUp(size, VM.getVM().getMinObjAlignmentInBytes()); |
0 | 128 } |
129 | |
130 // All vm's align longs, so pad out certain offsets. | |
131 public static long alignObjectOffset(long offset) { | |
132 return VM.getVM().alignUp(offset, VM.getVM().getBytesPerLong()); | |
133 } | |
134 | |
135 public boolean equals(Object obj) { | |
136 if (obj != null && (obj instanceof Oop)) { | |
137 return getHandle().equals(((Oop) obj).getHandle()); | |
138 } | |
139 return false; | |
140 } | |
141 | |
142 public int hashCode() { return getHandle().hashCode(); } | |
143 | |
144 /** Identity hash in the target VM */ | |
145 public long identityHash() { | |
146 Mark mark = getMark(); | |
147 if (mark.isUnlocked() && (!mark.hasNoHash())) { | |
148 return (int) mark.hash(); | |
149 } else if (mark.isMarked()) { | |
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); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
170 if (VM.getVM().isCompressedOopsEnabled()) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
171 visitor.doOop(compressedKlass, true); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
172 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
173 visitor.doOop(klass, true); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
174 } |
0 | 175 } |
176 } | |
177 | |
178 public void print() { printOn(System.out); } | |
179 public void printValue() { printValueOn(System.out); } | |
180 public void printRaw() { printRawOn(System.out); } | |
181 | |
182 public static void printOopValueOn(Oop obj, PrintStream tty) { | |
183 if (obj == null) { | |
184 tty.print("null"); | |
185 } else { | |
186 obj.printValueOn(tty); | |
187 tty.print(" @ " + obj.getHandle()); | |
188 } | |
189 } | |
190 | |
191 public static void printOopAddressOn(Oop obj, PrintStream tty) { | |
192 if (obj == null) { | |
193 tty.print("null"); | |
194 } else { | |
195 tty.print(obj.getHandle().toString()); | |
196 } | |
197 } | |
198 | |
199 public void printOn(PrintStream tty) { | |
200 OopPrinter printer = new OopPrinter(tty); | |
201 iterate(printer, true); | |
202 } | |
203 | |
204 public void printValueOn(PrintStream tty) { | |
205 try { | |
206 tty.print("Oop for " + getKlass().getName().asString()); | |
207 } catch (java.lang.NullPointerException e) { | |
208 tty.print("Oop"); | |
209 } | |
210 } | |
211 | |
212 public void printRawOn(PrintStream tty) { | |
213 tty.print("Dumping raw memory for "); | |
214 printValueOn(tty); | |
215 tty.println(); | |
216 long size = getObjectSize() * 4; | |
217 for (long i = 0; i < size; i += 4) { | |
218 long memVal = getHandle().getCIntegerAt(i, 4, true); | |
219 tty.println(Long.toHexString(memVal)); | |
220 } | |
221 } | |
222 | |
223 public boolean verify() { return true;} | |
224 | |
225 // Package-private routine to speed up ObjectHeap.newOop | |
226 static OopHandle getKlassForOopHandle(OopHandle handle) { | |
227 if (handle == null) { | |
228 return null; | |
229 } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
230 if (VM.getVM().isCompressedOopsEnabled()) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
231 return handle.getCompOopHandleAt(compressedKlass.getOffset()); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
232 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
233 return handle.getOopHandleAt(klass.getOffset()); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
234 } |
0 | 235 } |
236 }; |