Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/oops/Oop.java @ 13705:ac5b0f31f7a2
Truffle API-change: FrameDescriptors are now stored in the RootNode in a final field instead of the CallTarget.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 17 Jan 2014 17:06:08 +0100 |
parents | 8552f0992748 |
children |
rev | line source |
---|---|
0 | 1 /* |
8764
8552f0992748
8008796: SA: Oop.iterateFields() should support CompressedKlassPointers again
kmo
parents:
6848
diff
changeset
|
2 * Copyright (c) 2000, 2013, 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 | |
34 // Oop represents the superclass for all types of | |
35 // objects in the HotSpot object heap. | |
36 | |
37 public class Oop { | |
38 static { | |
39 VM.registerVMInitializedObserver(new Observer() { | |
40 public void update(Observable o, Object data) { | |
41 initialize(VM.getVM().getTypeDataBase()); | |
42 } | |
43 }); | |
44 } | |
45 | |
46 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { | |
47 Type type = db.lookupType("oopDesc"); | |
48 mark = new CIntField(type.getCIntegerField("_mark"), 0); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
49 klass = new MetadataField(type.getAddressField("_metadata._klass"), 0); |
6848
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6725
diff
changeset
|
50 compressedKlass = new NarrowKlassField(type.getAddressField("_metadata._compressed_klass"), 0); |
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; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
70 public static long getHeaderSize() { return headerSize; } // Header size in bytes. |
0 | 71 |
72 private static CIntField mark; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
73 private static MetadataField klass; |
6848
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6725
diff
changeset
|
74 private static NarrowKlassField compressedKlass; |
0 | 75 |
76 // Accessors for declared fields | |
77 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
|
78 public Klass getKlass() { |
6848
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6725
diff
changeset
|
79 if (VM.getVM().isCompressedKlassPointersEnabled()) { |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6725
diff
changeset
|
80 return (Klass)compressedKlass.getValue(getHandle()); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
81 } else { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
82 return (Klass)klass.getValue(getHandle()); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
83 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
84 } |
0 | 85 |
86 public boolean isA(Klass k) { | |
87 return getKlass().isSubtypeOf(k); | |
88 } | |
89 | |
90 // Returns the byte size of this object | |
91 public long getObjectSize() { | |
92 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
|
93 // 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
|
94 return ((InstanceKlass)k).getObjectSize(this); |
0 | 95 } |
96 | |
97 // Type test operations | |
98 public boolean isInstance() { return false; } | |
99 public boolean isInstanceRef() { return false; } | |
100 public boolean isArray() { return false; } | |
101 public boolean isObjArray() { return false; } | |
102 public boolean isTypeArray() { return false; } | |
103 public boolean isThread() { return false; } | |
104 | |
105 // Align the object size. | |
106 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
|
107 return VM.getVM().alignUp(size, VM.getVM().getMinObjAlignmentInBytes()); |
0 | 108 } |
109 | |
110 // All vm's align longs, so pad out certain offsets. | |
111 public static long alignObjectOffset(long offset) { | |
112 return VM.getVM().alignUp(offset, VM.getVM().getBytesPerLong()); | |
113 } | |
114 | |
115 public boolean equals(Object obj) { | |
116 if (obj != null && (obj instanceof Oop)) { | |
117 return getHandle().equals(((Oop) obj).getHandle()); | |
118 } | |
119 return false; | |
120 } | |
121 | |
122 public int hashCode() { return getHandle().hashCode(); } | |
123 | |
124 /** Identity hash in the target VM */ | |
125 public long identityHash() { | |
126 Mark mark = getMark(); | |
127 if (mark.isUnlocked() && (!mark.hasNoHash())) { | |
128 return (int) mark.hash(); | |
129 } else if (mark.isMarked()) { | |
130 return (int) mark.hash(); | |
131 } else { | |
132 return slowIdentityHash(); | |
133 } | |
134 } | |
135 | |
136 public long slowIdentityHash() { | |
137 return VM.getVM().getObjectSynchronizer().identityHashValueFor(this); | |
138 } | |
139 | |
140 public void iterate(OopVisitor visitor, boolean doVMFields) { | |
141 visitor.setObj(this); | |
142 visitor.prologue(); | |
143 iterateFields(visitor, doVMFields); | |
144 visitor.epilogue(); | |
145 } | |
146 | |
147 void iterateFields(OopVisitor visitor, boolean doVMFields) { | |
148 if (doVMFields) { | |
149 visitor.doCInt(mark, true); | |
6848
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6725
diff
changeset
|
150 if (VM.getVM().isCompressedKlassPointersEnabled()) { |
8764
8552f0992748
8008796: SA: Oop.iterateFields() should support CompressedKlassPointers again
kmo
parents:
6848
diff
changeset
|
151 visitor.doMetadata(compressedKlass, true); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
152 } else { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
153 visitor.doMetadata(klass, true); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
154 } |
0 | 155 } |
156 } | |
157 | |
158 public void print() { printOn(System.out); } | |
159 public void printValue() { printValueOn(System.out); } | |
160 public void printRaw() { printRawOn(System.out); } | |
161 | |
162 public static void printOopValueOn(Oop obj, PrintStream tty) { | |
163 if (obj == null) { | |
164 tty.print("null"); | |
165 } else { | |
166 obj.printValueOn(tty); | |
167 tty.print(" @ " + obj.getHandle()); | |
168 } | |
169 } | |
170 | |
171 public static void printOopAddressOn(Oop obj, PrintStream tty) { | |
172 if (obj == null) { | |
173 tty.print("null"); | |
174 } else { | |
175 tty.print(obj.getHandle().toString()); | |
176 } | |
177 } | |
178 | |
179 public void printOn(PrintStream tty) { | |
180 OopPrinter printer = new OopPrinter(tty); | |
181 iterate(printer, true); | |
182 } | |
183 | |
184 public void printValueOn(PrintStream tty) { | |
185 try { | |
186 tty.print("Oop for " + getKlass().getName().asString()); | |
187 } catch (java.lang.NullPointerException e) { | |
188 tty.print("Oop"); | |
189 } | |
190 } | |
191 | |
192 public void printRawOn(PrintStream tty) { | |
193 tty.print("Dumping raw memory for "); | |
194 printValueOn(tty); | |
195 tty.println(); | |
196 long size = getObjectSize() * 4; | |
197 for (long i = 0; i < size; i += 4) { | |
198 long memVal = getHandle().getCIntegerAt(i, 4, true); | |
199 tty.println(Long.toHexString(memVal)); | |
200 } | |
201 } | |
202 | |
203 public boolean verify() { return true;} | |
204 | |
205 // Package-private routine to speed up ObjectHeap.newOop | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
206 static Klass getKlassForOopHandle(OopHandle handle) { |
0 | 207 if (handle == null) { |
208 return null; | |
209 } | |
6848
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6725
diff
changeset
|
210 if (VM.getVM().isCompressedKlassPointersEnabled()) { |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6725
diff
changeset
|
211 return (Klass)Metadata.instantiateWrapperFor(handle.getCompKlassAddressAt(compressedKlass.getOffset())); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
212 } else { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
213 return (Klass)Metadata.instantiateWrapperFor(handle.getAddressAt(klass.getOffset())); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
214 } |
0 | 215 } |
216 }; |