src/hotspot/share/memory/binaryTreeDictionary.inline.hpp
author stuefe
Tue, 26 Nov 2019 16:21:29 +0100
branchstuefe-new-metaspace-branch
changeset 59272 54750b448264
parent 53547 9d1a788dea3d
permissions -rw-r--r--
Metadatatype back to metaspace.hpp to reduce patch size
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52767
diff changeset
     2
 * Copyright (c) 2001, 2019, 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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52767
diff changeset
    25
#ifndef SHARE_MEMORY_BINARYTREEDICTIONARY_INLINE_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52767
diff changeset
    26
#define SHARE_MEMORY_BINARYTREEDICTIONARY_INLINE_HPP
49708
6709f13dccd3 8200735: Move CMS specific code from binaryTreeDictionary and freeList to CMS files
stefank
parents: 47216
diff changeset
    27
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 27684
diff changeset
    28
#include "gc/shared/spaceDecorator.hpp"
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
    29
#include "logging/log.hpp"
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46674
diff changeset
    30
#include "logging/logStream.hpp"
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
    31
#include "memory/binaryTreeDictionary.hpp"
49708
6709f13dccd3 8200735: Move CMS specific code from binaryTreeDictionary and freeList to CMS files
stefank
parents: 47216
diff changeset
    32
#include "memory/freeList.inline.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
    33
#include "memory/resourceArea.hpp"
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49708
diff changeset
    34
#include "runtime/mutex.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6447
diff changeset
    35
#include "runtime/globals.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 27684
diff changeset
    36
#include "utilities/macros.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6447
diff changeset
    37
#include "utilities/ostream.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
////////////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// A binary tree based search structure for free blocks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// This is currently used in the Concurrent Mark&Sweep implementation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
////////////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
    44
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    45
TreeChunk<Chunk_t, FreeList_t>* TreeChunk<Chunk_t, FreeList_t>::as_TreeChunk(Chunk_t* fc) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // Do some assertion checking here.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    47
  return (TreeChunk<Chunk_t, FreeList_t>*) fc;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
    50
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    51
void TreeChunk<Chunk_t, FreeList_t>::verify_tree_chunk_list() const {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    52
  TreeChunk<Chunk_t, FreeList_t>* nextTC = (TreeChunk<Chunk_t, FreeList_t>*)next();
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 20729
diff changeset
    53
  if (prev() != NULL) { // interior list node shouldn't have tree fields
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    guarantee(embedded_list()->parent() == NULL && embedded_list()->left() == NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
              embedded_list()->right()  == NULL, "should be clear");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  if (nextTC != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    guarantee(as_TreeChunk(nextTC->prev()) == this, "broken chain");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    guarantee(nextTC->size() == size(), "wrong size");
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
    60
    nextTC->verify_tree_chunk_list();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
    64
template <class Chunk_t, class FreeList_t>
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14581
diff changeset
    65
TreeList<Chunk_t, FreeList_t>::TreeList() : _parent(NULL),
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14581
diff changeset
    66
  _left(NULL), _right(NULL) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
    68
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    69
TreeList<Chunk_t, FreeList_t>*
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    70
TreeList<Chunk_t, FreeList_t>::as_TreeList(TreeChunk<Chunk_t,FreeList_t>* tc) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // This first free chunk in the list will be the tree list.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    72
  assert((tc->size() >= (TreeChunk<Chunk_t, FreeList_t>::min_size())),
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    73
    "Chunk is too small for a TreeChunk");
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    74
  TreeList<Chunk_t, FreeList_t>* tl = tc->embedded_list();
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    75
  tl->initialize();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  tc->set_list(tl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  tl->set_size(tc->size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  tl->link_head(tc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  tl->link_tail(tc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  tl->set_count(1);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14581
diff changeset
    81
  assert(tl->parent() == NULL, "Should be clear");
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    82
  return tl;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    83
}
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    84
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
    85
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    86
TreeList<Chunk_t, FreeList_t>*
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    87
TreeList<Chunk_t, FreeList_t>::as_TreeList(HeapWord* addr, size_t size) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    88
  TreeChunk<Chunk_t, FreeList_t>* tc = (TreeChunk<Chunk_t, FreeList_t>*) addr;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    89
  assert((size >= TreeChunk<Chunk_t, FreeList_t>::min_size()),
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    90
    "Chunk is too small for a TreeChunk");
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    91
  // The space will have been mangled initially but
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    92
  // is not remangled when a Chunk_t is returned to the free list
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    93
  // (since it is used to maintain the chunk on the free list).
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    94
  tc->assert_is_mangled();
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    95
  tc->set_size(size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    96
  tc->link_prev(NULL);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    97
  tc->link_next(NULL);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
    98
  TreeList<Chunk_t, FreeList_t>* tl = TreeList<Chunk_t, FreeList_t>::as_TreeList(tc);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  return tl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
}
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   101
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   102
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   103
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   104
TreeList<Chunk_t, FreeList_t>*
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   105
TreeList<Chunk_t, FreeList_t>::get_better_list(
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   106
  BinaryTreeDictionary<Chunk_t, FreeList_t>* dictionary) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   107
  return this;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   110
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   111
TreeList<Chunk_t, FreeList_t>* TreeList<Chunk_t, FreeList_t>::remove_chunk_replace_if_needed(TreeChunk<Chunk_t, FreeList_t>* tc) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   113
  TreeList<Chunk_t, FreeList_t>* retTL = this;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   114
  Chunk_t* list = head();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  assert(!list || list != list->next(), "Chunk on list twice");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  assert(tc != NULL, "Chunk being removed is NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  assert(parent() == NULL || this == parent()->left() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    this == parent()->right(), "list is inconsistent");
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   119
  assert(tc->is_free(), "Header is not marked correctly");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  assert(head() == NULL || head()->prev() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  assert(tail() == NULL || tail()->next() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   123
  Chunk_t* prevFC = tc->prev();
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   124
  TreeChunk<Chunk_t, FreeList_t>* nextTC = TreeChunk<Chunk_t, FreeList_t>::as_TreeChunk(tc->next());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  assert(list != NULL, "should have at least the target chunk");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // Is this the first item on the list?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  if (tc == list) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   129
    // The "getChunk..." functions for a TreeList<Chunk_t, FreeList_t> will not return the
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    // first chunk in the list unless it is the last chunk in the list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    // because the first chunk is also acting as the tree node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    // When coalescing happens, however, the first chunk in the a tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    // list can be the start of a free range.  Free ranges are removed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    // from the free lists so that they are not available to be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    // allocated when the sweeper yields (giving up the free list lock)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    // to allow mutator activity.  If this chunk is the first in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    // list and is not the last in the list, do the work to copy the
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   138
    // TreeList<Chunk_t, FreeList_t> from the first chunk to the next chunk and update all
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   139
    // the TreeList<Chunk_t, FreeList_t> pointers in the chunks in the list.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    if (nextTC == NULL) {
5402
c51fd0c1d005 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 4574
diff changeset
   141
      assert(prevFC == NULL, "Not last chunk in the list");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      set_tail(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      set_head(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      // copy embedded list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      nextTC->set_embedded_list(tc->embedded_list());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      retTL = nextTC->embedded_list();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      // Fix the pointer to the list in each chunk in the list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      // This can be slow for a long list.  Consider having
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      // an option that does not allow the first chunk on the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      // list to be coalesced.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   152
      for (TreeChunk<Chunk_t, FreeList_t>* curTC = nextTC; curTC != NULL;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   153
          curTC = TreeChunk<Chunk_t, FreeList_t>::as_TreeChunk(curTC->next())) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
        curTC->set_list(retTL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   156
      // Fix the parent to point to the new TreeList<Chunk_t, FreeList_t>.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      if (retTL->parent() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
        if (this == retTL->parent()->left()) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   159
          retTL->parent()->set_left(retTL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
          assert(this == retTL->parent()->right(), "Parent is incorrect");
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   162
          retTL->parent()->set_right(retTL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
      // Fix the children's parent pointers to point to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      // new list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      assert(right() == retTL->right(), "Should have been copied");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
      if (retTL->right() != NULL) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   169
        retTL->right()->set_parent(retTL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      assert(left() == retTL->left(), "Should have been copied");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      if (retTL->left() != NULL) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   173
        retTL->left()->set_parent(retTL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      retTL->link_head(nextTC);
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   176
      assert(nextTC->is_free(), "Should be a free chunk");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    if (nextTC == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
      // Removing chunk at tail of list
14475
4c094dfbbb99 8003259: NPG: Build with gcc 4.7.2 broken by 7045397
coleenp
parents: 14123
diff changeset
   181
      this->link_tail(prevFC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    // Chunk is interior to the list
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   184
    prevFC->link_after(nextTC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 20729
diff changeset
   187
  // Below this point the embedded TreeList<Chunk_t, FreeList_t> being used for the
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  // tree node may have changed. Don't use "this"
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   189
  // TreeList<Chunk_t, FreeList_t>*.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  // chunk should still be a free chunk (bit set in _prev)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  assert(!retTL->head() || retTL->size() == retTL->head()->size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    "Wrong sized chunk in list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  debug_only(
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   194
    tc->link_prev(NULL);
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   195
    tc->link_next(NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    tc->set_list(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    bool prev_found = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    bool next_found = false;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   199
    for (Chunk_t* curFC = retTL->head();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
         curFC != NULL; curFC = curFC->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      assert(curFC != tc, "Chunk is still in list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      if (curFC == prevFC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
        prev_found = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
      if (curFC == nextTC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
        next_found = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    assert(prevFC == NULL || prev_found, "Chunk was lost from list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    assert(nextTC == NULL || next_found, "Chunk was lost from list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    assert(retTL->parent() == NULL ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
           retTL == retTL->parent()->left() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
           retTL == retTL->parent()->right(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
           "list is inconsistent");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  retTL->decrement_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   218
  assert(tc->is_free(), "Should still be a free chunk");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  assert(retTL->head() == NULL || retTL->head()->prev() == NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  assert(retTL->tail() == NULL || retTL->tail()->next() == NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  return retTL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
}
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   225
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   226
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   227
void TreeList<Chunk_t, FreeList_t>::return_chunk_at_tail(TreeChunk<Chunk_t, FreeList_t>* chunk) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  assert(chunk != NULL, "returning NULL chunk");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  assert(chunk->list() == this, "list should be set for chunk");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  assert(tail() != NULL, "The tree list is embedded in the first chunk");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  // which means that the list can never be empty.
52767
db7a459e10eb 8214356: Verification of class metadata unloading takes a long time
coleenp
parents: 50193
diff changeset
   232
  // This is expensive for metaspace
db7a459e10eb 8214356: Verification of class metadata unloading takes a long time
coleenp
parents: 50193
diff changeset
   233
  assert(!FLSVerifyDictionary || !this->verify_chunk_in_free_list(chunk), "Double entry");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  assert(head() == NULL || head()->prev() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  assert(tail() == NULL || tail()->next() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   237
  Chunk_t* fc = tail();
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   238
  fc->link_after(chunk);
14475
4c094dfbbb99 8003259: NPG: Build with gcc 4.7.2 broken by 7045397
coleenp
parents: 14123
diff changeset
   239
  this->link_tail(chunk);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  assert(!tail() || size() == tail()->size(), "Wrong sized chunk in list");
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   242
  FreeList_t::increment_count();
14581
8427edf5a77b 8003722: More gcc 4.7 compilation errors
coleenp
parents: 14475
diff changeset
   243
  debug_only(this->increment_returned_bytes_by(chunk->size()*sizeof(HeapWord));)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  assert(head() == NULL || head()->prev() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  assert(tail() == NULL || tail()->next() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   248
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   249
void TreeChunk<Chunk_t, FreeList_t>::assert_is_mangled() const {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   250
  assert((ZapUnusedHeapArea &&
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   251
          SpaceMangler::is_mangled((HeapWord*) Chunk_t::size_addr()) &&
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   252
          SpaceMangler::is_mangled((HeapWord*) Chunk_t::prev_addr()) &&
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   253
          SpaceMangler::is_mangled((HeapWord*) Chunk_t::next_addr())) ||
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   254
          (size() == 0 && prev() == NULL && next() == NULL),
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   255
    "Space should be clear or mangled");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   258
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   259
TreeChunk<Chunk_t, FreeList_t>* TreeList<Chunk_t, FreeList_t>::head_as_TreeChunk() {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   260
  assert(head() == NULL || (TreeChunk<Chunk_t, FreeList_t>::as_TreeChunk(head())->list() == this),
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   261
    "Wrong type of chunk?");
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   262
  return TreeChunk<Chunk_t, FreeList_t>::as_TreeChunk(head());
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   263
}
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   264
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   265
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   266
TreeChunk<Chunk_t, FreeList_t>* TreeList<Chunk_t, FreeList_t>::first_available() {
6447
32cc5cad7fa6 6983930: CMS: Various small cleanups ca September 2010
ysr
parents: 5547
diff changeset
   267
  assert(head() != NULL, "The head of the list cannot be NULL");
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   268
  Chunk_t* fc = head()->next();
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   269
  TreeChunk<Chunk_t, FreeList_t>* retTC;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  if (fc == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    retTC = head_as_TreeChunk();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  } else {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   273
    retTC = TreeChunk<Chunk_t, FreeList_t>::as_TreeChunk(fc);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  assert(retTC->list() == this, "Wrong type of chunk.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  return retTC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   279
// Returns the block with the largest heap address amongst
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   280
// those in the list for this size; potentially slow and expensive,
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   281
// use with caution!
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   282
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   283
TreeChunk<Chunk_t, FreeList_t>* TreeList<Chunk_t, FreeList_t>::largest_address() {
6447
32cc5cad7fa6 6983930: CMS: Various small cleanups ca September 2010
ysr
parents: 5547
diff changeset
   284
  assert(head() != NULL, "The head of the list cannot be NULL");
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   285
  Chunk_t* fc = head()->next();
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   286
  TreeChunk<Chunk_t, FreeList_t>* retTC;
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   287
  if (fc == NULL) {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   288
    retTC = head_as_TreeChunk();
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   289
  } else {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   290
    // walk down the list and return the one with the highest
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   291
    // heap address among chunks of this size.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   292
    Chunk_t* last = fc;
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   293
    while (fc->next() != NULL) {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   294
      if ((HeapWord*)last < (HeapWord*)fc) {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   295
        last = fc;
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   296
      }
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   297
      fc = fc->next();
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   298
    }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   299
    retTC = TreeChunk<Chunk_t, FreeList_t>::as_TreeChunk(last);
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   300
  }
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   301
  assert(retTC->list() == this, "Wrong type of chunk.");
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   302
  return retTC;
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   303
}
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   304
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   305
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   306
BinaryTreeDictionary<Chunk_t, FreeList_t>::BinaryTreeDictionary(MemRegion mr) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   307
  assert((mr.byte_size() > min_size()), "minimum chunk size");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  reset(mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  assert(root()->left() == NULL, "reset check failed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  assert(root()->right() == NULL, "reset check failed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  assert(root()->head()->next() == NULL, "reset check failed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  assert(root()->head()->prev() == NULL, "reset check failed");
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   314
  assert(total_size() == root()->size(), "reset check failed");
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   315
  assert(total_free_blocks() == 1, "reset check failed");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   318
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   319
void BinaryTreeDictionary<Chunk_t, FreeList_t>::inc_total_size(size_t inc) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   320
  _total_size = _total_size + inc;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   323
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   324
void BinaryTreeDictionary<Chunk_t, FreeList_t>::dec_total_size(size_t dec) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   325
  _total_size = _total_size - dec;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   328
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   329
void BinaryTreeDictionary<Chunk_t, FreeList_t>::reset(MemRegion mr) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   330
  assert((mr.byte_size() > min_size()), "minimum chunk size");
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   331
  set_root(TreeList<Chunk_t, FreeList_t>::as_TreeList(mr.start(), mr.word_size()));
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   332
  set_total_size(mr.word_size());
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   333
  set_total_free_blocks(1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   336
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   337
void BinaryTreeDictionary<Chunk_t, FreeList_t>::reset(HeapWord* addr, size_t byte_size) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  MemRegion mr(addr, heap_word_size(byte_size));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  reset(mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   342
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   343
void BinaryTreeDictionary<Chunk_t, FreeList_t>::reset() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  set_root(NULL);
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   345
  set_total_size(0);
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   346
  set_total_free_blocks(0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
// Get a free block of size at least size from tree, or NULL.
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   350
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   351
TreeChunk<Chunk_t, FreeList_t>*
46674
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   352
BinaryTreeDictionary<Chunk_t, FreeList_t>::get_chunk_from_tree(size_t size)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
{
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   354
  TreeList<Chunk_t, FreeList_t> *curTL, *prevTL;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   355
  TreeChunk<Chunk_t, FreeList_t>* retTC = NULL;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   356
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   357
  assert((size >= min_size()), "minimum chunk size");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  if (FLSVerifyDictionary) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   359
    verify_tree();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  // starting at the root, work downwards trying to find match.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  // Remember the last node of size too great or too small.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  for (prevTL = curTL = root(); curTL != NULL;) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    if (curTL->size() == size) {        // exact match
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    prevTL = curTL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    if (curTL->size() < size) {        // proceed to right sub-tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
      curTL = curTL->right();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    } else {                           // proceed to left sub-tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
      assert(curTL->size() > size, "size inconsistency");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
      curTL = curTL->left();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  if (curTL == NULL) { // couldn't find exact match
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   376
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    // try and find the next larger size by walking back up the search path
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    for (curTL = prevTL; curTL != NULL;) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
      if (curTL->size() >= size) break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
      else curTL = curTL->parent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    assert(curTL == NULL || curTL->count() > 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
      "An empty list should not be in the tree");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  if (curTL != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
    assert(curTL->size() >= size, "size inconsistency");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   388
    curTL = curTL->get_better_list(this);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   389
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    retTC = curTL->first_available();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    assert((retTC != NULL) && (curTL->count() > 0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
      "A list in the binary tree should not be NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    assert(retTC->size() >= size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
      "A chunk of the wrong size was found");
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   395
    remove_chunk_from_tree(retTC);
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   396
    assert(retTC->is_free(), "Header is not marked correctly");
1
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 (FLSVerifyDictionary) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  return retTC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   405
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   406
TreeList<Chunk_t, FreeList_t>* BinaryTreeDictionary<Chunk_t, FreeList_t>::find_list(size_t size) const {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   407
  TreeList<Chunk_t, FreeList_t>* curTL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  for (curTL = root(); curTL != NULL;) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    if (curTL->size() == size) {        // exact match
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    if (curTL->size() < size) {        // proceed to right sub-tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
      curTL = curTL->right();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    } else {                           // proceed to left sub-tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
      assert(curTL->size() > size, "size inconsistency");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
      curTL = curTL->left();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  return curTL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   424
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   425
bool BinaryTreeDictionary<Chunk_t, FreeList_t>::verify_chunk_in_free_list(Chunk_t* tc) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  size_t size = tc->size();
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   427
  TreeList<Chunk_t, FreeList_t>* tl = find_list(size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  if (tl == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  } else {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   431
    return tl->verify_chunk_in_free_list(tc);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   435
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   436
Chunk_t* BinaryTreeDictionary<Chunk_t, FreeList_t>::find_largest_dict() const {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   437
  TreeList<Chunk_t, FreeList_t> *curTL = root();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  if (curTL != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    while(curTL->right() != NULL) curTL = curTL->right();
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   440
    return curTL->largest_address();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
// Remove the current chunk from the tree.  If it is not the last
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
// chunk in a list on a tree node, just unlink it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
// If it is the last chunk in the list (the next link is NULL),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
// remove the node and repair the tree.
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   450
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   451
TreeChunk<Chunk_t, FreeList_t>*
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   452
BinaryTreeDictionary<Chunk_t, FreeList_t>::remove_chunk_from_tree(TreeChunk<Chunk_t, FreeList_t>* tc) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  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
   454
  assert(tc->is_free(), "Header is not marked correctly");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   456
  TreeList<Chunk_t, FreeList_t> *newTL, *parentTL;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   457
  TreeChunk<Chunk_t, FreeList_t>* retTC;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   458
  TreeList<Chunk_t, FreeList_t>* tl = tc->list();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  debug_only(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
    bool removing_only_chunk = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
    if (tl == _root) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
      if ((_root->left() == NULL) && (_root->right() == NULL)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
        if (_root->count() == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
          assert(_root->head() == tc, "Should only be this one chunk");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
          removing_only_chunk = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  assert(tl != NULL, "List should be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  assert(tl->parent() == NULL || tl == tl->parent()->left() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
         tl == tl->parent()->right(), "list is inconsistent");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   474
  bool complicated_splice = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  retTC = tc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  // Removing this chunk can have the side effect of changing the node
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   478
  // (TreeList<Chunk_t, FreeList_t>*) in the tree.  If the node is the root, update it.
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   479
  TreeList<Chunk_t, FreeList_t>* replacementTL = tl->remove_chunk_replace_if_needed(tc);
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   480
  assert(tc->is_free(), "Chunk should still be free");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  assert(replacementTL->parent() == NULL ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
         replacementTL == replacementTL->parent()->left() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
         replacementTL == replacementTL->parent()->right(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
         "list is inconsistent");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  if (tl == root()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    assert(replacementTL->parent() == NULL, "Incorrectly replacing root");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    set_root(replacementTL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   489
#ifdef ASSERT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    if (tl != replacementTL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
      assert(replacementTL->head() != NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
        "If the tree list was replaced, it should not be a NULL list");
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   493
      TreeList<Chunk_t, FreeList_t>* rhl = replacementTL->head_as_TreeChunk()->list();
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   494
      TreeList<Chunk_t, FreeList_t>* rtl =
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   495
        TreeChunk<Chunk_t, FreeList_t>::as_TreeChunk(replacementTL->tail())->list();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
      assert(rhl == replacementTL, "Broken head");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
      assert(rtl == replacementTL, "Broken tail");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
      assert(replacementTL->size() == tc->size(),  "Broken size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   500
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  // Does the tree need to be repaired?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  if (replacementTL->count() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    assert(replacementTL->head() == NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
           replacementTL->tail() == NULL, "list count is incorrect");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
    // Find the replacement node for the (soon to be empty) node being removed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
    // if we have a single (or no) child, splice child in our stead
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    if (replacementTL->left() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
      // left is NULL so pick right.  right may also be NULL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
      newTL = replacementTL->right();
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   511
      debug_only(replacementTL->clear_right();)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
    } else if (replacementTL->right() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
      // right is NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
      newTL = replacementTL->left();
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   515
      debug_only(replacementTL->clear_left();)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
    } else {  // we have both children, so, by patriarchal convention,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
              // 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
   518
      complicated_splice = true;
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   519
      newTL = remove_tree_minimum(replacementTL->right());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
      assert(newTL != NULL && newTL->left() == NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
             newTL->right() == NULL, "sub-tree minimum exists");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
    // newTL is the replacement for the (soon to be empty) node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    // newTL may be NULL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    // should verify; we just cleanly excised our replacement
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    if (FLSVerifyDictionary) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   527
      verify_tree();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
    // first make newTL my parent's child
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
    if ((parentTL = replacementTL->parent()) == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
      // newTL should be root
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
      assert(tl == root(), "Incorrectly replacing root");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
      set_root(newTL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
      if (newTL != NULL) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   535
        newTL->clear_parent();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    } else if (parentTL->right() == replacementTL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
      // replacementTL is a right child
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   539
      parentTL->set_right(newTL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    } else {                                // replacementTL is a left child
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
      assert(parentTL->left() == replacementTL, "should be left child");
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   542
      parentTL->set_left(newTL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    }
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   544
    debug_only(replacementTL->clear_parent();)
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   545
    if (complicated_splice) {  // we need newTL to get replacementTL's
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
                              // two children
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
      assert(newTL != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
             newTL->left() == NULL && newTL->right() == NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
            "newTL should not have encumbrances from the past");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
      // we'd like to assert as below:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
      // assert(replacementTL->left() != NULL && replacementTL->right() != NULL,
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   552
      //       "else !complicated_splice");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
      // ... however, the above assertion is too strong because we aren't
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
      // guaranteed that replacementTL->right() is still NULL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
      // Recall that we removed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
      // the right sub-tree minimum from replacementTL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
      // That may well have been its right
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
      // 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
   559
      assert(replacementTL->left() != NULL, "else !complicated_splice");
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   560
      newTL->set_left(replacementTL->left());
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   561
      newTL->set_right(replacementTL->right());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
      debug_only(
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   563
        replacementTL->clear_right();
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   564
        replacementTL->clear_left();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
      )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
    assert(replacementTL->right() == NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
           replacementTL->left() == NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
           replacementTL->parent() == NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
        "delete without encumbrances");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   573
  assert(total_size() >= retTC->size(), "Incorrect total size");
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   574
  dec_total_size(retTC->size());     // size book-keeping
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   575
  assert(total_free_blocks() > 0, "Incorrect total count");
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   576
  set_total_free_blocks(total_free_blocks() - 1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  assert(retTC != NULL, "null chunk?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  assert(retTC->prev() == NULL && retTC->next() == NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
         "should return without encumbrances");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  if (FLSVerifyDictionary) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   582
    verify_tree();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  assert(!removing_only_chunk || _root == NULL, "root should be NULL");
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   585
  return TreeChunk<Chunk_t, FreeList_t>::as_TreeChunk(retTC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
// Remove the leftmost node (lm) in the tree and return it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
// If lm has a right child, link it to the left node of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
// the parent of lm.
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   591
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   592
TreeList<Chunk_t, FreeList_t>* BinaryTreeDictionary<Chunk_t, FreeList_t>::remove_tree_minimum(TreeList<Chunk_t, FreeList_t>* tl) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  assert(tl != NULL && tl->parent() != NULL, "really need a proper sub-tree");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  // locate the subtree minimum by walking down left branches
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   595
  TreeList<Chunk_t, FreeList_t>* curTL = tl;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  for (; curTL->left() != NULL; curTL = curTL->left());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
  // obviously curTL now has at most one child, a right child
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
  if (curTL != root()) {  // Should this test just be removed?
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   599
    TreeList<Chunk_t, FreeList_t>* parentTL = curTL->parent();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
    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
   601
      parentTL->set_left(curTL->right());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
      // If the list tl has no left child, then curTL may be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
      // the right child of parentTL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
      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
   606
      parentTL->set_right(curTL->right());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
    // The only use of this method would not pass the root of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
    // tree (as indicated by the assertion above that the tree list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
    // has a parent) but the specification does not explicitly exclude the
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 20729
diff changeset
   612
    // passing of the root so accommodate it.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
    set_root(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
  debug_only(
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   616
    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
   617
    curTL->clear_right();    // recall, above, left child is already null
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
  // we just excised a (non-root) node, we should still verify all tree invariants
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  if (FLSVerifyDictionary) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   621
    verify_tree();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  return curTL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   626
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   627
void BinaryTreeDictionary<Chunk_t, FreeList_t>::insert_chunk_in_tree(Chunk_t* fc) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   628
  TreeList<Chunk_t, FreeList_t> *curTL, *prevTL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  size_t size = fc->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   631
  assert((size >= min_size()),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   632
         SIZE_FORMAT " is too small to be a TreeChunk<Chunk_t, FreeList_t> " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   633
         size, min_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  if (FLSVerifyDictionary) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   635
    verify_tree();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   638
  fc->clear_next();
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   639
  fc->link_prev(NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
  // work down from the _root, looking for insertion point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
  for (prevTL = curTL = root(); curTL != NULL;) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
    if (curTL->size() == size)  // exact match
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
    prevTL = curTL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
    if (curTL->size() > size) { // follow left branch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
      curTL = curTL->left();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    } else {                    // follow right branch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
      assert(curTL->size() < size, "size inconsistency");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
      curTL = curTL->right();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   653
  TreeChunk<Chunk_t, FreeList_t>* tc = TreeChunk<Chunk_t, FreeList_t>::as_TreeChunk(fc);
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   654
  // This chunk is being returned to the binary tree.  Its embedded
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   655
  // TreeList<Chunk_t, FreeList_t> should be unused at this point.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
  tc->initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
  if (curTL != NULL) {          // exact match
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
    tc->set_list(curTL);
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   659
    curTL->return_chunk_at_tail(tc);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
  } else {                     // need a new node in tree
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   661
    tc->clear_next();
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   662
    tc->link_prev(NULL);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   663
    TreeList<Chunk_t, FreeList_t>* newTL = TreeList<Chunk_t, FreeList_t>::as_TreeList(tc);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   664
    assert(((TreeChunk<Chunk_t, FreeList_t>*)tc)->list() == newTL,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
      "List was not initialized correctly");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
    if (prevTL == NULL) {      // we are the only tree node
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
      assert(root() == NULL, "control point invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
      set_root(newTL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
    } else {                   // insert under prevTL ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
      if (prevTL->size() < size) {   // am right child
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
        assert(prevTL->right() == NULL, "control point invariant");
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   672
        prevTL->set_right(newTL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
      } else {                       // am left child
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
        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
   675
        prevTL->set_left(newTL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  assert(tc->list() != NULL, "Tree list should be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   681
  inc_total_size(size);
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   682
  // Method 'total_size_in_tree' walks through the every block in the
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
  // tree, so it can cause significant performance loss if there are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  // many blocks in the tree
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   685
  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
   686
  set_total_free_blocks(total_free_blocks() + 1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  if (FLSVerifyDictionary) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   688
    verify_tree();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   692
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   693
size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::max_chunk_size() const {
46674
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   694
  verify_par_locked();
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   695
  TreeList<Chunk_t, FreeList_t>* tc = root();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  if (tc == NULL) return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  for (; tc->right() != NULL; tc = tc->right());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  return tc->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   701
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   702
size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::total_list_length(TreeList<Chunk_t, FreeList_t>* tl) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
  size_t res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
  res = tl->count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
  size_t cnt;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   707
  Chunk_t* tc = tl->head();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
  for (cnt = 0; tc != NULL; tc = tc->next(), cnt++);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
  assert(res == cnt, "The count is not being maintained correctly");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   714
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   715
size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::total_size_in_tree(TreeList<Chunk_t, FreeList_t>* tl) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
  if (tl == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
    return 0;
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   718
  return (tl->size() * total_list_length(tl)) +
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   719
         total_size_in_tree(tl->left())    +
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   720
         total_size_in_tree(tl->right());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   723
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   724
double BinaryTreeDictionary<Chunk_t, FreeList_t>::sum_of_squared_block_sizes(TreeList<Chunk_t, FreeList_t>* const tl) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
  if (tl == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
    return 0.0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
  double size = (double)(tl->size());
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   729
  double curr = size * size * total_list_length(tl);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
  curr += sum_of_squared_block_sizes(tl->left());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
  curr += sum_of_squared_block_sizes(tl->right());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
  return curr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   735
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   736
size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::total_free_blocks_in_tree(TreeList<Chunk_t, FreeList_t>* tl) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
  if (tl == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
    return 0;
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   739
  return total_list_length(tl) +
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   740
         total_free_blocks_in_tree(tl->left()) +
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   741
         total_free_blocks_in_tree(tl->right());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   744
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   745
size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::num_free_blocks() const {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   746
  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
   747
         "_total_free_blocks inconsistency");
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   748
  return total_free_blocks();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   751
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   752
size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::tree_height_helper(TreeList<Chunk_t, FreeList_t>* tl) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
  if (tl == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
    return 0;
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   755
  return 1 + MAX2(tree_height_helper(tl->left()),
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   756
                  tree_height_helper(tl->right()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   759
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   760
size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::tree_height() const {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   761
  return tree_height_helper(root());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   764
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   765
size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::total_nodes_helper(TreeList<Chunk_t, FreeList_t>* tl) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
  if (tl == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
  }
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   769
  return 1 + total_nodes_helper(tl->left()) +
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   770
    total_nodes_helper(tl->right());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
// Searches the tree for a chunk that ends at the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
// specified address.
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   775
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   776
class EndTreeSearchClosure : public DescendTreeSearchClosure<Chunk_t, FreeList_t> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
  HeapWord* _target;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   778
  Chunk_t* _found;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
  EndTreeSearchClosure(HeapWord* target) : _target(target), _found(NULL) {}
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   782
  bool do_list(FreeList_t* fl) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   783
    Chunk_t* item = fl->head();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
    while (item != NULL) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   785
      if (item->end() == (uintptr_t*) _target) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
        _found = item;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
        return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
      item = item->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   793
  Chunk_t* found() { return _found; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   796
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   797
Chunk_t* BinaryTreeDictionary<Chunk_t, FreeList_t>::find_chunk_ends_at(HeapWord* target) const {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   798
  EndTreeSearchClosure<Chunk_t, FreeList_t> etsc(target);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
  bool found_target = etsc.do_tree(root());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
  assert(found_target || etsc.found() == NULL, "Consistency check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
  assert(!found_target || etsc.found() != NULL, "Consistency check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
  return etsc.found();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
// Closures and methods for calculating total bytes returned to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
// free lists in the tree.
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   807
#ifndef PRODUCT
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   808
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   809
class InitializeDictReturnedBytesClosure : public AscendTreeCensusClosure<Chunk_t, FreeList_t> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
   public:
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   811
  void do_list(FreeList_t* fl) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   812
    fl->set_returned_bytes(0);
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   813
  }
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   814
};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   816
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   817
void BinaryTreeDictionary<Chunk_t, FreeList_t>::initialize_dict_returned_bytes() {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   818
  InitializeDictReturnedBytesClosure<Chunk_t, FreeList_t> idrb;
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   819
  idrb.do_tree(root());
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   820
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   822
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   823
class ReturnedBytesClosure : public AscendTreeCensusClosure<Chunk_t, FreeList_t> {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   824
  size_t _dict_returned_bytes;
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   825
 public:
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   826
  ReturnedBytesClosure() { _dict_returned_bytes = 0; }
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   827
  void do_list(FreeList_t* fl) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   828
    _dict_returned_bytes += fl->returned_bytes();
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   829
  }
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   830
  size_t dict_returned_bytes() { return _dict_returned_bytes; }
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   831
};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   833
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   834
size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::sum_dict_returned_bytes() {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   835
  ReturnedBytesClosure<Chunk_t, FreeList_t> rbc;
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   836
  rbc.do_tree(root());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   838
  return rbc.dict_returned_bytes();
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   839
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   841
// Count the number of entries in the tree.
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   842
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   843
class treeCountClosure : public DescendTreeCensusClosure<Chunk_t, FreeList_t> {
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   844
 public:
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   845
  uint count;
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   846
  treeCountClosure(uint c) { count = c; }
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   847
  void do_list(FreeList_t* fl) {
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   848
    count++;
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   849
  }
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   850
};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   852
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   853
size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::total_count() {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   854
  treeCountClosure<Chunk_t, FreeList_t> ctc(0);
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   855
  ctc.do_tree(root());
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   856
  return ctc.count;
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   857
}
46674
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   858
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   859
template <class Chunk_t, class FreeList_t>
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   860
Mutex* BinaryTreeDictionary<Chunk_t, FreeList_t>::par_lock() const {
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   861
  return _lock;
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   862
}
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   863
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   864
template <class Chunk_t, class FreeList_t>
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   865
void BinaryTreeDictionary<Chunk_t, FreeList_t>::set_par_lock(Mutex* lock) {
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   866
  _lock = lock;
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   867
}
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   868
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   869
template <class Chunk_t, class FreeList_t>
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   870
void BinaryTreeDictionary<Chunk_t, FreeList_t>::verify_par_locked() const {
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   871
#ifdef ASSERT
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   872
  Thread* my_thread = Thread::current();
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   873
  if (my_thread->is_GC_task_thread()) {
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   874
    assert(par_lock() != NULL, "Should be using locking?");
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   875
    assert_lock_strong(par_lock());
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   876
  }
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   877
#endif // ASSERT
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   878
}
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   879
#endif // PRODUCT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
// Print summary statistics
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   882
template <class Chunk_t, class FreeList_t>
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
   883
void BinaryTreeDictionary<Chunk_t, FreeList_t>::report_statistics(outputStream* st) const {
46674
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 46630
diff changeset
   884
  verify_par_locked();
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
   885
  st->print_cr("Statistics for BinaryTreeDictionary:");
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
   886
  st->print_cr("------------------------------------");
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   887
  size_t total_size = total_chunk_size(debug_only(NULL));
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
   888
  size_t free_blocks = num_free_blocks();
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
   889
  st->print_cr("Total Free Space: " SIZE_FORMAT, total_size);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
   890
  st->print_cr("Max   Chunk Size: " SIZE_FORMAT, max_chunk_size());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
   891
  st->print_cr("Number of Blocks: " SIZE_FORMAT, free_blocks);
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   892
  if (free_blocks > 0) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
   893
    st->print_cr("Av.  Block  Size: " SIZE_FORMAT, total_size/free_blocks);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
  }
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
   895
  st->print_cr("Tree      Height: " SIZE_FORMAT, tree_height());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   898
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   899
class PrintFreeListsClosure : public AscendTreeCensusClosure<Chunk_t, FreeList_t> {
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   900
  outputStream* _st;
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   901
  int _print_line;
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   902
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   903
 public:
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   904
  PrintFreeListsClosure(outputStream* st) {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   905
    _st = st;
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   906
    _print_line = 0;
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   907
  }
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   908
  void do_list(FreeList_t* fl) {
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   909
    if (++_print_line >= 40) {
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   910
      FreeList_t::print_labels_on(_st, "size");
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   911
      _print_line = 0;
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   912
    }
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
   913
    fl->print_on(_st);
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   914
    size_t sz = fl->size();
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   915
    for (Chunk_t* fc = fl->head(); fc != NULL;
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   916
         fc = fc->next()) {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   917
      _st->print_cr("\t[" PTR_FORMAT "," PTR_FORMAT ")  %s",
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24335
diff changeset
   918
                    p2i(fc), p2i((HeapWord*)fc + sz),
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   919
                    fc->cantCoalesce() ? "\t CC" : "");
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   920
    }
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   921
  }
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   922
};
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   923
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   924
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   925
void BinaryTreeDictionary<Chunk_t, FreeList_t>::print_free_lists(outputStream* st) const {
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   926
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   927
  FreeList_t::print_labels_on(st, "size");
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   928
  PrintFreeListsClosure<Chunk_t, FreeList_t> pflc(st);
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   929
  pflc.do_tree(root());
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   930
}
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   931
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
// Verify the following tree invariants:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
// . _root has no parent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
// . parent and child point to each other
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
// . each node's key correctly related to that of its child(ren)
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   936
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   937
void BinaryTreeDictionary<Chunk_t, FreeList_t>::verify_tree() const {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   938
  guarantee(root() == NULL || total_free_blocks() == 0 ||
22775
52bc5222f5f1 8026849: Fix typos in the GC code, part 2
jwilhelm
parents: 22551
diff changeset
   939
    total_size() != 0, "_total_size shouldn't be 0?");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
  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
   941
  verify_tree_helper(root());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   944
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   945
size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::verify_prev_free_ptrs(TreeList<Chunk_t, FreeList_t>* tl) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
  size_t ct = 0;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   947
  for (Chunk_t* curFC = tl->head(); curFC != NULL; curFC = curFC->next()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
    ct++;
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   949
    assert(curFC->prev() == NULL || curFC->prev()->is_free(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
      "Chunk should be free");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
  return ct;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
// Note: this helper is recursive rather than iterative, so use with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
// caution on very deep trees; and watch out for stack overflow errors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
// In general, to be used only for debugging.
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   958
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   959
void BinaryTreeDictionary<Chunk_t, FreeList_t>::verify_tree_helper(TreeList<Chunk_t, FreeList_t>* tl) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
  if (tl == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
  guarantee(tl->size() != 0, "A list must has a size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
  guarantee(tl->left()  == NULL || tl->left()->parent()  == tl,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
         "parent<-/->left");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
  guarantee(tl->right() == NULL || tl->right()->parent() == tl,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
         "parent<-/->right");;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
  guarantee(tl->left() == NULL  || tl->left()->size()    <  tl->size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
         "parent !> left");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
  guarantee(tl->right() == NULL || tl->right()->size()   >  tl->size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
         "parent !< left");
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   971
  guarantee(tl->head() == NULL || tl->head()->is_free(), "!Free");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
  guarantee(tl->head() == NULL || tl->head_as_TreeChunk()->list() == tl,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
    "list inconsistency");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
  guarantee(tl->count() > 0 || (tl->head() == NULL && tl->tail() == NULL),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
    "list count is inconsistent");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
  guarantee(tl->count() > 1 || tl->head() == tl->tail(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
    "list is incorrectly constructed");
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   978
  size_t count = verify_prev_free_ptrs(tl);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
  guarantee(count == (size_t)tl->count(), "Node count is incorrect");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
  if (tl->head() != NULL) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   981
    tl->head_as_TreeChunk()->verify_tree_chunk_list();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
  }
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   983
  verify_tree_helper(tl->left());
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   984
  verify_tree_helper(tl->right());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
22884
5cadaf2c3f32 8034171: Remove use of template template parameters from binaryTreeDictionary.
goetz
parents: 22775
diff changeset
   987
template <class Chunk_t, class FreeList_t>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 12933
diff changeset
   988
void BinaryTreeDictionary<Chunk_t, FreeList_t>::verify() const {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   989
  verify_tree();
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   990
  guarantee(total_size() == total_size_in_tree(root()), "Total Size inconsistency");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
}
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   992
50193
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49708
diff changeset
   993
template <class Chunk_t, class FreeList_t>
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49708
diff changeset
   994
size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::total_chunk_size(debug_only(const Mutex* lock)) const {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49708
diff changeset
   995
  debug_only(
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49708
diff changeset
   996
    if (lock != NULL && lock->owned_by_self()) {
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49708
diff changeset
   997
      assert(total_size_in_tree(root()) == total_size(),
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49708
diff changeset
   998
             "_total_size inconsistency");
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49708
diff changeset
   999
    }
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49708
diff changeset
  1000
  )
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49708
diff changeset
  1001
  return total_size();
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49708
diff changeset
  1002
}
49c3e91c424f 8176808: Split up metaspace.cpp
stuefe
parents: 49708
diff changeset
  1003
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52767
diff changeset
  1004
#endif // SHARE_MEMORY_BINARYTREEDICTIONARY_INLINE_HPP