duke@435: /* mikael@6198: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_RUNTIME_VIRTUALSPACE_HPP stefank@2314: #define SHARE_VM_RUNTIME_VIRTUALSPACE_HPP stefank@2314: stefank@2314: #include "memory/allocation.hpp" stefank@2314: duke@435: // ReservedSpace is a data structure for reserving a contiguous address range. duke@435: duke@435: class ReservedSpace VALUE_OBJ_CLASS_SPEC { duke@435: friend class VMStructs; duke@435: private: duke@435: char* _base; duke@435: size_t _size; coleenp@672: size_t _noaccess_prefix; duke@435: size_t _alignment; duke@435: bool _special; coleenp@1091: bool _executable; duke@435: duke@435: // ReservedSpace coleenp@1091: ReservedSpace(char* base, size_t size, size_t alignment, bool special, coleenp@1091: bool executable); duke@435: void initialize(size_t size, size_t alignment, bool large, coleenp@672: char* requested_address, coleenp@1091: const size_t noaccess_prefix, coleenp@1091: bool executable); duke@435: coleenp@672: protected: coleenp@672: // Create protection page at the beginning of the space. coleenp@672: void protect_noaccess_prefix(const size_t size); coleenp@672: duke@435: public: duke@435: // Constructor stefank@5578: ReservedSpace(); duke@435: ReservedSpace(size_t size); duke@435: ReservedSpace(size_t size, size_t alignment, bool large, coleenp@672: char* requested_address = NULL, coleenp@672: const size_t noaccess_prefix = 0); coleenp@1091: ReservedSpace(size_t size, size_t alignment, bool large, bool executable); duke@435: duke@435: // Accessors coleenp@1091: char* base() const { return _base; } coleenp@1091: size_t size() const { return _size; } coleenp@1091: size_t alignment() const { return _alignment; } coleenp@1091: bool special() const { return _special; } coleenp@1091: bool executable() const { return _executable; } coleenp@1091: size_t noaccess_prefix() const { return _noaccess_prefix; } coleenp@1091: bool is_reserved() const { return _base != NULL; } duke@435: void release(); duke@435: duke@435: // Splitting duke@435: ReservedSpace first_part(size_t partition_size, size_t alignment, duke@435: bool split = false, bool realloc = true); duke@435: ReservedSpace last_part (size_t partition_size, size_t alignment); duke@435: duke@435: // These simply call the above using the default alignment. duke@435: inline ReservedSpace first_part(size_t partition_size, duke@435: bool split = false, bool realloc = true); duke@435: inline ReservedSpace last_part (size_t partition_size); duke@435: duke@435: // Alignment duke@435: static size_t page_align_size_up(size_t size); duke@435: static size_t page_align_size_down(size_t size); duke@435: static size_t allocation_align_size_up(size_t size); duke@435: static size_t allocation_align_size_down(size_t size); duke@435: }; duke@435: duke@435: ReservedSpace duke@435: ReservedSpace::first_part(size_t partition_size, bool split, bool realloc) duke@435: { duke@435: return first_part(partition_size, alignment(), split, realloc); duke@435: } duke@435: duke@435: ReservedSpace ReservedSpace::last_part(size_t partition_size) duke@435: { duke@435: return last_part(partition_size, alignment()); duke@435: } duke@435: coleenp@672: // Class encapsulating behavior specific of memory space reserved for Java heap coleenp@672: class ReservedHeapSpace : public ReservedSpace { coleenp@672: public: coleenp@672: // Constructor coleenp@672: ReservedHeapSpace(size_t size, size_t forced_base_alignment, coleenp@672: bool large, char* requested_address); coleenp@672: }; coleenp@672: coleenp@1091: // Class encapsulating behavior specific memory space for Code coleenp@1091: class ReservedCodeSpace : public ReservedSpace { coleenp@1091: public: coleenp@1091: // Constructor coleenp@1091: ReservedCodeSpace(size_t r_size, size_t rs_align, bool large); coleenp@1091: }; coleenp@1091: duke@435: // VirtualSpace is data structure for committing a previously reserved address range in smaller chunks. duke@435: duke@435: class VirtualSpace VALUE_OBJ_CLASS_SPEC { duke@435: friend class VMStructs; duke@435: private: duke@435: // Reserved area duke@435: char* _low_boundary; duke@435: char* _high_boundary; duke@435: duke@435: // Committed area duke@435: char* _low; duke@435: char* _high; duke@435: duke@435: // The entire space has been committed and pinned in memory, no duke@435: // os::commit_memory() or os::uncommit_memory(). duke@435: bool _special; duke@435: coleenp@1091: // Need to know if commit should be executable. coleenp@1091: bool _executable; coleenp@1091: duke@435: // MPSS Support duke@435: // Each virtualspace region has a lower, middle, and upper region. duke@435: // Each region has an end boundary and a high pointer which is the duke@435: // high water mark for the last allocated byte. duke@435: // The lower and upper unaligned to LargePageSizeInBytes uses default page. duke@435: // size. The middle region uses large page size. duke@435: char* _lower_high; duke@435: char* _middle_high; duke@435: char* _upper_high; duke@435: duke@435: char* _lower_high_boundary; duke@435: char* _middle_high_boundary; duke@435: char* _upper_high_boundary; duke@435: duke@435: size_t _lower_alignment; duke@435: size_t _middle_alignment; duke@435: size_t _upper_alignment; duke@435: duke@435: // MPSS Accessors duke@435: char* lower_high() const { return _lower_high; } duke@435: char* middle_high() const { return _middle_high; } duke@435: char* upper_high() const { return _upper_high; } duke@435: duke@435: char* lower_high_boundary() const { return _lower_high_boundary; } duke@435: char* middle_high_boundary() const { return _middle_high_boundary; } duke@435: char* upper_high_boundary() const { return _upper_high_boundary; } duke@435: duke@435: size_t lower_alignment() const { return _lower_alignment; } duke@435: size_t middle_alignment() const { return _middle_alignment; } duke@435: size_t upper_alignment() const { return _upper_alignment; } duke@435: duke@435: public: duke@435: // Committed area duke@435: char* low() const { return _low; } duke@435: char* high() const { return _high; } duke@435: duke@435: // Reserved area duke@435: char* low_boundary() const { return _low_boundary; } duke@435: char* high_boundary() const { return _high_boundary; } duke@435: duke@435: bool special() const { return _special; } duke@435: duke@435: public: duke@435: // Initialization duke@435: VirtualSpace(); mgerdin@5859: bool initialize_with_granularity(ReservedSpace rs, size_t committed_byte_size, size_t max_commit_ganularity); duke@435: bool initialize(ReservedSpace rs, size_t committed_byte_size); duke@435: duke@435: // Destruction duke@435: ~VirtualSpace(); duke@435: stefank@5704: // Reserved memory stefank@5704: size_t reserved_size() const; stefank@5704: // Actually committed OS memory stefank@5704: size_t actual_committed_size() const; stefank@5704: // Memory used/expanded in this virtual space stefank@5704: size_t committed_size() const; stefank@5704: // Memory left to use/expand in this virtual space duke@435: size_t uncommitted_size() const; stefank@5704: stefank@5704: bool contains(const void* p) const; duke@435: duke@435: // Operations duke@435: // returns true on success, false otherwise duke@435: bool expand_by(size_t bytes, bool pre_touch = false); duke@435: void shrink_by(size_t bytes); duke@435: void release(); duke@435: duke@435: void check_for_contiguity() PRODUCT_RETURN; duke@435: duke@435: // Debugging stefank@5708: void print_on(outputStream* out) PRODUCT_RETURN; stefank@5708: void print(); duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_RUNTIME_VIRTUALSPACE_HPP