hotspot/src/share/vm/gc/g1/heapRegionSet.inline.hpp
author mgerdin
Mon, 07 Mar 2016 17:23:59 +0100
changeset 37039 79f62b89a7a6
parent 35065 b4ff0249c092
permissions -rw-r--r--
8151178: Move the collection set out of the G1 collector policy Summary: Create a G1CollectionSet class Reviewed-by: jwilhelm, tbenson, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     1
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26316
diff changeset
     2
 * Copyright (c) 2011, 2015, 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
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26316
diff changeset
    25
#ifndef SHARE_VM_GC_G1_HEAPREGIONSET_INLINE_HPP
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26316
diff changeset
    26
#define SHARE_VM_GC_G1_HEAPREGIONSET_INLINE_HPP
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    27
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26316
diff changeset
    28
#include "gc/g1/heapRegionSet.hpp"
7923
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();
33753
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 33105
diff changeset
    32
  assert_heap_region_set(hr->containing_set() == NULL, "should not already have a containing set");
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 33105
diff changeset
    33
  assert_heap_region_set(hr->next() == NULL, "should not already be linked");
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 33105
diff changeset
    34
  assert_heap_region_set(hr->prev() == NULL, "should not already be linked");
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    35
35065
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 33753
diff changeset
    36
  _length++;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    37
  hr->set_containing_set(this);
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    38
  verify_region(hr);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    39
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    40
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    41
inline void HeapRegionSetBase::remove(HeapRegion* hr) {
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    42
  check_mt_safety();
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    43
  verify_region(hr);
33753
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 33105
diff changeset
    44
  assert_heap_region_set(hr->next() == NULL, "should already be unlinked");
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 33105
diff changeset
    45
  assert_heap_region_set(hr->prev() == NULL, "should already be unlinked");
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    46
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    47
  hr->set_containing_set(NULL);
35065
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 33753
diff changeset
    48
  assert_heap_region_set(_length > 0, "pre-condition");
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 33753
diff changeset
    49
  _length--;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    50
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    51
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    52
inline void FreeRegionList::add_ordered(HeapRegion* hr) {
33753
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 33105
diff changeset
    53
  assert_free_region_list((length() == 0 && _head == NULL && _tail == NULL && _last == NULL) ||
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 33105
diff changeset
    54
                          (length() >  0 && _head != NULL && _tail != NULL),
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 33105
diff changeset
    55
                          "invariant");
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    56
  // 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
    57
  add(hr);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    58
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    59
  // Now link the region
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    60
  if (_head != NULL) {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    61
    HeapRegion* curr;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    62
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26157
diff changeset
    63
    if (_last != NULL && _last->hrm_index() < hr->hrm_index()) {
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    64
      curr = _last;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    65
    } else {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    66
      curr = _head;
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
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    69
    // Find first entry with a Region Index larger than entry to insert.
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26157
diff changeset
    70
    while (curr != NULL && curr->hrm_index() < hr->hrm_index()) {
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    71
      curr = curr->next();
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
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    74
    hr->set_next(curr);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    75
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    76
    if (curr == NULL) {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    77
      // Adding at the end
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    78
      hr->set_prev(_tail);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    79
      _tail->set_next(hr);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    80
      _tail = hr;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    81
    } else if (curr->prev() == NULL) {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    82
      // Adding at the beginning
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    83
      hr->set_prev(NULL);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    84
      _head = hr;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    85
      curr->set_prev(hr);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    86
    } else {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    87
      hr->set_prev(curr->prev());
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    88
      hr->prev()->set_next(hr);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    89
      curr->set_prev(hr);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    90
    }
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    91
  } else {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    92
    // The list was empty
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    93
    _tail = hr;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    94
    _head = hr;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    95
  }
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    96
  _last = hr;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    97
}
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
    98
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
    99
inline HeapRegion* FreeRegionList::remove_from_head_impl() {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   100
  HeapRegion* result = _head;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   101
  _head = result->next();
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   102
  if (_head == NULL) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   103
    _tail = NULL;
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   104
  } else {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   105
    _head->set_prev(NULL);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   106
  }
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   107
  result->set_next(NULL);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   108
  return result;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   109
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   110
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   111
inline HeapRegion* FreeRegionList::remove_from_tail_impl() {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   112
  HeapRegion* result = _tail;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   113
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   114
  _tail = result->prev();
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   115
  if (_tail == NULL) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   116
    _head = NULL;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   117
  } else {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   118
    _tail->set_next(NULL);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   119
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   120
  result->set_prev(NULL);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   121
  return result;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   122
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   123
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   124
inline HeapRegion* FreeRegionList::remove_region(bool from_head) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   125
  check_mt_safety();
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   126
  verify_optional();
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   127
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   128
  if (is_empty()) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   129
    return NULL;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   130
  }
33753
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 33105
diff changeset
   131
  assert_free_region_list(length() > 0 && _head != NULL && _tail != NULL, "invariant");
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   132
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   133
  HeapRegion* hr;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   134
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   135
  if (from_head) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   136
    hr = remove_from_head_impl();
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   137
  } else {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   138
    hr = remove_from_tail_impl();
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 23857
diff changeset
   139
  }
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   140
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   141
  if (_last == hr) {
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   142
    _last = NULL;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   143
  }
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   144
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   145
  // remove() will verify the region and check mt safety.
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   146
  remove(hr);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   147
  return hr;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   148
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   149
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26316
diff changeset
   150
#endif // SHARE_VM_GC_G1_HEAPREGIONSET_INLINE_HPP
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   151