author | kbarrett |
Tue, 21 Nov 2017 09:47:55 -0500 | |
changeset 48787 | 7638bf98a312 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2000, 2018, 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:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
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:
1
diff
changeset
|
21 |
* questions. |
1 | 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.*; |
|
30764 | 30 |
import sun.jvm.hotspot.gc.shared.*; |
1 | 31 |
import sun.jvm.hotspot.interpreter.*; |
32 |
import sun.jvm.hotspot.runtime.*; |
|
33 |
import sun.jvm.hotspot.memory.*; |
|
34 |
||
35 |
/** This class attempts to describe possible locations of pointers in |
|
36 |
the VM. */ |
|
37 |
||
38 |
public class PointerLocation { |
|
39 |
////////////////////////////////////////////////////////////////// |
|
40 |
// // |
|
41 |
// These are package private to simplify the implementation and // |
|
42 |
// interaction with PointerFinder // |
|
43 |
// // |
|
44 |
////////////////////////////////////////////////////////////////// |
|
45 |
||
46 |
Address addr; |
|
47 |
||
48 |
CollectedHeap heap; |
|
49 |
Generation gen; |
|
50 |
||
51 |
// If UseTLAB was enabled and the pointer was found in a |
|
52 |
// currently-active TLAB, these will be set |
|
53 |
boolean inTLAB; |
|
54 |
JavaThread tlabThread; |
|
55 |
ThreadLocalAllocBuffer tlab; |
|
56 |
||
57 |
// Generated code locations |
|
58 |
boolean inInterpreter; |
|
59 |
boolean inCodeCache; |
|
60 |
||
61 |
// FIXME: add other locations like VTableStubs, StubRoutines, maybe |
|
62 |
// even "on thread x's stack" |
|
63 |
||
64 |
InterpreterCodelet interpreterCodelet; |
|
65 |
CodeBlob blob; |
|
66 |
// FIXME: add more detail about CodeBlob |
|
6418 | 67 |
boolean inBlobCode; |
1 | 68 |
boolean inBlobData; |
69 |
boolean inBlobOops; |
|
70 |
boolean inBlobUnknownLocation; |
|
71 |
||
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
72 |
boolean inStrongGlobalJNIHandles; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
73 |
boolean inWeakGlobalJNIHandles; |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
74 |
|
1 | 75 |
boolean inLocalJNIHandleBlock; |
76 |
JNIHandleBlock handleBlock; |
|
77 |
sun.jvm.hotspot.runtime.Thread handleThread; |
|
78 |
||
79 |
public PointerLocation(Address addr) { |
|
80 |
this.addr = addr; |
|
81 |
} |
|
82 |
||
83 |
public boolean isInHeap() { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6418
diff
changeset
|
84 |
return (heap != null || (gen != null)); |
1 | 85 |
} |
86 |
||
87 |
public boolean isInNewGen() { |
|
31358
693058672cc6
8077842: Remove the level parameter passed around in GenCollectedHeap
jwilhelm
parents:
30764
diff
changeset
|
88 |
return ((gen != null) && (gen == ((GenCollectedHeap)heap).getGen(0))); |
1 | 89 |
} |
90 |
||
91 |
public boolean isInOldGen() { |
|
31358
693058672cc6
8077842: Remove the level parameter passed around in GenCollectedHeap
jwilhelm
parents:
30764
diff
changeset
|
92 |
return ((gen != null) && (gen == ((GenCollectedHeap)heap).getGen(1))); |
1 | 93 |
} |
94 |
||
95 |
public boolean inOtherGen() { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6418
diff
changeset
|
96 |
return (!isInNewGen() && !isInOldGen()); |
1 | 97 |
} |
98 |
||
99 |
/** Only valid if isInHeap() */ |
|
100 |
public Generation getGeneration() { |
|
101 |
return gen; |
|
102 |
} |
|
103 |
||
104 |
/** This may be true if isInNewGen is also true */ |
|
105 |
public boolean isInTLAB() { |
|
106 |
return inTLAB; |
|
107 |
} |
|
108 |
||
109 |
/** Only valid if isInTLAB() returns true */ |
|
110 |
public JavaThread getTLABThread() { |
|
111 |
return tlabThread; |
|
112 |
} |
|
113 |
||
114 |
/** Only valid if isInTLAB() returns true */ |
|
115 |
public ThreadLocalAllocBuffer getTLAB() { |
|
116 |
return tlab; |
|
117 |
} |
|
118 |
||
119 |
public boolean isInInterpreter() { |
|
120 |
return inInterpreter; |
|
121 |
} |
|
122 |
||
123 |
/** For now, only valid if isInInterpreter is true */ |
|
124 |
public InterpreterCodelet getInterpreterCodelet() { |
|
125 |
return interpreterCodelet; |
|
126 |
} |
|
127 |
||
128 |
public boolean isInCodeCache() { |
|
129 |
return inCodeCache; |
|
130 |
} |
|
131 |
||
132 |
/** For now, only valid if isInCodeCache is true */ |
|
133 |
public CodeBlob getCodeBlob() { |
|
134 |
return blob; |
|
135 |
} |
|
136 |
||
6418 | 137 |
public boolean isInBlobCode() { |
138 |
return inBlobCode; |
|
1 | 139 |
} |
140 |
||
141 |
public boolean isInBlobData() { |
|
142 |
return inBlobData; |
|
143 |
} |
|
144 |
||
145 |
public boolean isInBlobOops() { |
|
146 |
return inBlobOops; |
|
147 |
} |
|
148 |
||
149 |
public boolean isInBlobUnknownLocation() { |
|
150 |
return inBlobUnknownLocation; |
|
151 |
} |
|
152 |
||
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
153 |
public boolean isInStrongGlobalJNIHandles() { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
154 |
return inStrongGlobalJNIHandles; |
1 | 155 |
} |
156 |
||
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
157 |
public boolean isInWeakGlobalJNIHandles() { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
158 |
return inWeakGlobalJNIHandles; |
1 | 159 |
} |
160 |
||
161 |
public boolean isInLocalJNIHandleBlock() { |
|
162 |
return inLocalJNIHandleBlock; |
|
163 |
} |
|
164 |
||
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
165 |
/** Only valid if isInLocalJNIHandleBlock is true */ |
1 | 166 |
public JNIHandleBlock getJNIHandleBlock() { |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
167 |
assert isInLocalJNIHandleBlock(); |
1 | 168 |
return handleBlock; |
169 |
} |
|
170 |
||
171 |
/** Only valid if isInLocalJNIHandleBlock is true */ |
|
172 |
public sun.jvm.hotspot.runtime.Thread getJNIHandleThread() { |
|
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
173 |
assert isInLocalJNIHandleBlock(); |
1 | 174 |
return handleThread; |
175 |
} |
|
176 |
||
177 |
public boolean isUnknown() { |
|
178 |
return (!(isInHeap() || isInInterpreter() || isInCodeCache() || |
|
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
179 |
isInStrongGlobalJNIHandles() || isInWeakGlobalJNIHandles() || isInLocalJNIHandleBlock())); |
1 | 180 |
} |
181 |
||
182 |
public String toString() { |
|
183 |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
|
184 |
printOn(new PrintStream(bos)); |
|
185 |
return bos.toString(); |
|
186 |
} |
|
187 |
||
188 |
public void print() { |
|
189 |
printOn(System.out); |
|
190 |
} |
|
191 |
||
192 |
public void printOn(PrintStream tty) { |
|
193 |
tty.print("Address "); |
|
194 |
if (addr == null) { |
|
195 |
tty.print("0x0"); |
|
196 |
} else { |
|
197 |
tty.print(addr.toString()); |
|
198 |
} |
|
199 |
tty.print(": "); |
|
200 |
if (isInHeap()) { |
|
201 |
if (isInTLAB()) { |
|
202 |
tty.print("In thread-local allocation buffer for thread \"" + |
|
203 |
getTLABThread().getThreadName() + "\" ("); |
|
204 |
getTLABThread().printThreadIDOn(tty); |
|
205 |
tty.print(") "); |
|
206 |
getTLAB().printOn(tty); |
|
207 |
} else { |
|
208 |
if (isInNewGen()) { |
|
209 |
tty.print("In new generation "); |
|
210 |
} else if (isInOldGen()) { |
|
211 |
tty.print("In old generation "); |
|
212 |
} else { |
|
213 |
tty.print("In unknown section of Java heap"); |
|
214 |
} |
|
215 |
if (getGeneration() != null) { |
|
216 |
getGeneration().printOn(tty); |
|
217 |
} |
|
218 |
} |
|
219 |
} else if (isInInterpreter()) { |
|
220 |
tty.println("In interpreter codelet \"" + interpreterCodelet.getDescription() + "\""); |
|
221 |
interpreterCodelet.printOn(tty); |
|
222 |
} else if (isInCodeCache()) { |
|
223 |
CodeBlob b = getCodeBlob(); |
|
224 |
tty.print("In "); |
|
6418 | 225 |
if (isInBlobCode()) { |
226 |
tty.print("code"); |
|
1 | 227 |
} else if (isInBlobData()) { |
228 |
tty.print("data"); |
|
229 |
} else if (isInBlobOops()) { |
|
230 |
tty.print("oops"); |
|
231 |
} else { |
|
232 |
if (Assert.ASSERTS_ENABLED) { |
|
233 |
Assert.that(isInBlobUnknownLocation(), "Should have known location in CodeBlob"); |
|
234 |
} |
|
235 |
tty.print("unknown location"); |
|
236 |
} |
|
237 |
tty.print(" in "); |
|
238 |
b.printOn(tty); |
|
239 |
||
240 |
// FIXME: add more detail |
|
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
241 |
} else if (isInStrongGlobalJNIHandles()) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
242 |
tty.print("In JNI strong global"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
243 |
} else if (isInWeakGlobalJNIHandles()) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
244 |
tty.print("In JNI weak global"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
245 |
} else if (isInLocalJNIHandleBlock()) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
246 |
tty.print("In thread-local"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
247 |
tty.print(" JNI handle block (" + handleBlock.top() + " handle slots present)"); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
248 |
if (handleThread.isJavaThread()) { |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
249 |
tty.print(" for JavaThread "); |
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
250 |
((JavaThread) handleThread).printThreadIDOn(tty); |
1 | 251 |
} else { |
48787
7638bf98a312
8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
47216
diff
changeset
|
252 |
tty.print(" for a non-Java Thread"); |
1 | 253 |
} |
254 |
} else { |
|
255 |
// This must be last |
|
256 |
if (Assert.ASSERTS_ENABLED) { |
|
257 |
Assert.that(isUnknown(), "Should have unknown location"); |
|
258 |
} |
|
259 |
tty.print("In unknown location"); |
|
260 |
} |
|
261 |
} |
|
262 |
} |