Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/PointerLocation.java
41161 views
1
/*
2
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
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
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
package sun.jvm.hotspot.utilities;
26
27
import java.io.*;
28
import sun.jvm.hotspot.code.*;
29
import sun.jvm.hotspot.debugger.*;
30
import sun.jvm.hotspot.debugger.cdbg.*;
31
import sun.jvm.hotspot.gc.shared.*;
32
import sun.jvm.hotspot.interpreter.*;
33
import sun.jvm.hotspot.memory.*;
34
import sun.jvm.hotspot.oops.Metadata;
35
import sun.jvm.hotspot.runtime.*;
36
import sun.jvm.hotspot.types.Type;
37
38
/** This class attempts to describe possible locations of pointers in
39
the VM. */
40
41
public class PointerLocation {
42
//////////////////////////////////////////////////////////////////
43
// //
44
// These are package private to simplify the implementation and //
45
// interaction with PointerFinder //
46
// //
47
//////////////////////////////////////////////////////////////////
48
49
Address addr;
50
51
Metadata metadata;
52
Type ctype;
53
JavaThread stackThread;
54
55
LoadObject loadObject;
56
ClosestSymbol nativeSymbol;
57
58
CollectedHeap heap;
59
Generation gen;
60
61
// If UseTLAB was enabled and the pointer was found in a
62
// currently-active TLAB, these will be set
63
boolean inTLAB;
64
JavaThread tlabThread;
65
ThreadLocalAllocBuffer tlab;
66
67
// Generated code locations
68
boolean inInterpreter;
69
boolean inCodeCache;
70
71
// FIXME: add other locations like VTableStubs, StubRoutines, maybe
72
// even "on thread x's stack"
73
74
InterpreterCodelet interpreterCodelet;
75
CodeBlob blob;
76
// FIXME: add more detail about CodeBlob
77
boolean inBlobCode;
78
boolean inBlobData;
79
boolean inBlobOops;
80
boolean inBlobUnknownLocation;
81
82
boolean inStrongGlobalJNIHandles;
83
boolean inWeakGlobalJNIHandles;
84
85
boolean inLocalJNIHandleBlock;
86
JNIHandleBlock handleBlock;
87
sun.jvm.hotspot.runtime.Thread handleThread;
88
89
public PointerLocation(Address addr) {
90
this.addr = addr;
91
}
92
93
public boolean isMetadata() {
94
return metadata != null;
95
}
96
97
public boolean isCtype() {
98
return ctype != null;
99
}
100
101
public boolean isInJavaStack() {
102
return stackThread != null;
103
}
104
105
public boolean isNativeSymbol() {
106
return loadObject != null;
107
}
108
109
public boolean isInHeap() {
110
return (heap != null || (gen != null));
111
}
112
113
public boolean isInNewGen() {
114
return ((gen != null) && (gen == ((GenCollectedHeap)heap).getGen(0)));
115
}
116
117
public boolean isInOldGen() {
118
return ((gen != null) && (gen == ((GenCollectedHeap)heap).getGen(1)));
119
}
120
121
public boolean inOtherGen() {
122
return (!isInNewGen() && !isInOldGen());
123
}
124
125
/** Only valid if isInHeap() */
126
public Generation getGeneration() {
127
return gen;
128
}
129
130
/** This may be true if isInNewGen is also true */
131
public boolean isInTLAB() {
132
return inTLAB;
133
}
134
135
/** Only valid if isInTLAB() returns true */
136
public JavaThread getTLABThread() {
137
return tlabThread;
138
}
139
140
/** Only valid if isInTLAB() returns true */
141
public ThreadLocalAllocBuffer getTLAB() {
142
return tlab;
143
}
144
145
public boolean isInInterpreter() {
146
return inInterpreter;
147
}
148
149
/** For now, only valid if isInInterpreter is true */
150
public InterpreterCodelet getInterpreterCodelet() {
151
return interpreterCodelet;
152
}
153
154
public boolean isInCodeCache() {
155
return inCodeCache;
156
}
157
158
/** For now, only valid if isInCodeCache is true */
159
public CodeBlob getCodeBlob() {
160
return blob;
161
}
162
163
public boolean isInBlobCode() {
164
return inBlobCode;
165
}
166
167
public boolean isInBlobData() {
168
return inBlobData;
169
}
170
171
public boolean isInBlobOops() {
172
return inBlobOops;
173
}
174
175
public boolean isInBlobUnknownLocation() {
176
return inBlobUnknownLocation;
177
}
178
179
public boolean isInStrongGlobalJNIHandles() {
180
return inStrongGlobalJNIHandles;
181
}
182
183
public boolean isInWeakGlobalJNIHandles() {
184
return inWeakGlobalJNIHandles;
185
}
186
187
public boolean isInLocalJNIHandleBlock() {
188
return inLocalJNIHandleBlock;
189
}
190
191
/** Only valid if isInLocalJNIHandleBlock is true */
192
public JNIHandleBlock getJNIHandleBlock() {
193
assert isInLocalJNIHandleBlock();
194
return handleBlock;
195
}
196
197
/** Only valid if isInLocalJNIHandleBlock is true */
198
public sun.jvm.hotspot.runtime.Thread getJNIHandleThread() {
199
assert isInLocalJNIHandleBlock();
200
return handleThread;
201
}
202
203
public boolean isUnknown() {
204
return (!(isMetadata() || isCtype() || isInJavaStack() || isNativeSymbol() || isInHeap() ||
205
isInInterpreter() || isInCodeCache() || isInStrongGlobalJNIHandles() ||
206
isInWeakGlobalJNIHandles() || isInLocalJNIHandleBlock()));
207
}
208
209
public String toString() {
210
ByteArrayOutputStream bos = new ByteArrayOutputStream();
211
printOn(new PrintStream(bos));
212
return bos.toString();
213
}
214
215
public void print() {
216
printOn(System.out, true, true);
217
}
218
219
public void print(boolean printAddress, boolean verbose) {
220
printOn(System.out, printAddress, verbose);
221
}
222
223
public void printOn(PrintStream tty) {
224
printOn(tty, true, true);
225
}
226
227
public void printOn(PrintStream tty, boolean printAddress, boolean verbose) {
228
if (printAddress) {
229
tty.print("Address ");
230
if (addr == null) {
231
tty.print("0x0");
232
} else {
233
tty.print(addr.toString());
234
}
235
tty.print(": ");
236
}
237
if (isMetadata()) {
238
metadata.printValueOn(tty); // does not include "\n"
239
tty.println();
240
} else if (isCtype()) {
241
tty.println("Is of type " + ctype.getName());
242
} else if (isInJavaStack()) {
243
if (verbose) {
244
tty.format("In java stack [%s,%s,%s] for thread %s:\n ",
245
stackThread.getStackBase(), stackThread.lastSPDbg(),
246
stackThread.getStackBase().addOffsetTo(-stackThread.getStackSize()),
247
stackThread);
248
stackThread.printThreadInfoOn(tty); // includes "\n"
249
} else {
250
tty.format("In java stack for thread \"%s\" %s\n", stackThread.getThreadName(), stackThread);
251
}
252
} else if (isNativeSymbol()) {
253
CDebugger cdbg = VM.getVM().getDebugger().getCDebugger();
254
long diff;
255
if (nativeSymbol != null) {
256
String name = nativeSymbol.getName();
257
if (cdbg.canDemangle()) {
258
name = cdbg.demangle(name);
259
}
260
tty.print(name);
261
diff = nativeSymbol.getOffset();
262
} else {
263
tty.print(loadObject.getName());
264
diff = addr.minus(loadObject.getBase());
265
}
266
if (diff != 0L) {
267
tty.print(" + 0x" + Long.toHexString(diff));
268
}
269
tty.println();
270
} else if (isInHeap()) {
271
if (isInTLAB()) {
272
tty.print("In thread-local allocation buffer for thread (");
273
getTLABThread().printThreadInfoOn(tty);
274
tty.print(") ");
275
getTLAB().printOn(tty); // includes "\n"
276
} else {
277
if (isInNewGen()) {
278
tty.print("In new generation ");
279
} else if (isInOldGen()) {
280
tty.print("In old generation ");
281
} else {
282
tty.print("In unknown section of Java heap");
283
}
284
if (getGeneration() != null) {
285
getGeneration().printOn(tty); // does not include "\n"
286
}
287
tty.println();
288
}
289
} else if (isInInterpreter()) {
290
tty.print("In interpreter codelet: ");
291
interpreterCodelet.printOn(tty); // includes "\n"
292
} else if (isInCodeCache()) {
293
// TODO: print the type of CodeBlob. See "look for known code blobs" comment
294
// in PStack.java for example code.
295
CodeBlob b = getCodeBlob();
296
tty.print("In ");
297
if (isInBlobCode()) {
298
tty.print("code");
299
} else if (isInBlobData()) {
300
tty.print("data");
301
} else if (isInBlobOops()) {
302
tty.print("oops");
303
} else {
304
if (Assert.ASSERTS_ENABLED) {
305
Assert.that(isInBlobUnknownLocation(), "Should have known location in CodeBlob");
306
}
307
tty.print("unknown location");
308
}
309
tty.print(" in ");
310
if (verbose) {
311
b.printOn(tty); // includes "\n"
312
} else {
313
tty.println(b.toString());
314
}
315
316
// FIXME: add more detail
317
} else if (isInStrongGlobalJNIHandles()) {
318
tty.println("In JNI strong global");
319
} else if (isInWeakGlobalJNIHandles()) {
320
tty.println("In JNI weak global");
321
} else if (isInLocalJNIHandleBlock()) {
322
tty.print("In thread-local");
323
tty.print(" JNI handle block (" + handleBlock.top() + " handle slots present)");
324
if (handleThread.isJavaThread()) {
325
tty.print(" for JavaThread ");
326
((JavaThread) handleThread).printThreadIDOn(tty); // includes "\n"
327
} else {
328
tty.println(" for a non-Java Thread");
329
}
330
} else {
331
// This must be last
332
if (Assert.ASSERTS_ENABLED) {
333
Assert.that(isUnknown(), "Should have unknown location");
334
}
335
tty.println("In unknown location");
336
}
337
}
338
}
339
340