1 /*
2 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
31 import sun.jvm.hotspot.runtime.*;
32
33 /** <P> The (supported) Generation hierarchy currently looks like this: </P>
34
35 <ul>
36 <li> Generation
37 <ul>
38 <li> CardGeneration
39 <ul>
40 <li> TenuredGeneration
41 </ul>
42 <li> DefNewGeneration
43 </ul>
44 </ul>
45 */
46
47
48 public abstract class Generation extends VMObject {
49 private static long reservedFieldOffset;
50 private static long virtualSpaceFieldOffset;
51 private static CIntegerField levelField;
52 protected static final int K = 1024;
53 // Fields for class StatRecord
54 private static Field statRecordField;
55 private static CIntegerField invocationField;
56
57 // constants from Name enum
58 private static int NAME_DEF_NEW;
59 private static int NAME_PAR_NEW;
60 private static int NAME_MARK_SWEEP_COMPACT;
61 private static int NAME_CONCURRENT_MARK_SWEEP;
62 private static int NAME_OTHER;
63
64 static {
65 VM.registerVMInitializedObserver(new Observer() {
66 public void update(Observable o, Object data) {
67 initialize(VM.getVM().getTypeDataBase());
68 }
69 });
70 }
71
72 private static synchronized void initialize(TypeDataBase db) {
73 Type type = db.lookupType("Generation");
74
75 reservedFieldOffset = type.getField("_reserved").getOffset();
76 virtualSpaceFieldOffset = type.getField("_virtual_space").getOffset();
77 levelField = type.getCIntegerField("_level");
78 // StatRecord
79 statRecordField = type.getField("_stat_record");
80 type = db.lookupType("Generation::StatRecord");
81 invocationField = type.getCIntegerField("invocations");
82
83 // constants from Generation::Name
84 NAME_DEF_NEW = db.lookupIntConstant("Generation::DefNew").intValue();
85 NAME_PAR_NEW = db.lookupIntConstant("Generation::ParNew").intValue();
86 NAME_MARK_SWEEP_COMPACT = db.lookupIntConstant("Generation::MarkSweepCompact").intValue();
87 NAME_CONCURRENT_MARK_SWEEP = db.lookupIntConstant("Generation::ConcurrentMarkSweep").intValue();
88 NAME_OTHER = db.lookupIntConstant("Generation::Other").intValue();
89 }
90
91 public Generation(Address addr) {
92 super(addr);
93 }
94
95 public static class Name {
96 public static final Name DEF_NEW = new Name("DefNew");
97 public static final Name PAR_NEW = new Name("ParNew");
112 public Generation.Name kind() {
113 return Generation.Name.OTHER;
114 }
115
116 static Generation.Name nameForEnum(int value) {
117 if (value == NAME_DEF_NEW) {
118 return Name.DEF_NEW;
119 } else if (value == NAME_PAR_NEW) {
120 return Name.PAR_NEW;
121 } else if (value == NAME_MARK_SWEEP_COMPACT) {
122 return Name.MARK_SWEEP_COMPACT;
123 } else if (value == NAME_CONCURRENT_MARK_SWEEP) {
124 return Name.CONCURRENT_MARK_SWEEP;
125 } else if (value == NAME_OTHER) {
126 return Name.OTHER;
127 } else {
128 throw new RuntimeException("should not reach here");
129 }
130 }
131
132 public GenerationSpec spec() {
133 return ((GenCollectedHeap) VM.getVM().getUniverse().heap()).spec(level());
134 }
135
136 public int level() {
137 return (int) levelField.getValue(addr);
138 }
139
140 public int invocations() {
141 return getStatRecord().getInvocations();
142 }
143
144 /** The maximum number of object bytes the generation can currently
145 hold. */
146 public abstract long capacity();
147
148 /** The number of used bytes in the gen. */
149 public abstract long used();
150
151 /** The number of free bytes in the gen. */
152 public abstract long free();
153
154 /** The largest number of contiguous free words in the generation,
155 including expansion. (VM's version assumes it is called at a
156 safepoint.) */
157 public abstract long contiguousAvailable();
158
159 public MemRegion reserved() {
|
1 /*
2 * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
31 import sun.jvm.hotspot.runtime.*;
32
33 /** <P> The (supported) Generation hierarchy currently looks like this: </P>
34
35 <ul>
36 <li> Generation
37 <ul>
38 <li> CardGeneration
39 <ul>
40 <li> TenuredGeneration
41 </ul>
42 <li> DefNewGeneration
43 </ul>
44 </ul>
45 */
46
47
48 public abstract class Generation extends VMObject {
49 private static long reservedFieldOffset;
50 private static long virtualSpaceFieldOffset;
51 protected static final int K = 1024;
52 // Fields for class StatRecord
53 private static Field statRecordField;
54 private static CIntegerField invocationField;
55
56 // constants from Name enum
57 private static int NAME_DEF_NEW;
58 private static int NAME_PAR_NEW;
59 private static int NAME_MARK_SWEEP_COMPACT;
60 private static int NAME_CONCURRENT_MARK_SWEEP;
61 private static int NAME_OTHER;
62
63 static {
64 VM.registerVMInitializedObserver(new Observer() {
65 public void update(Observable o, Object data) {
66 initialize(VM.getVM().getTypeDataBase());
67 }
68 });
69 }
70
71 private static synchronized void initialize(TypeDataBase db) {
72 Type type = db.lookupType("Generation");
73
74 reservedFieldOffset = type.getField("_reserved").getOffset();
75 virtualSpaceFieldOffset = type.getField("_virtual_space").getOffset();
76 // StatRecord
77 statRecordField = type.getField("_stat_record");
78 type = db.lookupType("Generation::StatRecord");
79 invocationField = type.getCIntegerField("invocations");
80
81 // constants from Generation::Name
82 NAME_DEF_NEW = db.lookupIntConstant("Generation::DefNew").intValue();
83 NAME_PAR_NEW = db.lookupIntConstant("Generation::ParNew").intValue();
84 NAME_MARK_SWEEP_COMPACT = db.lookupIntConstant("Generation::MarkSweepCompact").intValue();
85 NAME_CONCURRENT_MARK_SWEEP = db.lookupIntConstant("Generation::ConcurrentMarkSweep").intValue();
86 NAME_OTHER = db.lookupIntConstant("Generation::Other").intValue();
87 }
88
89 public Generation(Address addr) {
90 super(addr);
91 }
92
93 public static class Name {
94 public static final Name DEF_NEW = new Name("DefNew");
95 public static final Name PAR_NEW = new Name("ParNew");
110 public Generation.Name kind() {
111 return Generation.Name.OTHER;
112 }
113
114 static Generation.Name nameForEnum(int value) {
115 if (value == NAME_DEF_NEW) {
116 return Name.DEF_NEW;
117 } else if (value == NAME_PAR_NEW) {
118 return Name.PAR_NEW;
119 } else if (value == NAME_MARK_SWEEP_COMPACT) {
120 return Name.MARK_SWEEP_COMPACT;
121 } else if (value == NAME_CONCURRENT_MARK_SWEEP) {
122 return Name.CONCURRENT_MARK_SWEEP;
123 } else if (value == NAME_OTHER) {
124 return Name.OTHER;
125 } else {
126 throw new RuntimeException("should not reach here");
127 }
128 }
129
130 public int invocations() {
131 return getStatRecord().getInvocations();
132 }
133
134 /** The maximum number of object bytes the generation can currently
135 hold. */
136 public abstract long capacity();
137
138 /** The number of used bytes in the gen. */
139 public abstract long used();
140
141 /** The number of free bytes in the gen. */
142 public abstract long free();
143
144 /** The largest number of contiguous free words in the generation,
145 including expansion. (VM's version assumes it is called at a
146 safepoint.) */
147 public abstract long contiguousAvailable();
148
149 public MemRegion reserved() {
|