Fri, 09 May 2008 08:55:13 -0700
6670684: 4/5 SA command universe did not print out CMS space information
Summary: Forward port of Yumin's fix for 6670684 from HSX-11; Yumin verified the port was correct.
Reviewed-by: dcubed
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 2001-2005 Sun Microsystems, Inc. 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 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | // |
duke@435 | 26 | // Free block maintenance for Concurrent Mark Sweep Generation |
duke@435 | 27 | // |
duke@435 | 28 | // The main data structure for free blocks are |
duke@435 | 29 | // . an indexed array of small free blocks, and |
duke@435 | 30 | // . a dictionary of large free blocks |
duke@435 | 31 | // |
duke@435 | 32 | |
duke@435 | 33 | // No virtuals in FreeChunk (don't want any vtables). |
duke@435 | 34 | |
duke@435 | 35 | // A FreeChunk is merely a chunk that can be in a doubly linked list |
duke@435 | 36 | // and has a size field. NOTE: FreeChunks are distinguished from allocated |
duke@435 | 37 | // objects in two ways (by the sweeper). The second word (prev) has the |
duke@435 | 38 | // LSB set to indicate a free chunk; allocated objects' klass() pointers |
duke@435 | 39 | // don't have their LSB set. The corresponding bit in the CMSBitMap is |
duke@435 | 40 | // set when the chunk is allocated. There are also blocks that "look free" |
duke@435 | 41 | // but are not part of the free list and should not be coalesced into larger |
duke@435 | 42 | // free blocks. These free blocks have their two LSB's set. |
duke@435 | 43 | |
duke@435 | 44 | class FreeChunk VALUE_OBJ_CLASS_SPEC { |
duke@435 | 45 | friend class VMStructs; |
duke@435 | 46 | FreeChunk* _next; |
duke@435 | 47 | FreeChunk* _prev; |
duke@435 | 48 | size_t _size; |
duke@435 | 49 | |
duke@435 | 50 | public: |
duke@435 | 51 | NOT_PRODUCT(static const size_t header_size();) |
duke@435 | 52 | // Returns "true" if the "wrd", which is required to be the second word |
duke@435 | 53 | // of a block, indicates that the block represents a free chunk. |
duke@435 | 54 | static bool secondWordIndicatesFreeChunk(intptr_t wrd) { |
duke@435 | 55 | return (wrd & 0x1) == 0x1; |
duke@435 | 56 | } |
duke@435 | 57 | bool isFree() const { |
duke@435 | 58 | return secondWordIndicatesFreeChunk((intptr_t)_prev); |
duke@435 | 59 | } |
duke@435 | 60 | bool cantCoalesce() const { return (((intptr_t)_prev) & 0x3) == 0x3; } |
duke@435 | 61 | FreeChunk* next() const { return _next; } |
duke@435 | 62 | FreeChunk* prev() const { return (FreeChunk*)(((intptr_t)_prev) & ~(0x3)); } |
duke@435 | 63 | debug_only(void* prev_addr() const { return (void*)&_prev; }) |
duke@435 | 64 | |
duke@435 | 65 | void linkAfter(FreeChunk* ptr) { |
duke@435 | 66 | linkNext(ptr); |
duke@435 | 67 | if (ptr != NULL) ptr->linkPrev(this); |
duke@435 | 68 | } |
duke@435 | 69 | void linkAfterNonNull(FreeChunk* ptr) { |
duke@435 | 70 | assert(ptr != NULL, "precondition violation"); |
duke@435 | 71 | linkNext(ptr); |
duke@435 | 72 | ptr->linkPrev(this); |
duke@435 | 73 | } |
duke@435 | 74 | void linkNext(FreeChunk* ptr) { _next = ptr; } |
duke@435 | 75 | void linkPrev(FreeChunk* ptr) { _prev = (FreeChunk*)((intptr_t)ptr | 0x1); } |
duke@435 | 76 | void clearPrev() { _prev = NULL; } |
duke@435 | 77 | void clearNext() { _next = NULL; } |
duke@435 | 78 | void dontCoalesce() { |
duke@435 | 79 | // the block should be free |
duke@435 | 80 | assert(isFree(), "Should look like a free block"); |
duke@435 | 81 | _prev = (FreeChunk*)(((intptr_t)_prev) | 0x2); |
duke@435 | 82 | } |
duke@435 | 83 | void markFree() { _prev = (FreeChunk*)((intptr_t)_prev | 0x1); } |
duke@435 | 84 | void markNotFree() { _prev = NULL; } |
duke@435 | 85 | |
duke@435 | 86 | size_t size() const { return _size; } |
duke@435 | 87 | void setSize(size_t size) { _size = size; } |
duke@435 | 88 | |
duke@435 | 89 | // For volatile reads: |
duke@435 | 90 | size_t* size_addr() { return &_size; } |
duke@435 | 91 | |
duke@435 | 92 | // Return the address past the end of this chunk |
duke@435 | 93 | HeapWord* end() const { return ((HeapWord*) this) + _size; } |
duke@435 | 94 | |
duke@435 | 95 | // debugging |
duke@435 | 96 | void verify() const PRODUCT_RETURN; |
duke@435 | 97 | void verifyList() const PRODUCT_RETURN; |
duke@435 | 98 | void mangleAllocated(size_t size) PRODUCT_RETURN; |
duke@435 | 99 | void mangleFreed(size_t size) PRODUCT_RETURN; |
duke@435 | 100 | }; |
duke@435 | 101 | |
duke@435 | 102 | // Alignment helpers etc. |
duke@435 | 103 | #define numQuanta(x,y) ((x+y-1)/y) |
duke@435 | 104 | enum AlignmentConstants { |
duke@435 | 105 | MinChunkSize = numQuanta(sizeof(FreeChunk), MinObjAlignmentInBytes) * MinObjAlignment |
duke@435 | 106 | }; |
duke@435 | 107 | |
duke@435 | 108 | // A FreeBlockDictionary is an abstract superclass that will allow |
duke@435 | 109 | // a number of alternative implementations in the future. |
duke@435 | 110 | class FreeBlockDictionary: public CHeapObj { |
duke@435 | 111 | public: |
duke@435 | 112 | enum Dither { |
duke@435 | 113 | atLeast, |
duke@435 | 114 | exactly, |
duke@435 | 115 | roughly |
duke@435 | 116 | }; |
duke@435 | 117 | enum DictionaryChoice { |
duke@435 | 118 | dictionaryBinaryTree = 0, |
duke@435 | 119 | dictionarySplayTree = 1, |
duke@435 | 120 | dictionarySkipList = 2 |
duke@435 | 121 | }; |
duke@435 | 122 | |
duke@435 | 123 | private: |
duke@435 | 124 | NOT_PRODUCT(Mutex* _lock;) |
duke@435 | 125 | |
duke@435 | 126 | public: |
duke@435 | 127 | virtual void removeChunk(FreeChunk* fc) = 0; |
duke@435 | 128 | virtual FreeChunk* getChunk(size_t size, Dither dither = atLeast) = 0; |
duke@435 | 129 | virtual void returnChunk(FreeChunk* chunk) = 0; |
duke@435 | 130 | virtual size_t totalChunkSize(debug_only(const Mutex* lock)) const = 0; |
duke@435 | 131 | virtual size_t maxChunkSize() const = 0; |
duke@435 | 132 | virtual size_t minSize() const = 0; |
duke@435 | 133 | // Reset the dictionary to the initial conditions for a single |
duke@435 | 134 | // block. |
duke@435 | 135 | virtual void reset(HeapWord* addr, size_t size) = 0; |
duke@435 | 136 | virtual void reset() = 0; |
duke@435 | 137 | |
duke@435 | 138 | virtual void dictCensusUpdate(size_t size, bool split, bool birth) = 0; |
duke@435 | 139 | virtual bool coalDictOverPopulated(size_t size) = 0; |
duke@435 | 140 | virtual void beginSweepDictCensus(double coalSurplusPercent, |
duke@435 | 141 | float sweep_current, float sweep_ewstimate) = 0; |
duke@435 | 142 | virtual void endSweepDictCensus(double splitSurplusPercent) = 0; |
duke@435 | 143 | virtual FreeChunk* findLargestDict() const = 0; |
duke@435 | 144 | // verify that the given chunk is in the dictionary. |
duke@435 | 145 | virtual bool verifyChunkInFreeLists(FreeChunk* tc) const = 0; |
duke@435 | 146 | |
duke@435 | 147 | // Sigma_{all_free_blocks} (block_size^2) |
duke@435 | 148 | virtual double sum_of_squared_block_sizes() const = 0; |
duke@435 | 149 | |
duke@435 | 150 | virtual FreeChunk* find_chunk_ends_at(HeapWord* target) const = 0; |
duke@435 | 151 | virtual void inc_totalSize(size_t v) = 0; |
duke@435 | 152 | virtual void dec_totalSize(size_t v) = 0; |
duke@435 | 153 | |
duke@435 | 154 | NOT_PRODUCT ( |
duke@435 | 155 | virtual size_t sumDictReturnedBytes() = 0; |
duke@435 | 156 | virtual void initializeDictReturnedBytes() = 0; |
duke@435 | 157 | virtual size_t totalCount() = 0; |
duke@435 | 158 | ) |
duke@435 | 159 | |
duke@435 | 160 | virtual void reportStatistics() const { |
duke@435 | 161 | gclog_or_tty->print("No statistics available"); |
duke@435 | 162 | } |
duke@435 | 163 | |
duke@435 | 164 | virtual void printDictCensus() const = 0; |
duke@435 | 165 | |
duke@435 | 166 | virtual void verify() const = 0; |
duke@435 | 167 | |
duke@435 | 168 | Mutex* par_lock() const PRODUCT_RETURN0; |
duke@435 | 169 | void set_par_lock(Mutex* lock) PRODUCT_RETURN; |
duke@435 | 170 | void verify_par_locked() const PRODUCT_RETURN; |
duke@435 | 171 | }; |