src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/Generation.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 35217 hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/Generation.java@ce4b5303a813
child 53814 eff915f3d3f2
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
30769
df60209aac9d 8080581: Align SA with new GC directory structure
pliden
parents: 27904
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: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
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
30769
df60209aac9d 8080581: Align SA with new GC directory structure
pliden
parents: 27904
diff changeset
    25
package sun.jvm.hotspot.gc.shared;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.debugger.*;
30769
df60209aac9d 8080581: Align SA with new GC directory structure
pliden
parents: 27904
diff changeset
    30
import sun.jvm.hotspot.memory.*;
df60209aac9d 8080581: Align SA with new GC directory structure
pliden
parents: 27904
diff changeset
    31
import sun.jvm.hotspot.runtime.*;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
/** <P> The (supported) Generation hierarchy currently looks like this: </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
    <ul>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    <li> Generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
      <ul>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
      <li> CardGeneration
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
        <ul>
27904
d606512952cc 8065993: Merge OneContigSpaceCardGeneration with TenuredGeneration
brutisso
parents: 13728
diff changeset
    41
        <li> TenuredGeneration
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
        </ul>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
      <li> DefNewGeneration
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
      </ul>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    </ul>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
public abstract class Generation extends VMObject {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  private static long          reservedFieldOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  private static long          virtualSpaceFieldOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  protected static final int  K = 1024;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // Fields for class StatRecord
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  private static Field         statRecordField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  private static CIntegerField invocationField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // constants from Name enum
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  private static int NAME_DEF_NEW;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  private static int NAME_PAR_NEW;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  private static int NAME_MARK_SWEEP_COMPACT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  private static int NAME_CONCURRENT_MARK_SWEEP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  private static int NAME_OTHER;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  private static synchronized void initialize(TypeDataBase db) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    Type type = db.lookupType("Generation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    reservedFieldOffset     = type.getField("_reserved").getOffset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    virtualSpaceFieldOffset = type.getField("_virtual_space").getOffset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    // StatRecord
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    statRecordField         = type.getField("_stat_record");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    type                    = db.lookupType("Generation::StatRecord");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    invocationField         = type.getCIntegerField("invocations");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    // constants from Generation::Name
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    NAME_DEF_NEW = db.lookupIntConstant("Generation::DefNew").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    NAME_PAR_NEW = db.lookupIntConstant("Generation::ParNew").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    NAME_MARK_SWEEP_COMPACT = db.lookupIntConstant("Generation::MarkSweepCompact").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    NAME_CONCURRENT_MARK_SWEEP = db.lookupIntConstant("Generation::ConcurrentMarkSweep").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    NAME_OTHER = db.lookupIntConstant("Generation::Other").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  public Generation(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    super(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  public static class Name {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    public static final Name DEF_NEW = new Name("DefNew");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    public static final Name PAR_NEW = new Name("ParNew");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    public static final Name MARK_SWEEP_COMPACT = new Name("MarkSweepCompact");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    public static final Name CONCURRENT_MARK_SWEEP = new Name("ConcurrentMarkSweep");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    public static final Name OTHER = new Name("Other");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    private Name(String value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      this.value = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    private String value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    public String toString() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      return value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  public Generation.Name kind() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    return Generation.Name.OTHER;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  static Generation.Name nameForEnum(int value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
     if (value == NAME_DEF_NEW) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
        return Name.DEF_NEW;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
     } else if (value == NAME_PAR_NEW) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
        return Name.PAR_NEW;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
     } else if (value == NAME_MARK_SWEEP_COMPACT) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
        return Name.MARK_SWEEP_COMPACT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
     } else if (value == NAME_CONCURRENT_MARK_SWEEP) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
        return Name.CONCURRENT_MARK_SWEEP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
     } else if (value == NAME_OTHER) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
        return Name.OTHER;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
     } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
        throw new RuntimeException("should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  public int invocations() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    return getStatRecord().getInvocations();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  /** The maximum number of object bytes the generation can currently
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      hold. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  public abstract long capacity();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  /** The number of used bytes in the gen. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  public abstract long used();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  /** The number of free bytes in the gen. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  public abstract long free();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  /** The largest number of contiguous free words in the generation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      including expansion. (VM's version assumes it is called at a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      safepoint.)  */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  public abstract long contiguousAvailable();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  public MemRegion reserved() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    return new MemRegion(addr.addOffsetTo(reservedFieldOffset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  /** Returns a region guaranteed to contain all the objects in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      generation. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  public MemRegion usedRegion() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    return reserved();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  /* Returns "TRUE" iff "p" points into an allocated object in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
     generation. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  public boolean isIn(Address p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    GenerationIsInClosure blk = new GenerationIsInClosure(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    spaceIterate(blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    return (blk.space() != null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  /** Returns "TRUE" iff "p" points into the reserved area of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
     generation. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  public boolean isInReserved(Address p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    return reserved().contains(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  protected VirtualSpace virtualSpace() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    return (VirtualSpace) VMObjectFactory.newObject(VirtualSpace.class, addr.addOffsetTo(virtualSpaceFieldOffset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  public abstract String name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  /** Equivalent to spaceIterate(blk, false) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  public void spaceIterate(SpaceClosure blk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    spaceIterate(blk, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  /** Iteration - do not use for time critical operations */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  public abstract void spaceIterate(SpaceClosure blk, boolean usedOnly);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  public void print() { printOn(System.out); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  public abstract void printOn(PrintStream tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  public static class StatRecord extends VMObject {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    public StatRecord(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
      super(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    public int getInvocations() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
      return (int) invocationField.getValue(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  private StatRecord getStatRecord() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    return (StatRecord) VMObjectFactory.newObject(Generation.StatRecord.class, addr.addOffsetTo(statRecordField.getOffset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
}