src/hotspot/share/gc/z/zVirtualMemory.cpp
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58468 97cd0aa39787
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
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"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    25
#include "gc/z/zGlobals.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    26
#include "gc/z/zVirtualMemory.inline.hpp"
54617
24f6b0e413a0 8221786: ZGC: Increase max heap size to 16TB
pliden
parents: 50525
diff changeset
    27
#include "logging/log.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    28
#include "services/memTracker.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    29
58287
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    30
ZVirtualMemoryManager::ZVirtualMemoryManager(size_t max_capacity) :
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    31
    _manager(),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    32
    _initialized(false) {
54617
24f6b0e413a0 8221786: ZGC: Increase max heap size to 16TB
pliden
parents: 50525
diff changeset
    33
58468
97cd0aa39787 8231825: ZGC: Remove ZMaxHeapSize and ZMaxHeapSizeShift
pliden
parents: 58287
diff changeset
    34
  // Check max supported heap size
97cd0aa39787 8231825: ZGC: Remove ZMaxHeapSize and ZMaxHeapSizeShift
pliden
parents: 58287
diff changeset
    35
  if (max_capacity > ZAddressOffsetMax) {
97cd0aa39787 8231825: ZGC: Remove ZMaxHeapSize and ZMaxHeapSizeShift
pliden
parents: 58287
diff changeset
    36
    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
    37
                  ZAddressOffsetMax / G);
97cd0aa39787 8231825: ZGC: Remove ZMaxHeapSize and ZMaxHeapSizeShift
pliden
parents: 58287
diff changeset
    38
    return;
97cd0aa39787 8231825: ZGC: Remove ZMaxHeapSize and ZMaxHeapSizeShift
pliden
parents: 58287
diff changeset
    39
  }
97cd0aa39787 8231825: ZGC: Remove ZMaxHeapSize and ZMaxHeapSizeShift
pliden
parents: 58287
diff changeset
    40
58287
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    41
  log_info(gc, init)("Address Space: " SIZE_FORMAT "T", ZAddressOffsetMax / K / G);
54617
24f6b0e413a0 8221786: ZGC: Increase max heap size to 16TB
pliden
parents: 50525
diff changeset
    42
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    43
  // Reserve address space
58287
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    44
  if (reserve(0, ZAddressOffsetMax) < max_capacity) {
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    45
    log_error(gc)("Failed to reserve address space for Java heap");
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    46
    return;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    47
  }
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
  // Successfully initialized
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    50
  _initialized = true;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    51
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    52
58287
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    53
size_t ZVirtualMemoryManager::reserve(uintptr_t start, size_t size) {
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    54
  if (size < ZGranuleSize) {
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    55
    // Too small
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    56
    return 0;
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    57
  }
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    58
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    59
  if (!reserve_platform(start, size)) {
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    60
    const size_t half = size / 2;
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    61
    return reserve(start, half) + reserve(start + half, half);
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    62
  }
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    63
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    64
  // Make the address range free
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    65
  _manager.free(start, size);
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    66
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    67
  return size;
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    68
}
a7f16447085e 8224820: ZGC: Support discontiguous heap reservations
eosterlund
parents: 54834
diff changeset
    69
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    70
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
    71
  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
    72
  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
    73
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    74
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    75
bool ZVirtualMemoryManager::is_initialized() const {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    76
  return _initialized;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    77
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    78
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    79
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
    80
  uintptr_t start;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    81
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    82
  if (alloc_from_front || size <= ZPageSizeSmall) {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    83
    // Small page
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    84
    start = _manager.alloc_from_front(size);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    85
  } else {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    86
    // Medium/Large page
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    87
    start = _manager.alloc_from_back(size);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    88
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    89
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    90
  return ZVirtualMemory(start, size);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    91
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    92
54834
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54617
diff changeset
    93
void ZVirtualMemoryManager::free(const ZVirtualMemory& vmem) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    94
  _manager.free(vmem.start(), vmem.size());
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    95
}