hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.inline.hpp
author jwilhelm
Fri, 28 Feb 2014 15:27:09 +0100
changeset 23471 ec9427262f0a
parent 23450 c7c6202fc7e2
child 23857 f00e672a0531
permissions -rw-r--r--
8036025: Sort the freelist in order to shrink the heap Summary: The free list is being maintained in a sorted fashion and old and humongous regions are allocated from the bottom of the heap while young regions are allocated at the top. Reviewed-by: tschatzl, mgerdin Contributed-by: jesper.wilhelmsson@oracle.com, staffan.friberg@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     1
/*
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
     2
 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     4
 *
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     8
 *
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    13
 * accompanied this code).
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    14
 *
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    18
 *
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    21
 * questions.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    22
 *
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    23
 */
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    24
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    25
#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    26
#define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    27
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    28
#include "gc_implementation/g1/heapRegionSet.hpp"
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    29
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    30
inline void HeapRegionSetBase::add(HeapRegion* hr) {
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    31
  check_mt_safety();
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    32
  assert(hr->containing_set() == NULL, hrs_ext_msg(this, "should not already have a containing set %u"));
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
    33
  assert(hr->next() == NULL, hrs_ext_msg(this, "should not already be linked"));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    34
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    35
  _count.increment(1u, hr->capacity());
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    36
  hr->set_containing_set(this);
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    37
  verify_region(hr);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    38
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    39
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    40
inline void HeapRegionSetBase::remove(HeapRegion* hr) {
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    41
  check_mt_safety();
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    42
  verify_region(hr);
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
    43
  assert(hr->next() == NULL, hrs_ext_msg(this, "should already be unlinked"));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    44
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    45
  hr->set_containing_set(NULL);
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    46
  assert(_count.length() > 0, hrs_ext_msg(this, "pre-condition"));
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    47
  _count.decrement(1u, hr->capacity());
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    48
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    49
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    50
inline void FreeRegionList::add_ordered(HeapRegion* hr) {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    51
  check_mt_safety();
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    52
  assert((length() == 0 && _head == NULL && _tail == NULL) ||
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    53
         (length() >  0 && _head != NULL && _tail != NULL),
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    54
         hrs_ext_msg(this, "invariant"));
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    55
  // add() will verify the region and check mt safety.
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    56
  add(hr);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    57
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    58
  // Now link the region
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    59
  if (_head != NULL) {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    60
    HeapRegion* curr;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    61
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    62
    if (_last != NULL && _last->hrs_index() < hr->hrs_index()) {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    63
      curr = _last;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    64
    } else {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    65
      curr = _head;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    66
    }
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    67
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    68
    // Find first entry with a Region Index larger than entry to insert.
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    69
    while (curr != NULL && curr->hrs_index() < hr->hrs_index()) {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    70
      curr = curr->next();
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    71
    }
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    72
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    73
    hr->set_next(curr);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    74
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    75
    if (curr == NULL) {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    76
      // Adding at the end
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    77
      hr->set_prev(_tail);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    78
      _tail->set_next(hr);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    79
      _tail = hr;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    80
    } else if (curr->prev() == NULL) {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    81
      // Adding at the beginning
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    82
      hr->set_prev(NULL);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    83
      _head = hr;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    84
      curr->set_prev(hr);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    85
    } else {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    86
      hr->set_prev(curr->prev());
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    87
      hr->prev()->set_next(hr);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    88
      curr->set_prev(hr);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    89
    }
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    90
  } else {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    91
    // The list was empty
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    92
    _tail = hr;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    93
    _head = hr;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    94
  }
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    95
  _last = hr;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    96
}
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    97
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    98
inline void FreeRegionList::add_as_head(HeapRegion* hr) {
8927
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
    99
  assert((length() == 0 && _head == NULL && _tail == NULL) ||
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   100
         (length() >  0 && _head != NULL && _tail != NULL),
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   101
         hrs_ext_msg(this, "invariant"));
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   102
  // add() will verify the region and check mt safety.
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   103
  add(hr);
8927
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   104
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   105
  // Now link the region.
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   106
  if (_head != NULL) {
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   107
    hr->set_next(_head);
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   108
    _head->set_prev(hr);
8927
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   109
  } else {
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   110
    _tail = hr;
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   111
  }
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   112
  _head = hr;
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   113
}
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   114
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   115
inline void FreeRegionList::add_as_tail(HeapRegion* hr) {
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   116
  check_mt_safety();
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   117
  assert((length() == 0 && _head == NULL && _tail == NULL) ||
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   118
         (length() >  0 && _head != NULL && _tail != NULL),
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   119
         hrs_ext_msg(this, "invariant"));
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   120
  // add() will verify the region and check mt safety.
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   121
  add(hr);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   122
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   123
  // Now link the region.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   124
  if (_tail != NULL) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   125
    _tail->set_next(hr);
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   126
    hr->set_prev(_tail);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   127
  } else {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   128
    _head = hr;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   129
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   130
  _tail = hr;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   131
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   132
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   133
inline HeapRegion* FreeRegionList::remove_head() {
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   134
  assert(!is_empty(), hrs_ext_msg(this, "the list should not be empty"));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   135
  assert(length() > 0 && _head != NULL && _tail != NULL,
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   136
         hrs_ext_msg(this, "invariant"));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   137
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   138
  // We need to unlink it first.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   139
  HeapRegion* hr = _head;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   140
  _head = hr->next();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   141
  if (_head == NULL) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   142
    _tail = NULL;
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   143
  } else {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   144
    _head->set_prev(NULL);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   145
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   146
  hr->set_next(NULL);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   147
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   148
  if (_last == hr) {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   149
    _last = NULL;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   150
  }
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   151
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   152
  // remove() will verify the region and check mt safety.
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   153
  remove(hr);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   154
  return hr;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   155
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   156
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   157
inline HeapRegion* FreeRegionList::remove_head_or_null() {
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   158
  check_mt_safety();
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   159
  if (!is_empty()) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   160
    return remove_head();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   161
  } else {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   162
    return NULL;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   163
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   164
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   165
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   166
inline HeapRegion* FreeRegionList::remove_tail() {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   167
  assert(!is_empty(), hrs_ext_msg(this, "The list should not be empty"));
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   168
  assert(length() > 0 && _head != NULL && _tail != NULL,
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   169
         hrs_ext_msg(this, "invariant"));
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   170
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   171
  // We need to unlink it first
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   172
  HeapRegion* hr = _tail;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   173
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   174
  _tail = hr->prev();
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   175
  if (_tail == NULL) {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   176
    _head = NULL;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   177
  } else {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   178
    _tail->set_next(NULL);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   179
  }
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   180
  hr->set_prev(NULL);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   181
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   182
  if (_last == hr) {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   183
    _last = NULL;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   184
  }
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   185
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   186
  // remove() will verify the region and check mt safety.
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   187
  remove(hr);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   188
  return hr;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   189
}
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   190
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   191
inline HeapRegion* FreeRegionList::remove_tail_or_null() {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   192
  check_mt_safety();
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   193
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   194
  if (!is_empty()) {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   195
    return remove_tail();
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   196
  } else {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   197
    return NULL;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   198
  }
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   199
}
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   200
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   201
inline HeapRegion* FreeRegionList::remove_region(bool from_head) {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   202
  if (from_head) {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   203
    return remove_head_or_null();
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   204
  } else {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   205
    return remove_tail_or_null();
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   206
  }
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   207
}
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   208
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   209
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP