Wed, 27 Apr 2016 01:25:04 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #ifndef SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_COMPACTIBLEFREELISTSPACE_HPP |
aoqi@0 | 26 | #define SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_COMPACTIBLEFREELISTSPACE_HPP |
aoqi@0 | 27 | |
aoqi@0 | 28 | #include "gc_implementation/concurrentMarkSweep/adaptiveFreeList.hpp" |
aoqi@0 | 29 | #include "gc_implementation/concurrentMarkSweep/promotionInfo.hpp" |
aoqi@0 | 30 | #include "memory/binaryTreeDictionary.hpp" |
aoqi@0 | 31 | #include "memory/blockOffsetTable.inline.hpp" |
aoqi@0 | 32 | #include "memory/freeList.hpp" |
aoqi@0 | 33 | #include "memory/space.hpp" |
aoqi@0 | 34 | |
aoqi@0 | 35 | // Classes in support of keeping track of promotions into a non-Contiguous |
aoqi@0 | 36 | // space, in this case a CompactibleFreeListSpace. |
aoqi@0 | 37 | |
aoqi@0 | 38 | // Forward declarations |
aoqi@0 | 39 | class CompactibleFreeListSpace; |
aoqi@0 | 40 | class BlkClosure; |
aoqi@0 | 41 | class BlkClosureCareful; |
aoqi@0 | 42 | class FreeChunk; |
aoqi@0 | 43 | class UpwardsObjectClosure; |
aoqi@0 | 44 | class ObjectClosureCareful; |
aoqi@0 | 45 | class Klass; |
aoqi@0 | 46 | |
aoqi@0 | 47 | class LinearAllocBlock VALUE_OBJ_CLASS_SPEC { |
aoqi@0 | 48 | public: |
aoqi@0 | 49 | LinearAllocBlock() : _ptr(0), _word_size(0), _refillSize(0), |
aoqi@0 | 50 | _allocation_size_limit(0) {} |
aoqi@0 | 51 | void set(HeapWord* ptr, size_t word_size, size_t refill_size, |
aoqi@0 | 52 | size_t allocation_size_limit) { |
aoqi@0 | 53 | _ptr = ptr; |
aoqi@0 | 54 | _word_size = word_size; |
aoqi@0 | 55 | _refillSize = refill_size; |
aoqi@0 | 56 | _allocation_size_limit = allocation_size_limit; |
aoqi@0 | 57 | } |
aoqi@0 | 58 | HeapWord* _ptr; |
aoqi@0 | 59 | size_t _word_size; |
aoqi@0 | 60 | size_t _refillSize; |
aoqi@0 | 61 | size_t _allocation_size_limit; // largest size that will be allocated |
aoqi@0 | 62 | |
aoqi@0 | 63 | void print_on(outputStream* st) const; |
aoqi@0 | 64 | }; |
aoqi@0 | 65 | |
aoqi@0 | 66 | // Concrete subclass of CompactibleSpace that implements |
aoqi@0 | 67 | // a free list space, such as used in the concurrent mark sweep |
aoqi@0 | 68 | // generation. |
aoqi@0 | 69 | |
aoqi@0 | 70 | class CompactibleFreeListSpace: public CompactibleSpace { |
aoqi@0 | 71 | friend class VMStructs; |
aoqi@0 | 72 | friend class ConcurrentMarkSweepGeneration; |
aoqi@0 | 73 | friend class ASConcurrentMarkSweepGeneration; |
aoqi@0 | 74 | friend class CMSCollector; |
aoqi@0 | 75 | // Local alloc buffer for promotion into this space. |
aoqi@0 | 76 | friend class CFLS_LAB; |
aoqi@0 | 77 | |
aoqi@0 | 78 | // "Size" of chunks of work (executed during parallel remark phases |
aoqi@0 | 79 | // of CMS collection); this probably belongs in CMSCollector, although |
aoqi@0 | 80 | // it's cached here because it's used in |
aoqi@0 | 81 | // initialize_sequential_subtasks_for_rescan() which modifies |
aoqi@0 | 82 | // par_seq_tasks which also lives in Space. XXX |
aoqi@0 | 83 | const size_t _rescan_task_size; |
aoqi@0 | 84 | const size_t _marking_task_size; |
aoqi@0 | 85 | |
aoqi@0 | 86 | // Yet another sequential tasks done structure. This supports |
aoqi@0 | 87 | // CMS GC, where we have threads dynamically |
aoqi@0 | 88 | // claiming sub-tasks from a larger parallel task. |
aoqi@0 | 89 | SequentialSubTasksDone _conc_par_seq_tasks; |
aoqi@0 | 90 | |
aoqi@0 | 91 | BlockOffsetArrayNonContigSpace _bt; |
aoqi@0 | 92 | |
aoqi@0 | 93 | CMSCollector* _collector; |
aoqi@0 | 94 | ConcurrentMarkSweepGeneration* _gen; |
aoqi@0 | 95 | |
aoqi@0 | 96 | // Data structures for free blocks (used during allocation/sweeping) |
aoqi@0 | 97 | |
aoqi@0 | 98 | // Allocation is done linearly from two different blocks depending on |
aoqi@0 | 99 | // whether the request is small or large, in an effort to reduce |
aoqi@0 | 100 | // fragmentation. We assume that any locking for allocation is done |
aoqi@0 | 101 | // by the containing generation. Thus, none of the methods in this |
aoqi@0 | 102 | // space are re-entrant. |
aoqi@0 | 103 | enum SomeConstants { |
aoqi@0 | 104 | SmallForLinearAlloc = 16, // size < this then use _sLAB |
aoqi@0 | 105 | SmallForDictionary = 257, // size < this then use _indexedFreeList |
aoqi@0 | 106 | IndexSetSize = SmallForDictionary // keep this odd-sized |
aoqi@0 | 107 | }; |
aoqi@0 | 108 | static size_t IndexSetStart; |
aoqi@0 | 109 | static size_t IndexSetStride; |
aoqi@0 | 110 | |
aoqi@0 | 111 | private: |
aoqi@0 | 112 | enum FitStrategyOptions { |
aoqi@0 | 113 | FreeBlockStrategyNone = 0, |
aoqi@0 | 114 | FreeBlockBestFitFirst |
aoqi@0 | 115 | }; |
aoqi@0 | 116 | |
aoqi@0 | 117 | PromotionInfo _promoInfo; |
aoqi@0 | 118 | |
aoqi@0 | 119 | // helps to impose a global total order on freelistLock ranks; |
aoqi@0 | 120 | // assumes that CFLSpace's are allocated in global total order |
aoqi@0 | 121 | static int _lockRank; |
aoqi@0 | 122 | |
aoqi@0 | 123 | // a lock protecting the free lists and free blocks; |
aoqi@0 | 124 | // mutable because of ubiquity of locking even for otherwise const methods |
aoqi@0 | 125 | mutable Mutex _freelistLock; |
aoqi@0 | 126 | // locking verifier convenience function |
aoqi@0 | 127 | void assert_locked() const PRODUCT_RETURN; |
aoqi@0 | 128 | void assert_locked(const Mutex* lock) const PRODUCT_RETURN; |
aoqi@0 | 129 | |
aoqi@0 | 130 | // Linear allocation blocks |
aoqi@0 | 131 | LinearAllocBlock _smallLinearAllocBlock; |
aoqi@0 | 132 | |
aoqi@0 | 133 | FreeBlockDictionary<FreeChunk>::DictionaryChoice _dictionaryChoice; |
aoqi@0 | 134 | AFLBinaryTreeDictionary* _dictionary; // ptr to dictionary for large size blocks |
aoqi@0 | 135 | |
aoqi@0 | 136 | AdaptiveFreeList<FreeChunk> _indexedFreeList[IndexSetSize]; |
aoqi@0 | 137 | // indexed array for small size blocks |
aoqi@0 | 138 | // allocation stategy |
aoqi@0 | 139 | bool _fitStrategy; // Use best fit strategy. |
aoqi@0 | 140 | bool _adaptive_freelists; // Use adaptive freelists |
aoqi@0 | 141 | |
aoqi@0 | 142 | // This is an address close to the largest free chunk in the heap. |
aoqi@0 | 143 | // It is currently assumed to be at the end of the heap. Free |
aoqi@0 | 144 | // chunks with addresses greater than nearLargestChunk are coalesced |
aoqi@0 | 145 | // in an effort to maintain a large chunk at the end of the heap. |
aoqi@0 | 146 | HeapWord* _nearLargestChunk; |
aoqi@0 | 147 | |
aoqi@0 | 148 | // Used to keep track of limit of sweep for the space |
aoqi@0 | 149 | HeapWord* _sweep_limit; |
aoqi@0 | 150 | |
aoqi@0 | 151 | // Support for compacting cms |
aoqi@0 | 152 | HeapWord* cross_threshold(HeapWord* start, HeapWord* end); |
aoqi@0 | 153 | HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top); |
aoqi@0 | 154 | |
aoqi@0 | 155 | // Initialization helpers. |
aoqi@0 | 156 | void initializeIndexedFreeListArray(); |
aoqi@0 | 157 | |
aoqi@0 | 158 | // Extra stuff to manage promotion parallelism. |
aoqi@0 | 159 | |
aoqi@0 | 160 | // a lock protecting the dictionary during par promotion allocation. |
aoqi@0 | 161 | mutable Mutex _parDictionaryAllocLock; |
aoqi@0 | 162 | Mutex* parDictionaryAllocLock() const { return &_parDictionaryAllocLock; } |
aoqi@0 | 163 | |
aoqi@0 | 164 | // Locks protecting the exact lists during par promotion allocation. |
aoqi@0 | 165 | Mutex* _indexedFreeListParLocks[IndexSetSize]; |
aoqi@0 | 166 | |
aoqi@0 | 167 | // Attempt to obtain up to "n" blocks of the size "word_sz" (which is |
aoqi@0 | 168 | // required to be smaller than "IndexSetSize".) If successful, |
aoqi@0 | 169 | // adds them to "fl", which is required to be an empty free list. |
aoqi@0 | 170 | // If the count of "fl" is negative, it's absolute value indicates a |
aoqi@0 | 171 | // number of free chunks that had been previously "borrowed" from global |
aoqi@0 | 172 | // list of size "word_sz", and must now be decremented. |
aoqi@0 | 173 | void par_get_chunk_of_blocks(size_t word_sz, size_t n, AdaptiveFreeList<FreeChunk>* fl); |
aoqi@0 | 174 | |
aoqi@0 | 175 | // Allocation helper functions |
aoqi@0 | 176 | // Allocate using a strategy that takes from the indexed free lists |
aoqi@0 | 177 | // first. This allocation strategy assumes a companion sweeping |
aoqi@0 | 178 | // strategy that attempts to keep the needed number of chunks in each |
aoqi@0 | 179 | // indexed free lists. |
aoqi@0 | 180 | HeapWord* allocate_adaptive_freelists(size_t size); |
aoqi@0 | 181 | // Allocate from the linear allocation buffers first. This allocation |
aoqi@0 | 182 | // strategy assumes maximal coalescing can maintain chunks large enough |
aoqi@0 | 183 | // to be used as linear allocation buffers. |
aoqi@0 | 184 | HeapWord* allocate_non_adaptive_freelists(size_t size); |
aoqi@0 | 185 | |
aoqi@0 | 186 | // Gets a chunk from the linear allocation block (LinAB). If there |
aoqi@0 | 187 | // is not enough space in the LinAB, refills it. |
aoqi@0 | 188 | HeapWord* getChunkFromLinearAllocBlock(LinearAllocBlock* blk, size_t size); |
aoqi@0 | 189 | HeapWord* getChunkFromSmallLinearAllocBlock(size_t size); |
aoqi@0 | 190 | // Get a chunk from the space remaining in the linear allocation block. Do |
aoqi@0 | 191 | // not attempt to refill if the space is not available, return NULL. Do the |
aoqi@0 | 192 | // repairs on the linear allocation block as appropriate. |
aoqi@0 | 193 | HeapWord* getChunkFromLinearAllocBlockRemainder(LinearAllocBlock* blk, size_t size); |
aoqi@0 | 194 | inline HeapWord* getChunkFromSmallLinearAllocBlockRemainder(size_t size); |
aoqi@0 | 195 | |
aoqi@0 | 196 | // Helper function for getChunkFromIndexedFreeList. |
aoqi@0 | 197 | // Replenish the indexed free list for this "size". Do not take from an |
aoqi@0 | 198 | // underpopulated size. |
aoqi@0 | 199 | FreeChunk* getChunkFromIndexedFreeListHelper(size_t size, bool replenish = true); |
aoqi@0 | 200 | |
aoqi@0 | 201 | // Get a chunk from the indexed free list. If the indexed free list |
aoqi@0 | 202 | // does not have a free chunk, try to replenish the indexed free list |
aoqi@0 | 203 | // then get the free chunk from the replenished indexed free list. |
aoqi@0 | 204 | inline FreeChunk* getChunkFromIndexedFreeList(size_t size); |
aoqi@0 | 205 | |
aoqi@0 | 206 | // The returned chunk may be larger than requested (or null). |
aoqi@0 | 207 | FreeChunk* getChunkFromDictionary(size_t size); |
aoqi@0 | 208 | // The returned chunk is the exact size requested (or null). |
aoqi@0 | 209 | FreeChunk* getChunkFromDictionaryExact(size_t size); |
aoqi@0 | 210 | |
aoqi@0 | 211 | // Find a chunk in the indexed free list that is the best |
aoqi@0 | 212 | // fit for size "numWords". |
aoqi@0 | 213 | FreeChunk* bestFitSmall(size_t numWords); |
aoqi@0 | 214 | // For free list "fl" of chunks of size > numWords, |
aoqi@0 | 215 | // remove a chunk, split off a chunk of size numWords |
aoqi@0 | 216 | // and return it. The split off remainder is returned to |
aoqi@0 | 217 | // the free lists. The old name for getFromListGreater |
aoqi@0 | 218 | // was lookInListGreater. |
aoqi@0 | 219 | FreeChunk* getFromListGreater(AdaptiveFreeList<FreeChunk>* fl, size_t numWords); |
aoqi@0 | 220 | // Get a chunk in the indexed free list or dictionary, |
aoqi@0 | 221 | // by considering a larger chunk and splitting it. |
aoqi@0 | 222 | FreeChunk* getChunkFromGreater(size_t numWords); |
aoqi@0 | 223 | // Verify that the given chunk is in the indexed free lists. |
aoqi@0 | 224 | bool verifyChunkInIndexedFreeLists(FreeChunk* fc) const; |
aoqi@0 | 225 | // Remove the specified chunk from the indexed free lists. |
aoqi@0 | 226 | void removeChunkFromIndexedFreeList(FreeChunk* fc); |
aoqi@0 | 227 | // Remove the specified chunk from the dictionary. |
aoqi@0 | 228 | void removeChunkFromDictionary(FreeChunk* fc); |
aoqi@0 | 229 | // Split a free chunk into a smaller free chunk of size "new_size". |
aoqi@0 | 230 | // Return the smaller free chunk and return the remainder to the |
aoqi@0 | 231 | // free lists. |
aoqi@0 | 232 | FreeChunk* splitChunkAndReturnRemainder(FreeChunk* chunk, size_t new_size); |
aoqi@0 | 233 | // Add a chunk to the free lists. |
aoqi@0 | 234 | void addChunkToFreeLists(HeapWord* chunk, size_t size); |
aoqi@0 | 235 | // Add a chunk to the free lists, preferring to suffix it |
aoqi@0 | 236 | // to the last free chunk at end of space if possible, and |
aoqi@0 | 237 | // updating the block census stats as well as block offset table. |
aoqi@0 | 238 | // Take any locks as appropriate if we are multithreaded. |
aoqi@0 | 239 | void addChunkToFreeListsAtEndRecordingStats(HeapWord* chunk, size_t size); |
aoqi@0 | 240 | // Add a free chunk to the indexed free lists. |
aoqi@0 | 241 | void returnChunkToFreeList(FreeChunk* chunk); |
aoqi@0 | 242 | // Add a free chunk to the dictionary. |
aoqi@0 | 243 | void returnChunkToDictionary(FreeChunk* chunk); |
aoqi@0 | 244 | |
aoqi@0 | 245 | // Functions for maintaining the linear allocation buffers (LinAB). |
aoqi@0 | 246 | // Repairing a linear allocation block refers to operations |
aoqi@0 | 247 | // performed on the remainder of a LinAB after an allocation |
aoqi@0 | 248 | // has been made from it. |
aoqi@0 | 249 | void repairLinearAllocationBlocks(); |
aoqi@0 | 250 | void repairLinearAllocBlock(LinearAllocBlock* blk); |
aoqi@0 | 251 | void refillLinearAllocBlock(LinearAllocBlock* blk); |
aoqi@0 | 252 | void refillLinearAllocBlockIfNeeded(LinearAllocBlock* blk); |
aoqi@0 | 253 | void refillLinearAllocBlocksIfNeeded(); |
aoqi@0 | 254 | |
aoqi@0 | 255 | void verify_objects_initialized() const; |
aoqi@0 | 256 | |
aoqi@0 | 257 | // Statistics reporting helper functions |
aoqi@0 | 258 | void reportFreeListStatistics() const; |
aoqi@0 | 259 | void reportIndexedFreeListStatistics() const; |
aoqi@0 | 260 | size_t maxChunkSizeInIndexedFreeLists() const; |
aoqi@0 | 261 | size_t numFreeBlocksInIndexedFreeLists() const; |
aoqi@0 | 262 | // Accessor |
aoqi@0 | 263 | HeapWord* unallocated_block() const { |
aoqi@0 | 264 | if (BlockOffsetArrayUseUnallocatedBlock) { |
aoqi@0 | 265 | HeapWord* ub = _bt.unallocated_block(); |
aoqi@0 | 266 | assert(ub >= bottom() && |
aoqi@0 | 267 | ub <= end(), "space invariant"); |
aoqi@0 | 268 | return ub; |
aoqi@0 | 269 | } else { |
aoqi@0 | 270 | return end(); |
aoqi@0 | 271 | } |
aoqi@0 | 272 | } |
aoqi@0 | 273 | void freed(HeapWord* start, size_t size) { |
aoqi@0 | 274 | _bt.freed(start, size); |
aoqi@0 | 275 | } |
aoqi@0 | 276 | |
aoqi@0 | 277 | protected: |
aoqi@0 | 278 | // reset the indexed free list to its initial empty condition. |
aoqi@0 | 279 | void resetIndexedFreeListArray(); |
aoqi@0 | 280 | // reset to an initial state with a single free block described |
aoqi@0 | 281 | // by the MemRegion parameter. |
aoqi@0 | 282 | void reset(MemRegion mr); |
aoqi@0 | 283 | // Return the total number of words in the indexed free lists. |
aoqi@0 | 284 | size_t totalSizeInIndexedFreeLists() const; |
aoqi@0 | 285 | |
aoqi@0 | 286 | public: |
aoqi@0 | 287 | // Constructor... |
aoqi@0 | 288 | CompactibleFreeListSpace(BlockOffsetSharedArray* bs, MemRegion mr, |
aoqi@0 | 289 | bool use_adaptive_freelists, |
aoqi@0 | 290 | FreeBlockDictionary<FreeChunk>::DictionaryChoice); |
aoqi@0 | 291 | // accessors |
aoqi@0 | 292 | bool bestFitFirst() { return _fitStrategy == FreeBlockBestFitFirst; } |
aoqi@0 | 293 | FreeBlockDictionary<FreeChunk>* dictionary() const { return _dictionary; } |
aoqi@0 | 294 | HeapWord* nearLargestChunk() const { return _nearLargestChunk; } |
aoqi@0 | 295 | void set_nearLargestChunk(HeapWord* v) { _nearLargestChunk = v; } |
aoqi@0 | 296 | |
aoqi@0 | 297 | // Set CMS global values |
aoqi@0 | 298 | static void set_cms_values(); |
aoqi@0 | 299 | |
aoqi@0 | 300 | // Return the free chunk at the end of the space. If no such |
aoqi@0 | 301 | // chunk exists, return NULL. |
aoqi@0 | 302 | FreeChunk* find_chunk_at_end(); |
aoqi@0 | 303 | |
aoqi@0 | 304 | bool adaptive_freelists() const { return _adaptive_freelists; } |
aoqi@0 | 305 | |
aoqi@0 | 306 | void set_collector(CMSCollector* collector) { _collector = collector; } |
aoqi@0 | 307 | |
aoqi@0 | 308 | // Support for parallelization of rescan and marking |
aoqi@0 | 309 | const size_t rescan_task_size() const { return _rescan_task_size; } |
aoqi@0 | 310 | const size_t marking_task_size() const { return _marking_task_size; } |
aoqi@0 | 311 | SequentialSubTasksDone* conc_par_seq_tasks() {return &_conc_par_seq_tasks; } |
aoqi@0 | 312 | void initialize_sequential_subtasks_for_rescan(int n_threads); |
aoqi@0 | 313 | void initialize_sequential_subtasks_for_marking(int n_threads, |
aoqi@0 | 314 | HeapWord* low = NULL); |
aoqi@0 | 315 | |
aoqi@0 | 316 | // Space enquiries |
aoqi@0 | 317 | size_t used() const; |
aoqi@0 | 318 | size_t free() const; |
aoqi@0 | 319 | size_t max_alloc_in_words() const; |
aoqi@0 | 320 | // XXX: should have a less conservative used_region() than that of |
aoqi@0 | 321 | // Space; we could consider keeping track of highest allocated |
aoqi@0 | 322 | // address and correcting that at each sweep, as the sweeper |
aoqi@0 | 323 | // goes through the entire allocated part of the generation. We |
aoqi@0 | 324 | // could also use that information to keep the sweeper from |
aoqi@0 | 325 | // sweeping more than is necessary. The allocator and sweeper will |
aoqi@0 | 326 | // of course need to synchronize on this, since the sweeper will |
aoqi@0 | 327 | // try to bump down the address and the allocator will try to bump it up. |
aoqi@0 | 328 | // For now, however, we'll just use the default used_region() |
aoqi@0 | 329 | // which overestimates the region by returning the entire |
aoqi@0 | 330 | // committed region (this is safe, but inefficient). |
aoqi@0 | 331 | |
aoqi@0 | 332 | // Returns a subregion of the space containing all the objects in |
aoqi@0 | 333 | // the space. |
aoqi@0 | 334 | MemRegion used_region() const { |
aoqi@0 | 335 | return MemRegion(bottom(), |
aoqi@0 | 336 | BlockOffsetArrayUseUnallocatedBlock ? |
aoqi@0 | 337 | unallocated_block() : end()); |
aoqi@0 | 338 | } |
aoqi@0 | 339 | |
aoqi@0 | 340 | bool is_in(const void* p) const { |
aoqi@0 | 341 | return used_region().contains(p); |
aoqi@0 | 342 | } |
aoqi@0 | 343 | |
aoqi@0 | 344 | virtual bool is_free_block(const HeapWord* p) const; |
aoqi@0 | 345 | |
aoqi@0 | 346 | // Resizing support |
aoqi@0 | 347 | void set_end(HeapWord* value); // override |
aoqi@0 | 348 | |
aoqi@0 | 349 | // mutual exclusion support |
aoqi@0 | 350 | Mutex* freelistLock() const { return &_freelistLock; } |
aoqi@0 | 351 | |
aoqi@0 | 352 | // Iteration support |
aoqi@0 | 353 | void oop_iterate(MemRegion mr, ExtendedOopClosure* cl); |
aoqi@0 | 354 | void oop_iterate(ExtendedOopClosure* cl); |
aoqi@0 | 355 | |
aoqi@0 | 356 | void object_iterate(ObjectClosure* blk); |
aoqi@0 | 357 | // Apply the closure to each object in the space whose references |
aoqi@0 | 358 | // point to objects in the heap. The usage of CompactibleFreeListSpace |
aoqi@0 | 359 | // by the ConcurrentMarkSweepGeneration for concurrent GC's allows |
aoqi@0 | 360 | // objects in the space with references to objects that are no longer |
aoqi@0 | 361 | // valid. For example, an object may reference another object |
aoqi@0 | 362 | // that has already been sweep up (collected). This method uses |
aoqi@0 | 363 | // obj_is_alive() to determine whether it is safe to iterate of |
aoqi@0 | 364 | // an object. |
aoqi@0 | 365 | void safe_object_iterate(ObjectClosure* blk); |
aoqi@0 | 366 | void object_iterate_mem(MemRegion mr, UpwardsObjectClosure* cl); |
aoqi@0 | 367 | |
aoqi@0 | 368 | // Requires that "mr" be entirely within the space. |
aoqi@0 | 369 | // Apply "cl->do_object" to all objects that intersect with "mr". |
aoqi@0 | 370 | // If the iteration encounters an unparseable portion of the region, |
aoqi@0 | 371 | // terminate the iteration and return the address of the start of the |
aoqi@0 | 372 | // subregion that isn't done. Return of "NULL" indicates that the |
aoqi@0 | 373 | // interation completed. |
aoqi@0 | 374 | virtual HeapWord* |
aoqi@0 | 375 | object_iterate_careful_m(MemRegion mr, |
aoqi@0 | 376 | ObjectClosureCareful* cl); |
aoqi@0 | 377 | virtual HeapWord* |
aoqi@0 | 378 | object_iterate_careful(ObjectClosureCareful* cl); |
aoqi@0 | 379 | |
aoqi@0 | 380 | // Override: provides a DCTO_CL specific to this kind of space. |
aoqi@0 | 381 | DirtyCardToOopClosure* new_dcto_cl(ExtendedOopClosure* cl, |
aoqi@0 | 382 | CardTableModRefBS::PrecisionStyle precision, |
aoqi@0 | 383 | HeapWord* boundary); |
aoqi@0 | 384 | |
aoqi@0 | 385 | void blk_iterate(BlkClosure* cl); |
aoqi@0 | 386 | void blk_iterate_careful(BlkClosureCareful* cl); |
aoqi@0 | 387 | HeapWord* block_start_const(const void* p) const; |
aoqi@0 | 388 | HeapWord* block_start_careful(const void* p) const; |
aoqi@0 | 389 | size_t block_size(const HeapWord* p) const; |
aoqi@0 | 390 | size_t block_size_no_stall(HeapWord* p, const CMSCollector* c) const; |
aoqi@0 | 391 | bool block_is_obj(const HeapWord* p) const; |
aoqi@0 | 392 | bool obj_is_alive(const HeapWord* p) const; |
aoqi@0 | 393 | size_t block_size_nopar(const HeapWord* p) const; |
aoqi@0 | 394 | bool block_is_obj_nopar(const HeapWord* p) const; |
aoqi@0 | 395 | |
aoqi@0 | 396 | // iteration support for promotion |
aoqi@0 | 397 | void save_marks(); |
aoqi@0 | 398 | bool no_allocs_since_save_marks(); |
aoqi@0 | 399 | |
aoqi@0 | 400 | // iteration support for sweeping |
aoqi@0 | 401 | void save_sweep_limit() { |
aoqi@0 | 402 | _sweep_limit = BlockOffsetArrayUseUnallocatedBlock ? |
aoqi@0 | 403 | unallocated_block() : end(); |
aoqi@0 | 404 | if (CMSTraceSweeper) { |
aoqi@0 | 405 | gclog_or_tty->print_cr(">>>>> Saving sweep limit " PTR_FORMAT |
aoqi@0 | 406 | " for space [" PTR_FORMAT "," PTR_FORMAT ") <<<<<<", |
aoqi@0 | 407 | p2i(_sweep_limit), p2i(bottom()), p2i(end())); |
aoqi@0 | 408 | } |
aoqi@0 | 409 | } |
aoqi@0 | 410 | NOT_PRODUCT( |
aoqi@0 | 411 | void clear_sweep_limit() { _sweep_limit = NULL; } |
aoqi@0 | 412 | ) |
aoqi@0 | 413 | HeapWord* sweep_limit() { return _sweep_limit; } |
aoqi@0 | 414 | |
aoqi@0 | 415 | // Apply "blk->do_oop" to the addresses of all reference fields in objects |
aoqi@0 | 416 | // promoted into this generation since the most recent save_marks() call. |
aoqi@0 | 417 | // Fields in objects allocated by applications of the closure |
aoqi@0 | 418 | // *are* included in the iteration. Thus, when the iteration completes |
aoqi@0 | 419 | // there should be no further such objects remaining. |
aoqi@0 | 420 | #define CFLS_OOP_SINCE_SAVE_MARKS_DECL(OopClosureType, nv_suffix) \ |
aoqi@0 | 421 | void oop_since_save_marks_iterate##nv_suffix(OopClosureType* blk); |
aoqi@0 | 422 | ALL_SINCE_SAVE_MARKS_CLOSURES(CFLS_OOP_SINCE_SAVE_MARKS_DECL) |
aoqi@0 | 423 | #undef CFLS_OOP_SINCE_SAVE_MARKS_DECL |
aoqi@0 | 424 | |
aoqi@0 | 425 | // Allocation support |
aoqi@0 | 426 | HeapWord* allocate(size_t size); |
aoqi@0 | 427 | HeapWord* par_allocate(size_t size); |
aoqi@0 | 428 | |
aoqi@0 | 429 | oop promote(oop obj, size_t obj_size); |
aoqi@0 | 430 | void gc_prologue(); |
aoqi@0 | 431 | void gc_epilogue(); |
aoqi@0 | 432 | |
aoqi@0 | 433 | // This call is used by a containing CMS generation / collector |
aoqi@0 | 434 | // to inform the CFLS space that a sweep has been completed |
aoqi@0 | 435 | // and that the space can do any related house-keeping functions. |
aoqi@0 | 436 | void sweep_completed(); |
aoqi@0 | 437 | |
aoqi@0 | 438 | // For an object in this space, the mark-word's two |
aoqi@0 | 439 | // LSB's having the value [11] indicates that it has been |
aoqi@0 | 440 | // promoted since the most recent call to save_marks() on |
aoqi@0 | 441 | // this generation and has not subsequently been iterated |
aoqi@0 | 442 | // over (using oop_since_save_marks_iterate() above). |
aoqi@0 | 443 | // This property holds only for single-threaded collections, |
aoqi@0 | 444 | // and is typically used for Cheney scans; for MT scavenges, |
aoqi@0 | 445 | // the property holds for all objects promoted during that |
aoqi@0 | 446 | // scavenge for the duration of the scavenge and is used |
aoqi@0 | 447 | // by card-scanning to avoid scanning objects (being) promoted |
aoqi@0 | 448 | // during that scavenge. |
aoqi@0 | 449 | bool obj_allocated_since_save_marks(const oop obj) const { |
aoqi@0 | 450 | assert(is_in_reserved(obj), "Wrong space?"); |
aoqi@0 | 451 | return ((PromotedObject*)obj)->hasPromotedMark(); |
aoqi@0 | 452 | } |
aoqi@0 | 453 | |
aoqi@0 | 454 | // A worst-case estimate of the space required (in HeapWords) to expand the |
aoqi@0 | 455 | // heap when promoting an obj of size obj_size. |
aoqi@0 | 456 | size_t expansionSpaceRequired(size_t obj_size) const; |
aoqi@0 | 457 | |
aoqi@0 | 458 | FreeChunk* allocateScratch(size_t size); |
aoqi@0 | 459 | |
aoqi@0 | 460 | // returns true if either the small or large linear allocation buffer is empty. |
aoqi@0 | 461 | bool linearAllocationWouldFail() const; |
aoqi@0 | 462 | |
aoqi@0 | 463 | // Adjust the chunk for the minimum size. This version is called in |
aoqi@0 | 464 | // most cases in CompactibleFreeListSpace methods. |
aoqi@0 | 465 | inline static size_t adjustObjectSize(size_t size) { |
aoqi@0 | 466 | return (size_t) align_object_size(MAX2(size, (size_t)MinChunkSize)); |
aoqi@0 | 467 | } |
aoqi@0 | 468 | // This is a virtual version of adjustObjectSize() that is called |
aoqi@0 | 469 | // only occasionally when the compaction space changes and the type |
aoqi@0 | 470 | // of the new compaction space is is only known to be CompactibleSpace. |
aoqi@0 | 471 | size_t adjust_object_size_v(size_t size) const { |
aoqi@0 | 472 | return adjustObjectSize(size); |
aoqi@0 | 473 | } |
aoqi@0 | 474 | // Minimum size of a free block. |
aoqi@0 | 475 | virtual size_t minimum_free_block_size() const { return MinChunkSize; } |
aoqi@0 | 476 | void removeFreeChunkFromFreeLists(FreeChunk* chunk); |
aoqi@0 | 477 | void addChunkAndRepairOffsetTable(HeapWord* chunk, size_t size, |
aoqi@0 | 478 | bool coalesced); |
aoqi@0 | 479 | |
aoqi@0 | 480 | // Support for decisions regarding concurrent collection policy |
aoqi@0 | 481 | bool should_concurrent_collect() const; |
aoqi@0 | 482 | |
aoqi@0 | 483 | // Support for compaction |
aoqi@0 | 484 | void prepare_for_compaction(CompactPoint* cp); |
aoqi@0 | 485 | void adjust_pointers(); |
aoqi@0 | 486 | void compact(); |
aoqi@0 | 487 | // reset the space to reflect the fact that a compaction of the |
aoqi@0 | 488 | // space has been done. |
aoqi@0 | 489 | virtual void reset_after_compaction(); |
aoqi@0 | 490 | |
aoqi@0 | 491 | // Debugging support |
aoqi@0 | 492 | void print() const; |
aoqi@0 | 493 | void print_on(outputStream* st) const; |
aoqi@0 | 494 | void prepare_for_verify(); |
aoqi@0 | 495 | void verify() const; |
aoqi@0 | 496 | void verifyFreeLists() const PRODUCT_RETURN; |
aoqi@0 | 497 | void verifyIndexedFreeLists() const; |
aoqi@0 | 498 | void verifyIndexedFreeList(size_t size) const; |
aoqi@0 | 499 | // Verify that the given chunk is in the free lists: |
aoqi@0 | 500 | // i.e. either the binary tree dictionary, the indexed free lists |
aoqi@0 | 501 | // or the linear allocation block. |
aoqi@0 | 502 | bool verify_chunk_in_free_list(FreeChunk* fc) const; |
aoqi@0 | 503 | // Verify that the given chunk is the linear allocation block |
aoqi@0 | 504 | bool verify_chunk_is_linear_alloc_block(FreeChunk* fc) const; |
aoqi@0 | 505 | // Do some basic checks on the the free lists. |
aoqi@0 | 506 | void check_free_list_consistency() const PRODUCT_RETURN; |
aoqi@0 | 507 | |
aoqi@0 | 508 | // Printing support |
aoqi@0 | 509 | void dump_at_safepoint_with_locks(CMSCollector* c, outputStream* st); |
aoqi@0 | 510 | void print_indexed_free_lists(outputStream* st) const; |
aoqi@0 | 511 | void print_dictionary_free_lists(outputStream* st) const; |
aoqi@0 | 512 | void print_promo_info_blocks(outputStream* st) const; |
aoqi@0 | 513 | |
aoqi@0 | 514 | NOT_PRODUCT ( |
aoqi@0 | 515 | void initializeIndexedFreeListArrayReturnedBytes(); |
aoqi@0 | 516 | size_t sumIndexedFreeListArrayReturnedBytes(); |
aoqi@0 | 517 | // Return the total number of chunks in the indexed free lists. |
aoqi@0 | 518 | size_t totalCountInIndexedFreeLists() const; |
aoqi@0 | 519 | // Return the total numberof chunks in the space. |
aoqi@0 | 520 | size_t totalCount(); |
aoqi@0 | 521 | ) |
aoqi@0 | 522 | |
aoqi@0 | 523 | // The census consists of counts of the quantities such as |
aoqi@0 | 524 | // the current count of the free chunks, number of chunks |
aoqi@0 | 525 | // created as a result of the split of a larger chunk or |
aoqi@0 | 526 | // coalescing of smaller chucks, etc. The counts in the |
aoqi@0 | 527 | // census is used to make decisions on splitting and |
aoqi@0 | 528 | // coalescing of chunks during the sweep of garbage. |
aoqi@0 | 529 | |
aoqi@0 | 530 | // Print the statistics for the free lists. |
aoqi@0 | 531 | void printFLCensus(size_t sweep_count) const; |
aoqi@0 | 532 | |
aoqi@0 | 533 | // Statistics functions |
aoqi@0 | 534 | // Initialize census for lists before the sweep. |
aoqi@0 | 535 | void beginSweepFLCensus(float inter_sweep_current, |
aoqi@0 | 536 | float inter_sweep_estimate, |
aoqi@0 | 537 | float intra_sweep_estimate); |
aoqi@0 | 538 | // Set the surplus for each of the free lists. |
aoqi@0 | 539 | void setFLSurplus(); |
aoqi@0 | 540 | // Set the hint for each of the free lists. |
aoqi@0 | 541 | void setFLHints(); |
aoqi@0 | 542 | // Clear the census for each of the free lists. |
aoqi@0 | 543 | void clearFLCensus(); |
aoqi@0 | 544 | // Perform functions for the census after the end of the sweep. |
aoqi@0 | 545 | void endSweepFLCensus(size_t sweep_count); |
aoqi@0 | 546 | // Return true if the count of free chunks is greater |
aoqi@0 | 547 | // than the desired number of free chunks. |
aoqi@0 | 548 | bool coalOverPopulated(size_t size); |
aoqi@0 | 549 | |
aoqi@0 | 550 | // Record (for each size): |
aoqi@0 | 551 | // |
aoqi@0 | 552 | // split-births = #chunks added due to splits in (prev-sweep-end, |
aoqi@0 | 553 | // this-sweep-start) |
aoqi@0 | 554 | // split-deaths = #chunks removed for splits in (prev-sweep-end, |
aoqi@0 | 555 | // this-sweep-start) |
aoqi@0 | 556 | // num-curr = #chunks at start of this sweep |
aoqi@0 | 557 | // num-prev = #chunks at end of previous sweep |
aoqi@0 | 558 | // |
aoqi@0 | 559 | // The above are quantities that are measured. Now define: |
aoqi@0 | 560 | // |
aoqi@0 | 561 | // num-desired := num-prev + split-births - split-deaths - num-curr |
aoqi@0 | 562 | // |
aoqi@0 | 563 | // Roughly, num-prev + split-births is the supply, |
aoqi@0 | 564 | // split-deaths is demand due to other sizes |
aoqi@0 | 565 | // and num-curr is what we have left. |
aoqi@0 | 566 | // |
aoqi@0 | 567 | // Thus, num-desired is roughly speaking the "legitimate demand" |
aoqi@0 | 568 | // for blocks of this size and what we are striving to reach at the |
aoqi@0 | 569 | // end of the current sweep. |
aoqi@0 | 570 | // |
aoqi@0 | 571 | // For a given list, let num-len be its current population. |
aoqi@0 | 572 | // Define, for a free list of a given size: |
aoqi@0 | 573 | // |
aoqi@0 | 574 | // coal-overpopulated := num-len >= num-desired * coal-surplus |
aoqi@0 | 575 | // (coal-surplus is set to 1.05, i.e. we allow a little slop when |
aoqi@0 | 576 | // coalescing -- we do not coalesce unless we think that the current |
aoqi@0 | 577 | // supply has exceeded the estimated demand by more than 5%). |
aoqi@0 | 578 | // |
aoqi@0 | 579 | // For the set of sizes in the binary tree, which is neither dense nor |
aoqi@0 | 580 | // closed, it may be the case that for a particular size we have never |
aoqi@0 | 581 | // had, or do not now have, or did not have at the previous sweep, |
aoqi@0 | 582 | // chunks of that size. We need to extend the definition of |
aoqi@0 | 583 | // coal-overpopulated to such sizes as well: |
aoqi@0 | 584 | // |
aoqi@0 | 585 | // For a chunk in/not in the binary tree, extend coal-overpopulated |
aoqi@0 | 586 | // defined above to include all sizes as follows: |
aoqi@0 | 587 | // |
aoqi@0 | 588 | // . a size that is non-existent is coal-overpopulated |
aoqi@0 | 589 | // . a size that has a num-desired <= 0 as defined above is |
aoqi@0 | 590 | // coal-overpopulated. |
aoqi@0 | 591 | // |
aoqi@0 | 592 | // Also define, for a chunk heap-offset C and mountain heap-offset M: |
aoqi@0 | 593 | // |
aoqi@0 | 594 | // close-to-mountain := C >= 0.99 * M |
aoqi@0 | 595 | // |
aoqi@0 | 596 | // Now, the coalescing strategy is: |
aoqi@0 | 597 | // |
aoqi@0 | 598 | // Coalesce left-hand chunk with right-hand chunk if and |
aoqi@0 | 599 | // only if: |
aoqi@0 | 600 | // |
aoqi@0 | 601 | // EITHER |
aoqi@0 | 602 | // . left-hand chunk is of a size that is coal-overpopulated |
aoqi@0 | 603 | // OR |
aoqi@0 | 604 | // . right-hand chunk is close-to-mountain |
aoqi@0 | 605 | void smallCoalBirth(size_t size); |
aoqi@0 | 606 | void smallCoalDeath(size_t size); |
aoqi@0 | 607 | void coalBirth(size_t size); |
aoqi@0 | 608 | void coalDeath(size_t size); |
aoqi@0 | 609 | void smallSplitBirth(size_t size); |
aoqi@0 | 610 | void smallSplitDeath(size_t size); |
aoqi@0 | 611 | void split_birth(size_t size); |
aoqi@0 | 612 | void splitDeath(size_t size); |
aoqi@0 | 613 | void split(size_t from, size_t to1); |
aoqi@0 | 614 | |
aoqi@0 | 615 | double flsFrag() const; |
aoqi@0 | 616 | }; |
aoqi@0 | 617 | |
aoqi@0 | 618 | // A parallel-GC-thread-local allocation buffer for allocation into a |
aoqi@0 | 619 | // CompactibleFreeListSpace. |
aoqi@0 | 620 | class CFLS_LAB : public CHeapObj<mtGC> { |
aoqi@0 | 621 | // The space that this buffer allocates into. |
aoqi@0 | 622 | CompactibleFreeListSpace* _cfls; |
aoqi@0 | 623 | |
aoqi@0 | 624 | // Our local free lists. |
aoqi@0 | 625 | AdaptiveFreeList<FreeChunk> _indexedFreeList[CompactibleFreeListSpace::IndexSetSize]; |
aoqi@0 | 626 | |
aoqi@0 | 627 | // Initialized from a command-line arg. |
aoqi@0 | 628 | |
aoqi@0 | 629 | // Allocation statistics in support of dynamic adjustment of |
aoqi@0 | 630 | // #blocks to claim per get_from_global_pool() call below. |
aoqi@0 | 631 | static AdaptiveWeightedAverage |
aoqi@0 | 632 | _blocks_to_claim [CompactibleFreeListSpace::IndexSetSize]; |
aoqi@0 | 633 | static size_t _global_num_blocks [CompactibleFreeListSpace::IndexSetSize]; |
aoqi@0 | 634 | static uint _global_num_workers[CompactibleFreeListSpace::IndexSetSize]; |
aoqi@0 | 635 | size_t _num_blocks [CompactibleFreeListSpace::IndexSetSize]; |
aoqi@0 | 636 | |
aoqi@0 | 637 | // Internal work method |
aoqi@0 | 638 | void get_from_global_pool(size_t word_sz, AdaptiveFreeList<FreeChunk>* fl); |
aoqi@0 | 639 | |
aoqi@0 | 640 | public: |
aoqi@0 | 641 | CFLS_LAB(CompactibleFreeListSpace* cfls); |
aoqi@0 | 642 | |
aoqi@0 | 643 | // Allocate and return a block of the given size, or else return NULL. |
aoqi@0 | 644 | HeapWord* alloc(size_t word_sz); |
aoqi@0 | 645 | |
aoqi@0 | 646 | // Return any unused portions of the buffer to the global pool. |
aoqi@0 | 647 | void retire(int tid); |
aoqi@0 | 648 | |
aoqi@0 | 649 | // Dynamic OldPLABSize sizing |
aoqi@0 | 650 | static void compute_desired_plab_size(); |
aoqi@0 | 651 | // When the settings are modified from default static initialization |
aoqi@0 | 652 | static void modify_initialization(size_t n, unsigned wt); |
aoqi@0 | 653 | }; |
aoqi@0 | 654 | |
aoqi@0 | 655 | size_t PromotionInfo::refillSize() const { |
aoqi@0 | 656 | const size_t CMSSpoolBlockSize = 256; |
aoqi@0 | 657 | const size_t sz = heap_word_size(sizeof(SpoolBlock) + sizeof(markOop) |
aoqi@0 | 658 | * CMSSpoolBlockSize); |
aoqi@0 | 659 | return CompactibleFreeListSpace::adjustObjectSize(sz); |
aoqi@0 | 660 | } |
aoqi@0 | 661 | |
aoqi@0 | 662 | #endif // SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_COMPACTIBLEFREELISTSPACE_HPP |