annotate agent/src/share/classes/sun/jvm/hotspot/utilities/ReversePtrsAnalysis.java @ 6725:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents 63997f575155
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
2 * Copyright (c) 2002, 2012, 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
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
115 // Do Java-level static fields
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
116 SystemDictionary sysDict = VM.getVM().getSystemDictionary();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
117 sysDict.allClassesDo(new SystemDictionary.ClassVisitor() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
118
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
119 public void visit(Klass k) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
120 if (k instanceof InstanceKlass) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
121 final InstanceKlass ik = (InstanceKlass)k;
2411
63997f575155 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 1552
diff changeset
122 ik.iterateStaticFields(
0
a61af66fc99e Initial load
duke
parents:
diff changeset
123 new DefaultOopVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 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
125 Oop next = field.getValue(getObj());
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
126 NamedFieldIdentifier nfi = new NamedFieldIdentifier("Static field \"" +
0
a61af66fc99e Initial load
duke
parents:
diff changeset
127 field.getID().getName() +
a61af66fc99e Initial load
duke
parents:
diff changeset
128 "\" in class \"" +
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
129 ik.getName().asString() + "\"");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
130 LivenessPathElement lp = new LivenessPathElement(null, nfi);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
131 rp.put(lp, next);
a61af66fc99e Initial load
duke
parents:
diff changeset
132 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 markAndTraverse(next);
a61af66fc99e Initial load
duke
parents:
diff changeset
134 } catch (AddressException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 System.err.print("RevPtrs analysis: WARNING: AddressException at 0x" +
a61af66fc99e Initial load
duke
parents:
diff changeset
136 Long.toHexString(e.getAddress()) +
a61af66fc99e Initial load
duke
parents:
diff changeset
137 " while traversing static fields of InstanceKlass ");
a61af66fc99e Initial load
duke
parents:
diff changeset
138 ik.printValueOn(System.err);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 System.err.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 } catch (UnknownOopException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 System.err.println("RevPtrs analysis: WARNING: UnknownOopException while " +
a61af66fc99e Initial load
duke
parents:
diff changeset
142 "traversing static fields of InstanceKlass ");
a61af66fc99e Initial load
duke
parents:
diff changeset
143 ik.printValueOn(System.err);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 System.err.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
2411
63997f575155 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 1552
diff changeset
147 });
0
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
a61af66fc99e Initial load
duke
parents:
diff changeset
152 if (progressThunk != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 progressThunk.heapIterationComplete();
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // Clear out markBits
a61af66fc99e Initial load
duke
parents:
diff changeset
157 markBits = null;
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 //---------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
162 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
163 //
a61af66fc99e Initial load
duke
parents:
diff changeset
164 private HeapProgressThunk progressThunk;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 private long usedSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 private long visitedSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 private double lastNotificationFraction;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 private static final double MINIMUM_NOTIFICATION_FRACTION = 0.01;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 private ObjectHeap heap;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 private MarkBits markBits;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 private int depth; // Debugging only
a61af66fc99e Initial load
duke
parents:
diff changeset
172 private ReversePtrs rp;
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 private void markAndTraverse(OopHandle handle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 markAndTraverse(heap.newOop(handle));
a61af66fc99e Initial load
duke
parents:
diff changeset
177 } catch (AddressException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 System.err.println("RevPtrs analysis: WARNING: AddressException at 0x" +
a61af66fc99e Initial load
duke
parents:
diff changeset
179 Long.toHexString(e.getAddress()) +
a61af66fc99e Initial load
duke
parents:
diff changeset
180 " while traversing oop at " + handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
181 } catch (UnknownOopException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 System.err.println("RevPtrs analysis: WARNING: UnknownOopException for " +
a61af66fc99e Initial load
duke
parents:
diff changeset
183 "oop at " + handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 private void printHeader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 for (int i = 0; i < depth; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 System.err.print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 private void markAndTraverse(final Oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // End of path
a61af66fc99e Initial load
duke
parents:
diff changeset
196 if (obj == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // Visited object
a61af66fc99e Initial load
duke
parents:
diff changeset
201 if (!markBits.mark(obj)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 // Root of work list for objects to be visited. A simple
a61af66fc99e Initial load
duke
parents:
diff changeset
206 // stack for saving new objects to be analyzed.
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 final Stack workList = new Stack();
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 // Next object to be visited.
a61af66fc99e Initial load
duke
parents:
diff changeset
211 Oop next = obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // Node in the list currently being visited.
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 while (true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 final Oop currObj = next;
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // For the progress meter
a61af66fc99e Initial load
duke
parents:
diff changeset
220 if (progressThunk != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 visitedSize += currObj.getObjectSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
222 double curFrac = (double) visitedSize / (double) usedSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 if (curFrac >
a61af66fc99e Initial load
duke
parents:
diff changeset
224 lastNotificationFraction + MINIMUM_NOTIFICATION_FRACTION) {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 progressThunk.heapIterationFractionUpdate(curFrac);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 lastNotificationFraction = curFrac;
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
229
a61af66fc99e Initial load
duke
parents:
diff changeset
230 if (DEBUG) {
a61af66fc99e Initial load
duke
parents:
diff changeset
231 ++depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
232 printHeader();
a61af66fc99e Initial load
duke
parents:
diff changeset
233 System.err.println("ReversePtrs.markAndTraverse(" +
a61af66fc99e Initial load
duke
parents:
diff changeset
234 currObj.getHandle() + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // Iterate over the references in the object. Do the
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // reverse pointer analysis for each reference.
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // Add the reference to the work-list so that its
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // references will be visited.
a61af66fc99e Initial load
duke
parents:
diff changeset
241 currObj.iterate(new DefaultOopVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 public void doOop(OopField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
243 // "field" refers to a reference in currObj
a61af66fc99e Initial load
duke
parents:
diff changeset
244 Oop next = field.getValue(currObj);
a61af66fc99e Initial load
duke
parents:
diff changeset
245 rp.put(new LivenessPathElement(currObj, field.getID()), next);
a61af66fc99e Initial load
duke
parents:
diff changeset
246 if ((next != null) && markBits.mark(next)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 workList.push(next);
a61af66fc99e Initial load
duke
parents:
diff changeset
248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 if (DEBUG) {
a61af66fc99e Initial load
duke
parents:
diff changeset
253 --depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 // Get the next object to visit.
a61af66fc99e Initial load
duke
parents:
diff changeset
257 next = (Oop) workList.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
259 } catch (EmptyStackException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
260 // Done
a61af66fc99e Initial load
duke
parents:
diff changeset
261 } catch (NullPointerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
262 System.err.println("ReversePtrs: WARNING: " + e +
a61af66fc99e Initial load
duke
parents:
diff changeset
263 " during traversal");
a61af66fc99e Initial load
duke
parents:
diff changeset
264 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
265 System.err.println("ReversePtrs: WARNING: " + e +
a61af66fc99e Initial load
duke
parents:
diff changeset
266 " during traversal");
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
a61af66fc99e Initial load
duke
parents:
diff changeset
271 class RootVisitor implements AddressVisitor {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 RootVisitor(String baseRootDescription) {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 this.baseRootDescription = baseRootDescription;
a61af66fc99e Initial load
duke
parents:
diff changeset
274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
275
a61af66fc99e Initial load
duke
parents:
diff changeset
276 public void visitAddress(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 Oop next = heap.newOop(addr.getOopHandleAt(0));
a61af66fc99e Initial load
duke
parents:
diff changeset
278 LivenessPathElement lp = new LivenessPathElement(null,
a61af66fc99e Initial load
duke
parents:
diff changeset
279 new NamedFieldIdentifier(baseRootDescription +
a61af66fc99e Initial load
duke
parents:
diff changeset
280 " @ " + addr));
a61af66fc99e Initial load
duke
parents:
diff changeset
281 rp.put(lp, next);
a61af66fc99e Initial load
duke
parents:
diff changeset
282 markAndTraverse(next);
a61af66fc99e Initial load
duke
parents:
diff changeset
283 }
a61af66fc99e Initial load
duke
parents:
diff changeset
284
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
285 public void visitCompOopAddress(Address addr) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
286 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
287 LivenessPathElement lp = new LivenessPathElement(null,
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
288 new NamedFieldIdentifier(baseRootDescription +
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
289 " @ " + addr));
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
290 rp.put(lp, next);
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
291 markAndTraverse(next);
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
292 }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
293
0
a61af66fc99e Initial load
duke
parents:
diff changeset
294 private String baseRootDescription;
a61af66fc99e Initial load
duke
parents:
diff changeset
295 }
a61af66fc99e Initial load
duke
parents:
diff changeset
296
a61af66fc99e Initial load
duke
parents:
diff changeset
297 // Traverse the roots on a given thread's stack
a61af66fc99e Initial load
duke
parents:
diff changeset
298 private void doStack(JavaThread thread, AddressVisitor oopVisitor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 for (StackFrameStream fst = new StackFrameStream(thread); !fst.isDone(); fst.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 fst.getCurrent().oopsDo(oopVisitor, fst.getRegisterMap());
a61af66fc99e Initial load
duke
parents:
diff changeset
301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304 // Traverse a JNIHandleBlock
a61af66fc99e Initial load
duke
parents:
diff changeset
305 private void doJNIHandleBlock(JNIHandleBlock handles, AddressVisitor oopVisitor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
306 handles.oopsDo(oopVisitor);
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308 }