author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 50525 | 767cdb97f103 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
48113
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
670
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
670
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
670
diff
changeset
|
21 |
* questions. |
1 | 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); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8878
diff
changeset
|
49 |
klass = new MetadataField(type.getAddressField("_metadata._klass"), 0); |
13969
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13728
diff
changeset
|
50 |
compressedKlass = new NarrowKlassField(type.getAddressField("_metadata._compressed_klass"), 0); |
1 | 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; |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
70 |
public static long getHeaderSize() { return headerSize; } // Header size in bytes. |
1 | 71 |
|
72 |
private static CIntField mark; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8878
diff
changeset
|
73 |
private static MetadataField klass; |
13969
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13728
diff
changeset
|
74 |
private static NarrowKlassField compressedKlass; |
1 | 75 |
|
76 |
// Accessors for declared fields |
|
77 |
public Mark getMark() { return new Mark(getHandle()); } |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
78 |
public Klass getKlass() { |
13969
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13728
diff
changeset
|
79 |
if (VM.getVM().isCompressedKlassPointersEnabled()) { |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13728
diff
changeset
|
80 |
return (Klass)compressedKlass.getValue(getHandle()); |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
81 |
} else { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8878
diff
changeset
|
82 |
return (Klass)klass.getValue(getHandle()); |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
83 |
} |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
84 |
} |
1 | 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(); |
|
8878
a6283814032c
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
7662
diff
changeset
|
93 |
// All other types should be overriding getObjectSize directly |
a6283814032c
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents:
7662
diff
changeset
|
94 |
return ((InstanceKlass)k).getObjectSize(this); |
1 | 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) { |
|
5694
1e0532a6abff
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
670
diff
changeset
|
107 |
return VM.getVM().alignUp(size, VM.getVM().getMinObjAlignmentInBytes()); |
1 | 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); |
|
13969
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13728
diff
changeset
|
150 |
if (VM.getVM().isCompressedKlassPointersEnabled()) { |
16365
011271eb4373
8008796: SA: Oop.iterateFields() should support CompressedKlassPointers again
kmo
parents:
13969
diff
changeset
|
151 |
visitor.doMetadata(compressedKlass, true); |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
152 |
} else { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8878
diff
changeset
|
153 |
visitor.doMetadata(klass, true); |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
154 |
} |
1 | 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); |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
48113
diff
changeset
|
167 |
tty.print(" @ " + VM.getVM().getUniverse().heap().oopAddressDescription(obj.getHandle())); |
1 | 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 |
||
48113
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
47216
diff
changeset
|
205 |
public static Klass getKlassForOopHandle(OopHandle handle) { |
1 | 206 |
if (handle == null) { |
207 |
return null; |
|
208 |
} |
|
13969
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13728
diff
changeset
|
209 |
if (VM.getVM().isCompressedKlassPointersEnabled()) { |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13728
diff
changeset
|
210 |
return (Klass)Metadata.instantiateWrapperFor(handle.getCompKlassAddressAt(compressedKlass.getOffset())); |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
211 |
} else { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8878
diff
changeset
|
212 |
return (Klass)Metadata.instantiateWrapperFor(handle.getAddressAt(klass.getOffset())); |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
213 |
} |
1 | 214 |
} |
215 |
}; |