annotate src/share/vm/gc_implementation/concurrentMarkSweep/freeBlockDictionary.hpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 790e66e5fbac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 //
a61af66fc99e Initial load
duke
parents:
diff changeset
26 // Free block maintenance for Concurrent Mark Sweep Generation
a61af66fc99e Initial load
duke
parents:
diff changeset
27 //
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // The main data structure for free blocks are
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // . an indexed array of small free blocks, and
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // . a dictionary of large free blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
31 //
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // No virtuals in FreeChunk (don't want any vtables).
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // A FreeChunk is merely a chunk that can be in a doubly linked list
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // and has a size field. NOTE: FreeChunks are distinguished from allocated
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // objects in two ways (by the sweeper). The second word (prev) has the
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // LSB set to indicate a free chunk; allocated objects' klass() pointers
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // don't have their LSB set. The corresponding bit in the CMSBitMap is
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // set when the chunk is allocated. There are also blocks that "look free"
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // but are not part of the free list and should not be coalesced into larger
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // free blocks. These free blocks have their two LSB's set.
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 class FreeChunk VALUE_OBJ_CLASS_SPEC {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 FreeChunk* _next;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 FreeChunk* _prev;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 size_t _size;
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
51 NOT_PRODUCT(static const size_t header_size();)
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // Returns "true" if the "wrd", which is required to be the second word
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // of a block, indicates that the block represents a free chunk.
a61af66fc99e Initial load
duke
parents:
diff changeset
54 static bool secondWordIndicatesFreeChunk(intptr_t wrd) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return (wrd & 0x1) == 0x1;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57 bool isFree() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 return secondWordIndicatesFreeChunk((intptr_t)_prev);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60 bool cantCoalesce() const { return (((intptr_t)_prev) & 0x3) == 0x3; }
a61af66fc99e Initial load
duke
parents:
diff changeset
61 FreeChunk* next() const { return _next; }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 FreeChunk* prev() const { return (FreeChunk*)(((intptr_t)_prev) & ~(0x3)); }
a61af66fc99e Initial load
duke
parents:
diff changeset
63 debug_only(void* prev_addr() const { return (void*)&_prev; })
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 void linkAfter(FreeChunk* ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 linkNext(ptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 if (ptr != NULL) ptr->linkPrev(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69 void linkAfterNonNull(FreeChunk* ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 assert(ptr != NULL, "precondition violation");
a61af66fc99e Initial load
duke
parents:
diff changeset
71 linkNext(ptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
72 ptr->linkPrev(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 void linkNext(FreeChunk* ptr) { _next = ptr; }
a61af66fc99e Initial load
duke
parents:
diff changeset
75 void linkPrev(FreeChunk* ptr) { _prev = (FreeChunk*)((intptr_t)ptr | 0x1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 void clearPrev() { _prev = NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
77 void clearNext() { _next = NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
78 void dontCoalesce() {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // the block should be free
a61af66fc99e Initial load
duke
parents:
diff changeset
80 assert(isFree(), "Should look like a free block");
a61af66fc99e Initial load
duke
parents:
diff changeset
81 _prev = (FreeChunk*)(((intptr_t)_prev) | 0x2);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 void markFree() { _prev = (FreeChunk*)((intptr_t)_prev | 0x1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
84 void markNotFree() { _prev = NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 size_t size() const { return _size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
87 void setSize(size_t size) { _size = size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // For volatile reads:
a61af66fc99e Initial load
duke
parents:
diff changeset
90 size_t* size_addr() { return &_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // Return the address past the end of this chunk
a61af66fc99e Initial load
duke
parents:
diff changeset
93 HeapWord* end() const { return ((HeapWord*) this) + _size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
96 void verify() const PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 void verifyList() const PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 void mangleAllocated(size_t size) PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 void mangleFreed(size_t size) PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 };
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // Alignment helpers etc.
a61af66fc99e Initial load
duke
parents:
diff changeset
103 #define numQuanta(x,y) ((x+y-1)/y)
a61af66fc99e Initial load
duke
parents:
diff changeset
104 enum AlignmentConstants {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 MinChunkSize = numQuanta(sizeof(FreeChunk), MinObjAlignmentInBytes) * MinObjAlignment
a61af66fc99e Initial load
duke
parents:
diff changeset
106 };
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // A FreeBlockDictionary is an abstract superclass that will allow
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // a number of alternative implementations in the future.
a61af66fc99e Initial load
duke
parents:
diff changeset
110 class FreeBlockDictionary: public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
112 enum Dither {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 atLeast,
a61af66fc99e Initial load
duke
parents:
diff changeset
114 exactly,
a61af66fc99e Initial load
duke
parents:
diff changeset
115 roughly
a61af66fc99e Initial load
duke
parents:
diff changeset
116 };
a61af66fc99e Initial load
duke
parents:
diff changeset
117 enum DictionaryChoice {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 dictionaryBinaryTree = 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
119 dictionarySplayTree = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
120 dictionarySkipList = 2
a61af66fc99e Initial load
duke
parents:
diff changeset
121 };
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
124 NOT_PRODUCT(Mutex* _lock;)
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
127 virtual void removeChunk(FreeChunk* fc) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 virtual FreeChunk* getChunk(size_t size, Dither dither = atLeast) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 virtual void returnChunk(FreeChunk* chunk) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 virtual size_t totalChunkSize(debug_only(const Mutex* lock)) const = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 virtual size_t maxChunkSize() const = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 virtual size_t minSize() const = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // Reset the dictionary to the initial conditions for a single
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // block.
a61af66fc99e Initial load
duke
parents:
diff changeset
135 virtual void reset(HeapWord* addr, size_t size) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 virtual void reset() = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 virtual void dictCensusUpdate(size_t size, bool split, bool birth) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 virtual bool coalDictOverPopulated(size_t size) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 virtual void beginSweepDictCensus(double coalSurplusPercent,
a61af66fc99e Initial load
duke
parents:
diff changeset
141 float sweep_current, float sweep_ewstimate) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
142 virtual void endSweepDictCensus(double splitSurplusPercent) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 virtual FreeChunk* findLargestDict() const = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // verify that the given chunk is in the dictionary.
a61af66fc99e Initial load
duke
parents:
diff changeset
145 virtual bool verifyChunkInFreeLists(FreeChunk* tc) const = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // Sigma_{all_free_blocks} (block_size^2)
a61af66fc99e Initial load
duke
parents:
diff changeset
148 virtual double sum_of_squared_block_sizes() const = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 virtual FreeChunk* find_chunk_ends_at(HeapWord* target) const = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
151 virtual void inc_totalSize(size_t v) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
152 virtual void dec_totalSize(size_t v) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 NOT_PRODUCT (
a61af66fc99e Initial load
duke
parents:
diff changeset
155 virtual size_t sumDictReturnedBytes() = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 virtual void initializeDictReturnedBytes() = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
157 virtual size_t totalCount() = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
158 )
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 virtual void reportStatistics() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 gclog_or_tty->print("No statistics available");
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 virtual void printDictCensus() const = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 virtual void verify() const = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 Mutex* par_lock() const PRODUCT_RETURN0;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 void set_par_lock(Mutex* lock) PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 void verify_par_locked() const PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 };