annotate src/share/vm/memory/binaryTreeDictionary.cpp @ 6119:a297b0e14605

7172226: HotSpot fails to build with GCC 4.7 because of stricter c++ argument dependent lookup Summary: Add "using" keyword to import base class functions from FreeList<T> to fix template name lookup in gcc 4.7 Reviewed-by: brutisso, iveresov
author mgerdin
date Mon, 04 Jun 2012 09:21:53 +0200
parents f69a5d43dc19
children 685df3c6f84b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
0
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 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1489
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1489
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1489
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1777
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1777
diff changeset
26 #include "gc_implementation/shared/allocationStats.hpp"
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
27 #include "memory/binaryTreeDictionary.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1777
diff changeset
28 #include "runtime/globals.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1777
diff changeset
29 #include "utilities/ostream.hpp"
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
30 #ifndef SERIALGC
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
31 #include "gc_implementation/shared/spaceDecorator.hpp"
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
32 #include "gc_implementation/concurrentMarkSweep/freeChunk.hpp"
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
33 #endif // SERIALGC
0
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 ////////////////////////////////////////////////////////////////////////////////
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // A binary tree based search structure for free blocks.
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // This is currently used in the Concurrent Mark&Sweep implementation.
a61af66fc99e Initial load
duke
parents:
diff changeset
38 ////////////////////////////////////////////////////////////////////////////////
a61af66fc99e Initial load
duke
parents:
diff changeset
39
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
40 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
41 TreeChunk<Chunk>* TreeChunk<Chunk>::as_TreeChunk(Chunk* fc) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // Do some assertion checking here.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
43 return (TreeChunk<Chunk>*) fc;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
44 }
a61af66fc99e Initial load
duke
parents:
diff changeset
45
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
46 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
47 void TreeChunk<Chunk>::verify_tree_chunk_list() const {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
48 TreeChunk<Chunk>* nextTC = (TreeChunk<Chunk>*)next();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
49 if (prev() != NULL) { // interior list node shouldn'r have tree fields
a61af66fc99e Initial load
duke
parents:
diff changeset
50 guarantee(embedded_list()->parent() == NULL && embedded_list()->left() == NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
51 embedded_list()->right() == NULL, "should be clear");
a61af66fc99e Initial load
duke
parents:
diff changeset
52 }
a61af66fc99e Initial load
duke
parents:
diff changeset
53 if (nextTC != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 guarantee(as_TreeChunk(nextTC->prev()) == this, "broken chain");
a61af66fc99e Initial load
duke
parents:
diff changeset
55 guarantee(nextTC->size() == size(), "wrong size");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
56 nextTC->verify_tree_chunk_list();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
61 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
62 TreeList<Chunk>* TreeList<Chunk>::as_TreeList(TreeChunk<Chunk>* tc) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // This first free chunk in the list will be the tree list.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
64 assert(tc->size() >= BinaryTreeDictionary<Chunk>::min_tree_chunk_size, "Chunk is too small for a TreeChunk");
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
65 TreeList<Chunk>* tl = tc->embedded_list();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
66 tc->set_list(tl);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
68 tl->set_protecting_lock(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
69 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
70 tl->set_hint(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
71 tl->set_size(tc->size());
a61af66fc99e Initial load
duke
parents:
diff changeset
72 tl->link_head(tc);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 tl->link_tail(tc);
a61af66fc99e Initial load
duke
parents:
diff changeset
74 tl->set_count(1);
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
75 tl->init_statistics(true /* split_birth */);
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
76 tl->set_parent(NULL);
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
77 tl->set_left(NULL);
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
78 tl->set_right(NULL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
79 return tl;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
81
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
82 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
83 TreeList<Chunk>* TreeList<Chunk>::as_TreeList(HeapWord* addr, size_t size) {
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
84 TreeChunk<Chunk>* tc = (TreeChunk<Chunk>*) addr;
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
85 assert(size >= BinaryTreeDictionary<Chunk>::min_tree_chunk_size, "Chunk is too small for a TreeChunk");
263
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 12
diff changeset
86 // The space in the heap will have been mangled initially but
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 12
diff changeset
87 // is not remangled when a free chunk is returned to the free list
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 12
diff changeset
88 // (since it is used to maintain the chunk on the free list).
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 12
diff changeset
89 assert((ZapUnusedHeapArea &&
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 12
diff changeset
90 SpaceMangler::is_mangled((HeapWord*) tc->size_addr()) &&
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 12
diff changeset
91 SpaceMangler::is_mangled((HeapWord*) tc->prev_addr()) &&
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 12
diff changeset
92 SpaceMangler::is_mangled((HeapWord*) tc->next_addr())) ||
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 12
diff changeset
93 (tc->size() == 0 && tc->prev() == NULL && tc->next() == NULL),
12eea04c8b06 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 12
diff changeset
94 "Space should be clear or mangled");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
95 tc->set_size(size);
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
96 tc->link_prev(NULL);
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
97 tc->link_next(NULL);
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
98 TreeList<Chunk>* tl = TreeList<Chunk>::as_TreeList(tc);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
99 return tl;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
102 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
103 TreeList<Chunk>* TreeList<Chunk>::remove_chunk_replace_if_needed(TreeChunk<Chunk>* tc) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
104
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
105 TreeList<Chunk>* retTL = this;
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
106 Chunk* list = head();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
107 assert(!list || list != list->next(), "Chunk on list twice");
a61af66fc99e Initial load
duke
parents:
diff changeset
108 assert(tc != NULL, "Chunk being removed is NULL");
a61af66fc99e Initial load
duke
parents:
diff changeset
109 assert(parent() == NULL || this == parent()->left() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
110 this == parent()->right(), "list is inconsistent");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
111 assert(tc->is_free(), "Header is not marked correctly");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
112 assert(head() == NULL || head()->prev() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
113 assert(tail() == NULL || tail()->next() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
114
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
115 Chunk* prevFC = tc->prev();
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
116 TreeChunk<Chunk>* nextTC = TreeChunk<Chunk>::as_TreeChunk(tc->next());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
117 assert(list != NULL, "should have at least the target chunk");
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Is this the first item on the list?
a61af66fc99e Initial load
duke
parents:
diff changeset
120 if (tc == list) {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
121 // The "getChunk..." functions for a TreeList<Chunk> will not return the
0
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // first chunk in the list unless it is the last chunk in the list
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // because the first chunk is also acting as the tree node.
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // When coalescing happens, however, the first chunk in the a tree
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // list can be the start of a free range. Free ranges are removed
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // from the free lists so that they are not available to be
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // allocated when the sweeper yields (giving up the free list lock)
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // to allow mutator activity. If this chunk is the first in the
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // list and is not the last in the list, do the work to copy the
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
130 // TreeList<Chunk> from the first chunk to the next chunk and update all
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
131 // the TreeList<Chunk> pointers in the chunks in the list.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
132 if (nextTC == NULL) {
1489
cff162798819 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 1145
diff changeset
133 assert(prevFC == NULL, "Not last chunk in the list");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
134 set_tail(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 set_head(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // copy embedded list.
a61af66fc99e Initial load
duke
parents:
diff changeset
138 nextTC->set_embedded_list(tc->embedded_list());
a61af66fc99e Initial load
duke
parents:
diff changeset
139 retTL = nextTC->embedded_list();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // Fix the pointer to the list in each chunk in the list.
a61af66fc99e Initial load
duke
parents:
diff changeset
141 // This can be slow for a long list. Consider having
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // an option that does not allow the first chunk on the
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // list to be coalesced.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
144 for (TreeChunk<Chunk>* curTC = nextTC; curTC != NULL;
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
145 curTC = TreeChunk<Chunk>::as_TreeChunk(curTC->next())) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
146 curTC->set_list(retTL);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
148 // Fix the parent to point to the new TreeList<Chunk>.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
149 if (retTL->parent() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 if (this == retTL->parent()->left()) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
151 retTL->parent()->set_left(retTL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
152 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 assert(this == retTL->parent()->right(), "Parent is incorrect");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
154 retTL->parent()->set_right(retTL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157 // Fix the children's parent pointers to point to the
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // new list.
a61af66fc99e Initial load
duke
parents:
diff changeset
159 assert(right() == retTL->right(), "Should have been copied");
a61af66fc99e Initial load
duke
parents:
diff changeset
160 if (retTL->right() != NULL) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
161 retTL->right()->set_parent(retTL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163 assert(left() == retTL->left(), "Should have been copied");
a61af66fc99e Initial load
duke
parents:
diff changeset
164 if (retTL->left() != NULL) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
165 retTL->left()->set_parent(retTL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167 retTL->link_head(nextTC);
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
168 assert(nextTC->is_free(), "Should be a free chunk");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 if (nextTC == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // Removing chunk at tail of list
a61af66fc99e Initial load
duke
parents:
diff changeset
173 link_tail(prevFC);
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // Chunk is interior to the list
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
176 prevFC->link_after(nextTC);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
179 // Below this point the embeded TreeList<Chunk> being used for the
0
a61af66fc99e Initial load
duke
parents:
diff changeset
180 // tree node may have changed. Don't use "this"
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
181 // TreeList<Chunk>*.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
182 // chunk should still be a free chunk (bit set in _prev)
a61af66fc99e Initial load
duke
parents:
diff changeset
183 assert(!retTL->head() || retTL->size() == retTL->head()->size(),
a61af66fc99e Initial load
duke
parents:
diff changeset
184 "Wrong sized chunk in list");
a61af66fc99e Initial load
duke
parents:
diff changeset
185 debug_only(
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
186 tc->link_prev(NULL);
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
187 tc->link_next(NULL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
188 tc->set_list(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 bool prev_found = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
190 bool next_found = false;
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
191 for (Chunk* curFC = retTL->head();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
192 curFC != NULL; curFC = curFC->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 assert(curFC != tc, "Chunk is still in list");
a61af66fc99e Initial load
duke
parents:
diff changeset
194 if (curFC == prevFC) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 prev_found = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197 if (curFC == nextTC) {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 next_found = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200 }
a61af66fc99e Initial load
duke
parents:
diff changeset
201 assert(prevFC == NULL || prev_found, "Chunk was lost from list");
a61af66fc99e Initial load
duke
parents:
diff changeset
202 assert(nextTC == NULL || next_found, "Chunk was lost from list");
a61af66fc99e Initial load
duke
parents:
diff changeset
203 assert(retTL->parent() == NULL ||
a61af66fc99e Initial load
duke
parents:
diff changeset
204 retTL == retTL->parent()->left() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
205 retTL == retTL->parent()->right(),
a61af66fc99e Initial load
duke
parents:
diff changeset
206 "list is inconsistent");
a61af66fc99e Initial load
duke
parents:
diff changeset
207 )
a61af66fc99e Initial load
duke
parents:
diff changeset
208 retTL->decrement_count();
a61af66fc99e Initial load
duke
parents:
diff changeset
209
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
210 assert(tc->is_free(), "Should still be a free chunk");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
211 assert(retTL->head() == NULL || retTL->head()->prev() == NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
212 "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
213 assert(retTL->tail() == NULL || retTL->tail()->next() == NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
214 "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
215 return retTL;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
217
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
218 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
219 void TreeList<Chunk>::return_chunk_at_tail(TreeChunk<Chunk>* chunk) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
220 assert(chunk != NULL, "returning NULL chunk");
a61af66fc99e Initial load
duke
parents:
diff changeset
221 assert(chunk->list() == this, "list should be set for chunk");
a61af66fc99e Initial load
duke
parents:
diff changeset
222 assert(tail() != NULL, "The tree list is embedded in the first chunk");
a61af66fc99e Initial load
duke
parents:
diff changeset
223 // which means that the list can never be empty.
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
224 assert(!verify_chunk_in_free_list(chunk), "Double entry");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
225 assert(head() == NULL || head()->prev() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
226 assert(tail() == NULL || tail()->next() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
227
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
228 Chunk* fc = tail();
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
229 fc->link_after(chunk);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
230 link_tail(chunk);
a61af66fc99e Initial load
duke
parents:
diff changeset
231
a61af66fc99e Initial load
duke
parents:
diff changeset
232 assert(!tail() || size() == tail()->size(), "Wrong sized chunk in list");
6119
a297b0e14605 7172226: HotSpot fails to build with GCC 4.7 because of stricter c++ argument dependent lookup
mgerdin
parents: 6028
diff changeset
233 increment_count();
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
234 debug_only(increment_returned_bytes_by(chunk->size()*sizeof(HeapWord));)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
235 assert(head() == NULL || head()->prev() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
236 assert(tail() == NULL || tail()->next() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // Add this chunk at the head of the list. "At the head of the list"
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // is defined to be after the chunk pointer to by head(). This is
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
241 // because the TreeList<Chunk> is embedded in the first TreeChunk<Chunk> in the
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
242 // list. See the definition of TreeChunk<Chunk>.
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
243 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
244 void TreeList<Chunk>::return_chunk_at_head(TreeChunk<Chunk>* chunk) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
245 assert(chunk->list() == this, "list should be set for chunk");
a61af66fc99e Initial load
duke
parents:
diff changeset
246 assert(head() != NULL, "The tree list is embedded in the first chunk");
a61af66fc99e Initial load
duke
parents:
diff changeset
247 assert(chunk != NULL, "returning NULL chunk");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
248 assert(!verify_chunk_in_free_list(chunk), "Double entry");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
249 assert(head() == NULL || head()->prev() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
250 assert(tail() == NULL || tail()->next() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
251
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
252 Chunk* fc = head()->next();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
253 if (fc != NULL) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
254 chunk->link_after(fc);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
255 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 assert(tail() == NULL, "List is inconsistent");
a61af66fc99e Initial load
duke
parents:
diff changeset
257 link_tail(chunk);
a61af66fc99e Initial load
duke
parents:
diff changeset
258 }
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
259 head()->link_after(chunk);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
260 assert(!head() || size() == head()->size(), "Wrong sized chunk in list");
6119
a297b0e14605 7172226: HotSpot fails to build with GCC 4.7 because of stricter c++ argument dependent lookup
mgerdin
parents: 6028
diff changeset
261 increment_count();
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
262 debug_only(increment_returned_bytes_by(chunk->size()*sizeof(HeapWord));)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
263 assert(head() == NULL || head()->prev() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
264 assert(tail() == NULL || tail()->next() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
267 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
268 TreeChunk<Chunk>* TreeList<Chunk>::head_as_TreeChunk() {
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
269 assert(head() == NULL || TreeChunk<Chunk>::as_TreeChunk(head())->list() == this,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
270 "Wrong type of chunk?");
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
271 return TreeChunk<Chunk>::as_TreeChunk(head());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
274 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
275 TreeChunk<Chunk>* TreeList<Chunk>::first_available() {
1777
179464550c7d 6983930: CMS: Various small cleanups ca September 2010
ysr
parents: 1552
diff changeset
276 assert(head() != NULL, "The head of the list cannot be NULL");
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
277 Chunk* fc = head()->next();
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
278 TreeChunk<Chunk>* retTC;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
279 if (fc == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 retTC = head_as_TreeChunk();
a61af66fc99e Initial load
duke
parents:
diff changeset
281 } else {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
282 retTC = TreeChunk<Chunk>::as_TreeChunk(fc);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
283 }
a61af66fc99e Initial load
duke
parents:
diff changeset
284 assert(retTC->list() == this, "Wrong type of chunk.");
a61af66fc99e Initial load
duke
parents:
diff changeset
285 return retTC;
a61af66fc99e Initial load
duke
parents:
diff changeset
286 }
a61af66fc99e Initial load
duke
parents:
diff changeset
287
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
288 // Returns the block with the largest heap address amongst
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
289 // those in the list for this size; potentially slow and expensive,
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
290 // use with caution!
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
291 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
292 TreeChunk<Chunk>* TreeList<Chunk>::largest_address() {
1777
179464550c7d 6983930: CMS: Various small cleanups ca September 2010
ysr
parents: 1552
diff changeset
293 assert(head() != NULL, "The head of the list cannot be NULL");
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
294 Chunk* fc = head()->next();
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
295 TreeChunk<Chunk>* retTC;
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
296 if (fc == NULL) {
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
297 retTC = head_as_TreeChunk();
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
298 } else {
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
299 // walk down the list and return the one with the highest
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
300 // heap address among chunks of this size.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
301 Chunk* last = fc;
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
302 while (fc->next() != NULL) {
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
303 if ((HeapWord*)last < (HeapWord*)fc) {
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
304 last = fc;
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
305 }
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
306 fc = fc->next();
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
307 }
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
308 retTC = TreeChunk<Chunk>::as_TreeChunk(last);
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
309 }
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
310 assert(retTC->list() == this, "Wrong type of chunk.");
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
311 return retTC;
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
312 }
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
313
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
314 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
315 BinaryTreeDictionary<Chunk>::BinaryTreeDictionary(bool adaptive_freelists, bool splay) :
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
316 _splay(splay), _adaptive_freelists(adaptive_freelists),
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
317 _total_size(0), _total_free_blocks(0), _root(0) {}
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
318
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
319 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
320 BinaryTreeDictionary<Chunk>::BinaryTreeDictionary(MemRegion mr,
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
321 bool adaptive_freelists,
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
322 bool splay):
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
323 _adaptive_freelists(adaptive_freelists), _splay(splay)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
324 {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
325 assert(mr.word_size() >= BinaryTreeDictionary<Chunk>::min_tree_chunk_size, "minimum chunk size");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 reset(mr);
a61af66fc99e Initial load
duke
parents:
diff changeset
328 assert(root()->left() == NULL, "reset check failed");
a61af66fc99e Initial load
duke
parents:
diff changeset
329 assert(root()->right() == NULL, "reset check failed");
a61af66fc99e Initial load
duke
parents:
diff changeset
330 assert(root()->head()->next() == NULL, "reset check failed");
a61af66fc99e Initial load
duke
parents:
diff changeset
331 assert(root()->head()->prev() == NULL, "reset check failed");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
332 assert(total_size() == root()->size(), "reset check failed");
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
333 assert(total_free_blocks() == 1, "reset check failed");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
335
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
336 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
337 void BinaryTreeDictionary<Chunk>::inc_total_size(size_t inc) {
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
338 _total_size = _total_size + inc;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
339 }
a61af66fc99e Initial load
duke
parents:
diff changeset
340
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
341 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
342 void BinaryTreeDictionary<Chunk>::dec_total_size(size_t dec) {
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
343 _total_size = _total_size - dec;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
344 }
a61af66fc99e Initial load
duke
parents:
diff changeset
345
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
346 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
347 void BinaryTreeDictionary<Chunk>::reset(MemRegion mr) {
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
348 assert(mr.word_size() >= BinaryTreeDictionary<Chunk>::min_tree_chunk_size, "minimum chunk size");
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
349 set_root(TreeList<Chunk>::as_TreeList(mr.start(), mr.word_size()));
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
350 set_total_size(mr.word_size());
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
351 set_total_free_blocks(1);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
353
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
354 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
355 void BinaryTreeDictionary<Chunk>::reset(HeapWord* addr, size_t byte_size) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
356 MemRegion mr(addr, heap_word_size(byte_size));
a61af66fc99e Initial load
duke
parents:
diff changeset
357 reset(mr);
a61af66fc99e Initial load
duke
parents:
diff changeset
358 }
a61af66fc99e Initial load
duke
parents:
diff changeset
359
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
360 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
361 void BinaryTreeDictionary<Chunk>::reset() {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
362 set_root(NULL);
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
363 set_total_size(0);
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
364 set_total_free_blocks(0);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
365 }
a61af66fc99e Initial load
duke
parents:
diff changeset
366
a61af66fc99e Initial load
duke
parents:
diff changeset
367 // Get a free block of size at least size from tree, or NULL.
a61af66fc99e Initial load
duke
parents:
diff changeset
368 // If a splay step is requested, the removal algorithm (only) incorporates
a61af66fc99e Initial load
duke
parents:
diff changeset
369 // a splay step as follows:
a61af66fc99e Initial load
duke
parents:
diff changeset
370 // . the search proceeds down the tree looking for a possible
a61af66fc99e Initial load
duke
parents:
diff changeset
371 // match. At the (closest) matching location, an appropriate splay step is applied
a61af66fc99e Initial load
duke
parents:
diff changeset
372 // (zig, zig-zig or zig-zag). A chunk of the appropriate size is then returned
a61af66fc99e Initial load
duke
parents:
diff changeset
373 // if available, and if it's the last chunk, the node is deleted. A deteleted
a61af66fc99e Initial load
duke
parents:
diff changeset
374 // node is replaced in place by its tree successor.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
375 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
376 TreeChunk<Chunk>*
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
377 BinaryTreeDictionary<Chunk>::get_chunk_from_tree(size_t size, enum FreeBlockDictionary<Chunk>::Dither dither, bool splay)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
378 {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
379 TreeList<Chunk> *curTL, *prevTL;
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
380 TreeChunk<Chunk>* retTC = NULL;
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
381 assert(size >= BinaryTreeDictionary<Chunk>::min_tree_chunk_size, "minimum chunk size");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
382 if (FLSVerifyDictionary) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
383 verify_tree();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
384 }
a61af66fc99e Initial load
duke
parents:
diff changeset
385 // starting at the root, work downwards trying to find match.
a61af66fc99e Initial load
duke
parents:
diff changeset
386 // Remember the last node of size too great or too small.
a61af66fc99e Initial load
duke
parents:
diff changeset
387 for (prevTL = curTL = root(); curTL != NULL;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
388 if (curTL->size() == size) { // exact match
a61af66fc99e Initial load
duke
parents:
diff changeset
389 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
390 }
a61af66fc99e Initial load
duke
parents:
diff changeset
391 prevTL = curTL;
a61af66fc99e Initial load
duke
parents:
diff changeset
392 if (curTL->size() < size) { // proceed to right sub-tree
a61af66fc99e Initial load
duke
parents:
diff changeset
393 curTL = curTL->right();
a61af66fc99e Initial load
duke
parents:
diff changeset
394 } else { // proceed to left sub-tree
a61af66fc99e Initial load
duke
parents:
diff changeset
395 assert(curTL->size() > size, "size inconsistency");
a61af66fc99e Initial load
duke
parents:
diff changeset
396 curTL = curTL->left();
a61af66fc99e Initial load
duke
parents:
diff changeset
397 }
a61af66fc99e Initial load
duke
parents:
diff changeset
398 }
a61af66fc99e Initial load
duke
parents:
diff changeset
399 if (curTL == NULL) { // couldn't find exact match
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
400
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
401 if (dither == FreeBlockDictionary<Chunk>::exactly) return NULL;
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
402
0
a61af66fc99e Initial load
duke
parents:
diff changeset
403 // try and find the next larger size by walking back up the search path
a61af66fc99e Initial load
duke
parents:
diff changeset
404 for (curTL = prevTL; curTL != NULL;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
405 if (curTL->size() >= size) break;
a61af66fc99e Initial load
duke
parents:
diff changeset
406 else curTL = curTL->parent();
a61af66fc99e Initial load
duke
parents:
diff changeset
407 }
a61af66fc99e Initial load
duke
parents:
diff changeset
408 assert(curTL == NULL || curTL->count() > 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
409 "An empty list should not be in the tree");
a61af66fc99e Initial load
duke
parents:
diff changeset
410 }
a61af66fc99e Initial load
duke
parents:
diff changeset
411 if (curTL != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
412 assert(curTL->size() >= size, "size inconsistency");
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
413 if (adaptive_freelists()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
414
a61af66fc99e Initial load
duke
parents:
diff changeset
415 // A candidate chunk has been found. If it is already under
a61af66fc99e Initial load
duke
parents:
diff changeset
416 // populated, get a chunk associated with the hint for this
a61af66fc99e Initial load
duke
parents:
diff changeset
417 // chunk.
a61af66fc99e Initial load
duke
parents:
diff changeset
418 if (curTL->surplus() <= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
419 /* Use the hint to find a size with a surplus, and reset the hint. */
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
420 TreeList<Chunk>* hintTL = curTL;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
421 while (hintTL->hint() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
422 assert(hintTL->hint() == 0 || hintTL->hint() > hintTL->size(),
a61af66fc99e Initial load
duke
parents:
diff changeset
423 "hint points in the wrong direction");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
424 hintTL = find_list(hintTL->hint());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
425 assert(curTL != hintTL, "Infinite loop");
a61af66fc99e Initial load
duke
parents:
diff changeset
426 if (hintTL == NULL ||
a61af66fc99e Initial load
duke
parents:
diff changeset
427 hintTL == curTL /* Should not happen but protect against it */ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
428 // No useful hint. Set the hint to NULL and go on.
a61af66fc99e Initial load
duke
parents:
diff changeset
429 curTL->set_hint(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
430 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
431 }
a61af66fc99e Initial load
duke
parents:
diff changeset
432 assert(hintTL->size() > size, "hint is inconsistent");
a61af66fc99e Initial load
duke
parents:
diff changeset
433 if (hintTL->surplus() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
434 // The hint led to a list that has a surplus. Use it.
a61af66fc99e Initial load
duke
parents:
diff changeset
435 // Set the hint for the candidate to an overpopulated
a61af66fc99e Initial load
duke
parents:
diff changeset
436 // size.
a61af66fc99e Initial load
duke
parents:
diff changeset
437 curTL->set_hint(hintTL->size());
a61af66fc99e Initial load
duke
parents:
diff changeset
438 // Change the candidate.
a61af66fc99e Initial load
duke
parents:
diff changeset
439 curTL = hintTL;
a61af66fc99e Initial load
duke
parents:
diff changeset
440 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
441 }
a61af66fc99e Initial load
duke
parents:
diff changeset
442 // The evm code reset the hint of the candidate as
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
443 // at an interim point. Why? Seems like this leaves
0
a61af66fc99e Initial load
duke
parents:
diff changeset
444 // the hint pointing to a list that didn't work.
a61af66fc99e Initial load
duke
parents:
diff changeset
445 // curTL->set_hint(hintTL->size());
a61af66fc99e Initial load
duke
parents:
diff changeset
446 }
a61af66fc99e Initial load
duke
parents:
diff changeset
447 }
a61af66fc99e Initial load
duke
parents:
diff changeset
448 }
a61af66fc99e Initial load
duke
parents:
diff changeset
449 // don't waste time splaying if chunk's singleton
a61af66fc99e Initial load
duke
parents:
diff changeset
450 if (splay && curTL->head()->next() != NULL) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
451 semi_splay_step(curTL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
452 }
a61af66fc99e Initial load
duke
parents:
diff changeset
453 retTC = curTL->first_available();
a61af66fc99e Initial load
duke
parents:
diff changeset
454 assert((retTC != NULL) && (curTL->count() > 0),
a61af66fc99e Initial load
duke
parents:
diff changeset
455 "A list in the binary tree should not be NULL");
a61af66fc99e Initial load
duke
parents:
diff changeset
456 assert(retTC->size() >= size,
a61af66fc99e Initial load
duke
parents:
diff changeset
457 "A chunk of the wrong size was found");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
458 remove_chunk_from_tree(retTC);
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
459 assert(retTC->is_free(), "Header is not marked correctly");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
461
a61af66fc99e Initial load
duke
parents:
diff changeset
462 if (FLSVerifyDictionary) {
a61af66fc99e Initial load
duke
parents:
diff changeset
463 verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
465 return retTC;
a61af66fc99e Initial load
duke
parents:
diff changeset
466 }
a61af66fc99e Initial load
duke
parents:
diff changeset
467
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
468 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
469 TreeList<Chunk>* BinaryTreeDictionary<Chunk>::find_list(size_t size) const {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
470 TreeList<Chunk>* curTL;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
471 for (curTL = root(); curTL != NULL;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
472 if (curTL->size() == size) { // exact match
a61af66fc99e Initial load
duke
parents:
diff changeset
473 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
474 }
a61af66fc99e Initial load
duke
parents:
diff changeset
475
a61af66fc99e Initial load
duke
parents:
diff changeset
476 if (curTL->size() < size) { // proceed to right sub-tree
a61af66fc99e Initial load
duke
parents:
diff changeset
477 curTL = curTL->right();
a61af66fc99e Initial load
duke
parents:
diff changeset
478 } else { // proceed to left sub-tree
a61af66fc99e Initial load
duke
parents:
diff changeset
479 assert(curTL->size() > size, "size inconsistency");
a61af66fc99e Initial load
duke
parents:
diff changeset
480 curTL = curTL->left();
a61af66fc99e Initial load
duke
parents:
diff changeset
481 }
a61af66fc99e Initial load
duke
parents:
diff changeset
482 }
a61af66fc99e Initial load
duke
parents:
diff changeset
483 return curTL;
a61af66fc99e Initial load
duke
parents:
diff changeset
484 }
a61af66fc99e Initial load
duke
parents:
diff changeset
485
a61af66fc99e Initial load
duke
parents:
diff changeset
486
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
487 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
488 bool BinaryTreeDictionary<Chunk>::verify_chunk_in_free_list(Chunk* tc) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
489 size_t size = tc->size();
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
490 TreeList<Chunk>* tl = find_list(size);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
491 if (tl == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
492 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
493 } else {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
494 return tl->verify_chunk_in_free_list(tc);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
495 }
a61af66fc99e Initial load
duke
parents:
diff changeset
496 }
a61af66fc99e Initial load
duke
parents:
diff changeset
497
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
498 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
499 Chunk* BinaryTreeDictionary<Chunk>::find_largest_dict() const {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
500 TreeList<Chunk> *curTL = root();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
501 if (curTL != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
502 while(curTL->right() != NULL) curTL = curTL->right();
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
503 return curTL->largest_address();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
504 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
505 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
506 }
a61af66fc99e Initial load
duke
parents:
diff changeset
507 }
a61af66fc99e Initial load
duke
parents:
diff changeset
508
a61af66fc99e Initial load
duke
parents:
diff changeset
509 // Remove the current chunk from the tree. If it is not the last
a61af66fc99e Initial load
duke
parents:
diff changeset
510 // chunk in a list on a tree node, just unlink it.
a61af66fc99e Initial load
duke
parents:
diff changeset
511 // If it is the last chunk in the list (the next link is NULL),
a61af66fc99e Initial load
duke
parents:
diff changeset
512 // remove the node and repair the tree.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
513 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
514 TreeChunk<Chunk>*
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
515 BinaryTreeDictionary<Chunk>::remove_chunk_from_tree(TreeChunk<Chunk>* tc) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
516 assert(tc != NULL, "Should not call with a NULL chunk");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
517 assert(tc->is_free(), "Header is not marked correctly");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
518
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
519 TreeList<Chunk> *newTL, *parentTL;
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
520 TreeChunk<Chunk>* retTC;
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
521 TreeList<Chunk>* tl = tc->list();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
522 debug_only(
a61af66fc99e Initial load
duke
parents:
diff changeset
523 bool removing_only_chunk = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
524 if (tl == _root) {
a61af66fc99e Initial load
duke
parents:
diff changeset
525 if ((_root->left() == NULL) && (_root->right() == NULL)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
526 if (_root->count() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
527 assert(_root->head() == tc, "Should only be this one chunk");
a61af66fc99e Initial load
duke
parents:
diff changeset
528 removing_only_chunk = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
529 }
a61af66fc99e Initial load
duke
parents:
diff changeset
530 }
a61af66fc99e Initial load
duke
parents:
diff changeset
531 }
a61af66fc99e Initial load
duke
parents:
diff changeset
532 )
a61af66fc99e Initial load
duke
parents:
diff changeset
533 assert(tl != NULL, "List should be set");
a61af66fc99e Initial load
duke
parents:
diff changeset
534 assert(tl->parent() == NULL || tl == tl->parent()->left() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
535 tl == tl->parent()->right(), "list is inconsistent");
a61af66fc99e Initial load
duke
parents:
diff changeset
536
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
537 bool complicated_splice = false;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
538
a61af66fc99e Initial load
duke
parents:
diff changeset
539 retTC = tc;
a61af66fc99e Initial load
duke
parents:
diff changeset
540 // Removing this chunk can have the side effect of changing the node
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
541 // (TreeList<Chunk>*) in the tree. If the node is the root, update it.
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
542 TreeList<Chunk>* replacementTL = tl->remove_chunk_replace_if_needed(tc);
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
543 assert(tc->is_free(), "Chunk should still be free");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
544 assert(replacementTL->parent() == NULL ||
a61af66fc99e Initial load
duke
parents:
diff changeset
545 replacementTL == replacementTL->parent()->left() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
546 replacementTL == replacementTL->parent()->right(),
a61af66fc99e Initial load
duke
parents:
diff changeset
547 "list is inconsistent");
a61af66fc99e Initial load
duke
parents:
diff changeset
548 if (tl == root()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
549 assert(replacementTL->parent() == NULL, "Incorrectly replacing root");
a61af66fc99e Initial load
duke
parents:
diff changeset
550 set_root(replacementTL);
a61af66fc99e Initial load
duke
parents:
diff changeset
551 }
a61af66fc99e Initial load
duke
parents:
diff changeset
552 debug_only(
a61af66fc99e Initial load
duke
parents:
diff changeset
553 if (tl != replacementTL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
554 assert(replacementTL->head() != NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
555 "If the tree list was replaced, it should not be a NULL list");
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
556 TreeList<Chunk>* rhl = replacementTL->head_as_TreeChunk()->list();
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
557 TreeList<Chunk>* rtl = TreeChunk<Chunk>::as_TreeChunk(replacementTL->tail())->list();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
558 assert(rhl == replacementTL, "Broken head");
a61af66fc99e Initial load
duke
parents:
diff changeset
559 assert(rtl == replacementTL, "Broken tail");
a61af66fc99e Initial load
duke
parents:
diff changeset
560 assert(replacementTL->size() == tc->size(), "Broken size");
a61af66fc99e Initial load
duke
parents:
diff changeset
561 }
a61af66fc99e Initial load
duke
parents:
diff changeset
562 )
a61af66fc99e Initial load
duke
parents:
diff changeset
563
a61af66fc99e Initial load
duke
parents:
diff changeset
564 // Does the tree need to be repaired?
a61af66fc99e Initial load
duke
parents:
diff changeset
565 if (replacementTL->count() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
566 assert(replacementTL->head() == NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
567 replacementTL->tail() == NULL, "list count is incorrect");
a61af66fc99e Initial load
duke
parents:
diff changeset
568 // Find the replacement node for the (soon to be empty) node being removed.
a61af66fc99e Initial load
duke
parents:
diff changeset
569 // if we have a single (or no) child, splice child in our stead
a61af66fc99e Initial load
duke
parents:
diff changeset
570 if (replacementTL->left() == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
571 // left is NULL so pick right. right may also be NULL.
a61af66fc99e Initial load
duke
parents:
diff changeset
572 newTL = replacementTL->right();
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
573 debug_only(replacementTL->clear_right();)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
574 } else if (replacementTL->right() == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
575 // right is NULL
a61af66fc99e Initial load
duke
parents:
diff changeset
576 newTL = replacementTL->left();
a61af66fc99e Initial load
duke
parents:
diff changeset
577 debug_only(replacementTL->clearLeft();)
a61af66fc99e Initial load
duke
parents:
diff changeset
578 } else { // we have both children, so, by patriarchal convention,
a61af66fc99e Initial load
duke
parents:
diff changeset
579 // my replacement is least node in right sub-tree
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
580 complicated_splice = true;
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
581 newTL = remove_tree_minimum(replacementTL->right());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
582 assert(newTL != NULL && newTL->left() == NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
583 newTL->right() == NULL, "sub-tree minimum exists");
a61af66fc99e Initial load
duke
parents:
diff changeset
584 }
a61af66fc99e Initial load
duke
parents:
diff changeset
585 // newTL is the replacement for the (soon to be empty) node.
a61af66fc99e Initial load
duke
parents:
diff changeset
586 // newTL may be NULL.
a61af66fc99e Initial load
duke
parents:
diff changeset
587 // should verify; we just cleanly excised our replacement
a61af66fc99e Initial load
duke
parents:
diff changeset
588 if (FLSVerifyDictionary) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
589 verify_tree();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
590 }
a61af66fc99e Initial load
duke
parents:
diff changeset
591 // first make newTL my parent's child
a61af66fc99e Initial load
duke
parents:
diff changeset
592 if ((parentTL = replacementTL->parent()) == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
593 // newTL should be root
a61af66fc99e Initial load
duke
parents:
diff changeset
594 assert(tl == root(), "Incorrectly replacing root");
a61af66fc99e Initial load
duke
parents:
diff changeset
595 set_root(newTL);
a61af66fc99e Initial load
duke
parents:
diff changeset
596 if (newTL != NULL) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
597 newTL->clear_parent();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
598 }
a61af66fc99e Initial load
duke
parents:
diff changeset
599 } else if (parentTL->right() == replacementTL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
600 // replacementTL is a right child
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
601 parentTL->set_right(newTL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
602 } else { // replacementTL is a left child
a61af66fc99e Initial load
duke
parents:
diff changeset
603 assert(parentTL->left() == replacementTL, "should be left child");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
604 parentTL->set_left(newTL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
605 }
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
606 debug_only(replacementTL->clear_parent();)
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
607 if (complicated_splice) { // we need newTL to get replacementTL's
0
a61af66fc99e Initial load
duke
parents:
diff changeset
608 // two children
a61af66fc99e Initial load
duke
parents:
diff changeset
609 assert(newTL != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
610 newTL->left() == NULL && newTL->right() == NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
611 "newTL should not have encumbrances from the past");
a61af66fc99e Initial load
duke
parents:
diff changeset
612 // we'd like to assert as below:
a61af66fc99e Initial load
duke
parents:
diff changeset
613 // assert(replacementTL->left() != NULL && replacementTL->right() != NULL,
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
614 // "else !complicated_splice");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
615 // ... however, the above assertion is too strong because we aren't
a61af66fc99e Initial load
duke
parents:
diff changeset
616 // guaranteed that replacementTL->right() is still NULL.
a61af66fc99e Initial load
duke
parents:
diff changeset
617 // Recall that we removed
a61af66fc99e Initial load
duke
parents:
diff changeset
618 // the right sub-tree minimum from replacementTL.
a61af66fc99e Initial load
duke
parents:
diff changeset
619 // That may well have been its right
a61af66fc99e Initial load
duke
parents:
diff changeset
620 // child! So we'll just assert half of the above:
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
621 assert(replacementTL->left() != NULL, "else !complicated_splice");
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
622 newTL->set_left(replacementTL->left());
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
623 newTL->set_right(replacementTL->right());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
624 debug_only(
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
625 replacementTL->clear_right();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
626 replacementTL->clearLeft();
a61af66fc99e Initial load
duke
parents:
diff changeset
627 )
a61af66fc99e Initial load
duke
parents:
diff changeset
628 }
a61af66fc99e Initial load
duke
parents:
diff changeset
629 assert(replacementTL->right() == NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
630 replacementTL->left() == NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
631 replacementTL->parent() == NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
632 "delete without encumbrances");
a61af66fc99e Initial load
duke
parents:
diff changeset
633 }
a61af66fc99e Initial load
duke
parents:
diff changeset
634
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
635 assert(total_size() >= retTC->size(), "Incorrect total size");
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
636 dec_total_size(retTC->size()); // size book-keeping
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
637 assert(total_free_blocks() > 0, "Incorrect total count");
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
638 set_total_free_blocks(total_free_blocks() - 1);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
639
a61af66fc99e Initial load
duke
parents:
diff changeset
640 assert(retTC != NULL, "null chunk?");
a61af66fc99e Initial load
duke
parents:
diff changeset
641 assert(retTC->prev() == NULL && retTC->next() == NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
642 "should return without encumbrances");
a61af66fc99e Initial load
duke
parents:
diff changeset
643 if (FLSVerifyDictionary) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
644 verify_tree();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
645 }
a61af66fc99e Initial load
duke
parents:
diff changeset
646 assert(!removing_only_chunk || _root == NULL, "root should be NULL");
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
647 return TreeChunk<Chunk>::as_TreeChunk(retTC);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
648 }
a61af66fc99e Initial load
duke
parents:
diff changeset
649
a61af66fc99e Initial load
duke
parents:
diff changeset
650 // Remove the leftmost node (lm) in the tree and return it.
a61af66fc99e Initial load
duke
parents:
diff changeset
651 // If lm has a right child, link it to the left node of
a61af66fc99e Initial load
duke
parents:
diff changeset
652 // the parent of lm.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
653 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
654 TreeList<Chunk>* BinaryTreeDictionary<Chunk>::remove_tree_minimum(TreeList<Chunk>* tl) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
655 assert(tl != NULL && tl->parent() != NULL, "really need a proper sub-tree");
a61af66fc99e Initial load
duke
parents:
diff changeset
656 // locate the subtree minimum by walking down left branches
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
657 TreeList<Chunk>* curTL = tl;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
658 for (; curTL->left() != NULL; curTL = curTL->left());
a61af66fc99e Initial load
duke
parents:
diff changeset
659 // obviously curTL now has at most one child, a right child
a61af66fc99e Initial load
duke
parents:
diff changeset
660 if (curTL != root()) { // Should this test just be removed?
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
661 TreeList<Chunk>* parentTL = curTL->parent();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
662 if (parentTL->left() == curTL) { // curTL is a left child
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
663 parentTL->set_left(curTL->right());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
664 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
665 // If the list tl has no left child, then curTL may be
a61af66fc99e Initial load
duke
parents:
diff changeset
666 // the right child of parentTL.
a61af66fc99e Initial load
duke
parents:
diff changeset
667 assert(parentTL->right() == curTL, "should be a right child");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
668 parentTL->set_right(curTL->right());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
669 }
a61af66fc99e Initial load
duke
parents:
diff changeset
670 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
671 // The only use of this method would not pass the root of the
a61af66fc99e Initial load
duke
parents:
diff changeset
672 // tree (as indicated by the assertion above that the tree list
a61af66fc99e Initial load
duke
parents:
diff changeset
673 // has a parent) but the specification does not explicitly exclude the
a61af66fc99e Initial load
duke
parents:
diff changeset
674 // passing of the root so accomodate it.
a61af66fc99e Initial load
duke
parents:
diff changeset
675 set_root(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
676 }
a61af66fc99e Initial load
duke
parents:
diff changeset
677 debug_only(
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
678 curTL->clear_parent(); // Test if this needs to be cleared
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
679 curTL->clear_right(); // recall, above, left child is already null
0
a61af66fc99e Initial load
duke
parents:
diff changeset
680 )
a61af66fc99e Initial load
duke
parents:
diff changeset
681 // we just excised a (non-root) node, we should still verify all tree invariants
a61af66fc99e Initial load
duke
parents:
diff changeset
682 if (FLSVerifyDictionary) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
683 verify_tree();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
684 }
a61af66fc99e Initial load
duke
parents:
diff changeset
685 return curTL;
a61af66fc99e Initial load
duke
parents:
diff changeset
686 }
a61af66fc99e Initial load
duke
parents:
diff changeset
687
a61af66fc99e Initial load
duke
parents:
diff changeset
688 // Based on a simplification of the algorithm by Sleator and Tarjan (JACM 1985).
a61af66fc99e Initial load
duke
parents:
diff changeset
689 // The simplifications are the following:
a61af66fc99e Initial load
duke
parents:
diff changeset
690 // . we splay only when we delete (not when we insert)
a61af66fc99e Initial load
duke
parents:
diff changeset
691 // . we apply a single spay step per deletion/access
a61af66fc99e Initial load
duke
parents:
diff changeset
692 // By doing such partial splaying, we reduce the amount of restructuring,
a61af66fc99e Initial load
duke
parents:
diff changeset
693 // while getting a reasonably efficient search tree (we think).
a61af66fc99e Initial load
duke
parents:
diff changeset
694 // [Measurements will be needed to (in)validate this expectation.]
a61af66fc99e Initial load
duke
parents:
diff changeset
695
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
696 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
697 void BinaryTreeDictionary<Chunk>::semi_splay_step(TreeList<Chunk>* tc) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
698 // apply a semi-splay step at the given node:
a61af66fc99e Initial load
duke
parents:
diff changeset
699 // . if root, norting needs to be done
a61af66fc99e Initial load
duke
parents:
diff changeset
700 // . if child of root, splay once
a61af66fc99e Initial load
duke
parents:
diff changeset
701 // . else zig-zig or sig-zag depending on path from grandparent
a61af66fc99e Initial load
duke
parents:
diff changeset
702 if (root() == tc) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
703 warning("*** Splaying not yet implemented; "
a61af66fc99e Initial load
duke
parents:
diff changeset
704 "tree operations may be inefficient ***");
a61af66fc99e Initial load
duke
parents:
diff changeset
705 }
a61af66fc99e Initial load
duke
parents:
diff changeset
706
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
707 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
708 void BinaryTreeDictionary<Chunk>::insert_chunk_in_tree(Chunk* fc) {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
709 TreeList<Chunk> *curTL, *prevTL;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
710 size_t size = fc->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
711
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
712 assert(size >= BinaryTreeDictionary<Chunk>::min_tree_chunk_size, "too small to be a TreeList<Chunk>");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
713 if (FLSVerifyDictionary) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
714 verify_tree();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
715 }
a61af66fc99e Initial load
duke
parents:
diff changeset
716
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
717 fc->clear_next();
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
718 fc->link_prev(NULL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
719
a61af66fc99e Initial load
duke
parents:
diff changeset
720 // work down from the _root, looking for insertion point
a61af66fc99e Initial load
duke
parents:
diff changeset
721 for (prevTL = curTL = root(); curTL != NULL;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
722 if (curTL->size() == size) // exact match
a61af66fc99e Initial load
duke
parents:
diff changeset
723 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
724 prevTL = curTL;
a61af66fc99e Initial load
duke
parents:
diff changeset
725 if (curTL->size() > size) { // follow left branch
a61af66fc99e Initial load
duke
parents:
diff changeset
726 curTL = curTL->left();
a61af66fc99e Initial load
duke
parents:
diff changeset
727 } else { // follow right branch
a61af66fc99e Initial load
duke
parents:
diff changeset
728 assert(curTL->size() < size, "size inconsistency");
a61af66fc99e Initial load
duke
parents:
diff changeset
729 curTL = curTL->right();
a61af66fc99e Initial load
duke
parents:
diff changeset
730 }
a61af66fc99e Initial load
duke
parents:
diff changeset
731 }
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
732 TreeChunk<Chunk>* tc = TreeChunk<Chunk>::as_TreeChunk(fc);
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
733 // This chunk is being returned to the binary tree. Its embedded
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
734 // TreeList<Chunk> should be unused at this point.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
735 tc->initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
736 if (curTL != NULL) { // exact match
a61af66fc99e Initial load
duke
parents:
diff changeset
737 tc->set_list(curTL);
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
738 curTL->return_chunk_at_tail(tc);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
739 } else { // need a new node in tree
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
740 tc->clear_next();
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
741 tc->link_prev(NULL);
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
742 TreeList<Chunk>* newTL = TreeList<Chunk>::as_TreeList(tc);
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
743 assert(((TreeChunk<Chunk>*)tc)->list() == newTL,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
744 "List was not initialized correctly");
a61af66fc99e Initial load
duke
parents:
diff changeset
745 if (prevTL == NULL) { // we are the only tree node
a61af66fc99e Initial load
duke
parents:
diff changeset
746 assert(root() == NULL, "control point invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
747 set_root(newTL);
a61af66fc99e Initial load
duke
parents:
diff changeset
748 } else { // insert under prevTL ...
a61af66fc99e Initial load
duke
parents:
diff changeset
749 if (prevTL->size() < size) { // am right child
a61af66fc99e Initial load
duke
parents:
diff changeset
750 assert(prevTL->right() == NULL, "control point invariant");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
751 prevTL->set_right(newTL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
752 } else { // am left child
a61af66fc99e Initial load
duke
parents:
diff changeset
753 assert(prevTL->size() > size && prevTL->left() == NULL, "cpt pt inv");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
754 prevTL->set_left(newTL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
755 }
a61af66fc99e Initial load
duke
parents:
diff changeset
756 }
a61af66fc99e Initial load
duke
parents:
diff changeset
757 }
a61af66fc99e Initial load
duke
parents:
diff changeset
758 assert(tc->list() != NULL, "Tree list should be set");
a61af66fc99e Initial load
duke
parents:
diff changeset
759
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
760 inc_total_size(size);
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
761 // Method 'total_size_in_tree' walks through the every block in the
0
a61af66fc99e Initial load
duke
parents:
diff changeset
762 // tree, so it can cause significant performance loss if there are
a61af66fc99e Initial load
duke
parents:
diff changeset
763 // many blocks in the tree
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
764 assert(!FLSVerifyDictionary || total_size_in_tree(root()) == total_size(), "_total_size inconsistency");
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
765 set_total_free_blocks(total_free_blocks() + 1);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
766 if (FLSVerifyDictionary) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
767 verify_tree();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
768 }
a61af66fc99e Initial load
duke
parents:
diff changeset
769 }
a61af66fc99e Initial load
duke
parents:
diff changeset
770
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
771 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
772 size_t BinaryTreeDictionary<Chunk>::max_chunk_size() const {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
773 FreeBlockDictionary<Chunk>::verify_par_locked();
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
774 TreeList<Chunk>* tc = root();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
775 if (tc == NULL) return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
776 for (; tc->right() != NULL; tc = tc->right());
a61af66fc99e Initial load
duke
parents:
diff changeset
777 return tc->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
778 }
a61af66fc99e Initial load
duke
parents:
diff changeset
779
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
780 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
781 size_t BinaryTreeDictionary<Chunk>::total_list_length(TreeList<Chunk>* tl) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
782 size_t res;
a61af66fc99e Initial load
duke
parents:
diff changeset
783 res = tl->count();
a61af66fc99e Initial load
duke
parents:
diff changeset
784 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
785 size_t cnt;
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
786 Chunk* tc = tl->head();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
787 for (cnt = 0; tc != NULL; tc = tc->next(), cnt++);
a61af66fc99e Initial load
duke
parents:
diff changeset
788 assert(res == cnt, "The count is not being maintained correctly");
a61af66fc99e Initial load
duke
parents:
diff changeset
789 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
790 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
791 }
a61af66fc99e Initial load
duke
parents:
diff changeset
792
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
793 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
794 size_t BinaryTreeDictionary<Chunk>::total_size_in_tree(TreeList<Chunk>* tl) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
795 if (tl == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
796 return 0;
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
797 return (tl->size() * total_list_length(tl)) +
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
798 total_size_in_tree(tl->left()) +
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
799 total_size_in_tree(tl->right());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
800 }
a61af66fc99e Initial load
duke
parents:
diff changeset
801
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
802 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
803 double BinaryTreeDictionary<Chunk>::sum_of_squared_block_sizes(TreeList<Chunk>* const tl) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
804 if (tl == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
805 return 0.0;
a61af66fc99e Initial load
duke
parents:
diff changeset
806 }
a61af66fc99e Initial load
duke
parents:
diff changeset
807 double size = (double)(tl->size());
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
808 double curr = size * size * total_list_length(tl);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
809 curr += sum_of_squared_block_sizes(tl->left());
a61af66fc99e Initial load
duke
parents:
diff changeset
810 curr += sum_of_squared_block_sizes(tl->right());
a61af66fc99e Initial load
duke
parents:
diff changeset
811 return curr;
a61af66fc99e Initial load
duke
parents:
diff changeset
812 }
a61af66fc99e Initial load
duke
parents:
diff changeset
813
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
814 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
815 size_t BinaryTreeDictionary<Chunk>::total_free_blocks_in_tree(TreeList<Chunk>* tl) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
816 if (tl == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
817 return 0;
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
818 return total_list_length(tl) +
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
819 total_free_blocks_in_tree(tl->left()) +
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
820 total_free_blocks_in_tree(tl->right());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
821 }
a61af66fc99e Initial load
duke
parents:
diff changeset
822
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
823 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
824 size_t BinaryTreeDictionary<Chunk>::num_free_blocks() const {
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
825 assert(total_free_blocks_in_tree(root()) == total_free_blocks(),
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
826 "_total_free_blocks inconsistency");
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
827 return total_free_blocks();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
828 }
a61af66fc99e Initial load
duke
parents:
diff changeset
829
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
830 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
831 size_t BinaryTreeDictionary<Chunk>::tree_height_helper(TreeList<Chunk>* tl) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
832 if (tl == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
833 return 0;
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
834 return 1 + MAX2(tree_height_helper(tl->left()),
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
835 tree_height_helper(tl->right()));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
836 }
a61af66fc99e Initial load
duke
parents:
diff changeset
837
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
838 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
839 size_t BinaryTreeDictionary<Chunk>::treeHeight() const {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
840 return tree_height_helper(root());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
841 }
a61af66fc99e Initial load
duke
parents:
diff changeset
842
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
843 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
844 size_t BinaryTreeDictionary<Chunk>::total_nodes_helper(TreeList<Chunk>* tl) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
845 if (tl == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
846 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
847 }
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
848 return 1 + total_nodes_helper(tl->left()) +
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
849 total_nodes_helper(tl->right());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
850 }
a61af66fc99e Initial load
duke
parents:
diff changeset
851
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
852 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
853 size_t BinaryTreeDictionary<Chunk>::total_nodes_in_tree(TreeList<Chunk>* tl) const {
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
854 return total_nodes_helper(root());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
855 }
a61af66fc99e Initial load
duke
parents:
diff changeset
856
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
857 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
858 void BinaryTreeDictionary<Chunk>::dict_census_udpate(size_t size, bool split, bool birth){
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
859 TreeList<Chunk>* nd = find_list(size);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
860 if (nd) {
a61af66fc99e Initial load
duke
parents:
diff changeset
861 if (split) {
a61af66fc99e Initial load
duke
parents:
diff changeset
862 if (birth) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
863 nd->increment_split_births();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
864 nd->increment_surplus();
a61af66fc99e Initial load
duke
parents:
diff changeset
865 } else {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
866 nd->increment_split_deaths();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
867 nd->decrement_surplus();
a61af66fc99e Initial load
duke
parents:
diff changeset
868 }
a61af66fc99e Initial load
duke
parents:
diff changeset
869 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
870 if (birth) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
871 nd->increment_coal_births();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
872 nd->increment_surplus();
a61af66fc99e Initial load
duke
parents:
diff changeset
873 } else {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
874 nd->increment_coal_deaths();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
875 nd->decrement_surplus();
a61af66fc99e Initial load
duke
parents:
diff changeset
876 }
a61af66fc99e Initial load
duke
parents:
diff changeset
877 }
a61af66fc99e Initial load
duke
parents:
diff changeset
878 }
a61af66fc99e Initial load
duke
parents:
diff changeset
879 // A list for this size may not be found (nd == 0) if
a61af66fc99e Initial load
duke
parents:
diff changeset
880 // This is a death where the appropriate list is now
a61af66fc99e Initial load
duke
parents:
diff changeset
881 // empty and has been removed from the list.
a61af66fc99e Initial load
duke
parents:
diff changeset
882 // This is a birth associated with a LinAB. The chunk
a61af66fc99e Initial load
duke
parents:
diff changeset
883 // for the LinAB is not in the dictionary.
a61af66fc99e Initial load
duke
parents:
diff changeset
884 }
a61af66fc99e Initial load
duke
parents:
diff changeset
885
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
886 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
887 bool BinaryTreeDictionary<Chunk>::coal_dict_over_populated(size_t size) {
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
888 if (FLSAlwaysCoalesceLarge) return true;
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
889
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
890 TreeList<Chunk>* list_of_size = find_list(size);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
891 // None of requested size implies overpopulated.
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
892 return list_of_size == NULL || list_of_size->coal_desired() <= 0 ||
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
893 list_of_size->count() > list_of_size->coal_desired();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
894 }
a61af66fc99e Initial load
duke
parents:
diff changeset
895
a61af66fc99e Initial load
duke
parents:
diff changeset
896 // Closures for walking the binary tree.
a61af66fc99e Initial load
duke
parents:
diff changeset
897 // do_list() walks the free list in a node applying the closure
a61af66fc99e Initial load
duke
parents:
diff changeset
898 // to each free chunk in the list
a61af66fc99e Initial load
duke
parents:
diff changeset
899 // do_tree() walks the nodes in the binary tree applying do_list()
a61af66fc99e Initial load
duke
parents:
diff changeset
900 // to each list at each node.
a61af66fc99e Initial load
duke
parents:
diff changeset
901
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
902 template <class Chunk>
0
a61af66fc99e Initial load
duke
parents:
diff changeset
903 class TreeCensusClosure : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
904 protected:
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
905 virtual void do_list(FreeList<Chunk>* fl) = 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
906 public:
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
907 virtual void do_tree(TreeList<Chunk>* tl) = 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
908 };
a61af66fc99e Initial load
duke
parents:
diff changeset
909
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
910 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
911 class AscendTreeCensusClosure : public TreeCensusClosure<Chunk> {
6119
a297b0e14605 7172226: HotSpot fails to build with GCC 4.7 because of stricter c++ argument dependent lookup
mgerdin
parents: 6028
diff changeset
912 using TreeCensusClosure<Chunk>::do_list;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
913 public:
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
914 void do_tree(TreeList<Chunk>* tl) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
915 if (tl != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
916 do_tree(tl->left());
a61af66fc99e Initial load
duke
parents:
diff changeset
917 do_list(tl);
a61af66fc99e Initial load
duke
parents:
diff changeset
918 do_tree(tl->right());
a61af66fc99e Initial load
duke
parents:
diff changeset
919 }
a61af66fc99e Initial load
duke
parents:
diff changeset
920 }
a61af66fc99e Initial load
duke
parents:
diff changeset
921 };
a61af66fc99e Initial load
duke
parents:
diff changeset
922
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
923 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
924 class DescendTreeCensusClosure : public TreeCensusClosure<Chunk> {
6119
a297b0e14605 7172226: HotSpot fails to build with GCC 4.7 because of stricter c++ argument dependent lookup
mgerdin
parents: 6028
diff changeset
925 using TreeCensusClosure<Chunk>::do_list;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
926 public:
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
927 void do_tree(TreeList<Chunk>* tl) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
928 if (tl != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
929 do_tree(tl->right());
a61af66fc99e Initial load
duke
parents:
diff changeset
930 do_list(tl);
a61af66fc99e Initial load
duke
parents:
diff changeset
931 do_tree(tl->left());
a61af66fc99e Initial load
duke
parents:
diff changeset
932 }
a61af66fc99e Initial load
duke
parents:
diff changeset
933 }
a61af66fc99e Initial load
duke
parents:
diff changeset
934 };
a61af66fc99e Initial load
duke
parents:
diff changeset
935
a61af66fc99e Initial load
duke
parents:
diff changeset
936 // For each list in the tree, calculate the desired, desired
a61af66fc99e Initial load
duke
parents:
diff changeset
937 // coalesce, count before sweep, and surplus before sweep.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
938 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
939 class BeginSweepClosure : public AscendTreeCensusClosure<Chunk> {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
940 double _percentage;
a61af66fc99e Initial load
duke
parents:
diff changeset
941 float _inter_sweep_current;
a61af66fc99e Initial load
duke
parents:
diff changeset
942 float _inter_sweep_estimate;
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
943 float _intra_sweep_estimate;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
944
a61af66fc99e Initial load
duke
parents:
diff changeset
945 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
946 BeginSweepClosure(double p, float inter_sweep_current,
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
947 float inter_sweep_estimate,
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
948 float intra_sweep_estimate) :
0
a61af66fc99e Initial load
duke
parents:
diff changeset
949 _percentage(p),
a61af66fc99e Initial load
duke
parents:
diff changeset
950 _inter_sweep_current(inter_sweep_current),
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
951 _inter_sweep_estimate(inter_sweep_estimate),
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
952 _intra_sweep_estimate(intra_sweep_estimate) { }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
953
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
954 void do_list(FreeList<Chunk>* fl) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
955 double coalSurplusPercent = _percentage;
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
956 fl->compute_desired(_inter_sweep_current, _inter_sweep_estimate, _intra_sweep_estimate);
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
957 fl->set_coal_desired((ssize_t)((double)fl->desired() * coalSurplusPercent));
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
958 fl->set_before_sweep(fl->count());
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
959 fl->set_bfr_surp(fl->surplus());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
960 }
a61af66fc99e Initial load
duke
parents:
diff changeset
961 };
a61af66fc99e Initial load
duke
parents:
diff changeset
962
a61af66fc99e Initial load
duke
parents:
diff changeset
963 // Used to search the tree until a condition is met.
a61af66fc99e Initial load
duke
parents:
diff changeset
964 // Similar to TreeCensusClosure but searches the
a61af66fc99e Initial load
duke
parents:
diff changeset
965 // tree and returns promptly when found.
a61af66fc99e Initial load
duke
parents:
diff changeset
966
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
967 template <class Chunk>
0
a61af66fc99e Initial load
duke
parents:
diff changeset
968 class TreeSearchClosure : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
969 protected:
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
970 virtual bool do_list(FreeList<Chunk>* fl) = 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
971 public:
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
972 virtual bool do_tree(TreeList<Chunk>* tl) = 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
973 };
a61af66fc99e Initial load
duke
parents:
diff changeset
974
a61af66fc99e Initial load
duke
parents:
diff changeset
975 #if 0 // Don't need this yet but here for symmetry.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
976 template <class Chunk>
0
a61af66fc99e Initial load
duke
parents:
diff changeset
977 class AscendTreeSearchClosure : public TreeSearchClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
978 public:
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
979 bool do_tree(TreeList<Chunk>* tl) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
980 if (tl != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
981 if (do_tree(tl->left())) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
982 if (do_list(tl)) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
983 if (do_tree(tl->right())) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
984 }
a61af66fc99e Initial load
duke
parents:
diff changeset
985 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
986 }
a61af66fc99e Initial load
duke
parents:
diff changeset
987 };
a61af66fc99e Initial load
duke
parents:
diff changeset
988 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
989
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
990 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
991 class DescendTreeSearchClosure : public TreeSearchClosure<Chunk> {
6119
a297b0e14605 7172226: HotSpot fails to build with GCC 4.7 because of stricter c++ argument dependent lookup
mgerdin
parents: 6028
diff changeset
992 using TreeSearchClosure<Chunk>::do_list;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
993 public:
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
994 bool do_tree(TreeList<Chunk>* tl) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
995 if (tl != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
996 if (do_tree(tl->right())) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
997 if (do_list(tl)) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
998 if (do_tree(tl->left())) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
999 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1003
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 // Searches the tree for a chunk that ends at the
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 // specified address.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1006 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1007 class EndTreeSearchClosure : public DescendTreeSearchClosure<Chunk> {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 HeapWord* _target;
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1009 Chunk* _found;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1010
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 EndTreeSearchClosure(HeapWord* target) : _target(target), _found(NULL) {}
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1013 bool do_list(FreeList<Chunk>* fl) {
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1014 Chunk* item = fl->head();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 while (item != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 if (item->end() == _target) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 _found = item;
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 item = item->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 }
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1024 Chunk* found() { return _found; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1026
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1027 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1028 Chunk* BinaryTreeDictionary<Chunk>::find_chunk_ends_at(HeapWord* target) const {
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1029 EndTreeSearchClosure<Chunk> etsc(target);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 bool found_target = etsc.do_tree(root());
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 assert(found_target || etsc.found() == NULL, "Consistency check");
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 assert(!found_target || etsc.found() != NULL, "Consistency check");
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 return etsc.found();
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1035
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1036 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1037 void BinaryTreeDictionary<Chunk>::begin_sweep_dict_census(double coalSurplusPercent,
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1038 float inter_sweep_current, float inter_sweep_estimate, float intra_sweep_estimate) {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1039 BeginSweepClosure<Chunk> bsc(coalSurplusPercent, inter_sweep_current,
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1040 inter_sweep_estimate,
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1041 intra_sweep_estimate);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 bsc.do_tree(root());
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1044
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 // Closures and methods for calculating total bytes returned to the
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 // free lists in the tree.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1047 #ifndef PRODUCT
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1048 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1049 class InitializeDictReturnedBytesClosure : public AscendTreeCensusClosure<Chunk> {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 public:
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1051 void do_list(FreeList<Chunk>* fl) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1052 fl->set_returned_bytes(0);
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1053 }
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1054 };
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1055
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1056 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1057 void BinaryTreeDictionary<Chunk>::initialize_dict_returned_bytes() {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1058 InitializeDictReturnedBytesClosure<Chunk> idrb;
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1059 idrb.do_tree(root());
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1060 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1061
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1062 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1063 class ReturnedBytesClosure : public AscendTreeCensusClosure<Chunk> {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1064 size_t _dict_returned_bytes;
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1065 public:
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1066 ReturnedBytesClosure() { _dict_returned_bytes = 0; }
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1067 void do_list(FreeList<Chunk>* fl) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1068 _dict_returned_bytes += fl->returned_bytes();
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1069 }
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1070 size_t dict_returned_bytes() { return _dict_returned_bytes; }
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1071 };
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1072
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1073 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1074 size_t BinaryTreeDictionary<Chunk>::sum_dict_returned_bytes() {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1075 ReturnedBytesClosure<Chunk> rbc;
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1076 rbc.do_tree(root());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1077
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1078 return rbc.dict_returned_bytes();
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1079 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1080
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1081 // Count the number of entries in the tree.
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1082 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1083 class treeCountClosure : public DescendTreeCensusClosure<Chunk> {
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1084 public:
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1085 uint count;
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1086 treeCountClosure(uint c) { count = c; }
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1087 void do_list(FreeList<Chunk>* fl) {
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1088 count++;
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1089 }
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1090 };
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1091
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1092 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1093 size_t BinaryTreeDictionary<Chunk>::total_count() {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1094 treeCountClosure<Chunk> ctc(0);
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1095 ctc.do_tree(root());
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1096 return ctc.count;
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1097 }
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1098 #endif // PRODUCT
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1099
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 // Calculate surpluses for the lists in the tree.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1101 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1102 class setTreeSurplusClosure : public AscendTreeCensusClosure<Chunk> {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 double percentage;
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 setTreeSurplusClosure(double v) { percentage = v; }
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1106 void do_list(FreeList<Chunk>* fl) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 double splitSurplusPercent = percentage;
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 fl->set_surplus(fl->count() -
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 (ssize_t)((double)fl->desired() * splitSurplusPercent));
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1112
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1113 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1114 void BinaryTreeDictionary<Chunk>::set_tree_surplus(double splitSurplusPercent) {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1115 setTreeSurplusClosure<Chunk> sts(splitSurplusPercent);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 sts.do_tree(root());
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1118
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 // Set hints for the lists in the tree.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1120 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1121 class setTreeHintsClosure : public DescendTreeCensusClosure<Chunk> {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 size_t hint;
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 setTreeHintsClosure(size_t v) { hint = v; }
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1125 void do_list(FreeList<Chunk>* fl) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 fl->set_hint(hint);
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 assert(fl->hint() == 0 || fl->hint() > fl->size(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 "Current hint is inconsistent");
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 if (fl->surplus() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 hint = fl->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1134
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1135 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1136 void BinaryTreeDictionary<Chunk>::set_tree_hints(void) {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1137 setTreeHintsClosure<Chunk> sth(0);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 sth.do_tree(root());
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1140
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 // Save count before previous sweep and splits and coalesces.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1142 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1143 class clearTreeCensusClosure : public AscendTreeCensusClosure<Chunk> {
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1144 void do_list(FreeList<Chunk>* fl) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1145 fl->set_prev_sweep(fl->count());
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1146 fl->set_coal_births(0);
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1147 fl->set_coal_deaths(0);
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1148 fl->set_split_births(0);
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1149 fl->set_split_deaths(0);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1151 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1152
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1153 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1154 void BinaryTreeDictionary<Chunk>::clear_tree_census(void) {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1155 clearTreeCensusClosure<Chunk> ctc;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 ctc.do_tree(root());
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1158
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 // Do reporting and post sweep clean up.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1160 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1161 void BinaryTreeDictionary<Chunk>::end_sweep_dict_census(double splitSurplusPercent) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 // Does walking the tree 3 times hurt?
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1163 set_tree_surplus(splitSurplusPercent);
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1164 set_tree_hints();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1165 if (PrintGC && Verbose) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1166 report_statistics();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 }
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1168 clear_tree_census();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1170
a61af66fc99e Initial load
duke
parents:
diff changeset
1171 // Print summary statistics
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1172 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1173 void BinaryTreeDictionary<Chunk>::report_statistics() const {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1174 FreeBlockDictionary<Chunk>::verify_par_locked();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 gclog_or_tty->print("Statistics for BinaryTreeDictionary:\n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 "------------------------------------\n");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1177 size_t total_size = total_chunk_size(debug_only(NULL));
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1178 size_t free_blocks = num_free_blocks();
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1179 gclog_or_tty->print("Total Free Space: %d\n", total_size);
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1180 gclog_or_tty->print("Max Chunk Size: %d\n", max_chunk_size());
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1181 gclog_or_tty->print("Number of Blocks: %d\n", free_blocks);
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1182 if (free_blocks > 0) {
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1183 gclog_or_tty->print("Av. Block Size: %d\n", total_size/free_blocks);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 gclog_or_tty->print("Tree Height: %d\n", treeHeight());
a61af66fc99e Initial load
duke
parents:
diff changeset
1186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1187
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 // Print census information - counts, births, deaths, etc.
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 // for each list in the tree. Also print some summary
a61af66fc99e Initial load
duke
parents:
diff changeset
1190 // information.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1191 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1192 class PrintTreeCensusClosure : public AscendTreeCensusClosure<Chunk> {
12
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
1193 int _print_line;
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1194 size_t _total_free;
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1195 FreeList<Chunk> _total;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1196
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 public:
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1198 PrintTreeCensusClosure() {
12
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
1199 _print_line = 0;
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1200 _total_free = 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 }
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1202 FreeList<Chunk>* total() { return &_total; }
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1203 size_t total_free() { return _total_free; }
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1204 void do_list(FreeList<Chunk>* fl) {
12
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
1205 if (++_print_line >= 40) {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1206 FreeList<Chunk>::print_labels_on(gclog_or_tty, "size");
12
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
1207 _print_line = 0;
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
1208 }
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
1209 fl->print_on(gclog_or_tty);
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1210 _total_free += fl->count() * fl->size() ;
12
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
1211 total()->set_count( total()->count() + fl->count() );
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1212 total()->set_bfr_surp( total()->bfr_surp() + fl->bfr_surp() );
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1213 total()->set_surplus( total()->split_deaths() + fl->surplus() );
12
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
1214 total()->set_desired( total()->desired() + fl->desired() );
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1215 total()->set_prev_sweep( total()->prev_sweep() + fl->prev_sweep() );
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1216 total()->set_before_sweep(total()->before_sweep() + fl->before_sweep());
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1217 total()->set_coal_births( total()->coal_births() + fl->coal_births() );
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1218 total()->set_coal_deaths( total()->coal_deaths() + fl->coal_deaths() );
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1219 total()->set_split_births(total()->split_births() + fl->split_births());
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1220 total()->set_split_deaths(total()->split_deaths() + fl->split_deaths());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1223
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1224 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1225 void BinaryTreeDictionary<Chunk>::print_dict_census(void) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1226
a61af66fc99e Initial load
duke
parents:
diff changeset
1227 gclog_or_tty->print("\nBinaryTree\n");
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1228 FreeList<Chunk>::print_labels_on(gclog_or_tty, "size");
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1229 PrintTreeCensusClosure<Chunk> ptc;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1230 ptc.do_tree(root());
a61af66fc99e Initial load
duke
parents:
diff changeset
1231
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1232 FreeList<Chunk>* total = ptc.total();
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1233 FreeList<Chunk>::print_labels_on(gclog_or_tty, " ");
12
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
1234 total->print_on(gclog_or_tty, "TOTAL\t");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1235 gclog_or_tty->print(
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1236 "total_free(words): " SIZE_FORMAT_W(16)
12
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
1237 " growth: %8.5f deficit: %8.5f\n",
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1238 ptc.total_free(),
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1239 (double)(total->split_births() + total->coal_births()
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1240 - total->split_deaths() - total->coal_deaths())
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1241 /(total->prev_sweep() != 0 ? (double)total->prev_sweep() : 1.0),
12
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
1242 (double)(total->desired() - total->count())
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
1243 /(total->desired() != 0 ? (double)total->desired() : 1.0));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1244 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1245
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1246 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1247 class PrintFreeListsClosure : public AscendTreeCensusClosure<Chunk> {
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1248 outputStream* _st;
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1249 int _print_line;
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1250
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1251 public:
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1252 PrintFreeListsClosure(outputStream* st) {
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1253 _st = st;
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1254 _print_line = 0;
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1255 }
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1256 void do_list(FreeList<Chunk>* fl) {
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1257 if (++_print_line >= 40) {
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1258 FreeList<Chunk>::print_labels_on(_st, "size");
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1259 _print_line = 0;
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1260 }
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1261 fl->print_on(gclog_or_tty);
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1262 size_t sz = fl->size();
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1263 for (Chunk* fc = fl->head(); fc != NULL;
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1264 fc = fc->next()) {
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1265 _st->print_cr("\t[" PTR_FORMAT "," PTR_FORMAT ") %s",
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1266 fc, (HeapWord*)fc + sz,
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1267 fc->cantCoalesce() ? "\t CC" : "");
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1268 }
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1269 }
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1270 };
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1271
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1272 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1273 void BinaryTreeDictionary<Chunk>::print_free_lists(outputStream* st) const {
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1274
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1275 FreeList<Chunk>::print_labels_on(st, "size");
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1276 PrintFreeListsClosure<Chunk> pflc(st);
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1277 pflc.do_tree(root());
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1278 }
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 269
diff changeset
1279
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1280 // Verify the following tree invariants:
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 // . _root has no parent
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 // . parent and child point to each other
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 // . each node's key correctly related to that of its child(ren)
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1284 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1285 void BinaryTreeDictionary<Chunk>::verify_tree() const {
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1286 guarantee(root() == NULL || total_free_blocks() == 0 ||
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1287 total_size() != 0, "_total_size should't be 0?");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 guarantee(root() == NULL || root()->parent() == NULL, "_root shouldn't have parent");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1289 verify_tree_helper(root());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1290 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1291
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1292 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1293 size_t BinaryTreeDictionary<Chunk>::verify_prev_free_ptrs(TreeList<Chunk>* tl) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1294 size_t ct = 0;
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1295 for (Chunk* curFC = tl->head(); curFC != NULL; curFC = curFC->next()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 ct++;
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1297 assert(curFC->prev() == NULL || curFC->prev()->is_free(),
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1298 "Chunk should be free");
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1300 return ct;
a61af66fc99e Initial load
duke
parents:
diff changeset
1301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1302
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 // Note: this helper is recursive rather than iterative, so use with
a61af66fc99e Initial load
duke
parents:
diff changeset
1304 // caution on very deep trees; and watch out for stack overflow errors;
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 // In general, to be used only for debugging.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1306 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1307 void BinaryTreeDictionary<Chunk>::verify_tree_helper(TreeList<Chunk>* tl) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1308 if (tl == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1309 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 guarantee(tl->size() != 0, "A list must has a size");
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 guarantee(tl->left() == NULL || tl->left()->parent() == tl,
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 "parent<-/->left");
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 guarantee(tl->right() == NULL || tl->right()->parent() == tl,
a61af66fc99e Initial load
duke
parents:
diff changeset
1314 "parent<-/->right");;
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 guarantee(tl->left() == NULL || tl->left()->size() < tl->size(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1316 "parent !> left");
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 guarantee(tl->right() == NULL || tl->right()->size() > tl->size(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1318 "parent !< left");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1319 guarantee(tl->head() == NULL || tl->head()->is_free(), "!Free");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1320 guarantee(tl->head() == NULL || tl->head_as_TreeChunk()->list() == tl,
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 "list inconsistency");
a61af66fc99e Initial load
duke
parents:
diff changeset
1322 guarantee(tl->count() > 0 || (tl->head() == NULL && tl->tail() == NULL),
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 "list count is inconsistent");
a61af66fc99e Initial load
duke
parents:
diff changeset
1324 guarantee(tl->count() > 1 || tl->head() == tl->tail(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 "list is incorrectly constructed");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1326 size_t count = verify_prev_free_ptrs(tl);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 guarantee(count == (size_t)tl->count(), "Node count is incorrect");
a61af66fc99e Initial load
duke
parents:
diff changeset
1328 if (tl->head() != NULL) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1329 tl->head_as_TreeChunk()->verify_tree_chunk_list();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1330 }
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1331 verify_tree_helper(tl->left());
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1332 verify_tree_helper(tl->right());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1334
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1335 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1336 void BinaryTreeDictionary<Chunk>::verify() const {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1337 verify_tree();
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
1338 guarantee(total_size() == total_size_in_tree(root()), "Total Size inconsistency");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 }
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1340
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1341 #ifndef SERIALGC
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1342 // Explicitly instantiate these types for FreeChunk.
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1343 template class BinaryTreeDictionary<FreeChunk>;
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1344 template class TreeChunk<FreeChunk>;
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1345 template class TreeList<FreeChunk>;
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
1346 #endif // SERIALGC