Tue, 19 May 2015 15:49:27 +0200
8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
Summary: added WhiteBox methods to count regions and exact aux data sizes
Reviewed-by: jwilhelm, brutisso
sjohanss@7118 | 1 | /* |
sjohanss@7118 | 2 | * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
sjohanss@7118 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
sjohanss@7118 | 4 | * |
sjohanss@7118 | 5 | * This code is free software; you can redistribute it and/or modify it |
sjohanss@7118 | 6 | * under the terms of the GNU General Public License version 2 only, as |
sjohanss@7118 | 7 | * published by the Free Software Foundation. |
sjohanss@7118 | 8 | * |
sjohanss@7118 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
sjohanss@7118 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
sjohanss@7118 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
sjohanss@7118 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
sjohanss@7118 | 13 | * accompanied this code). |
sjohanss@7118 | 14 | * |
sjohanss@7118 | 15 | * You should have received a copy of the GNU General Public License version |
sjohanss@7118 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
sjohanss@7118 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
sjohanss@7118 | 18 | * |
sjohanss@7118 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
sjohanss@7118 | 20 | * or visit www.oracle.com if you need additional information or have any |
sjohanss@7118 | 21 | * questions. |
sjohanss@7118 | 22 | * |
sjohanss@7118 | 23 | */ |
sjohanss@7118 | 24 | |
sjohanss@7118 | 25 | #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1ALLOCATOR_HPP |
sjohanss@7118 | 26 | #define SHARE_VM_GC_IMPLEMENTATION_G1_G1ALLOCATOR_HPP |
sjohanss@7118 | 27 | |
sjohanss@7118 | 28 | #include "gc_implementation/g1/g1AllocationContext.hpp" |
sjohanss@7118 | 29 | #include "gc_implementation/g1/g1AllocRegion.hpp" |
tschatzl@7651 | 30 | #include "gc_implementation/g1/g1InCSetState.hpp" |
sjohanss@7118 | 31 | #include "gc_implementation/shared/parGCAllocBuffer.hpp" |
sjohanss@7118 | 32 | |
sjohanss@7118 | 33 | // Base class for G1 allocators. |
sjohanss@7118 | 34 | class G1Allocator : public CHeapObj<mtGC> { |
sjohanss@7118 | 35 | friend class VMStructs; |
sjohanss@7118 | 36 | protected: |
sjohanss@7118 | 37 | G1CollectedHeap* _g1h; |
sjohanss@7118 | 38 | |
sjohanss@7118 | 39 | // Outside of GC pauses, the number of bytes used in all regions other |
sjohanss@7118 | 40 | // than the current allocation region. |
sjohanss@7118 | 41 | size_t _summary_bytes_used; |
sjohanss@7118 | 42 | |
sjohanss@7118 | 43 | public: |
sjohanss@7118 | 44 | G1Allocator(G1CollectedHeap* heap) : |
sjohanss@7118 | 45 | _g1h(heap), _summary_bytes_used(0) { } |
sjohanss@7118 | 46 | |
sjohanss@7118 | 47 | static G1Allocator* create_allocator(G1CollectedHeap* g1h); |
sjohanss@7118 | 48 | |
sjohanss@7118 | 49 | virtual void init_mutator_alloc_region() = 0; |
sjohanss@7118 | 50 | virtual void release_mutator_alloc_region() = 0; |
sjohanss@7118 | 51 | |
sjohanss@7118 | 52 | virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info) = 0; |
sjohanss@7118 | 53 | virtual void release_gc_alloc_regions(uint no_of_gc_workers, EvacuationInfo& evacuation_info) = 0; |
sjohanss@7118 | 54 | virtual void abandon_gc_alloc_regions() = 0; |
sjohanss@7118 | 55 | |
sjohanss@7118 | 56 | virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) = 0; |
sjohanss@7118 | 57 | virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) = 0; |
sjohanss@7118 | 58 | virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) = 0; |
sjohanss@7118 | 59 | virtual size_t used() = 0; |
sjohanss@7118 | 60 | virtual bool is_retained_old_region(HeapRegion* hr) = 0; |
sjohanss@7118 | 61 | |
sjohanss@7118 | 62 | void reuse_retained_old_region(EvacuationInfo& evacuation_info, |
sjohanss@7118 | 63 | OldGCAllocRegion* old, |
sjohanss@7118 | 64 | HeapRegion** retained); |
sjohanss@7118 | 65 | |
sjohanss@7118 | 66 | size_t used_unlocked() const { |
sjohanss@7118 | 67 | return _summary_bytes_used; |
sjohanss@7118 | 68 | } |
sjohanss@7118 | 69 | |
sjohanss@7118 | 70 | void increase_used(size_t bytes) { |
sjohanss@7118 | 71 | _summary_bytes_used += bytes; |
sjohanss@7118 | 72 | } |
sjohanss@7118 | 73 | |
sjohanss@7118 | 74 | void decrease_used(size_t bytes) { |
sjohanss@7118 | 75 | assert(_summary_bytes_used >= bytes, |
sjohanss@7118 | 76 | err_msg("invariant: _summary_bytes_used: "SIZE_FORMAT" should be >= bytes: "SIZE_FORMAT, |
sjohanss@7118 | 77 | _summary_bytes_used, bytes)); |
sjohanss@7118 | 78 | _summary_bytes_used -= bytes; |
sjohanss@7118 | 79 | } |
sjohanss@7118 | 80 | |
sjohanss@7118 | 81 | void set_used(size_t bytes) { |
sjohanss@7118 | 82 | _summary_bytes_used = bytes; |
sjohanss@7118 | 83 | } |
sjohanss@7131 | 84 | |
sjohanss@7131 | 85 | virtual HeapRegion* new_heap_region(uint hrs_index, |
sjohanss@7131 | 86 | G1BlockOffsetSharedArray* sharedOffsetArray, |
sjohanss@7131 | 87 | MemRegion mr) { |
sjohanss@7131 | 88 | return new HeapRegion(hrs_index, sharedOffsetArray, mr); |
sjohanss@7131 | 89 | } |
sjohanss@7118 | 90 | }; |
sjohanss@7118 | 91 | |
sjohanss@7118 | 92 | // The default allocator for G1. |
sjohanss@7118 | 93 | class G1DefaultAllocator : public G1Allocator { |
sjohanss@7118 | 94 | protected: |
sjohanss@7118 | 95 | // Alloc region used to satisfy mutator allocation requests. |
sjohanss@7118 | 96 | MutatorAllocRegion _mutator_alloc_region; |
sjohanss@7118 | 97 | |
sjohanss@7118 | 98 | // Alloc region used to satisfy allocation requests by the GC for |
sjohanss@7118 | 99 | // survivor objects. |
sjohanss@7118 | 100 | SurvivorGCAllocRegion _survivor_gc_alloc_region; |
sjohanss@7118 | 101 | |
sjohanss@7118 | 102 | // Alloc region used to satisfy allocation requests by the GC for |
sjohanss@7118 | 103 | // old objects. |
sjohanss@7118 | 104 | OldGCAllocRegion _old_gc_alloc_region; |
sjohanss@7118 | 105 | |
sjohanss@7118 | 106 | HeapRegion* _retained_old_gc_alloc_region; |
sjohanss@7118 | 107 | public: |
sjohanss@7118 | 108 | G1DefaultAllocator(G1CollectedHeap* heap) : G1Allocator(heap), _retained_old_gc_alloc_region(NULL) { } |
sjohanss@7118 | 109 | |
sjohanss@7118 | 110 | virtual void init_mutator_alloc_region(); |
sjohanss@7118 | 111 | virtual void release_mutator_alloc_region(); |
sjohanss@7118 | 112 | |
sjohanss@7118 | 113 | virtual void init_gc_alloc_regions(EvacuationInfo& evacuation_info); |
sjohanss@7118 | 114 | virtual void release_gc_alloc_regions(uint no_of_gc_workers, EvacuationInfo& evacuation_info); |
sjohanss@7118 | 115 | virtual void abandon_gc_alloc_regions(); |
sjohanss@7118 | 116 | |
sjohanss@7118 | 117 | virtual bool is_retained_old_region(HeapRegion* hr) { |
sjohanss@7118 | 118 | return _retained_old_gc_alloc_region == hr; |
sjohanss@7118 | 119 | } |
sjohanss@7118 | 120 | |
sjohanss@7118 | 121 | virtual MutatorAllocRegion* mutator_alloc_region(AllocationContext_t context) { |
sjohanss@7118 | 122 | return &_mutator_alloc_region; |
sjohanss@7118 | 123 | } |
sjohanss@7118 | 124 | |
sjohanss@7118 | 125 | virtual SurvivorGCAllocRegion* survivor_gc_alloc_region(AllocationContext_t context) { |
sjohanss@7118 | 126 | return &_survivor_gc_alloc_region; |
sjohanss@7118 | 127 | } |
sjohanss@7118 | 128 | |
sjohanss@7118 | 129 | virtual OldGCAllocRegion* old_gc_alloc_region(AllocationContext_t context) { |
sjohanss@7118 | 130 | return &_old_gc_alloc_region; |
sjohanss@7118 | 131 | } |
sjohanss@7118 | 132 | |
sjohanss@7118 | 133 | virtual size_t used() { |
sjohanss@7118 | 134 | assert(Heap_lock->owner() != NULL, |
sjohanss@7118 | 135 | "Should be owned on this thread's behalf."); |
sjohanss@7118 | 136 | size_t result = _summary_bytes_used; |
sjohanss@7118 | 137 | |
sjohanss@7118 | 138 | // Read only once in case it is set to NULL concurrently |
sjohanss@7118 | 139 | HeapRegion* hr = mutator_alloc_region(AllocationContext::current())->get(); |
sjohanss@7118 | 140 | if (hr != NULL) { |
sjohanss@7118 | 141 | result += hr->used(); |
sjohanss@7118 | 142 | } |
sjohanss@7118 | 143 | return result; |
sjohanss@7118 | 144 | } |
sjohanss@7118 | 145 | }; |
sjohanss@7118 | 146 | |
sjohanss@7118 | 147 | class G1ParGCAllocBuffer: public ParGCAllocBuffer { |
sjohanss@7118 | 148 | private: |
sjohanss@7118 | 149 | bool _retired; |
sjohanss@7118 | 150 | |
sjohanss@7118 | 151 | public: |
sjohanss@7118 | 152 | G1ParGCAllocBuffer(size_t gclab_word_size); |
sjohanss@7118 | 153 | virtual ~G1ParGCAllocBuffer() { |
sjohanss@7118 | 154 | guarantee(_retired, "Allocation buffer has not been retired"); |
sjohanss@7118 | 155 | } |
sjohanss@7118 | 156 | |
sjohanss@7118 | 157 | virtual void set_buf(HeapWord* buf) { |
sjohanss@7118 | 158 | ParGCAllocBuffer::set_buf(buf); |
sjohanss@7118 | 159 | _retired = false; |
sjohanss@7118 | 160 | } |
sjohanss@7118 | 161 | |
sjohanss@7118 | 162 | virtual void retire(bool end_of_gc, bool retain) { |
sjohanss@7118 | 163 | if (_retired) { |
sjohanss@7118 | 164 | return; |
sjohanss@7118 | 165 | } |
sjohanss@7118 | 166 | ParGCAllocBuffer::retire(end_of_gc, retain); |
sjohanss@7118 | 167 | _retired = true; |
sjohanss@7118 | 168 | } |
sjohanss@7118 | 169 | }; |
sjohanss@7118 | 170 | |
sjohanss@7118 | 171 | class G1ParGCAllocator : public CHeapObj<mtGC> { |
sjohanss@7118 | 172 | friend class G1ParScanThreadState; |
sjohanss@7118 | 173 | protected: |
sjohanss@7118 | 174 | G1CollectedHeap* _g1h; |
sjohanss@7118 | 175 | |
tschatzl@7651 | 176 | // The survivor alignment in effect in bytes. |
tschatzl@7651 | 177 | // == 0 : don't align survivors |
tschatzl@7651 | 178 | // != 0 : align survivors to that alignment |
tschatzl@7651 | 179 | // These values were chosen to favor the non-alignment case since some |
tschatzl@7651 | 180 | // architectures have a special compare against zero instructions. |
tschatzl@7651 | 181 | const uint _survivor_alignment_bytes; |
tschatzl@7651 | 182 | |
sjohanss@7118 | 183 | size_t _alloc_buffer_waste; |
sjohanss@7118 | 184 | size_t _undo_waste; |
sjohanss@7118 | 185 | |
sjohanss@7118 | 186 | void add_to_alloc_buffer_waste(size_t waste) { _alloc_buffer_waste += waste; } |
sjohanss@7118 | 187 | void add_to_undo_waste(size_t waste) { _undo_waste += waste; } |
sjohanss@7118 | 188 | |
tschatzl@7651 | 189 | virtual void retire_alloc_buffers() = 0; |
tschatzl@7651 | 190 | virtual G1ParGCAllocBuffer* alloc_buffer(InCSetState dest, AllocationContext_t context) = 0; |
sjohanss@7118 | 191 | |
tschatzl@7651 | 192 | // Calculate the survivor space object alignment in bytes. Returns that or 0 if |
tschatzl@7651 | 193 | // there are no restrictions on survivor alignment. |
tschatzl@7651 | 194 | static uint calc_survivor_alignment_bytes() { |
tschatzl@7651 | 195 | assert(SurvivorAlignmentInBytes >= ObjectAlignmentInBytes, "sanity"); |
tschatzl@7651 | 196 | if (SurvivorAlignmentInBytes == ObjectAlignmentInBytes) { |
tschatzl@7651 | 197 | // No need to align objects in the survivors differently, return 0 |
tschatzl@7651 | 198 | // which means "survivor alignment is not used". |
tschatzl@7651 | 199 | return 0; |
tschatzl@7651 | 200 | } else { |
tschatzl@7651 | 201 | assert(SurvivorAlignmentInBytes > 0, "sanity"); |
tschatzl@7651 | 202 | return SurvivorAlignmentInBytes; |
tschatzl@7651 | 203 | } |
tschatzl@7651 | 204 | } |
sjohanss@7118 | 205 | |
sjohanss@7118 | 206 | public: |
sjohanss@7118 | 207 | G1ParGCAllocator(G1CollectedHeap* g1h) : |
tschatzl@7651 | 208 | _g1h(g1h), _survivor_alignment_bytes(calc_survivor_alignment_bytes()), |
tschatzl@7651 | 209 | _alloc_buffer_waste(0), _undo_waste(0) { |
sjohanss@7118 | 210 | } |
sjohanss@7118 | 211 | |
sjohanss@7118 | 212 | static G1ParGCAllocator* create_allocator(G1CollectedHeap* g1h); |
sjohanss@7118 | 213 | |
sjohanss@7118 | 214 | size_t alloc_buffer_waste() { return _alloc_buffer_waste; } |
sjohanss@7118 | 215 | size_t undo_waste() {return _undo_waste; } |
sjohanss@7118 | 216 | |
tschatzl@7651 | 217 | // Allocate word_sz words in dest, either directly into the regions or by |
tschatzl@7651 | 218 | // allocating a new PLAB. Returns the address of the allocated memory, NULL if |
tschatzl@7651 | 219 | // not successful. |
tschatzl@7651 | 220 | HeapWord* allocate_direct_or_new_plab(InCSetState dest, |
tschatzl@7651 | 221 | size_t word_sz, |
tschatzl@7651 | 222 | AllocationContext_t context); |
tschatzl@7651 | 223 | |
tschatzl@7651 | 224 | // Allocate word_sz words in the PLAB of dest. Returns the address of the |
tschatzl@7651 | 225 | // allocated memory, NULL if not successful. |
tschatzl@7651 | 226 | HeapWord* plab_allocate(InCSetState dest, |
tschatzl@7651 | 227 | size_t word_sz, |
tschatzl@7651 | 228 | AllocationContext_t context) { |
tschatzl@7651 | 229 | G1ParGCAllocBuffer* buffer = alloc_buffer(dest, context); |
tschatzl@7651 | 230 | if (_survivor_alignment_bytes == 0) { |
tschatzl@7651 | 231 | return buffer->allocate(word_sz); |
sjohanss@7118 | 232 | } else { |
tschatzl@7651 | 233 | return buffer->allocate_aligned(word_sz, _survivor_alignment_bytes); |
sjohanss@7118 | 234 | } |
tschatzl@7651 | 235 | } |
tschatzl@7651 | 236 | |
tschatzl@7651 | 237 | HeapWord* allocate(InCSetState dest, size_t word_sz, |
tschatzl@7651 | 238 | AllocationContext_t context) { |
tschatzl@7651 | 239 | HeapWord* const obj = plab_allocate(dest, word_sz, context); |
sjohanss@7118 | 240 | if (obj != NULL) { |
sjohanss@7118 | 241 | return obj; |
sjohanss@7118 | 242 | } |
tschatzl@7651 | 243 | return allocate_direct_or_new_plab(dest, word_sz, context); |
sjohanss@7118 | 244 | } |
sjohanss@7118 | 245 | |
tschatzl@7651 | 246 | void undo_allocation(InCSetState dest, HeapWord* obj, size_t word_sz, AllocationContext_t context) { |
tschatzl@7651 | 247 | if (alloc_buffer(dest, context)->contains(obj)) { |
tschatzl@7651 | 248 | assert(alloc_buffer(dest, context)->contains(obj + word_sz - 1), |
sjohanss@7118 | 249 | "should contain whole object"); |
tschatzl@7651 | 250 | alloc_buffer(dest, context)->undo_allocation(obj, word_sz); |
sjohanss@7118 | 251 | } else { |
sjohanss@7118 | 252 | CollectedHeap::fill_with_object(obj, word_sz); |
sjohanss@7118 | 253 | add_to_undo_waste(word_sz); |
sjohanss@7118 | 254 | } |
sjohanss@7118 | 255 | } |
sjohanss@7118 | 256 | }; |
sjohanss@7118 | 257 | |
sjohanss@7118 | 258 | class G1DefaultParGCAllocator : public G1ParGCAllocator { |
sjohanss@7118 | 259 | G1ParGCAllocBuffer _surviving_alloc_buffer; |
sjohanss@7118 | 260 | G1ParGCAllocBuffer _tenured_alloc_buffer; |
tschatzl@7651 | 261 | G1ParGCAllocBuffer* _alloc_buffers[InCSetState::Num]; |
sjohanss@7118 | 262 | |
sjohanss@7118 | 263 | public: |
sjohanss@7118 | 264 | G1DefaultParGCAllocator(G1CollectedHeap* g1h); |
sjohanss@7118 | 265 | |
tschatzl@7651 | 266 | virtual G1ParGCAllocBuffer* alloc_buffer(InCSetState dest, AllocationContext_t context) { |
tschatzl@7651 | 267 | assert(dest.is_valid(), |
tschatzl@7651 | 268 | err_msg("Allocation buffer index out-of-bounds: " CSETSTATE_FORMAT, dest.value())); |
tschatzl@7651 | 269 | assert(_alloc_buffers[dest.value()] != NULL, |
tschatzl@7651 | 270 | err_msg("Allocation buffer is NULL: " CSETSTATE_FORMAT, dest.value())); |
tschatzl@7651 | 271 | return _alloc_buffers[dest.value()]; |
sjohanss@7118 | 272 | } |
sjohanss@7118 | 273 | |
sjohanss@7118 | 274 | virtual void retire_alloc_buffers() ; |
sjohanss@7118 | 275 | }; |
sjohanss@7118 | 276 | |
sjohanss@7118 | 277 | #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1ALLOCATOR_HPP |