src/hotspot/share/memory/freeList.inline.hpp
author ccheung
Fri, 17 Aug 2018 14:50:59 -0700
changeset 51439 0517bd2a0eda
parent 50193 49c3e91c424f
permissions -rw-r--r--
8209385: CDS runtime classpath checking is too strict when only classes from the system modules are archived Summary: skip checking the path entries which are not being referenced during CDS dump time Reviewed-by: jiangli, iklam
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46674
a9e42ff6158f 8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents: 30764
diff changeset
     2
 * Copyright (c) 2001, 2017, 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: 4574
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4574
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: 4574
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
49708
6709f13dccd3 8200735: Move CMS specific code from binaryTreeDictionary and freeList to CMS files
stefank
parents: 47216
diff changeset
    25
#ifndef SHARE_MEMORY_FREELIST_INLINE_HPP
6709f13dccd3 8200735: Move CMS specific code from binaryTreeDictionary and freeList to CMS files
stefank
parents: 47216
diff changeset
    26
#define SHARE_MEMORY_FREELIST_INLINE_HPP
6709f13dccd3 8200735: Move CMS specific code from binaryTreeDictionary and freeList to CMS files
stefank
parents: 47216
diff changeset
    27
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30154
diff changeset
    28
#include "gc/shared/collectedHeap.hpp"
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
    29
#include "memory/freeList.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6447
diff changeset
    30
#include "runtime/globals.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6447
diff changeset
    31
#include "runtime/mutex.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6447
diff changeset
    32
#include "runtime/vmThread.hpp"
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14123
diff changeset
    33
#include "utilities/macros.hpp"
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
    34
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// Free list.  A FreeList is used to access a linked list of chunks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// of space in the heap.  The head and tail are maintained so that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// items can be (as in the current implementation) added at the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// at the tail of the list and removed from the head of the list to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// maintain a FIFO queue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
    41
template <class Chunk>
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
    42
FreeList<Chunk>::FreeList() :
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  _head(NULL), _tail(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  , _protecting_lock(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  _size         = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  _count        = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
    52
template <class Chunk>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    53
void FreeList<Chunk>::link_head(Chunk* v) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    54
  assert_proper_lock_protection();
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    55
  set_head(v);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    56
  // If this method is not used (just set the head instead),
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    57
  // this check can be avoided.
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    58
  if (v != NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    59
    v->link_prev(NULL);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    60
  }
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    61
}
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    62
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    63
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    64
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    65
template <class Chunk>
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    66
void FreeList<Chunk>::reset() {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    67
  // Don't set the _size to 0 because this method is
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    68
  // used with a existing list that has a size but which has
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    69
  // been emptied.
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    70
  // Don't clear the _protecting_lock of an existing list.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  set_count(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  set_head(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  set_tail(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
    76
template <class Chunk>
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    77
void FreeList<Chunk>::initialize() {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    78
#ifdef ASSERT
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    79
  // Needed early because it might be checked in other initializing code.
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    80
  set_protecting_lock(NULL);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    81
#endif
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    82
  reset();
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    83
  set_size(0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    86
template <class Chunk_t>
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    87
Chunk_t* FreeList<Chunk_t>::get_chunk_at_head() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  assert_proper_lock_protection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  assert(head() == NULL || head()->prev() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  assert(tail() == NULL || tail()->next() == NULL, "list invariant");
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    91
  Chunk_t* fc = head();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  if (fc != NULL) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    93
    Chunk_t* nextFC = fc->next();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    if (nextFC != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      // The chunk fc being removed has a "next".  Set the "next" to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      // "prev" of fc.
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
    97
      nextFC->link_prev(NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    } else { // removed tail of list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      link_tail(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    link_head(nextFC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    decrement_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  assert(head() == NULL || head()->prev() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  assert(tail() == NULL || tail()->next() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  return fc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   110
template <class Chunk>
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   111
void FreeList<Chunk>::getFirstNChunksFromList(size_t n, FreeList<Chunk>* fl) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  assert_proper_lock_protection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  assert(fl->count() == 0, "Precondition");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  if (count() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    int k = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    fl->set_head(head()); n--;
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   117
    Chunk* tl = head();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    while (tl->next() != NULL && n > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      tl = tl->next(); n--; k++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    assert(tl != NULL, "Loop Inv.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    // First, fix up the list we took from.
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   124
    Chunk* new_head = tl->next();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    set_head(new_head);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    set_count(count() - k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    if (new_head == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      set_tail(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    } else {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   130
      new_head->link_prev(NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    // Now we can fix up the tail.
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   133
    tl->link_next(NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    // And return the result.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    fl->set_tail(tl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    fl->set_count(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
// Remove this chunk from the list
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   141
template <class Chunk>
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   142
void FreeList<Chunk>::remove_chunk(Chunk*fc) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
   assert_proper_lock_protection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
   assert(head() != NULL, "Remove from empty list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
   assert(fc != NULL, "Remove a NULL chunk");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
   assert(size() == fc->size(), "Wrong list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
   assert(head() == NULL || head()->prev() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
   assert(tail() == NULL || tail()->next() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   150
   Chunk* prevFC = fc->prev();
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   151
   Chunk* nextFC = fc->next();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
   if (nextFC != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
     // The chunk fc being removed has a "next".  Set the "next" to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
     // "prev" of fc.
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   155
     nextFC->link_prev(prevFC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
   } else { // removed tail of list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
     link_tail(prevFC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
   if (prevFC == NULL) { // removed head of list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
     link_head(nextFC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
     assert(nextFC == NULL || nextFC->prev() == NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
       "Prev of head should be NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
   } else {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   164
     prevFC->link_next(nextFC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
     assert(tail() != prevFC || prevFC->next() == NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
       "Next of tail should be NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
   decrement_count();
6447
32cc5cad7fa6 6983930: CMS: Various small cleanups ca September 2010
ysr
parents: 5547
diff changeset
   169
   assert(((head() == NULL) + (tail() == NULL) + (count() == 0)) % 3 == 0,
32cc5cad7fa6 6983930: CMS: Various small cleanups ca September 2010
ysr
parents: 5547
diff changeset
   170
          "H/T/C Inconsistency");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
   // clear next and prev fields of fc, debug only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
   NOT_PRODUCT(
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   173
     fc->link_prev(NULL);
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   174
     fc->link_next(NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
   )
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   176
   assert(fc->is_free(), "Should still be a free chunk");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
   assert(head() == NULL || head()->prev() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
   assert(tail() == NULL || tail()->next() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
   assert(head() == NULL || head()->size() == size(), "wrong item on list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
   assert(tail() == NULL || tail()->size() == size(), "wrong item on list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
// Add this chunk at the head of the list.
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   184
template <class Chunk>
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   185
void FreeList<Chunk>::return_chunk_at_head(Chunk* chunk, bool record_return) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  assert_proper_lock_protection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  assert(chunk != NULL, "insert a NULL chunk");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  assert(size() == chunk->size(), "Wrong size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  assert(head() == NULL || head()->prev() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  assert(tail() == NULL || tail()->next() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   192
  Chunk* oldHead = head();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  assert(chunk != oldHead, "double insertion");
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   194
  chunk->link_after(oldHead);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  link_head(chunk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  if (oldHead == NULL) { // only chunk in list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    assert(tail() == NULL, "inconsistent FreeList");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    link_tail(chunk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  increment_count(); // of # of chunks in list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  assert(head() == NULL || head()->prev() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  assert(tail() == NULL || tail()->next() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  assert(head() == NULL || head()->size() == size(), "wrong item on list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  assert(tail() == NULL || tail()->size() == size(), "wrong item on list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   207
template <class Chunk>
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   208
void FreeList<Chunk>::return_chunk_at_head(Chunk* chunk) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  assert_proper_lock_protection();
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   210
  return_chunk_at_head(chunk, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
// Add this chunk at the tail of the list.
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   214
template <class Chunk>
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   215
void FreeList<Chunk>::return_chunk_at_tail(Chunk* chunk, bool record_return) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  assert_proper_lock_protection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  assert(head() == NULL || head()->prev() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  assert(tail() == NULL || tail()->next() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  assert(chunk != NULL, "insert a NULL chunk");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  assert(size() == chunk->size(), "wrong size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   222
  Chunk* oldTail = tail();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  assert(chunk != oldTail, "double insertion");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  if (oldTail != NULL) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   225
    oldTail->link_after(chunk);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  } else { // only chunk in list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    assert(head() == NULL, "inconsistent FreeList");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    link_head(chunk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  link_tail(chunk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  increment_count();  // of # of chunks in list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  assert(head() == NULL || head()->prev() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  assert(tail() == NULL || tail()->next() == NULL, "list invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  assert(head() == NULL || head()->size() == size(), "wrong item on list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  assert(tail() == NULL || tail()->size() == size(), "wrong item on list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   238
template <class Chunk>
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   239
void FreeList<Chunk>::return_chunk_at_tail(Chunk* chunk) {
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   240
  return_chunk_at_tail(chunk, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   243
template <class Chunk>
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   244
void FreeList<Chunk>::prepend(FreeList<Chunk>* fl) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  assert_proper_lock_protection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  if (fl->count() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    if (count() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
      set_head(fl->head());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      set_tail(fl->tail());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      set_count(fl->count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      // Both are non-empty.
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   253
      Chunk* fl_tail = fl->tail();
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   254
      Chunk* this_head = head();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
      assert(fl_tail->next() == NULL, "Well-formedness of fl");
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   256
      fl_tail->link_next(this_head);
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   257
      this_head->link_prev(fl_tail);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
      set_head(fl->head());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      set_count(count() + fl->count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    fl->set_head(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    fl->set_tail(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    fl->set_count(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   267
// verify_chunk_in_free_lists() is used to verify that an item is in this free list.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
// It is used as a debugging aid.
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   269
template <class Chunk>
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   270
bool FreeList<Chunk>::verify_chunk_in_free_list(Chunk* fc) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  // This is an internal consistency check, not part of the check that the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  // chunk is in the free lists.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  guarantee(fc->size() == size(), "Wrong list is being searched");
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   274
  Chunk* curFC = head();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  while (curFC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    // This is an internal consistency check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    guarantee(size() == curFC->size(), "Chunk is in wrong list.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    if (fc == curFC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    curFC = curFC->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
27251
7d667f91ec8d 6979279: remove special-case code for ParallelGCThreads==0
mlarsson
parents: 26422
diff changeset
   286
#ifdef ASSERT
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   287
template <class Chunk>
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   288
void FreeList<Chunk>::assert_proper_lock_protection_work() const {
27251
7d667f91ec8d 6979279: remove special-case code for ParallelGCThreads==0
mlarsson
parents: 26422
diff changeset
   289
  // Nothing to do if the list has no assigned protecting lock
7d667f91ec8d 6979279: remove special-case code for ParallelGCThreads==0
mlarsson
parents: 26422
diff changeset
   290
  if (protecting_lock() == NULL) {
7d667f91ec8d 6979279: remove special-case code for ParallelGCThreads==0
mlarsson
parents: 26422
diff changeset
   291
    return;
7d667f91ec8d 6979279: remove special-case code for ParallelGCThreads==0
mlarsson
parents: 26422
diff changeset
   292
  }
7d667f91ec8d 6979279: remove special-case code for ParallelGCThreads==0
mlarsson
parents: 26422
diff changeset
   293
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   294
  Thread* thr = Thread::current();
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   295
  if (thr->is_VM_thread() || thr->is_ConcurrentGC_thread()) {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   296
    // assert that we are holding the freelist lock
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   297
  } else if (thr->is_GC_task_thread()) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   298
    assert(protecting_lock()->owned_by_self(), "FreeList RACE DETECTED");
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   299
  } else if (thr->is_Java_thread()) {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   300
    assert(!SafepointSynchronize::is_at_safepoint(), "Should not be executing");
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   301
  } else {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
   302
    ShouldNotReachHere();  // unaccounted thread type?
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
#endif
185
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   306
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   307
// Print the "label line" for free list stats.
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   308
template <class Chunk>
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   309
void FreeList<Chunk>::print_labels_on(outputStream* st, const char* c) {
185
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   310
  st->print("%16s\t", c);
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   311
  st->print("%14s\t"    "%14s\t"    "%14s\t"    "%14s\t"    "%14s\t"
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   312
            "%14s\t"    "%14s\t"    "%14s\t"    "%14s\t"    "%14s\t"    "\n",
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   313
            "bfrsurp", "surplus", "desired", "prvSwep", "bfrSwep",
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   314
            "count",   "cBirths", "cDeaths", "sBirths", "sDeaths");
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   315
}
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   316
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   317
// Print the AllocationStats for the given free list. If the second argument
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   318
// to the call is a non-null string, it is printed in the first column;
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   319
// otherwise, if the argument is null (the default), then the size of the
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   320
// (free list) block is printed in the first column.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   321
template <class Chunk_t>
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   322
void FreeList<Chunk_t>::print_on(outputStream* st, const char* c) const {
185
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   323
  if (c != NULL) {
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   324
    st->print("%16s", c);
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   325
  } else {
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   326
    st->print(SIZE_FORMAT_W(16), size());
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   327
  }
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   328
}
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 9998
diff changeset
   329
49708
6709f13dccd3 8200735: Move CMS specific code from binaryTreeDictionary and freeList to CMS files
stefank
parents: 47216
diff changeset
   330
#endif // SHARE_MEMORY_FREELIST_INLINE_HPP