Mercurial > hg > truffle
comparison src/share/vm/memory/metaspace.hpp @ 10183:868d87ed63c8
8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
Reviewed-by: mgerdin, coleenp
author | jmasa |
---|---|
date | Tue, 12 Feb 2013 14:15:45 -0800 |
parents | c23dbf0e8ab7 |
children | 2b1a9d972fc2 |
comparison
equal
deleted
inserted
replaced
10182:5c93c1f61226 | 10183:868d87ed63c8 |
---|---|
109 SpaceManager* vsm() const { return _vsm; } | 109 SpaceManager* vsm() const { return _vsm; } |
110 | 110 |
111 SpaceManager* _class_vsm; | 111 SpaceManager* _class_vsm; |
112 SpaceManager* class_vsm() const { return _class_vsm; } | 112 SpaceManager* class_vsm() const { return _class_vsm; } |
113 | 113 |
114 // Allocate space for metadata of type mdtype. This is space | |
115 // within a Metachunk and is used by | |
116 // allocate(ClassLoaderData*, size_t, bool, MetadataType, TRAPS) | |
117 // which returns a Metablock. | |
114 MetaWord* allocate(size_t word_size, MetadataType mdtype); | 118 MetaWord* allocate(size_t word_size, MetadataType mdtype); |
115 | 119 |
116 // Virtual Space lists for both classes and other metadata | 120 // Virtual Space lists for both classes and other metadata |
117 static VirtualSpaceList* _space_list; | 121 static VirtualSpaceList* _space_list; |
118 static VirtualSpaceList* _class_space_list; | 122 static VirtualSpaceList* _class_space_list; |
131 | 135 |
132 static size_t first_chunk_word_size() { return _first_chunk_word_size; } | 136 static size_t first_chunk_word_size() { return _first_chunk_word_size; } |
133 static size_t first_class_chunk_word_size() { return _first_class_chunk_word_size; } | 137 static size_t first_class_chunk_word_size() { return _first_class_chunk_word_size; } |
134 | 138 |
135 char* bottom() const; | 139 char* bottom() const; |
136 size_t used_words(MetadataType mdtype) const; | 140 size_t used_words_slow(MetadataType mdtype) const; |
137 size_t free_words(MetadataType mdtype) const; | 141 size_t free_words(MetadataType mdtype) const; |
138 size_t capacity_words(MetadataType mdtype) const; | 142 size_t capacity_words_slow(MetadataType mdtype) const; |
139 size_t waste_words(MetadataType mdtype) const; | 143 size_t waste_words(MetadataType mdtype) const; |
144 | |
145 size_t used_bytes_slow(MetadataType mdtype) const; | |
146 size_t capacity_bytes_slow(MetadataType mdtype) const; | |
140 | 147 |
141 static Metablock* allocate(ClassLoaderData* loader_data, size_t size, | 148 static Metablock* allocate(ClassLoaderData* loader_data, size_t size, |
142 bool read_only, MetadataType mdtype, TRAPS); | 149 bool read_only, MetadataType mdtype, TRAPS); |
143 void deallocate(MetaWord* ptr, size_t byte_size, bool is_class); | 150 void deallocate(MetaWord* ptr, size_t byte_size, bool is_class); |
144 | 151 |
159 }; | 166 }; |
160 | 167 |
161 class MetaspaceAux : AllStatic { | 168 class MetaspaceAux : AllStatic { |
162 | 169 |
163 // Statistics for class space and data space in metaspace. | 170 // Statistics for class space and data space in metaspace. |
164 static size_t used_in_bytes(Metaspace::MetadataType mdtype); | 171 |
172 // These methods iterate over the classloader data graph | |
173 // for the given Metaspace type. These are slow. | |
174 static size_t used_bytes_slow(Metaspace::MetadataType mdtype); | |
165 static size_t free_in_bytes(Metaspace::MetadataType mdtype); | 175 static size_t free_in_bytes(Metaspace::MetadataType mdtype); |
166 static size_t capacity_in_bytes(Metaspace::MetadataType mdtype); | 176 static size_t capacity_bytes_slow(Metaspace::MetadataType mdtype); |
177 | |
178 // Iterates over the virtual space list. | |
167 static size_t reserved_in_bytes(Metaspace::MetadataType mdtype); | 179 static size_t reserved_in_bytes(Metaspace::MetadataType mdtype); |
168 | 180 |
169 static size_t free_chunks_total(Metaspace::MetadataType mdtype); | 181 static size_t free_chunks_total(Metaspace::MetadataType mdtype); |
170 static size_t free_chunks_total_in_bytes(Metaspace::MetadataType mdtype); | 182 static size_t free_chunks_total_in_bytes(Metaspace::MetadataType mdtype); |
171 | 183 |
172 public: | 184 public: |
173 // Total of space allocated to metadata in all Metaspaces | 185 // Running sum of space in all Metachunks that has been |
174 static size_t used_in_bytes() { | 186 // allocated to a Metaspace. This is used instead of |
175 return used_in_bytes(Metaspace::ClassType) + | 187 // iterating over all the classloaders |
176 used_in_bytes(Metaspace::NonClassType); | 188 static size_t _allocated_capacity_words; |
177 } | 189 // Running sum of space in all Metachunks that have |
178 | 190 // are being used for metadata. |
179 // Total of available space in all Metaspaces | 191 static size_t _allocated_used_words; |
180 // Total of capacity allocated to all Metaspaces. This includes | 192 |
181 // space in Metachunks not yet allocated and in the Metachunk | 193 public: |
182 // freelist. | 194 // Decrement and increment _allocated_capacity_words |
183 static size_t capacity_in_bytes() { | 195 static void dec_capacity(size_t words); |
184 return capacity_in_bytes(Metaspace::ClassType) + | 196 static void inc_capacity(size_t words); |
185 capacity_in_bytes(Metaspace::NonClassType); | 197 |
198 // Decrement and increment _allocated_used_words | |
199 static void dec_used(size_t words); | |
200 static void inc_used(size_t words); | |
201 | |
202 // Total of space allocated to metadata in all Metaspaces. | |
203 // This sums the space used in each Metachunk by | |
204 // iterating over the classloader data graph | |
205 static size_t used_bytes_slow() { | |
206 return used_bytes_slow(Metaspace::ClassType) + | |
207 used_bytes_slow(Metaspace::NonClassType); | |
208 } | |
209 | |
210 // Used by MetaspaceCounters | |
211 static size_t free_chunks_total(); | |
212 static size_t free_chunks_total_in_bytes(); | |
213 | |
214 static size_t allocated_capacity_words() { | |
215 return _allocated_capacity_words; | |
216 } | |
217 static size_t allocated_capacity_bytes() { | |
218 return _allocated_capacity_words * BytesPerWord; | |
219 } | |
220 | |
221 static size_t allocated_used_words() { | |
222 return _allocated_used_words; | |
223 } | |
224 static size_t allocated_used_bytes() { | |
225 return _allocated_used_words * BytesPerWord; | |
226 } | |
227 | |
228 static size_t free_bytes(); | |
229 | |
230 // Total capacity in all Metaspaces | |
231 static size_t capacity_bytes_slow() { | |
232 #ifdef PRODUCT | |
233 // Use allocated_capacity_bytes() in PRODUCT instead of this function. | |
234 guarantee(false, "Should not call capacity_bytes_slow() in the PRODUCT"); | |
235 #endif | |
236 size_t class_capacity = capacity_bytes_slow(Metaspace::ClassType); | |
237 size_t non_class_capacity = capacity_bytes_slow(Metaspace::NonClassType); | |
238 assert(allocated_capacity_bytes() == class_capacity + non_class_capacity, | |
239 err_msg("bad accounting: allocated_capacity_bytes() " SIZE_FORMAT | |
240 " class_capacity + non_class_capacity " SIZE_FORMAT | |
241 " class_capacity " SIZE_FORMAT " non_class_capacity " SIZE_FORMAT, | |
242 allocated_capacity_bytes(), class_capacity + non_class_capacity, | |
243 class_capacity, non_class_capacity)); | |
244 | |
245 return class_capacity + non_class_capacity; | |
186 } | 246 } |
187 | 247 |
188 // Total space reserved in all Metaspaces | 248 // Total space reserved in all Metaspaces |
189 static size_t reserved_in_bytes() { | 249 static size_t reserved_in_bytes() { |
190 return reserved_in_bytes(Metaspace::ClassType) + | 250 return reserved_in_bytes(Metaspace::ClassType) + |
199 static void print_on(outputStream * out, Metaspace::MetadataType mdtype); | 259 static void print_on(outputStream * out, Metaspace::MetadataType mdtype); |
200 | 260 |
201 static void print_waste(outputStream* out); | 261 static void print_waste(outputStream* out); |
202 static void dump(outputStream* out); | 262 static void dump(outputStream* out); |
203 static void verify_free_chunks(); | 263 static void verify_free_chunks(); |
264 // Checks that the values returned by allocated_capacity_bytes() and | |
265 // capacity_bytes_slow() are the same. | |
266 static void verify_capacity(); | |
267 static void verify_used(); | |
268 static void verify_metrics(); | |
204 }; | 269 }; |
205 | 270 |
206 // Metaspace are deallocated when their class loader are GC'ed. | 271 // Metaspace are deallocated when their class loader are GC'ed. |
207 // This class implements a policy for inducing GC's to recover | 272 // This class implements a policy for inducing GC's to recover |
208 // Metaspaces. | 273 // Metaspaces. |
233 void set_shrink_factor(uint v) { _shrink_factor = v; } | 298 void set_shrink_factor(uint v) { _shrink_factor = v; } |
234 | 299 |
235 public: | 300 public: |
236 | 301 |
237 static size_t capacity_until_GC() { return _capacity_until_GC; } | 302 static size_t capacity_until_GC() { return _capacity_until_GC; } |
238 static size_t capacity_until_GC_in_bytes() { return _capacity_until_GC * BytesPerWord; } | |
239 static void inc_capacity_until_GC(size_t v) { _capacity_until_GC += v; } | 303 static void inc_capacity_until_GC(size_t v) { _capacity_until_GC += v; } |
240 static void dec_capacity_until_GC(size_t v) { | 304 static void dec_capacity_until_GC(size_t v) { |
241 _capacity_until_GC = _capacity_until_GC > v ? _capacity_until_GC - v : 0; | 305 _capacity_until_GC = _capacity_until_GC > v ? _capacity_until_GC - v : 0; |
242 } | 306 } |
243 static bool expand_after_GC() { return _expand_after_GC; } | 307 static bool expand_after_GC() { return _expand_after_GC; } |