comparison src/share/vm/gc_implementation/g1/g1PageBasedVirtualSpace.cpp @ 20337:1f1d373cd044

8038423: G1: Decommit memory within heap Summary: Allow G1 to decommit memory of arbitrary regions within the heap and their associated auxiliary data structures card table, BOT, hot card cache, and mark bitmaps. Reviewed-by: mgerdin, brutisso, jwilhelm
author tschatzl
date Thu, 21 Aug 2014 11:47:10 +0200
parents
children 8d5f66b42c53
comparison
equal deleted inserted replaced
20336:6701abbc4441 20337:1f1d373cd044
1 /*
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc_implementation/g1/g1PageBasedVirtualSpace.hpp"
27 #include "oops/markOop.hpp"
28 #include "oops/oop.inline.hpp"
29 #include "services/memTracker.hpp"
30 #ifdef TARGET_OS_FAMILY_linux
31 # include "os_linux.inline.hpp"
32 #endif
33 #ifdef TARGET_OS_FAMILY_solaris
34 # include "os_solaris.inline.hpp"
35 #endif
36 #ifdef TARGET_OS_FAMILY_windows
37 # include "os_windows.inline.hpp"
38 #endif
39 #ifdef TARGET_OS_FAMILY_aix
40 # include "os_aix.inline.hpp"
41 #endif
42 #ifdef TARGET_OS_FAMILY_bsd
43 # include "os_bsd.inline.hpp"
44 #endif
45 #include "utilities/bitMap.inline.hpp"
46
47 G1PageBasedVirtualSpace::G1PageBasedVirtualSpace() : _low_boundary(NULL),
48 _high_boundary(NULL), _committed(), _page_size(0), _special(false), _executable(false) {
49 }
50
51 bool G1PageBasedVirtualSpace::initialize_with_granularity(ReservedSpace rs, size_t page_size) {
52 if (!rs.is_reserved()) {
53 return false; // Allocation failed.
54 }
55 assert(_low_boundary == NULL, "VirtualSpace already initialized");
56 assert(page_size > 0, "Granularity must be non-zero.");
57
58 _low_boundary = rs.base();
59 _high_boundary = _low_boundary + rs.size();
60
61 _special = rs.special();
62 _executable = rs.executable();
63
64 _page_size = page_size;
65
66 assert(_committed.size() == 0, "virtual space initialized more than once");
67 uintx size_in_bits = rs.size() / page_size;
68 _committed.resize(size_in_bits, /* in_resource_area */ false);
69
70 if (_special) {
71 _committed.set_range(0, size_in_bits);
72 }
73
74 return true;
75 }
76
77
78 G1PageBasedVirtualSpace::~G1PageBasedVirtualSpace() {
79 release();
80 }
81
82 void G1PageBasedVirtualSpace::release() {
83 // This does not release memory it never reserved.
84 // Caller must release via rs.release();
85 _low_boundary = NULL;
86 _high_boundary = NULL;
87 _special = false;
88 _executable = false;
89 _page_size = 0;
90 _committed.resize(0, false);
91 }
92
93 size_t G1PageBasedVirtualSpace::committed_size() const {
94 return _committed.count_one_bits() * _page_size;
95 }
96
97 size_t G1PageBasedVirtualSpace::reserved_size() const {
98 return pointer_delta(_high_boundary, _low_boundary, sizeof(char));
99 }
100
101 size_t G1PageBasedVirtualSpace::uncommitted_size() const {
102 return reserved_size() - committed_size();
103 }
104
105 uintptr_t G1PageBasedVirtualSpace::addr_to_page_index(char* addr) const {
106 return (addr - _low_boundary) / _page_size;
107 }
108
109 bool G1PageBasedVirtualSpace::is_area_committed(uintptr_t start, size_t size_in_pages) const {
110 uintptr_t end = start + size_in_pages;
111 return _committed.get_next_zero_offset(start, end) >= end;
112 }
113
114 bool G1PageBasedVirtualSpace::is_area_uncommitted(uintptr_t start, size_t size_in_pages) const {
115 uintptr_t end = start + size_in_pages;
116 return _committed.get_next_one_offset(start, end) >= end;
117 }
118
119 char* G1PageBasedVirtualSpace::page_start(uintptr_t index) {
120 return _low_boundary + index * _page_size;
121 }
122
123 size_t G1PageBasedVirtualSpace::byte_size_for_pages(size_t num) {
124 return num * _page_size;
125 }
126
127 MemRegion G1PageBasedVirtualSpace::commit(uintptr_t start, size_t size_in_pages) {
128 // We need to make sure to commit all pages covered by the given area.
129 guarantee(is_area_uncommitted(start, size_in_pages), "Specified area is not uncommitted");
130
131 if (!_special) {
132 os::commit_memory_or_exit(page_start(start), byte_size_for_pages(size_in_pages), _executable,
133 err_msg("Failed to commit pages from "SIZE_FORMAT" of length "SIZE_FORMAT, start, size_in_pages));
134 }
135 _committed.set_range(start, start + size_in_pages);
136
137 MemRegion result((HeapWord*)page_start(start), byte_size_for_pages(size_in_pages) / HeapWordSize);
138 return result;
139 }
140
141 MemRegion G1PageBasedVirtualSpace::uncommit(uintptr_t start, size_t size_in_pages) {
142 guarantee(is_area_committed(start, size_in_pages), "checking");
143
144 if (!_special) {
145 os::uncommit_memory(page_start(start), byte_size_for_pages(size_in_pages));
146 }
147
148 _committed.clear_range(start, start + size_in_pages);
149
150 MemRegion result((HeapWord*)page_start(start), byte_size_for_pages(size_in_pages) / HeapWordSize);
151 return result;
152 }
153
154 bool G1PageBasedVirtualSpace::contains(const void* p) const {
155 return _low_boundary <= (const char*) p && (const char*) p < _high_boundary;
156 }
157
158 #ifndef PRODUCT
159 void G1PageBasedVirtualSpace::print_on(outputStream* out) {
160 out->print ("Virtual space:");
161 if (special()) out->print(" (pinned in memory)");
162 out->cr();
163 out->print_cr(" - committed: " SIZE_FORMAT, committed_size());
164 out->print_cr(" - reserved: " SIZE_FORMAT, reserved_size());
165 out->print_cr(" - [low_b, high_b]: [" INTPTR_FORMAT ", " INTPTR_FORMAT "]", p2i(_low_boundary), p2i(_high_boundary));
166 }
167
168 void G1PageBasedVirtualSpace::print() {
169 print_on(tty);
170 }
171 #endif