src/share/vm/memory/binaryTreeDictionary.cpp

Mon, 04 Jun 2012 09:21:53 +0200

author
mgerdin
date
Mon, 04 Jun 2012 09:21:53 +0200
changeset 3822
a297b0e14605
parent 3732
f69a5d43dc19
child 4196
685df3c6f84b
permissions
-rw-r--r--

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

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

mercurial