Mon, 06 Aug 2012 12:20:14 -0700
6818524: G1: use ergonomic resizing of PLABs
Summary: Employ PLABStats instances to record information about survivor and old PLABs, and use the recorded stats to adjust the sizes of survivor and old PLABS.
Reviewed-by: johnc, ysr
Contributed-by: Brandon Mitchell <brandon@twitter.com>
duke@435 | 1 | /* |
brutisso@2532 | 2 | * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/classLoader.hpp" |
stefank@2314 | 27 | #include "classfile/javaClasses.hpp" |
stefank@2314 | 28 | #include "gc_implementation/shared/vmGCOperations.hpp" |
stefank@2314 | 29 | #include "memory/gcLocker.inline.hpp" |
stefank@2314 | 30 | #include "memory/genCollectedHeap.hpp" |
stefank@2314 | 31 | #include "memory/oopFactory.hpp" |
stefank@2314 | 32 | #include "oops/instanceKlass.hpp" |
stefank@2314 | 33 | #include "oops/instanceRefKlass.hpp" |
stefank@2314 | 34 | #include "runtime/handles.inline.hpp" |
stefank@2314 | 35 | #include "runtime/init.hpp" |
stefank@2314 | 36 | #include "runtime/interfaceSupport.hpp" |
stefank@2314 | 37 | #include "utilities/dtrace.hpp" |
stefank@2314 | 38 | #include "utilities/preserveException.hpp" |
stefank@2314 | 39 | #ifndef SERIALGC |
stefank@2314 | 40 | #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
stefank@2314 | 41 | #endif |
kamg@2445 | 42 | |
dcubed@3202 | 43 | #ifndef USDT2 |
duke@435 | 44 | HS_DTRACE_PROBE_DECL1(hotspot, gc__begin, bool); |
duke@435 | 45 | HS_DTRACE_PROBE_DECL(hotspot, gc__end); |
dcubed@3202 | 46 | #endif /* !USDT2 */ |
duke@435 | 47 | |
duke@435 | 48 | // The same dtrace probe can't be inserted in two different files, so we |
duke@435 | 49 | // have to call it here, so it's only in one file. Can't create new probes |
duke@435 | 50 | // for the other file anymore. The dtrace probes have to remain stable. |
duke@435 | 51 | void VM_GC_Operation::notify_gc_begin(bool full) { |
dcubed@3202 | 52 | #ifndef USDT2 |
duke@435 | 53 | HS_DTRACE_PROBE1(hotspot, gc__begin, full); |
jcoomes@1902 | 54 | HS_DTRACE_WORKAROUND_TAIL_CALL_BUG(); |
dcubed@3202 | 55 | #else /* USDT2 */ |
dcubed@3202 | 56 | HOTSPOT_GC_BEGIN( |
dcubed@3202 | 57 | full); |
dcubed@3202 | 58 | #endif /* USDT2 */ |
duke@435 | 59 | } |
duke@435 | 60 | |
duke@435 | 61 | void VM_GC_Operation::notify_gc_end() { |
dcubed@3202 | 62 | #ifndef USDT2 |
duke@435 | 63 | HS_DTRACE_PROBE(hotspot, gc__end); |
jcoomes@1902 | 64 | HS_DTRACE_WORKAROUND_TAIL_CALL_BUG(); |
dcubed@3202 | 65 | #else /* USDT2 */ |
dcubed@3202 | 66 | HOTSPOT_GC_END( |
dcubed@3202 | 67 | ); |
dcubed@3202 | 68 | #endif /* USDT2 */ |
duke@435 | 69 | } |
duke@435 | 70 | |
duke@435 | 71 | void VM_GC_Operation::acquire_pending_list_lock() { |
duke@435 | 72 | // we may enter this with pending exception set |
duke@435 | 73 | instanceRefKlass::acquire_pending_list_lock(&_pending_list_basic_lock); |
duke@435 | 74 | } |
duke@435 | 75 | |
duke@435 | 76 | |
duke@435 | 77 | void VM_GC_Operation::release_and_notify_pending_list_lock() { |
duke@435 | 78 | |
duke@435 | 79 | instanceRefKlass::release_and_notify_pending_list_lock(&_pending_list_basic_lock); |
duke@435 | 80 | } |
duke@435 | 81 | |
duke@435 | 82 | // Allocations may fail in several threads at about the same time, |
duke@435 | 83 | // resulting in multiple gc requests. We only want to do one of them. |
duke@435 | 84 | // In case a GC locker is active and the need for a GC is already signalled, |
duke@435 | 85 | // we want to skip this GC attempt altogether, without doing a futile |
duke@435 | 86 | // safepoint operation. |
duke@435 | 87 | bool VM_GC_Operation::skip_operation() const { |
duke@435 | 88 | bool skip = (_gc_count_before != Universe::heap()->total_collections()); |
duke@435 | 89 | if (_full && skip) { |
duke@435 | 90 | skip = (_full_gc_count_before != Universe::heap()->total_full_collections()); |
duke@435 | 91 | } |
duke@435 | 92 | if (!skip && GC_locker::is_active_and_needs_gc()) { |
duke@435 | 93 | skip = Universe::heap()->is_maximal_no_gc(); |
duke@435 | 94 | assert(!(skip && (_gc_cause == GCCause::_gc_locker)), |
duke@435 | 95 | "GC_locker cannot be active when initiating GC"); |
duke@435 | 96 | } |
duke@435 | 97 | return skip; |
duke@435 | 98 | } |
duke@435 | 99 | |
duke@435 | 100 | bool VM_GC_Operation::doit_prologue() { |
duke@435 | 101 | assert(Thread::current()->is_Java_thread(), "just checking"); |
brutisso@2532 | 102 | assert(((_gc_cause != GCCause::_no_gc) && |
brutisso@2532 | 103 | (_gc_cause != GCCause::_no_cause_specified)), "Illegal GCCause"); |
duke@435 | 104 | |
duke@435 | 105 | acquire_pending_list_lock(); |
duke@435 | 106 | // If the GC count has changed someone beat us to the collection |
duke@435 | 107 | // Get the Heap_lock after the pending_list_lock. |
duke@435 | 108 | Heap_lock->lock(); |
ysr@777 | 109 | |
duke@435 | 110 | // Check invocations |
duke@435 | 111 | if (skip_operation()) { |
duke@435 | 112 | // skip collection |
duke@435 | 113 | Heap_lock->unlock(); |
duke@435 | 114 | release_and_notify_pending_list_lock(); |
duke@435 | 115 | _prologue_succeeded = false; |
duke@435 | 116 | } else { |
duke@435 | 117 | _prologue_succeeded = true; |
ysr@777 | 118 | SharedHeap* sh = SharedHeap::heap(); |
ysr@777 | 119 | if (sh != NULL) sh->_thread_holds_heap_lock_for_gc = true; |
duke@435 | 120 | } |
duke@435 | 121 | return _prologue_succeeded; |
duke@435 | 122 | } |
duke@435 | 123 | |
duke@435 | 124 | |
duke@435 | 125 | void VM_GC_Operation::doit_epilogue() { |
duke@435 | 126 | assert(Thread::current()->is_Java_thread(), "just checking"); |
duke@435 | 127 | // Release the Heap_lock first. |
ysr@777 | 128 | SharedHeap* sh = SharedHeap::heap(); |
ysr@777 | 129 | if (sh != NULL) sh->_thread_holds_heap_lock_for_gc = false; |
duke@435 | 130 | Heap_lock->unlock(); |
duke@435 | 131 | release_and_notify_pending_list_lock(); |
duke@435 | 132 | } |
duke@435 | 133 | |
duke@435 | 134 | bool VM_GC_HeapInspection::doit_prologue() { |
duke@435 | 135 | if (Universe::heap()->supports_heap_inspection()) { |
duke@435 | 136 | return VM_GC_Operation::doit_prologue(); |
duke@435 | 137 | } else { |
duke@435 | 138 | return false; |
duke@435 | 139 | } |
duke@435 | 140 | } |
duke@435 | 141 | |
duke@435 | 142 | bool VM_GC_HeapInspection::skip_operation() const { |
duke@435 | 143 | assert(Universe::heap()->supports_heap_inspection(), "huh?"); |
duke@435 | 144 | return false; |
duke@435 | 145 | } |
duke@435 | 146 | |
duke@435 | 147 | void VM_GC_HeapInspection::doit() { |
duke@435 | 148 | HandleMark hm; |
duke@435 | 149 | CollectedHeap* ch = Universe::heap(); |
kevinw@1827 | 150 | ch->ensure_parsability(false); // must happen, even if collection does |
kevinw@1827 | 151 | // not happen (e.g. due to GC_locker) |
duke@435 | 152 | if (_full_gc) { |
kevinw@1827 | 153 | // The collection attempt below would be skipped anyway if |
kevinw@1827 | 154 | // the gc locker is held. The following dump may then be a tad |
kevinw@1827 | 155 | // misleading to someone expecting only live objects to show |
kevinw@1827 | 156 | // up in the dump (see CR 6944195). Just issue a suitable warning |
kevinw@1827 | 157 | // in that case and do not attempt to do a collection. |
kevinw@1827 | 158 | // The latter is a subtle point, because even a failed attempt |
kevinw@1827 | 159 | // to GC will, in fact, induce one in the future, which we |
kevinw@1827 | 160 | // probably want to avoid in this case because the GC that we may |
kevinw@1827 | 161 | // be about to attempt holds value for us only |
kevinw@1827 | 162 | // if it happens now and not if it happens in the eventual |
kevinw@1827 | 163 | // future. |
kevinw@1827 | 164 | if (GC_locker::is_active()) { |
kevinw@1827 | 165 | warning("GC locker is held; pre-dump GC was skipped"); |
kevinw@1827 | 166 | } else { |
kevinw@1827 | 167 | ch->collect_as_vm_thread(GCCause::_heap_inspection); |
kevinw@1827 | 168 | } |
duke@435 | 169 | } |
ysr@1050 | 170 | HeapInspection::heap_inspection(_out, _need_prologue /* need_prologue */); |
duke@435 | 171 | } |
duke@435 | 172 | |
duke@435 | 173 | |
duke@435 | 174 | void VM_GenCollectForAllocation::doit() { |
kamg@2445 | 175 | SvcGCMarker sgcm(SvcGCMarker::MINOR); |
duke@435 | 176 | |
duke@435 | 177 | GenCollectedHeap* gch = GenCollectedHeap::heap(); |
duke@435 | 178 | GCCauseSetter gccs(gch, _gc_cause); |
duke@435 | 179 | _res = gch->satisfy_failed_allocation(_size, _tlab); |
duke@435 | 180 | assert(gch->is_in_reserved_or_null(_res), "result not in heap"); |
duke@435 | 181 | |
duke@435 | 182 | if (_res == NULL && GC_locker::is_active_and_needs_gc()) { |
duke@435 | 183 | set_gc_locked(); |
duke@435 | 184 | } |
duke@435 | 185 | } |
duke@435 | 186 | |
duke@435 | 187 | void VM_GenCollectFull::doit() { |
kamg@2445 | 188 | SvcGCMarker sgcm(SvcGCMarker::FULL); |
duke@435 | 189 | |
duke@435 | 190 | GenCollectedHeap* gch = GenCollectedHeap::heap(); |
duke@435 | 191 | GCCauseSetter gccs(gch, _gc_cause); |
duke@435 | 192 | gch->do_full_collection(gch->must_clear_all_soft_refs(), _max_level); |
duke@435 | 193 | } |
apetrusenko@574 | 194 | |
apetrusenko@574 | 195 | void VM_GenCollectForPermanentAllocation::doit() { |
kamg@2445 | 196 | SvcGCMarker sgcm(SvcGCMarker::FULL); |
kamg@2445 | 197 | |
ysr@777 | 198 | SharedHeap* heap = (SharedHeap*)Universe::heap(); |
ysr@777 | 199 | GCCauseSetter gccs(heap, _gc_cause); |
ysr@777 | 200 | switch (heap->kind()) { |
ysr@777 | 201 | case (CollectedHeap::GenCollectedHeap): { |
ysr@777 | 202 | GenCollectedHeap* gch = (GenCollectedHeap*)heap; |
ysr@777 | 203 | gch->do_full_collection(gch->must_clear_all_soft_refs(), |
ysr@777 | 204 | gch->n_gens() - 1); |
ysr@777 | 205 | break; |
ysr@777 | 206 | } |
ysr@777 | 207 | #ifndef SERIALGC |
ysr@777 | 208 | case (CollectedHeap::G1CollectedHeap): { |
ysr@777 | 209 | G1CollectedHeap* g1h = (G1CollectedHeap*)heap; |
ysr@777 | 210 | g1h->do_full_collection(_gc_cause == GCCause::_last_ditch_collection); |
ysr@777 | 211 | break; |
ysr@777 | 212 | } |
ysr@777 | 213 | #endif // SERIALGC |
ysr@777 | 214 | default: |
ysr@777 | 215 | ShouldNotReachHere(); |
ysr@777 | 216 | } |
ysr@777 | 217 | _res = heap->perm_gen()->allocate(_size, false); |
ysr@777 | 218 | assert(heap->is_in_reserved_or_null(_res), "result not in heap"); |
apetrusenko@574 | 219 | if (_res == NULL && GC_locker::is_active_and_needs_gc()) { |
apetrusenko@574 | 220 | set_gc_locked(); |
apetrusenko@574 | 221 | } |
apetrusenko@574 | 222 | } |