src/hotspot/share/gc/z/zPage.cpp
author eosterlund
Tue, 12 Nov 2019 20:01:23 +0000
changeset 59038 b9a42ca342db
parent 58708 f74ec3cbfcc0
permissions -rw-r--r--
8233061: ZGC: Enforce memory ordering in segmented bit maps Reviewed-by: pliden, stefank
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
/*
54094
ed3c6f07faab 8219633: ZGC: Rename ZPageSizeMin to ZGranuleSize
pliden
parents: 50525
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"
58708
f74ec3cbfcc0 8232238: ZGC: Move ZList inline funtions to zList.inline.hpp
pliden
parents: 54834
diff changeset
    25
#include "gc/z/zList.inline.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    26
#include "gc/z/zPage.inline.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    27
#include "gc/z/zPhysicalMemory.inline.hpp"
54161
349843ebb209 8220586: ZGC: Move relocation logic from ZPage to ZRelocate
pliden
parents: 54094
diff changeset
    28
#include "gc/z/zVirtualMemory.inline.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    29
#include "utilities/align.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    30
#include "utilities/debug.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    31
54834
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    32
ZPage::ZPage(const ZVirtualMemory& vmem, const ZPhysicalMemory& pmem) :
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    33
    _type(type_from_size(vmem.size())),
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    34
    _numa_id((uint8_t)-1),
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    35
    _seqnum(0),
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    36
    _virtual(vmem),
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    37
    _top(start()),
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    38
    _livemap(object_max_count()),
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    39
    _last_used(0),
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    40
    _physical(pmem) {
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    41
  assert_initialized();
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    42
}
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    43
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    44
ZPage::ZPage(uint8_t type, const ZVirtualMemory& vmem, const ZPhysicalMemory& pmem) :
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    45
    _type(type),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    46
    _numa_id((uint8_t)-1),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    47
    _seqnum(0),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    48
    _virtual(vmem),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    49
    _top(start()),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    50
    _livemap(object_max_count()),
54834
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    51
    _last_used(0),
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    52
    _physical(pmem) {
54834
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    53
  assert_initialized();
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    54
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    55
58708
f74ec3cbfcc0 8232238: ZGC: Move ZList inline funtions to zList.inline.hpp
pliden
parents: 54834
diff changeset
    56
ZPage::~ZPage() {}
f74ec3cbfcc0 8232238: ZGC: Move ZList inline funtions to zList.inline.hpp
pliden
parents: 54834
diff changeset
    57
54834
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    58
void ZPage::assert_initialized() const {
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    59
  assert(!_virtual.is_null(), "Should not be null");
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    60
  assert(!_physical.is_null(), "Should not be null");
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    61
  assert((_type == ZPageTypeSmall && size() == ZPageSizeSmall) ||
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    62
         (_type == ZPageTypeMedium && size() == ZPageSizeMedium) ||
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    63
         (_type == ZPageTypeLarge && is_aligned(size(), ZGranuleSize)),
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    64
         "Page type/size mismatch");
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    65
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    66
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    67
void ZPage::reset() {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    68
  _seqnum = ZGlobalSeqNum;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    69
  _top = start();
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    70
  _livemap.reset();
54834
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    71
  _last_used = 0;
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    72
}
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    73
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    74
ZPage* ZPage::retype(uint8_t type) {
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    75
  assert(_type != type, "Invalid retype");
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    76
  _type = type;
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    77
  _livemap.resize(object_max_count());
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    78
  return this;
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    79
}
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    80
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    81
ZPage* ZPage::split(size_t size) {
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    82
  return split(type_from_size(size), size);
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    83
}
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    84
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    85
ZPage* ZPage::split(uint8_t type, size_t size) {
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    86
  assert(_virtual.size() > size, "Invalid split");
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    87
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    88
  // Resize this page, keep _numa_id, _seqnum, and _last_used
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    89
  const ZVirtualMemory vmem = _virtual.split(size);
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    90
  const ZPhysicalMemory pmem = _physical.split(size);
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    91
  _type = type_from_size(_virtual.size());
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    92
  _top = start();
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    93
  _livemap.resize(object_max_count());
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    94
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    95
  // Create new page, inherit _seqnum and _last_used
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    96
  ZPage* const page = new ZPage(type, vmem, pmem);
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    97
  page->_seqnum = _seqnum;
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    98
  page->_last_used = _last_used;
39ba09047e19 8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents: 54169
diff changeset
    99
  return page;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   100
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   101
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   102
void ZPage::print_on(outputStream* out) const {
54169
5748eae24183 8220594: ZGC: Remove superfluous ZPage::is_active()
pliden
parents: 54168
diff changeset
   103
  out->print_cr(" %-6s  " PTR_FORMAT " " PTR_FORMAT " " PTR_FORMAT " %s%s",
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   104
                type_to_string(), start(), top(), end(),
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   105
                is_allocating()  ? " Allocating"  : "",
54169
5748eae24183 8220594: ZGC: Remove superfluous ZPage::is_active()
pliden
parents: 54168
diff changeset
   106
                is_relocatable() ? " Relocatable" : "");
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   107
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   108
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   109
void ZPage::print() const {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   110
  print_on(tty);
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   111
}