src/hotspot/share/gc/g1/g1RegionToSpaceMapper.cpp
author sangheki
Wed, 13 Nov 2019 10:49:12 -0800
changeset 59060 fce1fa1bdc91
parent 54264 41af8d0546bc
permissions -rw-r--r--
8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3) Reviewed-by: kbarrett, sjohanss, tschatzl, pliden
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     1
/*
54264
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 53116
diff changeset
     2
 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     4
 *
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     8
 *
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    13
 * accompanied this code).
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    14
 *
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    18
 *
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    21
 * questions.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    22
 *
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    23
 */
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    24
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30291
diff changeset
    26
#include "gc/g1/g1BiasedArray.hpp"
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
    27
#include "gc/g1/g1NUMA.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30291
diff changeset
    28
#include "gc/g1/g1RegionToSpaceMapper.hpp"
53116
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
    29
#include "logging/log.hpp"
26163
89f44df5b438 8055635: Missing include in g1RegionToSpaceMapper.hpp results in unresolved symbol of fastdebug build without precompiled headers
tschatzl
parents: 26160
diff changeset
    30
#include "memory/allocation.inline.hpp"
30291
54cdc5c1a9cb 8068352: Move virtualspace.* out of src/share/vm/runtime to memory directory
coleenp
parents: 30158
diff changeset
    31
#include "memory/virtualspace.hpp"
53116
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
    32
#include "runtime/java.hpp"
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
    33
#include "runtime/os.inline.hpp"
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    34
#include "services/memTracker.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    35
#include "utilities/align.hpp"
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    36
#include "utilities/bitMap.inline.hpp"
53116
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
    37
#include "utilities/formatBuffer.hpp"
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    38
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    39
G1RegionToSpaceMapper::G1RegionToSpaceMapper(ReservedSpace rs,
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    40
                                             size_t used_size,
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    41
                                             size_t page_size,
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    42
                                             size_t region_granularity,
38177
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 33105
diff changeset
    43
                                             size_t commit_factor,
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    44
                                             MemoryType type) :
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    45
  _listener(NULL),
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    46
  _storage(rs, used_size, page_size),
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    47
  _region_granularity(region_granularity),
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
    48
  _commit_map(rs.size() * commit_factor / region_granularity, mtGC),
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
    49
  _memory_type(type) {
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    50
  guarantee(is_power_of_2(page_size), "must be");
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    51
  guarantee(is_power_of_2(region_granularity), "must be");
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    52
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    53
  MemTracker::record_virtual_memory_type((address)rs.base(), type);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    54
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    55
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    56
// G1RegionToSpaceMapper implementation where the region granularity is larger than
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    57
// or the same as the commit granularity.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    58
// Basically, the space corresponding to one region region spans several OS pages.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    59
class G1RegionsLargerThanCommitSizeMapper : public G1RegionToSpaceMapper {
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    60
 private:
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    61
  size_t _pages_per_region;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    62
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    63
 public:
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    64
  G1RegionsLargerThanCommitSizeMapper(ReservedSpace rs,
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    65
                                      size_t actual_size,
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    66
                                      size_t page_size,
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    67
                                      size_t alloc_granularity,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    68
                                      size_t commit_factor,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    69
                                      MemoryType type) :
38177
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 33105
diff changeset
    70
    G1RegionToSpaceMapper(rs, actual_size, page_size, alloc_granularity, commit_factor, type),
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    71
    _pages_per_region(alloc_granularity / (page_size * commit_factor)) {
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    72
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    73
    guarantee(alloc_granularity >= page_size, "allocation granularity smaller than commit granularity");
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    74
  }
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    75
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
    76
  virtual void commit_regions(uint start_idx, size_t num_regions, WorkGang* pretouch_gang) {
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
    77
    const size_t start_page = (size_t)start_idx * _pages_per_region;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
    78
    const size_t size_in_pages = num_regions * _pages_per_region;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
    79
    bool zero_filled = _storage.commit(start_page, size_in_pages);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
    80
    if (_memory_type == mtJavaHeap) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
    81
      for (uint region_index = start_idx; region_index < start_idx + num_regions; region_index++ ) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
    82
        void* address = _storage.page_start(region_index * _pages_per_region);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
    83
        size_t size_in_bytes = _storage.page_size() * _pages_per_region;
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
    84
        G1NUMA::numa()->request_memory_on_node(address, size_in_bytes, region_index);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
    85
      }
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
    86
    }
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
    87
    if (AlwaysPreTouch) {
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
    88
      _storage.pretouch(start_page, size_in_pages, pretouch_gang);
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
    89
    }
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    90
    _commit_map.set_range(start_idx, start_idx + num_regions);
28482
e1a8d03c342f 8062063: Usage of UseHugeTLBFS, UseLargePagesInMetaspace and huge SurvivorAlignmentInBytes cause crashes in CMBitMapClosure::do_bit
sjohanss
parents: 27149
diff changeset
    91
    fire_on_commit(start_idx, num_regions, zero_filled);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    92
  }
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    93
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    94
  virtual void uncommit_regions(uint start_idx, size_t num_regions) {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
    95
    _storage.uncommit((size_t)start_idx * _pages_per_region, num_regions * _pages_per_region);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    96
    _commit_map.clear_range(start_idx, start_idx + num_regions);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    97
  }
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    98
};
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
    99
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   100
// G1RegionToSpaceMapper implementation where the region granularity is smaller
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   101
// than the commit granularity.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   102
// Basically, the contents of one OS page span several regions.
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   103
class G1RegionsSmallerThanCommitSizeMapper : public G1RegionToSpaceMapper {
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   104
 private:
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   105
  class CommitRefcountArray : public G1BiasedMappedArray<uint> {
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   106
   protected:
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   107
     virtual uint default_value() const { return 0; }
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   108
  };
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   109
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   110
  size_t _regions_per_page;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   111
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   112
  CommitRefcountArray _refcounts;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   113
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   114
  uintptr_t region_idx_to_page_idx(uint region) const {
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   115
    return region / _regions_per_page;
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   116
  }
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   117
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   118
 public:
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   119
  G1RegionsSmallerThanCommitSizeMapper(ReservedSpace rs,
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   120
                                       size_t actual_size,
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   121
                                       size_t page_size,
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   122
                                       size_t alloc_granularity,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   123
                                       size_t commit_factor,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   124
                                       MemoryType type) :
38177
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 33105
diff changeset
   125
    G1RegionToSpaceMapper(rs, actual_size, page_size, alloc_granularity, commit_factor, type),
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   126
    _regions_per_page((page_size * commit_factor) / alloc_granularity), _refcounts() {
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   127
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   128
    guarantee((page_size * commit_factor) >= alloc_granularity, "allocation granularity smaller than commit granularity");
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 41178
diff changeset
   129
    _refcounts.initialize((HeapWord*)rs.base(), (HeapWord*)(rs.base() + align_up(rs.size(), page_size)), page_size);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   130
  }
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   131
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   132
  virtual void commit_regions(uint start_idx, size_t num_regions, WorkGang* pretouch_gang) {
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   133
    size_t const NoPage = ~(size_t)0;
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   134
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   135
    size_t first_committed = NoPage;
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   136
    size_t num_committed = 0;
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   137
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   138
    bool all_zero_filled = true;
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
   139
    G1NUMA* numa = G1NUMA::numa();
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   140
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
   141
    for (uint region_idx = start_idx; region_idx < start_idx + num_regions; region_idx++) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
   142
      assert(!_commit_map.at(region_idx), "Trying to commit storage at region %u that is already committed", region_idx);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
   143
      size_t page_idx = region_idx_to_page_idx(region_idx);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
   144
      uint old_refcount = _refcounts.get_by_index(page_idx);
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   145
27149
9246fc481aa3 8059758: Footprint regressions with JDK-8038423
tschatzl
parents: 26163
diff changeset
   146
      bool zero_filled = false;
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   147
      if (old_refcount == 0) {
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   148
        if (first_committed == NoPage) {
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
   149
          first_committed = page_idx;
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   150
          num_committed = 1;
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   151
        } else {
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   152
          num_committed++;
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   153
        }
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
   154
        zero_filled = _storage.commit(page_idx, 1);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
   155
        if (_memory_type == mtJavaHeap) {
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
   156
          void* address = _storage.page_start(page_idx);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
   157
          size_t size_in_bytes = _storage.page_size();
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
   158
          numa->request_memory_on_node(address, size_in_bytes, region_idx);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
   159
        }
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   160
      }
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   161
      all_zero_filled &= zero_filled;
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   162
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
   163
      _refcounts.set_by_index(page_idx, old_refcount + 1);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 54264
diff changeset
   164
      _commit_map.set_bit(region_idx);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   165
    }
41178
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   166
    if (AlwaysPreTouch && num_committed > 0) {
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   167
      _storage.pretouch(first_committed, num_committed, pretouch_gang);
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   168
    }
e567be097315 8157952: Parallelize Memory Pretouch
tschatzl
parents: 38177
diff changeset
   169
    fire_on_commit(start_idx, num_regions, all_zero_filled);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   170
  }
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   171
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   172
  virtual void uncommit_regions(uint start_idx, size_t num_regions) {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   173
    for (uint i = start_idx; i < start_idx + num_regions; i++) {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   174
      assert(_commit_map.at(i), "Trying to uncommit storage at region %u that is not committed", i);
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   175
      size_t idx = region_idx_to_page_idx(i);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   176
      uint old_refcount = _refcounts.get_by_index(idx);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   177
      assert(old_refcount > 0, "must be");
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   178
      if (old_refcount == 1) {
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   179
        _storage.uncommit(idx, 1);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   180
      }
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   181
      _refcounts.set_by_index(idx, old_refcount - 1);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   182
      _commit_map.clear_bit(i);
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   183
    }
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   184
  }
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   185
};
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   186
27149
9246fc481aa3 8059758: Footprint regressions with JDK-8038423
tschatzl
parents: 26163
diff changeset
   187
void G1RegionToSpaceMapper::fire_on_commit(uint start_idx, size_t num_regions, bool zero_filled) {
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   188
  if (_listener != NULL) {
27149
9246fc481aa3 8059758: Footprint regressions with JDK-8038423
tschatzl
parents: 26163
diff changeset
   189
    _listener->on_commit(start_idx, num_regions, zero_filled);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   190
  }
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   191
}
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   192
53116
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   193
static bool map_nvdimm_space(ReservedSpace rs) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   194
  assert(AllocateOldGenAt != NULL, "");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   195
  int _backing_fd = os::create_file_for_heap(AllocateOldGenAt);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   196
  if (_backing_fd == -1) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   197
    log_error(gc, init)("Could not create file for Old generation at location %s", AllocateOldGenAt);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   198
    return false;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   199
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   200
  // commit this memory in nv-dimm
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   201
  char* ret = os::attempt_reserve_memory_at(rs.size(), rs.base(), _backing_fd);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   202
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   203
  if (ret != rs.base()) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   204
    if (ret != NULL) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   205
      os::unmap_memory(rs.base(), rs.size());
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   206
    }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   207
    log_error(gc, init)("Error in mapping Old Gen to given AllocateOldGenAt = %s", AllocateOldGenAt);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   208
    os::close(_backing_fd);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   209
    return false;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   210
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   211
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   212
  os::close(_backing_fd);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   213
  return true;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   214
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   215
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   216
G1RegionToHeteroSpaceMapper::G1RegionToHeteroSpaceMapper(ReservedSpace rs,
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   217
                                                         size_t actual_size,
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   218
                                                         size_t page_size,
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   219
                                                         size_t alloc_granularity,
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   220
                                                         size_t commit_factor,
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   221
                                                         MemoryType type) :
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   222
  G1RegionToSpaceMapper(rs, actual_size, page_size, alloc_granularity, commit_factor, type),
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   223
  _rs(rs),
54264
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 53116
diff changeset
   224
  _dram_mapper(NULL),
53116
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   225
  _num_committed_dram(0),
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   226
  _num_committed_nvdimm(0),
54264
41af8d0546bc 8221260: Initialize more class members on construction, remove some unused ones
lkorinth
parents: 53116
diff changeset
   227
  _start_index_of_dram(0),
53116
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   228
  _page_size(page_size),
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   229
  _commit_factor(commit_factor),
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   230
  _type(type) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   231
  assert(actual_size == 2 * MaxHeapSize, "For 2-way heterogenuous heap, reserved space is two times MaxHeapSize");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   232
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   233
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   234
bool G1RegionToHeteroSpaceMapper::initialize() {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   235
  // Since we need to re-map the reserved space - 'Xmx' to nv-dimm and 'Xmx' to dram, we need to release the reserved memory first.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   236
  // Because on some OSes (e.g. Windows) you cannot do a file mapping on memory reserved with regular mapping.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   237
  os::release_memory(_rs.base(), _rs.size());
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   238
  // First half of size Xmx is for nv-dimm.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   239
  ReservedSpace rs_nvdimm = _rs.first_part(MaxHeapSize);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   240
  assert(rs_nvdimm.base() == _rs.base(), "We should get the same base address");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   241
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   242
  // Second half of reserved memory is mapped to dram.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   243
  ReservedSpace rs_dram = _rs.last_part(MaxHeapSize);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   244
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   245
  assert(rs_dram.size() == rs_nvdimm.size() && rs_nvdimm.size() == MaxHeapSize, "They all should be same");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   246
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   247
  // Reserve dram memory
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   248
  char* base = os::attempt_reserve_memory_at(rs_dram.size(), rs_dram.base());
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   249
  if (base != rs_dram.base()) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   250
    if (base != NULL) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   251
      os::release_memory(base, rs_dram.size());
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   252
    }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   253
    log_error(gc, init)("Error in re-mapping memory on dram during G1 heterogenous memory initialization");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   254
    return false;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   255
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   256
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   257
  // We reserve and commit this entire space to NV-DIMM.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   258
  if (!map_nvdimm_space(rs_nvdimm)) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   259
    log_error(gc, init)("Error in re-mapping memory to nv-dimm during G1 heterogenous memory initialization");
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   260
    return false;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   261
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   262
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   263
  if (_region_granularity >= (_page_size * _commit_factor)) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   264
    _dram_mapper = new G1RegionsLargerThanCommitSizeMapper(rs_dram, rs_dram.size(), _page_size, _region_granularity, _commit_factor, _type);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   265
  } else {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   266
    _dram_mapper = new G1RegionsSmallerThanCommitSizeMapper(rs_dram, rs_dram.size(), _page_size, _region_granularity, _commit_factor, _type);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   267
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   268
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   269
  _start_index_of_dram = (uint)(rs_nvdimm.size() / _region_granularity);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   270
  return true;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   271
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   272
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   273
void G1RegionToHeteroSpaceMapper::commit_regions(uint start_idx, size_t num_regions, WorkGang* pretouch_gang) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   274
  uint end_idx = (start_idx + (uint)num_regions - 1);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   275
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   276
  uint num_dram = end_idx >= _start_index_of_dram ? MIN2((end_idx - _start_index_of_dram + 1), (uint)num_regions) : 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   277
  uint num_nvdimm = (uint)num_regions - num_dram;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   278
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   279
  if (num_nvdimm > 0) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   280
    // We do not need to commit nv-dimm regions, since they are committed in the beginning.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   281
    _num_committed_nvdimm += num_nvdimm;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   282
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   283
  if (num_dram > 0) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   284
    _dram_mapper->commit_regions(start_idx > _start_index_of_dram ? (start_idx - _start_index_of_dram) : 0, num_dram, pretouch_gang);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   285
    _num_committed_dram += num_dram;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   286
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   287
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   288
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   289
void G1RegionToHeteroSpaceMapper::uncommit_regions(uint start_idx, size_t num_regions) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   290
  uint end_idx = (start_idx + (uint)num_regions - 1);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   291
  uint num_dram = end_idx >= _start_index_of_dram ? MIN2((end_idx - _start_index_of_dram + 1), (uint)num_regions) : 0;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   292
  uint num_nvdimm = (uint)num_regions - num_dram;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   293
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   294
  if (num_nvdimm > 0) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   295
    // We do not uncommit memory for nv-dimm regions.
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   296
    _num_committed_nvdimm -= num_nvdimm;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   297
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   298
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   299
  if (num_dram > 0) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   300
    _dram_mapper->uncommit_regions(start_idx > _start_index_of_dram ? (start_idx - _start_index_of_dram) : 0, num_dram);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   301
    _num_committed_dram -= num_dram;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   302
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   303
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   304
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   305
uint G1RegionToHeteroSpaceMapper::num_committed_dram() const {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   306
  return _num_committed_dram;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   307
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   308
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   309
uint G1RegionToHeteroSpaceMapper::num_committed_nvdimm() const {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   310
  return _num_committed_nvdimm;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   311
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   312
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   313
G1RegionToSpaceMapper* G1RegionToSpaceMapper::create_heap_mapper(ReservedSpace rs,
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   314
                                                                 size_t actual_size,
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   315
                                                                 size_t page_size,
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   316
                                                                 size_t region_granularity,
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   317
                                                                 size_t commit_factor,
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   318
                                                                 MemoryType type) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   319
  if (AllocateOldGenAt != NULL) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   320
    G1RegionToHeteroSpaceMapper* mapper = new G1RegionToHeteroSpaceMapper(rs, actual_size, page_size, region_granularity, commit_factor, type);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   321
    if (!mapper->initialize()) {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   322
      delete mapper;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   323
      return NULL;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   324
    }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   325
    return (G1RegionToSpaceMapper*)mapper;
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   326
  } else {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   327
    return create_mapper(rs, actual_size, page_size, region_granularity, commit_factor, type);
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   328
  }
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   329
}
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   330
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   331
G1RegionToSpaceMapper* G1RegionToSpaceMapper::create_mapper(ReservedSpace rs,
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   332
                                                            size_t actual_size,
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   333
                                                            size_t page_size,
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   334
                                                            size_t region_granularity,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   335
                                                            size_t commit_factor,
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   336
                                                            MemoryType type) {
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   337
  if (region_granularity >= (page_size * commit_factor)) {
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   338
    return new G1RegionsLargerThanCommitSizeMapper(rs, actual_size, page_size, region_granularity, commit_factor, type);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   339
  } else {
30158
bd6094906ef8 8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
tschatzl
parents: 28482
diff changeset
   340
    return new G1RegionsSmallerThanCommitSizeMapper(rs, actual_size, page_size, region_granularity, commit_factor, type);
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   341
  }
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents:
diff changeset
   342
}
53116
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   343
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   344
void G1RegionToSpaceMapper::commit_and_set_special() {
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   345
  _storage.commit_and_set_special();
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51332
diff changeset
   346
}