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/PointerFinder.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 sun.jvm.hotspot.code.*;
28
import sun.jvm.hotspot.debugger.*;
29
import sun.jvm.hotspot.debugger.cdbg.*;
30
import sun.jvm.hotspot.gc.shared.*;
31
import sun.jvm.hotspot.interpreter.*;
32
import sun.jvm.hotspot.memory.*;
33
import sun.jvm.hotspot.oops.Metadata;
34
import sun.jvm.hotspot.runtime.*;
35
import sun.jvm.hotspot.types.WrongTypeException;
36
37
/** This class, only intended for use in the debugging system,
38
provides the functionality of find() in the VM. */
39
40
public class PointerFinder {
41
public static PointerLocation find(Address a) {
42
PointerLocation loc = new PointerLocation(a);
43
Threads threads = VM.getVM().getThreads();
44
45
// Check if address is a pointer to a Metadata object.
46
try {
47
loc.metadata = Metadata.instantiateWrapperFor(a);
48
return loc;
49
} catch (Exception e) {
50
// Just ignore. This just means we aren't dealing with a Metadata pointer.
51
}
52
53
// Check if address is some other C++ type that we can deduce
54
loc.ctype = VM.getVM().getTypeDataBase().guessTypeForAddress(a);
55
if (loc.ctype == null && VM.getVM().isSharingEnabled()) {
56
// Check if the value falls in the _md_region
57
try {
58
Address loc1 = a.getAddressAt(0);
59
FileMapInfo cdsFileMapInfo = VM.getVM().getFileMapInfo();
60
if (cdsFileMapInfo.inCopiedVtableSpace(loc1)) {
61
loc.ctype = cdsFileMapInfo.getTypeForVptrAddress(loc1);
62
}
63
} catch (AddressException | WrongTypeException e) {
64
// This can happen if "a" or "loc1" is a bad address. Just ignore.
65
}
66
}
67
if (loc.ctype != null) {
68
return loc;
69
}
70
71
// Check if address is in the stack of a JavaThread
72
for (int i = 0; i < threads.getNumberOfThreads(); i++) {
73
JavaThread t = threads.getJavaThreadAt(i);
74
Address stackBase = t.getStackBase();
75
if (stackBase != null) {
76
Long stackSize = t.getStackSize();
77
Address stackEnd = stackBase.addOffsetTo(-stackSize);
78
if (a.lessThanOrEqual(stackBase) && a.greaterThan(stackEnd)) {
79
loc.stackThread = t;
80
return loc;
81
}
82
}
83
}
84
85
// Check if address is in the java heap.
86
CollectedHeap heap = VM.getVM().getUniverse().heap();
87
if (heap instanceof GenCollectedHeap) {
88
GenCollectedHeap genheap = (GenCollectedHeap) heap;
89
if (genheap.isIn(a)) {
90
for (int i = 0; i < genheap.nGens(); i++) {
91
Generation g = genheap.getGen(i);
92
if (g.isIn(a)) {
93
loc.gen = g;
94
break;
95
}
96
}
97
98
if (Assert.ASSERTS_ENABLED) {
99
Assert.that(loc.gen != null, "Should have found this in a generation");
100
}
101
102
if (VM.getVM().getUseTLAB()) {
103
// Try to find thread containing it
104
for (int i = 0; i < threads.getNumberOfThreads(); i++) {
105
JavaThread t = threads.getJavaThreadAt(i);
106
ThreadLocalAllocBuffer tlab = t.tlab();
107
if (tlab.contains(a)) {
108
loc.inTLAB = true;
109
loc.tlabThread = t;
110
loc.tlab = tlab;
111
break;
112
}
113
}
114
}
115
116
return loc;
117
}
118
} else {
119
if (heap.isIn(a)) {
120
loc.heap = heap;
121
return loc;
122
}
123
}
124
125
// Check if address is in the interpreter
126
Interpreter interp = VM.getVM().getInterpreter();
127
if (interp.contains(a)) {
128
loc.inInterpreter = true;
129
loc.interpreterCodelet = interp.getCodeletContaining(a);
130
return loc;
131
}
132
133
// Check if address is in the code cache
134
if (!VM.getVM().isCore()) {
135
CodeCache c = VM.getVM().getCodeCache();
136
if (c.contains(a)) {
137
loc.inCodeCache = true;
138
loc.blob = c.findBlobUnsafe(a);
139
if (Assert.ASSERTS_ENABLED) {
140
Assert.that(loc.blob != null, "Should have found CodeBlob");
141
}
142
loc.inBlobCode = loc.blob.codeContains(a);
143
loc.inBlobData = loc.blob.dataContains(a);
144
145
if (loc.blob.isNMethod()) {
146
NMethod nm = (NMethod) loc.blob;
147
loc.inBlobOops = nm.oopsContains(a);
148
}
149
150
loc.inBlobUnknownLocation = (!(loc.inBlobCode ||
151
loc.inBlobData ||
152
loc.inBlobOops));
153
return loc;
154
}
155
}
156
157
// Check JNIHandles; both local and global
158
JNIHandles handles = VM.getVM().getJNIHandles();
159
160
// --- looking in oopstorage should model OopStorage::allocation_status?
161
// --- that is, if in a block but not allocated, then not valid.
162
163
// Look in global handles
164
OopStorage storage = handles.globalHandles();
165
if ((storage != null) && storage.findOop(a)) {
166
loc.inStrongGlobalJNIHandles = true;
167
return loc;
168
}
169
// Look in weak global handles
170
storage = handles.weakGlobalHandles();
171
if ((storage != null) && storage.findOop(a)) {
172
loc.inWeakGlobalJNIHandles = true;
173
return loc;
174
}
175
// Look in thread-local handles
176
for (int i = 0; i < threads.getNumberOfThreads(); i++) {
177
JavaThread t = threads.getJavaThreadAt(i);
178
JNIHandleBlock handleBlock = t.activeHandles();
179
if (handleBlock != null) {
180
handleBlock = handleBlock.blockContainingHandle(a);
181
if (handleBlock != null) {
182
loc.inLocalJNIHandleBlock = true;
183
loc.handleBlock = handleBlock;
184
loc.handleThread = t;
185
return loc;
186
}
187
}
188
}
189
190
// Check if address is a native (C++) symbol. Do this last because we don't always
191
// do a good job of computing if an address is actually within a native lib, and sometimes
192
// an address outside of a lib will be found as inside.
193
JVMDebugger dbg = VM.getVM().getDebugger();
194
CDebugger cdbg = dbg.getCDebugger();
195
if (cdbg != null) {
196
loc.loadObject = cdbg.loadObjectContainingPC(a);
197
if (loc.loadObject != null) {
198
loc.nativeSymbol = loc.loadObject.closestSymbolToPC(a);
199
return loc;
200
}
201
}
202
203
// Fall through; have to return it anyway.
204
return loc;
205
}
206
}
207
208