src/hotspot/share/gc/g1/heapRegionManager.cpp
author sangheki
Wed, 13 Nov 2019 10:51:41 -0800
changeset 59062 6530de931b8e
parent 59060 fce1fa1bdc91
child 59220 72e15d757e6c
permissions -rw-r--r--
8220312: Implementation: NUMA-Aware Memory Allocation for G1, Logging (3/3) Reviewed-by: kbarrett, sjohanss, tschatzl
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
/*
53985
0da5c17f5e43 8219747: Remove g1_ prefix to g1_remset and g1_policy members in G1CollectedHeap
tschatzl
parents: 53116
diff changeset
     2
 * Copyright (c) 2001, 2019, 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"
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 53987
diff changeset
    26
#include "gc/g1/g1Arguments.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30157
diff changeset
    27
#include "gc/g1/g1CollectedHeap.inline.hpp"
47789
a77a7d3bc4f6 8149127: Rename g1/concurrentMarkThread.* to g1/g1ConcurrentMarkThread.*
tschatzl
parents: 47216
diff changeset
    28
#include "gc/g1/g1ConcurrentRefine.hpp"
59062
6530de931b8e 8220312: Implementation: NUMA-Aware Memory Allocation for G1, Logging (3/3)
sangheki
parents: 59060
diff changeset
    29
#include "gc/g1/g1NUMAStats.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30157
diff changeset
    30
#include "gc/g1/heapRegion.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30157
diff changeset
    31
#include "gc/g1/heapRegionManager.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30157
diff changeset
    32
#include "gc/g1/heapRegionSet.inline.hpp"
53116
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 52594
diff changeset
    33
#include "gc/g1/heterogeneousHeapRegionManager.hpp"
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
    34
#include "logging/logStream.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    35
#include "memory/allocation.hpp"
52576
367ca5f32505 8213829: Remove circular dependency between g1CollectedHeap and g1ConcurrentMark
manc
parents: 51496
diff changeset
    36
#include "utilities/bitMap.inline.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    37
51496
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    38
class MasterFreeRegionListChecker : public HeapRegionSetChecker {
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    39
public:
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    40
  void check_mt_safety() {
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    41
    // Master Free List MT safety protocol:
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    42
    // (a) If we're at a safepoint, operations on the master free list
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    43
    // should be invoked by either the VM thread (which will serialize
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    44
    // them) or by the GC workers while holding the
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    45
    // FreeList_lock.
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    46
    // (b) If we're not at a safepoint, operations on the master free
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    47
    // list should be invoked while holding the Heap_lock.
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    48
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    49
    if (SafepointSynchronize::is_at_safepoint()) {
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    50
      guarantee(Thread::current()->is_VM_thread() ||
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    51
                FreeList_lock->owned_by_self(), "master free list MT safety protocol at a safepoint");
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    52
    } else {
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    53
      guarantee(Heap_lock->owned_by_self(), "master free list MT safety protocol outside a safepoint");
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    54
    }
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    55
  }
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    56
  bool is_correct_type(HeapRegion* hr) { return hr->is_free(); }
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    57
  const char* get_description() { return "Free Regions"; }
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    58
};
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    59
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    60
HeapRegionManager::HeapRegionManager() :
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    61
  _bot_mapper(NULL),
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    62
  _cardtable_mapper(NULL),
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    63
  _card_counts_mapper(NULL),
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    64
  _available_map(mtGC),
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    65
  _num_committed(0),
53116
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 52594
diff changeset
    66
  _allocated_heapregions_length(0),
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 52594
diff changeset
    67
  _regions(), _heap_mapper(NULL),
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 52594
diff changeset
    68
  _prev_bitmap_mapper(NULL),
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 52594
diff changeset
    69
  _next_bitmap_mapper(NULL),
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 52594
diff changeset
    70
  _free_list("Free list", new MasterFreeRegionListChecker())
51496
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    71
{ }
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 48969
diff changeset
    72
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 53987
diff changeset
    73
HeapRegionManager* HeapRegionManager::create_manager(G1CollectedHeap* heap) {
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 53987
diff changeset
    74
  if (G1Arguments::is_heterogeneous_heap()) {
55161
1a7f82c98eee 8224247: AllocateOldGenAt fires assertion failure
kkharbas
parents: 54678
diff changeset
    75
    return new HeterogeneousHeapRegionManager((uint)(G1Arguments::heap_max_size_bytes() / HeapRegion::GrainBytes) /*heap size as num of regions*/);
53116
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 52594
diff changeset
    76
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 52594
diff changeset
    77
  return new HeapRegionManager();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 52594
diff changeset
    78
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 52594
diff changeset
    79
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
    80
void HeapRegionManager::initialize(G1RegionToSpaceMapper* heap_storage,
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    81
                               G1RegionToSpaceMapper* prev_bitmap,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    82
                               G1RegionToSpaceMapper* next_bitmap,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    83
                               G1RegionToSpaceMapper* bot,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    84
                               G1RegionToSpaceMapper* cardtable,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    85
                               G1RegionToSpaceMapper* card_counts) {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    86
  _allocated_heapregions_length = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
    87
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    88
  _heap_mapper = heap_storage;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    89
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    90
  _prev_bitmap_mapper = prev_bitmap;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    91
  _next_bitmap_mapper = next_bitmap;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    92
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    93
  _bot_mapper = bot;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    94
  _cardtable_mapper = cardtable;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    95
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    96
  _card_counts_mapper = card_counts;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    97
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    98
  MemRegion reserved = heap_storage->reserved();
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
    99
  _regions.initialize(reserved.start(), reserved.end(), HeapRegion::GrainBytes);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   100
38177
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 35079
diff changeset
   101
  _available_map.initialize(_regions.length());
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   102
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   103
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   104
bool HeapRegionManager::is_available(uint region) const {
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   105
  return _available_map.at(region);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   106
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   107
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   108
HeapRegion* HeapRegionManager::allocate_free_region(HeapRegionType type, uint requested_node_index) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   109
  HeapRegion* hr = NULL;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   110
  bool from_head = !type.is_young();
59062
6530de931b8e 8220312: Implementation: NUMA-Aware Memory Allocation for G1, Logging (3/3)
sangheki
parents: 59060
diff changeset
   111
  G1NUMA* numa = G1NUMA::numa();
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   112
59062
6530de931b8e 8220312: Implementation: NUMA-Aware Memory Allocation for G1, Logging (3/3)
sangheki
parents: 59060
diff changeset
   113
  if (requested_node_index != G1NUMA::AnyNodeIndex && numa->is_enabled()) {
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   114
    // Try to allocate with requested node index.
59062
6530de931b8e 8220312: Implementation: NUMA-Aware Memory Allocation for G1, Logging (3/3)
sangheki
parents: 59060
diff changeset
   115
    hr = _free_list.remove_region_with_node_index(from_head, requested_node_index);
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   116
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   117
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   118
  if (hr == NULL) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   119
    // If there's a single active node or we did not get a region from our requested node,
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   120
    // try without requested node index.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   121
    hr = _free_list.remove_region(from_head);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   122
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   123
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   124
  if (hr != NULL) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   125
    assert(hr->next() == NULL, "Single region should not have next");
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   126
    assert(is_available(hr->hrm_index()), "Must be committed");
59062
6530de931b8e 8220312: Implementation: NUMA-Aware Memory Allocation for G1, Logging (3/3)
sangheki
parents: 59060
diff changeset
   127
6530de931b8e 8220312: Implementation: NUMA-Aware Memory Allocation for G1, Logging (3/3)
sangheki
parents: 59060
diff changeset
   128
    if (numa->is_enabled() && hr->node_index() < numa->num_active_nodes()) {
6530de931b8e 8220312: Implementation: NUMA-Aware Memory Allocation for G1, Logging (3/3)
sangheki
parents: 59060
diff changeset
   129
      numa->update_statistics(G1NUMAStats::NewRegionAlloc, requested_node_index, hr->node_index());
6530de931b8e 8220312: Implementation: NUMA-Aware Memory Allocation for G1, Logging (3/3)
sangheki
parents: 59060
diff changeset
   130
    }
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   131
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   132
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   133
  return hr;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   134
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   135
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   136
#ifdef ASSERT
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   137
bool HeapRegionManager::is_free(HeapRegion* hr) const {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   138
  return _free_list.contains(hr);
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
#endif
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   141
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   142
HeapRegion* HeapRegionManager::new_heap_region(uint hrm_index) {
26839
021bfc544c6f 8057658: Enable G1 FullGC extensions
sjohanss
parents: 26321
diff changeset
   143
  G1CollectedHeap* g1h = G1CollectedHeap::heap();
021bfc544c6f 8057658: Enable G1 FullGC extensions
sjohanss
parents: 26321
diff changeset
   144
  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
   145
  MemRegion mr(bottom, bottom + HeapRegion::GrainWords);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   146
  assert(reserved().contains(mr), "invariant");
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31592
diff changeset
   147
  return g1h->new_heap_region(hrm_index, mr);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   148
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   149
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 41081
diff changeset
   150
void HeapRegionManager::commit_regions(uint index, size_t num_regions, WorkGang* pretouch_gang) {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   151
  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
   152
  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
   153
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   154
  _num_committed += (uint)num_regions;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   155
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 41081
diff changeset
   156
  _heap_mapper->commit_regions(index, num_regions, pretouch_gang);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   157
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   158
  // Also commit auxiliary data
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 41081
diff changeset
   159
  _prev_bitmap_mapper->commit_regions(index, num_regions, pretouch_gang);
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 41081
diff changeset
   160
  _next_bitmap_mapper->commit_regions(index, num_regions, pretouch_gang);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   161
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 41081
diff changeset
   162
  _bot_mapper->commit_regions(index, num_regions, pretouch_gang);
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 41081
diff changeset
   163
  _cardtable_mapper->commit_regions(index, num_regions, pretouch_gang);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   164
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 41081
diff changeset
   165
  _card_counts_mapper->commit_regions(index, num_regions, pretouch_gang);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   166
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   167
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   168
void HeapRegionManager::uncommit_regions(uint start, size_t num_regions) {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   169
  guarantee(num_regions >= 1, "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
   170
  guarantee(_num_committed >= num_regions, "pre-condition");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   171
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   172
  // Reset node index to distinguish with committed regions.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   173
  for (uint i = start; i < start + num_regions; i++) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   174
    at(i)->set_node_index(G1NUMA::UnknownNodeIndex);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   175
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   176
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   177
  // Print before uncommitting.
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   178
  if (G1CollectedHeap::heap()->hr_printer()->is_active()) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   179
    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
   180
      HeapRegion* hr = at(i);
35079
edab77f91231 8145301: Improve and unify the printout format for the g1HRPrinter.
david
parents: 33786
diff changeset
   181
      G1CollectedHeap::heap()->hr_printer()->uncommit(hr);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   182
    }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   183
  }
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   184
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   185
  _num_committed -= (uint)num_regions;
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   186
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   187
  _available_map.par_clear_range(start, start + num_regions, BitMap::unknown_range);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   188
  _heap_mapper->uncommit_regions(start, num_regions);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   189
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   190
  // Also uncommit auxiliary data
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   191
  _prev_bitmap_mapper->uncommit_regions(start, num_regions);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   192
  _next_bitmap_mapper->uncommit_regions(start, num_regions);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   193
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   194
  _bot_mapper->uncommit_regions(start, num_regions);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   195
  _cardtable_mapper->uncommit_regions(start, num_regions);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   196
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   197
  _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
   198
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   199
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 41081
diff changeset
   200
void HeapRegionManager::make_regions_available(uint start, uint num_regions, WorkGang* pretouch_gang) {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   201
  guarantee(num_regions > 0, "No point in calling this for zero regions");
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 41081
diff changeset
   202
  commit_regions(start, num_regions, pretouch_gang);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   203
  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
   204
    if (_regions.get_by_index(i) == NULL) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   205
      HeapRegion* new_hr = new_heap_region(i);
41081
286019ba662d 8164948: Initializing stores of HeapRegions are not ordered with regards to their use in G1ConcurrentMark
tschatzl
parents: 38177
diff changeset
   206
      OrderAccess::storestore();
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   207
      _regions.set_by_index(i, new_hr);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   208
      _allocated_heapregions_length = MAX2(_allocated_heapregions_length, i + 1);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   209
    }
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   210
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   211
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   212
  _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
   213
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   214
  for (uint i = start; i < start + num_regions; i++) {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   215
    assert(is_available(i), "Just made region %u available but is apparently not.", i);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   216
    HeapRegion* hr = at(i);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   217
    if (G1CollectedHeap::heap()->hr_printer()->is_active()) {
35079
edab77f91231 8145301: Improve and unify the printout format for the g1HRPrinter.
david
parents: 33786
diff changeset
   218
      G1CollectedHeap::heap()->hr_printer()->commit(hr);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   219
    }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   220
    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
   221
    MemRegion mr(bottom, bottom + HeapRegion::GrainWords);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   222
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   223
    hr->initialize(mr);
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   224
    hr->set_node_index(G1NUMA::numa()->index_for_region(hr));
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   225
    insert_into_free_list(at(i));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   226
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   227
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   228
29685
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   229
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
   230
  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
   231
    _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
   232
    _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
   233
    _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
   234
    _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
   235
    _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
   236
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   237
  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
   238
    _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
   239
    _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
   240
    _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
   241
    _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
   242
    _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
   243
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   244
  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
   245
}
c19484601161 8061715: gc/g1/TestShrinkAuxiliaryData15.java fails with java.lang.RuntimeException: heap decommit failed - after > before
azakharov
parents: 27905
diff changeset
   246
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 41081
diff changeset
   247
uint HeapRegionManager::expand_by(uint num_regions, WorkGang* pretouch_workers) {
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 41081
diff changeset
   248
  return expand_at(0, num_regions, pretouch_workers);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   249
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   250
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 41081
diff changeset
   251
uint HeapRegionManager::expand_at(uint start, uint num_regions, WorkGang* pretouch_workers) {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   252
  if (num_regions == 0) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   253
    return 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   254
  }
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   255
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   256
  uint cur = start;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   257
  uint idx_last_found = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   258
  uint num_last_found = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   259
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   260
  uint expanded = 0;
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   261
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   262
  while (expanded < num_regions &&
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   263
         (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
   264
    uint to_expand = MIN2(num_regions - expanded, num_last_found);
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 41081
diff changeset
   265
    make_regions_available(idx_last_found, to_expand, pretouch_workers);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   266
    expanded += to_expand;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   267
    cur = idx_last_found + num_last_found + 1;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   268
  }
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   269
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   270
  verify_optional();
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   271
  return expanded;
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   272
}
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   273
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   274
uint HeapRegionManager::expand_on_preferred_node(uint preferred_index) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   275
  uint expand_candidate = UINT_MAX;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   276
  for (uint i = 0; i < max_length(); i++) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   277
    if (is_available(i)) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   278
      // Already in use continue
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   279
      continue;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   280
    }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   281
    // Always save the candidate so we can expand later on.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   282
    expand_candidate = i;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   283
    if (is_on_preferred_index(expand_candidate, preferred_index)) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   284
      // We have found a candidate on the preffered node, break.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   285
      break;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   286
    }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   287
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   288
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   289
  if (expand_candidate == UINT_MAX) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   290
     // No regions left, expand failed.
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   291
    return 0;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   292
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   293
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   294
  make_regions_available(expand_candidate, 1, NULL);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   295
  return 1;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   296
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   297
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   298
bool HeapRegionManager::is_on_preferred_index(uint region_index, uint preferred_node_index) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   299
  uint region_node_index = G1NUMA::numa()->preferred_node_index_for_index(region_index);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   300
  return region_node_index == preferred_node_index;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   301
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 58084
diff changeset
   302
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   303
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
   304
  uint found = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   305
  size_t length_found = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   306
  uint cur = 0;
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   307
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   308
  while (length_found < num && cur < max_length()) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   309
    HeapRegion* hr = _regions.get_by_index(cur);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   310
    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
   311
      // 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
   312
      length_found++;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   313
    } else {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   314
      // 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
   315
      found = cur + 1;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   316
      length_found = 0;
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   317
    }
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   318
    cur++;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   319
  }
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   320
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   321
  if (length_found == num) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   322
    for (uint i = found; i < (found + num); i++) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   323
      HeapRegion* hr = _regions.get_by_index(i);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   324
      // sanity check
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   325
      guarantee((!empty_only && !is_available(i)) || (is_available(i) && hr != NULL && hr->is_empty()),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   326
                "Found region sequence starting at " UINT32_FORMAT ", length " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   327
                " that is not empty at " UINT32_FORMAT ". Hr is " PTR_FORMAT, found, num, i, p2i(hr));
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   328
    }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   329
    return found;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   330
  } else {
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   331
    return G1_NO_HRM_INDEX;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   332
  }
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   333
}
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   334
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   335
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
   336
  guarantee(r != NULL, "Start region must be a valid region");
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   337
  guarantee(is_available(r->hrm_index()), "Trying to iterate starting from region %u which is not in the heap", r->hrm_index());
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   338
  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
   339
    HeapRegion* hr = _regions.get_by_index(i);
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   340
    if (is_available(i)) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   341
      return hr;
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   342
    }
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents: 7904
diff changeset
   343
  }
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   344
  return NULL;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   345
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   346
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   347
void HeapRegionManager::iterate(HeapRegionClosure* blk) const {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   348
  uint len = max_length();
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   349
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   350
  for (uint i = 0; i < len; i++) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   351
    if (!is_available(i)) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   352
      continue;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   353
    }
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   354
    guarantee(at(i) != NULL, "Tried to access region %u that has a NULL HeapRegion*", i);
48969
jwilhelm
parents: 48890
diff changeset
   355
    bool res = blk->do_heap_region(at(i));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   356
    if (res) {
48969
jwilhelm
parents: 48890
diff changeset
   357
      blk->set_incomplete();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   358
      return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   359
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   360
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   361
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   362
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   363
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
   364
  guarantee(res_idx != NULL, "checking");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   365
  guarantee(start_idx <= (max_length() + 1), "checking");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   366
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   367
  uint num_regions = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   368
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   369
  uint cur = start_idx;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   370
  while (cur < max_length() && is_available(cur)) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   371
    cur++;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   372
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   373
  if (cur == max_length()) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   374
    return num_regions;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   375
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   376
  *res_idx = cur;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   377
  while (cur < max_length() && !is_available(cur)) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   378
    cur++;
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
  num_regions = cur - *res_idx;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   381
#ifdef ASSERT
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   382
  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
   383
    assert(!is_available(i), "just checking");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   384
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   385
  assert(cur == max_length() || num_regions == 0 || is_available(cur),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   386
         "The region at the current position %u must be available or at the end of the heap.", cur);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   387
#endif
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   388
  return num_regions;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   389
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   390
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   391
uint HeapRegionManager::find_highest_free(bool* expanded) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   392
  // Loop downwards from the highest region index, looking for an
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   393
  // entry which is either free or not yet committed.  If not yet
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   394
  // committed, expand_at that index.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   395
  uint curr = max_length() - 1;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   396
  while (true) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   397
    HeapRegion *hr = _regions.get_by_index(curr);
52594
4d8a023c2a03 8213898: CDS dumping of springboot asserts in G1ArchiveAllocator::alloc_new_region
jiangli
parents: 52576
diff changeset
   398
    if (hr == NULL || !is_available(curr)) {
42595
b1ae41a4eae9 8169703: G1 crashes with guarantee(pretouch_gang != NULL) failed: No pretouch gang specified
tschatzl
parents: 41311
diff changeset
   399
      uint res = expand_at(curr, 1, NULL);
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   400
      if (res == 1) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   401
        *expanded = true;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   402
        return curr;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   403
      }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   404
    } else {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   405
      if (hr->is_free()) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   406
        *expanded = false;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   407
        return curr;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   408
      }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   409
    }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   410
    if (curr == 0) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   411
      return G1_NO_HRM_INDEX;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   412
    }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   413
    curr--;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   414
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   415
}
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   416
42595
b1ae41a4eae9 8169703: G1 crashes with guarantee(pretouch_gang != NULL) failed: No pretouch gang specified
tschatzl
parents: 41311
diff changeset
   417
bool HeapRegionManager::allocate_containing_regions(MemRegion range, size_t* commit_count, WorkGang* pretouch_workers) {
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   418
  size_t commits = 0;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   419
  uint start_index = (uint)_regions.get_index_by_address(range.start());
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   420
  uint last_index = (uint)_regions.get_index_by_address(range.last());
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   421
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   422
  // Ensure that each G1 region in the range is free, returning false if not.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   423
  // Commit those that are not yet available, and keep count.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   424
  for (uint curr_index = start_index; curr_index <= last_index; curr_index++) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   425
    if (!is_available(curr_index)) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   426
      commits++;
42595
b1ae41a4eae9 8169703: G1 crashes with guarantee(pretouch_gang != NULL) failed: No pretouch gang specified
tschatzl
parents: 41311
diff changeset
   427
      expand_at(curr_index, 1, pretouch_workers);
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   428
    }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   429
    HeapRegion* curr_region  = _regions.get_by_index(curr_index);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   430
    if (!curr_region->is_free()) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   431
      return false;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   432
    }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   433
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   434
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   435
  allocate_free_regions_starting_at(start_index, (last_index - start_index) + 1);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   436
  *commit_count = commits;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   437
  return true;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   438
}
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   439
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47789
diff changeset
   440
void HeapRegionManager::par_iterate(HeapRegionClosure* blk, HeapRegionClaimer* hrclaimer, const uint start_index) const {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   441
  // 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
   442
  // are currently not committed.
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   443
  // 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
   444
  // 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
   445
  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
   446
  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
   447
    const uint index = (start_index + count) % n_regions;
29580
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 27905
diff changeset
   448
    assert(index < n_regions, "sanity");
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   449
    // Skip over unavailable regions
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   450
    if (!is_available(index)) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   451
      continue;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   452
    }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   453
    HeapRegion* r = _regions.get_by_index(index);
33786
ac8da6513351 8139867: Change how startsHumongous and continuesHumongous regions work in G1.
david
parents: 33105
diff changeset
   454
    // We'll ignore regions already claimed.
27885
7786b3940066 8062943: REDO - Parallelize clearing the next mark bitmap
mlarsson
parents: 27009
diff changeset
   455
    // 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
   456
    // 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
   457
    // 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
   458
    // humongous status.
33786
ac8da6513351 8139867: Change how startsHumongous and continuesHumongous regions work in G1.
david
parents: 33105
diff changeset
   459
    if (hrclaimer->is_region_claimed(index)) {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   460
      continue;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   461
    }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   462
    // 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
   463
    if (!hrclaimer->claim_region(index)) {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   464
      continue;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   465
    }
48969
jwilhelm
parents: 48890
diff changeset
   466
    bool res = blk->do_heap_region(r);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   467
    if (res) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   468
      return;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   469
    }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   470
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   471
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   472
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   473
uint HeapRegionManager::shrink_by(uint num_regions_to_remove) {
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   474
  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
   475
  assert(length() <= _allocated_heapregions_length, "invariant");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   476
  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
   477
  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
   478
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   479
  if (num_regions_to_remove == 0) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   480
    return 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   481
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   482
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   483
  uint removed = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   484
  uint cur = _allocated_heapregions_length - 1;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   485
  uint idx_last_found = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   486
  uint num_last_found = 0;
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   487
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   488
  while ((removed < num_regions_to_remove) &&
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 26157
diff changeset
   489
      (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
   490
    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
   491
32589
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 32390
diff changeset
   492
    shrink_at(idx_last_found + num_last_found - to_remove, to_remove);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   493
32390
b0f6868d46ee 8133456: HeapRegionManager::shrink_by() iterates suboptimally across regions
tschatzl
parents: 32185
diff changeset
   494
    cur = idx_last_found;
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   495
    removed += to_remove;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   496
  }
17323
cc153b745ed5 8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents: 13195
diff changeset
   497
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   498
  verify_optional();
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   499
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   500
  return removed;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   501
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   502
32589
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 32390
diff changeset
   503
void HeapRegionManager::shrink_at(uint index, size_t num_regions) {
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 32390
diff changeset
   504
#ifdef ASSERT
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 32390
diff changeset
   505
  for (uint i = index; i < (index + num_regions); i++) {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   506
    assert(is_available(i), "Expected available region at index %u", i);
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   507
    assert(at(i)->is_empty(), "Expected empty region at index %u", i);
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   508
    assert(at(i)->is_free(), "Expected free region at index %u", i);
32589
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 32390
diff changeset
   509
  }
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 32390
diff changeset
   510
#endif
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 32390
diff changeset
   511
  uncommit_regions(index, num_regions);
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 32390
diff changeset
   512
}
f86fb16fcab0 8131734: assert(!is_null(v)) failed: narrow klass value can never be zero with -Xshared:auto
jiangli
parents: 32390
diff changeset
   513
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   514
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
   515
  guarantee(start_idx < _allocated_heapregions_length, "checking");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   516
  guarantee(res_idx != NULL, "checking");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   517
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   518
  uint num_regions_found = 0;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   519
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   520
  jlong cur = start_idx;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   521
  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
   522
    cur--;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   523
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   524
  if (cur == -1) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   525
    return num_regions_found;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   526
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   527
  jlong old_cur = cur;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   528
  // cur indexes the first empty region
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   529
  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
   530
    cur--;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   531
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   532
  *res_idx = cur + 1;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   533
  num_regions_found = old_cur - cur;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   534
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   535
#ifdef ASSERT
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   536
  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
   537
    assert(at(i)->is_empty(), "just checking");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   538
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   539
#endif
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   540
  return num_regions_found;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   541
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   542
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   543
void HeapRegionManager::verify() {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   544
  guarantee(length() <= _allocated_heapregions_length,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   545
            "invariant: _length: %u _allocated_length: %u",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   546
            length(), _allocated_heapregions_length);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   547
  guarantee(_allocated_heapregions_length <= max_length(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   548
            "invariant: _allocated_length: %u _max_length: %u",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   549
            _allocated_heapregions_length, max_length());
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   550
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   551
  bool prev_committed = true;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   552
  uint num_committed = 0;
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   553
  HeapWord* prev_end = heap_bottom();
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   554
  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
   555
    if (!is_available(i)) {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   556
      prev_committed = false;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   557
      continue;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   558
    }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   559
    num_committed++;
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents: 17323
diff changeset
   560
    HeapRegion* hr = _regions.get_by_index(i);
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   561
    guarantee(hr != NULL, "invariant: i: %u", i);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   562
    guarantee(!prev_committed || hr->bottom() == prev_end,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   563
              "invariant i: %u " HR_FORMAT " prev_end: " PTR_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   564
              i, HR_FORMAT_PARAMS(hr), p2i(prev_end));
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   565
    guarantee(hr->hrm_index() == i,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   566
              "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
   567
    // Asserts will fire if i is >= _length
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   568
    HeapWord* addr = hr->bottom();
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   569
    guarantee(addr_to_region(addr) == hr, "sanity");
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   570
    // 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
   571
    // 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
   572
    // but not put into a region set.
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   573
    prev_committed = true;
33786
ac8da6513351 8139867: Change how startsHumongous and continuesHumongous regions work in G1.
david
parents: 33105
diff changeset
   574
    prev_end = hr->end();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   575
  }
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   576
  for (uint i = _allocated_heapregions_length; i < max_length(); i++) {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   577
    guarantee(_regions.get_by_index(i) == NULL, "invariant i: %u", i);
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   578
  }
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   579
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   580
  guarantee(num_committed == _num_committed, "Found %u committed regions, but should be %u", num_committed, _num_committed);
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   581
  _free_list.verify();
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   582
}
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   583
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   584
#ifndef PRODUCT
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   585
void HeapRegionManager::verify_optional() {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   586
  verify();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   587
}
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8680
diff changeset
   588
#endif // PRODUCT
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 24424
diff changeset
   589
27009
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   590
HeapRegionClaimer::HeapRegionClaimer(uint n_workers) :
53116
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 52594
diff changeset
   591
    _n_workers(n_workers), _n_regions(G1CollectedHeap::heap()->_hrm->_allocated_heapregions_length), _claims(NULL) {
27009
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   592
  assert(n_workers > 0, "Need at least one worker.");
41311
92d8edabd52c 8165858: heapRegionManager is missing volatile specifier for _claims.
eosterlund
parents: 41178
diff changeset
   593
  uint* new_claims = NEW_C_HEAP_ARRAY(uint, _n_regions, mtGC);
92d8edabd52c 8165858: heapRegionManager is missing volatile specifier for _claims.
eosterlund
parents: 41178
diff changeset
   594
  memset(new_claims, Unclaimed, sizeof(*_claims) * _n_regions);
92d8edabd52c 8165858: heapRegionManager is missing volatile specifier for _claims.
eosterlund
parents: 41178
diff changeset
   595
  _claims = new_claims;
27009
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   596
}
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   597
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   598
HeapRegionClaimer::~HeapRegionClaimer() {
58084
cddef3bde924 8230398: Remove NULL checks before FREE_C_HEAP_ARRAY
lkorinth
parents: 55161
diff changeset
   599
  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
   600
}
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   601
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47789
diff changeset
   602
uint HeapRegionClaimer::offset_for_worker(uint worker_id) const {
27009
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   603
  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
   604
  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
   605
}
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   606
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   607
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
   608
  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
   609
  return _claims[region_index] == Claimed;
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   610
}
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   611
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   612
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
   613
  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
   614
  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
   615
  return old_val == Unclaimed;
e7e723732b6b 8058298: Separate heap region iterator claim values from the data structures iterated over
mlarsson
parents: 26846
diff changeset
   616
}