src/hotspot/share/gc/g1/g1Allocator.cpp
author sangheki
Wed, 13 Nov 2019 10:49:32 -0800
changeset 59061 df6f2350edfa
parent 59060 fce1fa1bdc91
child 59221 cc3a82fc7bcb
permissions -rw-r--r--
8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3) Reviewed-by: kbarrett, sjohanss, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     1
/*
53411
aa87f38fcba2 8217374: Rename G1 EvacuationInfo class to G1EvacuationInfo
tschatzl
parents: 52875
diff changeset
     2
 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     4
 *
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     7
 * published by the Free Software Foundation.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     8
 *
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    13
 * accompanied this code).
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    14
 *
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    18
 *
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    21
 * questions.
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    22
 *
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    23
 */
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    24
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    25
#include "precompiled.hpp"
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
    26
#include "gc/g1/g1Allocator.inline.hpp"
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
    27
#include "gc/g1/g1AllocRegion.inline.hpp"
34230
b9c64b7c06c9 8141570: Fix Zero interpreter build for --disable-precompiled-headers
coleenp
parents: 34146
diff changeset
    28
#include "gc/g1/g1EvacStats.inline.hpp"
53411
aa87f38fcba2 8217374: Rename G1 EvacuationInfo class to G1EvacuationInfo
tschatzl
parents: 52875
diff changeset
    29
#include "gc/g1/g1EvacuationInfo.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    30
#include "gc/g1/g1CollectedHeap.inline.hpp"
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    31
#include "gc/g1/g1NUMA.hpp"
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49333
diff changeset
    32
#include "gc/g1/g1Policy.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    33
#include "gc/g1/heapRegion.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    34
#include "gc/g1/heapRegionSet.inline.hpp"
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49333
diff changeset
    35
#include "gc/g1/heapRegionType.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    36
#include "utilities/align.hpp"
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    37
49713
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
    38
G1Allocator::G1Allocator(G1CollectedHeap* heap) :
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
    39
  _g1h(heap),
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    40
  _numa(heap->numa()),
34146
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33803
diff changeset
    41
  _survivor_is_full(false),
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33803
diff changeset
    42
  _old_is_full(false),
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    43
  _num_alloc_regions(_numa->num_active_nodes()),
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    44
  _mutator_alloc_regions(NULL),
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
    45
  _survivor_gc_alloc_regions(NULL),
54843
25c329958c70 8200545: Improve filter for enqueued deferred cards
tschatzl
parents: 54623
diff changeset
    46
  _old_gc_alloc_region(heap->alloc_buffer_stats(G1HeapRegionAttr::Old)),
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 49945
diff changeset
    47
  _retained_old_gc_alloc_region(NULL) {
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    48
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    49
  _mutator_alloc_regions = NEW_C_HEAP_ARRAY(MutatorAllocRegion, _num_alloc_regions, mtGC);
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
    50
  _survivor_gc_alloc_regions = NEW_C_HEAP_ARRAY(SurvivorGCAllocRegion, _num_alloc_regions, mtGC);
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
    51
  G1EvacStats* stat = heap->alloc_buffer_stats(G1HeapRegionAttr::Young);
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
    52
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    53
  for (uint i = 0; i < _num_alloc_regions; i++) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    54
    ::new(_mutator_alloc_regions + i) MutatorAllocRegion(i);
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
    55
    ::new(_survivor_gc_alloc_regions + i) SurvivorGCAllocRegion(stat, i);
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    56
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    57
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    58
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    59
G1Allocator::~G1Allocator() {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    60
  for (uint i = 0; i < _num_alloc_regions; i++) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    61
    _mutator_alloc_regions[i].~MutatorAllocRegion();
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
    62
    _survivor_gc_alloc_regions[i].~SurvivorGCAllocRegion();
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    63
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    64
  FREE_C_HEAP_ARRAY(MutatorAllocRegion, _mutator_alloc_regions);
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
    65
  FREE_C_HEAP_ARRAY(SurvivorGCAllocRegion, _survivor_gc_alloc_regions);
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32377
diff changeset
    66
}
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32377
diff changeset
    67
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    68
#ifdef ASSERT
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    69
bool G1Allocator::has_mutator_alloc_region() {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    70
  uint node_index = current_node_index();
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    71
  return mutator_alloc_region(node_index)->get() != NULL;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    72
}
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    73
#endif
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    74
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    75
void G1Allocator::init_mutator_alloc_regions() {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    76
  for (uint i = 0; i < _num_alloc_regions; i++) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    77
    assert(mutator_alloc_region(i)->get() == NULL, "pre-condition");
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    78
    mutator_alloc_region(i)->init();
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    79
  }
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    80
}
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    81
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    82
void G1Allocator::release_mutator_alloc_regions() {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    83
  for (uint i = 0; i < _num_alloc_regions; i++) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    84
    mutator_alloc_region(i)->release();
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    85
    assert(mutator_alloc_region(i)->get() == NULL, "post-condition");
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
    86
  }
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    87
}
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    88
49713
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
    89
bool G1Allocator::is_retained_old_region(HeapRegion* hr) {
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
    90
  return _retained_old_gc_alloc_region == hr;
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
    91
}
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
    92
53411
aa87f38fcba2 8217374: Rename G1 EvacuationInfo class to G1EvacuationInfo
tschatzl
parents: 52875
diff changeset
    93
void G1Allocator::reuse_retained_old_region(G1EvacuationInfo& evacuation_info,
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    94
                                            OldGCAllocRegion* old,
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    95
                                            HeapRegion** retained_old) {
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    96
  HeapRegion* retained_region = *retained_old;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
    97
  *retained_old = NULL;
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
    98
  assert(retained_region == NULL || !retained_region->is_archive(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
    99
         "Archive region should not be alloc region (index %u)", retained_region->hrm_index());
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   100
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   101
  // We will discard the current GC alloc region if:
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   102
  // a) it's in the collection set (it can happen!),
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   103
  // b) it's already full (no point in using it),
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   104
  // c) it's empty (this means that it was emptied during
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   105
  // a cleanup and it should be on the free list now), or
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   106
  // d) it's humongous (this means that it was emptied
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   107
  // during a cleanup and was added to the free list, but
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   108
  // has been subsequently used to allocate a humongous
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   109
  // object that may be less than the region size).
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   110
  if (retained_region != NULL &&
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   111
      !retained_region->in_collection_set() &&
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   112
      !(retained_region->top() == retained_region->end()) &&
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   113
      !retained_region->is_empty() &&
26846
7d4376f8560e 8058495: G1: normalize names for isHumongous() and friends
tonyp
parents: 26837
diff changeset
   114
      !retained_region->is_humongous()) {
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   115
    // The retained region was added to the old region set when it was
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   116
    // retired. We have to remove it now, since we don't allow regions
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   117
    // we allocate to in the region sets. We'll re-add it later, when
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   118
    // it's retired again.
32193
862a68285b1e 8133042: Remove some direct accesses of G1Allocator to G1CollectedHeap members
tschatzl
parents: 32185
diff changeset
   119
    _g1h->old_set_remove(retained_region);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   120
    old->set(retained_region);
32193
862a68285b1e 8133042: Remove some direct accesses of G1Allocator to G1CollectedHeap members
tschatzl
parents: 32185
diff changeset
   121
    _g1h->hr_printer()->reuse(retained_region);
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   122
    evacuation_info.set_alloc_regions_used_before(retained_region->used());
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   123
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   124
}
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   125
53411
aa87f38fcba2 8217374: Rename G1 EvacuationInfo class to G1EvacuationInfo
tschatzl
parents: 52875
diff changeset
   126
void G1Allocator::init_gc_alloc_regions(G1EvacuationInfo& evacuation_info) {
49333
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49323
diff changeset
   127
  assert_at_safepoint_on_vm_thread();
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   128
34146
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33803
diff changeset
   129
  _survivor_is_full = false;
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33803
diff changeset
   130
  _old_is_full = false;
32377
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32193
diff changeset
   131
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   132
  for (uint i = 0; i < _num_alloc_regions; i++) {
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   133
    survivor_gc_alloc_region(i)->init();
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   134
  }
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   135
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   136
  _old_gc_alloc_region.init();
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   137
  reuse_retained_old_region(evacuation_info,
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   138
                            &_old_gc_alloc_region,
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   139
                            &_retained_old_gc_alloc_region);
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   140
}
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   141
53411
aa87f38fcba2 8217374: Rename G1 EvacuationInfo class to G1EvacuationInfo
tschatzl
parents: 52875
diff changeset
   142
void G1Allocator::release_gc_alloc_regions(G1EvacuationInfo& evacuation_info) {
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   143
  uint survivor_region_count = 0;
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   144
  for (uint node_index = 0; node_index < _num_alloc_regions; node_index++) {
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   145
    survivor_region_count += survivor_gc_alloc_region(node_index)->count();
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   146
    survivor_gc_alloc_region(node_index)->release();
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   147
  }
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   148
  evacuation_info.set_allocation_regions(survivor_region_count +
49323
565336327354 8198424: Remove G1AllocationContext
sjohanss
parents: 48963
diff changeset
   149
                                         old_gc_alloc_region()->count());
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   150
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   151
  // If we have an old GC alloc region to release, we'll save it in
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   152
  // _retained_old_gc_alloc_region. If we don't
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   153
  // _retained_old_gc_alloc_region will become NULL. This is what we
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   154
  // want either way so no reason to check explicitly for either
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   155
  // condition.
49323
565336327354 8198424: Remove G1AllocationContext
sjohanss
parents: 48963
diff changeset
   156
  _retained_old_gc_alloc_region = old_gc_alloc_region()->release();
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   157
}
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   158
49713
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   159
void G1Allocator::abandon_gc_alloc_regions() {
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   160
  for (uint i = 0; i < _num_alloc_regions; i++) {
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   161
    assert(survivor_gc_alloc_region(i)->get() == NULL, "pre-condition");
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   162
  }
49323
565336327354 8198424: Remove G1AllocationContext
sjohanss
parents: 48963
diff changeset
   163
  assert(old_gc_alloc_region()->get() == NULL, "pre-condition");
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   164
  _retained_old_gc_alloc_region = NULL;
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   165
}
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   166
49713
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   167
bool G1Allocator::survivor_is_full() const {
34146
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33803
diff changeset
   168
  return _survivor_is_full;
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33803
diff changeset
   169
}
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33803
diff changeset
   170
49713
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   171
bool G1Allocator::old_is_full() const {
34146
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33803
diff changeset
   172
  return _old_is_full;
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33803
diff changeset
   173
}
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33803
diff changeset
   174
49713
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   175
void G1Allocator::set_survivor_full() {
34146
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33803
diff changeset
   176
  _survivor_is_full = true;
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33803
diff changeset
   177
}
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33803
diff changeset
   178
49713
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   179
void G1Allocator::set_old_full() {
34146
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33803
diff changeset
   180
  _old_is_full = true;
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33803
diff changeset
   181
}
42523f0da397 8141280: G1ResManAllocator doesn't work with _survivor_is_full/_old_is_full
sjohanss
parents: 33803
diff changeset
   182
49323
565336327354 8198424: Remove G1AllocationContext
sjohanss
parents: 48963
diff changeset
   183
size_t G1Allocator::unsafe_max_tlab_alloc() {
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   184
  // Return the remaining space in the cur alloc region, but not less than
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   185
  // the min TLAB size.
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   186
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   187
  // Also, this value can be at most the humongous object threshold,
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   188
  // since we can't allow tlabs to grow big enough to accommodate
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   189
  // humongous objects.
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   190
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
   191
  uint node_index = current_node_index();
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
   192
  HeapRegion* hr = mutator_alloc_region(node_index)->get();
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   193
  size_t max_tlab = _g1h->max_tlab_size() * wordSize;
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   194
  if (hr == NULL) {
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   195
    return max_tlab;
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   196
  } else {
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   197
    return MIN2(MAX2(hr->free(), (size_t) MinTLABSize), max_tlab);
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   198
  }
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   199
}
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   200
49713
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   201
size_t G1Allocator::used_in_alloc_regions() {
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   202
  assert(Heap_lock->owner() != NULL, "Should be owned on this thread's behalf.");
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
   203
  size_t used = 0;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
   204
  for (uint i = 0; i < _num_alloc_regions; i++) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
   205
    used += mutator_alloc_region(i)->used_in_alloc_regions();
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
   206
  }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54843
diff changeset
   207
  return used;
49713
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   208
}
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   209
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   210
54843
25c329958c70 8200545: Improve filter for enqueued deferred cards
tschatzl
parents: 54623
diff changeset
   211
HeapWord* G1Allocator::par_allocate_during_gc(G1HeapRegionAttr dest,
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   212
                                              size_t word_size,
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   213
                                              uint node_index) {
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   214
  size_t temp = 0;
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   215
  HeapWord* result = par_allocate_during_gc(dest, word_size, word_size, &temp, node_index);
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   216
  assert(result == NULL || temp == word_size,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   217
         "Requested " SIZE_FORMAT " words, but got " SIZE_FORMAT " at " PTR_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   218
         word_size, temp, p2i(result));
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   219
  return result;
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   220
}
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   221
54843
25c329958c70 8200545: Improve filter for enqueued deferred cards
tschatzl
parents: 54623
diff changeset
   222
HeapWord* G1Allocator::par_allocate_during_gc(G1HeapRegionAttr dest,
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   223
                                              size_t min_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   224
                                              size_t desired_word_size,
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   225
                                              size_t* actual_word_size,
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   226
                                              uint node_index) {
54843
25c329958c70 8200545: Improve filter for enqueued deferred cards
tschatzl
parents: 54623
diff changeset
   227
  switch (dest.type()) {
25c329958c70 8200545: Improve filter for enqueued deferred cards
tschatzl
parents: 54623
diff changeset
   228
    case G1HeapRegionAttr::Young:
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   229
      return survivor_attempt_allocation(min_word_size, desired_word_size, actual_word_size, node_index);
54843
25c329958c70 8200545: Improve filter for enqueued deferred cards
tschatzl
parents: 54623
diff changeset
   230
    case G1HeapRegionAttr::Old:
49323
565336327354 8198424: Remove G1AllocationContext
sjohanss
parents: 48963
diff changeset
   231
      return old_attempt_allocation(min_word_size, desired_word_size, actual_word_size);
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   232
    default:
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   233
      ShouldNotReachHere();
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   234
      return NULL; // Keep some compilers happy
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   235
  }
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   236
}
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   237
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   238
HeapWord* G1Allocator::survivor_attempt_allocation(size_t min_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   239
                                                   size_t desired_word_size,
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   240
                                                   size_t* actual_word_size,
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   241
                                                   uint node_index) {
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   242
  assert(!_g1h->is_humongous(desired_word_size),
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   243
         "we should not be seeing humongous-size allocations in this path");
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   244
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   245
  HeapWord* result = survivor_gc_alloc_region(node_index)->attempt_allocation(min_word_size,
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   246
                                                                              desired_word_size,
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   247
                                                                              actual_word_size);
49323
565336327354 8198424: Remove G1AllocationContext
sjohanss
parents: 48963
diff changeset
   248
  if (result == NULL && !survivor_is_full()) {
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 53985
diff changeset
   249
    MutexLocker x(FreeList_lock, Mutex::_no_safepoint_check_flag);
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   250
    result = survivor_gc_alloc_region(node_index)->attempt_allocation_locked(min_word_size,
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   251
                                                                             desired_word_size,
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   252
                                                                             actual_word_size);
32377
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32193
diff changeset
   253
    if (result == NULL) {
49323
565336327354 8198424: Remove G1AllocationContext
sjohanss
parents: 48963
diff changeset
   254
      set_survivor_full();
32377
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32193
diff changeset
   255
    }
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   256
  }
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   257
  if (result != NULL) {
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   258
    _g1h->dirty_young_block(result, *actual_word_size);
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   259
  }
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   260
  return result;
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   261
}
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   262
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   263
HeapWord* G1Allocator::old_attempt_allocation(size_t min_word_size,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   264
                                              size_t desired_word_size,
49323
565336327354 8198424: Remove G1AllocationContext
sjohanss
parents: 48963
diff changeset
   265
                                              size_t* actual_word_size) {
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   266
  assert(!_g1h->is_humongous(desired_word_size),
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   267
         "we should not be seeing humongous-size allocations in this path");
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   268
49323
565336327354 8198424: Remove G1AllocationContext
sjohanss
parents: 48963
diff changeset
   269
  HeapWord* result = old_gc_alloc_region()->attempt_allocation(min_word_size,
565336327354 8198424: Remove G1AllocationContext
sjohanss
parents: 48963
diff changeset
   270
                                                               desired_word_size,
565336327354 8198424: Remove G1AllocationContext
sjohanss
parents: 48963
diff changeset
   271
                                                               actual_word_size);
565336327354 8198424: Remove G1AllocationContext
sjohanss
parents: 48963
diff changeset
   272
  if (result == NULL && !old_is_full()) {
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 53985
diff changeset
   273
    MutexLocker x(FreeList_lock, Mutex::_no_safepoint_check_flag);
49323
565336327354 8198424: Remove G1AllocationContext
sjohanss
parents: 48963
diff changeset
   274
    result = old_gc_alloc_region()->attempt_allocation_locked(min_word_size,
565336327354 8198424: Remove G1AllocationContext
sjohanss
parents: 48963
diff changeset
   275
                                                              desired_word_size,
565336327354 8198424: Remove G1AllocationContext
sjohanss
parents: 48963
diff changeset
   276
                                                              actual_word_size);
32377
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32193
diff changeset
   277
    if (result == NULL) {
49323
565336327354 8198424: Remove G1AllocationContext
sjohanss
parents: 48963
diff changeset
   278
      set_old_full();
32377
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32193
diff changeset
   279
    }
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   280
  }
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   281
  return result;
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   282
}
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   283
49713
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   284
uint G1PLABAllocator::calc_survivor_alignment_bytes() {
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   285
  assert(SurvivorAlignmentInBytes >= ObjectAlignmentInBytes, "sanity");
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   286
  if (SurvivorAlignmentInBytes == ObjectAlignmentInBytes) {
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   287
    // No need to align objects in the survivors differently, return 0
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   288
    // which means "survivor alignment is not used".
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   289
    return 0;
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   290
  } else {
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   291
    assert(SurvivorAlignmentInBytes > 0, "sanity");
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   292
    return SurvivorAlignmentInBytes;
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   293
  }
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   294
}
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   295
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   296
G1PLABAllocator::G1PLABAllocator(G1Allocator* allocator) :
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   297
  _g1h(G1CollectedHeap::heap()),
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   298
  _allocator(allocator),
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   299
  _survivor_alignment_bytes(calc_survivor_alignment_bytes()) {
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   300
  for (region_type_t state = 0; state < G1HeapRegionAttr::Num; state++) {
49713
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   301
    _direct_allocated[state] = 0;
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   302
    uint length = alloc_buffers_length(state);
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   303
    _alloc_buffers[state] = NEW_C_HEAP_ARRAY(PLAB*, length, mtGC);
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   304
    for (uint node_index = 0; node_index < length; node_index++) {
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   305
      _alloc_buffers[state][node_index] = new PLAB(_g1h->desired_plab_sz(state));
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   306
    }
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32377
diff changeset
   307
  }
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   308
}
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   309
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   310
G1PLABAllocator::~G1PLABAllocator() {
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   311
  for (region_type_t state = 0; state < G1HeapRegionAttr::Num; state++) {
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   312
    uint length = alloc_buffers_length(state);
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   313
    for (uint node_index = 0; node_index < length; node_index++) {
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   314
      delete _alloc_buffers[state][node_index];
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   315
    }
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   316
    FREE_C_HEAP_ARRAY(PLAB*, _alloc_buffers[state]);
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   317
  }
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   318
}
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   319
32383
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
   320
bool G1PLABAllocator::may_throw_away_buffer(size_t const allocation_word_sz, size_t const buffer_size) const {
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
   321
  return (allocation_word_sz * 100 < buffer_size * ParallelGCBufferWastePct);
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
   322
}
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
   323
54843
25c329958c70 8200545: Improve filter for enqueued deferred cards
tschatzl
parents: 54623
diff changeset
   324
HeapWord* G1PLABAllocator::allocate_direct_or_new_plab(G1HeapRegionAttr dest,
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   325
                                                       size_t word_sz,
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   326
                                                       bool* plab_refill_failed,
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   327
                                                       uint node_index) {
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49713
diff changeset
   328
  size_t plab_word_size = _g1h->desired_plab_sz(dest);
32383
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
   329
  size_t required_in_plab = PLAB::size_required_for_allocation(word_sz);
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
   330
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
   331
  // Only get a new PLAB if the allocation fits and it would not waste more than
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
   332
  // ParallelGCBufferWastePct in the existing buffer.
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
   333
  if ((required_in_plab <= plab_word_size) &&
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
   334
    may_throw_away_buffer(required_in_plab, plab_word_size)) {
bc9971c6bf2b 8067339: PLAB reallocation might result in failure to allocate object in that recently allocated PLAB
tschatzl
parents: 32379
diff changeset
   335
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   336
    PLAB* alloc_buf = alloc_buffer(dest, node_index);
29327
b539902e30f8 8073466: Remove buffer retaining functionality and clean up in ParGCAllocBuffer
tschatzl
parents: 28375
diff changeset
   337
    alloc_buf->retire();
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   338
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   339
    size_t actual_plab_size = 0;
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   340
    HeapWord* buf = _allocator->par_allocate_during_gc(dest,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   341
                                                       required_in_plab,
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   342
                                                       plab_word_size,
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   343
                                                       &actual_plab_size,
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   344
                                                       node_index);
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   345
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   346
    assert(buf == NULL || ((actual_plab_size >= required_in_plab) && (actual_plab_size <= plab_word_size)),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   347
           "Requested at minimum " SIZE_FORMAT ", desired " SIZE_FORMAT " words, but got " SIZE_FORMAT " at " PTR_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   348
           required_in_plab, plab_word_size, actual_plab_size, p2i(buf));
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   349
32377
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32193
diff changeset
   350
    if (buf != NULL) {
32389
626f27450e12 8067336: Allow that PLAB allocations at the end of regions are flexible
tschatzl
parents: 32383
diff changeset
   351
      alloc_buf->set_buf(buf, actual_plab_size);
32377
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32193
diff changeset
   352
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32193
diff changeset
   353
      HeapWord* const obj = alloc_buf->allocate(word_sz);
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   354
      assert(obj != NULL, "PLAB should have been big enough, tried to allocate "
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   355
                          SIZE_FORMAT " requiring " SIZE_FORMAT " PLAB size " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   356
                          word_sz, required_in_plab, plab_word_size);
32377
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32193
diff changeset
   357
      return obj;
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   358
    }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   359
    // Otherwise.
32377
5ee15c417d02 8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure
tschatzl
parents: 32193
diff changeset
   360
    *plab_refill_failed = true;
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   361
  }
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32377
diff changeset
   362
  // Try direct allocation.
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   363
  HeapWord* result = _allocator->par_allocate_during_gc(dest, word_sz, node_index);
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32377
diff changeset
   364
  if (result != NULL) {
54843
25c329958c70 8200545: Improve filter for enqueued deferred cards
tschatzl
parents: 54623
diff changeset
   365
    _direct_allocated[dest.type()] += word_sz;
32379
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32377
diff changeset
   366
  }
aa14adafaf0f 8073013: Add detailed information about PLAB memory usage
tschatzl
parents: 32377
diff changeset
   367
  return result;
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   368
}
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   369
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   370
void G1PLABAllocator::undo_allocation(G1HeapRegionAttr dest, HeapWord* obj, size_t word_sz, uint node_index) {
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   371
  alloc_buffer(dest, node_index)->undo_allocation(obj, word_sz);
32185
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   372
}
49a57ff2c3cb 8073052: Rename and clean up the allocation manager hierarchy in g1Allocator.?pp
tschatzl
parents: 31632
diff changeset
   373
49713
456e51e56ea2 8200169: Flatten G1Allocator class hierarchy
sjohanss
parents: 49643
diff changeset
   374
void G1PLABAllocator::flush_and_retire_stats() {
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   375
  for (region_type_t state = 0; state < G1HeapRegionAttr::Num; state++) {
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   376
    G1EvacStats* stats = _g1h->alloc_buffer_stats(state);
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   377
    for (uint node_index = 0; node_index < alloc_buffers_length(state); node_index++) {
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   378
      PLAB* const buf = alloc_buffer(state, node_index);
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   379
      if (buf != NULL) {
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   380
        buf->flush_and_retire_stats(stats);
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   381
      }
28213
b0bf57cd1e9d 8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents: 27889
diff changeset
   382
    }
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   383
    stats->add_direct_allocated(_direct_allocated[state]);
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   384
    _direct_allocated[state] = 0;
26837
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   385
  }
72a43d3841e7 8057536: Refactor G1 to allow context specific allocations
sjohanss
parents:
diff changeset
   386
}
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30275
diff changeset
   387
53846
fe95464806a7 8219096: Merge print_termination_stats code with current logging
tschatzl
parents: 53411
diff changeset
   388
size_t G1PLABAllocator::waste() const {
fe95464806a7 8219096: Merge print_termination_stats code with current logging
tschatzl
parents: 53411
diff changeset
   389
  size_t result = 0;
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   390
  for (region_type_t state = 0; state < G1HeapRegionAttr::Num; state++) {
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   391
    for (uint node_index = 0; node_index < alloc_buffers_length(state); node_index++) {
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   392
      PLAB* const buf = alloc_buffer(state, node_index);
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   393
      if (buf != NULL) {
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   394
        result += buf->waste();
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   395
      }
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30275
diff changeset
   396
    }
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30275
diff changeset
   397
  }
53846
fe95464806a7 8219096: Merge print_termination_stats code with current logging
tschatzl
parents: 53411
diff changeset
   398
  return result;
fe95464806a7 8219096: Merge print_termination_stats code with current logging
tschatzl
parents: 53411
diff changeset
   399
}
fe95464806a7 8219096: Merge print_termination_stats code with current logging
tschatzl
parents: 53411
diff changeset
   400
fe95464806a7 8219096: Merge print_termination_stats code with current logging
tschatzl
parents: 53411
diff changeset
   401
size_t G1PLABAllocator::undo_waste() const {
fe95464806a7 8219096: Merge print_termination_stats code with current logging
tschatzl
parents: 53411
diff changeset
   402
  size_t result = 0;
59061
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   403
  for (region_type_t state = 0; state < G1HeapRegionAttr::Num; state++) {
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   404
    for (uint node_index = 0; node_index < alloc_buffers_length(state); node_index++) {
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   405
      PLAB* const buf = alloc_buffer(state, node_index);
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   406
      if (buf != NULL) {
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   407
        result += buf->undo_waste();
df6f2350edfa 8220311: Implementation: NUMA-Aware Memory Allocation for G1, Survivor (2/3)
sangheki
parents: 59060
diff changeset
   408
      }
53846
fe95464806a7 8219096: Merge print_termination_stats code with current logging
tschatzl
parents: 53411
diff changeset
   409
    }
fe95464806a7 8219096: Merge print_termination_stats code with current logging
tschatzl
parents: 53411
diff changeset
   410
  }
fe95464806a7 8219096: Merge print_termination_stats code with current logging
tschatzl
parents: 53411
diff changeset
   411
  return result;
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30275
diff changeset
   412
}
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   413
46285
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 37985
diff changeset
   414
bool G1ArchiveAllocator::_archive_check_enabled = false;
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46625
diff changeset
   415
G1ArchiveRegionMap G1ArchiveAllocator::_closed_archive_region_map;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46625
diff changeset
   416
G1ArchiveRegionMap G1ArchiveAllocator::_open_archive_region_map;
46285
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 37985
diff changeset
   417
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46625
diff changeset
   418
G1ArchiveAllocator* G1ArchiveAllocator::create_allocator(G1CollectedHeap* g1h, bool open) {
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   419
  // Create the archive allocator, and also enable archive object checking
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   420
  // in mark-sweep, since we will be creating archive regions.
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46625
diff changeset
   421
  G1ArchiveAllocator* result =  new G1ArchiveAllocator(g1h, open);
46285
5b673a9fa682 8171235: Move archive object code from G1MarkSweep into G1ArchiveAllocator
sjohanss
parents: 37985
diff changeset
   422
  enable_archive_object_check();
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   423
  return result;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   424
}
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   425
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   426
bool G1ArchiveAllocator::alloc_new_region() {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   427
  // Allocate the highest free region in the reserved heap,
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   428
  // and add it to our list of allocated regions. It is marked
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   429
  // archive and added to the old set.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   430
  HeapRegion* hr = _g1h->alloc_highest_free_region();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   431
  if (hr == NULL) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   432
    return false;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   433
  }
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   434
  assert(hr->is_empty(), "expected empty region (index %u)", hr->hrm_index());
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46625
diff changeset
   435
  if (_open) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46625
diff changeset
   436
    hr->set_open_archive();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46625
diff changeset
   437
  } else {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46625
diff changeset
   438
    hr->set_closed_archive();
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46625
diff changeset
   439
  }
53985
0da5c17f5e43 8219747: Remove g1_ prefix to g1_remset and g1_policy members in G1CollectedHeap
tschatzl
parents: 53846
diff changeset
   440
  _g1h->policy()->remset_tracker()->update_at_allocate(hr);
51494
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 51332
diff changeset
   441
  _g1h->archive_set_add(hr);
35079
edab77f91231 8145301: Improve and unify the printout format for the g1HRPrinter.
david
parents: 34230
diff changeset
   442
  _g1h->hr_printer()->alloc(hr);
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   443
  _allocated_regions.append(hr);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   444
  _allocation_region = hr;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   445
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   446
  // Set up _bottom and _max to begin allocating in the lowest
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   447
  // min_region_size'd chunk of the allocated G1 region.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   448
  _bottom = hr->bottom();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   449
  _max = _bottom + HeapRegion::min_region_size_in_words();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   450
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   451
  // Tell mark-sweep that objects in this region are not to be marked.
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46625
diff changeset
   452
  set_range_archive(MemRegion(_bottom, HeapRegion::GrainWords), _open);
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   453
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   454
  // Since we've modified the old set, call update_sizes.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   455
  _g1h->g1mm()->update_sizes();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   456
  return true;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   457
}
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   458
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   459
HeapWord* G1ArchiveAllocator::archive_mem_allocate(size_t word_size) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   460
  assert(word_size != 0, "size must not be zero");
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   461
  if (_allocation_region == NULL) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   462
    if (!alloc_new_region()) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   463
      return NULL;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   464
    }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   465
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   466
  HeapWord* old_top = _allocation_region->top();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   467
  assert(_bottom >= _allocation_region->bottom(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   468
         "inconsistent allocation state: " PTR_FORMAT " < " PTR_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   469
         p2i(_bottom), p2i(_allocation_region->bottom()));
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   470
  assert(_max <= _allocation_region->end(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   471
         "inconsistent allocation state: " PTR_FORMAT " > " PTR_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   472
         p2i(_max), p2i(_allocation_region->end()));
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   473
  assert(_bottom <= old_top && old_top <= _max,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   474
         "inconsistent allocation state: expected "
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   475
         PTR_FORMAT " <= " PTR_FORMAT " <= " PTR_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   476
         p2i(_bottom), p2i(old_top), p2i(_max));
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   477
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   478
  // Allocate the next word_size words in the current allocation chunk.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   479
  // If allocation would cross the _max boundary, insert a filler and begin
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   480
  // at the base of the next min_region_size'd chunk. Also advance to the next
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   481
  // chunk if we don't yet cross the boundary, but the remainder would be too
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   482
  // small to fill.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   483
  HeapWord* new_top = old_top + word_size;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   484
  size_t remainder = pointer_delta(_max, new_top);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   485
  if ((new_top > _max) ||
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   486
      ((new_top < _max) && (remainder < CollectedHeap::min_fill_size()))) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   487
    if (old_top != _max) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   488
      size_t fill_size = pointer_delta(_max, old_top);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   489
      CollectedHeap::fill_with_object(old_top, fill_size);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   490
      _summary_bytes_used += fill_size * HeapWordSize;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   491
    }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   492
    _allocation_region->set_top(_max);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   493
    old_top = _bottom = _max;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   494
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   495
    // Check if we've just used up the last min_region_size'd chunk
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   496
    // in the current region, and if so, allocate a new one.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   497
    if (_bottom != _allocation_region->end()) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   498
      _max = _bottom + HeapRegion::min_region_size_in_words();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   499
    } else {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   500
      if (!alloc_new_region()) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   501
        return NULL;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   502
      }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   503
      old_top = _allocation_region->bottom();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   504
    }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   505
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   506
  _allocation_region->set_top(old_top + word_size);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   507
  _summary_bytes_used += word_size * HeapWordSize;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   508
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   509
  return old_top;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   510
}
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   511
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   512
void G1ArchiveAllocator::complete_archive(GrowableArray<MemRegion>* ranges,
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   513
                                          size_t end_alignment_in_bytes) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   514
  assert((end_alignment_in_bytes >> LogHeapWordSize) < HeapRegion::min_region_size_in_words(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   515
         "alignment " SIZE_FORMAT " too large", end_alignment_in_bytes);
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   516
  assert(is_aligned(end_alignment_in_bytes, HeapWordSize),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   517
         "alignment " SIZE_FORMAT " is not HeapWord (%u) aligned", end_alignment_in_bytes, HeapWordSize);
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   518
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   519
  // If we've allocated nothing, simply return.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   520
  if (_allocation_region == NULL) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   521
    return;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   522
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   523
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   524
  // If an end alignment was requested, insert filler objects.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   525
  if (end_alignment_in_bytes != 0) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   526
    HeapWord* currtop = _allocation_region->top();
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   527
    HeapWord* newtop = align_up(currtop, end_alignment_in_bytes);
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   528
    size_t fill_size = pointer_delta(newtop, currtop);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   529
    if (fill_size != 0) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   530
      if (fill_size < CollectedHeap::min_fill_size()) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   531
        // If the required fill is smaller than we can represent,
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   532
        // bump up to the next aligned address. We know we won't exceed the current
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   533
        // region boundary because the max supported alignment is smaller than the min
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   534
        // region size, and because the allocation code never leaves space smaller than
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   535
        // the min_fill_size at the top of the current allocation region.
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   536
        newtop = align_up(currtop + CollectedHeap::min_fill_size(),
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46618
diff changeset
   537
                          end_alignment_in_bytes);
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   538
        fill_size = pointer_delta(newtop, currtop);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   539
      }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   540
      HeapWord* fill = archive_mem_allocate(fill_size);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   541
      CollectedHeap::fill_with_objects(fill, fill_size);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   542
    }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   543
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   544
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   545
  // Loop through the allocated regions, and create MemRegions summarizing
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   546
  // the allocated address range, combining contiguous ranges. Add the
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   547
  // MemRegions to the GrowableArray provided by the caller.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   548
  int index = _allocated_regions.length() - 1;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   549
  assert(_allocated_regions.at(index) == _allocation_region,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   550
         "expected region %u at end of array, found %u",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   551
         _allocation_region->hrm_index(), _allocated_regions.at(index)->hrm_index());
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   552
  HeapWord* base_address = _allocation_region->bottom();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   553
  HeapWord* top = base_address;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   554
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   555
  while (index >= 0) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   556
    HeapRegion* next = _allocated_regions.at(index);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   557
    HeapWord* new_base = next->bottom();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   558
    HeapWord* new_top = next->top();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   559
    if (new_base != top) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   560
      ranges->append(MemRegion(base_address, pointer_delta(top, base_address)));
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   561
      base_address = new_base;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   562
    }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   563
    top = new_top;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   564
    index = index - 1;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   565
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   566
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32589
diff changeset
   567
  assert(top != base_address, "zero-sized range, address " PTR_FORMAT, p2i(base_address));
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   568
  ranges->append(MemRegion(base_address, pointer_delta(top, base_address)));
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   569
  _allocated_regions.clear();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   570
  _allocation_region = NULL;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 31331
diff changeset
   571
};