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