hotspot/agent/src/share/classes/sun/jvm/hotspot/gc/shared/GenCollectedHeap.java
author pliden
Tue, 19 May 2015 09:41:52 +0200
changeset 30769 df60209aac9d
parent 30764 hotspot/agent/src/share/classes/sun/jvm/hotspot/memory/GenCollectedHeap.java@fec48bf5a827
permissions -rw-r--r--
8080581: Align SA with new GC directory structure Reviewed-by: dsamersoff, sla
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
29200
5e480434bef4 8061802: REDO - Remove the generations array
jwilhelm
parents: 27252
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: 30764
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
30154
39cd4e2ccf1c 8076452: Remove SharedHeap
brutisso
parents: 29794
diff changeset
    35
public class GenCollectedHeap extends CollectedHeap {
29200
5e480434bef4 8061802: REDO - Remove the generations array
jwilhelm
parents: 27252
diff changeset
    36
  private static AddressField youngGenField;
5e480434bef4 8061802: REDO - Remove the generations array
jwilhelm
parents: 27252
diff changeset
    37
  private static AddressField oldGenField;
29794
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
    38
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
    39
  private static AddressField youngGenSpecField;
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
    40
  private static AddressField oldGenSpecField;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  private static GenerationFactory genFactory;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  private static synchronized void initialize(TypeDataBase db) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    Type type = db.lookupType("GenCollectedHeap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
29200
5e480434bef4 8061802: REDO - Remove the generations array
jwilhelm
parents: 27252
diff changeset
    55
    youngGenField = type.getAddressField("_young_gen");
5e480434bef4 8061802: REDO - Remove the generations array
jwilhelm
parents: 27252
diff changeset
    56
    oldGenField = type.getAddressField("_old_gen");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    genFactory = new GenerationFactory();
29794
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
    59
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
    60
    Type collectorPolicyType = db.lookupType("GenCollectorPolicy");
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
    61
    youngGenSpecField = collectorPolicyType.getAddressField("_young_gen_spec");
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
    62
    oldGenSpecField = collectorPolicyType.getAddressField("_old_gen_spec");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  public GenCollectedHeap(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    super(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  public int nGens() {
30155
a3a254791703 8076267: Remove n_gens()
jwilhelm
parents: 30154
diff changeset
    70
    return 2; // Young + Old
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  public Generation getGen(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    if (Assert.ASSERTS_ENABLED) {
29200
5e480434bef4 8061802: REDO - Remove the generations array
jwilhelm
parents: 27252
diff changeset
    75
      Assert.that((i == 0) || (i == 1), "Index " + i +
5e480434bef4 8061802: REDO - Remove the generations array
jwilhelm
parents: 27252
diff changeset
    76
                  " out of range (should be 0 or 1)");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
29200
5e480434bef4 8061802: REDO - Remove the generations array
jwilhelm
parents: 27252
diff changeset
    79
    switch (i) {
5e480434bef4 8061802: REDO - Remove the generations array
jwilhelm
parents: 27252
diff changeset
    80
    case 0:
29202
bcce9add4235 8073532: jmap -heap fails after generation array removal
mgerdin
parents: 29200
diff changeset
    81
      return genFactory.newObject(youngGenField.getValue(addr));
29200
5e480434bef4 8061802: REDO - Remove the generations array
jwilhelm
parents: 27252
diff changeset
    82
    case 1:
29202
bcce9add4235 8073532: jmap -heap fails after generation array removal
mgerdin
parents: 29200
diff changeset
    83
      return genFactory.newObject(oldGenField.getValue(addr));
29200
5e480434bef4 8061802: REDO - Remove the generations array
jwilhelm
parents: 27252
diff changeset
    84
    default:
5e480434bef4 8061802: REDO - Remove the generations array
jwilhelm
parents: 27252
diff changeset
    85
      // no generation for i, and assertions disabled.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    }
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 boolean isIn(Address a) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    for (int i = 0; i < nGens(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      Generation gen = getGen(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      if (gen.isIn(a)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
        return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
    98
    return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  public long capacity() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    long capacity = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    for (int i = 0; i < nGens(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      capacity += getGen(i).capacity();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    return capacity;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  public long used() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    long used = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    for (int i = 0; i < nGens(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
      used += getGen(i).used();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    return used;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  /** Package-private access to GenerationSpecs */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  GenerationSpec spec(int level) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    if (Assert.ASSERTS_ENABLED) {
29794
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
   120
      Assert.that((level == 0) || (level == 1), "Index " + level +
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
   121
                  " out of range (should be 0 or 1)");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
29794
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
   124
    if ((level != 0) && (level != 1)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
29794
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
   128
    if (level == 0) {
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
   129
      return (GenerationSpec)
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
   130
              VMObjectFactory.newObject(GenerationSpec.class,
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
   131
                      youngGenSpecField.getAddress());
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
   132
    } else {
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
   133
      return (GenerationSpec)
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
   134
              VMObjectFactory.newObject(GenerationSpec.class,
2dcbd946f9a8 8075635: Remove GenerationSpec array
jwilhelm
parents: 29202
diff changeset
   135
                      oldGenSpecField.getAddress());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  public CollectedHeapName kind() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    return CollectedHeapName.GEN_COLLECTED_HEAP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  public void printOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    for (int i = 0; i < nGens(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      tty.print("Gen " + i + ": ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      getGen(i).printOn(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      tty.println("Invocations: " + getGen(i).invocations());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
}