comparison src/share/vm/gc_implementation/g1/g1MonitoringSupport.hpp @ 3980:8229bd737950

7075646: G1: fix inconsistencies in the monitoring data Summary: Fixed a few inconsistencies in the monitoring data, in particular when reported from jstat. Reviewed-by: jmasa, brutisso, johnc
author tonyp
date Fri, 23 Sep 2011 16:07:49 -0400
parents b52782ae3880
children 81aa07130d30
comparison
equal deleted inserted replaced
3979:4dfb2df418f2 3980:8229bd737950
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1MONITORINGSUPPORT_HPP 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1MONITORINGSUPPORT_HPP
27 27
28 #include "gc_implementation/shared/hSpaceCounters.hpp" 28 #include "gc_implementation/shared/hSpaceCounters.hpp"
29 29
30 class G1CollectedHeap; 30 class G1CollectedHeap;
31 class G1SpaceMonitoringSupport; 31
32 32 // Class for monitoring logical spaces in G1. It provides data for
33 // Class for monitoring logical spaces in G1. 33 // both G1's jstat counters as well as G1's memory pools.
34 // G1 defines a set of regions as a young 34 //
35 // collection (analogous to a young generation). 35 // G1 splits the heap into heap regions and each heap region belongs
36 // The young collection is a logical generation 36 // to one of the following categories:
37 // with no fixed chunk (see space.hpp) reflecting 37 //
38 // the address space for the generation. In addition 38 // * eden : regions that have been allocated since the last GC
39 // to the young collection there is its complement 39 // * survivors : regions with objects that survived the last few GCs
40 // the non-young collection that is simply the regions 40 // * old : long-lived non-humongous regions
41 // not in the young collection. The non-young collection 41 // * humongous : humongous regions
42 // is treated here as a logical old generation only 42 // * free : free regions
43 // because the monitoring tools expect a generational 43 //
44 // heap. The monitoring tools expect that a Space 44 // The combination of eden and survivor regions form the equivalent of
45 // (see space.hpp) exists that describe the 45 // the young generation in the other GCs. The combination of old and
46 // address space of young collection and non-young 46 // humongous regions form the equivalent of the old generation in the
47 // collection and such a view is provided here. 47 // other GCs. Free regions do not have a good equivalent in the other
48 // 48 // GCs given that they can be allocated as any of the other region types.
49 // This class provides interfaces to access 49 //
50 // the value of variables for the young collection 50 // The monitoring tools expect the heap to contain a number of
51 // that include the "capacity" and "used" of the 51 // generations (young, old, perm) and each generation to contain a
52 // young collection along with constant values 52 // number of spaces (young: eden, survivors, old). Given that G1 does
53 // for the minimum and maximum capacities for 53 // not maintain those spaces physically (e.g., the set of
54 // the logical spaces. Similarly for the non-young 54 // non-contiguous eden regions can be considered as a "logical"
55 // collection. 55 // space), we'll provide the illusion that those generations and
56 // 56 // spaces exist. In reality, each generation and space refers to a set
57 // Also provided are counters for G1 concurrent collections 57 // of heap regions that are potentially non-contiguous.
58 // and stop-the-world full heap collecitons. 58 //
59 // 59 // This class provides interfaces to access the min, current, and max
60 // Below is a description of how "used" and "capactiy" 60 // capacity and current occupancy for each of G1's logical spaces and
61 // (or committed) is calculated for the logical spaces. 61 // generations we expose to the monitoring tools. Also provided are
62 // 62 // counters for G1 concurrent collections and stop-the-world full heap
63 // 1) The used space calculation for a pool is not necessarily 63 // collections.
64 // independent of the others. We can easily get from G1 the overall 64 //
65 // used space in the entire heap, the number of regions in the young 65 // Below is a description of how the various sizes are calculated.
66 // generation (includes both eden and survivors), and the number of 66 //
67 // survivor regions. So, from that we calculate: 67 // * Current Capacity
68 // 68 //
69 // survivor_used = survivor_num * region_size 69 // - heap_capacity = current heap capacity (e.g., current committed size)
70 // eden_used = young_region_num * region_size - survivor_used 70 // - young_gen_capacity = current max young gen target capacity
71 // old_gen_used = overall_used - eden_used - survivor_used 71 // (i.e., young gen target capacity + max allowed expansion capacity)
72 // 72 // - survivor_capacity = current survivor region capacity
73 // Note that survivor_used and eden_used are upper bounds. To get the 73 // - eden_capacity = young_gen_capacity - survivor_capacity
74 // actual value we would have to iterate over the regions and add up 74 // - old_capacity = heap_capacity - young_gen_capacity
75 // ->used(). But that'd be expensive. So, we'll accept some lack of 75 //
76 // accuracy for those two. But, we have to be careful when calculating 76 // What we do in the above is to distribute the free regions among
77 // old_gen_used, in case we subtract from overall_used more then the 77 // eden_capacity and old_capacity.
78 // actual number and our result goes negative. 78 //
79 // 79 // * Occupancy
80 // 2) Calculating the used space is straightforward, as described 80 //
81 // above. However, how do we calculate the committed space, given that 81 // - young_gen_used = current young region capacity
82 // we allocate space for the eden, survivor, and old gen out of the 82 // - survivor_used = survivor_capacity
83 // same pool of regions? One way to do this is to use the used value 83 // - eden_used = young_gen_used - survivor_used
84 // as also the committed value for the eden and survivor spaces and 84 // - old_used = overall_used - young_gen_used
85 // then calculate the old gen committed space as follows: 85 //
86 // 86 // Unfortunately, we currently only keep track of the number of
87 // old_gen_committed = overall_committed - eden_committed - survivor_committed 87 // currently allocated young and survivor regions + the overall used
88 // 88 // bytes in the heap, so the above can be a little inaccurate.
89 // Maybe a better way to do that would be to calculate used for eden 89 //
90 // and survivor as a sum of ->used() over their regions and then 90 // * Min Capacity
91 // calculate committed as region_num * region_size (i.e., what we use 91 //
92 // to calculate the used space now). This is something to consider 92 // We set this to 0 for all spaces. We could consider setting the old
93 // in the future. 93 // min capacity to the min capacity of the heap (see 7078465).
94 // 94 //
95 // 3) Another decision that is again not straightforward is what is 95 // * Max Capacity
96 // the max size that each memory pool can grow to. One way to do this 96 //
97 // would be to use the committed size for the max for the eden and 97 // For jstat, we set the max capacity of all spaces to heap_capacity,
98 // survivors and calculate the old gen max as follows (basically, it's 98 // given that we don't always have a reasonably upper bound on how big
99 // a similar pattern to what we use for the committed space, as 99 // each space can grow. For the memory pools, we actually make the max
100 // described above): 100 // capacity undefined. We could consider setting the old max capacity
101 // 101 // to the max capacity of the heap (see 7078465).
102 // old_gen_max = overall_max - eden_max - survivor_max 102 //
103 // 103 // If we had more accurate occupancy / capacity information per
104 // Unfortunately, the above makes the max of each pool fluctuate over 104 // region set the above calculations would be greatly simplified and
105 // time and, even though this is allowed according to the spec, it 105 // be made more accurate.
106 // broke several assumptions in the M&M framework (there were cases 106 //
107 // where used would reach a value greater than max). So, for max we 107 // We update all the above synchronously and we store the results in
108 // use -1, which means "undefined" according to the spec. 108 // fields so that we just read said fields when needed. A subtle point
109 // 109 // is that all the above sizes need to be recalculated when the old
110 // 4) Now, there is a very subtle issue with all the above. The 110 // gen changes capacity (after a GC or after a humongous allocation)
111 // framework will call get_memory_usage() on the three pools 111 // but only the eden occupancy changes when a new eden region is
112 // asynchronously. As a result, each call might get a different value 112 // allocated. So, in the latter case we have minimal recalcuation to
113 // for, say, survivor_num which will yield inconsistent values for 113 // do which is important as we want to keep the eden region allocation
114 // eden_used, survivor_used, and old_gen_used (as survivor_num is used 114 // path as low-overhead as possible.
115 // in the calculation of all three). This would normally be
116 // ok. However, it's possible that this might cause the sum of
117 // eden_used, survivor_used, and old_gen_used to go over the max heap
118 // size and this seems to sometimes cause JConsole (and maybe other
119 // clients) to get confused. There's not a really an easy / clean
120 // solution to this problem, due to the asynchrounous nature of the
121 // framework.
122 115
123 class G1MonitoringSupport : public CHeapObj { 116 class G1MonitoringSupport : public CHeapObj {
124 G1CollectedHeap* _g1h; 117 G1CollectedHeap* _g1h;
125 VirtualSpace* _g1_storage_addr;
126 118
127 // jstat performance counters 119 // jstat performance counters
128 // incremental collections both fully and partially young 120 // incremental collections both fully and partially young
129 CollectorCounters* _incremental_collection_counters; 121 CollectorCounters* _incremental_collection_counters;
130 // full stop-the-world collections 122 // full stop-the-world collections
131 CollectorCounters* _full_collection_counters; 123 CollectorCounters* _full_collection_counters;
132 // young collection set counters. The _eden_counters, 124 // young collection set counters. The _eden_counters,
133 // _from_counters, and _to_counters are associated with 125 // _from_counters, and _to_counters are associated with
134 // this "generational" counter. 126 // this "generational" counter.
135 GenerationCounters* _young_collection_counters; 127 GenerationCounters* _young_collection_counters;
136 // non-young collection set counters. The _old_space_counters 128 // old collection set counters. The _old_space_counters
137 // below are associated with this "generational" counter. 129 // below are associated with this "generational" counter.
138 GenerationCounters* _non_young_collection_counters; 130 GenerationCounters* _old_collection_counters;
139 // Counters for the capacity and used for 131 // Counters for the capacity and used for
140 // the whole heap 132 // the whole heap
141 HSpaceCounters* _old_space_counters; 133 HSpaceCounters* _old_space_counters;
142 // the young collection 134 // the young collection
143 HSpaceCounters* _eden_counters; 135 HSpaceCounters* _eden_counters;
144 // the survivor collection (only one, _to_counters, is actively used) 136 // the survivor collection (only one, _to_counters, is actively used)
145 HSpaceCounters* _from_counters; 137 HSpaceCounters* _from_counters;
146 HSpaceCounters* _to_counters; 138 HSpaceCounters* _to_counters;
139
140 // When it's appropriate to recalculate the various sizes (at the
141 // end of a GC, when a new eden region is allocated, etc.) we store
142 // them here so that we can easily report them when needed and not
143 // have to recalculate them every time.
144
145 size_t _overall_reserved;
146 size_t _overall_committed;
147 size_t _overall_used;
148
149 size_t _young_region_num;
150 size_t _young_gen_committed;
151 size_t _eden_committed;
152 size_t _eden_used;
153 size_t _survivor_committed;
154 size_t _survivor_used;
155
156 size_t _old_committed;
157 size_t _old_used;
158
159 G1CollectedHeap* g1h() { return _g1h; }
147 160
148 // It returns x - y if x > y, 0 otherwise. 161 // It returns x - y if x > y, 0 otherwise.
149 // As described in the comment above, some of the inputs to the 162 // As described in the comment above, some of the inputs to the
150 // calculations we have to do are obtained concurrently and hence 163 // calculations we have to do are obtained concurrently and hence
151 // may be inconsistent with each other. So, this provides a 164 // may be inconsistent with each other. So, this provides a
158 } else { 171 } else {
159 return 0; 172 return 0;
160 } 173 }
161 } 174 }
162 175
176 // Recalculate all the sizes.
177 void recalculate_sizes();
178 // Recalculate only what's necessary when a new eden region is allocated.
179 void recalculate_eden_size();
180
163 public: 181 public:
164 G1MonitoringSupport(G1CollectedHeap* g1h, VirtualSpace* g1_storage_addr); 182 G1MonitoringSupport(G1CollectedHeap* g1h);
165 183
166 G1CollectedHeap* g1h() { return _g1h; } 184 // Unfortunately, the jstat tool assumes that no space has 0
167 VirtualSpace* g1_storage_addr() { return _g1_storage_addr; } 185 // capacity. In our case, given that each space is logical, it's
168 186 // possible that no regions will be allocated to it, hence to have 0
169 // Performance Counter accessors 187 // capacity (e.g., if there are no survivor regions, the survivor
170 void update_counters(); 188 // space has 0 capacity). The way we deal with this is to always pad
171 void update_eden_counters(); 189 // each capacity value we report to jstat by a very small amount to
190 // make sure that it's never zero. Given that we sometimes have to
191 // report a capacity of a generation that contains several spaces
192 // (e.g., young gen includes one eden, two survivor spaces), the
193 // mult parameter is provided in order to adding the appropriate
194 // padding multiple times so that the capacities add up correctly.
195 static size_t pad_capacity(size_t size_bytes, size_t mult = 1) {
196 return size_bytes + MinObjAlignmentInBytes * mult;
197 }
198
199 // Recalculate all the sizes from scratch and update all the jstat
200 // counters accordingly.
201 void update_sizes();
202 // Recalculate only what's necessary when a new eden region is
203 // allocated and update any jstat counters that need to be updated.
204 void update_eden_size();
172 205
173 CollectorCounters* incremental_collection_counters() { 206 CollectorCounters* incremental_collection_counters() {
174 return _incremental_collection_counters; 207 return _incremental_collection_counters;
175 } 208 }
176 CollectorCounters* full_collection_counters() { 209 CollectorCounters* full_collection_counters() {
177 return _full_collection_counters; 210 return _full_collection_counters;
178 } 211 }
179 GenerationCounters* non_young_collection_counters() { 212 GenerationCounters* young_collection_counters() {
180 return _non_young_collection_counters; 213 return _young_collection_counters;
214 }
215 GenerationCounters* old_collection_counters() {
216 return _old_collection_counters;
181 } 217 }
182 HSpaceCounters* old_space_counters() { return _old_space_counters; } 218 HSpaceCounters* old_space_counters() { return _old_space_counters; }
183 HSpaceCounters* eden_counters() { return _eden_counters; } 219 HSpaceCounters* eden_counters() { return _eden_counters; }
184 HSpaceCounters* from_counters() { return _from_counters; } 220 HSpaceCounters* from_counters() { return _from_counters; }
185 HSpaceCounters* to_counters() { return _to_counters; } 221 HSpaceCounters* to_counters() { return _to_counters; }
186 222
187 // Monitoring support used by 223 // Monitoring support used by
188 // MemoryService 224 // MemoryService
189 // jstat counters 225 // jstat counters
190 size_t overall_committed(); 226
191 size_t overall_used(); 227 size_t overall_reserved() { return _overall_reserved; }
192 228 size_t overall_committed() { return _overall_committed; }
193 size_t eden_space_committed(); 229 size_t overall_used() { return _overall_used; }
194 size_t eden_space_used(); 230
195 231 size_t young_gen_committed() { return _young_gen_committed; }
196 size_t survivor_space_committed(); 232 size_t young_gen_max() { return overall_reserved(); }
197 size_t survivor_space_used(); 233 size_t eden_space_committed() { return _eden_committed; }
198 234 size_t eden_space_used() { return _eden_used; }
199 size_t old_space_committed(); 235 size_t survivor_space_committed() { return _survivor_committed; }
200 size_t old_space_used(); 236 size_t survivor_space_used() { return _survivor_used; }
237
238 size_t old_gen_committed() { return old_space_committed(); }
239 size_t old_gen_max() { return overall_reserved(); }
240 size_t old_space_committed() { return _old_committed; }
241 size_t old_space_used() { return _old_used; }
242 };
243
244 class G1GenerationCounters: public GenerationCounters {
245 protected:
246 G1MonitoringSupport* _g1mm;
247
248 public:
249 G1GenerationCounters(G1MonitoringSupport* g1mm,
250 const char* name, int ordinal, int spaces,
251 size_t min_capacity, size_t max_capacity,
252 size_t curr_capacity);
253 };
254
255 class G1YoungGenerationCounters: public G1GenerationCounters {
256 public:
257 G1YoungGenerationCounters(G1MonitoringSupport* g1mm, const char* name);
258 virtual void update_all();
259 };
260
261 class G1OldGenerationCounters: public G1GenerationCounters {
262 public:
263 G1OldGenerationCounters(G1MonitoringSupport* g1mm, const char* name);
264 virtual void update_all();
201 }; 265 };
202 266
203 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1MONITORINGSUPPORT_HPP 267 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1MONITORINGSUPPORT_HPP