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