src/share/vm/runtime/virtualspace.hpp

Wed, 17 Aug 2011 10:32:53 -0700

author
jcoomes
date
Wed, 17 Aug 2011 10:32:53 -0700
changeset 3057
24cee90e9453
parent 2314
f95d63e2154a
child 4037
da91efe96a93
permissions
-rw-r--r--

6791672: enable 1G and larger pages on solaris
Reviewed-by: ysr, iveresov, johnc

duke@435 1 /*
stefank@2314 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_RUNTIME_VIRTUALSPACE_HPP
stefank@2314 26 #define SHARE_VM_RUNTIME_VIRTUALSPACE_HPP
stefank@2314 27
stefank@2314 28 #include "memory/allocation.hpp"
stefank@2314 29
duke@435 30 // ReservedSpace is a data structure for reserving a contiguous address range.
duke@435 31
duke@435 32 class ReservedSpace VALUE_OBJ_CLASS_SPEC {
duke@435 33 friend class VMStructs;
duke@435 34 private:
duke@435 35 char* _base;
duke@435 36 size_t _size;
coleenp@672 37 size_t _noaccess_prefix;
duke@435 38 size_t _alignment;
duke@435 39 bool _special;
coleenp@1091 40 bool _executable;
duke@435 41
duke@435 42 // ReservedSpace
coleenp@1091 43 ReservedSpace(char* base, size_t size, size_t alignment, bool special,
coleenp@1091 44 bool executable);
duke@435 45 void initialize(size_t size, size_t alignment, bool large,
coleenp@672 46 char* requested_address,
coleenp@1091 47 const size_t noaccess_prefix,
coleenp@1091 48 bool executable);
duke@435 49
duke@435 50 // Release parts of an already-reserved memory region [addr, addr + len) to
duke@435 51 // get a new region that has "compound alignment." Return the start of the
duke@435 52 // resulting region, or NULL on failure.
duke@435 53 //
duke@435 54 // The region is logically divided into a prefix and a suffix. The prefix
duke@435 55 // starts at the result address, which is aligned to prefix_align. The suffix
duke@435 56 // starts at result address + prefix_size, which is aligned to suffix_align.
duke@435 57 // The total size of the result region is size prefix_size + suffix_size.
duke@435 58 char* align_reserved_region(char* addr, const size_t len,
duke@435 59 const size_t prefix_size,
duke@435 60 const size_t prefix_align,
duke@435 61 const size_t suffix_size,
duke@435 62 const size_t suffix_align);
duke@435 63
duke@435 64 // Reserve memory, call align_reserved_region() to alignment it and return the
duke@435 65 // result.
duke@435 66 char* reserve_and_align(const size_t reserve_size,
duke@435 67 const size_t prefix_size,
duke@435 68 const size_t prefix_align,
duke@435 69 const size_t suffix_size,
duke@435 70 const size_t suffix_align);
duke@435 71
coleenp@672 72 protected:
coleenp@672 73 // Create protection page at the beginning of the space.
coleenp@672 74 void protect_noaccess_prefix(const size_t size);
coleenp@672 75
duke@435 76 public:
duke@435 77 // Constructor
duke@435 78 ReservedSpace(size_t size);
duke@435 79 ReservedSpace(size_t size, size_t alignment, bool large,
coleenp@672 80 char* requested_address = NULL,
coleenp@672 81 const size_t noaccess_prefix = 0);
duke@435 82 ReservedSpace(const size_t prefix_size, const size_t prefix_align,
coleenp@672 83 const size_t suffix_size, const size_t suffix_align,
kvn@1077 84 char* requested_address,
kvn@1077 85 const size_t noaccess_prefix = 0);
coleenp@1091 86 ReservedSpace(size_t size, size_t alignment, bool large, bool executable);
duke@435 87
duke@435 88 // Accessors
coleenp@1091 89 char* base() const { return _base; }
coleenp@1091 90 size_t size() const { return _size; }
coleenp@1091 91 size_t alignment() const { return _alignment; }
coleenp@1091 92 bool special() const { return _special; }
coleenp@1091 93 bool executable() const { return _executable; }
coleenp@1091 94 size_t noaccess_prefix() const { return _noaccess_prefix; }
coleenp@1091 95 bool is_reserved() const { return _base != NULL; }
duke@435 96 void release();
duke@435 97
duke@435 98 // Splitting
duke@435 99 ReservedSpace first_part(size_t partition_size, size_t alignment,
duke@435 100 bool split = false, bool realloc = true);
duke@435 101 ReservedSpace last_part (size_t partition_size, size_t alignment);
duke@435 102
duke@435 103 // These simply call the above using the default alignment.
duke@435 104 inline ReservedSpace first_part(size_t partition_size,
duke@435 105 bool split = false, bool realloc = true);
duke@435 106 inline ReservedSpace last_part (size_t partition_size);
duke@435 107
duke@435 108 // Alignment
duke@435 109 static size_t page_align_size_up(size_t size);
duke@435 110 static size_t page_align_size_down(size_t size);
duke@435 111 static size_t allocation_align_size_up(size_t size);
duke@435 112 static size_t allocation_align_size_down(size_t size);
duke@435 113 };
duke@435 114
duke@435 115 ReservedSpace
duke@435 116 ReservedSpace::first_part(size_t partition_size, bool split, bool realloc)
duke@435 117 {
duke@435 118 return first_part(partition_size, alignment(), split, realloc);
duke@435 119 }
duke@435 120
duke@435 121 ReservedSpace ReservedSpace::last_part(size_t partition_size)
duke@435 122 {
duke@435 123 return last_part(partition_size, alignment());
duke@435 124 }
duke@435 125
coleenp@672 126 // Class encapsulating behavior specific of memory space reserved for Java heap
coleenp@672 127 class ReservedHeapSpace : public ReservedSpace {
coleenp@672 128 public:
coleenp@672 129 // Constructor
coleenp@672 130 ReservedHeapSpace(size_t size, size_t forced_base_alignment,
coleenp@672 131 bool large, char* requested_address);
coleenp@672 132 ReservedHeapSpace(const size_t prefix_size, const size_t prefix_align,
kvn@1077 133 const size_t suffix_size, const size_t suffix_align,
kvn@1077 134 char* requested_address);
coleenp@672 135 };
coleenp@672 136
coleenp@1091 137 // Class encapsulating behavior specific memory space for Code
coleenp@1091 138 class ReservedCodeSpace : public ReservedSpace {
coleenp@1091 139 public:
coleenp@1091 140 // Constructor
coleenp@1091 141 ReservedCodeSpace(size_t r_size, size_t rs_align, bool large);
coleenp@1091 142 };
coleenp@1091 143
duke@435 144 // VirtualSpace is data structure for committing a previously reserved address range in smaller chunks.
duke@435 145
duke@435 146 class VirtualSpace VALUE_OBJ_CLASS_SPEC {
duke@435 147 friend class VMStructs;
duke@435 148 private:
duke@435 149 // Reserved area
duke@435 150 char* _low_boundary;
duke@435 151 char* _high_boundary;
duke@435 152
duke@435 153 // Committed area
duke@435 154 char* _low;
duke@435 155 char* _high;
duke@435 156
duke@435 157 // The entire space has been committed and pinned in memory, no
duke@435 158 // os::commit_memory() or os::uncommit_memory().
duke@435 159 bool _special;
duke@435 160
coleenp@1091 161 // Need to know if commit should be executable.
coleenp@1091 162 bool _executable;
coleenp@1091 163
duke@435 164 // MPSS Support
duke@435 165 // Each virtualspace region has a lower, middle, and upper region.
duke@435 166 // Each region has an end boundary and a high pointer which is the
duke@435 167 // high water mark for the last allocated byte.
duke@435 168 // The lower and upper unaligned to LargePageSizeInBytes uses default page.
duke@435 169 // size. The middle region uses large page size.
duke@435 170 char* _lower_high;
duke@435 171 char* _middle_high;
duke@435 172 char* _upper_high;
duke@435 173
duke@435 174 char* _lower_high_boundary;
duke@435 175 char* _middle_high_boundary;
duke@435 176 char* _upper_high_boundary;
duke@435 177
duke@435 178 size_t _lower_alignment;
duke@435 179 size_t _middle_alignment;
duke@435 180 size_t _upper_alignment;
duke@435 181
duke@435 182 // MPSS Accessors
duke@435 183 char* lower_high() const { return _lower_high; }
duke@435 184 char* middle_high() const { return _middle_high; }
duke@435 185 char* upper_high() const { return _upper_high; }
duke@435 186
duke@435 187 char* lower_high_boundary() const { return _lower_high_boundary; }
duke@435 188 char* middle_high_boundary() const { return _middle_high_boundary; }
duke@435 189 char* upper_high_boundary() const { return _upper_high_boundary; }
duke@435 190
duke@435 191 size_t lower_alignment() const { return _lower_alignment; }
duke@435 192 size_t middle_alignment() const { return _middle_alignment; }
duke@435 193 size_t upper_alignment() const { return _upper_alignment; }
duke@435 194
duke@435 195 public:
duke@435 196 // Committed area
duke@435 197 char* low() const { return _low; }
duke@435 198 char* high() const { return _high; }
duke@435 199
duke@435 200 // Reserved area
duke@435 201 char* low_boundary() const { return _low_boundary; }
duke@435 202 char* high_boundary() const { return _high_boundary; }
duke@435 203
duke@435 204 bool special() const { return _special; }
duke@435 205
duke@435 206 public:
duke@435 207 // Initialization
duke@435 208 VirtualSpace();
duke@435 209 bool initialize(ReservedSpace rs, size_t committed_byte_size);
duke@435 210
duke@435 211 // Destruction
duke@435 212 ~VirtualSpace();
duke@435 213
duke@435 214 // Testers (all sizes are byte sizes)
duke@435 215 size_t committed_size() const;
duke@435 216 size_t reserved_size() const;
duke@435 217 size_t uncommitted_size() const;
duke@435 218 bool contains(const void* p) const;
duke@435 219
duke@435 220 // Operations
duke@435 221 // returns true on success, false otherwise
duke@435 222 bool expand_by(size_t bytes, bool pre_touch = false);
duke@435 223 void shrink_by(size_t bytes);
duke@435 224 void release();
duke@435 225
duke@435 226 void check_for_contiguity() PRODUCT_RETURN;
duke@435 227
duke@435 228 // Debugging
duke@435 229 void print() PRODUCT_RETURN;
duke@435 230 };
stefank@2314 231
stefank@2314 232 #endif // SHARE_VM_RUNTIME_VIRTUALSPACE_HPP

mercurial