src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/Universe.java
author rkennke
Thu, 19 Oct 2017 20:48:31 -0400
changeset 47663 3e78d37acdde
parent 47216 71c04702a3d5
child 47819 ee36a8e36561
permissions -rw-r--r--
8189373: jmap -heap exited with error code Summary: Add CMSHeap related bits to SA code Reviewed-by: dholmes, jgeorge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 39227
diff changeset
     2
 * Copyright (c) 2000, 2017, 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: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
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: 3261
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.memory;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.debugger.*;
47663
3e78d37acdde 8189373: jmap -heap exited with error code
rkennke
parents: 47216
diff changeset
    30
import sun.jvm.hotspot.gc.cms.CMSHeap;
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30159
diff changeset
    31
import sun.jvm.hotspot.gc.shared.*;
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30159
diff changeset
    32
import sun.jvm.hotspot.gc.g1.G1CollectedHeap;
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30159
diff changeset
    33
import sun.jvm.hotspot.gc.parallel.*;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
import sun.jvm.hotspot.oops.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
public class Universe {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  private static AddressField collectedHeapField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  private static VirtualConstructor heapConstructor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  private static sun.jvm.hotspot.types.OopField mainThreadGroupField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  private static sun.jvm.hotspot.types.OopField systemThreadGroupField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // single dimensional primitive array klasses
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    46
  private static sun.jvm.hotspot.types.AddressField boolArrayKlassField;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    47
  private static sun.jvm.hotspot.types.AddressField byteArrayKlassField;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    48
  private static sun.jvm.hotspot.types.AddressField charArrayKlassField;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    49
  private static sun.jvm.hotspot.types.AddressField intArrayKlassField;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    50
  private static sun.jvm.hotspot.types.AddressField shortArrayKlassField;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    51
  private static sun.jvm.hotspot.types.AddressField longArrayKlassField;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    52
  private static sun.jvm.hotspot.types.AddressField singleArrayKlassField;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    53
  private static sun.jvm.hotspot.types.AddressField doubleArrayKlassField;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
2254
f13dda645a4b 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 670
diff changeset
    55
  private static AddressField narrowOopBaseField;
f13dda645a4b 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 670
diff changeset
    56
  private static CIntegerField narrowOopShiftField;
13969
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13728
diff changeset
    57
  private static AddressField narrowKlassBaseField;
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13728
diff changeset
    58
  private static CIntegerField narrowKlassShiftField;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    59
25335
2557b9b45520 8046282: SA update
poonam
parents: 13969
diff changeset
    60
  public enum NARROW_OOP_MODE {
2557b9b45520 8046282: SA update
poonam
parents: 13969
diff changeset
    61
    UnscaledNarrowOop,
2557b9b45520 8046282: SA update
poonam
parents: 13969
diff changeset
    62
    ZeroBasedNarrowOop,
2557b9b45520 8046282: SA update
poonam
parents: 13969
diff changeset
    63
    HeapBasedNarrowOop
2557b9b45520 8046282: SA update
poonam
parents: 13969
diff changeset
    64
  }
2557b9b45520 8046282: SA update
poonam
parents: 13969
diff changeset
    65
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  private static synchronized void initialize(TypeDataBase db) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    Type type = db.lookupType("Universe");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    collectedHeapField = type.getAddressField("_collectedHeap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    heapConstructor = new VirtualConstructor(db);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    heapConstructor.addMapping("GenCollectedHeap", GenCollectedHeap.class);
47663
3e78d37acdde 8189373: jmap -heap exited with error code
rkennke
parents: 47216
diff changeset
    81
    heapConstructor.addMapping("CMSHeap", CMSHeap.class);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    heapConstructor.addMapping("ParallelScavengeHeap", ParallelScavengeHeap.class);
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 5547
diff changeset
    83
    heapConstructor.addMapping("G1CollectedHeap", G1CollectedHeap.class);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    mainThreadGroupField   = type.getOopField("_main_thread_group");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    systemThreadGroupField = type.getOopField("_system_thread_group");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    88
    boolArrayKlassField      = type.getAddressField("_boolArrayKlassObj");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    89
    byteArrayKlassField      = type.getAddressField("_byteArrayKlassObj");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    90
    charArrayKlassField      = type.getAddressField("_charArrayKlassObj");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    91
    intArrayKlassField       = type.getAddressField("_intArrayKlassObj");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    92
    shortArrayKlassField     = type.getAddressField("_shortArrayKlassObj");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    93
    longArrayKlassField      = type.getAddressField("_longArrayKlassObj");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    94
    singleArrayKlassField    = type.getAddressField("_singleArrayKlassObj");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    95
    doubleArrayKlassField    = type.getAddressField("_doubleArrayKlassObj");
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    96
2254
f13dda645a4b 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 670
diff changeset
    97
    narrowOopBaseField = type.getAddressField("_narrow_oop._base");
f13dda645a4b 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 670
diff changeset
    98
    narrowOopShiftField = type.getCIntegerField("_narrow_oop._shift");
13969
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13728
diff changeset
    99
    narrowKlassBaseField = type.getAddressField("_narrow_klass._base");
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13728
diff changeset
   100
    narrowKlassShiftField = type.getCIntegerField("_narrow_klass._shift");
39227
59ace61f7436 8157243: JMap heap test fail when used with external heap
sjohanss
parents: 35217
diff changeset
   101
59ace61f7436 8157243: JMap heap test fail when used with external heap
sjohanss
parents: 35217
diff changeset
   102
    UniverseExt.initialize(heapConstructor);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  public Universe() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  }
25335
2557b9b45520 8046282: SA update
poonam
parents: 13969
diff changeset
   107
  public static String narrowOopModeToString(NARROW_OOP_MODE mode) {
2557b9b45520 8046282: SA update
poonam
parents: 13969
diff changeset
   108
    switch (mode) {
2557b9b45520 8046282: SA update
poonam
parents: 13969
diff changeset
   109
    case UnscaledNarrowOop:
2557b9b45520 8046282: SA update
poonam
parents: 13969
diff changeset
   110
      return "32-bits Oops";
2557b9b45520 8046282: SA update
poonam
parents: 13969
diff changeset
   111
    case ZeroBasedNarrowOop:
2557b9b45520 8046282: SA update
poonam
parents: 13969
diff changeset
   112
      return "zero based Compressed Oops";
2557b9b45520 8046282: SA update
poonam
parents: 13969
diff changeset
   113
    case HeapBasedNarrowOop:
2557b9b45520 8046282: SA update
poonam
parents: 13969
diff changeset
   114
      return "Compressed Oops with base";
2557b9b45520 8046282: SA update
poonam
parents: 13969
diff changeset
   115
    }
2557b9b45520 8046282: SA update
poonam
parents: 13969
diff changeset
   116
    return "";
2557b9b45520 8046282: SA update
poonam
parents: 13969
diff changeset
   117
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  public CollectedHeap heap() {
30159
5d1c43b3b9b3 8076534: CollectedHeapName in SA agent incorrect
pliden
parents: 25335
diff changeset
   119
    return (CollectedHeap) heapConstructor.instantiateWrapperFor(collectedHeapField.getValue());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
2254
f13dda645a4b 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 670
diff changeset
   122
  public static long getNarrowOopBase() {
f13dda645a4b 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 670
diff changeset
   123
    if (narrowOopBaseField.getValue() == null) {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   124
      return 0;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   125
    } else {
2254
f13dda645a4b 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 670
diff changeset
   126
      return narrowOopBaseField.getValue().minus(null);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   127
    }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   128
  }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   129
2254
f13dda645a4b 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 670
diff changeset
   130
  public static int getNarrowOopShift() {
f13dda645a4b 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 670
diff changeset
   131
    return (int)narrowOopShiftField.getValue();
f13dda645a4b 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 670
diff changeset
   132
  }
f13dda645a4b 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 670
diff changeset
   133
13969
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13728
diff changeset
   134
  public static long getNarrowKlassBase() {
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13728
diff changeset
   135
    if (narrowKlassBaseField.getValue() == null) {
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13728
diff changeset
   136
      return 0;
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13728
diff changeset
   137
    } else {
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13728
diff changeset
   138
      return narrowKlassBaseField.getValue().minus(null);
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13728
diff changeset
   139
    }
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13728
diff changeset
   140
  }
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13728
diff changeset
   141
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13728
diff changeset
   142
  public static int getNarrowKlassShift() {
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13728
diff changeset
   143
    return (int)narrowKlassShiftField.getValue();
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13728
diff changeset
   144
  }
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13728
diff changeset
   145
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13728
diff changeset
   146
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  /** Returns "TRUE" iff "p" points into the allocated area of the heap. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  public boolean isIn(Address p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    return heap().isIn(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  /** Returns "TRUE" iff "p" points into the reserved area of the heap. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  public boolean isInReserved(Address p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    return heap().isInReserved(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  private Oop newOop(OopHandle handle) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    return VM.getVM().getObjectHeap().newOop(handle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  public Oop mainThreadGroup() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    return newOop(mainThreadGroupField.getValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  public Oop systemThreadGroup() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    return newOop(systemThreadGroupField.getValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  public void print() { printOn(System.out); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  public void printOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    heap().printOn(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  // Check whether an element of a typeArrayOop with the given type must be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  // aligned 0 mod 8.  The typeArrayOop itself must be aligned at least this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  // strongly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  public static boolean elementTypeShouldBeAligned(BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    return type == BasicType.T_DOUBLE || type == BasicType.T_LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  // Check whether an object field (static/non-static) of the given type must be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  // aligned 0 mod 8.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  public static boolean fieldTypeShouldBeAligned(BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    return type == BasicType.T_DOUBLE || type == BasicType.T_LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
}