< prev index next >

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

Print this page




  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;
  26 
  27 import java.util.*;
  28 import sun.jvm.hotspot.gc.epsilon.*;
  29 import sun.jvm.hotspot.gc.g1.*;
  30 import sun.jvm.hotspot.gc.parallel.*;
  31 import sun.jvm.hotspot.gc.serial.*;

  32 import sun.jvm.hotspot.gc.shared.*;
  33 import sun.jvm.hotspot.gc.z.*;
  34 import sun.jvm.hotspot.debugger.JVMDebugger;
  35 import sun.jvm.hotspot.memory.*;
  36 import sun.jvm.hotspot.oops.*;
  37 import sun.jvm.hotspot.runtime.*;
  38 
  39 public class HeapSummary extends Tool {
  40 
  41    public HeapSummary() {
  42       super();
  43    }
  44 
  45    public HeapSummary(JVMDebugger d) {
  46       super(d);
  47    }
  48 
  49    public static void main(String[] args) {
  50       HeapSummary hs = new HeapSummary();
  51       hs.execute(args);


  66          for (int f = 0; f < flags.length; f++) {
  67             flagMap.put(flags[f].getName(), flags[f]);
  68          }
  69       }
  70 
  71       System.out.println();
  72       printGCAlgorithm(flagMap);
  73       System.out.println();
  74       System.out.println("Heap Configuration:");
  75       printValue("MinHeapFreeRatio         = ", getFlagValue("MinHeapFreeRatio", flagMap));
  76       printValue("MaxHeapFreeRatio         = ", getFlagValue("MaxHeapFreeRatio", flagMap));
  77       printValMB("MaxHeapSize              = ", getFlagValue("MaxHeapSize", flagMap));
  78       printValMB("NewSize                  = ", getFlagValue("NewSize", flagMap));
  79       printValMB("MaxNewSize               = ", getFlagValue("MaxNewSize", flagMap));
  80       printValMB("OldSize                  = ", getFlagValue("OldSize", flagMap));
  81       printValue("NewRatio                 = ", getFlagValue("NewRatio", flagMap));
  82       printValue("SurvivorRatio            = ", getFlagValue("SurvivorRatio", flagMap));
  83       printValMB("MetaspaceSize            = ", getFlagValue("MetaspaceSize", flagMap));
  84       printValMB("CompressedClassSpaceSize = ", getFlagValue("CompressedClassSpaceSize", flagMap));
  85       printValMB("MaxMetaspaceSize         = ", getFlagValue("MaxMetaspaceSize", flagMap));
  86       printValMB("G1HeapRegionSize         = ", HeapRegion.grainBytes());




  87 
  88       System.out.println();
  89       System.out.println("Heap Usage:");
  90 
  91       if (heap instanceof GenCollectedHeap) {
  92          GenCollectedHeap genHeap = (GenCollectedHeap) heap;
  93          for (int n = 0; n < genHeap.nGens(); n++) {
  94             Generation gen = genHeap.getGen(n);
  95             if (gen instanceof DefNewGeneration) {
  96                System.out.println("New Generation (Eden + 1 Survivor Space):");
  97                printGen(gen);
  98 
  99                ContiguousSpace eden = ((DefNewGeneration)gen).eden();
 100                System.out.println("Eden Space:");
 101                printSpace(eden);
 102 
 103                ContiguousSpace from = ((DefNewGeneration)gen).from();
 104                System.out.println("From Space:");
 105                printSpace(from);
 106 


 109                printSpace(to);
 110             } else {
 111                System.out.println(gen.name() + ":");
 112                printGen(gen);
 113             }
 114          }
 115       } else if (heap instanceof G1CollectedHeap) {
 116           printG1HeapSummary((G1CollectedHeap)heap);
 117       } else if (heap instanceof ParallelScavengeHeap) {
 118          ParallelScavengeHeap psh = (ParallelScavengeHeap) heap;
 119          PSYoungGen youngGen = psh.youngGen();
 120          printPSYoungGen(youngGen);
 121 
 122          PSOldGen oldGen = psh.oldGen();
 123          long oldFree = oldGen.capacity() - oldGen.used();
 124          System.out.println("PS Old Generation");
 125          printValMB("capacity = ", oldGen.capacity());
 126          printValMB("used     = ", oldGen.used());
 127          printValMB("free     = ", oldFree);
 128          System.out.println(alignment + (double)oldGen.used() * 100.0 / oldGen.capacity() + "% used");








 129       } else if (heap instanceof EpsilonHeap) {
 130          EpsilonHeap eh = (EpsilonHeap) heap;
 131          printSpace(eh.space());
 132       } else if (heap instanceof ZCollectedHeap) {
 133          ZCollectedHeap zheap = (ZCollectedHeap) heap;
 134          zheap.printOn(System.out);
 135       } else {
 136          throw new RuntimeException("unknown CollectedHeap type : " + heap.getClass());
 137       }
 138 
 139       System.out.println();
 140    }
 141 
 142    // Helper methods
 143 
 144    private void printGCAlgorithm(Map flagMap) {
 145        long l = getFlagValue("UseTLAB", flagMap);
 146        if (l == 1L) {
 147           System.out.println("using thread-local object allocation.");
 148        }


 163 
 164        l = getFlagValue("UseG1GC", flagMap);
 165        if (l == 1L) {
 166            System.out.print("Garbage-First (G1) GC ");
 167            l = getFlagValue("ParallelGCThreads", flagMap);
 168            System.out.println("with " + l + " thread(s)");
 169            return;
 170        }
 171 
 172        l = getFlagValue("UseEpsilonGC", flagMap);
 173        if (l == 1L) {
 174            System.out.println("Epsilon (no-op) GC");
 175            return;
 176        }
 177 
 178        l = getFlagValue("UseZGC", flagMap);
 179        if (l == 1L) {
 180            System.out.print("ZGC ");
 181            l = getFlagValue("ParallelGCThreads", flagMap);
 182            System.out.println("with " + l + " thread(s)");






 183            return;
 184        }
 185 
 186        System.out.println("Mark Sweep Compact GC");
 187    }
 188 
 189    private void printPSYoungGen(PSYoungGen youngGen) {
 190       System.out.println("PS Young Generation");
 191       MutableSpace eden = youngGen.edenSpace();
 192       System.out.println("Eden Space:");
 193       printMutableSpace(eden);
 194       MutableSpace from = youngGen.fromSpace();
 195       System.out.println("From Space:");
 196       printMutableSpace(from);
 197       MutableSpace to = youngGen.toSpace();
 198       System.out.println("To Space:");
 199       printMutableSpace(to);
 200    }
 201 
 202    private void printMutableSpace(MutableSpace space) {




  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;
  26 
  27 import java.util.*;
  28 import sun.jvm.hotspot.gc.epsilon.*;
  29 import sun.jvm.hotspot.gc.g1.*;
  30 import sun.jvm.hotspot.gc.parallel.*;
  31 import sun.jvm.hotspot.gc.serial.*;
  32 import sun.jvm.hotspot.gc.shenandoah.*;
  33 import sun.jvm.hotspot.gc.shared.*;
  34 import sun.jvm.hotspot.gc.z.*;
  35 import sun.jvm.hotspot.debugger.JVMDebugger;
  36 import sun.jvm.hotspot.memory.*;
  37 import sun.jvm.hotspot.oops.*;
  38 import sun.jvm.hotspot.runtime.*;
  39 
  40 public class HeapSummary extends Tool {
  41 
  42    public HeapSummary() {
  43       super();
  44    }
  45 
  46    public HeapSummary(JVMDebugger d) {
  47       super(d);
  48    }
  49 
  50    public static void main(String[] args) {
  51       HeapSummary hs = new HeapSummary();
  52       hs.execute(args);


  67          for (int f = 0; f < flags.length; f++) {
  68             flagMap.put(flags[f].getName(), flags[f]);
  69          }
  70       }
  71 
  72       System.out.println();
  73       printGCAlgorithm(flagMap);
  74       System.out.println();
  75       System.out.println("Heap Configuration:");
  76       printValue("MinHeapFreeRatio         = ", getFlagValue("MinHeapFreeRatio", flagMap));
  77       printValue("MaxHeapFreeRatio         = ", getFlagValue("MaxHeapFreeRatio", flagMap));
  78       printValMB("MaxHeapSize              = ", getFlagValue("MaxHeapSize", flagMap));
  79       printValMB("NewSize                  = ", getFlagValue("NewSize", flagMap));
  80       printValMB("MaxNewSize               = ", getFlagValue("MaxNewSize", flagMap));
  81       printValMB("OldSize                  = ", getFlagValue("OldSize", flagMap));
  82       printValue("NewRatio                 = ", getFlagValue("NewRatio", flagMap));
  83       printValue("SurvivorRatio            = ", getFlagValue("SurvivorRatio", flagMap));
  84       printValMB("MetaspaceSize            = ", getFlagValue("MetaspaceSize", flagMap));
  85       printValMB("CompressedClassSpaceSize = ", getFlagValue("CompressedClassSpaceSize", flagMap));
  86       printValMB("MaxMetaspaceSize         = ", getFlagValue("MaxMetaspaceSize", flagMap));
  87       if (heap instanceof ShenandoahHeap) {
  88          printValMB("ShenandoahRegionSize     = ", ShenandoahHeapRegion.regionSizeBytes());
  89       } else {
  90          printValMB("G1HeapRegionSize         = ", HeapRegion.grainBytes());
  91       }
  92 
  93       System.out.println();
  94       System.out.println("Heap Usage:");
  95 
  96       if (heap instanceof GenCollectedHeap) {
  97          GenCollectedHeap genHeap = (GenCollectedHeap) heap;
  98          for (int n = 0; n < genHeap.nGens(); n++) {
  99             Generation gen = genHeap.getGen(n);
 100             if (gen instanceof DefNewGeneration) {
 101                System.out.println("New Generation (Eden + 1 Survivor Space):");
 102                printGen(gen);
 103 
 104                ContiguousSpace eden = ((DefNewGeneration)gen).eden();
 105                System.out.println("Eden Space:");
 106                printSpace(eden);
 107 
 108                ContiguousSpace from = ((DefNewGeneration)gen).from();
 109                System.out.println("From Space:");
 110                printSpace(from);
 111 


 114                printSpace(to);
 115             } else {
 116                System.out.println(gen.name() + ":");
 117                printGen(gen);
 118             }
 119          }
 120       } else if (heap instanceof G1CollectedHeap) {
 121           printG1HeapSummary((G1CollectedHeap)heap);
 122       } else if (heap instanceof ParallelScavengeHeap) {
 123          ParallelScavengeHeap psh = (ParallelScavengeHeap) heap;
 124          PSYoungGen youngGen = psh.youngGen();
 125          printPSYoungGen(youngGen);
 126 
 127          PSOldGen oldGen = psh.oldGen();
 128          long oldFree = oldGen.capacity() - oldGen.used();
 129          System.out.println("PS Old Generation");
 130          printValMB("capacity = ", oldGen.capacity());
 131          printValMB("used     = ", oldGen.used());
 132          printValMB("free     = ", oldFree);
 133          System.out.println(alignment + (double)oldGen.used() * 100.0 / oldGen.capacity() + "% used");
 134       } else if (heap instanceof ShenandoahHeap) {
 135          ShenandoahHeap sh = (ShenandoahHeap) heap;
 136          long num_regions = sh.numOfRegions();
 137          System.out.println("Shenandoah Heap:");
 138          System.out.println("   regions   = " + num_regions);
 139          printValMB("capacity  = ", num_regions * ShenandoahHeapRegion.regionSizeBytes());
 140          printValMB("used      = ", sh.used());
 141          printValMB("committed = ", sh.committed());
 142       } else if (heap instanceof EpsilonHeap) {
 143          EpsilonHeap eh = (EpsilonHeap) heap;
 144          printSpace(eh.space());
 145       } else if (heap instanceof ZCollectedHeap) {
 146          ZCollectedHeap zheap = (ZCollectedHeap) heap;
 147          zheap.printOn(System.out);
 148       } else {
 149          throw new RuntimeException("unknown CollectedHeap type : " + heap.getClass());
 150       }
 151 
 152       System.out.println();
 153    }
 154 
 155    // Helper methods
 156 
 157    private void printGCAlgorithm(Map flagMap) {
 158        long l = getFlagValue("UseTLAB", flagMap);
 159        if (l == 1L) {
 160           System.out.println("using thread-local object allocation.");
 161        }


 176 
 177        l = getFlagValue("UseG1GC", flagMap);
 178        if (l == 1L) {
 179            System.out.print("Garbage-First (G1) GC ");
 180            l = getFlagValue("ParallelGCThreads", flagMap);
 181            System.out.println("with " + l + " thread(s)");
 182            return;
 183        }
 184 
 185        l = getFlagValue("UseEpsilonGC", flagMap);
 186        if (l == 1L) {
 187            System.out.println("Epsilon (no-op) GC");
 188            return;
 189        }
 190 
 191        l = getFlagValue("UseZGC", flagMap);
 192        if (l == 1L) {
 193            System.out.print("ZGC ");
 194            l = getFlagValue("ParallelGCThreads", flagMap);
 195            System.out.println("with " + l + " thread(s)");
 196            return;
 197        }
 198 
 199        l = getFlagValue("UseShenandoahGC", flagMap);
 200        if (l == 1L) {
 201            System.out.print("Shenandoah GC");
 202            return;
 203        }
 204 
 205        System.out.println("Mark Sweep Compact GC");
 206    }
 207 
 208    private void printPSYoungGen(PSYoungGen youngGen) {
 209       System.out.println("PS Young Generation");
 210       MutableSpace eden = youngGen.edenSpace();
 211       System.out.println("Eden Space:");
 212       printMutableSpace(eden);
 213       MutableSpace from = youngGen.fromSpace();
 214       System.out.println("From Space:");
 215       printMutableSpace(from);
 216       MutableSpace to = youngGen.toSpace();
 217       System.out.println("To Space:");
 218       printMutableSpace(to);
 219    }
 220 
 221    private void printMutableSpace(MutableSpace space) {


< prev index next >