comparison src/share/vm/gc_implementation/shared/vmGCOperations.cpp @ 12907:bf9e50c573ad

8025635: SoftReferences are not cleared before metaspace OOME are thrown Reviewed-by: jcoomes, tamao, tschatzl, stefank
author jmasa
date Thu, 17 Oct 2013 06:29:58 -0700
parents f2110083203d
children a3ba776d6ab6 63a4eb8bcd23 9c3dc501b5eb
comparison
equal deleted inserted replaced
12906:94c0343b1887 12907:bf9e50c573ad
209 // Check again if the space is available. Another thread 209 // Check again if the space is available. Another thread
210 // may have similarly failed a metadata allocation and induced 210 // may have similarly failed a metadata allocation and induced
211 // a GC that freed space for the allocation. 211 // a GC that freed space for the allocation.
212 if (!MetadataAllocationFailALot) { 212 if (!MetadataAllocationFailALot) {
213 _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype); 213 _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype);
214 } 214 }
215 215
216 if (_result == NULL) { 216 if (_result == NULL) {
217 if (UseConcMarkSweepGC) { 217 if (UseConcMarkSweepGC) {
218 if (CMSClassUnloadingEnabled) { 218 if (CMSClassUnloadingEnabled) {
219 MetaspaceGC::set_should_concurrent_collect(true); 219 MetaspaceGC::set_should_concurrent_collect(true);
221 // For CMS expand since the collection is going to be concurrent. 221 // For CMS expand since the collection is going to be concurrent.
222 _result = 222 _result =
223 _loader_data->metaspace_non_null()->expand_and_allocate(_size, _mdtype); 223 _loader_data->metaspace_non_null()->expand_and_allocate(_size, _mdtype);
224 } 224 }
225 if (_result == NULL) { 225 if (_result == NULL) {
226 // Don't clear the soft refs. This GC is for reclaiming metadata 226 // Don't clear the soft refs yet.
227 // and is unrelated to the fullness of the Java heap which should
228 // be the criteria for clearing SoftReferences.
229 if (Verbose && PrintGCDetails && UseConcMarkSweepGC) { 227 if (Verbose && PrintGCDetails && UseConcMarkSweepGC) {
230 gclog_or_tty->print_cr("\nCMS full GC for Metaspace"); 228 gclog_or_tty->print_cr("\nCMS full GC for Metaspace");
231 } 229 }
232 heap->collect_as_vm_thread(GCCause::_metadata_GC_threshold); 230 heap->collect_as_vm_thread(GCCause::_metadata_GC_threshold);
233 // After a GC try to allocate without expanding. Could fail 231 // After a GC try to allocate without expanding. Could fail
234 // and expansion will be tried below. 232 // and expansion will be tried below.
235 _result = 233 _result =
236 _loader_data->metaspace_non_null()->allocate(_size, _mdtype); 234 _loader_data->metaspace_non_null()->allocate(_size, _mdtype);
237 } 235 }
238 if (_result == NULL && !UseConcMarkSweepGC /* CMS already tried */) { 236 if (_result == NULL) {
239 // If still failing, allow the Metaspace to expand. 237 // If still failing, allow the Metaspace to expand.
240 // See delta_capacity_until_GC() for explanation of the 238 // See delta_capacity_until_GC() for explanation of the
241 // amount of the expansion. 239 // amount of the expansion.
242 // This should work unless there really is no more space 240 // This should work unless there really is no more space
243 // or a MaxMetaspaceSize has been specified on the command line. 241 // or a MaxMetaspaceSize has been specified on the command line.
244 _result = 242 _result =
245 _loader_data->metaspace_non_null()->expand_and_allocate(_size, _mdtype); 243 _loader_data->metaspace_non_null()->expand_and_allocate(_size, _mdtype);
246 244 if (_result == NULL) {
245 // If expansion failed, do a last-ditch collection and try allocating
246 // again. A last-ditch collection will clear softrefs. This
247 // behavior is similar to the last-ditch collection done for perm
248 // gen when it was full and a collection for failed allocation
249 // did not free perm gen space.
250 heap->collect_as_vm_thread(GCCause::_last_ditch_collection);
251 _result =
252 _loader_data->metaspace_non_null()->allocate(_size, _mdtype);
253 }
247 } 254 }
248 if (Verbose && PrintGCDetails && _result == NULL) { 255 if (Verbose && PrintGCDetails && _result == NULL) {
249 gclog_or_tty->print_cr("\nAfter Metaspace GC failed to allocate size " 256 gclog_or_tty->print_cr("\nAfter Metaspace GC failed to allocate size "
250 SIZE_FORMAT, _size); 257 SIZE_FORMAT, _size);
251 } 258 }