hotspot/src/share/vm/gc_implementation/g1/heapRegionManager.cpp
author jwilhelm
Mon, 04 May 2015 17:10:50 +0200
changeset 30579 5208524ce05c
parent 30157 e36165b16dde
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
/*
29580
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 27905
diff changeset
     2
 * Copyright (c) 2001, 2015, 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"
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
    27
#include "gc_implementation/g1/heapRegionManager.inline.hpp"
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    28
#include "gc_implementation/g1/heapRegionSet.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    29
#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    30
#include "gc_implementation/g1/concurrentG1Refine.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    31
#include "memory/allocation.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    32
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
    33
void HeapRegionManager::initialize(G1RegionToSpaceMapper* heap_storage,
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    34
                               G1RegionToSpaceMapper* prev_bitmap,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    35
                               G1RegionToSpaceMapper* next_bitmap,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    36
                               G1RegionToSpaceMapper* bot,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    37
                               G1RegionToSpaceMapper* cardtable,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    38
                               G1RegionToSpaceMapper* card_counts) {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    39
  _allocated_heapregions_length = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    40
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    41
  _heap_mapper = heap_storage;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    42
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    43
  _prev_bitmap_mapper = prev_bitmap;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    44
  _next_bitmap_mapper = next_bitmap;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    45
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    46
  _bot_mapper = bot;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    47
  _cardtable_mapper = cardtable;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    48
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    49
  _card_counts_mapper = card_counts;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    50
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    51
  MemRegion reserved = heap_storage->reserved();
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    52
  _regions.initialize(reserved.start(), reserved.end(), HeapRegion::GrainBytes);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    53
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    54
  _available_map.resize(_regions.length(), false);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    55
  _available_map.clear();
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    56
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    57
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
    58
bool HeapRegionManager::is_available(uint region) const {
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    59
  return _available_map.at(region);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    60
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    61
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    62
#ifdef ASSERT
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
    63
bool HeapRegionManager::is_free(HeapRegion* hr) const {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    64
  return _free_list.contains(hr);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    65
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    66
#endif
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    67
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
    68
HeapRegion* HeapRegionManager::new_heap_region(uint hrm_index) {
26839
021bfc544c6f 8057658: Enable G1 FullGC extensions
sjohanss
parents: 26321
diff changeset
    69
  G1CollectedHeap* g1h = G1CollectedHeap::heap();
021bfc544c6f 8057658: Enable G1 FullGC extensions
sjohanss
parents: 26321
diff changeset
    70
  HeapWord* bottom = g1h->bottom_addr_for_region(hrm_index);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    71
  MemRegion mr(bottom, bottom + HeapRegion::GrainWords);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    72
  assert(reserved().contains(mr), "invariant");
26839
021bfc544c6f 8057658: Enable G1 FullGC extensions
sjohanss
parents: 26321
diff changeset
    73
  return g1h->allocator()->new_heap_region(hrm_index, g1h->bot_shared(), mr);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    74
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    75
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
    76
void HeapRegionManager::commit_regions(uint index, size_t num_regions) {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    77
  guarantee(num_regions > 0, "Must commit more than zero regions");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    78
  guarantee(_num_committed + num_regions <= max_length(), "Cannot commit more than the maximum amount of regions");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    79
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    80
  _num_committed += (uint)num_regions;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    81
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    82
  _heap_mapper->commit_regions(index, num_regions);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    83
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    84
  // Also commit auxiliary data
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    85
  _prev_bitmap_mapper->commit_regions(index, num_regions);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    86
  _next_bitmap_mapper->commit_regions(index, num_regions);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    87
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    88
  _bot_mapper->commit_regions(index, num_regions);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    89
  _cardtable_mapper->commit_regions(index, num_regions);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    90
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    91
  _card_counts_mapper->commit_regions(index, num_regions);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    92
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    93
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
    94
void HeapRegionManager::uncommit_regions(uint start, size_t num_regions) {
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    95
  guarantee(num_regions >= 1, err_msg("Need to specify at least one region to uncommit, tried to uncommit zero regions at %u", start));
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    96
  guarantee(_num_committed >= num_regions, "pre-condition");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    97
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    98
  // Print before uncommitting.
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    99
  if (G1CollectedHeap::heap()->hr_printer()->is_active()) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   100
    for (uint i = start; i < start + num_regions; i++) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   101
      HeapRegion* hr = at(i);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   102
      G1CollectedHeap::heap()->hr_printer()->uncommit(hr->bottom(), hr->end());
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   103
    }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   104
  }
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   105
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   106
  _num_committed -= (uint)num_regions;
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   107
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   108
  _available_map.par_clear_range(start, start + num_regions, BitMap::unknown_range);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   109
  _heap_mapper->uncommit_regions(start, num_regions);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   110
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   111
  // Also uncommit auxiliary data
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   112
  _prev_bitmap_mapper->uncommit_regions(start, num_regions);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   113
  _next_bitmap_mapper->uncommit_regions(start, num_regions);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   114
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   115
  _bot_mapper->uncommit_regions(start, num_regions);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   116
  _cardtable_mapper->uncommit_regions(start, num_regions);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   117
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   118
  _card_counts_mapper->uncommit_regions(start, num_regions);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   119
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   120
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   121
void HeapRegionManager::make_regions_available(uint start, uint num_regions) {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   122
  guarantee(num_regions > 0, "No point in calling this for zero regions");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   123
  commit_regions(start, num_regions);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   124
  for (uint i = start; i < start + num_regions; i++) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   125
    if (_regions.get_by_index(i) == NULL) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   126
      HeapRegion* new_hr = new_heap_region(i);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   127
      _regions.set_by_index(i, new_hr);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   128
      _allocated_heapregions_length = MAX2(_allocated_heapregions_length, i + 1);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   129
    }
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   130
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   131
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   132
  _available_map.par_set_range(start, start + num_regions, BitMap::unknown_range);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   133
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   134
  for (uint i = start; i < start + num_regions; i++) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   135
    assert(is_available(i), err_msg("Just made region %u available but is apparently not.", i));
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   136
    HeapRegion* hr = at(i);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   137
    if (G1CollectedHeap::heap()->hr_printer()->is_active()) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   138
      G1CollectedHeap::heap()->hr_printer()->commit(hr->bottom(), hr->end());
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   139
    }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   140
    HeapWord* bottom = G1CollectedHeap::heap()->bottom_addr_for_region(i);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   141
    MemRegion mr(bottom, bottom + HeapRegion::GrainWords);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   142
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   143
    hr->initialize(mr);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   144
    insert_into_free_list(at(i));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   145
  }
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
29685
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   148
MemoryUsage HeapRegionManager::get_auxiliary_data_memory_usage() const {
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   149
  size_t used_sz =
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   150
    _prev_bitmap_mapper->committed_size() +
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   151
    _next_bitmap_mapper->committed_size() +
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   152
    _bot_mapper->committed_size() +
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   153
    _cardtable_mapper->committed_size() +
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   154
    _card_counts_mapper->committed_size();
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   155
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   156
  size_t committed_sz =
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   157
    _prev_bitmap_mapper->reserved_size() +
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   158
    _next_bitmap_mapper->reserved_size() +
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   159
    _bot_mapper->reserved_size() +
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   160
    _cardtable_mapper->reserved_size() +
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   161
    _card_counts_mapper->reserved_size();
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   162
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   163
  return MemoryUsage(0, used_sz, committed_sz, committed_sz);
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   164
}
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   165
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   166
uint HeapRegionManager::expand_by(uint num_regions) {
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   167
  return expand_at(0, num_regions);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   168
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   169
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   170
uint HeapRegionManager::expand_at(uint start, uint num_regions) {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   171
  if (num_regions == 0) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   172
    return 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   173
  }
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   174
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   175
  uint cur = start;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   176
  uint idx_last_found = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   177
  uint num_last_found = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   178
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   179
  uint expanded = 0;
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   180
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   181
  while (expanded < num_regions &&
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   182
         (num_last_found = find_unavailable_from_idx(cur, &idx_last_found)) > 0) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   183
    uint to_expand = MIN2(num_regions - expanded, num_last_found);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   184
    make_regions_available(idx_last_found, to_expand);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   185
    expanded += to_expand;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   186
    cur = idx_last_found + num_last_found + 1;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   187
  }
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   188
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   189
  verify_optional();
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   190
  return expanded;
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   191
}
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   192
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   193
uint HeapRegionManager::find_contiguous(size_t num, bool empty_only) {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   194
  uint found = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   195
  size_t length_found = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   196
  uint cur = 0;
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   197
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   198
  while (length_found < num && cur < max_length()) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   199
    HeapRegion* hr = _regions.get_by_index(cur);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   200
    if ((!empty_only && !is_available(cur)) || (is_available(cur) && hr != NULL && hr->is_empty())) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   201
      // This region is a potential candidate for allocation into.
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   202
      length_found++;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   203
    } else {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   204
      // This region is not a candidate. The next region is the next possible one.
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   205
      found = cur + 1;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   206
      length_found = 0;
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   207
    }
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   208
    cur++;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   209
  }
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   210
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   211
  if (length_found == num) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   212
    for (uint i = found; i < (found + num); i++) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   213
      HeapRegion* hr = _regions.get_by_index(i);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   214
      // sanity check
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   215
      guarantee((!empty_only && !is_available(i)) || (is_available(i) && hr != NULL && hr->is_empty()),
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   216
                err_msg("Found region sequence starting at " UINT32_FORMAT ", length " SIZE_FORMAT
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   217
                        " that is not empty at " UINT32_FORMAT ". Hr is " PTR_FORMAT, found, num, i, p2i(hr)));
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   218
    }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   219
    return found;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   220
  } else {
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   221
    return G1_NO_HRM_INDEX;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   222
  }
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   223
}
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   224
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   225
HeapRegion* HeapRegionManager::next_region_in_heap(const HeapRegion* r) const {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   226
  guarantee(r != NULL, "Start region must be a valid region");
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   227
  guarantee(is_available(r->hrm_index()), err_msg("Trying to iterate starting from region %u which is not in the heap", r->hrm_index()));
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   228
  for (uint i = r->hrm_index() + 1; i < _allocated_heapregions_length; i++) {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   229
    HeapRegion* hr = _regions.get_by_index(i);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   230
    if (is_available(i)) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   231
      return hr;
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   232
    }
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   233
  }
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   234
  return NULL;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   235
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   236
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   237
void HeapRegionManager::iterate(HeapRegionClosure* blk) const {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   238
  uint len = max_length();
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   239
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   240
  for (uint i = 0; i < len; i++) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   241
    if (!is_available(i)) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   242
      continue;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   243
    }
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   244
    guarantee(at(i) != NULL, err_msg("Tried to access region %u that has a NULL HeapRegion*", i));
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   245
    bool res = blk->doHeapRegion(at(i));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   246
    if (res) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   247
      blk->incomplete();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   248
      return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   249
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   250
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   251
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   252
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   253
uint HeapRegionManager::find_unavailable_from_idx(uint start_idx, uint* res_idx) const {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   254
  guarantee(res_idx != NULL, "checking");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   255
  guarantee(start_idx <= (max_length() + 1), "checking");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   256
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   257
  uint num_regions = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   258
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   259
  uint cur = start_idx;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   260
  while (cur < max_length() && is_available(cur)) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   261
    cur++;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   262
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   263
  if (cur == max_length()) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   264
    return num_regions;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   265
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   266
  *res_idx = cur;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   267
  while (cur < max_length() && !is_available(cur)) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   268
    cur++;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   269
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   270
  num_regions = cur - *res_idx;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   271
#ifdef ASSERT
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   272
  for (uint i = *res_idx; i < (*res_idx + num_regions); i++) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   273
    assert(!is_available(i), "just checking");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   274
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   275
  assert(cur == max_length() || num_regions == 0 || is_available(cur),
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   276
         err_msg("The region at the current position %u must be available or at the end of the heap.", cur));
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   277
#endif
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   278
  return num_regions;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   279
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   280
27885
7786b3940066 8062943: REDO - Parallelize clearing the next mark bitmap
mlarsson
parents: 27009
diff changeset
   281
void HeapRegionManager::par_iterate(HeapRegionClosure* blk, uint worker_id, HeapRegionClaimer* hrclaimer, bool concurrent) const {
27009
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   282
  const uint start_index = hrclaimer->start_region_for_worker(worker_id);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   283
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   284
  // Every worker will actually look at all regions, skipping over regions that
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   285
  // are currently not committed.
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   286
  // This also (potentially) iterates over regions newly allocated during GC. This
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   287
  // is no problem except for some extra work.
27009
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   288
  const uint n_regions = hrclaimer->n_regions();
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   289
  for (uint count = 0; count < n_regions; count++) {
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   290
    const uint index = (start_index + count) % n_regions;
29580
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 27905
diff changeset
   291
    assert(index < n_regions, "sanity");
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   292
    // Skip over unavailable regions
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   293
    if (!is_available(index)) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   294
      continue;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   295
    }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   296
    HeapRegion* r = _regions.get_by_index(index);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   297
    // We'll ignore "continues humongous" regions (we'll process them
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   298
    // when we come across their corresponding "start humongous"
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   299
    // region) and regions already claimed.
27885
7786b3940066 8062943: REDO - Parallelize clearing the next mark bitmap
mlarsson
parents: 27009
diff changeset
   300
    // However, if the iteration is specified as concurrent, the values for
7786b3940066 8062943: REDO - Parallelize clearing the next mark bitmap
mlarsson
parents: 27009
diff changeset
   301
    // is_starts_humongous and is_continues_humongous can not be trusted,
7786b3940066 8062943: REDO - Parallelize clearing the next mark bitmap
mlarsson
parents: 27009
diff changeset
   302
    // and we should just blindly iterate over regions regardless of their
7786b3940066 8062943: REDO - Parallelize clearing the next mark bitmap
mlarsson
parents: 27009
diff changeset
   303
    // humongous status.
7786b3940066 8062943: REDO - Parallelize clearing the next mark bitmap
mlarsson
parents: 27009
diff changeset
   304
    if (hrclaimer->is_region_claimed(index) || (!concurrent && r->is_continues_humongous())) {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   305
      continue;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   306
    }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   307
    // OK, try to claim it
27009
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   308
    if (!hrclaimer->claim_region(index)) {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   309
      continue;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   310
    }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   311
    // Success!
27885
7786b3940066 8062943: REDO - Parallelize clearing the next mark bitmap
mlarsson
parents: 27009
diff changeset
   312
    // As mentioned above, special treatment of humongous regions can only be
7786b3940066 8062943: REDO - Parallelize clearing the next mark bitmap
mlarsson
parents: 27009
diff changeset
   313
    // done if we are iterating non-concurrently.
7786b3940066 8062943: REDO - Parallelize clearing the next mark bitmap
mlarsson
parents: 27009
diff changeset
   314
    if (!concurrent && r->is_starts_humongous()) {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   315
      // If the region is "starts humongous" we'll iterate over its
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   316
      // "continues humongous" first; in fact we'll do them
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   317
      // first. The order is important. In one case, calling the
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   318
      // closure on the "starts humongous" region might de-allocate
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   319
      // and clear all its "continues humongous" regions and, as a
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   320
      // result, we might end up processing them twice. So, we'll do
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   321
      // them first (note: most closures will ignore them anyway) and
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   322
      // then we'll do the "starts humongous" region.
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   323
      for (uint ch_index = index + 1; ch_index < index + r->region_num(); ch_index++) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   324
        HeapRegion* chr = _regions.get_by_index(ch_index);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   325
26846
7d4376f8560e 8058495: G1: normalize names for isHumongous() and friends
tonyp
parents: 26839
diff changeset
   326
        assert(chr->is_continues_humongous(), "Must be humongous region");
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   327
        assert(chr->humongous_start_region() == r,
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   328
               err_msg("Must work on humongous continuation of the original start region "
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   329
                       PTR_FORMAT ", but is " PTR_FORMAT, p2i(r), p2i(chr)));
27009
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   330
        assert(!hrclaimer->is_region_claimed(ch_index),
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   331
               "Must not have been claimed yet because claiming of humongous continuation first claims the start region");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   332
30157
e36165b16dde 8069004: Kitchensink hanged with 16Gb heap and GC pause >30 min
drwhite
parents: 29698
diff changeset
   333
        // Claim the region so no other worker tries to process the region. When a worker processes a
e36165b16dde 8069004: Kitchensink hanged with 16Gb heap and GC pause >30 min
drwhite
parents: 29698
diff changeset
   334
        // starts_humongous region it may also process the associated continues_humongous regions.
e36165b16dde 8069004: Kitchensink hanged with 16Gb heap and GC pause >30 min
drwhite
parents: 29698
diff changeset
   335
        // The continues_humongous regions can be changed to free regions. Unless this worker claims
e36165b16dde 8069004: Kitchensink hanged with 16Gb heap and GC pause >30 min
drwhite
parents: 29698
diff changeset
   336
        // all of these regions, other workers might try claim and process these newly free regions.
e36165b16dde 8069004: Kitchensink hanged with 16Gb heap and GC pause >30 min
drwhite
parents: 29698
diff changeset
   337
        bool claim_result = hrclaimer->claim_region(ch_index);
e36165b16dde 8069004: Kitchensink hanged with 16Gb heap and GC pause >30 min
drwhite
parents: 29698
diff changeset
   338
        guarantee(claim_result, "We should always be able to claim the continuesHumongous part of the humongous object");
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   339
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   340
        bool res2 = blk->doHeapRegion(chr);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   341
        if (res2) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   342
          return;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   343
        }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   344
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   345
        // Right now, this holds (i.e., no closure that actually
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   346
        // does something with "continues humongous" regions
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   347
        // clears them). We might have to weaken it in the future,
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   348
        // but let's leave these two asserts here for extra safety.
26846
7d4376f8560e 8058495: G1: normalize names for isHumongous() and friends
tonyp
parents: 26839
diff changeset
   349
        assert(chr->is_continues_humongous(), "should still be the case");
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   350
        assert(chr->humongous_start_region() == r, "sanity");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   351
      }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   352
    }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   353
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   354
    bool res = blk->doHeapRegion(r);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   355
    if (res) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   356
      return;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   357
    }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   358
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   359
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   360
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   361
uint HeapRegionManager::shrink_by(uint num_regions_to_remove) {
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   362
  assert(length() > 0, "the region sequence should not be empty");
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   363
  assert(length() <= _allocated_heapregions_length, "invariant");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   364
  assert(_allocated_heapregions_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
   365
  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
   366
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   367
  if (num_regions_to_remove == 0) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   368
    return 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   369
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   370
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   371
  uint removed = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   372
  uint cur = _allocated_heapregions_length - 1;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   373
  uint idx_last_found = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   374
  uint num_last_found = 0;
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   375
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   376
  while ((removed < num_regions_to_remove) &&
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   377
      (num_last_found = find_empty_from_idx_reverse(cur, &idx_last_found)) > 0) {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   378
    uint to_remove = MIN2(num_regions_to_remove - removed, num_last_found);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   379
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   380
    uncommit_regions(idx_last_found + num_last_found - to_remove, to_remove);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   381
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   382
    cur -= num_last_found;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   383
    removed += to_remove;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   384
  }
17323
cc153b745ed5 8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents: 13195
diff changeset
   385
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   386
  verify_optional();
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   387
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   388
  return removed;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   389
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   390
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   391
uint HeapRegionManager::find_empty_from_idx_reverse(uint start_idx, uint* res_idx) const {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   392
  guarantee(start_idx < _allocated_heapregions_length, "checking");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   393
  guarantee(res_idx != NULL, "checking");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   394
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   395
  uint num_regions_found = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   396
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   397
  jlong cur = start_idx;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   398
  while (cur != -1 && !(is_available(cur) && at(cur)->is_empty())) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   399
    cur--;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   400
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   401
  if (cur == -1) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   402
    return num_regions_found;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   403
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   404
  jlong old_cur = cur;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   405
  // cur indexes the first empty region
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   406
  while (cur != -1 && is_available(cur) && at(cur)->is_empty()) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   407
    cur--;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   408
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   409
  *res_idx = cur + 1;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   410
  num_regions_found = old_cur - cur;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   411
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   412
#ifdef ASSERT
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   413
  for (uint i = *res_idx; i < (*res_idx + num_regions_found); i++) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   414
    assert(at(i)->is_empty(), "just checking");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   415
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   416
#endif
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   417
  return num_regions_found;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   418
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   419
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   420
void HeapRegionManager::verify() {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   421
  guarantee(length() <= _allocated_heapregions_length,
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   422
            err_msg("invariant: _length: %u _allocated_length: %u",
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   423
                    length(), _allocated_heapregions_length));
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   424
  guarantee(_allocated_heapregions_length <= max_length(),
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   425
            err_msg("invariant: _allocated_length: %u _max_length: %u",
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   426
                    _allocated_heapregions_length, max_length()));
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   427
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   428
  bool prev_committed = true;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   429
  uint num_committed = 0;
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   430
  HeapWord* prev_end = heap_bottom();
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   431
  for (uint i = 0; i < _allocated_heapregions_length; i++) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   432
    if (!is_available(i)) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   433
      prev_committed = false;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   434
      continue;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   435
    }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   436
    num_committed++;
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   437
    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
   438
    guarantee(hr != NULL, err_msg("invariant: i: %u", i));
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   439
    guarantee(!prev_committed || hr->bottom() == prev_end,
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   440
              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
   441
                      i, HR_FORMAT_PARAMS(hr), p2i(prev_end)));
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   442
    guarantee(hr->hrm_index() == i,
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   443
              err_msg("invariant: i: %u hrm_index(): %u", i, hr->hrm_index()));
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   444
    // Asserts will fire if i is >= _length
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   445
    HeapWord* addr = hr->bottom();
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   446
    guarantee(addr_to_region(addr) == hr, "sanity");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   447
    // We cannot check whether the region is part of a particular set: at the time
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   448
    // this method may be called, we have only completed allocation of the regions,
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   449
    // but not put into a region set.
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   450
    prev_committed = true;
26846
7d4376f8560e 8058495: G1: normalize names for isHumongous() and friends
tonyp
parents: 26839
diff changeset
   451
    if (hr->is_starts_humongous()) {
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   452
      prev_end = hr->orig_end();
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   453
    } else {
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   454
      prev_end = hr->end();
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   455
    }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   456
  }
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   457
  for (uint i = _allocated_heapregions_length; i < max_length(); i++) {
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   458
    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
   459
  }
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   460
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   461
  guarantee(num_committed == _num_committed, err_msg("Found %u committed regions, but should be %u", num_committed, _num_committed));
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   462
  _free_list.verify();
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   463
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   464
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   465
#ifndef PRODUCT
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   466
void HeapRegionManager::verify_optional() {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   467
  verify();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   468
}
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   469
#endif // PRODUCT
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   470
27009
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   471
HeapRegionClaimer::HeapRegionClaimer(uint n_workers) :
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   472
    _n_workers(n_workers), _n_regions(G1CollectedHeap::heap()->_hrm._allocated_heapregions_length), _claims(NULL) {
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   473
  assert(n_workers > 0, "Need at least one worker.");
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   474
  _claims = NEW_C_HEAP_ARRAY(uint, _n_regions, mtGC);
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   475
  memset(_claims, Unclaimed, sizeof(*_claims) * _n_regions);
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   476
}
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   477
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   478
HeapRegionClaimer::~HeapRegionClaimer() {
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   479
  if (_claims != NULL) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 27009
diff changeset
   480
    FREE_C_HEAP_ARRAY(uint, _claims);
27009
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   481
  }
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   482
}
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   483
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   484
uint HeapRegionClaimer::start_region_for_worker(uint worker_id) const {
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   485
  assert(worker_id < _n_workers, "Invalid worker_id.");
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   486
  return _n_regions * worker_id / _n_workers;
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   487
}
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   488
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   489
bool HeapRegionClaimer::is_region_claimed(uint region_index) const {
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   490
  assert(region_index < _n_regions, "Invalid index.");
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   491
  return _claims[region_index] == Claimed;
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   492
}
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   493
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   494
bool HeapRegionClaimer::claim_region(uint region_index) {
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   495
  assert(region_index < _n_regions, "Invalid index.");
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   496
  uint old_val = Atomic::cmpxchg(Claimed, &_claims[region_index], Unclaimed);
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   497
  return old_val == Unclaimed;
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   498
}