comparison src/share/vm/gc_implementation/shared/vmGCOperations.cpp @ 6725:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents 436b4a3231bf
children aed758eda82a
comparison
equal deleted inserted replaced
6724:36d1d483d5d6 6725:da91efe96a93
1 /* 1 /*
2 * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
190 GenCollectedHeap* gch = GenCollectedHeap::heap(); 190 GenCollectedHeap* gch = GenCollectedHeap::heap();
191 GCCauseSetter gccs(gch, _gc_cause); 191 GCCauseSetter gccs(gch, _gc_cause);
192 gch->do_full_collection(gch->must_clear_all_soft_refs(), _max_level); 192 gch->do_full_collection(gch->must_clear_all_soft_refs(), _max_level);
193 } 193 }
194 194
195 void VM_GenCollectForPermanentAllocation::doit() { 195 void VM_CollectForMetadataAllocation::doit() {
196 SvcGCMarker sgcm(SvcGCMarker::FULL); 196 SvcGCMarker sgcm(SvcGCMarker::FULL);
197 197
198 SharedHeap* heap = (SharedHeap*)Universe::heap(); 198 CollectedHeap* heap = Universe::heap();
199 GCCauseSetter gccs(heap, _gc_cause); 199 GCCauseSetter gccs(heap, _gc_cause);
200 switch (heap->kind()) { 200
201 case (CollectedHeap::GenCollectedHeap): { 201 bool do_cms_concurrent = false;
202 GenCollectedHeap* gch = (GenCollectedHeap*)heap; 202
203 gch->do_full_collection(gch->must_clear_all_soft_refs(), 203 // Check again if the space is available. Another thread
204 gch->n_gens() - 1); 204 // may have similarly failed a metadata allocation and induced
205 break; 205 // a GC that freed space for the allocation.
206 } 206 if (!MetadataAllocationFailALot) {
207 #ifndef SERIALGC 207 _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype);
208 case (CollectedHeap::G1CollectedHeap): { 208 }
209 G1CollectedHeap* g1h = (G1CollectedHeap*)heap; 209
210 g1h->do_full_collection(_gc_cause == GCCause::_last_ditch_collection); 210 if (_result == NULL) {
211 break; 211 if (!UseConcMarkSweepGC) {
212 } 212 // Don't clear the soft refs the first time.
213 #endif // SERIALGC 213 heap->collect_as_vm_thread(GCCause::_metadata_GC_threshold);
214 default: 214 _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype);
215 ShouldNotReachHere(); 215 // Don't do this for now
216 } 216 // This seems too costly to do a second full GC
217 _res = heap->perm_gen()->allocate(_size, false); 217 // Let the metaspace grow instead
218 assert(heap->is_in_reserved_or_null(_res), "result not in heap"); 218 // if (_result == NULL) {
219 if (_res == NULL && GC_locker::is_active_and_needs_gc()) { 219 // // If allocation fails again, clear soft refs
220 // heap->collect_as_vm_thread(GCCause::_last_ditch_collection);
221 // _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype);
222 // }
223 } else {
224 MetaspaceGC::set_should_concurrent_collect(true);
225 do_cms_concurrent = true;
226 }
227 if (_result == NULL) {
228 // If still failing, allow the Metaspace to expand.
229 // See delta_capacity_until_GC() for explanation of the
230 // amount of the expansion.
231 // This should work unless there really is no more space
232 // or a MaxMetaspaceSize has been specified on the command line.
233 MetaspaceGC::set_expand_after_GC(true);
234 size_t before_inc = MetaspaceGC::capacity_until_GC();
235 size_t delta_words = MetaspaceGC::delta_capacity_until_GC(_size);
236 MetaspaceGC::inc_capacity_until_GC(delta_words);
237 if (PrintGCDetails && Verbose) {
238 gclog_or_tty->print_cr("Increase capacity to GC from " SIZE_FORMAT
239 " to " SIZE_FORMAT, before_inc, MetaspaceGC::capacity_until_GC());
240 }
241 _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype);
242 if (do_cms_concurrent && _result == NULL) {
243 // Rather than fail with a metaspace out-of-memory, do a full
244 // GC for CMS.
245 heap->collect_as_vm_thread(GCCause::_metadata_GC_threshold);
246 _result = _loader_data->metaspace_non_null()->allocate(_size, _mdtype);
247 }
248 if (_result == NULL) {
249 if (PrintGCDetails) {
250 gclog_or_tty->print_cr("\nAfter Metaspace GC failed to allocate size "
251 SIZE_FORMAT, _size);
252 }
253 }
254 }
255 }
256
257 if (_result == NULL && GC_locker::is_active_and_needs_gc()) {
220 set_gc_locked(); 258 set_gc_locked();
221 } 259 }
222 } 260 }