1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/runtime/virtualspace.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,211 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, 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 +#ifndef SHARE_VM_RUNTIME_VIRTUALSPACE_HPP 1.29 +#define SHARE_VM_RUNTIME_VIRTUALSPACE_HPP 1.30 + 1.31 +#include "memory/allocation.hpp" 1.32 + 1.33 +// ReservedSpace is a data structure for reserving a contiguous address range. 1.34 + 1.35 +class ReservedSpace VALUE_OBJ_CLASS_SPEC { 1.36 + friend class VMStructs; 1.37 + private: 1.38 + char* _base; 1.39 + size_t _size; 1.40 + size_t _noaccess_prefix; 1.41 + size_t _alignment; 1.42 + bool _special; 1.43 + bool _executable; 1.44 + 1.45 + // ReservedSpace 1.46 + ReservedSpace(char* base, size_t size, size_t alignment, bool special, 1.47 + bool executable); 1.48 + void initialize(size_t size, size_t alignment, bool large, 1.49 + char* requested_address, 1.50 + const size_t noaccess_prefix, 1.51 + bool executable); 1.52 + 1.53 + protected: 1.54 + // Create protection page at the beginning of the space. 1.55 + void protect_noaccess_prefix(const size_t size); 1.56 + 1.57 + public: 1.58 + // Constructor 1.59 + ReservedSpace(); 1.60 + ReservedSpace(size_t size); 1.61 + ReservedSpace(size_t size, size_t alignment, bool large, 1.62 + char* requested_address = NULL, 1.63 + const size_t noaccess_prefix = 0); 1.64 + ReservedSpace(size_t size, size_t alignment, bool large, bool executable); 1.65 + 1.66 + // Accessors 1.67 + char* base() const { return _base; } 1.68 + size_t size() const { return _size; } 1.69 + size_t alignment() const { return _alignment; } 1.70 + bool special() const { return _special; } 1.71 + bool executable() const { return _executable; } 1.72 + size_t noaccess_prefix() const { return _noaccess_prefix; } 1.73 + bool is_reserved() const { return _base != NULL; } 1.74 + void release(); 1.75 + 1.76 + // Splitting 1.77 + ReservedSpace first_part(size_t partition_size, size_t alignment, 1.78 + bool split = false, bool realloc = true); 1.79 + ReservedSpace last_part (size_t partition_size, size_t alignment); 1.80 + 1.81 + // These simply call the above using the default alignment. 1.82 + inline ReservedSpace first_part(size_t partition_size, 1.83 + bool split = false, bool realloc = true); 1.84 + inline ReservedSpace last_part (size_t partition_size); 1.85 + 1.86 + // Alignment 1.87 + static size_t page_align_size_up(size_t size); 1.88 + static size_t page_align_size_down(size_t size); 1.89 + static size_t allocation_align_size_up(size_t size); 1.90 + static size_t allocation_align_size_down(size_t size); 1.91 +}; 1.92 + 1.93 +ReservedSpace 1.94 +ReservedSpace::first_part(size_t partition_size, bool split, bool realloc) 1.95 +{ 1.96 + return first_part(partition_size, alignment(), split, realloc); 1.97 +} 1.98 + 1.99 +ReservedSpace ReservedSpace::last_part(size_t partition_size) 1.100 +{ 1.101 + return last_part(partition_size, alignment()); 1.102 +} 1.103 + 1.104 +// Class encapsulating behavior specific of memory space reserved for Java heap 1.105 +class ReservedHeapSpace : public ReservedSpace { 1.106 +public: 1.107 + // Constructor 1.108 + ReservedHeapSpace(size_t size, size_t forced_base_alignment, 1.109 + bool large, char* requested_address); 1.110 +}; 1.111 + 1.112 +// Class encapsulating behavior specific memory space for Code 1.113 +class ReservedCodeSpace : public ReservedSpace { 1.114 + public: 1.115 + // Constructor 1.116 + ReservedCodeSpace(size_t r_size, size_t rs_align, bool large); 1.117 +}; 1.118 + 1.119 +// VirtualSpace is data structure for committing a previously reserved address range in smaller chunks. 1.120 + 1.121 +class VirtualSpace VALUE_OBJ_CLASS_SPEC { 1.122 + friend class VMStructs; 1.123 + private: 1.124 + // Reserved area 1.125 + char* _low_boundary; 1.126 + char* _high_boundary; 1.127 + 1.128 + // Committed area 1.129 + char* _low; 1.130 + char* _high; 1.131 + 1.132 + // The entire space has been committed and pinned in memory, no 1.133 + // os::commit_memory() or os::uncommit_memory(). 1.134 + bool _special; 1.135 + 1.136 + // Need to know if commit should be executable. 1.137 + bool _executable; 1.138 + 1.139 + // MPSS Support 1.140 + // Each virtualspace region has a lower, middle, and upper region. 1.141 + // Each region has an end boundary and a high pointer which is the 1.142 + // high water mark for the last allocated byte. 1.143 + // The lower and upper unaligned to LargePageSizeInBytes uses default page. 1.144 + // size. The middle region uses large page size. 1.145 + char* _lower_high; 1.146 + char* _middle_high; 1.147 + char* _upper_high; 1.148 + 1.149 + char* _lower_high_boundary; 1.150 + char* _middle_high_boundary; 1.151 + char* _upper_high_boundary; 1.152 + 1.153 + size_t _lower_alignment; 1.154 + size_t _middle_alignment; 1.155 + size_t _upper_alignment; 1.156 + 1.157 + // MPSS Accessors 1.158 + char* lower_high() const { return _lower_high; } 1.159 + char* middle_high() const { return _middle_high; } 1.160 + char* upper_high() const { return _upper_high; } 1.161 + 1.162 + char* lower_high_boundary() const { return _lower_high_boundary; } 1.163 + char* middle_high_boundary() const { return _middle_high_boundary; } 1.164 + char* upper_high_boundary() const { return _upper_high_boundary; } 1.165 + 1.166 + size_t lower_alignment() const { return _lower_alignment; } 1.167 + size_t middle_alignment() const { return _middle_alignment; } 1.168 + size_t upper_alignment() const { return _upper_alignment; } 1.169 + 1.170 + public: 1.171 + // Committed area 1.172 + char* low() const { return _low; } 1.173 + char* high() const { return _high; } 1.174 + 1.175 + // Reserved area 1.176 + char* low_boundary() const { return _low_boundary; } 1.177 + char* high_boundary() const { return _high_boundary; } 1.178 + 1.179 + bool special() const { return _special; } 1.180 + 1.181 + public: 1.182 + // Initialization 1.183 + VirtualSpace(); 1.184 + bool initialize_with_granularity(ReservedSpace rs, size_t committed_byte_size, size_t max_commit_ganularity); 1.185 + bool initialize(ReservedSpace rs, size_t committed_byte_size); 1.186 + 1.187 + // Destruction 1.188 + ~VirtualSpace(); 1.189 + 1.190 + // Reserved memory 1.191 + size_t reserved_size() const; 1.192 + // Actually committed OS memory 1.193 + size_t actual_committed_size() const; 1.194 + // Memory used/expanded in this virtual space 1.195 + size_t committed_size() const; 1.196 + // Memory left to use/expand in this virtual space 1.197 + size_t uncommitted_size() const; 1.198 + 1.199 + bool contains(const void* p) const; 1.200 + 1.201 + // Operations 1.202 + // returns true on success, false otherwise 1.203 + bool expand_by(size_t bytes, bool pre_touch = false); 1.204 + void shrink_by(size_t bytes); 1.205 + void release(); 1.206 + 1.207 + void check_for_contiguity() PRODUCT_RETURN; 1.208 + 1.209 + // Debugging 1.210 + void print_on(outputStream* out) PRODUCT_RETURN; 1.211 + void print(); 1.212 +}; 1.213 + 1.214 +#endif // SHARE_VM_RUNTIME_VIRTUALSPACE_HPP