src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/g1/HeapRegion.java
author jgeorge
Tue, 20 Mar 2018 11:24:32 +0530
changeset 49463 ccb003941743
parent 47619 74f5b6c267e3
child 53814 eff915f3d3f2
permissions -rw-r--r--
8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC Summary: Provide an improved heap summary for G1GC with parameters like 'capacity', 'used', 'free', etc with the 'universe' command, and introduce a new command 'g1regiondetails' to display the individual region details. Reviewed-by: sjohanss, minqi
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
     1
/*
49463
ccb003941743 8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents: 47619
diff changeset
     2
 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
     4
 *
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
     8
 *
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    13
 * accompanied this code).
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    14
 *
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    18
 *
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    21
 * questions.
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    22
 *
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    23
 */
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    24
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25481
diff changeset
    25
package sun.jvm.hotspot.gc.g1;
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    26
49463
ccb003941743 8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents: 47619
diff changeset
    27
import java.io.PrintStream;
25481
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    28
import java.util.ArrayList;
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    29
import java.util.List;
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    30
import java.util.Observable;
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    31
import java.util.Observer;
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    32
import sun.jvm.hotspot.debugger.Address;
47602
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
    33
import sun.jvm.hotspot.debugger.OopHandle;
30769
df60209aac9d 8080581: Align SA with new GC directory structure
pliden
parents: 30764
diff changeset
    34
import sun.jvm.hotspot.gc.shared.CompactibleSpace;
25481
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    35
import sun.jvm.hotspot.memory.MemRegion;
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    36
import sun.jvm.hotspot.runtime.VM;
47602
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
    37
import sun.jvm.hotspot.runtime.VMObjectFactory;
25481
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    38
import sun.jvm.hotspot.types.AddressField;
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    39
import sun.jvm.hotspot.types.CIntegerField;
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    40
import sun.jvm.hotspot.types.Type;
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    41
import sun.jvm.hotspot.types.TypeDataBase;
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    42
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    43
// Mirror class for HeapRegion. Currently we don't actually include
25481
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    44
// any of its fields but only iterate over it.
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    45
25481
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    46
public class HeapRegion extends CompactibleSpace {
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    47
    // static int GrainBytes;
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    48
    static private CIntegerField grainBytesField;
25481
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    49
    static private AddressField topField;
47602
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
    50
    private static long typeFieldOffset;
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
    51
    private static long pointerSize;
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
    52
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
    53
    private HeapRegionType type;
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    54
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    55
    static {
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    56
        VM.registerVMInitializedObserver(new Observer() {
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    57
                public void update(Observable o, Object data) {
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    58
                    initialize(VM.getVM().getTypeDataBase());
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    59
                }
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    60
            });
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    61
    }
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    62
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    63
    static private synchronized void initialize(TypeDataBase db) {
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    64
        Type type = db.lookupType("HeapRegion");
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    65
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    66
        grainBytesField = type.getCIntegerField("GrainBytes");
25481
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    67
        topField = type.getAddressField("_top");
47602
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
    68
        typeFieldOffset = type.getField("_type").getOffset();
25481
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    69
47602
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
    70
        pointerSize = db.lookupType("HeapRegion*").getSize();
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    71
    }
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    72
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    73
    static public long grainBytes() {
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    74
        return grainBytesField.getValue();
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    75
    }
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    76
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    77
    public HeapRegion(Address addr) {
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    78
        super(addr);
47619
74f5b6c267e3 8189069: regression after push of 8187403: "AssertionFailure: addr should be OopHandle"
ysuenaga
parents: 47602
diff changeset
    79
        Address typeAddr = (addr instanceof OopHandle) ? addr.addOffsetToAsOopHandle(typeFieldOffset)
74f5b6c267e3 8189069: regression after push of 8187403: "AssertionFailure: addr should be OopHandle"
ysuenaga
parents: 47602
diff changeset
    80
                                                       : addr.addOffsetTo(typeFieldOffset);
47602
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
    81
        type = (HeapRegionType)VMObjectFactory.newObject(HeapRegionType.class, typeAddr);
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
    82
    }
25481
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    83
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    84
    public Address top() {
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    85
        return topField.getValue(addr);
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    86
    }
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    87
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    88
    @Override
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    89
    public List getLiveRegions() {
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    90
        List res = new ArrayList();
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    91
        res.add(new MemRegion(bottom(), top()));
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    92
        return res;
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    93
    }
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    94
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    95
    @Override
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    96
    public long used() {
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    97
        return top().minus(bottom());
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    98
    }
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
    99
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
   100
    @Override
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
   101
    public long free() {
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
   102
        return end().minus(top());
1427aa24638c 8047818: G1 HeapRegions can no longer be ContiguousSpaces
mgerdin
parents: 10663
diff changeset
   103
    }
47602
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   104
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   105
    public boolean isFree() {
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   106
        return type.isFree();
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   107
    }
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   108
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   109
    public boolean isYoung() {
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   110
        return type.isYoung();
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   111
    }
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   112
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   113
    public boolean isHumongous() {
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   114
        return type.isHumongous();
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   115
    }
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   116
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   117
    public boolean isPinned() {
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   118
        return type.isPinned();
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   119
    }
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   120
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   121
    public boolean isOld() {
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   122
        return type.isOld();
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   123
    }
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   124
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   125
    public static long getPointerSize() {
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   126
        return pointerSize;
d4380ee1cbe9 8187403: [Unknown generation] is shown in Stack Memory on HSDB
ysuenaga
parents: 47216
diff changeset
   127
    }
49463
ccb003941743 8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents: 47619
diff changeset
   128
ccb003941743 8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents: 47619
diff changeset
   129
    public void printOn(PrintStream tty) {
ccb003941743 8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents: 47619
diff changeset
   130
        tty.print("Region: " + bottom() + "," + top() + "," + end());
ccb003941743 8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents: 47619
diff changeset
   131
        tty.println(":" + type.typeAnnotation());
ccb003941743 8175312: SA: clhsdb: Provide an improved heap summary for 'universe' for G1GC
jgeorge
parents: 47619
diff changeset
   132
    }
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents:
diff changeset
   133
}