src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7476
c2844108a708
parent 6876
710a3c8b516e
child 9806
758c07667682
permissions
-rw-r--r--

merge

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
jmasa@7474 175 // Used by par_get_chunk_of_blocks() for the chunks from the
jmasa@7474 176 // indexed_free_lists.
jmasa@7474 177 bool par_get_chunk_of_blocks_IFL(size_t word_sz, size_t n, AdaptiveFreeList<FreeChunk>* fl);
jmasa@7474 178
jmasa@7474 179 // Used by par_get_chunk_of_blocks_dictionary() to get a chunk
jmasa@7474 180 // evenly splittable into "n" "word_sz" chunks. Returns that
jmasa@7474 181 // evenly splittable chunk. May split a larger chunk to get the
jmasa@7474 182 // evenly splittable chunk.
jmasa@7474 183 FreeChunk* get_n_way_chunk_to_split(size_t word_sz, size_t n);
jmasa@7474 184
jmasa@7474 185 // Used by par_get_chunk_of_blocks() for the chunks from the
jmasa@7474 186 // dictionary.
jmasa@7474 187 void par_get_chunk_of_blocks_dictionary(size_t word_sz, size_t n, AdaptiveFreeList<FreeChunk>* fl);
jmasa@7474 188
aoqi@0 189 // Allocation helper functions
aoqi@0 190 // Allocate using a strategy that takes from the indexed free lists
aoqi@0 191 // first. This allocation strategy assumes a companion sweeping
aoqi@0 192 // strategy that attempts to keep the needed number of chunks in each
aoqi@0 193 // indexed free lists.
aoqi@0 194 HeapWord* allocate_adaptive_freelists(size_t size);
aoqi@0 195 // Allocate from the linear allocation buffers first. This allocation
aoqi@0 196 // strategy assumes maximal coalescing can maintain chunks large enough
aoqi@0 197 // to be used as linear allocation buffers.
aoqi@0 198 HeapWord* allocate_non_adaptive_freelists(size_t size);
aoqi@0 199
aoqi@0 200 // Gets a chunk from the linear allocation block (LinAB). If there
aoqi@0 201 // is not enough space in the LinAB, refills it.
aoqi@0 202 HeapWord* getChunkFromLinearAllocBlock(LinearAllocBlock* blk, size_t size);
aoqi@0 203 HeapWord* getChunkFromSmallLinearAllocBlock(size_t size);
aoqi@0 204 // Get a chunk from the space remaining in the linear allocation block. Do
aoqi@0 205 // not attempt to refill if the space is not available, return NULL. Do the
aoqi@0 206 // repairs on the linear allocation block as appropriate.
aoqi@0 207 HeapWord* getChunkFromLinearAllocBlockRemainder(LinearAllocBlock* blk, size_t size);
aoqi@0 208 inline HeapWord* getChunkFromSmallLinearAllocBlockRemainder(size_t size);
aoqi@0 209
aoqi@0 210 // Helper function for getChunkFromIndexedFreeList.
aoqi@0 211 // Replenish the indexed free list for this "size". Do not take from an
aoqi@0 212 // underpopulated size.
aoqi@0 213 FreeChunk* getChunkFromIndexedFreeListHelper(size_t size, bool replenish = true);
aoqi@0 214
aoqi@0 215 // Get a chunk from the indexed free list. If the indexed free list
aoqi@0 216 // does not have a free chunk, try to replenish the indexed free list
aoqi@0 217 // then get the free chunk from the replenished indexed free list.
aoqi@0 218 inline FreeChunk* getChunkFromIndexedFreeList(size_t size);
aoqi@0 219
aoqi@0 220 // The returned chunk may be larger than requested (or null).
aoqi@0 221 FreeChunk* getChunkFromDictionary(size_t size);
aoqi@0 222 // The returned chunk is the exact size requested (or null).
aoqi@0 223 FreeChunk* getChunkFromDictionaryExact(size_t size);
aoqi@0 224
aoqi@0 225 // Find a chunk in the indexed free list that is the best
aoqi@0 226 // fit for size "numWords".
aoqi@0 227 FreeChunk* bestFitSmall(size_t numWords);
aoqi@0 228 // For free list "fl" of chunks of size > numWords,
aoqi@0 229 // remove a chunk, split off a chunk of size numWords
aoqi@0 230 // and return it. The split off remainder is returned to
aoqi@0 231 // the free lists. The old name for getFromListGreater
aoqi@0 232 // was lookInListGreater.
aoqi@0 233 FreeChunk* getFromListGreater(AdaptiveFreeList<FreeChunk>* fl, size_t numWords);
aoqi@0 234 // Get a chunk in the indexed free list or dictionary,
aoqi@0 235 // by considering a larger chunk and splitting it.
aoqi@0 236 FreeChunk* getChunkFromGreater(size_t numWords);
aoqi@0 237 // Verify that the given chunk is in the indexed free lists.
aoqi@0 238 bool verifyChunkInIndexedFreeLists(FreeChunk* fc) const;
aoqi@0 239 // Remove the specified chunk from the indexed free lists.
aoqi@0 240 void removeChunkFromIndexedFreeList(FreeChunk* fc);
aoqi@0 241 // Remove the specified chunk from the dictionary.
aoqi@0 242 void removeChunkFromDictionary(FreeChunk* fc);
aoqi@0 243 // Split a free chunk into a smaller free chunk of size "new_size".
aoqi@0 244 // Return the smaller free chunk and return the remainder to the
aoqi@0 245 // free lists.
aoqi@0 246 FreeChunk* splitChunkAndReturnRemainder(FreeChunk* chunk, size_t new_size);
aoqi@0 247 // Add a chunk to the free lists.
aoqi@0 248 void addChunkToFreeLists(HeapWord* chunk, size_t size);
aoqi@0 249 // Add a chunk to the free lists, preferring to suffix it
aoqi@0 250 // to the last free chunk at end of space if possible, and
aoqi@0 251 // updating the block census stats as well as block offset table.
aoqi@0 252 // Take any locks as appropriate if we are multithreaded.
aoqi@0 253 void addChunkToFreeListsAtEndRecordingStats(HeapWord* chunk, size_t size);
aoqi@0 254 // Add a free chunk to the indexed free lists.
aoqi@0 255 void returnChunkToFreeList(FreeChunk* chunk);
aoqi@0 256 // Add a free chunk to the dictionary.
aoqi@0 257 void returnChunkToDictionary(FreeChunk* chunk);
aoqi@0 258
aoqi@0 259 // Functions for maintaining the linear allocation buffers (LinAB).
aoqi@0 260 // Repairing a linear allocation block refers to operations
aoqi@0 261 // performed on the remainder of a LinAB after an allocation
aoqi@0 262 // has been made from it.
aoqi@0 263 void repairLinearAllocationBlocks();
aoqi@0 264 void repairLinearAllocBlock(LinearAllocBlock* blk);
aoqi@0 265 void refillLinearAllocBlock(LinearAllocBlock* blk);
aoqi@0 266 void refillLinearAllocBlockIfNeeded(LinearAllocBlock* blk);
aoqi@0 267 void refillLinearAllocBlocksIfNeeded();
aoqi@0 268
aoqi@0 269 void verify_objects_initialized() const;
aoqi@0 270
aoqi@0 271 // Statistics reporting helper functions
aoqi@0 272 void reportFreeListStatistics() const;
aoqi@0 273 void reportIndexedFreeListStatistics() const;
aoqi@0 274 size_t maxChunkSizeInIndexedFreeLists() const;
aoqi@0 275 size_t numFreeBlocksInIndexedFreeLists() const;
aoqi@0 276 // Accessor
aoqi@0 277 HeapWord* unallocated_block() const {
aoqi@0 278 if (BlockOffsetArrayUseUnallocatedBlock) {
aoqi@0 279 HeapWord* ub = _bt.unallocated_block();
aoqi@0 280 assert(ub >= bottom() &&
aoqi@0 281 ub <= end(), "space invariant");
aoqi@0 282 return ub;
aoqi@0 283 } else {
aoqi@0 284 return end();
aoqi@0 285 }
aoqi@0 286 }
aoqi@0 287 void freed(HeapWord* start, size_t size) {
aoqi@0 288 _bt.freed(start, size);
aoqi@0 289 }
aoqi@0 290
aoqi@0 291 protected:
aoqi@0 292 // reset the indexed free list to its initial empty condition.
aoqi@0 293 void resetIndexedFreeListArray();
aoqi@0 294 // reset to an initial state with a single free block described
aoqi@0 295 // by the MemRegion parameter.
aoqi@0 296 void reset(MemRegion mr);
aoqi@0 297 // Return the total number of words in the indexed free lists.
aoqi@0 298 size_t totalSizeInIndexedFreeLists() const;
aoqi@0 299
aoqi@0 300 public:
aoqi@0 301 // Constructor...
aoqi@0 302 CompactibleFreeListSpace(BlockOffsetSharedArray* bs, MemRegion mr,
aoqi@0 303 bool use_adaptive_freelists,
aoqi@0 304 FreeBlockDictionary<FreeChunk>::DictionaryChoice);
aoqi@0 305 // accessors
aoqi@0 306 bool bestFitFirst() { return _fitStrategy == FreeBlockBestFitFirst; }
aoqi@0 307 FreeBlockDictionary<FreeChunk>* dictionary() const { return _dictionary; }
aoqi@0 308 HeapWord* nearLargestChunk() const { return _nearLargestChunk; }
aoqi@0 309 void set_nearLargestChunk(HeapWord* v) { _nearLargestChunk = v; }
aoqi@0 310
aoqi@0 311 // Set CMS global values
aoqi@0 312 static void set_cms_values();
aoqi@0 313
aoqi@0 314 // Return the free chunk at the end of the space. If no such
aoqi@0 315 // chunk exists, return NULL.
aoqi@0 316 FreeChunk* find_chunk_at_end();
aoqi@0 317
aoqi@0 318 bool adaptive_freelists() const { return _adaptive_freelists; }
aoqi@0 319
aoqi@0 320 void set_collector(CMSCollector* collector) { _collector = collector; }
aoqi@0 321
aoqi@0 322 // Support for parallelization of rescan and marking
aoqi@0 323 const size_t rescan_task_size() const { return _rescan_task_size; }
aoqi@0 324 const size_t marking_task_size() const { return _marking_task_size; }
aoqi@0 325 SequentialSubTasksDone* conc_par_seq_tasks() {return &_conc_par_seq_tasks; }
aoqi@0 326 void initialize_sequential_subtasks_for_rescan(int n_threads);
aoqi@0 327 void initialize_sequential_subtasks_for_marking(int n_threads,
aoqi@0 328 HeapWord* low = NULL);
aoqi@0 329
aoqi@0 330 // Space enquiries
aoqi@0 331 size_t used() const;
aoqi@0 332 size_t free() const;
aoqi@0 333 size_t max_alloc_in_words() const;
aoqi@0 334 // XXX: should have a less conservative used_region() than that of
aoqi@0 335 // Space; we could consider keeping track of highest allocated
aoqi@0 336 // address and correcting that at each sweep, as the sweeper
aoqi@0 337 // goes through the entire allocated part of the generation. We
aoqi@0 338 // could also use that information to keep the sweeper from
aoqi@0 339 // sweeping more than is necessary. The allocator and sweeper will
aoqi@0 340 // of course need to synchronize on this, since the sweeper will
aoqi@0 341 // try to bump down the address and the allocator will try to bump it up.
aoqi@0 342 // For now, however, we'll just use the default used_region()
aoqi@0 343 // which overestimates the region by returning the entire
aoqi@0 344 // committed region (this is safe, but inefficient).
aoqi@0 345
aoqi@0 346 // Returns a subregion of the space containing all the objects in
aoqi@0 347 // the space.
aoqi@0 348 MemRegion used_region() const {
aoqi@0 349 return MemRegion(bottom(),
aoqi@0 350 BlockOffsetArrayUseUnallocatedBlock ?
aoqi@0 351 unallocated_block() : end());
aoqi@0 352 }
aoqi@0 353
aoqi@0 354 virtual bool is_free_block(const HeapWord* p) const;
aoqi@0 355
aoqi@0 356 // Resizing support
aoqi@0 357 void set_end(HeapWord* value); // override
aoqi@0 358
aoqi@0 359 // mutual exclusion support
aoqi@0 360 Mutex* freelistLock() const { return &_freelistLock; }
aoqi@0 361
aoqi@0 362 // Iteration support
aoqi@0 363 void oop_iterate(ExtendedOopClosure* cl);
aoqi@0 364
aoqi@0 365 void object_iterate(ObjectClosure* blk);
aoqi@0 366 // Apply the closure to each object in the space whose references
aoqi@0 367 // point to objects in the heap. The usage of CompactibleFreeListSpace
aoqi@0 368 // by the ConcurrentMarkSweepGeneration for concurrent GC's allows
aoqi@0 369 // objects in the space with references to objects that are no longer
aoqi@0 370 // valid. For example, an object may reference another object
aoqi@0 371 // that has already been sweep up (collected). This method uses
aoqi@0 372 // obj_is_alive() to determine whether it is safe to iterate of
aoqi@0 373 // an object.
aoqi@0 374 void safe_object_iterate(ObjectClosure* blk);
mgerdin@6979 375
mgerdin@6979 376 // Iterate over all objects that intersect with mr, calling "cl->do_object"
mgerdin@6979 377 // on each. There is an exception to this: if this closure has already
mgerdin@6979 378 // been invoked on an object, it may skip such objects in some cases. This is
mgerdin@6979 379 // Most likely to happen in an "upwards" (ascending address) iteration of
mgerdin@6979 380 // MemRegions.
aoqi@0 381 void object_iterate_mem(MemRegion mr, UpwardsObjectClosure* cl);
aoqi@0 382
aoqi@0 383 // Requires that "mr" be entirely within the space.
aoqi@0 384 // Apply "cl->do_object" to all objects that intersect with "mr".
aoqi@0 385 // If the iteration encounters an unparseable portion of the region,
aoqi@0 386 // terminate the iteration and return the address of the start of the
aoqi@0 387 // subregion that isn't done. Return of "NULL" indicates that the
aoqi@0 388 // interation completed.
mgerdin@6980 389 HeapWord* object_iterate_careful_m(MemRegion mr,
mgerdin@6980 390 ObjectClosureCareful* cl);
aoqi@0 391
aoqi@0 392 // Override: provides a DCTO_CL specific to this kind of space.
aoqi@0 393 DirtyCardToOopClosure* new_dcto_cl(ExtendedOopClosure* cl,
aoqi@0 394 CardTableModRefBS::PrecisionStyle precision,
aoqi@0 395 HeapWord* boundary);
aoqi@0 396
aoqi@0 397 void blk_iterate(BlkClosure* cl);
aoqi@0 398 void blk_iterate_careful(BlkClosureCareful* cl);
aoqi@0 399 HeapWord* block_start_const(const void* p) const;
aoqi@0 400 HeapWord* block_start_careful(const void* p) const;
aoqi@0 401 size_t block_size(const HeapWord* p) const;
aoqi@0 402 size_t block_size_no_stall(HeapWord* p, const CMSCollector* c) const;
aoqi@0 403 bool block_is_obj(const HeapWord* p) const;
aoqi@0 404 bool obj_is_alive(const HeapWord* p) const;
aoqi@0 405 size_t block_size_nopar(const HeapWord* p) const;
aoqi@0 406 bool block_is_obj_nopar(const HeapWord* p) const;
aoqi@0 407
aoqi@0 408 // iteration support for promotion
aoqi@0 409 void save_marks();
aoqi@0 410 bool no_allocs_since_save_marks();
aoqi@0 411
aoqi@0 412 // iteration support for sweeping
aoqi@0 413 void save_sweep_limit() {
aoqi@0 414 _sweep_limit = BlockOffsetArrayUseUnallocatedBlock ?
aoqi@0 415 unallocated_block() : end();
aoqi@0 416 if (CMSTraceSweeper) {
aoqi@0 417 gclog_or_tty->print_cr(">>>>> Saving sweep limit " PTR_FORMAT
aoqi@0 418 " for space [" PTR_FORMAT "," PTR_FORMAT ") <<<<<<",
aoqi@0 419 p2i(_sweep_limit), p2i(bottom()), p2i(end()));
aoqi@0 420 }
aoqi@0 421 }
aoqi@0 422 NOT_PRODUCT(
aoqi@0 423 void clear_sweep_limit() { _sweep_limit = NULL; }
aoqi@0 424 )
aoqi@0 425 HeapWord* sweep_limit() { return _sweep_limit; }
aoqi@0 426
aoqi@0 427 // Apply "blk->do_oop" to the addresses of all reference fields in objects
aoqi@0 428 // promoted into this generation since the most recent save_marks() call.
aoqi@0 429 // Fields in objects allocated by applications of the closure
aoqi@0 430 // *are* included in the iteration. Thus, when the iteration completes
aoqi@0 431 // there should be no further such objects remaining.
aoqi@0 432 #define CFLS_OOP_SINCE_SAVE_MARKS_DECL(OopClosureType, nv_suffix) \
aoqi@0 433 void oop_since_save_marks_iterate##nv_suffix(OopClosureType* blk);
aoqi@0 434 ALL_SINCE_SAVE_MARKS_CLOSURES(CFLS_OOP_SINCE_SAVE_MARKS_DECL)
aoqi@0 435 #undef CFLS_OOP_SINCE_SAVE_MARKS_DECL
aoqi@0 436
aoqi@0 437 // Allocation support
aoqi@0 438 HeapWord* allocate(size_t size);
aoqi@0 439 HeapWord* par_allocate(size_t size);
aoqi@0 440
aoqi@0 441 oop promote(oop obj, size_t obj_size);
aoqi@0 442 void gc_prologue();
aoqi@0 443 void gc_epilogue();
aoqi@0 444
aoqi@0 445 // This call is used by a containing CMS generation / collector
aoqi@0 446 // to inform the CFLS space that a sweep has been completed
aoqi@0 447 // and that the space can do any related house-keeping functions.
aoqi@0 448 void sweep_completed();
aoqi@0 449
aoqi@0 450 // For an object in this space, the mark-word's two
aoqi@0 451 // LSB's having the value [11] indicates that it has been
aoqi@0 452 // promoted since the most recent call to save_marks() on
aoqi@0 453 // this generation and has not subsequently been iterated
aoqi@0 454 // over (using oop_since_save_marks_iterate() above).
aoqi@0 455 // This property holds only for single-threaded collections,
aoqi@0 456 // and is typically used for Cheney scans; for MT scavenges,
aoqi@0 457 // the property holds for all objects promoted during that
aoqi@0 458 // scavenge for the duration of the scavenge and is used
aoqi@0 459 // by card-scanning to avoid scanning objects (being) promoted
aoqi@0 460 // during that scavenge.
aoqi@0 461 bool obj_allocated_since_save_marks(const oop obj) const {
aoqi@0 462 assert(is_in_reserved(obj), "Wrong space?");
aoqi@0 463 return ((PromotedObject*)obj)->hasPromotedMark();
aoqi@0 464 }
aoqi@0 465
aoqi@0 466 // A worst-case estimate of the space required (in HeapWords) to expand the
aoqi@0 467 // heap when promoting an obj of size obj_size.
aoqi@0 468 size_t expansionSpaceRequired(size_t obj_size) const;
aoqi@0 469
aoqi@0 470 FreeChunk* allocateScratch(size_t size);
aoqi@0 471
aoqi@0 472 // returns true if either the small or large linear allocation buffer is empty.
aoqi@0 473 bool linearAllocationWouldFail() const;
aoqi@0 474
aoqi@0 475 // Adjust the chunk for the minimum size. This version is called in
aoqi@0 476 // most cases in CompactibleFreeListSpace methods.
aoqi@0 477 inline static size_t adjustObjectSize(size_t size) {
aoqi@0 478 return (size_t) align_object_size(MAX2(size, (size_t)MinChunkSize));
aoqi@0 479 }
aoqi@0 480 // This is a virtual version of adjustObjectSize() that is called
aoqi@0 481 // only occasionally when the compaction space changes and the type
aoqi@0 482 // of the new compaction space is is only known to be CompactibleSpace.
aoqi@0 483 size_t adjust_object_size_v(size_t size) const {
aoqi@0 484 return adjustObjectSize(size);
aoqi@0 485 }
aoqi@0 486 // Minimum size of a free block.
aoqi@0 487 virtual size_t minimum_free_block_size() const { return MinChunkSize; }
aoqi@0 488 void removeFreeChunkFromFreeLists(FreeChunk* chunk);
aoqi@0 489 void addChunkAndRepairOffsetTable(HeapWord* chunk, size_t size,
aoqi@0 490 bool coalesced);
aoqi@0 491
aoqi@0 492 // Support for decisions regarding concurrent collection policy
aoqi@0 493 bool should_concurrent_collect() const;
aoqi@0 494
aoqi@0 495 // Support for compaction
aoqi@0 496 void prepare_for_compaction(CompactPoint* cp);
aoqi@0 497 void adjust_pointers();
aoqi@0 498 void compact();
aoqi@0 499 // reset the space to reflect the fact that a compaction of the
aoqi@0 500 // space has been done.
aoqi@0 501 virtual void reset_after_compaction();
aoqi@0 502
aoqi@0 503 // Debugging support
aoqi@0 504 void print() const;
aoqi@0 505 void print_on(outputStream* st) const;
aoqi@0 506 void prepare_for_verify();
aoqi@0 507 void verify() const;
aoqi@0 508 void verifyFreeLists() const PRODUCT_RETURN;
aoqi@0 509 void verifyIndexedFreeLists() const;
aoqi@0 510 void verifyIndexedFreeList(size_t size) const;
aoqi@0 511 // Verify that the given chunk is in the free lists:
aoqi@0 512 // i.e. either the binary tree dictionary, the indexed free lists
aoqi@0 513 // or the linear allocation block.
aoqi@0 514 bool verify_chunk_in_free_list(FreeChunk* fc) const;
aoqi@0 515 // Verify that the given chunk is the linear allocation block
aoqi@0 516 bool verify_chunk_is_linear_alloc_block(FreeChunk* fc) const;
aoqi@0 517 // Do some basic checks on the the free lists.
aoqi@0 518 void check_free_list_consistency() const PRODUCT_RETURN;
aoqi@0 519
aoqi@0 520 // Printing support
aoqi@0 521 void dump_at_safepoint_with_locks(CMSCollector* c, outputStream* st);
aoqi@0 522 void print_indexed_free_lists(outputStream* st) const;
aoqi@0 523 void print_dictionary_free_lists(outputStream* st) const;
aoqi@0 524 void print_promo_info_blocks(outputStream* st) const;
aoqi@0 525
aoqi@0 526 NOT_PRODUCT (
aoqi@0 527 void initializeIndexedFreeListArrayReturnedBytes();
aoqi@0 528 size_t sumIndexedFreeListArrayReturnedBytes();
aoqi@0 529 // Return the total number of chunks in the indexed free lists.
aoqi@0 530 size_t totalCountInIndexedFreeLists() const;
aoqi@0 531 // Return the total numberof chunks in the space.
aoqi@0 532 size_t totalCount();
aoqi@0 533 )
aoqi@0 534
aoqi@0 535 // The census consists of counts of the quantities such as
aoqi@0 536 // the current count of the free chunks, number of chunks
aoqi@0 537 // created as a result of the split of a larger chunk or
aoqi@0 538 // coalescing of smaller chucks, etc. The counts in the
aoqi@0 539 // census is used to make decisions on splitting and
aoqi@0 540 // coalescing of chunks during the sweep of garbage.
aoqi@0 541
aoqi@0 542 // Print the statistics for the free lists.
aoqi@0 543 void printFLCensus(size_t sweep_count) const;
aoqi@0 544
aoqi@0 545 // Statistics functions
aoqi@0 546 // Initialize census for lists before the sweep.
aoqi@0 547 void beginSweepFLCensus(float inter_sweep_current,
aoqi@0 548 float inter_sweep_estimate,
aoqi@0 549 float intra_sweep_estimate);
aoqi@0 550 // Set the surplus for each of the free lists.
aoqi@0 551 void setFLSurplus();
aoqi@0 552 // Set the hint for each of the free lists.
aoqi@0 553 void setFLHints();
aoqi@0 554 // Clear the census for each of the free lists.
aoqi@0 555 void clearFLCensus();
aoqi@0 556 // Perform functions for the census after the end of the sweep.
aoqi@0 557 void endSweepFLCensus(size_t sweep_count);
aoqi@0 558 // Return true if the count of free chunks is greater
aoqi@0 559 // than the desired number of free chunks.
aoqi@0 560 bool coalOverPopulated(size_t size);
aoqi@0 561
aoqi@0 562 // Record (for each size):
aoqi@0 563 //
aoqi@0 564 // split-births = #chunks added due to splits in (prev-sweep-end,
aoqi@0 565 // this-sweep-start)
aoqi@0 566 // split-deaths = #chunks removed for splits in (prev-sweep-end,
aoqi@0 567 // this-sweep-start)
aoqi@0 568 // num-curr = #chunks at start of this sweep
aoqi@0 569 // num-prev = #chunks at end of previous sweep
aoqi@0 570 //
aoqi@0 571 // The above are quantities that are measured. Now define:
aoqi@0 572 //
aoqi@0 573 // num-desired := num-prev + split-births - split-deaths - num-curr
aoqi@0 574 //
aoqi@0 575 // Roughly, num-prev + split-births is the supply,
aoqi@0 576 // split-deaths is demand due to other sizes
aoqi@0 577 // and num-curr is what we have left.
aoqi@0 578 //
aoqi@0 579 // Thus, num-desired is roughly speaking the "legitimate demand"
aoqi@0 580 // for blocks of this size and what we are striving to reach at the
aoqi@0 581 // end of the current sweep.
aoqi@0 582 //
aoqi@0 583 // For a given list, let num-len be its current population.
aoqi@0 584 // Define, for a free list of a given size:
aoqi@0 585 //
aoqi@0 586 // coal-overpopulated := num-len >= num-desired * coal-surplus
aoqi@0 587 // (coal-surplus is set to 1.05, i.e. we allow a little slop when
aoqi@0 588 // coalescing -- we do not coalesce unless we think that the current
aoqi@0 589 // supply has exceeded the estimated demand by more than 5%).
aoqi@0 590 //
aoqi@0 591 // For the set of sizes in the binary tree, which is neither dense nor
aoqi@0 592 // closed, it may be the case that for a particular size we have never
aoqi@0 593 // had, or do not now have, or did not have at the previous sweep,
aoqi@0 594 // chunks of that size. We need to extend the definition of
aoqi@0 595 // coal-overpopulated to such sizes as well:
aoqi@0 596 //
aoqi@0 597 // For a chunk in/not in the binary tree, extend coal-overpopulated
aoqi@0 598 // defined above to include all sizes as follows:
aoqi@0 599 //
aoqi@0 600 // . a size that is non-existent is coal-overpopulated
aoqi@0 601 // . a size that has a num-desired <= 0 as defined above is
aoqi@0 602 // coal-overpopulated.
aoqi@0 603 //
aoqi@0 604 // Also define, for a chunk heap-offset C and mountain heap-offset M:
aoqi@0 605 //
aoqi@0 606 // close-to-mountain := C >= 0.99 * M
aoqi@0 607 //
aoqi@0 608 // Now, the coalescing strategy is:
aoqi@0 609 //
aoqi@0 610 // Coalesce left-hand chunk with right-hand chunk if and
aoqi@0 611 // only if:
aoqi@0 612 //
aoqi@0 613 // EITHER
aoqi@0 614 // . left-hand chunk is of a size that is coal-overpopulated
aoqi@0 615 // OR
aoqi@0 616 // . right-hand chunk is close-to-mountain
aoqi@0 617 void smallCoalBirth(size_t size);
aoqi@0 618 void smallCoalDeath(size_t size);
aoqi@0 619 void coalBirth(size_t size);
aoqi@0 620 void coalDeath(size_t size);
aoqi@0 621 void smallSplitBirth(size_t size);
aoqi@0 622 void smallSplitDeath(size_t size);
aoqi@0 623 void split_birth(size_t size);
aoqi@0 624 void splitDeath(size_t size);
aoqi@0 625 void split(size_t from, size_t to1);
aoqi@0 626
aoqi@0 627 double flsFrag() const;
aoqi@0 628 };
aoqi@0 629
aoqi@0 630 // A parallel-GC-thread-local allocation buffer for allocation into a
aoqi@0 631 // CompactibleFreeListSpace.
aoqi@0 632 class CFLS_LAB : public CHeapObj<mtGC> {
aoqi@0 633 // The space that this buffer allocates into.
aoqi@0 634 CompactibleFreeListSpace* _cfls;
aoqi@0 635
aoqi@0 636 // Our local free lists.
aoqi@0 637 AdaptiveFreeList<FreeChunk> _indexedFreeList[CompactibleFreeListSpace::IndexSetSize];
aoqi@0 638
aoqi@0 639 // Initialized from a command-line arg.
aoqi@0 640
aoqi@0 641 // Allocation statistics in support of dynamic adjustment of
aoqi@0 642 // #blocks to claim per get_from_global_pool() call below.
aoqi@0 643 static AdaptiveWeightedAverage
aoqi@0 644 _blocks_to_claim [CompactibleFreeListSpace::IndexSetSize];
aoqi@0 645 static size_t _global_num_blocks [CompactibleFreeListSpace::IndexSetSize];
aoqi@0 646 static uint _global_num_workers[CompactibleFreeListSpace::IndexSetSize];
aoqi@0 647 size_t _num_blocks [CompactibleFreeListSpace::IndexSetSize];
aoqi@0 648
aoqi@0 649 // Internal work method
aoqi@0 650 void get_from_global_pool(size_t word_sz, AdaptiveFreeList<FreeChunk>* fl);
aoqi@0 651
aoqi@0 652 public:
aoqi@0 653 CFLS_LAB(CompactibleFreeListSpace* cfls);
aoqi@0 654
aoqi@0 655 // Allocate and return a block of the given size, or else return NULL.
aoqi@0 656 HeapWord* alloc(size_t word_sz);
aoqi@0 657
aoqi@0 658 // Return any unused portions of the buffer to the global pool.
aoqi@0 659 void retire(int tid);
aoqi@0 660
aoqi@0 661 // Dynamic OldPLABSize sizing
aoqi@0 662 static void compute_desired_plab_size();
aoqi@0 663 // When the settings are modified from default static initialization
aoqi@0 664 static void modify_initialization(size_t n, unsigned wt);
aoqi@0 665 };
aoqi@0 666
aoqi@0 667 size_t PromotionInfo::refillSize() const {
aoqi@0 668 const size_t CMSSpoolBlockSize = 256;
aoqi@0 669 const size_t sz = heap_word_size(sizeof(SpoolBlock) + sizeof(markOop)
aoqi@0 670 * CMSSpoolBlockSize);
aoqi@0 671 return CompactibleFreeListSpace::adjustObjectSize(sz);
aoqi@0 672 }
aoqi@0 673
aoqi@0 674 #endif // SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_COMPACTIBLEFREELISTSPACE_HPP

mercurial