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 java.util.*;
29 import sun.jvm.hotspot.debugger.*;
30 import sun.jvm.hotspot.gc.shared.*;
31 import sun.jvm.hotspot.memory.*;
32 import sun.jvm.hotspot.oops.*;
33 import sun.jvm.hotspot.runtime.*;
34 import sun.jvm.hotspot.utilities.*;
35
36 /** For a set of known roots, descends recursively into the object
37 graph, for each object recording those objects (and their fields)
38 which point to it. NOTE: currently only a subset of the roots
39 known to the VM is exposed to the SA: objects on the stack, static
40 fields in classes, and JNI handles. These should be most of the
41 user-level roots keeping objects alive. */
42
43 public class ReversePtrsAnalysis {
44 // Used for debugging this code
45 private static final boolean DEBUG = false;
46
47 public ReversePtrsAnalysis() {
48 }
49
96 thread = thread.next()) {
97 ByteArrayOutputStream bos = new ByteArrayOutputStream();
98 thread.printThreadIDOn(new PrintStream(bos));
99 String threadDesc =
100 " in thread \"" + thread.getThreadName() +
101 "\" (id " + bos.toString() + ")";
102 doStack(thread,
103 new RootVisitor("Stack root" + threadDesc));
104 doJNIHandleBlock(thread.activeHandles(),
105 new RootVisitor("JNI handle root" + threadDesc));
106 }
107
108 // Do global JNI handles
109 JNIHandles handles = VM.getVM().getJNIHandles();
110 doJNIHandleBlock(handles.globalHandles(),
111 new RootVisitor("Global JNI handle root"));
112 doJNIHandleBlock(handles.weakGlobalHandles(),
113 new RootVisitor("Weak global JNI handle root"));
114
115 // Do Java-level static fields
116 SystemDictionary sysDict = VM.getVM().getSystemDictionary();
117 sysDict.allClassesDo(new SystemDictionary.ClassVisitor() {
118
119 public void visit(Klass k) {
120 if (k instanceof InstanceKlass) {
121 final InstanceKlass ik = (InstanceKlass)k;
122 ik.iterateStaticFields(
123 new DefaultOopVisitor() {
124 public void doOop(OopField field, boolean isVMField) {
125 Oop next = field.getValue(getObj());
126 NamedFieldIdentifier nfi = new NamedFieldIdentifier("Static field \"" +
127 field.getID().getName() +
128 "\" in class \"" +
129 ik.getName().asString() + "\"");
130 LivenessPathElement lp = new LivenessPathElement(null, nfi);
131 rp.put(lp, next);
132 try {
133 markAndTraverse(next);
134 } catch (AddressException e) {
135 System.err.print("RevPtrs analysis: WARNING: AddressException at 0x" +
136 Long.toHexString(e.getAddress()) +
137 " while traversing static fields of InstanceKlass ");
|
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 java.util.*;
29 import sun.jvm.hotspot.debugger.*;
30 import sun.jvm.hotspot.classfile.*;
31 import sun.jvm.hotspot.gc.shared.*;
32 import sun.jvm.hotspot.memory.*;
33 import sun.jvm.hotspot.oops.*;
34 import sun.jvm.hotspot.runtime.*;
35 import sun.jvm.hotspot.utilities.*;
36
37 /** For a set of known roots, descends recursively into the object
38 graph, for each object recording those objects (and their fields)
39 which point to it. NOTE: currently only a subset of the roots
40 known to the VM is exposed to the SA: objects on the stack, static
41 fields in classes, and JNI handles. These should be most of the
42 user-level roots keeping objects alive. */
43
44 public class ReversePtrsAnalysis {
45 // Used for debugging this code
46 private static final boolean DEBUG = false;
47
48 public ReversePtrsAnalysis() {
49 }
50
97 thread = thread.next()) {
98 ByteArrayOutputStream bos = new ByteArrayOutputStream();
99 thread.printThreadIDOn(new PrintStream(bos));
100 String threadDesc =
101 " in thread \"" + thread.getThreadName() +
102 "\" (id " + bos.toString() + ")";
103 doStack(thread,
104 new RootVisitor("Stack root" + threadDesc));
105 doJNIHandleBlock(thread.activeHandles(),
106 new RootVisitor("JNI handle root" + threadDesc));
107 }
108
109 // Do global JNI handles
110 JNIHandles handles = VM.getVM().getJNIHandles();
111 doJNIHandleBlock(handles.globalHandles(),
112 new RootVisitor("Global JNI handle root"));
113 doJNIHandleBlock(handles.weakGlobalHandles(),
114 new RootVisitor("Weak global JNI handle root"));
115
116 // Do Java-level static fields
117 ClassLoaderDataGraph cldg = VM.getVM().getClassLoaderDataGraph();
118 cldg.classesDo(new ClassLoaderDataGraph.ClassVisitor() {
119
120 public void visit(Klass k) {
121 if (k instanceof InstanceKlass) {
122 final InstanceKlass ik = (InstanceKlass)k;
123 ik.iterateStaticFields(
124 new DefaultOopVisitor() {
125 public void doOop(OopField field, boolean isVMField) {
126 Oop next = field.getValue(getObj());
127 NamedFieldIdentifier nfi = new NamedFieldIdentifier("Static field \"" +
128 field.getID().getName() +
129 "\" in class \"" +
130 ik.getName().asString() + "\"");
131 LivenessPathElement lp = new LivenessPathElement(null, nfi);
132 rp.put(lp, next);
133 try {
134 markAndTraverse(next);
135 } catch (AddressException e) {
136 System.err.print("RevPtrs analysis: WARNING: AddressException at 0x" +
137 Long.toHexString(e.getAddress()) +
138 " while traversing static fields of InstanceKlass ");
|