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 *
23 */
24
25 #ifndef SHARE_VM_GC_G1_G1MONITORINGSUPPORT_HPP
26 #define SHARE_VM_GC_G1_G1MONITORINGSUPPORT_HPP
27
28 #include "gc/shared/collectorCounters.hpp"
29 #include "gc/shared/generationCounters.hpp"
30 #include "services/memoryManager.hpp"
31 #include "services/memoryService.hpp"
32
33 class CollectorCounters;
34 class G1CollectedHeap;
35 class HSpaceCounters;
36 class MemoryPool;
37
38 // Class for monitoring logical spaces in G1. It provides data for
39 // both G1's jstat counters as well as G1's memory pools.
40 //
41 // G1 splits the heap into heap regions and each heap region belongs
42 // to one of the following categories:
43 //
44 // * eden : regions that have been allocated since the last GC
45 // * survivors : regions with objects that survived the last few GCs
46 // * old : long-lived non-humongous regions
47 // * humongous : humongous regions
48 // * free : free regions
49 //
50 // The combination of eden and survivor regions form the equivalent of
51 // the young generation in the other GCs. The combination of old and
107 //
108 // If we had more accurate occupancy / capacity information per
109 // region set the above calculations would be greatly simplified and
110 // be made more accurate.
111 //
112 // We update all the above synchronously and we store the results in
113 // fields so that we just read said fields when needed. A subtle point
114 // is that all the above sizes need to be recalculated when the old
115 // gen changes capacity (after a GC or after a humongous allocation)
116 // but only the eden occupancy changes when a new eden region is
117 // allocated. So, in the latter case we have minimal recalculation to
118 // do which is important as we want to keep the eden region allocation
119 // path as low-overhead as possible.
120
121 class G1MonitoringSupport : public CHeapObj<mtGC> {
122 friend class VMStructs;
123 friend class G1MonitoringScope;
124
125 G1CollectedHeap* _g1h;
126
127 // java.lang.management MemoryManager and MemoryPool support
128 GCMemoryManager _incremental_memory_manager;
129 GCMemoryManager _full_gc_memory_manager;
130
131 MemoryPool* _eden_pool;
132 MemoryPool* _survivor_pool;
133 MemoryPool* _old_pool;
134
135 // jstat performance counters
136 // incremental collections both young and mixed
137 CollectorCounters* _incremental_collection_counters;
138 // full stop-the-world collections
139 CollectorCounters* _full_collection_counters;
140 // stop-the-world phases in G1
141 CollectorCounters* _conc_collection_counters;
142 // young collection set counters. The _eden_counters,
143 // _from_counters, and _to_counters are associated with
144 // this "generational" counter.
145 GenerationCounters* _young_gen_counters;
146 // old collection set counters. The _old_space_counters
181 // going negative (which would mean a very large result, given that
182 // the parameter are size_t).
183 static size_t subtract_up_to_zero(size_t x, size_t y) {
184 if (x > y) {
185 return x - y;
186 } else {
187 return 0;
188 }
189 }
190
191 // Recalculate all the sizes.
192 void recalculate_sizes();
193
194 void recalculate_eden_size();
195
196 public:
197 G1MonitoringSupport(G1CollectedHeap* g1h);
198 ~G1MonitoringSupport();
199
200 void initialize_serviceability();
201 GrowableArray<GCMemoryManager*> memory_managers();
202 GrowableArray<MemoryPool*> memory_pools();
203
204 // Unfortunately, the jstat tool assumes that no space has 0
205 // capacity. In our case, given that each space is logical, it's
206 // possible that no regions will be allocated to it, hence to have 0
207 // capacity (e.g., if there are no survivor regions, the survivor
208 // space has 0 capacity). The way we deal with this is to always pad
209 // each capacity value we report to jstat by a very small amount to
210 // make sure that it's never zero. Given that we sometimes have to
211 // report a capacity of a generation that contains several spaces
212 // (e.g., young gen includes one eden, two survivor spaces), the
213 // mult parameter is provided in order to adding the appropriate
214 // padding multiple times so that the capacities add up correctly.
215 static size_t pad_capacity(size_t size_bytes, size_t mult = 1) {
216 return size_bytes + MinObjAlignmentInBytes * mult;
217 }
218
219 // Recalculate all the sizes from scratch and update all the jstat
220 // counters accordingly.
221 void update_sizes();
222
223 void update_eden_size();
224
225 CollectorCounters* conc_collection_counters() {
226 return _conc_collection_counters;
227 }
228
229 // Monitoring support used by
230 // MemoryService
231 // jstat counters
232 // Tracing
233
234 size_t young_gen_committed() { return _young_gen_committed; }
235
236 size_t eden_space_committed() { return _eden_space_committed; }
237 size_t eden_space_used() { return _eden_space_used; }
238 size_t survivor_space_committed() { return _survivor_space_committed; }
239 size_t survivor_space_used() { return _survivor_space_used; }
240
241 size_t old_gen_committed() { return _old_gen_committed; }
242 size_t old_gen_used() { return _old_gen_used; }
243 };
244
245 // Scope object for java.lang.management support.
246 class G1MonitoringScope : public StackObj {
247 TraceCollectorStats _tcs;
248 TraceMemoryManagerStats _tms;
249 public:
250 G1MonitoringScope(G1MonitoringSupport* g1mm, bool full_gc, bool all_memory_pools_affected);
251 };
252
253 #endif // SHARE_VM_GC_G1_G1MONITORINGSUPPORT_HPP
|
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 *
23 */
24
25 #ifndef SHARE_VM_GC_G1_G1MONITORINGSUPPORT_HPP
26 #define SHARE_VM_GC_G1_G1MONITORINGSUPPORT_HPP
27
28 #include "gc/shared/collectorCounters.hpp"
29 #include "gc/shared/generationCounters.hpp"
30 #include "services/memoryManager.hpp"
31 #include "services/memoryService.hpp"
32 #include "runtime/mutex.hpp"
33
34 class CollectorCounters;
35 class G1CollectedHeap;
36 class HSpaceCounters;
37 class MemoryPool;
38
39 // Class for monitoring logical spaces in G1. It provides data for
40 // both G1's jstat counters as well as G1's memory pools.
41 //
42 // G1 splits the heap into heap regions and each heap region belongs
43 // to one of the following categories:
44 //
45 // * eden : regions that have been allocated since the last GC
46 // * survivors : regions with objects that survived the last few GCs
47 // * old : long-lived non-humongous regions
48 // * humongous : humongous regions
49 // * free : free regions
50 //
51 // The combination of eden and survivor regions form the equivalent of
52 // the young generation in the other GCs. The combination of old and
108 //
109 // If we had more accurate occupancy / capacity information per
110 // region set the above calculations would be greatly simplified and
111 // be made more accurate.
112 //
113 // We update all the above synchronously and we store the results in
114 // fields so that we just read said fields when needed. A subtle point
115 // is that all the above sizes need to be recalculated when the old
116 // gen changes capacity (after a GC or after a humongous allocation)
117 // but only the eden occupancy changes when a new eden region is
118 // allocated. So, in the latter case we have minimal recalculation to
119 // do which is important as we want to keep the eden region allocation
120 // path as low-overhead as possible.
121
122 class G1MonitoringSupport : public CHeapObj<mtGC> {
123 friend class VMStructs;
124 friend class G1MonitoringScope;
125
126 G1CollectedHeap* _g1h;
127
128 Mutex _update_mutex;
129
130 // java.lang.management MemoryManager and MemoryPool support
131 GCMemoryManager _incremental_memory_manager;
132 GCMemoryManager _full_gc_memory_manager;
133
134 MemoryPool* _eden_pool;
135 MemoryPool* _survivor_pool;
136 MemoryPool* _old_pool;
137
138 // jstat performance counters
139 // incremental collections both young and mixed
140 CollectorCounters* _incremental_collection_counters;
141 // full stop-the-world collections
142 CollectorCounters* _full_collection_counters;
143 // stop-the-world phases in G1
144 CollectorCounters* _conc_collection_counters;
145 // young collection set counters. The _eden_counters,
146 // _from_counters, and _to_counters are associated with
147 // this "generational" counter.
148 GenerationCounters* _young_gen_counters;
149 // old collection set counters. The _old_space_counters
184 // going negative (which would mean a very large result, given that
185 // the parameter are size_t).
186 static size_t subtract_up_to_zero(size_t x, size_t y) {
187 if (x > y) {
188 return x - y;
189 } else {
190 return 0;
191 }
192 }
193
194 // Recalculate all the sizes.
195 void recalculate_sizes();
196
197 void recalculate_eden_size();
198
199 public:
200 G1MonitoringSupport(G1CollectedHeap* g1h);
201 ~G1MonitoringSupport();
202
203 void initialize_serviceability();
204
205 MemoryUsage memory_usage();
206 GrowableArray<GCMemoryManager*> memory_managers();
207 GrowableArray<MemoryPool*> memory_pools();
208
209 // Unfortunately, the jstat tool assumes that no space has 0
210 // capacity. In our case, given that each space is logical, it's
211 // possible that no regions will be allocated to it, hence to have 0
212 // capacity (e.g., if there are no survivor regions, the survivor
213 // space has 0 capacity). The way we deal with this is to always pad
214 // each capacity value we report to jstat by a very small amount to
215 // make sure that it's never zero. Given that we sometimes have to
216 // report a capacity of a generation that contains several spaces
217 // (e.g., young gen includes one eden, two survivor spaces), the
218 // mult parameter is provided in order to adding the appropriate
219 // padding multiple times so that the capacities add up correctly.
220 static size_t pad_capacity(size_t size_bytes, size_t mult = 1) {
221 return size_bytes + MinObjAlignmentInBytes * mult;
222 }
223
224 // Recalculate all the sizes from scratch and update all the jstat
225 // counters accordingly.
226 void update_sizes();
227
228 void update_eden_size();
229
230 CollectorCounters* conc_collection_counters() {
231 return _conc_collection_counters;
232 }
233
234 // Monitoring support used by
235 // MemoryService
236 // jstat counters
237 // Tracing
238 // Values may not be consistent wrt to each other.
239
240 size_t young_gen_committed() { return _young_gen_committed; }
241
242 size_t eden_space_used() { return _eden_space_used; }
243 size_t survivor_space_used() { return _survivor_space_used; }
244
245 size_t old_gen_committed() { return _old_gen_committed; }
246 size_t old_gen_used() { return _old_gen_used; }
247
248 // Monitoring support for MemoryPools. Values in the returned MemoryUsage are
249 // guaranteed to be consistent with each other.
250 MemoryUsage eden_space_memory_usage(size_t initial_size, size_t max_size);
251 MemoryUsage survivor_space_memory_usage(size_t initial_size, size_t max_size);
252
253 MemoryUsage old_gen_memory_usage(size_t initial_size, size_t max_size);
254 };
255
256 // Scope object for java.lang.management support.
257 class G1MonitoringScope : public StackObj {
258 TraceCollectorStats _tcs;
259 TraceMemoryManagerStats _tms;
260 public:
261 G1MonitoringScope(G1MonitoringSupport* g1mm, bool full_gc, bool all_memory_pools_affected);
262 };
263
264 #endif // SHARE_VM_GC_G1_G1MONITORINGSUPPORT_HPP
|