tschatzl@7051: /* tschatzl@7051: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. tschatzl@7051: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. tschatzl@7051: * tschatzl@7051: * This code is free software; you can redistribute it and/or modify it tschatzl@7051: * under the terms of the GNU General Public License version 2 only, as tschatzl@7051: * published by the Free Software Foundation. tschatzl@7051: * tschatzl@7051: * This code is distributed in the hope that it will be useful, but WITHOUT tschatzl@7051: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or tschatzl@7051: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License tschatzl@7051: * version 2 for more details (a copy is included in the LICENSE file that tschatzl@7051: * accompanied this code). tschatzl@7051: * tschatzl@7051: * You should have received a copy of the GNU General Public License version tschatzl@7051: * 2 along with this work; if not, write to the Free Software Foundation, tschatzl@7051: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. tschatzl@7051: * tschatzl@7051: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA tschatzl@7051: * or visit www.oracle.com if you need additional information or have any tschatzl@7051: * questions. tschatzl@7051: * tschatzl@7051: */ tschatzl@7051: tschatzl@7051: #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1PAGEBASEDVIRTUALSPACE_HPP tschatzl@7051: #define SHARE_VM_GC_IMPLEMENTATION_G1_G1PAGEBASEDVIRTUALSPACE_HPP tschatzl@7051: tschatzl@7051: #include "memory/allocation.hpp" tschatzl@7051: #include "memory/memRegion.hpp" tschatzl@7051: #include "runtime/virtualspace.hpp" tschatzl@7051: #include "utilities/bitMap.hpp" tschatzl@7051: tschatzl@7051: // Virtual space management helper for a virtual space with an OS page allocation tschatzl@7051: // granularity. tschatzl@7051: // (De-)Allocation requests are always OS page aligned by passing a page index tschatzl@7051: // and multiples of pages. tschatzl@7051: // The implementation gives an error when trying to commit or uncommit pages that tschatzl@7051: // have already been committed or uncommitted. tschatzl@7051: class G1PageBasedVirtualSpace VALUE_OBJ_CLASS_SPEC { tschatzl@7051: friend class VMStructs; tschatzl@7051: private: tschatzl@7051: // Reserved area addresses. tschatzl@7051: char* _low_boundary; tschatzl@7051: char* _high_boundary; tschatzl@7051: tschatzl@7051: // The commit/uncommit granularity in bytes. tschatzl@7051: size_t _page_size; tschatzl@7051: tschatzl@7051: // Bitmap used for verification of commit/uncommit operations. tschatzl@7051: BitMap _committed; tschatzl@7051: tschatzl@7051: // Indicates that the entire space has been committed and pinned in memory, tschatzl@7051: // os::commit_memory() or os::uncommit_memory() have no function. tschatzl@7051: bool _special; tschatzl@7051: tschatzl@7051: // Indicates whether the committed space should be executable. tschatzl@7051: bool _executable; tschatzl@7051: tschatzl@7051: // Returns the index of the page which contains the given address. tschatzl@7051: uintptr_t addr_to_page_index(char* addr) const; tschatzl@7051: // Returns the address of the given page index. tschatzl@7051: char* page_start(uintptr_t index); tschatzl@7051: // Returns the byte size of the given number of pages. tschatzl@7051: size_t byte_size_for_pages(size_t num); tschatzl@7051: tschatzl@7051: // Returns true if the entire area is backed by committed memory. tschatzl@7051: bool is_area_committed(uintptr_t start, size_t size_in_pages) const; tschatzl@7051: // Returns true if the entire area is not backed by committed memory. tschatzl@7051: bool is_area_uncommitted(uintptr_t start, size_t size_in_pages) const; tschatzl@7051: tschatzl@7051: public: tschatzl@7051: tschatzl@7051: // Commit the given area of pages starting at start being size_in_pages large. tschatzl@7051: MemRegion commit(uintptr_t start, size_t size_in_pages); tschatzl@7051: tschatzl@7051: // Uncommit the given area of pages starting at start being size_in_pages large. tschatzl@7051: MemRegion uncommit(uintptr_t start, size_t size_in_pages); tschatzl@7051: tschatzl@7051: bool special() const { return _special; } tschatzl@7051: tschatzl@7051: // Initialization tschatzl@7051: G1PageBasedVirtualSpace(); tschatzl@7051: bool initialize_with_granularity(ReservedSpace rs, size_t page_size); tschatzl@7051: tschatzl@7051: // Destruction tschatzl@7051: ~G1PageBasedVirtualSpace(); tschatzl@7051: tschatzl@7051: // Amount of reserved memory. tschatzl@7051: size_t reserved_size() const; tschatzl@7051: // Memory used in this virtual space. tschatzl@7051: size_t committed_size() const; tschatzl@7051: // Memory left to use/expand in this virtual space. tschatzl@7051: size_t uncommitted_size() const; tschatzl@7051: tschatzl@7051: bool contains(const void* p) const; tschatzl@7051: tschatzl@7051: MemRegion reserved() { tschatzl@7051: MemRegion x((HeapWord*)_low_boundary, reserved_size() / HeapWordSize); tschatzl@7051: return x; tschatzl@7051: } tschatzl@7051: tschatzl@7051: void release(); tschatzl@7051: tschatzl@7051: void check_for_contiguity() PRODUCT_RETURN; tschatzl@7051: tschatzl@7051: // Debugging tschatzl@7051: void print_on(outputStream* out) PRODUCT_RETURN; tschatzl@7051: void print(); tschatzl@7051: }; tschatzl@7051: tschatzl@7051: #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1PAGEBASEDVIRTUALSPACE_HPP