src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java
author rkennke
Mon, 10 Dec 2018 15:47:44 +0100
changeset 52925 9c18c9d839d3
parent 51741 ed9b1200dd81
child 53814 eff915f3d3f2
permissions -rw-r--r--
8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental) Reviewed-by: kvn, roland, shade, coleenp, lmesnik, pliden, jgeorge, ihse, erikj Contributed-by: Christine Flood <chf@redhat.com>, Aleksey Shipilev <shade@redhat.com>, Roland Westrelin <rwestrel@redhat.com>, Zhenygu Gu <zgu@redhat.com>, Andrew Haley <aph@redhat.com>, Andrew Dinn <adinn@redhat.com>, Mario Torre <mtorre@redhat.com>, Roman Kennke <rkennke@redhat.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
51554
5b0d86499960 8209958: Clean up duplicate basic array type statics in Universe
coleenp
parents: 50523
diff changeset
     2
 * Copyright (c) 2000, 2018, 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.*;
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
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.*;
52925
9c18c9d839d3 8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents: 51741
diff changeset
    39
import sun.jvm.hotspot.gc.shenandoah.*;
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 22234
diff changeset
    40
import sun.jvm.hotspot.gc.parallel.*;
51741
ed9b1200dd81 8209163: SA: Show Object Histogram asserts with ZGC
pliden
parents: 51554
diff changeset
    41
import sun.jvm.hotspot.gc.z.*;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
import sun.jvm.hotspot.memory.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
public class ObjectHeap {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    49
  private static final boolean DEBUG;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    50
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    51
  static {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    52
    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
    53
  }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    54
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  public ObjectHeap(TypeDataBase db) throws WrongTypeException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    // 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
    57
    oopSize     = VM.getVM().getOopSize();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    byteSize    = db.getJByteType().getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    charSize    = db.getJCharType().getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    booleanSize = db.getJBooleanType().getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    intSize     = db.getJIntType().getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    shortSize   = db.getJShortType().getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    longSize    = db.getJLongType().getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    floatSize   = db.getJFloatType().getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    doubleSize  = db.getJDoubleType().getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  /** Comparison operation for oops, either or both of which may be null */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  public boolean equal(Oop o1, Oop o2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    if (o1 != null) return o1.equals(o2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    return (o2 == null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // Cached sizes of basic types
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  private long oopSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  private long byteSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  private long charSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  private long booleanSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  private long intSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  private long shortSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  private long longSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  private long floatSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  private long doubleSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  public long getOopSize()     { return oopSize;     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  public long getByteSize()    { return byteSize;    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  public long getCharSize()    { return charSize;    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  public long getBooleanSize() { return booleanSize; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  public long getIntSize()     { return intSize;     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  public long getShortSize()   { return shortSize;   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  public long getLongSize()    { return longSize;    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  public long getFloatSize()   { return floatSize;   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  public long getDoubleSize()  { return doubleSize;  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  /** an interface to filter objects while walking heap */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  public static interface ObjectFilter {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    public boolean canInclude(Oop obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  /** The base heap iteration mechanism */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  public void iterate(HeapVisitor visitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    iterateLiveRegions(collectLiveRegions(), visitor, null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  /** iterate objects satisfying a specified ObjectFilter */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  public void iterate(HeapVisitor visitor, ObjectFilter of) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    iterateLiveRegions(collectLiveRegions(), visitor, of);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  /** iterate objects of given Klass. param 'includeSubtypes' tells whether to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
   *  include objects of subtypes or not */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  public void iterateObjectsOfKlass(HeapVisitor visitor, final Klass k, boolean includeSubtypes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    if (includeSubtypes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      if (k.isFinal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
        // do the simpler "exact" klass loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
        iterateExact(visitor, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
        iterateSubtypes(visitor, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      // there can no object of abstract classes and interfaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
      if (!k.isAbstract() && !k.isInterface()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
        iterateExact(visitor, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  /** iterate objects of given Klass (objects of subtypes included) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  public void iterateObjectsOfKlass(HeapVisitor visitor, final Klass k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    iterateObjectsOfKlass(visitor, k, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  /** This routine can be used to iterate through the heap at an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      extremely low level (stepping word-by-word) to provide the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      ability to do very low-level debugging */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  public void iterateRaw(RawHeapVisitor visitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    List liveRegions = collectLiveRegions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    // Summarize size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    long totalSize = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    for (int i = 0; i < liveRegions.size(); i += 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      Address bottom = (Address) liveRegions.get(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      Address top    = (Address) liveRegions.get(i+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      totalSize += top.minus(bottom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    visitor.prologue(totalSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    for (int i = 0; i < liveRegions.size(); i += 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      Address bottom = (Address) liveRegions.get(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      Address top    = (Address) liveRegions.get(i+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      // Traverses the space from bottom to top
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      while (bottom.lessThan(top)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
        visitor.visitAddress(bottom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
        bottom = bottom.addOffsetTo(VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    visitor.epilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   162
  public boolean isValidMethod(Address handle) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   163
    try {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   164
      Method m = (Method)Metadata.instantiateWrapperFor(handle);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   165
      return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   166
    } catch (Exception e) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   167
      return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  }
764
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 360
diff changeset
   169
  }
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 360
diff changeset
   170
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  // Creates an instance from the Oop hierarchy based based on the handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  public Oop newOop(OopHandle handle) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    // The only known way to detect the right type of an oop is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    // traversing the class chain until a well-known klass is recognized.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    // A more direct solution would require the klasses to expose
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    // the C++ vtbl structure.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    // Handle the null reference
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    if (handle == null) return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    // 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
   182
    Klass klass = Oop.getKlassForOopHandle(handle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    if (klass != null) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   184
      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
   185
      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
   186
      if (klass instanceof InstanceKlass) return new Instance(handle, this);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
764
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 360
diff changeset
   189
    if (DEBUG) {
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 360
diff changeset
   190
      System.err.println("Unknown oop at " + handle);
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 360
diff changeset
   191
      System.err.println("Oop's klass is " + klass);
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 360
diff changeset
   192
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    throw new UnknownOopException();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  // Print all objects in the object heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  public void print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    HeapPrinter printer = new HeapPrinter(System.out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    iterate(printer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  //---------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  // Internals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  private void iterateExact(HeapVisitor visitor, final Klass k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    iterateLiveRegions(collectLiveRegions(), visitor, new ObjectFilter() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
          public boolean canInclude(Oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
            Klass tk = obj.getKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
            // null Klass is seen sometimes!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
            return (tk != null && tk.equals(k));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  private void iterateSubtypes(HeapVisitor visitor, final Klass k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    iterateLiveRegions(collectLiveRegions(), visitor, new ObjectFilter() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
          public boolean canInclude(Oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
            Klass tk = obj.getKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
            // null Klass is seen sometimes!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
            return (tk != null && tk.isSubtypeOf(k));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  private void iterateLiveRegions(List liveRegions, HeapVisitor visitor, ObjectFilter of) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    // Summarize size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    long totalSize = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    for (int i = 0; i < liveRegions.size(); i += 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
      Address bottom = (Address) liveRegions.get(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
      Address top    = (Address) liveRegions.get(i+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      totalSize += top.minus(bottom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    visitor.prologue(totalSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    CompactibleFreeListSpace cmsSpaceOld = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    CollectedHeap heap = VM.getVM().getUniverse().heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    if (heap instanceof GenCollectedHeap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      GenCollectedHeap genHeap = (GenCollectedHeap) heap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      Generation genOld = genHeap.getGen(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      if (genOld instanceof ConcurrentMarkSweepGeneration) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
          ConcurrentMarkSweepGeneration concGen = (ConcurrentMarkSweepGeneration)genOld;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
          cmsSpaceOld = concGen.cmsSpace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    for (int i = 0; i < liveRegions.size(); i += 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      Address bottom = (Address) liveRegions.get(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      Address top    = (Address) liveRegions.get(i+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
        // Traverses the space from bottom to top
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
        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
   256
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
        while (handle.lessThan(top)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
        Oop obj = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
          try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
            obj = newOop(handle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
          } catch (UnknownOopException exp) {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   263
            if (DEBUG) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   264
              throw new RuntimeException(" UnknownOopException  " + exp);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   265
            }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
          if (obj == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
             //Find the object size using Printezis bits and skip over
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
             long size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
             if ( (cmsSpaceOld != null) && cmsSpaceOld.contains(handle) ){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
                 size = cmsSpaceOld.collector().blockSizeUsingPrintezisBits(handle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
             if (size <= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
                //Either Printezis bits not set or handle is not in cms space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
                throw new UnknownOopException();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
             handle = handle.addOffsetToAsOopHandle(CompactibleFreeListSpace.adjustObjectSizeInBytes(size));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
             continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
          if (of == null || of.canInclude(obj)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
                  if (visitor.doObj(obj)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
                         // doObj() returns true to abort this loop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
                          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
                  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
          }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10663
diff changeset
   289
          if ( (cmsSpaceOld != null) && cmsSpaceOld.contains(handle)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
              handle = handle.addOffsetToAsOopHandle(CompactibleFreeListSpace.adjustObjectSizeInBytes(obj.getObjectSize()) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
              handle = handle.addOffsetToAsOopHandle(obj.getObjectSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
      catch (AddressException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
        // This is okay at the top of these regions
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   298
          }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
      catch (UnknownOopException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
        // This is okay at the top of these regions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    visitor.epilogue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   307
  private void addLiveRegions(String name, List input, List output) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
     for (Iterator itr = input.iterator(); itr.hasNext();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
        MemRegion reg = (MemRegion) itr.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
        Address top = reg.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
        Address bottom = reg.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
           Assert.that(top != null, "top address in a live region should not be null");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
           Assert.that(bottom != null, "bottom address in a live region should not be null");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
        output.add(top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
        output.add(bottom);
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   320
        if (DEBUG) {
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   321
          System.err.println("Live region: " + name + ": " + bottom + ", " + top);
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   322
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  private class LiveRegionsCollector implements SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
     LiveRegionsCollector(List l) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
        liveRegions = l;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
     public void doSpace(Space s) {
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   332
        addLiveRegions(s.toString(), s.getLiveRegions(), liveRegions);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
     private List liveRegions;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  // Returns a List<Address> where the addresses come in pairs. These
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  // designate the live regions of the heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  private List collectLiveRegions() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    // We want to iterate through all live portions of the heap, but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    // do not want to abort the heap traversal prematurely if we find
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    // a problem (like an allocated but uninitialized object at the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    // top of a generation). To do this we enumerate all generations'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    // bottom and top regions, and factor in TLABs if necessary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    // List<Address>. Addresses come in pairs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    List liveRegions = new ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    LiveRegionsCollector lrc = new LiveRegionsCollector(liveRegions);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    CollectedHeap heap = VM.getVM().getUniverse().heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    if (heap instanceof GenCollectedHeap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
       GenCollectedHeap genHeap = (GenCollectedHeap) heap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
       // Run through all generations, obtaining bottom-top pairs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
       for (int i = 0; i < genHeap.nGens(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
         Generation gen = genHeap.getGen(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
         gen.spaceIterate(lrc, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    } else if (heap instanceof ParallelScavengeHeap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
       ParallelScavengeHeap psh = (ParallelScavengeHeap) heap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
       PSYoungGen youngGen = psh.youngGen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
       // Add eden space
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   363
       addLiveRegions("eden", youngGen.edenSpace().getLiveRegions(), liveRegions);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
       // Add from-space but not to-space
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   365
       addLiveRegions("from", youngGen.fromSpace().getLiveRegions(), liveRegions);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
       PSOldGen oldGen = psh.oldGen();
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   367
       addLiveRegions("old ", oldGen.objectSpace().getLiveRegions(), liveRegions);
10663
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 8878
diff changeset
   368
    } else if (heap instanceof G1CollectedHeap) {
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 8878
diff changeset
   369
        G1CollectedHeap g1h = (G1CollectedHeap) heap;
3ef855a3329b 7059019: G1: add G1 support to the SA
tonyp
parents: 8878
diff changeset
   370
        g1h.heapRegionIterate(lrc);
52925
9c18c9d839d3 8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents: 51741
diff changeset
   371
    } else if (heap instanceof ShenandoahHeap) {
9c18c9d839d3 8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents: 51741
diff changeset
   372
       // Operation (currently) not supported with Shenandoah GC. Print
9c18c9d839d3 8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents: 51741
diff changeset
   373
       // a warning and leave the list of live regions empty.
9c18c9d839d3 8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents: 51741
diff changeset
   374
       System.err.println("Warning: Operation not supported with Shenandoah GC");
51741
ed9b1200dd81 8209163: SA: Show Object Histogram asserts with ZGC
pliden
parents: 51554
diff changeset
   375
    } else if (heap instanceof ZCollectedHeap) {
ed9b1200dd81 8209163: SA: Show Object Histogram asserts with ZGC
pliden
parents: 51554
diff changeset
   376
       // Operation (currently) not supported with ZGC. Print
ed9b1200dd81 8209163: SA: Show Object Histogram asserts with ZGC
pliden
parents: 51554
diff changeset
   377
       // a warning and leave the list of live regions empty.
ed9b1200dd81 8209163: SA: Show Object Histogram asserts with ZGC
pliden
parents: 51554
diff changeset
   378
       System.err.println("Warning: Operation not supported with ZGC");
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents: 47216
diff changeset
   379
    } else if (heap instanceof EpsilonHeap) {
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents: 47216
diff changeset
   380
       EpsilonHeap eh = (EpsilonHeap) heap;
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents: 47216
diff changeset
   381
       liveRegions.add(eh.space().top());
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents: 47216
diff changeset
   382
       liveRegions.add(eh.space().bottom());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
       if (Assert.ASSERTS_ENABLED) {
50523
7b7c75d87f9b 8204180: Implementation: JEP 318: Epsilon, A No-Op Garbage Collector
shade
parents: 47216
diff changeset
   385
          Assert.that(false, "Unexpected CollectedHeap type: " + heap.getClass().getName());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    // If UseTLAB is enabled, snip out regions associated with TLABs'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    // dead regions. Note that TLABs can be present in any generation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    // FIXME: consider adding fewer boundaries to live region list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    // Theoretically only need to stop at TLAB's top and resume at its
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    // end.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    if (VM.getVM().getUseTLAB()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
      for (JavaThread thread = VM.getVM().getThreads().first(); thread != null; thread = thread.next()) {
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   398
        ThreadLocalAllocBuffer tlab = thread.tlab();
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   399
        if (tlab.start() != null) {
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   400
          if ((tlab.top() == null) || (tlab.end() == null)) {
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   401
            System.err.print("Warning: skipping invalid TLAB for thread ");
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   402
            thread.printThreadIDOn(System.err);
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   403
            System.err.println();
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   404
          } else {
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   405
            if (DEBUG) {
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   406
              System.err.print("TLAB for " + thread.getThreadName() + ", #");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
              thread.printThreadIDOn(System.err);
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   408
              System.err.print(": ");
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   409
              tlab.printOn(System.err);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
            }
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   411
            // Go from:
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   412
            //  - below start() to start()
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   413
            //  - start() to top()
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   414
            //  - end() and above
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   415
            liveRegions.add(tlab.start());
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   416
            liveRegions.add(tlab.start());
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   417
            liveRegions.add(tlab.top());
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   418
            liveRegions.add(tlab.hardEnd());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
    // Now sort live regions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
    sortLiveRegions(liveRegions);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
      Assert.that(liveRegions.size() % 2 == 0, "Must have even number of region boundaries");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
22216
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   431
    if (DEBUG) {
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   432
      System.err.println("liveRegions:");
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   433
      for (int i = 0; i < liveRegions.size(); i += 2) {
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   434
          Address bottom = (Address) liveRegions.get(i);
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   435
          Address top    = (Address) liveRegions.get(i+1);
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   436
          System.err.println(" " + bottom + " - " + top);
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   437
      }
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   438
    }
888245fbd0a5 8029395: SA: jstack throws WrongTypeException
sla
parents: 15735
diff changeset
   439
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    return liveRegions;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  private void sortLiveRegions(List liveRegions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    Collections.sort(liveRegions, new Comparator() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
        public int compare(Object o1, Object o2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
          Address a1 = (Address) o1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
          Address a2 = (Address) o2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
          if (AddressOps.lt(a1, a2)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
            return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
          } else if (AddressOps.gt(a1, a2)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
            return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
          return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
}