annotate agent/src/share/classes/sun/jvm/hotspot/oops/Oop.java @ 6725:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents 63997f575155
children 8e47bac5643a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
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
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 *
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
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
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // Oop represents the superclass for all types of
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // objects in the HotSpot object heap.
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 public class Oop {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 initialize(VM.getVM().getTypeDataBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
42 }
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 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 Type type = db.lookupType("oopDesc");
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
54 headerSize = type.getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 private OopHandle handle;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 private ObjectHeap heap;
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 Oop(OopHandle handle, ObjectHeap heap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 this.handle = handle;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 this.heap = heap;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 ObjectHeap getHeap() { return heap; }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 /** Should not be used or needed by most clients outside this
a61af66fc99e Initial load
duke
parents:
diff changeset
68 package; is needed, however, by {@link
a61af66fc99e Initial load
duke
parents:
diff changeset
69 sun.jvm.hotspot.utilities.MarkBits}. */
a61af66fc99e Initial load
duke
parents:
diff changeset
70 public OopHandle getHandle() { return handle; }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // Accessors for declared fields
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 public boolean isA(Klass k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 return getKlass().isSubtypeOf(k);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // Returns the byte size of this object
a61af66fc99e Initial load
duke
parents:
diff changeset
94 public long getObjectSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // Type test operations
a61af66fc99e Initial load
duke
parents:
diff changeset
101 public boolean isInstance() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
102 public boolean isInstanceRef() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
103 public boolean isArray() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
104 public boolean isObjArray() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
105 public boolean isTypeArray() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 public boolean isThread() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // Align the object size.
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // All vm's align longs, so pad out certain offsets.
a61af66fc99e Initial load
duke
parents:
diff changeset
114 public static long alignObjectOffset(long offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 return VM.getVM().alignUp(offset, VM.getVM().getBytesPerLong());
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 public boolean equals(Object obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 if (obj != null && (obj instanceof Oop)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 return getHandle().equals(((Oop) obj).getHandle());
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 public int hashCode() { return getHandle().hashCode(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 /** Identity hash in the target VM */
a61af66fc99e Initial load
duke
parents:
diff changeset
128 public long identityHash() {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 Mark mark = getMark();
a61af66fc99e Initial load
duke
parents:
diff changeset
130 if (mark.isUnlocked() && (!mark.hasNoHash())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 return (int) mark.hash();
a61af66fc99e Initial load
duke
parents:
diff changeset
132 } else if (mark.isMarked()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 return (int) mark.hash();
a61af66fc99e Initial load
duke
parents:
diff changeset
134 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 return slowIdentityHash();
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 public long slowIdentityHash() {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 return VM.getVM().getObjectSynchronizer().identityHashValueFor(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 public void iterate(OopVisitor visitor, boolean doVMFields) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 visitor.setObj(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 visitor.prologue();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 iterateFields(visitor, doVMFields);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 visitor.epilogue();
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 void iterateFields(OopVisitor visitor, boolean doVMFields) {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 if (doVMFields) {
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 public void print() { printOn(System.out); }
a61af66fc99e Initial load
duke
parents:
diff changeset
162 public void printValue() { printValueOn(System.out); }
a61af66fc99e Initial load
duke
parents:
diff changeset
163 public void printRaw() { printRawOn(System.out); }
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 public static void printOopValueOn(Oop obj, PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 if (obj == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 tty.print("null");
a61af66fc99e Initial load
duke
parents:
diff changeset
168 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 obj.printValueOn(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
170 tty.print(" @ " + obj.getHandle());
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 public static void printOopAddressOn(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 tty.print(obj.getHandle().toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 public void printOn(PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 OopPrinter printer = new OopPrinter(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
184 iterate(printer, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 public void printValueOn(PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 tty.print("Oop for " + getKlass().getName().asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
190 } catch (java.lang.NullPointerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 tty.print("Oop");
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195 public void printRawOn(PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 tty.print("Dumping raw memory for ");
a61af66fc99e Initial load
duke
parents:
diff changeset
197 printValueOn(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 tty.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
199 long size = getObjectSize() * 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
200 for (long i = 0; i < size; i += 4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 long memVal = getHandle().getCIntegerAt(i, 4, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
202 tty.println(Long.toHexString(memVal));
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206 public boolean verify() { return true;}
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
210 if (handle == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219 };