src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java
author shade
Tue, 05 Jun 2018 17:17:24 +0200
branchepsilon-gc-branch
changeset 56668 5cd17d3d3f83
parent 56667 d999bdb8173c
permissions -rw-r--r--
Change "unexpected heap type" to a more generic version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 22234
diff changeset
     2
 * Copyright (c) 2000, 2015, 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: 781
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 781
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: 781
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
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// The ObjectHeap is an abstraction over all generations in the VM
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// It gives access to all present objects and classes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
package sun.jvm.hotspot.oops;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
import sun.jvm.hotspot.debugger.*;
30769
df60209aac9d 8080581: Align SA with new GC directory structure
pliden
parents: 30764
diff changeset
    35
import sun.jvm.hotspot.gc.cms.*;
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 22234
diff changeset
    36
import sun.jvm.hotspot.gc.shared.*;
56576
92316ff16d5c Serviceability support for Epsilon
shade
parents: 47216
diff changeset
    37
import sun.jvm.hotspot.gc.epsilon.*;
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 22234
diff changeset
    38
import sun.jvm.hotspot.gc.g1.*;
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 22234
diff changeset
    39
import sun.jvm.hotspot.gc.parallel.*;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
import sun.jvm.hotspot.memory.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
public class ObjectHeap {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    47
  private static final boolean DEBUG;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    48
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    49
  static {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    50
    DEBUG = System.getProperty("sun.jvm.hotspot.oops.ObjectHeap.DEBUG") != null;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    51
  }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    52
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    53
  private Address              boolArrayKlassHandle;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    54
  private Address              byteArrayKlassHandle;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    55
  private Address              charArrayKlassHandle;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    56
  private Address              intArrayKlassHandle;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    57
  private Address              shortArrayKlassHandle;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    58
  private Address              longArrayKlassHandle;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    59
  private Address              singleArrayKlassHandle;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    60
  private Address              doubleArrayKlassHandle;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  private TypeArrayKlass         boolArrayKlassObj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  private TypeArrayKlass         byteArrayKlassObj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  private TypeArrayKlass         charArrayKlassObj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  private TypeArrayKlass         intArrayKlassObj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  private TypeArrayKlass         shortArrayKlassObj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  private TypeArrayKlass         longArrayKlassObj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  private TypeArrayKlass         singleArrayKlassObj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  private TypeArrayKlass         doubleArrayKlassObj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  public void initialize(TypeDataBase db) throws WrongTypeException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    // Lookup the roots in the object hierarchy.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    Type universeType = db.lookupType("Universe");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    75
    boolArrayKlassHandle      = universeType.getAddressField("_boolArrayKlassObj").getValue();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    76
    boolArrayKlassObj         = new TypeArrayKlass(boolArrayKlassHandle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    78
    byteArrayKlassHandle      = universeType.getAddressField("_byteArrayKlassObj").getValue();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    79
    byteArrayKlassObj         = new TypeArrayKlass(byteArrayKlassHandle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    81
    charArrayKlassHandle      = universeType.getAddressField("_charArrayKlassObj").getValue();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    82
    charArrayKlassObj         = new TypeArrayKlass(charArrayKlassHandle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    84
    intArrayKlassHandle       = universeType.getAddressField("_intArrayKlassObj").getValue();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    85
    intArrayKlassObj          = new TypeArrayKlass(intArrayKlassHandle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    87
    shortArrayKlassHandle     = universeType.getAddressField("_shortArrayKlassObj").getValue();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    88
    shortArrayKlassObj        = new TypeArrayKlass(shortArrayKlassHandle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    90
    longArrayKlassHandle      = universeType.getAddressField("_longArrayKlassObj").getValue();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    91
    longArrayKlassObj         = new TypeArrayKlass(longArrayKlassHandle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    93
    singleArrayKlassHandle    = universeType.getAddressField("_singleArrayKlassObj").getValue();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    94
    singleArrayKlassObj       = new TypeArrayKlass(singleArrayKlassHandle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    96
    doubleArrayKlassHandle    = universeType.getAddressField("_doubleArrayKlassObj").getValue();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
    97
    doubleArrayKlassObj       = new TypeArrayKlass(doubleArrayKlassHandle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  public ObjectHeap(TypeDataBase db) throws WrongTypeException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    // Get commonly used sizes of basic types
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   102
    oopSize     = VM.getVM().getOopSize();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    byteSize    = db.getJByteType().getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    charSize    = db.getJCharType().getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    booleanSize = db.getJBooleanType().getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    intSize     = db.getJIntType().getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    shortSize   = db.getJShortType().getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    longSize    = db.getJLongType().getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    floatSize   = db.getJFloatType().getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    doubleSize  = db.getJDoubleType().getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    initialize(db);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  /** Comparison operation for oops, either or both of which may be null */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  public boolean equal(Oop o1, Oop o2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    if (o1 != null) return o1.equals(o2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    return (o2 == null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // Cached sizes of basic types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  private long oopSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  private long byteSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  private long charSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  private long booleanSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  private long intSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  private long shortSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  private long longSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  private long floatSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  private long doubleSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  public long getOopSize()     { return oopSize;     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  public long getByteSize()    { return byteSize;    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  public long getCharSize()    { return charSize;    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  public long getBooleanSize() { return booleanSize; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  public long getIntSize()     { return intSize;     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  public long getShortSize()   { return shortSize;   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  public long getLongSize()    { return longSize;    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  public long getFloatSize()   { return floatSize;   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  public long getDoubleSize()  { return doubleSize;  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // Accessors for well-known system classes (from Universe)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  public TypeArrayKlass         getBoolArrayKlassObj()         { return boolArrayKlassObj; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  public TypeArrayKlass         getByteArrayKlassObj()         { return byteArrayKlassObj; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  public TypeArrayKlass         getCharArrayKlassObj()         { return charArrayKlassObj; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  public TypeArrayKlass         getIntArrayKlassObj()          { return intArrayKlassObj; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  public TypeArrayKlass         getShortArrayKlassObj()        { return shortArrayKlassObj; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  public TypeArrayKlass         getLongArrayKlassObj()         { return longArrayKlassObj; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  public TypeArrayKlass         getSingleArrayKlassObj()       { return singleArrayKlassObj; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  public TypeArrayKlass         getDoubleArrayKlassObj()       { return doubleArrayKlassObj; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  /** Takes a BasicType and returns the corresponding primitive array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      klass */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  public Klass typeArrayKlassObj(int t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    if (t == BasicType.getTBoolean()) return getBoolArrayKlassObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    if (t == BasicType.getTChar())    return getCharArrayKlassObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    if (t == BasicType.getTFloat())   return getSingleArrayKlassObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    if (t == BasicType.getTDouble())  return getDoubleArrayKlassObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    if (t == BasicType.getTByte())    return getByteArrayKlassObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    if (t == BasicType.getTShort())   return getShortArrayKlassObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    if (t == BasicType.getTInt())     return getIntArrayKlassObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    if (t == BasicType.getTLong())    return getLongArrayKlassObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    throw new RuntimeException("Illegal basic type " + t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  /** an interface to filter objects while walking heap */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  public static interface ObjectFilter {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    public boolean canInclude(Oop obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  /** The base heap iteration mechanism */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  public void iterate(HeapVisitor visitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    iterateLiveRegions(collectLiveRegions(), visitor, null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  /** iterate objects satisfying a specified ObjectFilter */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  public void iterate(HeapVisitor visitor, ObjectFilter of) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    iterateLiveRegions(collectLiveRegions(), visitor, of);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  /** iterate objects of given Klass. param 'includeSubtypes' tells whether to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
   *  include objects of subtypes or not */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  public void iterateObjectsOfKlass(HeapVisitor visitor, final Klass k, boolean includeSubtypes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    if (includeSubtypes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      if (k.isFinal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
        // do the simpler "exact" klass loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
        iterateExact(visitor, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
        iterateSubtypes(visitor, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      // there can no object of abstract classes and interfaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
      if (!k.isAbstract() && !k.isInterface()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
        iterateExact(visitor, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  /** iterate objects of given Klass (objects of subtypes included) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  public void iterateObjectsOfKlass(HeapVisitor visitor, final Klass k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    iterateObjectsOfKlass(visitor, k, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  /** This routine can be used to iterate through the heap at an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
      extremely low level (stepping word-by-word) to provide the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
      ability to do very low-level debugging */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  public void iterateRaw(RawHeapVisitor visitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    List liveRegions = collectLiveRegions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    // Summarize size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    long totalSize = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    for (int i = 0; i < liveRegions.size(); i += 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
      Address bottom = (Address) liveRegions.get(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
      Address top    = (Address) liveRegions.get(i+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      totalSize += top.minus(bottom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    visitor.prologue(totalSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    for (int i = 0; i < liveRegions.size(); i += 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
      Address bottom = (Address) liveRegions.get(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      Address top    = (Address) liveRegions.get(i+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
      // Traverses the space from bottom to top
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
      while (bottom.lessThan(top)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
        visitor.visitAddress(bottom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
        bottom = bottom.addOffsetTo(VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    visitor.epilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   233
  public boolean isValidMethod(Address handle) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   234
    try {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   235
      Method m = (Method)Metadata.instantiateWrapperFor(handle);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   236
      return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   237
    } catch (Exception e) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   238
      return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  }
764
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 360
diff changeset
   240
  }
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 360
diff changeset
   241
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  // Creates an instance from the Oop hierarchy based based on the handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  public Oop newOop(OopHandle handle) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    // The only known way to detect the right type of an oop is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    // traversing the class chain until a well-known klass is recognized.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    // A more direct solution would require the klasses to expose
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    // the C++ vtbl structure.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    // Handle the null reference
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    if (handle == null) return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    // Then check if obj.klass() is one of the root objects
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   253
    Klass klass = Oop.getKlassForOopHandle(handle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    if (klass != null) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   255
      if (klass instanceof TypeArrayKlass) return new TypeArray(handle, this);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   256
      if (klass instanceof ObjArrayKlass) return new ObjArray(handle, this);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   257
      if (klass instanceof InstanceKlass) return new Instance(handle, this);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
764
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 360
diff changeset
   260
    if (DEBUG) {
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 360
diff changeset
   261
      System.err.println("Unknown oop at " + handle);
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 360
diff changeset
   262
      System.err.println("Oop's klass is " + klass);
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 360
diff changeset
   263
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    throw new UnknownOopException();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  // Print all objects in the object heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  public void print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    HeapPrinter printer = new HeapPrinter(System.out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    iterate(printer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  //---------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  // Internals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  private void iterateExact(HeapVisitor visitor, final Klass k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    iterateLiveRegions(collectLiveRegions(), visitor, new ObjectFilter() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
          public boolean canInclude(Oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
            Klass tk = obj.getKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
            // null Klass is seen sometimes!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
            return (tk != null && tk.equals(k));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  private void iterateSubtypes(HeapVisitor visitor, final Klass k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    iterateLiveRegions(collectLiveRegions(), visitor, new ObjectFilter() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
          public boolean canInclude(Oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
            Klass tk = obj.getKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
            // null Klass is seen sometimes!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
            return (tk != null && tk.isSubtypeOf(k));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  private void iterateLiveRegions(List liveRegions, HeapVisitor visitor, ObjectFilter of) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    // Summarize size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    long totalSize = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    for (int i = 0; i < liveRegions.size(); i += 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
      Address bottom = (Address) liveRegions.get(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
      Address top    = (Address) liveRegions.get(i+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
      totalSize += top.minus(bottom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    visitor.prologue(totalSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    CompactibleFreeListSpace cmsSpaceOld = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    CollectedHeap heap = VM.getVM().getUniverse().heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    if (heap instanceof GenCollectedHeap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
      GenCollectedHeap genHeap = (GenCollectedHeap) heap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
      Generation genOld = genHeap.getGen(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
      if (genOld instanceof ConcurrentMarkSweepGeneration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
          ConcurrentMarkSweepGeneration concGen = (ConcurrentMarkSweepGeneration)genOld;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
          cmsSpaceOld = concGen.cmsSpace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    for (int i = 0; i < liveRegions.size(); i += 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
      Address bottom = (Address) liveRegions.get(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
      Address top    = (Address) liveRegions.get(i+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
        // Traverses the space from bottom to top
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
        OopHandle handle = bottom.addOffsetToAsOopHandle(0);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   327
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
        while (handle.lessThan(top)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
        Oop obj = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
          try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
            obj = newOop(handle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
          } catch (UnknownOopException exp) {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   334
            if (DEBUG) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   335
              throw new RuntimeException(" UnknownOopException  " + exp);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   336
            }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
          if (obj == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
             //Find the object size using Printezis bits and skip over
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
             long size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
             if ( (cmsSpaceOld != null) && cmsSpaceOld.contains(handle) ){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
                 size = cmsSpaceOld.collector().blockSizeUsingPrintezisBits(handle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
             if (size <= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
                //Either Printezis bits not set or handle is not in cms space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
                throw new UnknownOopException();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
             handle = handle.addOffsetToAsOopHandle(CompactibleFreeListSpace.adjustObjectSizeInBytes(size));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
             continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
          if (of == null || of.canInclude(obj)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
                  if (visitor.doObj(obj)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
                         // doObj() returns true to abort this loop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
                          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
                  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
          }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   360
          if ( (cmsSpaceOld != null) && cmsSpaceOld.contains(handle)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
              handle = handle.addOffsetToAsOopHandle(CompactibleFreeListSpace.adjustObjectSizeInBytes(obj.getObjectSize()) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
              handle = handle.addOffsetToAsOopHandle(obj.getObjectSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
      catch (AddressException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
        // This is okay at the top of these regions
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   369
          }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
      catch (UnknownOopException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
        // This is okay at the top of these regions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    visitor.epilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   378
  private void addLiveRegions(String name, List input, List output) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
     for (Iterator itr = input.iterator(); itr.hasNext();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
        MemRegion reg = (MemRegion) itr.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
        Address top = reg.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
        Address bottom = reg.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
           Assert.that(top != null, "top address in a live region should not be null");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
           Assert.that(bottom != null, "bottom address in a live region should not be null");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
        output.add(top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
        output.add(bottom);
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   391
        if (DEBUG) {
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   392
          System.err.println("Live region: " + name + ": " + bottom + ", " + top);
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   393
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  private class LiveRegionsCollector implements SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
     LiveRegionsCollector(List l) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
        liveRegions = l;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
     public void doSpace(Space s) {
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   403
        addLiveRegions(s.toString(), s.getLiveRegions(), liveRegions);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
     private List liveRegions;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  // Returns a List<Address> where the addresses come in pairs. These
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  // designate the live regions of the heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  private List collectLiveRegions() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    // We want to iterate through all live portions of the heap, but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    // do not want to abort the heap traversal prematurely if we find
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    // a problem (like an allocated but uninitialized object at the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    // top of a generation). To do this we enumerate all generations'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    // bottom and top regions, and factor in TLABs if necessary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    // List<Address>. Addresses come in pairs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    List liveRegions = new ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    LiveRegionsCollector lrc = new LiveRegionsCollector(liveRegions);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    CollectedHeap heap = VM.getVM().getUniverse().heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    if (heap instanceof GenCollectedHeap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
       GenCollectedHeap genHeap = (GenCollectedHeap) heap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
       // Run through all generations, obtaining bottom-top pairs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
       for (int i = 0; i < genHeap.nGens(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
         Generation gen = genHeap.getGen(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
         gen.spaceIterate(lrc, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
    } else if (heap instanceof ParallelScavengeHeap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
       ParallelScavengeHeap psh = (ParallelScavengeHeap) heap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
       PSYoungGen youngGen = psh.youngGen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
       // Add eden space
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   434
       addLiveRegions("eden", youngGen.edenSpace().getLiveRegions(), liveRegions);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
       // Add from-space but not to-space
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   436
       addLiveRegions("from", youngGen.fromSpace().getLiveRegions(), liveRegions);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
       PSOldGen oldGen = psh.oldGen();
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   438
       addLiveRegions("old ", oldGen.objectSpace().getLiveRegions(), liveRegions);
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 8878
diff changeset
   439
    } else if (heap instanceof G1CollectedHeap) {
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 8878
diff changeset
   440
        G1CollectedHeap g1h = (G1CollectedHeap) heap;
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 8878
diff changeset
   441
        g1h.heapRegionIterate(lrc);
56576
92316ff16d5c Serviceability support for Epsilon
shade
parents: 47216
diff changeset
   442
    } else if (heap instanceof EpsilonHeap) {
92316ff16d5c Serviceability support for Epsilon
shade
parents: 47216
diff changeset
   443
       EpsilonHeap eh = (EpsilonHeap) heap;
56667
d999bdb8173c Fix SA heap iteration code
shade
parents: 56576
diff changeset
   444
       liveRegions.add(eh.space().top());
d999bdb8173c Fix SA heap iteration code
shade
parents: 56576
diff changeset
   445
       liveRegions.add(eh.space().bottom());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
       if (Assert.ASSERTS_ENABLED) {
56668
5cd17d3d3f83 Change "unexpected heap type" to a more generic version
shade
parents: 56667
diff changeset
   448
          Assert.that(false, "Unexpected CollectedHeap type: " + heap.getClass().getName());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    // If UseTLAB is enabled, snip out regions associated with TLABs'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    // dead regions. Note that TLABs can be present in any generation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    // FIXME: consider adding fewer boundaries to live region list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    // Theoretically only need to stop at TLAB's top and resume at its
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
    // end.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
    if (VM.getVM().getUseTLAB()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
      for (JavaThread thread = VM.getVM().getThreads().first(); thread != null; thread = thread.next()) {
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   461
        ThreadLocalAllocBuffer tlab = thread.tlab();
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   462
        if (tlab.start() != null) {
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   463
          if ((tlab.top() == null) || (tlab.end() == null)) {
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   464
            System.err.print("Warning: skipping invalid TLAB for thread ");
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   465
            thread.printThreadIDOn(System.err);
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   466
            System.err.println();
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   467
          } else {
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   468
            if (DEBUG) {
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   469
              System.err.print("TLAB for " + thread.getThreadName() + ", #");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
              thread.printThreadIDOn(System.err);
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   471
              System.err.print(": ");
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   472
              tlab.printOn(System.err);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
            }
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   474
            // Go from:
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   475
            //  - below start() to start()
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   476
            //  - start() to top()
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   477
            //  - end() and above
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   478
            liveRegions.add(tlab.start());
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   479
            liveRegions.add(tlab.start());
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   480
            liveRegions.add(tlab.top());
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   481
            liveRegions.add(tlab.hardEnd());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    // Now sort live regions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    sortLiveRegions(liveRegions);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
      Assert.that(liveRegions.size() % 2 == 0, "Must have even number of region boundaries");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   494
    if (DEBUG) {
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   495
      System.err.println("liveRegions:");
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   496
      for (int i = 0; i < liveRegions.size(); i += 2) {
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   497
          Address bottom = (Address) liveRegions.get(i);
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   498
          Address top    = (Address) liveRegions.get(i+1);
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   499
          System.err.println(" " + bottom + " - " + top);
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   500
      }
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   501
    }
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   502
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    return liveRegions;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  private void sortLiveRegions(List liveRegions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
    Collections.sort(liveRegions, new Comparator() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
        public int compare(Object o1, Object o2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
          Address a1 = (Address) o1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
          Address a2 = (Address) o2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
          if (AddressOps.lt(a1, a2)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
            return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
          } else if (AddressOps.gt(a1, a2)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
            return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
          return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
}