annotate agent/src/share/classes/sun/jvm/hotspot/utilities/ReversePtrsAnalysis.java @ 2411:63997f575155

7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue Reviewed-by: kvn, dcubed
author never
date Wed, 30 Mar 2011 07:47:19 -0700
parents c18cbe5936b8
children da91efe96a93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2411
63997f575155 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 1552
diff changeset
2 * Copyright (c) 2002, 2011, 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.utilities;
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.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.gc_interface.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.memory.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 /** For a set of known roots, descends recursively into the object
a61af66fc99e Initial load
duke
parents:
diff changeset
37 graph, for each object recording those objects (and their fields)
a61af66fc99e Initial load
duke
parents:
diff changeset
38 which point to it. NOTE: currently only a subset of the roots
a61af66fc99e Initial load
duke
parents:
diff changeset
39 known to the VM is exposed to the SA: objects on the stack, static
a61af66fc99e Initial load
duke
parents:
diff changeset
40 fields in classes, and JNI handles. These should be most of the
a61af66fc99e Initial load
duke
parents:
diff changeset
41 user-level roots keeping objects alive. */
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 public class ReversePtrsAnalysis {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // Used for debugging this code
a61af66fc99e Initial load
duke
parents:
diff changeset
45 private static final boolean DEBUG = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 public ReversePtrsAnalysis() {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 }
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 /** Sets an optional progress thunk */
a61af66fc99e Initial load
duke
parents:
diff changeset
51 public void setHeapProgressThunk(HeapProgressThunk thunk) {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 progressThunk = thunk;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 /** Runs the analysis algorithm */
a61af66fc99e Initial load
duke
parents:
diff changeset
57 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 if (VM.getVM().getRevPtrs() != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 return; // Assume already done
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 VM vm = VM.getVM();
a61af66fc99e Initial load
duke
parents:
diff changeset
63 rp = new ReversePtrs();
a61af66fc99e Initial load
duke
parents:
diff changeset
64 vm.setRevPtrs(rp);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 Universe universe = vm.getUniverse();
a61af66fc99e Initial load
duke
parents:
diff changeset
66 CollectedHeap collHeap = universe.heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
67 usedSize = collHeap.used();
a61af66fc99e Initial load
duke
parents:
diff changeset
68 visitedSize = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // Note that an experiment to iterate the heap linearly rather
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // than in recursive-descent order has been done. It turns out
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // that the recursive-descent algorithm is nearly twice as fast
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // due to the fact that it scans only live objects and (currently)
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // only a fraction of the perm gen, namely the static fields
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // contained in instanceKlasses. (Iterating the heap linearly
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // would also change the semantics of the result so that
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // ReversePtrs.get() would return a non-null value even for dead
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // objects.) Nonetheless, the reverse pointer computation is still
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // quite slow and optimization in field iteration of objects
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // should be done.
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 if (progressThunk != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // Get it started
a61af66fc99e Initial load
duke
parents:
diff changeset
84 progressThunk.heapIterationFractionUpdate(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // Allocate mark bits for heap
a61af66fc99e Initial load
duke
parents:
diff changeset
88 markBits = new MarkBits(collHeap);
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // Get a hold of the object heap
a61af66fc99e Initial load
duke
parents:
diff changeset
91 heap = vm.getObjectHeap();
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // Do each thread's roots
a61af66fc99e Initial load
duke
parents:
diff changeset
94 for (JavaThread thread = VM.getVM().getThreads().first();
a61af66fc99e Initial load
duke
parents:
diff changeset
95 thread != null;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 thread = thread.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 ByteArrayOutputStream bos = new ByteArrayOutputStream();
a61af66fc99e Initial load
duke
parents:
diff changeset
98 thread.printThreadIDOn(new PrintStream(bos));
a61af66fc99e Initial load
duke
parents:
diff changeset
99 String threadDesc =
a61af66fc99e Initial load
duke
parents:
diff changeset
100 " in thread \"" + thread.getThreadName() +
a61af66fc99e Initial load
duke
parents:
diff changeset
101 "\" (id " + bos.toString() + ")";
a61af66fc99e Initial load
duke
parents:
diff changeset
102 doStack(thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
103 new RootVisitor("Stack root" + threadDesc));
a61af66fc99e Initial load
duke
parents:
diff changeset
104 doJNIHandleBlock(thread.activeHandles(),
a61af66fc99e Initial load
duke
parents:
diff changeset
105 new RootVisitor("JNI handle root" + threadDesc));
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // Do global JNI handles
a61af66fc99e Initial load
duke
parents:
diff changeset
109 JNIHandles handles = VM.getVM().getJNIHandles();
a61af66fc99e Initial load
duke
parents:
diff changeset
110 doJNIHandleBlock(handles.globalHandles(),
a61af66fc99e Initial load
duke
parents:
diff changeset
111 new RootVisitor("Global JNI handle root"));
a61af66fc99e Initial load
duke
parents:
diff changeset
112 doJNIHandleBlock(handles.weakGlobalHandles(),
a61af66fc99e Initial load
duke
parents:
diff changeset
113 new RootVisitor("Weak global JNI handle root"));
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // Do Java-level static fields in perm gen
a61af66fc99e Initial load
duke
parents:
diff changeset
116 heap.iteratePerm(new DefaultHeapVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 public boolean doObj(Oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 if (obj instanceof InstanceKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 final InstanceKlass ik = (InstanceKlass) obj;
2411
63997f575155 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 1552
diff changeset
120 ik.iterateStaticFields(
0
a61af66fc99e Initial load
duke
parents:
diff changeset
121 new DefaultOopVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 public void doOop(OopField field, boolean isVMField) {
2411
63997f575155 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 1552
diff changeset
123 Oop next = field.getValue(getObj());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
124 LivenessPathElement lp = new LivenessPathElement(null,
a61af66fc99e Initial load
duke
parents:
diff changeset
125 new NamedFieldIdentifier("Static field \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
126 field.getID().getName() +
a61af66fc99e Initial load
duke
parents:
diff changeset
127 "\" in class \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
128 ik.getName().asString() + "\""));
a61af66fc99e Initial load
duke
parents:
diff changeset
129 rp.put(lp, next);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 markAndTraverse(next);
a61af66fc99e Initial load
duke
parents:
diff changeset
132 } catch (AddressException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 System.err.print("RevPtrs analysis: WARNING: AddressException at 0x" +
a61af66fc99e Initial load
duke
parents:
diff changeset
134 Long.toHexString(e.getAddress()) +
a61af66fc99e Initial load
duke
parents:
diff changeset
135 " while traversing static fields of InstanceKlass ");
a61af66fc99e Initial load
duke
parents:
diff changeset
136 ik.printValueOn(System.err);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 System.err.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
138 } catch (UnknownOopException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 System.err.println("RevPtrs analysis: WARNING: UnknownOopException while " +
a61af66fc99e Initial load
duke
parents:
diff changeset
140 "traversing static fields of InstanceKlass ");
a61af66fc99e Initial load
duke
parents:
diff changeset
141 ik.printValueOn(System.err);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 System.err.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
2411
63997f575155 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 1552
diff changeset
145 });
0
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149 });
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 if (progressThunk != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 progressThunk.heapIterationComplete();
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // Clear out markBits
a61af66fc99e Initial load
duke
parents:
diff changeset
156 markBits = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
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 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
162 //
a61af66fc99e Initial load
duke
parents:
diff changeset
163 private HeapProgressThunk progressThunk;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 private long usedSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 private long visitedSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 private double lastNotificationFraction;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 private static final double MINIMUM_NOTIFICATION_FRACTION = 0.01;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 private ObjectHeap heap;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 private MarkBits markBits;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 private int depth; // Debugging only
a61af66fc99e Initial load
duke
parents:
diff changeset
171 private ReversePtrs rp;
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 private void markAndTraverse(OopHandle handle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 markAndTraverse(heap.newOop(handle));
a61af66fc99e Initial load
duke
parents:
diff changeset
176 } catch (AddressException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 System.err.println("RevPtrs analysis: WARNING: AddressException at 0x" +
a61af66fc99e Initial load
duke
parents:
diff changeset
178 Long.toHexString(e.getAddress()) +
a61af66fc99e Initial load
duke
parents:
diff changeset
179 " while traversing oop at " + handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 } catch (UnknownOopException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 System.err.println("RevPtrs analysis: WARNING: UnknownOopException for " +
a61af66fc99e Initial load
duke
parents:
diff changeset
182 "oop at " + handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 private void printHeader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 for (int i = 0; i < depth; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 System.err.print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 private void markAndTraverse(final Oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 // End of path
a61af66fc99e Initial load
duke
parents:
diff changeset
195 if (obj == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // Visited object
a61af66fc99e Initial load
duke
parents:
diff changeset
200 if (!markBits.mark(obj)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 // Root of work list for objects to be visited. A simple
a61af66fc99e Initial load
duke
parents:
diff changeset
205 // stack for saving new objects to be analyzed.
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207 final Stack workList = new Stack();
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 // Next object to be visited.
a61af66fc99e Initial load
duke
parents:
diff changeset
210 Oop next = obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 // Node in the list currently being visited.
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 while (true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 final Oop currObj = next;
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // For the progress meter
a61af66fc99e Initial load
duke
parents:
diff changeset
219 if (progressThunk != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 visitedSize += currObj.getObjectSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
221 double curFrac = (double) visitedSize / (double) usedSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
222 if (curFrac >
a61af66fc99e Initial load
duke
parents:
diff changeset
223 lastNotificationFraction + MINIMUM_NOTIFICATION_FRACTION) {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 progressThunk.heapIterationFractionUpdate(curFrac);
a61af66fc99e Initial load
duke
parents:
diff changeset
225 lastNotificationFraction = curFrac;
a61af66fc99e Initial load
duke
parents:
diff changeset
226 }
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
228
a61af66fc99e Initial load
duke
parents:
diff changeset
229 if (DEBUG) {
a61af66fc99e Initial load
duke
parents:
diff changeset
230 ++depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
231 printHeader();
a61af66fc99e Initial load
duke
parents:
diff changeset
232 System.err.println("ReversePtrs.markAndTraverse(" +
a61af66fc99e Initial load
duke
parents:
diff changeset
233 currObj.getHandle() + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 // Iterate over the references in the object. Do the
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // reverse pointer analysis for each reference.
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // Add the reference to the work-list so that its
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // references will be visited.
a61af66fc99e Initial load
duke
parents:
diff changeset
240 currObj.iterate(new DefaultOopVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 public void doOop(OopField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 // "field" refers to a reference in currObj
a61af66fc99e Initial load
duke
parents:
diff changeset
243 Oop next = field.getValue(currObj);
a61af66fc99e Initial load
duke
parents:
diff changeset
244 rp.put(new LivenessPathElement(currObj, field.getID()), next);
a61af66fc99e Initial load
duke
parents:
diff changeset
245 if ((next != null) && markBits.mark(next)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
246 workList.push(next);
a61af66fc99e Initial load
duke
parents:
diff changeset
247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
250
a61af66fc99e Initial load
duke
parents:
diff changeset
251 if (DEBUG) {
a61af66fc99e Initial load
duke
parents:
diff changeset
252 --depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
253 }
a61af66fc99e Initial load
duke
parents:
diff changeset
254
a61af66fc99e Initial load
duke
parents:
diff changeset
255 // Get the next object to visit.
a61af66fc99e Initial load
duke
parents:
diff changeset
256 next = (Oop) workList.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
258 } catch (EmptyStackException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 // Done
a61af66fc99e Initial load
duke
parents:
diff changeset
260 } catch (NullPointerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 System.err.println("ReversePtrs: WARNING: " + e +
a61af66fc99e Initial load
duke
parents:
diff changeset
262 " during traversal");
a61af66fc99e Initial load
duke
parents:
diff changeset
263 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
264 System.err.println("ReversePtrs: WARNING: " + e +
a61af66fc99e Initial load
duke
parents:
diff changeset
265 " during traversal");
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268
a61af66fc99e Initial load
duke
parents:
diff changeset
269
a61af66fc99e Initial load
duke
parents:
diff changeset
270 class RootVisitor implements AddressVisitor {
a61af66fc99e Initial load
duke
parents:
diff changeset
271 RootVisitor(String baseRootDescription) {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 this.baseRootDescription = baseRootDescription;
a61af66fc99e Initial load
duke
parents:
diff changeset
273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 public void visitAddress(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 Oop next = heap.newOop(addr.getOopHandleAt(0));
a61af66fc99e Initial load
duke
parents:
diff changeset
277 LivenessPathElement lp = new LivenessPathElement(null,
a61af66fc99e Initial load
duke
parents:
diff changeset
278 new NamedFieldIdentifier(baseRootDescription +
a61af66fc99e Initial load
duke
parents:
diff changeset
279 " @ " + addr));
a61af66fc99e Initial load
duke
parents:
diff changeset
280 rp.put(lp, next);
a61af66fc99e Initial load
duke
parents:
diff changeset
281 markAndTraverse(next);
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
283
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
284 public void visitCompOopAddress(Address addr) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
285 Oop next = heap.newOop(addr.getCompOopHandleAt(0));
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
286 LivenessPathElement lp = new LivenessPathElement(null,
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
287 new NamedFieldIdentifier(baseRootDescription +
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
288 " @ " + addr));
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
289 rp.put(lp, next);
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
290 markAndTraverse(next);
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
291 }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
292
0
a61af66fc99e Initial load
duke
parents:
diff changeset
293 private String baseRootDescription;
a61af66fc99e Initial load
duke
parents:
diff changeset
294 }
a61af66fc99e Initial load
duke
parents:
diff changeset
295
a61af66fc99e Initial load
duke
parents:
diff changeset
296 // Traverse the roots on a given thread's stack
a61af66fc99e Initial load
duke
parents:
diff changeset
297 private void doStack(JavaThread thread, AddressVisitor oopVisitor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
298 for (StackFrameStream fst = new StackFrameStream(thread); !fst.isDone(); fst.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 fst.getCurrent().oopsDo(oopVisitor, fst.getRegisterMap());
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303 // Traverse a JNIHandleBlock
a61af66fc99e Initial load
duke
parents:
diff changeset
304 private void doJNIHandleBlock(JNIHandleBlock handles, AddressVisitor oopVisitor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
305 handles.oopsDo(oopVisitor);
a61af66fc99e Initial load
duke
parents:
diff changeset
306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }