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.tools.jcore;
26
27 import java.io.*;
28 import java.lang.reflect.Constructor;
29 import java.util.jar.JarOutputStream;
30 import java.util.jar.JarEntry;
31 import java.util.jar.Manifest;
32 import sun.jvm.hotspot.memory.*;
33 import sun.jvm.hotspot.oops.*;
34 import sun.jvm.hotspot.debugger.*;
35 import sun.jvm.hotspot.runtime.*;
36 import sun.jvm.hotspot.tools.*;
37
38 public class ClassDump extends Tool {
39 private ClassFilter classFilter;
40 private String outputDirectory;
41 private JarOutputStream jarStream;
42 private String pkgList;
43
44 public ClassDump() {
45 super();
46 }
47
48 public ClassDump(JVMDebugger d, String pkgList) {
49 super(d);
50 this.pkgList = pkgList;
51 }
83 try {
84 Class filterClass = Class.forName(filterClassName);
85 if (pkgList == null) {
86 classFilter = (ClassFilter) filterClass.newInstance();
87 } else {
88 Constructor con = filterClass.getConstructor(String.class);
89 classFilter = (ClassFilter) con.newInstance(pkgList);
90 }
91 } catch(Exception exp) {
92 System.err.println("Warning: Can not create class filter!");
93 }
94 }
95
96 // outputDirectory and jarStream are alternatives: setting one closes the other.
97 // If neither is set, use outputDirectory from the System property:
98 if (outputDirectory == null && jarStream == null) {
99 String dirName = System.getProperty("sun.jvm.hotspot.tools.jcore.outputDir", ".");
100 setOutputDirectory(dirName);
101 }
102
103 // walk through the system dictionary
104 SystemDictionary dict = VM.getVM().getSystemDictionary();
105 dict.classesDo(new SystemDictionary.ClassVisitor() {
106 public void visit(Klass k) {
107 if (k instanceof InstanceKlass) {
108 try {
109 dumpKlass((InstanceKlass) k);
110 } catch (Exception e) {
111 System.out.println(k.getName().asString());
112 e.printStackTrace();
113 }
114 }
115 }
116 });
117 }
118 catch (AddressException e) {
119 System.err.println("Error accessing address 0x"
120 + Long.toHexString(e.getAddress()));
121 e.printStackTrace();
122 }
123 if (jarStream != null) {
124 try {
125 jarStream.close();
|
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.tools.jcore;
26
27 import java.io.*;
28 import java.lang.reflect.Constructor;
29 import java.util.jar.JarOutputStream;
30 import java.util.jar.JarEntry;
31 import java.util.jar.Manifest;
32 import sun.jvm.hotspot.classfile.*;
33 import sun.jvm.hotspot.memory.*;
34 import sun.jvm.hotspot.oops.*;
35 import sun.jvm.hotspot.debugger.*;
36 import sun.jvm.hotspot.runtime.*;
37 import sun.jvm.hotspot.tools.*;
38
39 public class ClassDump extends Tool {
40 private ClassFilter classFilter;
41 private String outputDirectory;
42 private JarOutputStream jarStream;
43 private String pkgList;
44
45 public ClassDump() {
46 super();
47 }
48
49 public ClassDump(JVMDebugger d, String pkgList) {
50 super(d);
51 this.pkgList = pkgList;
52 }
84 try {
85 Class filterClass = Class.forName(filterClassName);
86 if (pkgList == null) {
87 classFilter = (ClassFilter) filterClass.newInstance();
88 } else {
89 Constructor con = filterClass.getConstructor(String.class);
90 classFilter = (ClassFilter) con.newInstance(pkgList);
91 }
92 } catch(Exception exp) {
93 System.err.println("Warning: Can not create class filter!");
94 }
95 }
96
97 // outputDirectory and jarStream are alternatives: setting one closes the other.
98 // If neither is set, use outputDirectory from the System property:
99 if (outputDirectory == null && jarStream == null) {
100 String dirName = System.getProperty("sun.jvm.hotspot.tools.jcore.outputDir", ".");
101 setOutputDirectory(dirName);
102 }
103
104 // walk through the loaded classes
105 ClassLoaderDataGraph cldg = VM.getVM().getClassLoaderDataGraph();
106 cldg.classesDo(new ClassLoaderDataGraph.ClassVisitor() {
107 public void visit(Klass k) {
108 if (k instanceof InstanceKlass) {
109 try {
110 dumpKlass((InstanceKlass) k);
111 } catch (Exception e) {
112 System.out.println(k.getName().asString());
113 e.printStackTrace();
114 }
115 }
116 }
117 });
118 }
119 catch (AddressException e) {
120 System.err.println("Error accessing address 0x"
121 + Long.toHexString(e.getAddress()));
122 e.printStackTrace();
123 }
124 if (jarStream != null) {
125 try {
126 jarStream.close();
|