Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/oops/Oop.java @ 6842:b9a9ed0f8eeb
7197424: update copyright year to match last edit in jdk8 hotspot repository
Summary: Update copyright year to 2012 for relevant files
Reviewed-by: dholmes, coleenp
author | mikael |
---|---|
date | Tue, 09 Oct 2012 10:09:34 -0700 |
parents | da91efe96a93 |
children | 8e47bac5643a |
rev | line source |
---|---|
0 | 1 /* |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
2 * Copyright (c) 2000, 2012, 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); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
50 if (VM.getVM().isCompressedHeadersEnabled()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
51 // compressedKlass = new CIntField(type.getCIntegerField("_metadata._compressed_klass"), 0); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
52 throw new InternalError("unimplemented"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
53 } |
0 | 54 headerSize = type.getSize(); |
55 } | |
56 | |
57 private OopHandle handle; | |
58 private ObjectHeap heap; | |
59 | |
60 Oop(OopHandle handle, ObjectHeap heap) { | |
61 this.handle = handle; | |
62 this.heap = heap; | |
63 } | |
64 | |
65 ObjectHeap getHeap() { return heap; } | |
66 | |
67 /** Should not be used or needed by most clients outside this | |
68 package; is needed, however, by {@link | |
69 sun.jvm.hotspot.utilities.MarkBits}. */ | |
70 public OopHandle getHandle() { return handle; } | |
71 | |
72 private static long headerSize; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
73 public static long getHeaderSize() { return headerSize; } // Header size in bytes. |
0 | 74 |
75 private static CIntField mark; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
76 private static MetadataField klass; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
77 private static CIntField compressedKlass; |
0 | 78 |
79 // Accessors for declared fields | |
80 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
|
81 public Klass getKlass() { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
82 if (VM.getVM().isCompressedHeadersEnabled()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
83 throw new InternalError("unimplemented"); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
84 } else { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
85 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
|
86 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
87 } |
0 | 88 |
89 public boolean isA(Klass k) { | |
90 return getKlass().isSubtypeOf(k); | |
91 } | |
92 | |
93 // Returns the byte size of this object | |
94 public long getObjectSize() { | |
95 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
|
96 // 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
|
97 return ((InstanceKlass)k).getObjectSize(this); |
0 | 98 } |
99 | |
100 // Type test operations | |
101 public boolean isInstance() { return false; } | |
102 public boolean isInstanceRef() { return false; } | |
103 public boolean isArray() { return false; } | |
104 public boolean isObjArray() { return false; } | |
105 public boolean isTypeArray() { return false; } | |
106 public boolean isThread() { return false; } | |
107 | |
108 // Align the object size. | |
109 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
|
110 return VM.getVM().alignUp(size, VM.getVM().getMinObjAlignmentInBytes()); |
0 | 111 } |
112 | |
113 // All vm's align longs, so pad out certain offsets. | |
114 public static long alignObjectOffset(long offset) { | |
115 return VM.getVM().alignUp(offset, VM.getVM().getBytesPerLong()); | |
116 } | |
117 | |
118 public boolean equals(Object obj) { | |
119 if (obj != null && (obj instanceof Oop)) { | |
120 return getHandle().equals(((Oop) obj).getHandle()); | |
121 } | |
122 return false; | |
123 } | |
124 | |
125 public int hashCode() { return getHandle().hashCode(); } | |
126 | |
127 /** Identity hash in the target VM */ | |
128 public long identityHash() { | |
129 Mark mark = getMark(); | |
130 if (mark.isUnlocked() && (!mark.hasNoHash())) { | |
131 return (int) mark.hash(); | |
132 } else if (mark.isMarked()) { | |
133 return (int) mark.hash(); | |
134 } else { | |
135 return slowIdentityHash(); | |
136 } | |
137 } | |
138 | |
139 public long slowIdentityHash() { | |
140 return VM.getVM().getObjectSynchronizer().identityHashValueFor(this); | |
141 } | |
142 | |
143 public void iterate(OopVisitor visitor, boolean doVMFields) { | |
144 visitor.setObj(this); | |
145 visitor.prologue(); | |
146 iterateFields(visitor, doVMFields); | |
147 visitor.epilogue(); | |
148 } | |
149 | |
150 void iterateFields(OopVisitor visitor, boolean doVMFields) { | |
151 if (doVMFields) { | |
152 visitor.doCInt(mark, true); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
153 if (VM.getVM().isCompressedHeadersEnabled()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
154 throw new InternalError("unimplemented"); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
155 } else { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
156 visitor.doMetadata(klass, true); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
157 } |
0 | 158 } |
159 } | |
160 | |
161 public void print() { printOn(System.out); } | |
162 public void printValue() { printValueOn(System.out); } | |
163 public void printRaw() { printRawOn(System.out); } | |
164 | |
165 public static void printOopValueOn(Oop obj, PrintStream tty) { | |
166 if (obj == null) { | |
167 tty.print("null"); | |
168 } else { | |
169 obj.printValueOn(tty); | |
170 tty.print(" @ " + obj.getHandle()); | |
171 } | |
172 } | |
173 | |
174 public static void printOopAddressOn(Oop obj, PrintStream tty) { | |
175 if (obj == null) { | |
176 tty.print("null"); | |
177 } else { | |
178 tty.print(obj.getHandle().toString()); | |
179 } | |
180 } | |
181 | |
182 public void printOn(PrintStream tty) { | |
183 OopPrinter printer = new OopPrinter(tty); | |
184 iterate(printer, true); | |
185 } | |
186 | |
187 public void printValueOn(PrintStream tty) { | |
188 try { | |
189 tty.print("Oop for " + getKlass().getName().asString()); | |
190 } catch (java.lang.NullPointerException e) { | |
191 tty.print("Oop"); | |
192 } | |
193 } | |
194 | |
195 public void printRawOn(PrintStream tty) { | |
196 tty.print("Dumping raw memory for "); | |
197 printValueOn(tty); | |
198 tty.println(); | |
199 long size = getObjectSize() * 4; | |
200 for (long i = 0; i < size; i += 4) { | |
201 long memVal = getHandle().getCIntegerAt(i, 4, true); | |
202 tty.println(Long.toHexString(memVal)); | |
203 } | |
204 } | |
205 | |
206 public boolean verify() { return true;} | |
207 | |
208 // 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
|
209 static Klass getKlassForOopHandle(OopHandle handle) { |
0 | 210 if (handle == null) { |
211 return null; | |
212 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
213 if (VM.getVM().isCompressedHeadersEnabled()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
214 throw new InternalError("Unimplemented"); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
215 } else { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2411
diff
changeset
|
216 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
|
217 } |
0 | 218 } |
219 }; |