src/share/vm/gc_implementation/g1/g1PageBasedVirtualSpace.cpp

Mon, 19 Aug 2019 10:11:31 +0200

author
neugens
date
Mon, 19 Aug 2019 10:11:31 +0200
changeset 9861
a248d0be1309
parent 7781
33e421924c67
permissions
-rw-r--r--

8229401: Fix JFR code cache test failures
8223689: Add JFR Thread Sampling Support
8223690: Add JFR BiasedLock Event Support
8223691: Add JFR G1 Region Type Change Event Support
8223692: Add JFR G1 Heap Summary Event Support
Summary: Backport JFR from JDK11, additional fixes
Reviewed-by: neugens, apetushkov
Contributed-by: denghui.ddh@alibaba-inc.com

tschatzl@7051 1 /*
tschatzl@7781 2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
tschatzl@7051 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
tschatzl@7051 4 *
tschatzl@7051 5 * This code is free software; you can redistribute it and/or modify it
tschatzl@7051 6 * under the terms of the GNU General Public License version 2 only, as
tschatzl@7051 7 * published by the Free Software Foundation.
tschatzl@7051 8 *
tschatzl@7051 9 * This code is distributed in the hope that it will be useful, but WITHOUT
tschatzl@7051 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
tschatzl@7051 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
tschatzl@7051 12 * version 2 for more details (a copy is included in the LICENSE file that
tschatzl@7051 13 * accompanied this code).
tschatzl@7051 14 *
tschatzl@7051 15 * You should have received a copy of the GNU General Public License version
tschatzl@7051 16 * 2 along with this work; if not, write to the Free Software Foundation,
tschatzl@7051 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
tschatzl@7051 18 *
tschatzl@7051 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
tschatzl@7051 20 * or visit www.oracle.com if you need additional information or have any
tschatzl@7051 21 * questions.
tschatzl@7051 22 *
tschatzl@7051 23 */
tschatzl@7051 24
tschatzl@7051 25 #include "precompiled.hpp"
tschatzl@7051 26 #include "gc_implementation/g1/g1PageBasedVirtualSpace.hpp"
tschatzl@7051 27 #include "oops/markOop.hpp"
tschatzl@7051 28 #include "oops/oop.inline.hpp"
tschatzl@7051 29 #include "services/memTracker.hpp"
tschatzl@7051 30 #ifdef TARGET_OS_FAMILY_linux
tschatzl@7051 31 # include "os_linux.inline.hpp"
tschatzl@7051 32 #endif
tschatzl@7051 33 #ifdef TARGET_OS_FAMILY_solaris
tschatzl@7051 34 # include "os_solaris.inline.hpp"
tschatzl@7051 35 #endif
tschatzl@7051 36 #ifdef TARGET_OS_FAMILY_windows
tschatzl@7051 37 # include "os_windows.inline.hpp"
tschatzl@7051 38 #endif
tschatzl@7051 39 #ifdef TARGET_OS_FAMILY_aix
tschatzl@7051 40 # include "os_aix.inline.hpp"
tschatzl@7051 41 #endif
tschatzl@7051 42 #ifdef TARGET_OS_FAMILY_bsd
tschatzl@7051 43 # include "os_bsd.inline.hpp"
tschatzl@7051 44 #endif
tschatzl@7051 45 #include "utilities/bitMap.inline.hpp"
tschatzl@7051 46
tschatzl@7781 47 G1PageBasedVirtualSpace::G1PageBasedVirtualSpace(ReservedSpace rs, size_t used_size, size_t page_size) :
tschatzl@7781 48 _low_boundary(NULL), _high_boundary(NULL), _committed(), _page_size(0), _special(false),
sjohanss@7509 49 _dirty(), _executable(false) {
tschatzl@7781 50 initialize_with_page_size(rs, used_size, page_size);
tschatzl@7051 51 }
tschatzl@7051 52
tschatzl@7781 53 void G1PageBasedVirtualSpace::initialize_with_page_size(ReservedSpace rs, size_t used_size, size_t page_size) {
tschatzl@7781 54 guarantee(rs.is_reserved(), "Given reserved space must have been reserved already.");
tschatzl@7781 55
tschatzl@7051 56 assert(_low_boundary == NULL, "VirtualSpace already initialized");
tschatzl@7781 57 assert(page_size > 0, "Page size must be non-zero.");
tschatzl@7781 58
tschatzl@7781 59 guarantee(is_ptr_aligned(rs.base(), page_size),
tschatzl@7781 60 err_msg("Reserved space base " PTR_FORMAT " is not aligned to requested page size " SIZE_FORMAT, p2i(rs.base()), page_size));
tschatzl@7781 61 guarantee(is_size_aligned(used_size, os::vm_page_size()),
tschatzl@7781 62 err_msg("Given used reserved space size needs to be OS page size aligned (%d bytes) but is " SIZE_FORMAT, os::vm_page_size(), used_size));
tschatzl@7781 63 guarantee(used_size <= rs.size(),
tschatzl@7781 64 err_msg("Used size of reserved space " SIZE_FORMAT " bytes is smaller than reservation at " SIZE_FORMAT " bytes", used_size, rs.size()));
tschatzl@7781 65 guarantee(is_size_aligned(rs.size(), page_size),
tschatzl@7781 66 err_msg("Expected that the virtual space is size aligned, but " SIZE_FORMAT " is not aligned to page size " SIZE_FORMAT, rs.size(), page_size));
tschatzl@7051 67
tschatzl@7051 68 _low_boundary = rs.base();
tschatzl@7781 69 _high_boundary = _low_boundary + used_size;
tschatzl@7051 70
tschatzl@7051 71 _special = rs.special();
tschatzl@7051 72 _executable = rs.executable();
tschatzl@7051 73
tschatzl@7051 74 _page_size = page_size;
tschatzl@7051 75
tschatzl@7051 76 assert(_committed.size() == 0, "virtual space initialized more than once");
tschatzl@7781 77 BitMap::idx_t size_in_pages = rs.size() / page_size;
tschatzl@7781 78 _committed.resize(size_in_pages, /* in_resource_area */ false);
sjohanss@7509 79 if (_special) {
tschatzl@7781 80 _dirty.resize(size_in_pages, /* in_resource_area */ false);
sjohanss@7509 81 }
tschatzl@7051 82
tschatzl@7781 83 _tail_size = used_size % _page_size;
tschatzl@7051 84 }
tschatzl@7051 85
tschatzl@7051 86 G1PageBasedVirtualSpace::~G1PageBasedVirtualSpace() {
tschatzl@7051 87 release();
tschatzl@7051 88 }
tschatzl@7051 89
tschatzl@7051 90 void G1PageBasedVirtualSpace::release() {
tschatzl@7051 91 // This does not release memory it never reserved.
tschatzl@7051 92 // Caller must release via rs.release();
tschatzl@7051 93 _low_boundary = NULL;
tschatzl@7051 94 _high_boundary = NULL;
tschatzl@7051 95 _special = false;
tschatzl@7051 96 _executable = false;
tschatzl@7051 97 _page_size = 0;
tschatzl@7781 98 _tail_size = 0;
tschatzl@7051 99 _committed.resize(0, false);
sjohanss@7509 100 _dirty.resize(0, false);
tschatzl@7051 101 }
tschatzl@7051 102
tschatzl@7051 103 size_t G1PageBasedVirtualSpace::committed_size() const {
tschatzl@7781 104 size_t result = _committed.count_one_bits() * _page_size;
tschatzl@7781 105 // The last page might not be in full.
tschatzl@7781 106 if (is_last_page_partial() && _committed.at(_committed.size() - 1)) {
tschatzl@7781 107 result -= _page_size - _tail_size;
tschatzl@7781 108 }
tschatzl@7781 109 return result;
tschatzl@7051 110 }
tschatzl@7051 111
tschatzl@7051 112 size_t G1PageBasedVirtualSpace::reserved_size() const {
tschatzl@7051 113 return pointer_delta(_high_boundary, _low_boundary, sizeof(char));
tschatzl@7051 114 }
tschatzl@7051 115
tschatzl@7051 116 size_t G1PageBasedVirtualSpace::uncommitted_size() const {
tschatzl@7051 117 return reserved_size() - committed_size();
tschatzl@7051 118 }
tschatzl@7051 119
tschatzl@7781 120 size_t G1PageBasedVirtualSpace::addr_to_page_index(char* addr) const {
tschatzl@7051 121 return (addr - _low_boundary) / _page_size;
tschatzl@7051 122 }
tschatzl@7051 123
tschatzl@7781 124 bool G1PageBasedVirtualSpace::is_area_committed(size_t start_page, size_t size_in_pages) const {
tschatzl@7781 125 size_t end_page = start_page + size_in_pages;
tschatzl@7781 126 return _committed.get_next_zero_offset(start_page, end_page) >= end_page;
tschatzl@7051 127 }
tschatzl@7051 128
tschatzl@7781 129 bool G1PageBasedVirtualSpace::is_area_uncommitted(size_t start_page, size_t size_in_pages) const {
tschatzl@7781 130 size_t end_page = start_page + size_in_pages;
tschatzl@7781 131 return _committed.get_next_one_offset(start_page, end_page) >= end_page;
tschatzl@7051 132 }
tschatzl@7051 133
tschatzl@7781 134 char* G1PageBasedVirtualSpace::page_start(size_t index) const {
tschatzl@7051 135 return _low_boundary + index * _page_size;
tschatzl@7051 136 }
tschatzl@7051 137
tschatzl@7781 138 bool G1PageBasedVirtualSpace::is_after_last_page(size_t index) const {
tschatzl@7781 139 guarantee(index <= _committed.size(),
tschatzl@7781 140 err_msg("Given boundary page " SIZE_FORMAT " is beyond managed page count " SIZE_FORMAT, index, _committed.size()));
tschatzl@7781 141 return index == _committed.size();
tschatzl@7051 142 }
tschatzl@7051 143
tschatzl@7781 144 void G1PageBasedVirtualSpace::commit_preferred_pages(size_t start, size_t num_pages) {
tschatzl@7781 145 assert(num_pages > 0, "No full pages to commit");
tschatzl@7781 146 assert(start + num_pages <= _committed.size(),
tschatzl@7781 147 err_msg("Tried to commit area from page " SIZE_FORMAT " to page " SIZE_FORMAT " "
tschatzl@7781 148 "that is outside of managed space of " SIZE_FORMAT " pages",
tschatzl@7781 149 start, start + num_pages, _committed.size()));
tschatzl@7781 150
tschatzl@7781 151 char* start_addr = page_start(start);
tschatzl@7781 152 size_t size = num_pages * _page_size;
tschatzl@7781 153
tschatzl@7781 154 os::commit_memory_or_exit(start_addr, size, _page_size, _executable,
tschatzl@7781 155 err_msg("Failed to commit area from " PTR_FORMAT " to " PTR_FORMAT " of length " SIZE_FORMAT ".",
tschatzl@7781 156 p2i(start_addr), p2i(start_addr + size), size));
tschatzl@7781 157 }
tschatzl@7781 158
tschatzl@7781 159 void G1PageBasedVirtualSpace::commit_tail() {
tschatzl@7781 160 assert(_tail_size > 0, "The size of the tail area must be > 0 when reaching here");
tschatzl@7781 161
tschatzl@7781 162 char* const aligned_end_address = (char*)align_ptr_down(_high_boundary, _page_size);
tschatzl@7781 163 os::commit_memory_or_exit(aligned_end_address, _tail_size, os::vm_page_size(), _executable,
tschatzl@7781 164 err_msg("Failed to commit tail area from " PTR_FORMAT " to " PTR_FORMAT " of length " SIZE_FORMAT ".",
tschatzl@7781 165 p2i(aligned_end_address), p2i(_high_boundary), _tail_size));
tschatzl@7781 166 }
tschatzl@7781 167
tschatzl@7781 168 void G1PageBasedVirtualSpace::commit_internal(size_t start_page, size_t end_page) {
tschatzl@7781 169 guarantee(start_page < end_page,
tschatzl@7781 170 err_msg("Given start page " SIZE_FORMAT " is larger or equal to end page " SIZE_FORMAT, start_page, end_page));
tschatzl@7781 171 guarantee(end_page <= _committed.size(),
tschatzl@7781 172 err_msg("Given end page " SIZE_FORMAT " is beyond end of managed page amount of " SIZE_FORMAT, end_page, _committed.size()));
tschatzl@7781 173
tschatzl@7781 174 size_t pages = end_page - start_page;
tschatzl@7781 175 bool need_to_commit_tail = is_after_last_page(end_page) && is_last_page_partial();
tschatzl@7781 176
tschatzl@7781 177 // If we have to commit some (partial) tail area, decrease the amount of pages to avoid
tschatzl@7781 178 // committing that in the full-page commit code.
tschatzl@7781 179 if (need_to_commit_tail) {
tschatzl@7781 180 pages--;
tschatzl@7781 181 }
tschatzl@7781 182
tschatzl@7781 183 if (pages > 0) {
tschatzl@7781 184 commit_preferred_pages(start_page, pages);
tschatzl@7781 185 }
tschatzl@7781 186
tschatzl@7781 187 if (need_to_commit_tail) {
tschatzl@7781 188 commit_tail();
tschatzl@7781 189 }
tschatzl@7781 190 }
tschatzl@7781 191
tschatzl@7781 192 char* G1PageBasedVirtualSpace::bounded_end_addr(size_t end_page) const {
tschatzl@7781 193 return MIN2(_high_boundary, page_start(end_page));
tschatzl@7781 194 }
tschatzl@7781 195
tschatzl@7781 196 void G1PageBasedVirtualSpace::pretouch_internal(size_t start_page, size_t end_page) {
tschatzl@7781 197 guarantee(start_page < end_page,
tschatzl@7781 198 err_msg("Given start page " SIZE_FORMAT " is larger or equal to end page " SIZE_FORMAT, start_page, end_page));
tschatzl@7781 199
tschatzl@7781 200 os::pretouch_memory(page_start(start_page), bounded_end_addr(end_page));
tschatzl@7781 201 }
tschatzl@7781 202
tschatzl@7781 203 bool G1PageBasedVirtualSpace::commit(size_t start_page, size_t size_in_pages) {
tschatzl@7051 204 // We need to make sure to commit all pages covered by the given area.
tschatzl@7781 205 guarantee(is_area_uncommitted(start_page, size_in_pages), "Specified area is not uncommitted");
tschatzl@7051 206
sjohanss@7509 207 bool zero_filled = true;
tschatzl@7781 208 size_t end_page = start_page + size_in_pages;
sjohanss@7509 209
sjohanss@7509 210 if (_special) {
sjohanss@7509 211 // Check for dirty pages and update zero_filled if any found.
tschatzl@7781 212 if (_dirty.get_next_one_offset(start_page, end_page) < end_page) {
sjohanss@7509 213 zero_filled = false;
tschatzl@7781 214 _dirty.clear_range(start_page, end_page);
sjohanss@7509 215 }
sjohanss@7509 216 } else {
tschatzl@7781 217 commit_internal(start_page, end_page);
tschatzl@7051 218 }
tschatzl@7781 219 _committed.set_range(start_page, end_page);
tschatzl@7051 220
tschatzl@7777 221 if (AlwaysPreTouch) {
tschatzl@7781 222 pretouch_internal(start_page, end_page);
tschatzl@7777 223 }
sjohanss@7509 224 return zero_filled;
tschatzl@7051 225 }
tschatzl@7051 226
tschatzl@7781 227 void G1PageBasedVirtualSpace::uncommit_internal(size_t start_page, size_t end_page) {
tschatzl@7781 228 guarantee(start_page < end_page,
tschatzl@7781 229 err_msg("Given start page " SIZE_FORMAT " is larger or equal to end page " SIZE_FORMAT, start_page, end_page));
tschatzl@7051 230
tschatzl@7781 231 char* start_addr = page_start(start_page);
tschatzl@7781 232 os::uncommit_memory(start_addr, pointer_delta(bounded_end_addr(end_page), start_addr, sizeof(char)));
tschatzl@7781 233 }
tschatzl@7781 234
tschatzl@7781 235 void G1PageBasedVirtualSpace::uncommit(size_t start_page, size_t size_in_pages) {
tschatzl@7781 236 guarantee(is_area_committed(start_page, size_in_pages), "checking");
tschatzl@7781 237
tschatzl@7781 238 size_t end_page = start_page + size_in_pages;
sjohanss@7509 239 if (_special) {
sjohanss@7509 240 // Mark that memory is dirty. If committed again the memory might
sjohanss@7509 241 // need to be cleared explicitly.
tschatzl@7781 242 _dirty.set_range(start_page, end_page);
sjohanss@7509 243 } else {
tschatzl@7781 244 uncommit_internal(start_page, end_page);
tschatzl@7051 245 }
tschatzl@7051 246
tschatzl@7781 247 _committed.clear_range(start_page, end_page);
tschatzl@7051 248 }
tschatzl@7051 249
tschatzl@7051 250 bool G1PageBasedVirtualSpace::contains(const void* p) const {
tschatzl@7051 251 return _low_boundary <= (const char*) p && (const char*) p < _high_boundary;
tschatzl@7051 252 }
tschatzl@7051 253
tschatzl@7051 254 #ifndef PRODUCT
tschatzl@7051 255 void G1PageBasedVirtualSpace::print_on(outputStream* out) {
tschatzl@7051 256 out->print ("Virtual space:");
sjohanss@7509 257 if (_special) out->print(" (pinned in memory)");
tschatzl@7051 258 out->cr();
tschatzl@7051 259 out->print_cr(" - committed: " SIZE_FORMAT, committed_size());
tschatzl@7051 260 out->print_cr(" - reserved: " SIZE_FORMAT, reserved_size());
tschatzl@7781 261 out->print_cr(" - preferred page size: " SIZE_FORMAT, _page_size);
tschatzl@7781 262 out->print_cr(" - [low_b, high_b]: [" PTR_FORMAT ", " PTR_FORMAT "]", p2i(_low_boundary), p2i(_high_boundary));
tschatzl@7051 263 }
tschatzl@7051 264
tschatzl@7051 265 void G1PageBasedVirtualSpace::print() {
tschatzl@7051 266 print_on(tty);
tschatzl@7051 267 }
tschatzl@7051 268 #endif

mercurial