src/hotspot/os/bsd/gc/z/zPhysicalMemoryBacking_bsd.cpp
author eosterlund
Tue, 12 Nov 2019 09:27:21 +0000
changeset 59026 f51714d3385d
permissions -rw-r--r--
8224817: Implementation of JEP 364: ZGC on macOS Reviewed-by: pliden, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59026
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
     1
/*
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
     4
 *
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
     8
 *
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    13
 * accompanied this code).
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    14
 *
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    18
 *
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    21
 * questions.
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    22
 */
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    23
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    24
#include "precompiled.hpp"
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    25
#include "gc/z/zAddress.inline.hpp"
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    26
#include "gc/z/zGlobals.hpp"
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    27
#include "gc/z/zLargePages.inline.hpp"
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    28
#include "gc/z/zPhysicalMemory.inline.hpp"
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    29
#include "gc/z/zPhysicalMemoryBacking_bsd.hpp"
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    30
#include "runtime/globals.hpp"
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    31
#include "runtime/init.hpp"
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    32
#include "runtime/os.hpp"
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    33
#include "utilities/align.hpp"
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    34
#include "utilities/debug.hpp"
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    35
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    36
bool ZPhysicalMemoryBacking::is_initialized() const {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    37
  return _file.is_initialized();
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    38
}
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    39
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    40
void ZPhysicalMemoryBacking::warn_commit_limits(size_t max) const {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    41
  // Does nothing
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    42
}
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    43
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    44
bool ZPhysicalMemoryBacking::supports_uncommit() {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    45
  assert(!is_init_completed(), "Invalid state");
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    46
  assert(_file.size() >= ZGranuleSize, "Invalid size");
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    47
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    48
  // Test if uncommit is supported by uncommitting and then re-committing a granule
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    49
  return commit(uncommit(ZGranuleSize)) == ZGranuleSize;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    50
}
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    51
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    52
size_t ZPhysicalMemoryBacking::commit(size_t size) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    53
  size_t committed = 0;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    54
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    55
  // Fill holes in the backing file
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    56
  while (committed < size) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    57
    size_t allocated = 0;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    58
    const size_t remaining = size - committed;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    59
    const uintptr_t start = _uncommitted.alloc_from_front_at_most(remaining, &allocated);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    60
    if (start == UINTPTR_MAX) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    61
      // No holes to commit
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    62
      break;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    63
    }
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    64
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    65
    // Try commit hole
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    66
    const size_t filled = _file.commit(start, allocated);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    67
    if (filled > 0) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    68
      // Successful or partialy successful
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    69
      _committed.free(start, filled);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    70
      committed += filled;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    71
    }
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    72
    if (filled < allocated) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    73
      // Failed or partialy failed
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    74
      _uncommitted.free(start + filled, allocated - filled);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    75
      return committed;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    76
    }
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    77
  }
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    78
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    79
  // Expand backing file
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    80
  if (committed < size) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    81
    const size_t remaining = size - committed;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    82
    const uintptr_t start = _file.size();
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    83
    const size_t expanded = _file.commit(start, remaining);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    84
    if (expanded > 0) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    85
      // Successful or partialy successful
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    86
      _committed.free(start, expanded);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    87
      committed += expanded;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    88
    }
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    89
  }
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    90
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    91
  return committed;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    92
}
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    93
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    94
size_t ZPhysicalMemoryBacking::uncommit(size_t size) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    95
  size_t uncommitted = 0;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    96
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    97
  // Punch holes in backing file
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    98
  while (uncommitted < size) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
    99
    size_t allocated = 0;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   100
    const size_t remaining = size - uncommitted;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   101
    const uintptr_t start = _committed.alloc_from_back_at_most(remaining, &allocated);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   102
    assert(start != UINTPTR_MAX, "Allocation should never fail");
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   103
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   104
    // Try punch hole
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   105
    const size_t punched = _file.uncommit(start, allocated);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   106
    if (punched > 0) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   107
      // Successful or partialy successful
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   108
      _uncommitted.free(start, punched);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   109
      uncommitted += punched;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   110
    }
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   111
    if (punched < allocated) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   112
      // Failed or partialy failed
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   113
      _committed.free(start + punched, allocated - punched);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   114
      return uncommitted;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   115
    }
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   116
  }
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   117
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   118
  return uncommitted;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   119
}
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   120
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   121
ZPhysicalMemory ZPhysicalMemoryBacking::alloc(size_t size) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   122
  assert(is_aligned(size, ZGranuleSize), "Invalid size");
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   123
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   124
  ZPhysicalMemory pmem;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   125
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   126
  // Allocate segments
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   127
  for (size_t allocated = 0; allocated < size; allocated += ZGranuleSize) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   128
    const uintptr_t start = _committed.alloc_from_front(ZGranuleSize);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   129
    assert(start != UINTPTR_MAX, "Allocation should never fail");
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   130
    pmem.add_segment(ZPhysicalMemorySegment(start, ZGranuleSize));
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   131
  }
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   132
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   133
  return pmem;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   134
}
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   135
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   136
void ZPhysicalMemoryBacking::free(const ZPhysicalMemory& pmem) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   137
  const size_t nsegments = pmem.nsegments();
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   138
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   139
  // Free segments
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   140
  for (size_t i = 0; i < nsegments; i++) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   141
    const ZPhysicalMemorySegment& segment = pmem.segment(i);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   142
    _committed.free(segment.start(), segment.size());
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   143
  }
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   144
}
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   145
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   146
void ZPhysicalMemoryBacking::pretouch_view(uintptr_t addr, size_t size) const {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   147
  const size_t page_size = ZLargePages::is_explicit() ? ZGranuleSize : os::vm_page_size();
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   148
  os::pretouch_memory((void*)addr, (void*)(addr + size), page_size);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   149
}
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   150
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   151
void ZPhysicalMemoryBacking::map_view(const ZPhysicalMemory& pmem, uintptr_t addr, bool pretouch) const {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   152
  const size_t nsegments = pmem.nsegments();
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   153
  size_t size = 0;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   154
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   155
  // Map segments
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   156
  for (size_t i = 0; i < nsegments; i++) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   157
    const ZPhysicalMemorySegment& segment = pmem.segment(i);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   158
    const uintptr_t segment_addr = addr + size;
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   159
    _file.map(segment_addr, segment.size(), segment.start());
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   160
    size += segment.size();
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   161
  }
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   162
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   163
  // Pre-touch memory
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   164
  if (pretouch) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   165
    pretouch_view(addr, size);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   166
  }
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   167
}
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   168
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   169
void ZPhysicalMemoryBacking::unmap_view(const ZPhysicalMemory& pmem, uintptr_t addr) const {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   170
  _file.unmap(addr, pmem.size());
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   171
}
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   172
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   173
uintptr_t ZPhysicalMemoryBacking::nmt_address(uintptr_t offset) const {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   174
  // From an NMT point of view we treat the first heap view (marked0) as committed
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   175
  return ZAddress::marked0(offset);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   176
}
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   177
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   178
void ZPhysicalMemoryBacking::map(const ZPhysicalMemory& pmem, uintptr_t offset) const {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   179
  if (ZVerifyViews) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   180
    // Map good view
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   181
    map_view(pmem, ZAddress::good(offset), AlwaysPreTouch);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   182
  } else {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   183
    // Map all views
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   184
    map_view(pmem, ZAddress::marked0(offset), AlwaysPreTouch);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   185
    map_view(pmem, ZAddress::marked1(offset), AlwaysPreTouch);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   186
    map_view(pmem, ZAddress::remapped(offset), AlwaysPreTouch);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   187
  }
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   188
}
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   189
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   190
void ZPhysicalMemoryBacking::unmap(const ZPhysicalMemory& pmem, uintptr_t offset) const {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   191
  if (ZVerifyViews) {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   192
    // Unmap good view
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   193
    unmap_view(pmem, ZAddress::good(offset));
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   194
  } else {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   195
    // Unmap all views
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   196
    unmap_view(pmem, ZAddress::marked0(offset));
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   197
    unmap_view(pmem, ZAddress::marked1(offset));
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   198
    unmap_view(pmem, ZAddress::remapped(offset));
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   199
  }
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   200
}
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   201
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   202
void ZPhysicalMemoryBacking::debug_map(const ZPhysicalMemory& pmem, uintptr_t offset) const {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   203
  // Map good view
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   204
  assert(ZVerifyViews, "Should be enabled");
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   205
  map_view(pmem, ZAddress::good(offset), false /* pretouch */);
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   206
}
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   207
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   208
void ZPhysicalMemoryBacking::debug_unmap(const ZPhysicalMemory& pmem, uintptr_t offset) const {
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   209
  // Unmap good view
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   210
  assert(ZVerifyViews, "Should be enabled");
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   211
  unmap_view(pmem, ZAddress::good(offset));
f51714d3385d 8224817: Implementation of JEP 364: ZGC on macOS
eosterlund
parents:
diff changeset
   212
}