< prev index next >

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/JMap.java

Print this page




  54     }
  55 
  56     protected void printFlagsUsage() {
  57         System.out.println("    <no option>\tto print same info as Solaris pmap");
  58         System.out.println("    -heap\tto print java heap summary");
  59         System.out.println("    -heap:format=b\tto dump java heap in hprof binary format");
  60         System.out.println("    -histo\tto print histogram of java object heap");
  61         System.out.println("    -clstats\tto print class loader statistics");
  62         System.out.println("    -finalizerinfo\tto print information on objects awaiting finalization");
  63         super.printFlagsUsage();
  64     }
  65 
  66     public static final int MODE_HEAP_SUMMARY = 0;
  67     public static final int MODE_HISTOGRAM = 1;
  68     public static final int MODE_CLSTATS = 2;
  69     public static final int MODE_PMAP = 3;
  70     public static final int MODE_HEAP_GRAPH_HPROF_BIN = 4;
  71     public static final int MODE_HEAP_GRAPH_GXL = 5;
  72     public static final int MODE_FINALIZERINFO = 6;
  73 


  74     public void run() {
  75         Tool tool = null;
  76         switch (mode) {
  77 
  78         case MODE_HEAP_SUMMARY:
  79             tool = new HeapSummary();
  80             break;
  81 
  82         case MODE_HISTOGRAM:
  83             tool = new ObjectHistogram();
  84             break;
  85 
  86         case MODE_CLSTATS:
  87             tool = new ClassLoaderStats();
  88             break;
  89 
  90         case MODE_PMAP:
  91             tool = new PMap();
  92             break;
  93 
  94         case MODE_HEAP_GRAPH_HPROF_BIN:
  95             writeHeapHprofBin();
  96             return;
  97 
  98         case MODE_HEAP_GRAPH_GXL:
  99             writeHeapGXL();
 100             return;
 101 
 102         case MODE_FINALIZERINFO:
 103             tool = new FinalizerInfo();
 104             break;
 105 
 106         default:
 107             usage();
 108             break;
 109        }
 110 
 111        tool.setAgent(getAgent());
 112        tool.setDebugeeType(getDebugeeType());
 113        tool.run();
 114     }
 115 
 116     public static void main(String[] args) {
 117         int mode = MODE_PMAP;
 118         if (args.length > 1 ) {
 119             String modeFlag = args[0];
 120             boolean copyArgs = true;
 121             if (modeFlag.equals("-heap")) {
 122                 mode = MODE_HEAP_SUMMARY;
 123             } else if (modeFlag.equals("-histo")) {
 124                 mode = MODE_HISTOGRAM;
 125             } else if (modeFlag.equals("-clstats")) {
 126                 mode = MODE_CLSTATS;
 127             } else if (modeFlag.equals("-finalizerinfo")) {
 128                 mode = MODE_FINALIZERINFO;
 129             } else {
 130                 int index = modeFlag.indexOf("-heap:format=");
 131                 if (index != -1) {
 132                     String format = modeFlag.substring(1 + modeFlag.indexOf('='));
 133                     if (format.equals("b")) {



 134                         mode = MODE_HEAP_GRAPH_HPROF_BIN;
 135                     } else if (format.equals("x")) {
 136                         mode = MODE_HEAP_GRAPH_GXL;
 137                     } else {
 138                         System.err.println("unknown heap format:" + format);
 139 
 140                         // Exit with error status
 141                         System.exit(1);













 142                     }
 143                 } else {
 144                     copyArgs = false;
 145                 }
 146             }
 147 
 148             if (copyArgs) {
 149                 String[] newArgs = new String[args.length - 1];
 150                 for (int i = 0; i < newArgs.length; i++) {
 151                     newArgs[i] = args[i + 1];
 152                 }
 153                 args = newArgs;
 154             }
 155         }
 156 
 157         JMap jmap = new JMap(mode);
 158         jmap.execute(args);
 159     }
 160 
 161     public boolean writeHeapHprofBin(String fileName) {




  54     }
  55 
  56     protected void printFlagsUsage() {
  57         System.out.println("    <no option>\tto print same info as Solaris pmap");
  58         System.out.println("    -heap\tto print java heap summary");
  59         System.out.println("    -heap:format=b\tto dump java heap in hprof binary format");
  60         System.out.println("    -histo\tto print histogram of java object heap");
  61         System.out.println("    -clstats\tto print class loader statistics");
  62         System.out.println("    -finalizerinfo\tto print information on objects awaiting finalization");
  63         super.printFlagsUsage();
  64     }
  65 
  66     public static final int MODE_HEAP_SUMMARY = 0;
  67     public static final int MODE_HISTOGRAM = 1;
  68     public static final int MODE_CLSTATS = 2;
  69     public static final int MODE_PMAP = 3;
  70     public static final int MODE_HEAP_GRAPH_HPROF_BIN = 4;
  71     public static final int MODE_HEAP_GRAPH_GXL = 5;
  72     public static final int MODE_FINALIZERINFO = 6;
  73 
  74     private static String dumpfile = "heap.bin";
  75 
  76     public void run() {
  77         Tool tool = null;
  78         switch (mode) {
  79 
  80         case MODE_HEAP_SUMMARY:
  81             tool = new HeapSummary();
  82             break;
  83 
  84         case MODE_HISTOGRAM:
  85             tool = new ObjectHistogram();
  86             break;
  87 
  88         case MODE_CLSTATS:
  89             tool = new ClassLoaderStats();
  90             break;
  91 
  92         case MODE_PMAP:
  93             tool = new PMap();
  94             break;
  95 
  96         case MODE_HEAP_GRAPH_HPROF_BIN:
  97             writeHeapHprofBin(dumpfile);
  98             return;
  99 
 100         case MODE_HEAP_GRAPH_GXL:
 101             writeHeapGXL(dumpfile);
 102             return;
 103 
 104         case MODE_FINALIZERINFO:
 105             tool = new FinalizerInfo();
 106             break;
 107 
 108         default:
 109             usage();
 110             break;
 111        }
 112 
 113        tool.setAgent(getAgent());
 114        tool.setDebugeeType(getDebugeeType());
 115        tool.run();
 116     }
 117 
 118     public static void main(String[] args) {
 119         int mode = MODE_PMAP;
 120         if (args.length > 1 ) {
 121             String modeFlag = args[0];
 122             boolean copyArgs = true;
 123             if (modeFlag.equals("-heap")) {
 124                 mode = MODE_HEAP_SUMMARY;
 125             } else if (modeFlag.equals("-histo")) {
 126                 mode = MODE_HISTOGRAM;
 127             } else if (modeFlag.equals("-clstats")) {
 128                 mode = MODE_CLSTATS;
 129             } else if (modeFlag.equals("-finalizerinfo")) {
 130                 mode = MODE_FINALIZERINFO;
 131             } else {
 132                 int index = modeFlag.indexOf("-heap:");
 133                 if (index != -1) {
 134                     String[] options = modeFlag.substring(6).split(",");
 135                     for (String option : options) {
 136                         String[] keyValue = option.split("=");
 137                         if (keyValue[0].equals("format")) {
 138                             if (keyValue[1].equals("b")) {
 139                                 mode = MODE_HEAP_GRAPH_HPROF_BIN;
 140                             } else if (keyValue[1].equals("x")) {
 141                                 mode = MODE_HEAP_GRAPH_GXL;
 142                             } else {
 143                                 System.err.println("unknown heap format:" + keyValue[0]);
 144 
 145                                 // Exit with error status
 146                                 System.exit(1);
 147                             }
 148                         } else if (keyValue[0].equals("file")) {
 149                             if ((keyValue[1] == null) || keyValue[1].equals("")) {
 150                                 System.err.println("File name must be set.");
 151                                 System.exit(1);
 152                             }
 153                             dumpfile = keyValue[1];
 154                         } else {
 155                             System.err.println("unknown option:" + keyValue[0]);
 156 
 157                             // Exit with error status
 158                             System.exit(1);
 159                         }
 160                     }
 161                 } else {
 162                     copyArgs = false;
 163                 }
 164             }
 165 
 166             if (copyArgs) {
 167                 String[] newArgs = new String[args.length - 1];
 168                 for (int i = 0; i < newArgs.length; i++) {
 169                     newArgs[i] = args[i + 1];
 170                 }
 171                 args = newArgs;
 172             }
 173         }
 174 
 175         JMap jmap = new JMap(mode);
 176         jmap.execute(args);
 177     }
 178 
 179     public boolean writeHeapHprofBin(String fileName) {


< prev index next >