hotspot/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java
author farvidsson
Wed, 16 Oct 2013 09:20:23 +0200
changeset 21065 b8281f54308b
parent 19979 ebe1dbb6e1aa
child 22234 da823d78ad65
permissions -rw-r--r--
8025638: jmap returns 0 instead of 1 when it fails. Summary: Re-factored some code handling return values and fails/errors during tool execution. Reviewed-by: sla, kevinw Contributed-by: fredrik.arvidsson@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
11577
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
     2
 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1217
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1217
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1217
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
package sun.jvm.hotspot.tools;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import sun.jvm.hotspot.gc_interface.*;
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
    29
import sun.jvm.hotspot.gc_implementation.g1.*;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.gc_implementation.parallelScavenge.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.gc_implementation.shared.*;
18481
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 15811
diff changeset
    32
import sun.jvm.hotspot.debugger.JVMDebugger;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import sun.jvm.hotspot.memory.*;
10985
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
    34
import sun.jvm.hotspot.oops.*;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
public class HeapSummary extends Tool {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
18481
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 15811
diff changeset
    39
   public HeapSummary() {
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 15811
diff changeset
    40
      super();
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 15811
diff changeset
    41
   }
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 15811
diff changeset
    42
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 15811
diff changeset
    43
   public HeapSummary(JVMDebugger d) {
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 15811
diff changeset
    44
      super(d);
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 15811
diff changeset
    45
   }
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 15811
diff changeset
    46
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
   public static void main(String[] args) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
      HeapSummary hs = new HeapSummary();
21065
b8281f54308b 8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents: 19979
diff changeset
    49
      hs.execute(args);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
   public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
      CollectedHeap heap = VM.getVM().getUniverse().heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
      VM.Flag[] flags = VM.getVM().getCommandLineFlags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      Map flagMap = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
      if (flags == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
         System.out.println("WARNING: command line flags are not available");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
         for (int f = 0; f < flags.length; f++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
            flagMap.put(flags[f].getName(), flags[f]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      System.out.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      printGCAlgorithm(flagMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      System.out.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      System.out.println("Heap Configuration:");
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 18481
diff changeset
    68
      printValue("MinHeapFreeRatio         = ", getFlagValue("MinHeapFreeRatio", flagMap));
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 18481
diff changeset
    69
      printValue("MaxHeapFreeRatio         = ", getFlagValue("MaxHeapFreeRatio", flagMap));
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 18481
diff changeset
    70
      printValMB("MaxHeapSize              = ", getFlagValue("MaxHeapSize", flagMap));
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 18481
diff changeset
    71
      printValMB("NewSize                  = ", getFlagValue("NewSize", flagMap));
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 18481
diff changeset
    72
      printValMB("MaxNewSize               = ", getFlagValue("MaxNewSize", flagMap));
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 18481
diff changeset
    73
      printValMB("OldSize                  = ", getFlagValue("OldSize", flagMap));
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 18481
diff changeset
    74
      printValue("NewRatio                 = ", getFlagValue("NewRatio", flagMap));
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 18481
diff changeset
    75
      printValue("SurvivorRatio            = ", getFlagValue("SurvivorRatio", flagMap));
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 18481
diff changeset
    76
      printValMB("MetaspaceSize            = ", getFlagValue("MetaspaceSize", flagMap));
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 18481
diff changeset
    77
      printValMB("CompressedClassSpaceSize = ", getFlagValue("CompressedClassSpaceSize", flagMap));
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 18481
diff changeset
    78
      printValMB("MaxMetaspaceSize         = ", getFlagValue("MaxMetaspaceSize", flagMap));
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 18481
diff changeset
    79
      printValMB("G1HeapRegionSize         = ", HeapRegion.grainBytes());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
      System.out.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
      System.out.println("Heap Usage:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
    84
      if (heap instanceof SharedHeap) {
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
    85
         SharedHeap sharedHeap = (SharedHeap) heap;
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
    86
         if (sharedHeap instanceof GenCollectedHeap) {
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
    87
            GenCollectedHeap genHeap = (GenCollectedHeap) sharedHeap;
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
    88
            for (int n = 0; n < genHeap.nGens(); n++) {
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
    89
               Generation gen = genHeap.getGen(n);
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
    90
               if (gen instanceof sun.jvm.hotspot.memory.DefNewGeneration) {
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
    91
                  System.out.println("New Generation (Eden + 1 Survivor Space):");
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
    92
                  printGen(gen);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
    94
                  ContiguousSpace eden = ((DefNewGeneration)gen).eden();
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
    95
                  System.out.println("Eden Space:");
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
    96
                  printSpace(eden);
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
    97
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
    98
                  ContiguousSpace from = ((DefNewGeneration)gen).from();
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
    99
                  System.out.println("From Space:");
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   100
                  printSpace(from);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   102
                  ContiguousSpace to = ((DefNewGeneration)gen).to();
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   103
                  System.out.println("To Space:");
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   104
                  printSpace(to);
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   105
               } else {
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   106
                  System.out.println(gen.name() + ":");
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   107
                  printGen(gen);
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   108
               }
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   109
            }
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   110
         } else if (sharedHeap instanceof G1CollectedHeap) {
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   111
             G1CollectedHeap g1h = (G1CollectedHeap) sharedHeap;
10675
8b887b2cb116 7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents: 10663
diff changeset
   112
             G1MonitoringSupport g1mm = g1h.g1mm();
11577
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
   113
             long edenRegionNum = g1mm.edenRegionNum();
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
   114
             long survivorRegionNum = g1mm.survivorRegionNum();
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
   115
             HeapRegionSetBase oldSet = g1h.oldSet();
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
   116
             HeapRegionSetBase humongousSet = g1h.humongousSet();
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
   117
             long oldRegionNum = oldSet.regionNum() + humongousSet.regionNum();
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
   118
             printG1Space("G1 Heap:", g1h.n_regions(),
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
   119
                          g1h.used(), g1h.capacity());
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
   120
             System.out.println("G1 Young Generation:");
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
   121
             printG1Space("Eden Space:", edenRegionNum,
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
   122
                          g1mm.edenUsed(), g1mm.edenCommitted());
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
   123
             printG1Space("Survivor Space:", survivorRegionNum,
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
   124
                          g1mm.survivorUsed(), g1mm.survivorCommitted());
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
   125
             printG1Space("G1 Old Generation:", oldRegionNum,
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
   126
                          g1mm.oldUsed(), g1mm.oldCommitted());
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   127
         } else {
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   128
             throw new RuntimeException("unknown SharedHeap type : " + heap.getClass());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      } else if (heap instanceof ParallelScavengeHeap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
         ParallelScavengeHeap psh = (ParallelScavengeHeap) heap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
         PSYoungGen youngGen = psh.youngGen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
         printPSYoungGen(youngGen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
         PSOldGen oldGen = psh.oldGen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
         long oldFree = oldGen.capacity() - oldGen.used();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
         System.out.println("PS Old Generation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
         printValMB("capacity = ", oldGen.capacity());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
         printValMB("used     = ", oldGen.used());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
         printValMB("free     = ", oldFree);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
         System.out.println(alignment + (double)oldGen.used() * 100.0 / oldGen.capacity() + "% used");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      } else {
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   143
         throw new RuntimeException("unknown CollectedHeap type : " + heap.getClass());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      }
10985
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   145
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   146
      System.out.println();
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   147
      printInternStringStatistics();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
   // Helper methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
   private void printGCAlgorithm(Map flagMap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
       // print about new generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
       long l = getFlagValue("UseParNewGC", flagMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
       if (l == 1L) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
          System.out.println("using parallel threads in the new generation.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
       l = getFlagValue("UseTLAB", flagMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
       if (l == 1L) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
          System.out.println("using thread-local object allocation.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
       l = getFlagValue("UseConcMarkSweepGC", flagMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
       if (l == 1L) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
          System.out.println("Concurrent Mark-Sweep GC");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
          return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
       l = getFlagValue("UseParallelGC", flagMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
       if (l == 1L) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
          System.out.print("Parallel GC ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
          l = getFlagValue("ParallelGCThreads", flagMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
          System.out.println("with " + l + " thread(s)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
          return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   178
       l = getFlagValue("UseG1GC", flagMap);
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   179
       if (l == 1L) {
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   180
           System.out.print("Garbage-First (G1) GC ");
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   181
           l = getFlagValue("ParallelGCThreads", flagMap);
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   182
           System.out.println("with " + l + " thread(s)");
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   183
           return;
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   184
       }
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
   185
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
       System.out.println("Mark Sweep Compact GC");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
   private void printPSYoungGen(PSYoungGen youngGen) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
      System.out.println("PS Young Generation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      MutableSpace eden = youngGen.edenSpace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      System.out.println("Eden Space:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
      printMutableSpace(eden);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
      MutableSpace from = youngGen.fromSpace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
      System.out.println("From Space:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
      printMutableSpace(from);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
      MutableSpace to = youngGen.toSpace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
      System.out.println("To Space:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      printMutableSpace(to);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
   private void printMutableSpace(MutableSpace space) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
      printValMB("capacity = ", space.capacity());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
      printValMB("used     = ", space.used());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
      long free = space.capacity() - space.used();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
      printValMB("free     = ", free);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
      System.out.println(alignment + (double)space.used() * 100.0 / space.capacity() + "% used");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
   private static String alignment = "   ";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
   private void printGen(Generation gen) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
      printValMB("capacity = ", gen.capacity());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
      printValMB("used     = ", gen.used());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      printValMB("free     = ", gen.free());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      System.out.println(alignment + (double)gen.used() * 100.0 / gen.capacity() + "% used");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
   private void printSpace(ContiguousSpace space) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
      printValMB("capacity = ", space.capacity());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      printValMB("used     = ", space.used());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      printValMB("free     = ", space.free());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
      System.out.println(alignment +  (double)space.used() * 100.0 / space.capacity() + "% used");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
11577
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
   226
   private void printG1Space(String spaceName, long regionNum,
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
   227
                             long used, long capacity) {
10675
8b887b2cb116 7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents: 10663
diff changeset
   228
      long free = capacity - used;
8b887b2cb116 7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents: 10663
diff changeset
   229
      System.out.println(spaceName);
11577
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10985
diff changeset
   230
      printValue("regions  = ", regionNum);
10675
8b887b2cb116 7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents: 10663
diff changeset
   231
      printValMB("capacity = ", capacity);
8b887b2cb116 7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents: 10663
diff changeset
   232
      printValMB("used     = ", used);
8b887b2cb116 7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents: 10663
diff changeset
   233
      printValMB("free     = ", free);
8b887b2cb116 7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents: 10663
diff changeset
   234
      double occPerc = (capacity > 0) ? (double) used * 100.0 / capacity : 0.0;
8b887b2cb116 7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents: 10663
diff changeset
   235
      System.out.println(alignment + occPerc + "% used");
8b887b2cb116 7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents: 10663
diff changeset
   236
   }
8b887b2cb116 7097048: G1: extend the G1 SA changes to print per-heap space information
tonyp
parents: 10663
diff changeset
   237
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
   private static final double FACTOR = 1024*1024;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
   private void printValMB(String title, long value) {
989
04e4dadeec8a 6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents: 1
diff changeset
   240
      if (value < 0) {
04e4dadeec8a 6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents: 1
diff changeset
   241
        System.out.println(alignment + title +   (value >>> 20)  + " MB");
04e4dadeec8a 6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents: 1
diff changeset
   242
      } else {
04e4dadeec8a 6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents: 1
diff changeset
   243
        double mb = value/FACTOR;
04e4dadeec8a 6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents: 1
diff changeset
   244
        System.out.println(alignment + title + value + " (" + mb + "MB)");
04e4dadeec8a 6718125: SA: jmap prints negative size for MaxNewHeap.
swamyv
parents: 1
diff changeset
   245
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
   private void printValue(String title, long value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      System.out.println(alignment + title + value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
   private long getFlagValue(String name, Map flagMap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      VM.Flag f = (VM.Flag) flagMap.get(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
      if (f != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
         if (f.isBool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
            return f.getBool()? 1L : 0L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
         } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
            return Long.parseLong(f.getValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
         return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
   }
10985
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   264
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   265
   private void printInternStringStatistics() {
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   266
      class StringStat implements StringTable.StringVisitor {
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   267
         private int count;
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   268
         private long size;
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   269
         private OopField stringValueField;
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   270
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   271
         StringStat() {
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   272
            VM vm = VM.getVM();
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   273
            SystemDictionary sysDict = vm.getSystemDictionary();
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   274
            InstanceKlass strKlass = sysDict.getStringKlass();
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   275
            // String has a field named 'value' of type 'char[]'.
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   276
            stringValueField = (OopField) strKlass.findField("value", "[C");
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   277
         }
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   278
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   279
         private long stringSize(Instance instance) {
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   280
            // We include String content in size calculation.
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   281
            return instance.getObjectSize() +
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   282
                   stringValueField.getValue(instance).getObjectSize();
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   283
         }
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   284
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   285
         public void visit(Instance str) {
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   286
            count++;
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   287
            size += stringSize(str);
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   288
         }
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   289
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   290
         public void print() {
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   291
            System.out.println(count +
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   292
                  " interned Strings occupying " + size + " bytes.");
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   293
         }
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   294
      }
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   295
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   296
      StringStat stat = new StringStat();
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   297
      StringTable strTable = VM.getVM().getStringTable();
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   298
      strTable.stringsDo(stat);
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   299
      stat.print();
f529e2356036 7108242: jinfo -permstat shouldn't report interned strings as part of perm
never
parents: 10675
diff changeset
   300
   }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
}