1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/g1/g1PageBasedVirtualSpace.cpp Thu Aug 21 11:47:10 2014 +0200 1.3 @@ -0,0 +1,171 @@ 1.4 +/* 1.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "gc_implementation/g1/g1PageBasedVirtualSpace.hpp" 1.30 +#include "oops/markOop.hpp" 1.31 +#include "oops/oop.inline.hpp" 1.32 +#include "services/memTracker.hpp" 1.33 +#ifdef TARGET_OS_FAMILY_linux 1.34 +# include "os_linux.inline.hpp" 1.35 +#endif 1.36 +#ifdef TARGET_OS_FAMILY_solaris 1.37 +# include "os_solaris.inline.hpp" 1.38 +#endif 1.39 +#ifdef TARGET_OS_FAMILY_windows 1.40 +# include "os_windows.inline.hpp" 1.41 +#endif 1.42 +#ifdef TARGET_OS_FAMILY_aix 1.43 +# include "os_aix.inline.hpp" 1.44 +#endif 1.45 +#ifdef TARGET_OS_FAMILY_bsd 1.46 +# include "os_bsd.inline.hpp" 1.47 +#endif 1.48 +#include "utilities/bitMap.inline.hpp" 1.49 + 1.50 +G1PageBasedVirtualSpace::G1PageBasedVirtualSpace() : _low_boundary(NULL), 1.51 + _high_boundary(NULL), _committed(), _page_size(0), _special(false), _executable(false) { 1.52 +} 1.53 + 1.54 +bool G1PageBasedVirtualSpace::initialize_with_granularity(ReservedSpace rs, size_t page_size) { 1.55 + if (!rs.is_reserved()) { 1.56 + return false; // Allocation failed. 1.57 + } 1.58 + assert(_low_boundary == NULL, "VirtualSpace already initialized"); 1.59 + assert(page_size > 0, "Granularity must be non-zero."); 1.60 + 1.61 + _low_boundary = rs.base(); 1.62 + _high_boundary = _low_boundary + rs.size(); 1.63 + 1.64 + _special = rs.special(); 1.65 + _executable = rs.executable(); 1.66 + 1.67 + _page_size = page_size; 1.68 + 1.69 + assert(_committed.size() == 0, "virtual space initialized more than once"); 1.70 + uintx size_in_bits = rs.size() / page_size; 1.71 + _committed.resize(size_in_bits, /* in_resource_area */ false); 1.72 + 1.73 + if (_special) { 1.74 + _committed.set_range(0, size_in_bits); 1.75 + } 1.76 + 1.77 + return true; 1.78 +} 1.79 + 1.80 + 1.81 +G1PageBasedVirtualSpace::~G1PageBasedVirtualSpace() { 1.82 + release(); 1.83 +} 1.84 + 1.85 +void G1PageBasedVirtualSpace::release() { 1.86 + // This does not release memory it never reserved. 1.87 + // Caller must release via rs.release(); 1.88 + _low_boundary = NULL; 1.89 + _high_boundary = NULL; 1.90 + _special = false; 1.91 + _executable = false; 1.92 + _page_size = 0; 1.93 + _committed.resize(0, false); 1.94 +} 1.95 + 1.96 +size_t G1PageBasedVirtualSpace::committed_size() const { 1.97 + return _committed.count_one_bits() * _page_size; 1.98 +} 1.99 + 1.100 +size_t G1PageBasedVirtualSpace::reserved_size() const { 1.101 + return pointer_delta(_high_boundary, _low_boundary, sizeof(char)); 1.102 +} 1.103 + 1.104 +size_t G1PageBasedVirtualSpace::uncommitted_size() const { 1.105 + return reserved_size() - committed_size(); 1.106 +} 1.107 + 1.108 +uintptr_t G1PageBasedVirtualSpace::addr_to_page_index(char* addr) const { 1.109 + return (addr - _low_boundary) / _page_size; 1.110 +} 1.111 + 1.112 +bool G1PageBasedVirtualSpace::is_area_committed(uintptr_t start, size_t size_in_pages) const { 1.113 + uintptr_t end = start + size_in_pages; 1.114 + return _committed.get_next_zero_offset(start, end) >= end; 1.115 +} 1.116 + 1.117 +bool G1PageBasedVirtualSpace::is_area_uncommitted(uintptr_t start, size_t size_in_pages) const { 1.118 + uintptr_t end = start + size_in_pages; 1.119 + return _committed.get_next_one_offset(start, end) >= end; 1.120 +} 1.121 + 1.122 +char* G1PageBasedVirtualSpace::page_start(uintptr_t index) { 1.123 + return _low_boundary + index * _page_size; 1.124 +} 1.125 + 1.126 +size_t G1PageBasedVirtualSpace::byte_size_for_pages(size_t num) { 1.127 + return num * _page_size; 1.128 +} 1.129 + 1.130 +MemRegion G1PageBasedVirtualSpace::commit(uintptr_t start, size_t size_in_pages) { 1.131 + // We need to make sure to commit all pages covered by the given area. 1.132 + guarantee(is_area_uncommitted(start, size_in_pages), "Specified area is not uncommitted"); 1.133 + 1.134 + if (!_special) { 1.135 + os::commit_memory_or_exit(page_start(start), byte_size_for_pages(size_in_pages), _executable, 1.136 + err_msg("Failed to commit pages from "SIZE_FORMAT" of length "SIZE_FORMAT, start, size_in_pages)); 1.137 + } 1.138 + _committed.set_range(start, start + size_in_pages); 1.139 + 1.140 + MemRegion result((HeapWord*)page_start(start), byte_size_for_pages(size_in_pages) / HeapWordSize); 1.141 + return result; 1.142 +} 1.143 + 1.144 +MemRegion G1PageBasedVirtualSpace::uncommit(uintptr_t start, size_t size_in_pages) { 1.145 + guarantee(is_area_committed(start, size_in_pages), "checking"); 1.146 + 1.147 + if (!_special) { 1.148 + os::uncommit_memory(page_start(start), byte_size_for_pages(size_in_pages)); 1.149 + } 1.150 + 1.151 + _committed.clear_range(start, start + size_in_pages); 1.152 + 1.153 + MemRegion result((HeapWord*)page_start(start), byte_size_for_pages(size_in_pages) / HeapWordSize); 1.154 + return result; 1.155 +} 1.156 + 1.157 +bool G1PageBasedVirtualSpace::contains(const void* p) const { 1.158 + return _low_boundary <= (const char*) p && (const char*) p < _high_boundary; 1.159 +} 1.160 + 1.161 +#ifndef PRODUCT 1.162 +void G1PageBasedVirtualSpace::print_on(outputStream* out) { 1.163 + out->print ("Virtual space:"); 1.164 + if (special()) out->print(" (pinned in memory)"); 1.165 + out->cr(); 1.166 + out->print_cr(" - committed: " SIZE_FORMAT, committed_size()); 1.167 + out->print_cr(" - reserved: " SIZE_FORMAT, reserved_size()); 1.168 + out->print_cr(" - [low_b, high_b]: [" INTPTR_FORMAT ", " INTPTR_FORMAT "]", p2i(_low_boundary), p2i(_high_boundary)); 1.169 +} 1.170 + 1.171 +void G1PageBasedVirtualSpace::print() { 1.172 + print_on(tty); 1.173 +} 1.174 +#endif