hotspot/src/share/vm/gc_implementation/g1/heapRegionSeq.cpp
author johnc
Thu, 20 Jan 2011 13:57:12 -0800
changeset 7924 6cbca8cebf93
parent 7923 fc200fcd4e05
child 8071 195789ab14f9
permissions -rw-r--r--
Merge
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
/*
7904
e90e097fced4 7007068: G1: refine the BOT during evac failure handling
tonyp
parents: 7397
diff changeset
     2
 * Copyright (c) 2001, 2011, 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"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    26
#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    27
#include "gc_implementation/g1/heapRegionSeq.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    28
#include "memory/allocation.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    29
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    30
// Local to this file.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    31
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    32
static int orderRegions(HeapRegion** hr1p, HeapRegion** hr2p) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    33
  if ((*hr1p)->end() <= (*hr2p)->bottom()) return -1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    34
  else if ((*hr2p)->end() <= (*hr1p)->bottom()) return 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    35
  else if (*hr1p == *hr2p) return 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    36
  else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    37
    assert(false, "We should never compare distinct overlapping regions.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    38
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    39
  return 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    40
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    41
1425
ec7818f129f8 6758633: G1: SEGV with GCOld on Linux
iveresov
parents: 1374
diff changeset
    42
HeapRegionSeq::HeapRegionSeq(const size_t max_size) :
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    43
  _alloc_search_start(0),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    44
  // The line below is the worst bit of C++ hackery I've ever written
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    45
  // (Detlefs, 11/23).  You should think of it as equivalent to
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    46
  // "_regions(100, true)": initialize the growable array and inform it
6183
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 5547
diff changeset
    47
  // that it should allocate its elem array(s) on the C heap.
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 5547
diff changeset
    48
  //
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 5547
diff changeset
    49
  // The first argument, however, is actually a comma expression
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 5547
diff changeset
    50
  // (set_allocation_type(this, C_HEAP), 100). The purpose of the
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 5547
diff changeset
    51
  // set_allocation_type() call is to replace the default allocation
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 5547
diff changeset
    52
  // type for embedded objects STACK_OR_EMBEDDED with C_HEAP. It will
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 5547
diff changeset
    53
  // allow to pass the assert in GenericGrowableArray() which checks
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 5547
diff changeset
    54
  // that a growable array object must be on C heap if elements are.
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 5547
diff changeset
    55
  //
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 5547
diff changeset
    56
  // Note: containing object is allocated on C heap since it is CHeapObj.
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 5547
diff changeset
    57
  //
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 5547
diff changeset
    58
  _regions((ResourceObj::set_allocation_type((address)&_regions,
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 5547
diff changeset
    59
                                             ResourceObj::C_HEAP),
1425
ec7818f129f8 6758633: G1: SEGV with GCOld on Linux
iveresov
parents: 1374
diff changeset
    60
            (int)max_size),
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    61
           true),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    62
  _next_rr_candidate(0),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    63
  _seq_bottom(NULL)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    64
{}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    65
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    66
// Private methods.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    67
2344
f2e09ba7ceab 6543938: G1: remove the concept of popularity
apetrusenko
parents: 2105
diff changeset
    68
void HeapRegionSeq::print_empty_runs() {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    69
  int empty_run = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    70
  int n_empty = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    71
  int empty_run_start;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    72
  for (int i = 0; i < _regions.length(); i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    73
    HeapRegion* r = _regions.at(i);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    74
    if (r->continuesHumongous()) continue;
2344
f2e09ba7ceab 6543938: G1: remove the concept of popularity
apetrusenko
parents: 2105
diff changeset
    75
    if (r->is_empty()) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    76
      assert(!r->isHumongous(), "H regions should not be empty.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    77
      if (empty_run == 0) empty_run_start = i;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    78
      empty_run++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    79
      n_empty++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    80
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    81
      if (empty_run > 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    82
        gclog_or_tty->print("  %d:%d", empty_run_start, empty_run);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    83
        empty_run = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    84
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    85
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    86
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    87
  if (empty_run > 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    88
    gclog_or_tty->print(" %d:%d", empty_run_start, empty_run);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    89
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    90
  gclog_or_tty->print_cr(" [tot = %d]", n_empty);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    91
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    92
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    93
int HeapRegionSeq::find(HeapRegion* hr) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    94
  // FIXME: optimized for adjacent regions of fixed size.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    95
  int ind = hr->hrs_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    96
  if (ind != -1) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    97
    assert(_regions.at(ind) == hr, "Mismatch");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    98
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    99
  return ind;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   100
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   101
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   102
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   103
// Public methods.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   104
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   105
void HeapRegionSeq::insert(HeapRegion* hr) {
1425
ec7818f129f8 6758633: G1: SEGV with GCOld on Linux
iveresov
parents: 1374
diff changeset
   106
  assert(!_regions.is_full(), "Too many elements in HeapRegionSeq");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   107
  if (_regions.length() == 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   108
      || _regions.top()->end() <= hr->bottom()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   109
    hr->set_hrs_index(_regions.length());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   110
    _regions.append(hr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   111
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   112
    _regions.append(hr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   113
    _regions.sort(orderRegions);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   114
    for (int i = 0; i < _regions.length(); i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   115
      _regions.at(i)->set_hrs_index(i);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   116
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   117
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   118
  char* bot = (char*)_regions.at(0)->bottom();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   119
  if (_seq_bottom == NULL || bot < _seq_bottom) _seq_bottom = bot;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   120
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   121
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   122
size_t HeapRegionSeq::length() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   123
  return _regions.length();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   124
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   125
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   126
size_t HeapRegionSeq::free_suffix() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   127
  size_t res = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   128
  int first = _regions.length() - 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   129
  int cur = first;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   130
  while (cur >= 0 &&
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   131
         (_regions.at(cur)->is_empty()
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   132
          && (first == cur
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   133
              || (_regions.at(cur+1)->bottom() ==
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   134
                  _regions.at(cur)->end())))) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   135
      res++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   136
      cur--;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   137
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   138
  return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   139
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   140
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   141
int HeapRegionSeq::find_contiguous_from(int from, size_t num) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   142
  assert(num > 1, "pre-condition");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   143
  assert(0 <= from && from <= _regions.length(),
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   144
         err_msg("from: %d should be valid and <= than %d",
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   145
                 from, _regions.length()));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   146
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   147
  int curr = from;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   148
  int first = -1;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   149
  size_t num_so_far = 0;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   150
  while (curr < _regions.length() && num_so_far < num) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   151
    HeapRegion* curr_hr = _regions.at(curr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   152
    if (curr_hr->is_empty()) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   153
      if (first == -1) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   154
        first = curr;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   155
        num_so_far = 1;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   156
      } else {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   157
        num_so_far += 1;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   158
      }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   159
    } else {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   160
      first = -1;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   161
      num_so_far = 0;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   162
    }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   163
    curr += 1;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   164
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   165
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   166
  assert(num_so_far <= num, "post-condition");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   167
  if (num_so_far == num) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   168
    // we find enough space for the humongous object
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   169
    assert(from <= first && first < _regions.length(), "post-condition");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   170
    assert(first < curr && (curr - first) == (int) num, "post-condition");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   171
    for (int i = first; i < first + (int) num; ++i) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   172
      assert(_regions.at(i)->is_empty(), "post-condition");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   173
    }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   174
    return first;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   175
  } else {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   176
    // we failed to find enough space for the humongous object
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   177
    return -1;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   178
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   179
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   180
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   181
int HeapRegionSeq::find_contiguous(size_t num) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   182
  assert(num > 1, "otherwise we should not be calling this");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   183
  assert(0 <= _alloc_search_start && _alloc_search_start <= _regions.length(),
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   184
         err_msg("_alloc_search_start: %d should be valid and <= than %d",
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   185
                 _alloc_search_start, _regions.length()));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   186
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   187
  int start = _alloc_search_start;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   188
  int res = find_contiguous_from(start, num);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   189
  if (res == -1 && start != 0) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   190
    // Try starting from the beginning. If _alloc_search_start was 0,
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   191
    // no point in doing this again.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   192
    res = find_contiguous_from(0, num);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   193
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   194
  if (res != -1) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   195
    assert(0 <= res && res < _regions.length(),
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   196
           err_msg("res: %d should be valid", res));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   197
    _alloc_search_start = res + (int) num;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   198
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   199
  assert(0 < _alloc_search_start && _alloc_search_start <= _regions.length(),
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   200
         err_msg("_alloc_search_start: %d should be valid",
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   201
                 _alloc_search_start));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   202
  return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   203
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   204
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   205
void HeapRegionSeq::iterate(HeapRegionClosure* blk) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   206
  iterate_from((HeapRegion*)NULL, blk);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   207
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   208
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   209
// The first argument r is the heap region at which iteration begins.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   210
// This operation runs fastest when r is NULL, or the heap region for
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   211
// which a HeapRegionClosure most recently returned true, or the
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   212
// heap region immediately to its right in the sequence.  In all
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   213
// other cases a linear search is required to find the index of r.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   214
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   215
void HeapRegionSeq::iterate_from(HeapRegion* r, HeapRegionClosure* blk) {
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
  // :::: FIXME ::::
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   218
  // Static cache value is bad, especially when we start doing parallel
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   219
  // remembered set update. For now just don't cache anything (the
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   220
  // code in the def'd out blocks).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   221
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   222
#if 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   223
  static int cached_j = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   224
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   225
  int len = _regions.length();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   226
  int j = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   227
  // Find the index of r.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   228
  if (r != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   229
#if 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   230
    assert(cached_j >= 0, "Invariant.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   231
    if ((cached_j < len) && (r == _regions.at(cached_j))) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   232
      j = cached_j;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   233
    } else if ((cached_j + 1 < len) && (r == _regions.at(cached_j + 1))) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   234
      j = cached_j + 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   235
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   236
      j = find(r);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   237
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   238
      if (j < 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   239
        j = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   240
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   241
#if 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   242
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   243
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   244
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   245
  int i;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   246
  for (i = j; i < len; i += 1) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   247
    int res = blk->doHeapRegion(_regions.at(i));
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   248
    if (res) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   249
#if 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   250
      cached_j = i;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   251
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   252
      blk->incomplete();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   253
      return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   254
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   255
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   256
  for (i = 0; i < j; i += 1) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   257
    int res = blk->doHeapRegion(_regions.at(i));
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   258
    if (res) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   259
#if 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   260
      cached_j = i;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   261
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   262
      blk->incomplete();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   263
      return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   264
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   265
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   266
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   267
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   268
void HeapRegionSeq::iterate_from(int idx, HeapRegionClosure* blk) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   269
  int len = _regions.length();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   270
  int i;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   271
  for (i = idx; i < len; i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   272
    if (blk->doHeapRegion(_regions.at(i))) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   273
      blk->incomplete();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   274
      return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   275
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   276
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   277
  for (i = 0; i < idx; i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   278
    if (blk->doHeapRegion(_regions.at(i))) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   279
      blk->incomplete();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   280
      return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   281
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   282
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   283
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   284
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   285
MemRegion HeapRegionSeq::shrink_by(size_t shrink_bytes,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   286
                                   size_t& num_regions_deleted) {
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   287
  // 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
   288
  // we just removed.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   289
  _alloc_search_start = 0;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   290
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   291
  assert(shrink_bytes % os::vm_page_size() == 0, "unaligned");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   292
  assert(shrink_bytes % HeapRegion::GrainBytes == 0, "unaligned");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   293
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   294
  if (_regions.length() == 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   295
    num_regions_deleted = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   296
    return MemRegion();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   297
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   298
  int j = _regions.length() - 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   299
  HeapWord* end = _regions.at(j)->end();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   300
  HeapWord* last_start = end;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   301
  while (j >= 0 && shrink_bytes > 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   302
    HeapRegion* cur = _regions.at(j);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   303
    // We have to leave humongous regions where they are,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   304
    // and work around them.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   305
    if (cur->isHumongous()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   306
      return MemRegion(last_start, end);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   307
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   308
    assert(cur == _regions.top(), "Should be top");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   309
    if (!cur->is_empty()) break;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   310
    shrink_bytes -= cur->capacity();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   311
    num_regions_deleted++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   312
    _regions.pop();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   313
    last_start = cur->bottom();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   314
    // We need to delete these somehow, but can't currently do so here: if
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   315
    // we do, the ZF thread may still access the deleted region.  We'll
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   316
    // leave this here as a reminder that we have to do something about
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   317
    // this.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   318
    // delete cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   319
    j--;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   320
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   321
  return MemRegion(last_start, end);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   322
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   323
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   324
class PrintHeapRegionClosure : public  HeapRegionClosure {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   325
public:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   326
  bool doHeapRegion(HeapRegion* r) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   327
    gclog_or_tty->print(PTR_FORMAT ":", r);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   328
    r->print();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   329
    return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   330
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   331
};
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   332
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   333
void HeapRegionSeq::print() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   334
  PrintHeapRegionClosure cl;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   335
  iterate(&cl);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   336
}