hotspot/src/share/vm/gc_implementation/g1/heapRegionSeq.cpp
author drchase
Fri, 09 May 2014 16:50:54 -0400
changeset 24424 2658d7834c6e
parent 24106 dae9277bdf2a
child 26157 70eddb655686
permissions -rw-r--r--
8037816: Fix for 8036122 breaks build with Xcode5/clang Summary: Repaired or selectively disabled offending formats; future-proofed with additional checking Reviewed-by: kvn, jrose, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     1
/*
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24106
diff changeset
     2
 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     4
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     8
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    13
 * accompanied this code).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    14
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3807
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3807
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: 3807
diff changeset
    21
 * questions.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    22
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    23
 */
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    25
#include "precompiled.hpp"
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    26
#include "gc_implementation/g1/heapRegion.hpp"
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    27
#include "gc_implementation/g1/heapRegionSeq.inline.hpp"
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 22234
diff changeset
    28
#include "gc_implementation/g1/heapRegionSet.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    29
#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    30
#include "memory/allocation.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    31
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    32
// Private
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    33
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
    34
uint HeapRegionSeq::find_contiguous_from(uint from, uint num) {
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
    35
  uint len = length();
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    36
  assert(num > 1, "use this only for sequences of length 2 or greater");
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    37
  assert(from <= len,
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
    38
         err_msg("from: %u should be valid and <= than %u", from, len));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    39
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
    40
  uint curr = from;
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
    41
  uint first = G1_NULL_HRS_INDEX;
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
    42
  uint num_so_far = 0;
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    43
  while (curr < len && num_so_far < num) {
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    44
    if (at(curr)->is_empty()) {
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    45
      if (first == G1_NULL_HRS_INDEX) {
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    46
        first = curr;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    47
        num_so_far = 1;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    48
      } else {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    49
        num_so_far += 1;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    50
      }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    51
    } else {
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    52
      first = G1_NULL_HRS_INDEX;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    53
      num_so_far = 0;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    54
    }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    55
    curr += 1;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    56
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    57
  assert(num_so_far <= num, "post-condition");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    58
  if (num_so_far == num) {
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 8071
diff changeset
    59
    // we found enough space for the humongous object
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    60
    assert(from <= first && first < len, "post-condition");
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    61
    assert(first < curr && (curr - first) == num, "post-condition");
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
    62
    for (uint i = first; i < first + num; ++i) {
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    63
      assert(at(i)->is_empty(), "post-condition");
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    64
    }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    65
    return first;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    66
  } else {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    67
    // we failed to find enough space for the humongous object
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    68
    return G1_NULL_HRS_INDEX;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    69
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    70
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    71
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    72
// Public
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    73
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
    74
void HeapRegionSeq::initialize(HeapWord* bottom, HeapWord* end) {
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
    75
  assert((uintptr_t) bottom % HeapRegion::GrainBytes == 0,
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    76
         "bottom should be heap region aligned");
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
    77
  assert((uintptr_t) end % HeapRegion::GrainBytes == 0,
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    78
         "end should be heap region aligned");
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    79
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    80
  _next_search_index = 0;
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    81
  _allocated_length = 0;
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    82
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
    83
  _regions.initialize(bottom, end, HeapRegion::GrainBytes);
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    84
}
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    85
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    86
MemRegion HeapRegionSeq::expand_by(HeapWord* old_end,
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    87
                                   HeapWord* new_end,
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    88
                                   FreeRegionList* list) {
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    89
  assert(old_end < new_end, "don't call it otherwise");
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    90
  G1CollectedHeap* g1h = G1CollectedHeap::heap();
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    91
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    92
  HeapWord* next_bottom = old_end;
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
    93
  assert(heap_bottom() <= next_bottom, "invariant");
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    94
  while (next_bottom < new_end) {
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
    95
    assert(next_bottom < heap_end(), "invariant");
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
    96
    uint index = length();
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
    97
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
    98
    assert(index < max_length(), "otherwise we cannot expand further");
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
    99
    if (index == 0) {
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   100
      // We have not allocated any regions so far
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   101
      assert(next_bottom == heap_bottom(), "invariant");
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   102
    } else {
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   103
      // next_bottom should match the end of the last/previous region
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   104
      assert(next_bottom == at(index - 1)->end(), "invariant");
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   105
    }
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   106
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   107
    if (index == _allocated_length) {
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   108
      // We have to allocate a new HeapRegion.
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   109
      HeapRegion* new_hr = g1h->new_heap_region(index, next_bottom);
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   110
      if (new_hr == NULL) {
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   111
        // allocation failed, we bail out and return what we have done so far
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   112
        return MemRegion(old_end, next_bottom);
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   113
      }
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   114
      assert(_regions.get_by_index(index) == NULL, "invariant");
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   115
      _regions.set_by_index(index, new_hr);
17323
cc153b745ed5 8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents: 13195
diff changeset
   116
      increment_allocated_length();
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   117
    }
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   118
    // Have to increment the length first, otherwise we will get an
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   119
    // assert failure at(index) below.
17323
cc153b745ed5 8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents: 13195
diff changeset
   120
    increment_length();
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   121
    HeapRegion* hr = at(index);
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   122
    list->add_as_tail(hr);
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   123
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   124
    next_bottom = hr->end();
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   125
  }
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   126
  assert(next_bottom == new_end, "post-condition");
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   127
  return MemRegion(old_end, next_bottom);
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   128
}
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   129
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   130
uint HeapRegionSeq::free_suffix() {
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   131
  uint res = 0;
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   132
  uint index = length();
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   133
  while (index > 0) {
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   134
    index -= 1;
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   135
    if (!at(index)->is_empty()) {
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   136
      break;
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   137
    }
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   138
    res += 1;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   139
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   140
  return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   141
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   142
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   143
uint HeapRegionSeq::find_contiguous(uint num) {
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   144
  assert(num > 1, "use this only for sequences of length 2 or greater");
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   145
  assert(_next_search_index <= length(),
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   146
         err_msg("_next_search_index: %u should be valid and <= than %u",
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   147
                 _next_search_index, length()));
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   148
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   149
  uint start = _next_search_index;
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   150
  uint res = find_contiguous_from(start, num);
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   151
  if (res == G1_NULL_HRS_INDEX && start > 0) {
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   152
    // Try starting from the beginning. If _next_search_index was 0,
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   153
    // no point in doing this again.
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   154
    res = find_contiguous_from(0, num);
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   155
  }
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   156
  if (res != G1_NULL_HRS_INDEX) {
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   157
    assert(res < length(), err_msg("res: %u should be valid", res));
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   158
    _next_search_index = res + num;
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   159
    assert(_next_search_index <= length(),
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   160
           err_msg("_next_search_index: %u should be valid and <= than %u",
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   161
                   _next_search_index, length()));
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   162
  }
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   163
  return res;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   164
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   165
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   166
void HeapRegionSeq::iterate(HeapRegionClosure* blk) const {
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   167
  iterate_from((HeapRegion*) NULL, blk);
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   168
}
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   169
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   170
void HeapRegionSeq::iterate_from(HeapRegion* hr, HeapRegionClosure* blk) const {
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   171
  uint hr_index = 0;
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   172
  if (hr != NULL) {
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   173
    hr_index = hr->hrs_index();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   174
  }
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   175
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   176
  uint len = length();
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   177
  for (uint i = hr_index; i < len; i += 1) {
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   178
    bool res = blk->doHeapRegion(at(i));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   179
    if (res) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   180
      blk->incomplete();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   181
      return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   182
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   183
  }
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   184
  for (uint i = 0; i < hr_index; i += 1) {
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   185
    bool res = blk->doHeapRegion(at(i));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   186
    if (res) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   187
      blk->incomplete();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   188
      return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   189
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   190
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   191
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   192
17323
cc153b745ed5 8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents: 13195
diff changeset
   193
uint HeapRegionSeq::shrink_by(uint num_regions_to_remove) {
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   194
  // Reset this in case it's currently pointing into the regions that
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   195
  // we just removed.
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   196
  _next_search_index = 0;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   197
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   198
  assert(length() > 0, "the region sequence should not be empty");
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   199
  assert(length() <= _allocated_length, "invariant");
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   200
  assert(_allocated_length > 0, "we should have at least one region committed");
17323
cc153b745ed5 8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents: 13195
diff changeset
   201
  assert(num_regions_to_remove < length(), "We should never remove all regions");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   202
17323
cc153b745ed5 8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents: 13195
diff changeset
   203
  uint i = 0;
cc153b745ed5 8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents: 13195
diff changeset
   204
  for (; i < num_regions_to_remove; i++) {
cc153b745ed5 8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents: 13195
diff changeset
   205
    HeapRegion* cur = at(length() - 1);
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   206
17323
cc153b745ed5 8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents: 13195
diff changeset
   207
    if (!cur->is_empty()) {
cc153b745ed5 8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents: 13195
diff changeset
   208
      // We have to give up if the region can not be moved
cc153b745ed5 8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents: 13195
diff changeset
   209
      break;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   210
  }
17323
cc153b745ed5 8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents: 13195
diff changeset
   211
    assert(!cur->isHumongous(), "Humongous regions should not be empty");
cc153b745ed5 8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents: 13195
diff changeset
   212
cc153b745ed5 8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents: 13195
diff changeset
   213
    decrement_length();
cc153b745ed5 8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents: 13195
diff changeset
   214
  }
cc153b745ed5 8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents: 13195
diff changeset
   215
  return i;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   216
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   217
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   218
#ifndef PRODUCT
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   219
void HeapRegionSeq::verify_optional() {
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   220
  guarantee(length() <= _allocated_length,
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   221
            err_msg("invariant: _length: %u _allocated_length: %u",
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   222
                    length(), _allocated_length));
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   223
  guarantee(_allocated_length <= max_length(),
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   224
            err_msg("invariant: _allocated_length: %u _max_length: %u",
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   225
                    _allocated_length, max_length()));
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   226
  guarantee(_next_search_index <= length(),
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   227
            err_msg("invariant: _next_search_index: %u _length: %u",
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   228
                    _next_search_index, length()));
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   229
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   230
  HeapWord* prev_end = heap_bottom();
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   231
  for (uint i = 0; i < _allocated_length; i += 1) {
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   232
    HeapRegion* hr = _regions.get_by_index(i);
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   233
    guarantee(hr != NULL, err_msg("invariant: i: %u", i));
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   234
    guarantee(hr->bottom() == prev_end,
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   235
              err_msg("invariant i: %u "HR_FORMAT" prev_end: "PTR_FORMAT,
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24106
diff changeset
   236
                      i, HR_FORMAT_PARAMS(hr), p2i(prev_end)));
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   237
    guarantee(hr->hrs_index() == i,
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   238
              err_msg("invariant: i: %u hrs_index(): %u", i, hr->hrs_index()));
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   239
    if (i < length()) {
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   240
      // Asserts will fire if i is >= _length
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   241
      HeapWord* addr = hr->bottom();
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   242
      guarantee(addr_to_region(addr) == hr, "sanity");
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   243
    } else {
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   244
      guarantee(hr->is_empty(), "sanity");
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   245
      guarantee(!hr->isHumongous(), "sanity");
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   246
      // using assert instead of guarantee here since containing_set()
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   247
      // is only available in non-product builds.
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   248
      assert(hr->containing_set() == NULL, "sanity");
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   249
    }
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   250
    if (hr->startsHumongous()) {
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   251
      prev_end = hr->orig_end();
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   252
    } else {
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   253
      prev_end = hr->end();
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   254
    }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   255
  }
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   256
  for (uint i = _allocated_length; i < max_length(); i += 1) {
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   257
    guarantee(_regions.get_by_index(i) == NULL, err_msg("invariant i: %u", i));
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   258
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   259
}
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   260
#endif // PRODUCT