src/hotspot/share/gc/g1/heterogeneousHeapRegionManager.cpp
author tschatzl
Wed, 17 Jul 2019 16:33:19 +0200
changeset 55722 5ee183a90e65
parent 53116 bb03098c4dde
child 59060 fce1fa1bdc91
permissions -rw-r--r--
8227084: Add timing information for merge heap root preparation Reviewed-by: sangheki, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53116
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
     1
/*
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
     4
 *
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
     8
 *
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    13
 * accompanied this code).
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    14
 *
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    18
 *
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    21
 * questions.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    22
 *
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    23
 */
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    24
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    25
#include "precompiled.hpp"
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    26
#include "gc/g1/g1CollectedHeap.inline.hpp"
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    27
#include "gc/g1/g1ConcurrentRefine.hpp"
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    28
#include "gc/g1/heapRegion.hpp"
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    29
#include "gc/g1/heapRegionManager.inline.hpp"
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    30
#include "gc/g1/heapRegionSet.inline.hpp"
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    31
#include "gc/g1/heterogeneousHeapRegionManager.hpp"
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    32
#include "memory/allocation.hpp"
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    33
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    34
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    35
HeterogeneousHeapRegionManager* HeterogeneousHeapRegionManager::manager() {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    36
  G1CollectedHeap* g1h = G1CollectedHeap::heap();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    37
  assert(g1h != NULL, "Uninitialized access to HeterogeneousHeapRegionManager::manager()");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    38
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    39
  HeapRegionManager* hrm = g1h->hrm();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    40
  assert(hrm != NULL, "Uninitialized access to HeterogeneousHeapRegionManager::manager()");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    41
  return (HeterogeneousHeapRegionManager*)hrm;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    42
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    43
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    44
void HeterogeneousHeapRegionManager::initialize(G1RegionToSpaceMapper* heap_storage,
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    45
                                                G1RegionToSpaceMapper* prev_bitmap,
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    46
                                                G1RegionToSpaceMapper* next_bitmap,
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    47
                                                G1RegionToSpaceMapper* bot,
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    48
                                                G1RegionToSpaceMapper* cardtable,
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    49
                                                G1RegionToSpaceMapper* card_counts) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    50
  HeapRegionManager::initialize(heap_storage, prev_bitmap, next_bitmap, bot, cardtable, card_counts);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    51
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    52
  // We commit bitmap for all regions during initialization and mark the bitmap space as special.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    53
  // This allows regions to be un-committed while concurrent-marking threads are accessing the bitmap concurrently.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    54
  _prev_bitmap_mapper->commit_and_set_special();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    55
  _next_bitmap_mapper->commit_and_set_special();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    56
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    57
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    58
// expand_by() is called to grow the heap. We grow into nvdimm now.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    59
// Dram regions are committed later as needed during mutator region allocation or
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    60
// when young list target length is determined after gc cycle.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    61
uint HeterogeneousHeapRegionManager::expand_by(uint num_regions, WorkGang* pretouch_workers) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    62
  uint num_regions_possible = total_regions_committed() >= max_expandable_length() ? 0 : max_expandable_length() - total_regions_committed();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    63
  uint num_expanded = expand_nvdimm(MIN2(num_regions, num_regions_possible), pretouch_workers);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    64
  return num_expanded;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    65
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    66
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    67
// Expands heap starting from 'start' index. The question is should we expand from one memory (e.g. nvdimm) to another (e.g. dram).
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    68
// Looking at the code, expand_at() is called for humongous allocation where 'start' is in nv-dimm.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    69
// So we only allocate regions in the same kind of memory as 'start'.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    70
uint HeterogeneousHeapRegionManager::expand_at(uint start, uint num_regions, WorkGang* pretouch_workers) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    71
  if (num_regions == 0) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    72
    return 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    73
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    74
  uint target_num_regions = MIN2(num_regions, max_expandable_length() - total_regions_committed());
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    75
  uint end = is_in_nvdimm(start) ? end_index_of_nvdimm() : end_index_of_dram();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    76
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    77
  uint num_expanded = expand_in_range(start, end, target_num_regions, pretouch_workers);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    78
  assert(total_regions_committed() <= max_expandable_length(), "must be");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    79
  return num_expanded;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    80
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    81
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    82
// This function ensures that there are 'expected_num_regions' committed regions in dram.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    83
// If new regions are committed, it un-commits that many regions from nv-dimm.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    84
// If there are already more regions committed in dram, extra regions are un-committed.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    85
void HeterogeneousHeapRegionManager::adjust_dram_regions(uint expected_num_regions, WorkGang* pretouch_workers) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    86
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    87
  // Release back the extra regions allocated in evacuation failure scenario.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    88
  if(_no_borrowed_regions > 0) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    89
    _no_borrowed_regions -= shrink_dram(_no_borrowed_regions);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    90
    _no_borrowed_regions -= shrink_nvdimm(_no_borrowed_regions);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    91
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    92
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    93
  if(expected_num_regions > free_list_dram_length()) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    94
    // If we are going to expand DRAM, we expand a little more so that we can absorb small variations in Young gen sizing.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    95
    uint targeted_dram_regions = expected_num_regions * (1 + (double)G1YoungExpansionBufferPercent / 100);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    96
    uint to_be_made_available = targeted_dram_regions - free_list_dram_length();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    97
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    98
#ifdef ASSERT
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
    99
    uint total_committed_before = total_regions_committed();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   100
#endif
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   101
    uint can_be_made_available = shrink_nvdimm(to_be_made_available);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   102
    uint ret = expand_dram(can_be_made_available, pretouch_workers);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   103
#ifdef ASSERT
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   104
    assert(ret == can_be_made_available, "should be equal");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   105
    assert(total_committed_before == total_regions_committed(), "invariant not met");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   106
#endif
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   107
  } else {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   108
    uint to_be_released = free_list_dram_length() - expected_num_regions;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   109
    // if number of extra DRAM regions is small, do not shrink.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   110
    if (to_be_released < expected_num_regions * G1YoungExpansionBufferPercent / 100) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   111
      return;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   112
    }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   113
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   114
#ifdef ASSERT
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   115
    uint total_committed_before = total_regions_committed();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   116
#endif
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   117
    uint ret = shrink_dram(to_be_released);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   118
    assert(ret == to_be_released, "Should be able to shrink by given amount");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   119
    ret = expand_nvdimm(to_be_released, pretouch_workers);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   120
#ifdef ASSERT
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   121
    assert(ret == to_be_released, "Should be able to expand by given amount");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   122
    assert(total_committed_before == total_regions_committed(), "invariant not met");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   123
#endif
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   124
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   125
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   126
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   127
uint HeterogeneousHeapRegionManager::total_regions_committed() const {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   128
  return num_committed_dram() + num_committed_nvdimm();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   129
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   130
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   131
uint HeterogeneousHeapRegionManager::num_committed_dram() const {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   132
  // This class does not keep count of committed regions in dram and nv-dimm.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   133
  // G1RegionToHeteroSpaceMapper keeps this information.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   134
  return static_cast<G1RegionToHeteroSpaceMapper*>(_heap_mapper)->num_committed_dram();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   135
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   136
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   137
uint HeterogeneousHeapRegionManager::num_committed_nvdimm() const {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   138
  // See comment for num_committed_dram()
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   139
  return static_cast<G1RegionToHeteroSpaceMapper*>(_heap_mapper)->num_committed_nvdimm();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   140
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   141
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   142
// Return maximum number of regions that heap can expand to.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   143
uint HeterogeneousHeapRegionManager::max_expandable_length() const {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   144
  return _max_regions;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   145
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   146
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   147
uint HeterogeneousHeapRegionManager::find_unavailable_in_range(uint start_idx, uint end_idx, uint* res_idx) const {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   148
  guarantee(res_idx != NULL, "checking");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   149
  guarantee(start_idx <= (max_length() + 1), "checking");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   150
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   151
  uint num_regions = 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   152
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   153
  uint cur = start_idx;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   154
  while (cur <= end_idx && is_available(cur)) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   155
    cur++;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   156
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   157
  if (cur == end_idx + 1) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   158
    return num_regions;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   159
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   160
  *res_idx = cur;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   161
  while (cur <= end_idx && !is_available(cur)) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   162
    cur++;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   163
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   164
  num_regions = cur - *res_idx;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   165
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   166
#ifdef ASSERT
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   167
  for (uint i = *res_idx; i < (*res_idx + num_regions); i++) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   168
    assert(!is_available(i), "just checking");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   169
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   170
  assert(cur == end_idx + 1 || num_regions == 0 || is_available(cur),
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   171
    "The region at the current position %u must be available or at the end", cur);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   172
#endif
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   173
  return num_regions;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   174
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   175
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   176
uint HeterogeneousHeapRegionManager::expand_dram(uint num_regions, WorkGang* pretouch_workers) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   177
  return expand_in_range(start_index_of_dram(), end_index_of_dram(), num_regions, pretouch_workers);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   178
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   179
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   180
uint HeterogeneousHeapRegionManager::expand_nvdimm(uint num_regions, WorkGang* pretouch_workers) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   181
  return expand_in_range(start_index_of_nvdimm(), end_index_of_nvdimm(), num_regions, pretouch_workers);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   182
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   183
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   184
// Follows same logic as expand_at() form HeapRegionManager.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   185
uint HeterogeneousHeapRegionManager::expand_in_range(uint start, uint end, uint num_regions, WorkGang* pretouch_gang) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   186
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   187
  uint so_far = 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   188
  uint chunk_start = 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   189
  uint num_last_found = 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   190
  while (so_far < num_regions &&
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   191
         (num_last_found = find_unavailable_in_range(start, end, &chunk_start)) > 0) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   192
    uint to_commit = MIN2(num_regions - so_far, num_last_found);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   193
    make_regions_available(chunk_start, to_commit, pretouch_gang);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   194
    so_far += to_commit;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   195
    start = chunk_start + to_commit + 1;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   196
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   197
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   198
  return so_far;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   199
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   200
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   201
// Shrink in the range of indexes which are reserved for dram.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   202
uint HeterogeneousHeapRegionManager::shrink_dram(uint num_regions, bool update_free_list) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   203
  return shrink_in_range(start_index_of_dram(), end_index_of_dram(), num_regions, update_free_list);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   204
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   205
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   206
// Shrink in the range of indexes which are reserved for nv-dimm.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   207
uint HeterogeneousHeapRegionManager::shrink_nvdimm(uint num_regions, bool update_free_list) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   208
  return shrink_in_range(start_index_of_nvdimm(), end_index_of_nvdimm(), num_regions, update_free_list);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   209
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   210
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   211
// Find empty regions in given range, un-commit them and return the count.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   212
uint HeterogeneousHeapRegionManager::shrink_in_range(uint start, uint end, uint num_regions, bool update_free_list) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   213
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   214
  if (num_regions == 0) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   215
    return 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   216
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   217
  uint so_far = 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   218
  uint idx_last_found = 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   219
  uint num_last_found;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   220
  while (so_far < num_regions &&
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   221
         (num_last_found = find_empty_in_range_reverse(start, end, &idx_last_found)) > 0) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   222
    uint to_uncommit = MIN2(num_regions - so_far, num_last_found);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   223
    if(update_free_list) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   224
      _free_list.remove_starting_at(at(idx_last_found + num_last_found - to_uncommit), to_uncommit);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   225
    }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   226
    uncommit_regions(idx_last_found + num_last_found - to_uncommit, to_uncommit);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   227
    so_far += to_uncommit;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   228
    end = idx_last_found;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   229
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   230
  return so_far;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   231
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   232
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   233
uint HeterogeneousHeapRegionManager::find_empty_in_range_reverse(uint start_idx, uint end_idx, uint* res_idx) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   234
  guarantee(res_idx != NULL, "checking");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   235
  guarantee(start_idx < max_length(), "checking");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   236
  guarantee(end_idx < max_length(), "checking");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   237
  if(start_idx > end_idx) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   238
    return 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   239
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   240
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   241
  uint num_regions_found = 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   242
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   243
  jlong cur = end_idx;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   244
  while (cur >= start_idx && !(is_available(cur) && at(cur)->is_empty())) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   245
    cur--;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   246
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   247
  if (cur == start_idx - 1) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   248
    return num_regions_found;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   249
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   250
  jlong old_cur = cur;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   251
  // cur indexes the first empty region
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   252
  while (cur >= start_idx && is_available(cur) && at(cur)->is_empty()) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   253
    cur--;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   254
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   255
  *res_idx = cur + 1;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   256
  num_regions_found = old_cur - cur;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   257
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   258
#ifdef ASSERT
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   259
  for (uint i = *res_idx; i < (*res_idx + num_regions_found); i++) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   260
    assert(at(i)->is_empty(), "just checking");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   261
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   262
#endif
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   263
  return num_regions_found;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   264
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   265
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   266
HeapRegion* HeterogeneousHeapRegionManager::allocate_free_region(HeapRegionType type) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   267
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   268
  // We want to prevent mutators from proceeding when we have borrowed regions from the last collection. This
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   269
  // will force a full collection to remedy the situation.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   270
  // Free region requests from GC threads can proceed.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   271
  if(type.is_eden() || type.is_humongous()) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   272
    if(has_borrowed_regions()) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   273
      return NULL;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   274
    }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   275
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   276
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   277
  // old and humongous regions are allocated from nv-dimm; eden and survivor regions are allocated from dram
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   278
  // assumption: dram regions take higher indexes
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   279
  bool from_nvdimm = (type.is_old() || type.is_humongous()) ? true : false;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   280
  bool from_head = from_nvdimm;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   281
  HeapRegion* hr = _free_list.remove_region(from_head);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   282
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   283
  if (hr != NULL && ( (from_nvdimm && !is_in_nvdimm(hr->hrm_index())) || (!from_nvdimm && !is_in_dram(hr->hrm_index())) ) ) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   284
    _free_list.add_ordered(hr);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   285
    hr = NULL;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   286
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   287
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   288
#ifdef ASSERT
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   289
  uint total_committed_before = total_regions_committed();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   290
#endif
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   291
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   292
  if (hr == NULL) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   293
    if (!from_nvdimm) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   294
      uint ret = shrink_nvdimm(1);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   295
      if (ret == 1) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   296
        ret = expand_dram(1, NULL);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   297
        assert(ret == 1, "We should be able to commit one region");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   298
        hr = _free_list.remove_region(from_head);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   299
      }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   300
    }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   301
    else { /*is_old*/
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   302
      uint ret = shrink_dram(1);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   303
      if (ret == 1) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   304
        ret = expand_nvdimm(1, NULL);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   305
        assert(ret == 1, "We should be able to commit one region");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   306
        hr = _free_list.remove_region(from_head);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   307
      }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   308
    }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   309
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   310
#ifdef ASSERT
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   311
  assert(total_committed_before == total_regions_committed(), "invariant not met");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   312
#endif
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   313
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   314
  // When an old region is requested (which happens during collection pause) and we can't find any empty region
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   315
  // in the set of available regions (which is an evacuation failure scenario), we borrow (or pre-allocate) an unavailable region
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   316
  // from nv-dimm. This region is used to evacuate surviving objects from eden, survivor or old.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   317
  if(hr == NULL && type.is_old()) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   318
    hr = borrow_old_region_for_gc();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   319
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   320
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   321
  if (hr != NULL) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   322
    assert(hr->next() == NULL, "Single region should not have next");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   323
    assert(is_available(hr->hrm_index()), "Must be committed");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   324
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   325
  return hr;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   326
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   327
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   328
uint HeterogeneousHeapRegionManager::find_contiguous_only_empty(size_t num) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   329
  if (has_borrowed_regions()) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   330
      return G1_NO_HRM_INDEX;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   331
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   332
  return find_contiguous(start_index_of_nvdimm(), end_index_of_nvdimm(), num, true);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   333
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   334
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   335
uint HeterogeneousHeapRegionManager::find_contiguous_empty_or_unavailable(size_t num) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   336
  if (has_borrowed_regions()) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   337
    return G1_NO_HRM_INDEX;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   338
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   339
  return find_contiguous(start_index_of_nvdimm(), end_index_of_nvdimm(), num, false);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   340
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   341
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   342
uint HeterogeneousHeapRegionManager::find_contiguous(size_t start, size_t end, size_t num, bool empty_only) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   343
  uint found = 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   344
  size_t length_found = 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   345
  uint cur = (uint)start;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   346
  uint length_unavailable = 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   347
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   348
  while (length_found < num && cur <= end) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   349
    HeapRegion* hr = _regions.get_by_index(cur);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   350
    if ((!empty_only && !is_available(cur)) || (is_available(cur) && hr != NULL && hr->is_empty())) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   351
      // This region is a potential candidate for allocation into.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   352
      if (!is_available(cur)) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   353
        if(shrink_dram(1) == 1) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   354
          uint ret = expand_in_range(cur, cur, 1, NULL);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   355
          assert(ret == 1, "We should be able to expand at this index");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   356
        } else {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   357
          length_unavailable++;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   358
        }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   359
      }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   360
      length_found++;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   361
    }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   362
    else {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   363
      // This region is not a candidate. The next region is the next possible one.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   364
      found = cur + 1;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   365
      length_found = 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   366
    }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   367
    cur++;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   368
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   369
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   370
  if (length_found == num) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   371
    for (uint i = found; i < (found + num); i++) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   372
      HeapRegion* hr = _regions.get_by_index(i);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   373
      // sanity check
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   374
      guarantee((!empty_only && !is_available(i)) || (is_available(i) && hr != NULL && hr->is_empty()),
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   375
                "Found region sequence starting at " UINT32_FORMAT ", length " SIZE_FORMAT
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   376
                " that is not empty at " UINT32_FORMAT ". Hr is " PTR_FORMAT, found, num, i, p2i(hr));
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   377
    }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   378
    if (!empty_only && length_unavailable > (max_expandable_length() - total_regions_committed())) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   379
      // if 'length_unavailable' number of regions will be made available, we will exceed max regions.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   380
      return G1_NO_HRM_INDEX;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   381
    }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   382
    return found;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   383
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   384
  else {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   385
    return G1_NO_HRM_INDEX;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   386
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   387
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   388
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   389
uint HeterogeneousHeapRegionManager::find_highest_free(bool* expanded) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   390
  // Loop downwards from the highest dram region index, looking for an
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   391
  // entry which is either free or not yet committed.  If not yet
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   392
  // committed, expand_at that index.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   393
  uint curr = end_index_of_dram();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   394
  while (true) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   395
    HeapRegion *hr = _regions.get_by_index(curr);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   396
    if (hr == NULL && !(total_regions_committed() < _max_regions)) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   397
      uint res = shrink_nvdimm(1);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   398
      if (res == 1) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   399
        res = expand_in_range(curr, curr, 1, NULL);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   400
        assert(res == 1, "We should be able to expand since shrink was successful");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   401
        *expanded = true;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   402
        return curr;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   403
      }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   404
    }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   405
    else {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   406
      if (hr->is_free()) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   407
        *expanded = false;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   408
        return curr;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   409
      }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   410
    }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   411
    if (curr == start_index_of_dram()) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   412
      return G1_NO_HRM_INDEX;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   413
    }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   414
    curr--;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   415
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   416
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   417
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   418
// We need to override this since region 0 which serves are dummy region in base class may not be available here.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   419
// This is a corner condition when either number of regions is small. When adaptive sizing is used, initial heap size
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   420
// could be just one region.  This region is commited in dram to be used for young generation, leaving region 0 (which is in nvdimm)
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   421
// unavailable.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   422
HeapRegion* HeterogeneousHeapRegionManager::get_dummy_region() {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   423
  uint curr = 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   424
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   425
  while (curr < _regions.length()) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   426
    if (is_available(curr)) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   427
      return new_heap_region(curr);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   428
    }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   429
    curr++;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   430
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   431
  assert(false, "We should always find a region available for dummy region");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   432
  return NULL;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   433
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   434
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   435
// First shrink in dram, then in nv-dimm.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   436
uint HeterogeneousHeapRegionManager::shrink_by(uint num_regions) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   437
  // This call is made at end of full collection. Before making this call the region sets are tore down (tear_down_region_sets()).
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   438
  // So shrink() calls below do not need to remove uncomitted regions from free list.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   439
  uint ret = shrink_dram(num_regions, false /* update_free_list */);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   440
  ret += shrink_nvdimm(num_regions - ret, false /* update_free_list */);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   441
  return ret;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   442
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   443
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   444
void HeterogeneousHeapRegionManager::verify() {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   445
  HeapRegionManager::verify();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   446
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   447
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   448
uint HeterogeneousHeapRegionManager::free_list_dram_length() const {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   449
  return _free_list.num_of_regions_in_range(start_index_of_dram(), end_index_of_dram());
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   450
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   451
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   452
uint HeterogeneousHeapRegionManager::free_list_nvdimm_length() const {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   453
  return _free_list.num_of_regions_in_range(start_index_of_nvdimm(), end_index_of_nvdimm());
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   454
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   455
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   456
bool HeterogeneousHeapRegionManager::is_in_nvdimm(uint index) const {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   457
  return index >= start_index_of_nvdimm() && index <= end_index_of_nvdimm();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   458
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   459
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   460
bool HeterogeneousHeapRegionManager::is_in_dram(uint index) const {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   461
  return index >= start_index_of_dram() && index <= end_index_of_dram();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   462
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   463
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   464
// We have to make sure full collection copies all surviving objects to NV-DIMM.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   465
// We might not have enough regions in nvdimm_set, so we need to make more regions on NV-DIMM available for full collection.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   466
// Note: by doing this we are breaking the in-variant that total number of committed regions is equal to current heap size.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   467
// After full collection ends, we will re-establish this in-variant by freeing DRAM regions.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   468
void HeterogeneousHeapRegionManager::prepare_for_full_collection_start() {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   469
  _total_commited_before_full_gc = total_regions_committed() - _no_borrowed_regions;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   470
  _no_borrowed_regions = 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   471
  expand_nvdimm(num_committed_dram(), NULL);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   472
  remove_all_free_regions();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   473
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   474
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   475
// We need to bring back the total committed regions to before full collection start.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   476
// Unless we are close to OOM, all regular (not pinned) regions in DRAM should be free.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   477
// We shrink all free regions in DRAM and if needed from NV-DIMM (when there are pinned DRAM regions)
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   478
// If we can't bring back committed regions count to _total_commited_before_full_gc, we keep the extra count in _no_borrowed_regions.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   479
// When this GC finishes, new regions won't be allocated since has_borrowed_regions() is true. VM will be forced to re-try GC
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   480
// with clear soft references followed by OOM error in worst case.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   481
void HeterogeneousHeapRegionManager::prepare_for_full_collection_end() {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   482
  uint shrink_size = total_regions_committed() - _total_commited_before_full_gc;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   483
  uint so_far = 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   484
  uint idx_last_found = 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   485
  uint num_last_found;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   486
  uint end = (uint)_regions.length() - 1;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   487
  while (so_far < shrink_size &&
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   488
         (num_last_found = find_empty_in_range_reverse(0, end, &idx_last_found)) > 0) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   489
    uint to_uncommit = MIN2(shrink_size - so_far, num_last_found);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   490
    uncommit_regions(idx_last_found + num_last_found - to_uncommit, to_uncommit);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   491
    so_far += to_uncommit;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   492
    end = idx_last_found;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   493
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   494
  // See comment above the function.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   495
  _no_borrowed_regions = shrink_size - so_far;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   496
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   497
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   498
uint HeterogeneousHeapRegionManager::start_index_of_dram() const { return _max_regions;}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   499
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   500
uint HeterogeneousHeapRegionManager::end_index_of_dram() const { return 2*_max_regions - 1; }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   501
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   502
uint HeterogeneousHeapRegionManager::start_index_of_nvdimm() const { return 0; }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   503
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   504
uint HeterogeneousHeapRegionManager::end_index_of_nvdimm() const { return _max_regions - 1; }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   505
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   506
// This function is called when there are no free nv-dimm regions.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   507
// It borrows a region from the set of unavailable regions in nv-dimm for GC purpose.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   508
HeapRegion* HeterogeneousHeapRegionManager::borrow_old_region_for_gc() {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   509
  assert(free_list_nvdimm_length() == 0, "this function should be called only when there are no nv-dimm regions in free list");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   510
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   511
  uint ret = expand_nvdimm(1, NULL);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   512
  if(ret != 1) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   513
    return NULL;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   514
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   515
  HeapRegion* hr = _free_list.remove_region(true /*from_head*/);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   516
  assert(is_in_nvdimm(hr->hrm_index()), "allocated region should be in nv-dimm");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   517
  _no_borrowed_regions++;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   518
  return hr;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   519
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   520
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   521
bool HeterogeneousHeapRegionManager::has_borrowed_regions() const {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   522
  return _no_borrowed_regions > 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents:
diff changeset
   523
}