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-- |
1 | 1 |
/* |
29200 | 2 |
* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
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 | 22 |
* |
23 |
*/ |
|
24 |
||
30769 | 25 |
package sun.jvm.hotspot.gc.shared; |
1 | 26 |
|
27 |
import java.io.*; |
|
28 |
import java.util.*; |
|
29 |
||
30 |
import sun.jvm.hotspot.debugger.*; |
|
31 |
import sun.jvm.hotspot.runtime.*; |
|
32 |
import sun.jvm.hotspot.types.*; |
|
33 |
import sun.jvm.hotspot.utilities.*; |
|
34 |
||
30154 | 35 |
public class GenCollectedHeap extends CollectedHeap { |
29200 | 36 |
private static AddressField youngGenField; |
37 |
private static AddressField oldGenField; |
|
29794 | 38 |
|
39 |
private static AddressField youngGenSpecField; |
|
40 |
private static AddressField oldGenSpecField; |
|
1 | 41 |
|
42 |
private static GenerationFactory genFactory; |
|
43 |
||
44 |
static { |
|
45 |
VM.registerVMInitializedObserver(new Observer() { |
|
46 |
public void update(Observable o, Object data) { |
|
47 |
initialize(VM.getVM().getTypeDataBase()); |
|
48 |
} |
|
49 |
}); |
|
50 |
} |
|
51 |
||
52 |
private static synchronized void initialize(TypeDataBase db) { |
|
53 |
Type type = db.lookupType("GenCollectedHeap"); |
|
54 |
||
29200 | 55 |
youngGenField = type.getAddressField("_young_gen"); |
56 |
oldGenField = type.getAddressField("_old_gen"); |
|
1 | 57 |
|
58 |
genFactory = new GenerationFactory(); |
|
29794 | 59 |
|
60 |
Type collectorPolicyType = db.lookupType("GenCollectorPolicy"); |
|
61 |
youngGenSpecField = collectorPolicyType.getAddressField("_young_gen_spec"); |
|
62 |
oldGenSpecField = collectorPolicyType.getAddressField("_old_gen_spec"); |
|
1 | 63 |
} |
64 |
||
65 |
public GenCollectedHeap(Address addr) { |
|
66 |
super(addr); |
|
67 |
} |
|
68 |
||
69 |
public int nGens() { |
|
30155 | 70 |
return 2; // Young + Old |
1 | 71 |
} |
72 |
||
73 |
public Generation getGen(int i) { |
|
74 |
if (Assert.ASSERTS_ENABLED) { |
|
29200 | 75 |
Assert.that((i == 0) || (i == 1), "Index " + i + |
76 |
" out of range (should be 0 or 1)"); |
|
1 | 77 |
} |
78 |
||
29200 | 79 |
switch (i) { |
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 | 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 | 84 |
default: |
85 |
// no generation for i, and assertions disabled. |
|
1 | 86 |
return null; |
87 |
} |
|
88 |
} |
|
89 |
||
90 |
public boolean isIn(Address a) { |
|
91 |
for (int i = 0; i < nGens(); i++) { |
|
92 |
Generation gen = getGen(i); |
|
93 |
if (gen.isIn(a)) { |
|
94 |
return true; |
|
95 |
} |
|
96 |
} |
|
97 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5547
diff
changeset
|
98 |
return false; |
1 | 99 |
} |
100 |
||
101 |
public long capacity() { |
|
102 |
long capacity = 0; |
|
103 |
for (int i = 0; i < nGens(); i++) { |
|
104 |
capacity += getGen(i).capacity(); |
|
105 |
} |
|
106 |
return capacity; |
|
107 |
} |
|
108 |
||
109 |
public long used() { |
|
110 |
long used = 0; |
|
111 |
for (int i = 0; i < nGens(); i++) { |
|
112 |
used += getGen(i).used(); |
|
113 |
} |
|
114 |
return used; |
|
115 |
} |
|
116 |
||
117 |
/** Package-private access to GenerationSpecs */ |
|
118 |
GenerationSpec spec(int level) { |
|
119 |
if (Assert.ASSERTS_ENABLED) { |
|
29794 | 120 |
Assert.that((level == 0) || (level == 1), "Index " + level + |
121 |
" out of range (should be 0 or 1)"); |
|
1 | 122 |
} |
123 |
||
29794 | 124 |
if ((level != 0) && (level != 1)) { |
1 | 125 |
return null; |
126 |
} |
|
127 |
||
29794 | 128 |
if (level == 0) { |
129 |
return (GenerationSpec) |
|
130 |
VMObjectFactory.newObject(GenerationSpec.class, |
|
131 |
youngGenSpecField.getAddress()); |
|
132 |
} else { |
|
133 |
return (GenerationSpec) |
|
134 |
VMObjectFactory.newObject(GenerationSpec.class, |
|
135 |
oldGenSpecField.getAddress()); |
|
1 | 136 |
} |
137 |
} |
|
138 |
||
139 |
public CollectedHeapName kind() { |
|
140 |
return CollectedHeapName.GEN_COLLECTED_HEAP; |
|
141 |
} |
|
142 |
||
143 |
public void printOn(PrintStream tty) { |
|
144 |
for (int i = 0; i < nGens(); i++) { |
|
145 |
tty.print("Gen " + i + ": "); |
|
146 |
getGen(i).printOn(tty); |
|
147 |
tty.println("Invocations: " + getGen(i).invocations()); |
|
148 |
tty.println(); |
|
149 |
} |
|
150 |
} |
|
151 |
} |