author | brutisso |
Thu, 02 Apr 2015 16:08:41 +0200 | |
changeset 30154 | 39cd4e2ccf1c |
parent 29794 | 2dcbd946f9a8 |
child 30155 | a3a254791703 |
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 |
||
25 |
package sun.jvm.hotspot.memory; |
|
26 |
||
27 |
import java.io.*; |
|
28 |
import java.util.*; |
|
29 |
||
30 |
import sun.jvm.hotspot.debugger.*; |
|
31 |
import sun.jvm.hotspot.gc_interface.*; |
|
32 |
import sun.jvm.hotspot.runtime.*; |
|
33 |
import sun.jvm.hotspot.types.*; |
|
34 |
import sun.jvm.hotspot.utilities.*; |
|
35 |
||
30154 | 36 |
public class GenCollectedHeap extends CollectedHeap { |
1 | 37 |
private static CIntegerField nGensField; |
29200 | 38 |
private static AddressField youngGenField; |
39 |
private static AddressField oldGenField; |
|
29794 | 40 |
|
41 |
private static AddressField youngGenSpecField; |
|
42 |
private static AddressField oldGenSpecField; |
|
1 | 43 |
|
44 |
private static GenerationFactory genFactory; |
|
45 |
||
46 |
static { |
|
47 |
VM.registerVMInitializedObserver(new Observer() { |
|
48 |
public void update(Observable o, Object data) { |
|
49 |
initialize(VM.getVM().getTypeDataBase()); |
|
50 |
} |
|
51 |
}); |
|
52 |
} |
|
53 |
||
54 |
private static synchronized void initialize(TypeDataBase db) { |
|
55 |
Type type = db.lookupType("GenCollectedHeap"); |
|
56 |
||
57 |
nGensField = type.getCIntegerField("_n_gens"); |
|
29200 | 58 |
youngGenField = type.getAddressField("_young_gen"); |
59 |
oldGenField = type.getAddressField("_old_gen"); |
|
1 | 60 |
|
61 |
genFactory = new GenerationFactory(); |
|
29794 | 62 |
|
63 |
Type collectorPolicyType = db.lookupType("GenCollectorPolicy"); |
|
64 |
youngGenSpecField = collectorPolicyType.getAddressField("_young_gen_spec"); |
|
65 |
oldGenSpecField = collectorPolicyType.getAddressField("_old_gen_spec"); |
|
1 | 66 |
} |
67 |
||
68 |
public GenCollectedHeap(Address addr) { |
|
69 |
super(addr); |
|
70 |
} |
|
71 |
||
72 |
public int nGens() { |
|
73 |
return (int) nGensField.getValue(addr); |
|
74 |
} |
|
75 |
||
76 |
public Generation getGen(int i) { |
|
77 |
if (Assert.ASSERTS_ENABLED) { |
|
29200 | 78 |
Assert.that((i == 0) || (i == 1), "Index " + i + |
79 |
" out of range (should be 0 or 1)"); |
|
1 | 80 |
} |
81 |
||
29200 | 82 |
switch (i) { |
83 |
case 0: |
|
29202
bcce9add4235
8073532: jmap -heap fails after generation array removal
mgerdin
parents:
29200
diff
changeset
|
84 |
return genFactory.newObject(youngGenField.getValue(addr)); |
29200 | 85 |
case 1: |
29202
bcce9add4235
8073532: jmap -heap fails after generation array removal
mgerdin
parents:
29200
diff
changeset
|
86 |
return genFactory.newObject(oldGenField.getValue(addr)); |
29200 | 87 |
default: |
88 |
// no generation for i, and assertions disabled. |
|
1 | 89 |
return null; |
90 |
} |
|
91 |
} |
|
92 |
||
93 |
public boolean isIn(Address a) { |
|
94 |
for (int i = 0; i < nGens(); i++) { |
|
95 |
Generation gen = getGen(i); |
|
96 |
if (gen.isIn(a)) { |
|
97 |
return true; |
|
98 |
} |
|
99 |
} |
|
100 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5547
diff
changeset
|
101 |
return false; |
1 | 102 |
} |
103 |
||
104 |
public long capacity() { |
|
105 |
long capacity = 0; |
|
106 |
for (int i = 0; i < nGens(); i++) { |
|
107 |
capacity += getGen(i).capacity(); |
|
108 |
} |
|
109 |
return capacity; |
|
110 |
} |
|
111 |
||
112 |
public long used() { |
|
113 |
long used = 0; |
|
114 |
for (int i = 0; i < nGens(); i++) { |
|
115 |
used += getGen(i).used(); |
|
116 |
} |
|
117 |
return used; |
|
118 |
} |
|
119 |
||
120 |
/** Package-private access to GenerationSpecs */ |
|
121 |
GenerationSpec spec(int level) { |
|
122 |
if (Assert.ASSERTS_ENABLED) { |
|
29794 | 123 |
Assert.that((level == 0) || (level == 1), "Index " + level + |
124 |
" out of range (should be 0 or 1)"); |
|
1 | 125 |
} |
126 |
||
29794 | 127 |
if ((level != 0) && (level != 1)) { |
1 | 128 |
return null; |
129 |
} |
|
130 |
||
29794 | 131 |
if (level == 0) { |
132 |
return (GenerationSpec) |
|
133 |
VMObjectFactory.newObject(GenerationSpec.class, |
|
134 |
youngGenSpecField.getAddress()); |
|
135 |
} else { |
|
136 |
return (GenerationSpec) |
|
137 |
VMObjectFactory.newObject(GenerationSpec.class, |
|
138 |
oldGenSpecField.getAddress()); |
|
1 | 139 |
} |
140 |
} |
|
141 |
||
142 |
public CollectedHeapName kind() { |
|
143 |
return CollectedHeapName.GEN_COLLECTED_HEAP; |
|
144 |
} |
|
145 |
||
146 |
public void printOn(PrintStream tty) { |
|
147 |
for (int i = 0; i < nGens(); i++) { |
|
148 |
tty.print("Gen " + i + ": "); |
|
149 |
getGen(i).printOn(tty); |
|
150 |
tty.println("Invocations: " + getGen(i).invocations()); |
|
151 |
tty.println(); |
|
152 |
} |
|
153 |
} |
|
154 |
} |