src/hotspot/share/gc/z/zVirtualMemory.cpp
author stefank
Mon, 28 Oct 2019 11:26:53 +0100
changeset 58814 bfb419c66ae9
parent 58787 32d39d9525f9
permissions -rw-r--r--
8232650: ZGC: Add initialization hooks for OS specific code Reviewed-by: pliden, eosterlund
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     1
/*
54834
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54617
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     4
 *
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     7
 * published by the Free Software Foundation.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     8
 *
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    13
 * accompanied this code).
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    14
 *
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    18
 *
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    21
 * questions.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    22
 */
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    23
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    24
#include "precompiled.hpp"
58787
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    25
#include "gc/z/zAddressSpaceLimit.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    26
#include "gc/z/zGlobals.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    27
#include "gc/z/zVirtualMemory.inline.hpp"
54617
24f6b0e413a0 8221786: ZGC: Increase max heap size to 16TB
pliden
parents: 50525
diff changeset
    28
#include "logging/log.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    29
#include "services/memTracker.hpp"
58787
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    30
#include "utilities/debug.hpp"
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    31
#include "utilities/align.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    32
58287
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    33
ZVirtualMemoryManager::ZVirtualMemoryManager(size_t max_capacity) :
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    34
    _manager(),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    35
    _initialized(false) {
54617
24f6b0e413a0 8221786: ZGC: Increase max heap size to 16TB
pliden
parents: 50525
diff changeset
    36
58468
97cd0aa39787 8231825: ZGC: Remove ZMaxHeapSize and ZMaxHeapSizeShift
pliden
parents: 58287
diff changeset
    37
  // Check max supported heap size
97cd0aa39787 8231825: ZGC: Remove ZMaxHeapSize and ZMaxHeapSizeShift
pliden
parents: 58287
diff changeset
    38
  if (max_capacity > ZAddressOffsetMax) {
97cd0aa39787 8231825: ZGC: Remove ZMaxHeapSize and ZMaxHeapSizeShift
pliden
parents: 58287
diff changeset
    39
    log_error(gc)("Java heap too large (max supported heap size is " SIZE_FORMAT "G)",
97cd0aa39787 8231825: ZGC: Remove ZMaxHeapSize and ZMaxHeapSizeShift
pliden
parents: 58287
diff changeset
    40
                  ZAddressOffsetMax / G);
97cd0aa39787 8231825: ZGC: Remove ZMaxHeapSize and ZMaxHeapSizeShift
pliden
parents: 58287
diff changeset
    41
    return;
97cd0aa39787 8231825: ZGC: Remove ZMaxHeapSize and ZMaxHeapSizeShift
pliden
parents: 58287
diff changeset
    42
  }
97cd0aa39787 8231825: ZGC: Remove ZMaxHeapSize and ZMaxHeapSizeShift
pliden
parents: 58287
diff changeset
    43
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    44
  // Reserve address space
58787
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    45
  if (!reserve(max_capacity)) {
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    46
    log_error(gc)("Failed to reserve enough address space for Java heap");
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    47
    return;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    48
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    49
58814
bfb419c66ae9 8232650: ZGC: Add initialization hooks for OS specific code
stefank
parents: 58787
diff changeset
    50
  // Initialize OS specific parts
bfb419c66ae9 8232650: ZGC: Add initialization hooks for OS specific code
stefank
parents: 58787
diff changeset
    51
  initialize_os();
bfb419c66ae9 8232650: ZGC: Add initialization hooks for OS specific code
stefank
parents: 58787
diff changeset
    52
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    53
  // Successfully initialized
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    54
  _initialized = true;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    55
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    56
58787
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    57
size_t ZVirtualMemoryManager::reserve_discontiguous(uintptr_t start, size_t size, size_t min_range) {
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    58
  if (size < min_range) {
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    59
    // Too small
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    60
    return 0;
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    61
  }
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    62
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    63
  assert(is_aligned(size, ZGranuleSize), "Misaligned");
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    64
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    65
  if (reserve_contiguous_platform(start, size)) {
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    66
    // Make the address range free
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    67
    _manager.free(start, size);
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    68
    return size;
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    69
  }
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    70
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    71
  const size_t half = size / 2;
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    72
  if (half < min_range) {
58287
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    73
    // Too small
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    74
    return 0;
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    75
  }
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    76
58787
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    77
  // Divide and conquer
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    78
  const size_t first_part = align_down(half, ZGranuleSize);
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    79
  const size_t second_part = size - first_part;
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    80
  return reserve_discontiguous(start, first_part, min_range) +
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    81
         reserve_discontiguous(start + first_part, second_part, min_range);
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    82
}
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    83
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    84
size_t ZVirtualMemoryManager::reserve_discontiguous(size_t size) {
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    85
  // Don't try to reserve address ranges smaller than 1% of the requested size.
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    86
  // This avoids an explosion of reservation attempts in case large parts of the
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    87
  // address space is already occupied.
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    88
  const size_t min_range = align_up(size / 100, ZGranuleSize);
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    89
  size_t start = 0;
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    90
  size_t reserved = 0;
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    91
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    92
  // Reserve size somewhere between [0, ZAddressOffsetMax)
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    93
  while (reserved < size && start < ZAddressOffsetMax) {
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    94
    const size_t remaining = MIN2(size - reserved, ZAddressOffsetMax - start);
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    95
    reserved += reserve_discontiguous(start, remaining, min_range);
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    96
    start += remaining;
58287
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    97
  }
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    98
58787
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
    99
  return reserved;
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   100
}
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   101
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   102
bool ZVirtualMemoryManager::reserve_contiguous(size_t size) {
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   103
  // Allow at most 8192 attempts spread evenly across [0, ZAddressOffsetMax)
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   104
  const size_t end = ZAddressOffsetMax - size;
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   105
  const size_t increment = align_up(end / 8192, ZGranuleSize);
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   106
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   107
  for (size_t start = 0; start <= end; start += increment) {
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   108
    if (reserve_contiguous_platform(start, size)) {
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   109
      // Make the address range free
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   110
      _manager.free(start, size);
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   111
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   112
      // Success
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   113
      return true;
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   114
    }
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   115
  }
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   116
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   117
  // Failed
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   118
  return false;
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   119
}
58287
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
   120
58787
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   121
bool ZVirtualMemoryManager::reserve(size_t max_capacity) {
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   122
  const size_t limit = MIN2(ZAddressOffsetMax, ZAddressSpaceLimit::heap_view());
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   123
  const size_t size = MIN2(max_capacity * ZVirtualToPhysicalRatio, limit);
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   124
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   125
  size_t reserved = size;
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   126
  bool contiguous = true;
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   127
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   128
  // Prefer a contiguous address space
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   129
  if (!reserve_contiguous(size)) {
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   130
    // Fall back to a discontiguous address space
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   131
    reserved = reserve_discontiguous(size);
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   132
    contiguous = false;
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   133
  }
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   134
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   135
  log_info(gc, init)("Address Space Type: %s/%s/%s",
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   136
                     (contiguous ? "Contiguous" : "Discontiguous"),
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   137
                     (limit == ZAddressOffsetMax ? "Unrestricted" : "Restricted"),
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   138
                     (reserved == size ? "Complete" : "Degraded"));
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   139
  log_info(gc, init)("Address Space Size: " SIZE_FORMAT "M x " SIZE_FORMAT " = " SIZE_FORMAT "M",
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   140
                     reserved / M, ZHeapViews, (reserved * ZHeapViews) / M);
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   141
32d39d9525f9 8231552: ZGC: Refine address space reservation
pliden
parents: 58468
diff changeset
   142
  return reserved >= max_capacity;
58287
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
   143
}
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
   144
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   145
void ZVirtualMemoryManager::nmt_reserve(uintptr_t start, size_t size) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   146
  MemTracker::record_virtual_memory_reserve((void*)start, size, CALLER_PC);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   147
  MemTracker::record_virtual_memory_type((void*)start, mtJavaHeap);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   148
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   149
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   150
bool ZVirtualMemoryManager::is_initialized() const {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   151
  return _initialized;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   152
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   153
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   154
ZVirtualMemory ZVirtualMemoryManager::alloc(size_t size, bool alloc_from_front) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   155
  uintptr_t start;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   156
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   157
  if (alloc_from_front || size <= ZPageSizeSmall) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   158
    // Small page
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   159
    start = _manager.alloc_from_front(size);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   160
  } else {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   161
    // Medium/Large page
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   162
    start = _manager.alloc_from_back(size);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   163
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   164
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   165
  return ZVirtualMemory(start, size);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   166
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   167
54834
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54617
diff changeset
   168
void ZVirtualMemoryManager::free(const ZVirtualMemory& vmem) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   169
  _manager.free(vmem.start(), vmem.size());
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   170
}