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