Tue, 28 Jul 2009 12:12:40 -0700
6862919: Update copyright year
Summary: Update copyright for files that have been modified in 2009, up to 07/09
Reviewed-by: tbell, ohair
duke@435 | 1 | /* |
xdono@1279 | 2 | * Copyright 2002-2009 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | package sun.jvm.hotspot.tools.jcore; |
duke@435 | 26 | |
duke@435 | 27 | import java.io.*; |
duke@435 | 28 | import sun.jvm.hotspot.memory.*; |
duke@435 | 29 | import sun.jvm.hotspot.oops.*; |
duke@435 | 30 | import sun.jvm.hotspot.debugger.*; |
duke@435 | 31 | import sun.jvm.hotspot.runtime.*; |
duke@435 | 32 | import sun.jvm.hotspot.tools.*; |
duke@435 | 33 | |
duke@435 | 34 | public class ClassDump extends Tool { |
duke@435 | 35 | private ClassFilter classFilter; |
duke@435 | 36 | private String outputDirectory; |
duke@435 | 37 | |
duke@435 | 38 | public void run() { |
duke@435 | 39 | // Ready to go with the database... |
duke@435 | 40 | try { |
duke@435 | 41 | |
duke@435 | 42 | // load class filters |
duke@435 | 43 | |
duke@435 | 44 | String filterClassName = System.getProperty("sun.jvm.hotspot.tools.jcore.filter"); |
duke@435 | 45 | if (filterClassName != null) { |
duke@435 | 46 | try { |
duke@435 | 47 | Class filterClass = Class.forName(filterClassName); |
duke@435 | 48 | classFilter = (ClassFilter) filterClass.newInstance(); |
duke@435 | 49 | } catch(Exception exp) { |
duke@435 | 50 | System.err.println("Warning: Can not create class filter!"); |
duke@435 | 51 | } |
duke@435 | 52 | } |
duke@435 | 53 | |
duke@435 | 54 | outputDirectory = System.getProperty("sun.jvm.hotspot.tools.jcore.outputDir"); |
duke@435 | 55 | if (outputDirectory == null) |
duke@435 | 56 | outputDirectory = "."; |
duke@435 | 57 | |
duke@435 | 58 | // walk through the system dictionary |
duke@435 | 59 | SystemDictionary dict = VM.getVM().getSystemDictionary(); |
duke@435 | 60 | dict.classesDo(new SystemDictionary.ClassVisitor() { |
duke@435 | 61 | public void visit(Klass k) { |
never@1140 | 62 | if (k instanceof InstanceKlass) { |
never@1140 | 63 | try { |
never@1140 | 64 | dumpKlass((InstanceKlass) k); |
never@1140 | 65 | } catch (Exception e) { |
never@1140 | 66 | System.out.println(k.getName().asString()); |
never@1140 | 67 | e.printStackTrace(); |
never@1140 | 68 | } |
never@1140 | 69 | } |
duke@435 | 70 | } |
duke@435 | 71 | }); |
duke@435 | 72 | } |
duke@435 | 73 | catch (AddressException e) { |
duke@435 | 74 | System.err.println("Error accessing address 0x" |
duke@435 | 75 | + Long.toHexString(e.getAddress())); |
duke@435 | 76 | e.printStackTrace(); |
duke@435 | 77 | } |
duke@435 | 78 | } |
duke@435 | 79 | |
duke@435 | 80 | public String getName() { |
duke@435 | 81 | return "jcore"; |
duke@435 | 82 | } |
duke@435 | 83 | |
duke@435 | 84 | private void dumpKlass(InstanceKlass kls) { |
duke@435 | 85 | if (classFilter != null && ! classFilter.canInclude(kls) ) { |
duke@435 | 86 | return; |
duke@435 | 87 | } |
duke@435 | 88 | |
duke@435 | 89 | String klassName = kls.getName().asString(); |
duke@435 | 90 | klassName = klassName.replace('/', File.separatorChar); |
duke@435 | 91 | int index = klassName.lastIndexOf(File.separatorChar); |
duke@435 | 92 | File dir = null; |
duke@435 | 93 | if (index != -1) { |
duke@435 | 94 | String dirName = klassName.substring(0, index); |
duke@435 | 95 | dir = new File(outputDirectory, dirName); |
duke@435 | 96 | } else { |
duke@435 | 97 | dir = new File(outputDirectory); |
duke@435 | 98 | } |
duke@435 | 99 | |
duke@435 | 100 | dir.mkdirs(); |
duke@435 | 101 | File f = new File(dir, klassName.substring(klassName.lastIndexOf(File.separatorChar) + 1) |
duke@435 | 102 | + ".class"); |
duke@435 | 103 | try { |
duke@435 | 104 | f.createNewFile(); |
duke@435 | 105 | OutputStream os = new BufferedOutputStream(new FileOutputStream(f)); |
duke@435 | 106 | try { |
duke@435 | 107 | ClassWriter cw = new ClassWriter(kls, os); |
duke@435 | 108 | cw.write(); |
duke@435 | 109 | } finally { |
duke@435 | 110 | os.close(); |
duke@435 | 111 | } |
duke@435 | 112 | } catch(IOException exp) { |
duke@435 | 113 | exp.printStackTrace(); |
duke@435 | 114 | } |
duke@435 | 115 | } |
duke@435 | 116 | |
duke@435 | 117 | public static void main(String[] args) { |
duke@435 | 118 | ClassDump cd = new ClassDump(); |
duke@435 | 119 | cd.start(args); |
duke@435 | 120 | cd.stop(); |
duke@435 | 121 | } |
duke@435 | 122 | } |